jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}

$(document).ready( function() {    
    
//    $('#boton_submit_hotel').click( function () {
//        $("#wait_screen").center();
//        $("#wait_screen").show();
//        $('#boton_submit_hotel').hide();
//    });

    $('form#busca_hotel').submit(function () {

        if ($('form#busca_hotel').validate().form()){
            $("#wait_screen").center();
            $("#wait_screen").show();
            $('#boton_submit_hotel').hide();
            return true;
        }
        else
            return false;
    });

    var d = new Date();
    d.setDate(d.getDate()+1);
    
    Calendar.setup({
        trigger    : "hs_arrival_button",
        inputField : "hs_arrival",
        dateFormat : "%d/%m/%Y",
        onSelect   : function() {this.hide()},
        min        : Calendar.dateToInt(d),
        bottomBar  : false
    });

    d.setDate(d.getDate()+1);
    Calendar.setup({
        trigger    : "hs_departure_button",
        inputField : "hs_departure",
        dateFormat : "%d/%m/%Y",
        onSelect   : function() {this.hide()},
        min        : Calendar.dateToInt(d),
        bottomBar  : false
    });

    $("#busca_hotel").validate({
		rules: {
			destino: "required",
                        hs_arrival: {required:true,
                                     date: true},
                        hs_departure: {required:true,
                                       date: true}
		},
		messages: {
			destino: "<br/>Selecciona un destino para buscar hotel.",
			hs_arrival: "<br/>La fecha de llegada al destino es obligatoria.",
			hs_departure: "<br/>La fecha de salida del destino es obligatoria."
		}
	});

    //resultado restaurante
    $('.col110 a,.col110t a,.col120 a,.col120t a,#paginacion a').click( function (event) {
            event.preventDefault();

            $('form#busca_hotel').attr('action',this.href);            
            $('#boton_submit_hotel').click();
    });
});
