﻿var bookingEngineUnload = true;
document.write("<script type='text/javascript' src='/scripts-v56/calendar/calendar-init.js'></script>");

var bookingEngineBreaks = {
    type: null,
	init: function() {
        
        formControl.checkMotorsCallback = function() {
             if($F('arrivee') == "") { 
                Error.display($('arrivee'), false);
                return false;
            }
            return true;
        }        
        
        this.type = this.getType();
        if(breaksCities[this.type]) {
            switch(this.type) {
                case 'citybreaks':
                    bookingEngine.minStay = 2;
                    bookingEngine.init();
                    break;
                case 'earlybreaks':
                    var now = new Date();
                    bookingEngine.firstBookingDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 14, 0, 0, 0);
                    bookingEngine.init();
                    bookingEngine.showDate();
                    bookingEngine.setDateHiddenFieldsValue(bookingEngine.firstBookingDate );
                    break;
            }
            Event.observe($('pays'), 'change', function(e) {
                var citiesList = breaksCities[this.type][$F('pays')];
                $('hotel_ou_ville').options.length = 0;
                if(citiesList) {
                    for(var index=0; index < citiesList.length; index++) {
                        $('hotel_ou_ville')[index] = new Option(citiesList[index], citiesList[index]);
                    }
                }
            }.bind(this));
        }
    },
    getType: function() {
        var type = null;
        var js = /calendar-breaks-init\.js(\?.*)?$/;
        $$('head script[src]').findAll(function(s) {
            return s.src.match(js);
        }).each(function(s) {
            type = s.src.match(/\?.*type=([a-z,]*)/);
        });
        if(type) return type[1];
        return null;
    }
}

Event.observe(window, 'load', function () {
	bookingEngineBreaks.init();
});