/// <reference path="jquery-1.3.2.js" />

// the french localization
$.tools.dateinput.localize("fr", {
    months: 'janvier,f&eacute;vrier,mars,avril,mai,juin,juillet,ao&ucirc;t,' +
                   	'septembre,octobre,novembre,d&eacute;cembre',
    shortMonths: 'jan,f&eacute;v,mar,avr,mai,jun,jul,ao&ucirc;,sep,oct,nov,d&eacute;c',
    days: 'dimanche,lundi,mardi,mercredi,jeudi,vendredi,samedi',
    shortDays: 'dim,lun,mar,mer,jeu,ven,sam'
});
var isoDate;
$(":date").dateinput({
    trigger: true,
    lang: 'fr',
    format: 'dd/mm/yyyy',
    min: -1

});



// use the same callback for two different events. possible with bind
$(":date").bind("onShow onHide", function() {
    $(this).parent().toggleClass("active");
});


// when first date input is changed
$(":date:first").data("dateinput").change(function() {

    // we use it's value for the seconds input min option
    $(":date:last").data("dateinput").setMin(this.getValue(), true).addDay(1);
});


$(document).ready(function() {
    $("#search-button").click(function() {
        // validate signup form on keyup and submit
        $("#booking").validate({
            submitHandler: function(form) {
                var _url = $("#booking").attr("action");
                var _type = $("#booking").attr("method");
                $("#booking").hide("200");
                $.ajax({
                    url: _url,
                    async: true,
                    data: $("#booking").serialize(),
                    type: _type,
                    cache: false,
                    dataType: "json",
                    success: function(data) {
                        $("#resultbooking").html(data);
                    },
                    error: function() {
                        $("#resultbooking").html(data);
                    }
                });

                $('<div id="loading"><div class="message">Traitement en cours, veuillez patienter !</div><div class="image"></div></div>')
                .insertAfter("#resultbooking").ajaxStart(function() {
                    $(this).show();
                }).ajaxStop(function() {
                    $(this).hide();
                });
            }
        });
    });
});
