/** > /scripts-v66/booking/common/utils-booking-engine.js **/
var bookingEngineToggler = {
   
    init : function(){
        /* Initialisation de l'état fermé du div */
        var toggler = false;
        /* Ecouteur du lien plus de critère */
        jQuery(".more-criteria a.lnk-moreoptions").click(function(){
            if(toggler == true){
                jQuery(".roomOptions").slideUp("slow", function(){
                    jQuery(this).addClass("off").removeClass("on");
                    toggler = false;
                });
                /* Gestion du changement de la puce +/- */
                jQuery(".more-criteria .undeploy").addClass("deploy").removeClass("undeploy");
                return false;
            } else {
                jQuery(".roomOptions").slideDown("slow", function(){
                    jQuery(this).addClass("on").removeClass("off");
                    toggler = true;
                });
                /* Gestion du changement de la puce +/- */
                jQuery(".more-criteria .deploy").addClass("undeploy").removeClass("deploy");
                return false;
            }
        });
    }
};

var roomDisplay = {
   
    init : function(form){
	  
        /* Ecouteur du select enfant par chambre */
        jQuery("select[name$=childrenNumber]").change(function(){
            roomDisplay.showChildrensRooms(this);
        });
	  
        /* Ecouteur du select chambre */
        jQuery("select[name$=search.roomNumber]").change(function(){
            roomDisplay.showRoom(this,1);
        });
	  
        /* Ecouteur du select fake enfant */
        jQuery("select[name$=search.childrenNumber]").change(function(){
            roomDisplay.showChildrens(this,form);
            roomDisplay.showRoom(this,0);
        });
		
    },
	  
    /* Gestion d'affichage du bloc "Chambres" */
    showRoom : function(e, nbr){
        var fieldset = jQuery(e).parents('fieldset');
        if(jQuery(e).val() > nbr){
            jQuery(".roomsDetails").slideDown("slow", function(){
                jQuery(this).addClass("on").removeClass("off");
                jQuery(this).find(".lnk-moreoptions").click(function(){
                    var link = this;
                    if(jQuery(this).parent().hasClass("undeploy")){
                        jQuery(".roomsWrapper").slideUp("slow", function(){
                            jQuery(link).parent().addClass("deploy").removeClass("undeploy");
                        });
                    } else {
                        jQuery(".roomsWrapper").slideDown("slow", function(){
                            jQuery(link).parent().addClass("undeploy").removeClass("deploy");
                        });
                    }
                    return false;
                });
            });
            jQuery(fieldset).find('.adults').hide();
            jQuery(fieldset).find('.childrens').hide();
        } else {
            jQuery(".roomsDetails").slideUp("slow", function(){
                jQuery(this).addClass("off").removeClass("on");
            });
            jQuery(fieldset).find('.adults').show();
            //keep hidden children's combo if no children policy
            if (!fieldset.hasClass('tNoChipol')) {
                jQuery(fieldset).find('.childrens').show();
            }
        }
    },
		
    /* Gestion Enfants depuis les fake select */
    showChildrens : function(e,classform){
        if(jQuery(e).val() > 0){
            jQuery(e).parents(".".classform).find(".tChildrensAges").addClass("on").removeClass("off");
        }
        else{
            jQuery(e).parents(".".classform).find(".tChildrensAges").addClass("off").removeClass("on");
        }
    },
		
    /* Gestion Enfants depuis les rooms criteria */
    showChildrensRooms : function(e){
        if(jQuery(e).val() > 0){
            jQuery(e).parents(".roomDetails").find(".tChildrensAges").addClass("on").removeClass("off");
        }
        else{
            jQuery(e).parents(".roomDetails").find(".tChildrensAges").addClass("off").removeClass("on");
        }
    }
};
/** < /scripts-v66/booking/common/utils-booking-engine.js **/

/** > /scripts-v66/booking/common/booking-engine.js **/
/*
 *	Booking Engine
 *	@version: 2.0
 *	@date 24/06/2010
 *	/!\ Files to be included to the HTML :
<script type="text/javascript" src="/scripts-v66/lib/jquery-1.6.1-min-ah.js"></script>
<script type="text/javascript" src="/scripts-v66/lib/ajax-request.js"></script>
 */

var BookingEngine = function(formulaire, givenName, hasAutoCompletion,optionCal,searchType){
    this.initialize(formulaire, givenName, hasAutoCompletion,optionCal,searchType);
}

BookingEngine.prototype = {
		
    initialize : function(formulaire, givenName, hasAutoCompletion, optionCal,searchType){
        this.$currentForm = jQuery("#"+formulaire);
        this.idEngine = formulaire;
        this.prefEngine = this.idEngine;
        this.tmplRooms = this.$currentForm.find(".roomsWrapper");
        this.tmplBrands = this.$currentForm.find(".containerBrands");
        this.givenName = givenName;
        this.hasAutoCompletion = hasAutoCompletion != undefined ? hasAutoCompletion : null;
        this.autoComplete = null;
	
        this.btnSubmit = this.$currentForm.find(".tSubmit");
        this.btnCriteria = this.$currentForm.find(".moreCriteria .lnk-moreoptions");
        this.roomOptions = this.$currentForm.find(".roomOptions");
			
        this.destination = this.$currentForm.find(".tSearchDestination");
        this.localLink = this.$currentForm.find("a.localHotelsHelper");
        this.country = this.$currentForm.find("select.tCountries");
        this.city = this.$currentForm.find("select.tCities");
	
        this.radiusVal = this.$currentForm.find("select[name='search.radius.value']");
        this.radiusUnit = this.$currentForm.find("select[name='search.radius.unit']");
			
        this.onMap = this.$currentForm.find("input[name$='search.displayOnMap']");
			
        this.arrivalDate = this.$currentForm.find("input[name='search.dateIn']");
        this.arrivalDay = this.$currentForm.find("input[name='search.dayIn']");
        this.arrivalMonth = this.$currentForm.find("input[name='search.monthIn']");
        this.arrivalYear = this.$currentForm.find("input[name='search.yearIn']");
        this.departureDate = this.$currentForm.find("input[name='search.dateOut']");
        this.departureDay = this.$currentForm.find("input[name='search.dayOut']");
        this.departureMonth = this.$currentForm.find("input[name='search.monthOut']");
        this.departureYear = this.$currentForm.find("input[name='search.yearOut']");
        this.showNight = this.$currentForm.find(".tNights");
        this.nbNight = this.$currentForm.find("input[name='search.nightNb']");
			
        this.fakeRoom = this.$currentForm.find("select[name='search.roomNumber']");
        this.fakeAdult = this.$currentForm.find("select[name='search.adultNumber']");
        this.fakeChild = this.$currentForm.find("select[name='search.childrenNumber']");
			
        this.hotelRating = this.$currentForm.find("select[name='filter.hotelRatingClass']");
			
        this.forkPrice = this.$currentForm.find("select[name='filter.forkPrice.bound']");
        this.forkCurrency = this.$currentForm.find("input[name='filter.forkPrice.currency']");
        this.listBrands = this.$currentForm.find("input[name='filter.selectbrands']");
        this.advBrandsOption = this.$currentForm.find('ul.brandsSelect');
        this.advServicesOption = this.$currentForm.find('ul.servicesSelect');
        this.advLeasureOption = this.$currentForm.find('ul.leisureSelect');
        this.servicesOption = this.$currentForm.find('ul.tServicesSelect');
			
        this.preferedCode = this.$currentForm.find("input[name='identification.preferredCode.code']");
        this.cardCode = this.$currentForm.find("input[name='identification.fidelityCard.number']");
        this.showPro = this.$currentForm.find("input[name='identification.businessTravel']");
        this.showProAcc = this.$currentForm.find("input[name='identification.reserverType']");
        this.proReserverId = this.$currentForm.find("input[name='identification.reserverId']");
        this.proReserverNumber = this.$currentForm.find("input[name='identification.reserverContract']");
        this.proReserverContract = this.$currentForm.find("input[name='identification.reserverContract']");
        this.proReserverType = this.$currentForm.find("input[name='identification.reserverType']");
        this.proAccountId = this.$currentForm.find("input[name='identification.accountId']");
        this.proAccountContract = this.$currentForm.find("input[name='identification.accountContract']");
        this.geoType = this.$currentForm.find("input[name='search.geoZone.type']");
        this.geoCode = this.$currentForm.find("input[name='search.geoZone.code']");
        this.optionCal = optionCal;
        this.searchType = searchType;
        this.HP = false;
			

        //parade pour le submit intempestif de Chrome et Safari
        var defaultPostSubmit = false;
		
        this.$currentForm.bind("submit", {
            _this : this
        }, function(e){
																	  
            if (e.data._this.defaultPostSubmit) {
                return true;
            }
            else{
                e.data._this.subBooking();
                return false;
            }
        });
    },
		

		
    success : function(errors, json){
        if(errors && errors.length > 0){
            ajaxRequest.showErrors(errors, "errorMessage", this.idEngine);
        }
        else if (json.viewBeans && json.viewBeans.SearchCriteriaViewBean && json.viewBeans.OriginViewBean){
            //language
            this.lang = jQuery("html").attr("lang");
            if(this.lang == "en") this.lang = "gb";

            this.initBookingEngineToggler();
	
            //execute room template
            this.tmplRooms.setTemplateURL("/"+this.lang+"/templates-v66/booking/booking-engine-rooms.tpl");
				
            //execute brands template : advanced search engine
            if (this.idEngine == "advancedBookingEngine")
                this.tmplBrands.setTemplateURL("/"+this.lang+"/templates-v66/booking/booking-engine-brands.tpl");
				
            this.data = json.viewBeans.SearchCriteriaViewBean;
            this.origin = json.viewBeans.OriginViewBean;
            if(json.viewBeans.CurrenciesViewBean) this.CurrenciesViewBean = json.viewBeans.CurrenciesViewBean;
				
            this.initRoomsDatas();
            this.implementBooking();
				
            //Template : initialisation
            this.tmplRooms.setParam("idForm", this.idEngine);
            this.tmplRooms.setParam("prefForm", this.prefEngine);
            this.tmplRooms.setParam("roomNb", this.fakeRoom.val());
            this.tmplRooms.setParam("ChildNb",null);
            this.tmplRooms.processTemplate(this.data);
            this.setChildrenObservers();
				
            this.initDataTemplate();
            this.deserializeFormDatas(this.$currentForm);
				
            //Date
            //option calendar
            if(this.optionCal){//controle sur option
                this.now = new Date();
                this.now = new Date(this.now.getFullYear(),this.now.getMonth(),this.now.getDate(),12,0,0);
			
                if(this.optionCal.firstArrivalDate && this.optionCal.lastArrivalDate){
                    if(this.optionCal.firstArrivalDate.getTime()>this.optionCal.lastArrivalDate.getTime()){
                        this.optionCal.firstArrivalDate = null;
                        this.optionCal.lastArrivalDate = null;
                    }
                }
                if(this.optionCal.defaultDate){
                    if(this.optionCal.defaultDate.getTime()> (this.now.getTime()+3600*24*1000*this.data.bookingEngineRules.maxPeriodResa)) this.optionCal.defaultDate = null;
                }
                if(this.optionCal.firstArrivalDate){
                    if(this.optionCal.firstArrivalDate.getTime()> (this.now.getTime()+3600*24*1000*this.data.bookingEngineRules.maxPeriodResa)) this.optionCal.firstArrivalDate = null;
                }
                if(this.optionCal.lastArrivalDate){
                    if(this.optionCal.lastArrivalDate.getTime() < this.now.getTime()) this.optionCal.lastArrivalDate = null;
                }

                /*if(this.optionCal.minStay && !this.optionCal.maxStay){this.optionCal.maxStay = this.data.bookingEngineRules.maxDateResa}*/
                if(this.optionCal.maxStay){
                    if(this.optionCal.maxStay > this.data.bookingEngineRules.maxDateResa) {
                        this.optionCal.maxStay = this.data.bookingEngineRules.maxDateResa
                    };
                    if(this.optionCal.minStay){
                        if(this.optionCal.minStay>this.optionCal.maxStay){

                            this.optionCal.minStay = null;
                            this.optionCal.maxStay = null;
                        }
                    }
                }
					
					

					
				
						
                if(this.optionCal.maxStay > this.data.bookingEngineRules.maxDateResa) {
                    this.optionCal.maxStay = this.data.bookingEngineRules.maxDateResa
                };
            }
			
				
            new Calendar(this.idEngine, this.data.bookingEngineRules.maxDateResa, this.data.bookingEngineRules.maxPeriodResa, this.optionCal);
            jQuery(".middleContent").css("visibility", "visible"); //loading state
				
            //disable APAC & AMLAT inputs if this section is hidden
            if (this.country && this.city && jQuery("#engine-hotel-tab").hasClass("hideListCountryCity")) {
                this.country.attr("disabled", "true");
                this.city.attr("disabled", "true");
            }
				
            //disable and hide hotel rating's combo if it's currently a brand site (not AH.com)
            var isVisibleConfort = true;
            if (this.origin.siteCode != 'ALL' && this.hotelRating.length != 0 && this.hotelRating.parent('.confort').length != 0) {
                this.hotelRating.attr("disabled", "true");
                this.hotelRating.parent('.confort').hide();
                isVisibleConfort = false;
            }
				
            //disable and hide budget's combo if no budget's list available
            var isVisibleBudget = true;
            if (this.data.bookingEngineRules.forkPrices != null && this.data.bookingEngineRules.forkPrices.length == 0 && this.forkPrice.length != 0 && this.forkPrice.parent('.budget').length != 0) {
                this.forkPrice.attr("disabled", "true");
                this.forkPrice.parent('.budget').hide();
                isVisibleBudget = false;
            }
				
            if ((jQuery(".confortBudget").length != 0) && (!isVisibleConfort || !isVisibleBudget)) {
                jQuery(".confortBudget").removeClass('twoCriterias');
            }
				
            //disable and hide children's combo if no children policy (max children number = 0)
            if (this.data.bookingEngineRules.maxRoomOccupancy != null && this.data.bookingEngineRules.maxRoomOccupancy.childrenNumber == 0 && this.fakeChild.length != 0 && this.fakeChild.parent('.childrens').length != 0 && this.fakeChild.parent('.childrens').parent('fieldset.rooms-form').length != 0) {
                this.fakeChild.attr("disabled", "true");
                this.fakeChild.parent('.childrens').hide();
                this.fakeChild.parent('.childrens').parent('fieldset.rooms-form').addClass('tNoChipol'); /* class used for no children policy */
            }
            if(this.idEngine == "newbookingEngine" && this.data != null && this.data.idBox != null){
                utils.writeIdBox(this.data.idBox, this.lang);
            }
            if (this.showPro.attr('checked')) {
                jQuery("div.engineproDetails").addClass("on").removeClass("off");
            }
            if(this.data.reserverId !=null && this.data.reserverType !=null && this.data.reserverContract !=null) {
                if ( this.data.reserverType == "SC" && this.origin.subSiteCode != "TRA"){
                    jQuery('input[name="identification.reserverType"]').attr("checked", true);
                    jQuery("div.engineproDetails").addClass("on").removeClass("off");
                    this.rewriteReserverInfos();
                }
            }
				
            if(this.hasAutoCompletion) this.autoComplete = new autoCompletion(this.idEngine, "tSearchDestination", this.origin.siteCode);
        }
    },
	
    failure : function(){
		
    },
	
    implementBooking : function() {
        utils.clearInput.init(this.destination);
			
        // Show map : advanced search engine
        if (this.idEngine == "advancedBookingEngine" && (this.origin.subSiteCode != "BIZ" || this.origin.subSiteCode != "TRA")) {
            if (this.data.showMap == true) {
                this.$currentForm.find(".tDisplayOnMapYes").attr("checked", "true");
            }
            else{
                this.$currentForm.find(".tDisplayOnMapNo").attr("checked", "true");
            }
        }
			
        // APAC & Sudamerica : home engine
        if(this.country && this.city && typeof countryCity != 'undefined'){
            this.rewriteCountryCity();
					
            this.country.bind("change", {
                _this : this
            }, function(e){
                e.data._this.rewriteCountryCity();
                e.data._this.updateField();
            });
					
            this.city.bind("change", {
                _this : this
            }, function(e){
                e.data._this.updateField();
            });

            if (this.localLink){
                this.localLink.bind("click", {
                    _this : this
                }, function(e){
                    var _this = e.data._this;
                    _this.localLink.addClass('hidden');
                    _this.country.removeClass('hidden');
                    _this.city.removeClass('hidden');
                });
            }
        }
			
        // B2B inputs : home engine
        if (this.showPro.length != 0 && this.proReserverId.length != 0 && this.proReserverContract.length != 0) {
            utils.clearInput.init(this.proReserverId);
            utils.clearInput.init(this.proReserverContract);

            this.showPro.bind("click", {
                _this : this
            }, function(e){
                var _this = e.data._this;
                if (_this.showPro.attr('checked')) {
                    jQuery("div.engineproDetails").addClass("on").removeClass("off");
                } else {
                    jQuery("div.engineproDetails").addClass("off").removeClass("on");
                }
            });
				
        }
        if (this.showProAcc.length != 0 && this.proReserverId.length != 0 && this.proReserverContract.length != 0) {
            utils.clearInput.init(this.proReserverId);
            utils.clearInput.init(this.proReserverContract);
				
            this.showProAcc.bind("click", {
                _this : this
            }, function(e){
                var _this = e.data._this;
                if (_this.showProAcc.attr('checked')) {
                    jQuery("div.engineproDetails").addClass("on").removeClass("off");
                    _this.proReserverId.attr("disabled",false);
                    _this.proReserverContract.attr("disabled",false);
                } else {
                    _this.proReserverId.val(_this.proReserverId.attr('title'))
                    _this.proReserverContract.val(_this.proReserverContract.attr('title'));
                    //_this.proReserverId.attr("disabled",true);
                    _this.proReserverContract.attr("disabled",true);
                    jQuery("div.engineproDetails").addClass("off").removeClass("on");
                }
            });
        }

        //Clean disabled
        this.cleanDisabled();
			
        // Fill form
        this.implementInput();
        this.implementForkPrices();
        this.implementAmenities();
			
        //Show roomOptions : home booking engine
        if (this.idEngine == "bookingEngine" && jQuery("div.roomServices ul.tServicesSelect :checked").length !=0 || (this.preferedCode.length != 0 && this.preferedCode.val() !="") || (this.forkPrice.length != 0 && this.forkPrice.val() !="ALL")) {
            jQuery("#"+this.idEngine+" div.roomOptions").addClass("on").removeClass("off");
            jQuery("#"+this.idEngine+" div.moreCriteria .deploy").addClass("undeploy").removeClass("deploy");
        }
			
        //Form action
        this.enterKeyAction();
			
        this.btnSubmit.bind("click", {
            _this : this
        }, function(e){
            e.preventDefault();
            var _this = e.data._this;
            _this.subBooking();
        });
			
        this.$currentForm.find("#advanced-search a, a.lnk-advancedsearch, .advanced-search a").bind("click", {
            _this : this
        }, function(e){
            var _this = e.data._this;
            if (_this.destination.val() == _this.destination.attr('title')) _this.destination.val("");
            if (_this.proReserverId.val() == _this.proReserverId.attr('title')) _this.proReserverId.val("");
            if (_this.proReserverNumber.val() == _this.proReserverNumber.attr('title')) _this.proReserverNumber.val("");
            if (_this.proAccountId.val() == _this.proAccountId.attr('title')) _this.proAccountId.val("");
            if (_this.proAccountContract.val() == _this.proAccountContract.attr('title')) _this.proAccountContract.val("");
            var urlDatas = this.href + "?" + _this.$currentForm.serialize();
            top.document.location.href = urlDatas;
            return false;
        });
			
        //If given, override new search link's url
        if (jQuery("a.lnk-advancedsearch").length != 0 && this.data.altNewSearchUrl != null) {
            jQuery("a.lnk-advancedsearch").attr("href", this.data.altNewSearchUrl);
        }
    },
		
    //template data initialisation
    initDataTemplate : function(){
						
        // Brands template : advanced search engine
        if (this.idEngine == "advancedBookingEngine"){
            if (this.data.brandFilters != null) {
                /**
					 * Réorganisation de brandFilters afin que les marques soient affichées côté front en mode colonne (de haut en bas puis de gauche à droite) et non en mode linéaire (de gauche à droite)
					 */
                var nbCols = 3; /* nombre de colonnes affichées côté front */
					
                /* calcul du nombre total de marques */
                var nbBrands = 0;
                for (var objBrand in this.data.brandFilters) {
                    nbBrands++;
                }
					
                /* calcul dans notre tableau de marques disposées en mode colonne du nombre de lignes complètes (nbRowsGlobal) et du nombre de lignes partielles (nbExtraRows) */
                var nbRowsGlobal = 1;
                var nbExtraRows = 0;
                if (nbBrands > nbCols) {
                    nbRowsGlobal = parseInt(nbBrands / nbCols, 10);
                    nbExtraRows = nbBrands % nbCols;
                }
					
                /* création du tableau de marques disposées en mode colonne (tabColsBrands) */
                var tabColsBrands = new Array();
                var indexCol = indexRow = maxNbRows = 0;
                var nbRowsLocal = false;
                for (var objBrand in this.data.brandFilters) {
                    if (!nbRowsLocal || indexRow == nbRowsLocal) {
                        if (nbRowsLocal != false) {
                            indexCol++;
                        }
                        indexRow = 0;
                        tabColsBrands[indexCol] = new Array();
                        nbRowsLocal = nbRowsGlobal;
                        if (indexCol < nbExtraRows) {
                            nbRowsLocal++;
                        }
                    }
                    tabColsBrands[indexCol][indexRow] = this.data.brandFilters[objBrand];
                    indexRow++;
                    if (maxNbRows < indexRow) {
                        maxNbRows = indexRow;
                    }
                }
					
                /* utilisation du tableau de marques disposées en mode colonne (tabColsBrands) pour parvenir au même genre d'affichage côté front (tabBrandsForTemplate) */
                var tabBrandsForTemplate = new Array();
                for (var indexRow = 0; indexRow < maxNbRows; indexRow++) {
                    for (var indexCol = 0; indexCol < nbCols; indexCol++) {
                        if (typeof tabColsBrands[indexCol] != "undefined" && typeof tabColsBrands[indexCol][indexRow] != "undefined") {
                            tabBrandsForTemplate.push(tabColsBrands[indexCol][indexRow]);
                        }
                    }
                }
                this.tmplBrands.setParam("dataBrand", tabBrandsForTemplate);
            }
            this.tmplBrands.setParam("prefForm",this.prefEngine);
            this.tmplBrands.processTemplate(this.origin);
            this.implementBrands(this.data.brands);
        }
    },
		
    //Rooms Data
    initRoomsDatas : function(){
        //nb adult
        this.fakeAdult.bind("change", {
            _this : this
        }, function(e){
            var _this = e.data._this;
            var $adultNb = _this.fakeAdult.val();
            try {
                // Compatibilité avec les pages migrées en jQuery 1.6.1
                _this.$currentForm.find("div.roomCriteria select:first").find("option:selected").removeProp("selected");
                _this.$currentForm.find("div.roomCriteria select:first").find("option[value="+$adultNb+"]").prop("selected","selected");
            }
            catch (e) {
                // Compatibilité avec les pages toujours en jQuery 1.3.1
                _this.$currentForm.find("div.roomCriteria select:first").find("option:selected").removeAttr("selected");
                _this.$currentForm.find("div.roomCriteria select:first").find("option[value="+$adultNb+"]").attr("selected","selected");
            }
        });
			
        //nb fake children
        this.fakeChild.bind("change", {
            _this : this
        }, function(e){
            var _this = e.data._this;
            _this.$currentForm.find("div.roomCriteria .tChildren:first").find("option[value="+_this.fakeChild.val()+"]").attr("selected", "selected");
            _this.$currentForm.find("div.roomCriteria .tChildren:first").change();
            _this.showRoom(this);
				
            for (var i=0; i < _this.fakeChild.val(); i++) {
                _this.$currentForm.find("select[name$='children["+[i]+"].age']").parents("div.childrensAge").addClass("on").removeClass("off");
                _this.$currentForm.find("select[name$='children["+[i+1]+"].age']").parents("div.childrensAge").addClass("off").removeClass("on");
            }
        });
			
        this.fakeRoom.bind("change", {
            _this : this
        }, function(e){
            var _this = e.data._this;
            _this.tmplRooms.setParam("roomNb", _this.fakeRoom.val());
            _this.tmplRooms.processTemplate(_this.data);
            _this.showRoom(this);
            _this.fakeChild.val(_this.fakeChild.data("initValue"));
            _this.setChildrenObservers();
        });
			
        jQuery(".roomsDetails").find(".lnk-moreoptions").bind("click", {
            _this : this
        }, function(e){
            var link = this;
            var _this = e.data._this;
            var $roomDetails = _this.$currentForm.find(".roomsDetails");
            if(jQuery(this).parent().hasClass("undeploy")){
                $roomDetails.find(".roomsWrapper").slideUp("slow", function(){
                    jQuery(link).parent().addClass("deploy").removeClass("undeploy");
                });
            } else {
                $roomDetails.find(".roomsWrapper").slideDown("slow", function(){
                    jQuery(link).parent().addClass("undeploy").removeClass("deploy");
                });
            }
            return false;
        });
    },
		
    setChildrenObservers : function(){
        //nb children
        this.$currentForm.find("select.tChildren").bind("change", {
            _this : this
        }, function(e){
            var _this = e.data._this;
            if(_this.tmplRooms) {
                _this.tmplRooms.find(".off select").removeAttr("disabled");
            }
            var $childNb = jQuery(this).val();
            var $parentRoom = jQuery(this).parents("div.roomDetails");
		
            if ($childNb == 0) {
                $parentRoom.find(".tChildrensAges").removeClass("on").addClass("off");
                $parentRoom.find("select[name$=age]").parents("div.childrensAge").removeClass("on").addClass("off");
            }
				
            else {
                $parentRoom.find(".tChildrensAges").addClass("on").removeClass("off");
                $parentRoom.find("div.childrensAge").addClass("off").removeClass("on");
                for (var i=0; i<$childNb; i++) {
                    var $sel = $parentRoom.find("select[name$='children["+[i]+"].age']");
                    $sel.parents("div.childrensAge").addClass("on").removeClass("off");
                }
            }
        });
    },
		
    //All input
    implementInput : function(){
        var _this = this;
			
        //Destination
        if (this.data.destination !=null) {
            this.destination.val(this.data.destination);
        }
			
        //Radius
			
        if (this.data.radius && this.data.radius.value !='0') {
            this.radiusVal.find("option[value$="+this.data.radius.value+"]").attr("selected", "selected");
            this.radiusUnit.find("option[value$="+this.data.radius.unit+"]").attr("selected", "selected");
        }
			
        //Rating class
        if (this.data.ratingClass !=null) {
            this.hotelRating.find("option[value$="+this.data.ratingClass+"]").attr("selected", "selected");
        }
			 
        if (this.data.period !=null) {
            var $Date = this.data.period;
            jQuery.each($Date,function () {
                //Date in
                var startDate = new Date($Date.yearIn, $Date.monthIn-1, $Date.dayIn);
                _this.arrivalDate.val(utils.printDate(startDate, i18n.calendar.displayDateFormat));
                _this.arrivalDay.val($Date.dayIn);
                _this.arrivalMonth.val($Date.monthIn);
                _this.arrivalYear.val($Date.yearIn);
                //Date out
                var endDate = new Date($Date.yearOut, $Date.monthOut-1, $Date.dayOut);
                _this.departureDate.val(utils.printDate(endDate, i18n.calendar.displayDateFormat));
                _this.departureDay.val($Date.dayOut);
                _this.departureMonth.val($Date.monthOut);
                _this.departureYear.val($Date.yearOut);
            /*//Night
					$bookingTools.showNight.removeClass('off').addClass('on').find("span .tDuree").empty().append($Date.nbDay);
					$bookingTools.nbNight.val($Date.nbDay);*/
            });
        }
			
        //Rooms number
        if(this.data.bookingEngineRules.maxRoomOccupancy != null) {
            // Room number
            var roomNb = this.data.bookingEngineRules.maxRoomOccupancy.quantity;
            for (var i=0; i < roomNb; i++){
                var oOption = document.createElement('option');
                oOption.value = Number(i+1);
                oOption.innerHTML = Number(i+1);
                if (this.data.roomsCriteria != null && this.data.roomsCriteria.length > 0) {
                    if(this.data.roomsCriteria.length == Number(i+1)) oOption.selected = true;
                }
                else{
                    if(this.data.bookingEngineRules.selectedRoomOccupancy.quantity == Number(i+1)) oOption.selected = true;
                }
                this.fakeRoom.append(oOption);
            }
            this.fakeRoom.hide().show();
 				
            // Adult number
            var fakeAdultNb = this.data.bookingEngineRules.maxRoomOccupancy.adultNumber;
            for (var i=0; i < fakeAdultNb; i++){
                var oOption = document.createElement('option');
                oOption.value = Number(i+1);
                oOption.innerHTML = Number(i+1);
                if (this.data.roomsCriteria != null && this.data.roomsCriteria.length > 0) {
                    if(this.data.roomsCriteria[0].adultNumber == Number(i+1)){
                        oOption.selected = true;
                    }
                }
                else{
                    if(this.data.bookingEngineRules.selectedRoomOccupancy.adultNumber == Number(i+1)){
                        oOption.selected = true;
                    }
                }
                this.fakeAdult.append(oOption);
            }
            this.fakeAdult.hide().show();
            this.fakeAdult.data("initValue", this.fakeAdult.val());
				
            // Child number
            var fakeChildNb = this.data.bookingEngineRules.maxRoomOccupancy.childrenNumber;
            for (var i=0; i < fakeChildNb + 1; i++){
                var oOption = document.createElement('option');
                oOption.value = i;
                oOption.innerHTML = i;
                if (this.data.roomsCriteria != null && this.data.roomsCriteria.length > 0) {
                    if(this.data.roomsCriteria[0].childrenNumber == i) oOption.selected = true;
                }
                else{
                    if(this.data.bookingEngineRules.selectedRoomOccupancy.childrenNumber == Number(i+1)) oOption.selected = true;
                }
                this.fakeChild.append(oOption);
            }
            this.fakeChild.data("initValue", this.fakeChild.val());
            this.fakeChild.hide().show().change();
        }
			
        //FidelityCard
        if (this.data.fidelityCard != null) {
            this.cardCode.val(this.data.fidelityCard.number);
            jQuery("a.aclubPopin").hide();
        }
			
        //PreferredCode
        if (this.data.preferredCode != null) {
            this.preferedCode.val(this.data.preferredCode.code);
        }
        if(this.showPro.length == 0){
            if(this.origin.subSiteCode == "BIZ"){
                if(this.data.reserverType == "SC"){
                    this.rewriteReserverInfos();
                }
            }
            else if(this.origin.subSiteCode == "TRA"){
                if(this.data.reserverType != "SC"){
                    this.rewriteReserverInfos();
                }
            }
            else if(this.origin.accorhotels == true){
                if(this.data.reserverType == "SC"){
                    jQuery("input[name='identification.reserverType']").attr("checked", true);
                    jQuery("div.engineproDetails").addClass("on").removeClass("off");
                    this.rewriteReserverInfos();
                }
            }
				
				
            if(this.data.accountContract!= null) {
                this.proAccountContract.val(this.data.accountContract);
            }
            if(this.data.accountId!= null) {
                this.proAccountId.val(this.data.accountId);
            }
				
            if(jQuery('input[name="identification.account"]').length > 0 && (this.proAccountContract.val() != "" && this.proAccountId.val() != ""))
                jQuery('input[name="identification.account"]').attr("checked", true).parents('.numContrat').find('.text').removeClass('off');
					
            if(jQuery('input[name="identification.reserver"]').length > 0 && this.proReserverContract.val() != "")
                jQuery('input[name="identification.reserver"]').attr("checked", true).parents('.numContrat').find('.text').removeClass('off');
					
        }
    },
		
    rewriteReserverInfos : function(){
        if(this.data.reserverId!= null) {
            this.proReserverId.val(this.data.reserverId);
        }
        if(this.data.reserverContract!= null) {
            this.proReserverContract.val(this.data.reserverContract);
        }
        if(this.data.reserverType!= null){
            if(this.proReserverType.attr("type") == "hidden")
                this.proReserverType.val(this.data.reserverType);
            else if(this.proReserverType.attr("type") == "radio"){		//TRA
                var resType = this.data.reserverType;
                this.proReserverType.each(function(){
                    if(this.value == resType) this.checked = true;
                });
                if(this.data.reserverType == "SC" && this.proReserverId.val() !="" ) {
                    this.proReserverId.val("");

                }
            }
        }
    },
		
    //Forkprice
    implementForkPrices : function(){
        var _this = this;
			
        if(this.forkPrice && this.data.bookingEngineRules.forkPrices != null ){
            jQuery.each(this.data.bookingEngineRules.forkPrices,function (i) {
                var forkBound = this.bound;
                var forkCurrency = this.currency;
                var reg = new RegExp("[ |]+", "g");
                var tabBound = forkBound.split(reg);
                var min = tabBound[0];
                var max = tabBound[1];
                if(_this.CurrenciesViewBean != null){
                    var userCurrency = _this.CurrenciesViewBean.defaultCurrency;
                    if(userCurrency != forkCurrency){
                        min = (min/ (_this.CurrenciesViewBean.currencies[userCurrency] / _this.CurrenciesViewBean.currencies[forkCurrency])).toFixed(2);
                        min = Math.round(Number(min));
                        min = Math.floor((min+5)/10)*10;
                        max = (max/ (_this.CurrenciesViewBean.currencies[userCurrency] / _this.CurrenciesViewBean.currencies[forkCurrency])).toFixed(2);
                        max = Math.round(Number(max));
                        max = Math.floor((max+5)/10)*10;
                        forkCurrency = userCurrency;
                    }
                }
                if(min==0 &&  max>0){
                    _this.forkPrice.append('<option value="'+forkBound+'">&nbsp;<&nbsp;'+max+'&nbsp;'+forkCurrency+'</option>')
                }
                else if(min>0 && max>0){
                    _this.forkPrice.append('<option value="'+forkBound+'">&nbsp;'+min+'&nbsp;-&nbsp;'+max+'&nbsp;'+forkCurrency+'</option>')
                }
                else if(min>0 && max==0){
                    _this.forkPrice.append('<option value="'+forkBound+'">&nbsp;>&nbsp;'+min+'&nbsp;'+forkCurrency+'</option>')
                }
                _this.forkCurrency.val(forkCurrency);
                _this.forkPrice.change(function(){
                    var currentBound = _this.forkPrice.find('option:selected').val();
                });
            });
        }
        if(this.forkPrice && this.data.forkPrice != null){
            //this.forkPrice.find("option[value$='"+this.data.forkPrice.bound+"']").attr("selected", 'selected'); //=> bug IE6
            var selectedItem = this.forkPrice.find("option[value$='"+this.data.forkPrice.bound+"']").get(0);
            if(selectedItem) selectedItem.setAttribute('selected',true);
            this.forkCurrency.val(this.data.forkPrice.currency);
        }
    },
		
    //Brands
    implementBrands : function(brand){
        var $iptYes = this.$currentForm.find(".tFilterBrandsYes");
        var $iptNo = this.$currentForm.find(".tFilterBrandsNo");
        var $allBrands = this.$currentForm.find(".allBrands");
        var $brandsSelect = this.$currentForm.find(".brandsSelect");
        if (brand != null) {

            var $BrandsTools = brand ;
            var reg = new RegExp("[ |]+", "g");
            var Brandlist = $BrandsTools.split(reg);
            for (var i=0; i < Brandlist.length; i++) {
                if ($brandsSelect.length > 0) {
                    //cas ALL select
                    if(Brandlist[0]=="ALL"){
                        $iptYes.attr("checked", "checked");
                    }
                    else {
                        $allBrands.slideDown("slow");
                        $iptYes.removeAttr("checked");
                        $iptNo.attr("checked", "checked");
                        $iptNo.parent().parent().prev().addClass("on");
                        this.$currentForm.find("input[value="+Brandlist[i]+"]").attr("checked", "checked");
                    }
                }
                else {
                    this.$currentForm.find('input[name="filter.brands"]').empty().val(this.data.brands);
                }
            }
        }
        //Brands concatenation
        if ($brandsSelect.length > 0) {
            $iptYes.bind("click", {
                _this : this
            }, function(e){
                $iptYes.attr("checked", "checked");
                $iptNo.removeAttr("checked");
                $allBrands.slideUp("slow");//listener open brands
                $iptYes.parent().parent().prev().removeClass("on");
                e.data._this.$currentForm.find('input[name="filter.brands"]').val("ALL")
            });
				
            $iptNo.bind("click", {
                _this : this
            }, function(e){
                $iptNo.attr("checked", "checked");
                $iptYes.removeAttr("checked");
                $allBrands.slideDown("slow");//listener hide brands
                $iptNo.parent().parent().prev().addClass("on");
                e.data._this.concBrands();
                e.data._this.$currentForm.find(".brandsSelect input").click(function(){
                    e.data._this.concBrands();
                });
            });
				
            //this.$currentForm.find('.brandsSelect input').click(function(){ _this.concBrands();});
            if (this.$currentForm.find("ul.allBrands input:checked").length = this.$currentForm.find(".allBrands :input").length){
                this.$currentForm.find('input[name="filter.brands"]').val("ALL");
            }
        }
    },
		
    //Concatenation brands
    concBrands : function() {
        var inputVal = "";
        this.$currentForm.find(".allBrands input:checked").each(function(i){
            if(i==0){
                inputVal = (this).value;
            }
            else{
                inputVal += "|"+(this).value;
            }
        });
        //this.$currentForm.find('input[name="filter.brands"]').val(inputVal);
        if(inputVal != "") this.$currentForm.find('input[name="filter.brands"]').val(inputVal);
    },
		
    //Dynamise amnenities
    dynAmnenities : function(src,list,name){
        var _this = this;
        jQuery.each(src,function (i) {
            var j = this.code;
            var k = this.label;
            if (this.selected && this.selected==true) {
                var l = "checked";
            } else var l = "";
            list.append('<li><input type="checkbox" id="filter-'+name+'-'+j+'-'+_this.prefEngine+'" name="filter.'+name+'['+i+']" value="'+j+'" '+l+'  /><label for="filter-'+name+'-'+j+'-'+_this.prefEngine+'">'+k+'</label></li>');
        });
    },
		
    //Amenities
    implementAmenities : function(){
        //advanced engine
        if (this.idEngine == "advancedBookingEngine"){
            var $AdvancedSearchAmenities = {
                activities : this.data.advancedSearchActivities,
                services : this.data.advancedSearchServices
            }
            //console.log($AdvancedSearchAmenities.activities);
            //console.log($AdvancedSearchAmenities.activities[0]);
            // advanced services
            if (this.advServicesOption) {
                this.dynAmnenities($AdvancedSearchAmenities.services,this.advServicesOption,'services');
            }
            // advanced leasure
            if (this.advLeasureOption && $AdvancedSearchAmenities.activities[0]!=undefined ) {
                this.dynAmnenities($AdvancedSearchAmenities.activities,this.advLeasureOption,'activities');
            }
            //disable leisure box if no leisure
            else {
                jQuery('.leisure').parent('.containerMoreOptions').hide();
            }
        }
        //other engine
        if (this.servicesOption) {
            var $HomeAmenities = {
                activities : this.data.homeActivities,
                services : this.data.homeServices
            }
            //services
            this.dynAmnenities($HomeAmenities.services,this.servicesOption,'services');
            //leasure
            this.dynAmnenities($HomeAmenities.activities,this.servicesOption,'activities');
        }
    },
		
    //Enter submit
    enterKeyAction : function() {
	
        this.$currentForm.bind("keyup", {
            _this : this
        }, function(event){
            var _this = event.data._this;
            if (event.keyCode == 13) {
                //disable auto submit when key return has been made on the auto complete drop down list
                if (_this.hasAutoCompletion == true) {
                    if (_this.autoComplete.isKeyReturnInResults() == false) {
                        _this.subBooking();
                    }else _this.hasAutoCompletion = false;
                } else {
                    _this.subBooking();
                }
            }
        });
    },
		
    //Submit Booking
    subBooking : function() {
        // Clear errors
        //this.destination.parent().removeClass('validatorInvalidState');
        //this.departureDate.parent().removeClass('validatorInvalidState');
        this.$currentForm.find(".validatorInvalidState").removeClass("validatorInvalidState");
        this.concBrands();
        if (this.showPro.length != 0 && this.proReserverId.length != 0 && this.proReserverContract.length != 0) {
            this.showPro.parent().removeClass('validatorInvalidState');
            this.proReserverId.parent().removeClass('validatorInvalidState');
            this.proReserverContract.parent().removeClass('validatorInvalidState');
        }
			
        this.destination.parents('form').find('.errorMessage').hide();
		
        var isB2B = false;
        var isMarq = true;
        // Destination check
        if (this.destination.val() == ''|| this.destination.val() == this.destination[0].title) {
            this.destination.parent().addClass('validatorInvalidState');
            this.destination.parents('form').find('.errorMessage').show().text(i18n.destination.error);
            return false;
        }
        // Dates check
        else if(this.arrivalDate.val() != "" && this.departureDate.val() == ""){
            this.departureDate.parent().addClass('validatorInvalidState');
            this.arrivalDate.parents('form').find('.errorMessage').show().text(i18n.calendar.error);
            return false;
        }
			
        else if(this.origin.subSiteCode == "BIZ"){
            isMarq = false;
            isB2B = false;
            if(this.proReserverId.val() == this.proReserverId[0].title && this.proReserverContract.val() == this.proReserverContract[0].title){
                this.proReserverId.val("")
                this.proReserverContract.val("");
                this.proReserverType.val("");
                this.showPro.val("");
            }
            else{
                if (this.proReserverId.val() == '' || this.proReserverId.val() == this.proReserverId[0].title) {
                    this.proReserverId.val("");
                    this.showPro.val("");
                }
					
                if (this.proReserverContract.val() == '' || this.proReserverContract.val() == this.proReserverContract[0].title) {
                    this.proReserverContract.val("");
                    this.showPro.val("");
                }
            }
        }
        else if(this.origin.subSiteCode == "TRA" || window.location.hostname =="travelagencies.accorhotels.com"){
            isMarq = false;
            if(this.proReserverId.val() == this.proReserverId[0].title){
                this.proReserverId.val("");
            }
				
				
            if(this.$currentForm.hasClass("advancedbookingEngineStar") || this.idEngine == "bookingEngineStar"){
                if(this.proAccountId.val() == this.proAccountId[0].title){
                    this.proAccountId.val("");
                }
                if(this.proAccountContract.val() == this.proAccountContract[0].title){
                    this.proAccountContract.val("");
                }
            }
        }
			
			

        else if (this.showProAcc.length != 0   && this.proReserverId.length != 0 && this.proReserverContract.length != 0) {
            if (this.showPro.attr('checked') ||this.showProAcc.attr('checked') ) {
                if ((this.proReserverId.val() == '' || this.proReserverId.val() == this.proReserverId[0].title) || (this.proReserverContract.val() == '' || this.proReserverContract.val() == this.proReserverContract[0].title)) {
                    this.showPro.parent().addClass('validatorInvalidState');
                    this.proReserverId.parent().addClass('validatorInvalidState');
                    this.proReserverContract.parent().addClass('validatorInvalidState');
                    this.arrivalDate.parents('form').find('.errorMessage').show().text(i18n.b2b.error);
                    return false;
                }
					
                if(this.arrivalDate.val() == "" && this.departureDate.val() == ""){
                    this.arrivalDate.parent().addClass('validatorInvalidState');
                    this.departureDate.parent().addClass('validatorInvalidState');
                    this.arrivalDate.parents('form').find('.errorMessage').show().text(i18n.b2b.errorCal);
                    return false;
                }
                else if(this.arrivalDate.val() == ""){
                    this.arrivalDate.parent().addClass('validatorInvalidState');
                    this.arrivalDate.parents('form').find('.errorMessage').show().text(i18n.b2b.errorCal);
                    return false;
                }
                else if(this.departureDate.val() == ""){
                    this.departureDate.parent().addClass('validatorInvalidState');
                    this.departureDate.parents('form').find('.errorMessage').show().text(i18n.b2b.errorCal);
                    return false;
                }
            //isB2B = true;
					
					
            } else {					//disable B2B inputs if B2B checkbox is not activated
                this.proReserverId.attr("disabled","true");
                this.proReserverContract.attr("disabled","true");
                this.showProAcc.attr("disabled","true");
            }
        }
			
			
			
	
        //carte fid + date
        //disabled fake & off rooms information
        if(this.fakeAdult) {
            this.fakeAdult.attr("disabled","true");
        }
        if(this.fakeChild) {
            this.fakeChild.attr("disabled","true");
        }
        if(this.tmplRooms) {
            this.tmplRooms.find(".off select").attr("disabled","true");
        }
        //disabled brands inputs
        if(this.listBrands) {
            this.listBrands.attr("disabled","true");
        }
			
        //update currency value in input field
        if(jQuery("#selectCurrency").length > 0)
            this.$currentForm.find("#search-currency-code").val(jQuery("#selectCurrency").val());
        else
            this.$currentForm.find("#search-currency-code").attr("disabled", true);
				
        //remove brand string detected when using auto complete
        //if (jQuery('body#home').length || jQuery('body#advanced-search').length || this.idEngine == "advancedBookingEngineBus") {

        if(this.autoComplete){
            //if(this.hasAutoCompletion && this.hasAutoCompletion == true){
            this.destination.val(this.autoComplete.filterBrandStrDetected(this.destination.val()));
        }
			
        //execute ajaxrequest
        if(ajaxRequest.retry != this.$currentForm.attr("action")) {
            this.startSubmitInProgressEffect();
        }
			
        if (isMarq && this.proReserverId.val() && this.proReserverId.val() != this.proReserverId[0].title && this.origin.accorhotels == false) {
            // If B2B checkbox is activated, send POST form data to accorhotels's website (ex business)
            utils.initExternalHotelAlertHome("#compBrandHotelPopinButtons, #tExternalHotelMsgBrand", this,'http://www.accorhotels.com/identification/identify.action?identification.reserverType=SC&lang='+this.lang);
            this.stopSubmitInProgressEffect();
        }
        else if(isB2B){
            this.$currentForm.attr("action","http://www.accorhotels.com/identification/identify.action?identification.reserverType=SC&lang="+this.lang);
            this.defaultPostSubmit = true;
            this.$currentForm.submit();
					
        }else {
            //this.$currentForm.attr("action", "http://businesstravel.accorhotels.com/identification/identify.action?identification.reserverType=SC");
            ajaxRequest._executeByForm(this.idEngine,
                "errorMessage",
                "validatorInvalidState",
                this.givenName + ".answerBooking(errors,response)"
                );

        }
			
        return false;
    },
		
    answerBooking :  function(errors, json){
        this.stopSubmitInProgressEffect();
        if(errors && errors.length > 0){
            ajaxRequest.showErrors(errors, "errorMessage",this.idEngine);
				
            //enabled fake & off rooms information
            if(this.fakeAdult) {
                this.fakeAdult.attr("disabled",false);
            }
            if(this.fakeChild) {
                this.fakeChild.attr("disabled",false);
            }
            if(this.tmplRooms) {
                this.tmplRooms.find(".off select").attr("disabled",false);
            }
            if(this.proReserverId) {
                this.proReserverId.attr("disabled",false);
            }
            if(this.proReserverContract) {
                this.proReserverContract.attr("disabled",false);
            }
            if(this.showProAcc){
            	this.showProAcc.attr("disabled",false);
            }
				
            if(this.origin.subSiteCode == "BIZ"){
                if(this.proReserverId.val() == '') this.proReserverId.val(this.proReserverId[0].title)
                if(this.proReserverContract.val() == '') this.proReserverContract.val(this.proReserverContract[0].title);
                if(this.proReserverType.val() == '') this.proReserverType.val("SC");
                ajaxRequest.showErrorFields(json.fieldErrors, "validatorInvalidState", this.idEngine);
            }
            else if(this.origin.subSiteCode == "TRA"){
                if(this.proReserverId.val() == ''){
                    this.proReserverId.val(this.proReserverId[0].title)	;
                }
                if(this.proAccountId.val() == ''){
                    this.proAccountId.val(this.proAccountId[0].title)	;
                }
                if(this.proAccountContract.val() == ''){
                    this.proAccountContract.val(this.proAccountContract[0].title)	;
                }
                if(!utils.isEmpty(json.fieldErrors))ajaxRequest.showErrorFields(json.fieldErrors, "validatorInvalidState", this.idEngine);
            }
        }
    },
		
    //clean disabled
    cleanDisabled : function(){
        this.$currentForm.find(':disabled').removeAttr('disabled');
    },
		
    //Démarrage de l'effet "loader" lors de l'appel Ajax
    startSubmitInProgressEffect : function() {
        this.btnSubmit.wrap('<div class="submitInProgress" />');
        var btnSubmitWidth = this.btnSubmit.width();
        var loaderWidth = 16;
        var loaderMarginLeft = (btnSubmitWidth / 2) - (loaderWidth / 2);
        this.btnSubmit.prepend('<div class="loader" style="margin-left:'+loaderMarginLeft+'px"></div>');
    },
		
    //Arrêt de l'effet "loader" lors du retour Ajax
    stopSubmitInProgressEffect : function() {
        this.btnSubmit.find('.loader').remove();
        this.btnSubmit.parent().replaceWith(this.btnSubmit);
    },
		
    //APAC & subamerica : rewrite countries
    rewriteCountryCity: function(){
        var countrySelect = this.country;
        var citySelect = this.city;
			
        var index=1;
        if (countrySelect.val()) {
            citySelect.html("");
            citySelect.append("<option value=''>"+selectCity+"</option>");
            if(countryCity[countrySelect.val()].cities.length>0) {
                for(var j=0;j<countryCity[countrySelect.val()].cities.length; j++){
                    var city = countryCity[countrySelect.val()].cities[j];
                    citySelect.append("<option value=\""+city+"\">"+city+"</option>");
                    index++;
                }
            }
            else {
                citySelect.append("<option value=''>"+selectNo+"</option>");
            }
        }
        else {
            citySelect.html("");
            citySelect.append("<option value=''>"+selectCity+"</option>");
            countrySelect.append("<option value=''>"+selectCountry+"</option>");
            jQuery.each(countryCity, function(i) {
                countrySelect.append("<option value=\""+i+"\">"+i+"</option>");
            });
        }
    },
	    
    //APAC & subamerica : update search destination field
    updateField : function(fieldToUpdate, countriesSelect, citiesSelect){
        if(this.destination && this.country && this.city){
            if(this.country.val()!='') {
                this.destination.val(this.country.val());
            }
            if(this.city.val()!=''){
                this.destination.val(this.city.val()+', '+this.country.val());
            }
            if(this.geoType) {
                this.geoType.val('');
            }
            if(this.geoCode) {
                this.geoCode.val('');
            }
        }
    },
    
    deserializeFormDatas: function($formObj){
        var formElements = document.getElementById($formObj.attr('id')).elements;
        if(utils.getUrlParameter("filter.brands")!="ALL" &&utils.getUrlParameter("filter.brands")!=""){
            this.implementBrands(utils.getUrlParameter("filter.brands"));
        }
			
	
        if(utils.getUrlParameter("identification.accountId") && utils.getUrlParameter("identification.accountContract")){
				
            jQuery('input[name="identification.account"]').attr("checked", true);
            jQuery("div.engineproDetails").addClass("on").removeClass("off");
            jQuery('.numContrat').find('.text').removeClass('off');
            var reserver = jQuery('input[name="identification.reserver"]');
            if(this.searchType!=1){
                numContrat.hideField(reserver); //fonction de adv-search tra
            }
        }
        if(utils.getUrlParameter("identification.reserverContract")){
            jQuery('input[name="identification.reserver"]').attr("checked", true);
            jQuery('input[name="identification.reserverType"]').attr("checked", true);
            jQuery('.numContrat').find('.text').removeClass('off');
            jQuery("div.engineproDetails").addClass("on").removeClass("off");
            var account = jQuery('input[name="identification.account"]');
            if(this.searchType!=1){
                numContrat.hideField(account);
            }
				
        }
        if(utils.getUrlParameter("search.dateIn")=="" &&utils.getUrlParameter("search.dayIn")!=""&&utils.getUrlParameter("search.monthIn")!=""&&utils.getUrlParameter("search.yearIn")!=""){

            var dateIn = new Date(utils.getUrlParameter("search.yearIn"), utils.getUrlParameter("search.monthIn")-1, utils.getUrlParameter("search.dayIn"), 12, 0, 0);
            this.arrivalDate.val(utils.printDate(dateIn, i18n.calendar.displayDateFormat));
				
            if(utils.getUrlParameter("search.nightNb")){
                var dateOut = new Date();
                dateOut.setTime(dateIn.getTime()+3600*24*1000*utils.getUrlParameter("search.nightNb"));
                this.departureDay.val(dateOut.getDate());
                this.departureMonth.val(dateOut.getMonth()+1);
                this.departureYear.val(dateOut.getFullYear());
                this.departureDate.val(utils.printDate(dateOut, i18n.calendar.displayDateFormat));
					
            }

        }
			
			
        for(var i=0; i<formElements.length; i++){
			
            var formElement = formElements[i];
					
																							   
            if(formElement.name && utils.getUrlParameter(formElement.name)!="" && formElement.type!="checkbox"){
                if(formElement.type=="text" || formElement.type=="textarea" || formElement.type=="hidden"){
                    formElement.value = utils.decode(utils.getUrlParameter(formElement.name));
                }	else if(formElement.type=="radio" && formElement.value == utils.getUrlParameter(formElement.name)){
                    formElement.checked = true;
                } else if(formElement.type=="select-one"){
						
                    if(typeof document.body.style.maxHeight === "undefined" && formElement.name =="filter.forkPrice.bound" ) {//if IE6
                        saveElem = formElement;
                        saveValue = utils.decode(utils.getUrlParameter(formElement.name));
                        this.HP = true;
                    }
						
                    formElement.value = utils.decode(utils.getUrlParameter(formElement.name));
                }
            }
            else{
                if(formElement.type=="checkbox" && formElement.name){
                    if(jQuery.inArray(formElement.value, utils.getMultipleUrlParameter(formElement.name)) != -1)
                        formElement.checked = true;
                }
            }
        }
			
        /** Traitement dans le cas où l'on se trouve sur la page de recherche avancée */
        if (jQuery("body#advanced-search, div#advanced-search").length > 0) {
            try{
                this.fakeRoom.val(utils.getUrlParameter(this.fakeRoom.attr('name')));
                this.fakeRoom.change();
                this.rewriteChildInfoFromDeserialization();
            }
            catch(e){ // pour IE6
                setTimeout(this.givenName+".fakeRoom.val(utils.getUrlParameter("+this.givenName+".fakeRoom.attr('name')));"+ this.givenName +".fakeRoom.change();" + this.givenName +".rewriteChildInfoFromDeserialization();", 100);
					
                if(this.HP) setTimeout("utils.getRateIe6(saveElem, saveValue);",100);
            }
        }
    },
		
    rewriteChildInfoFromDeserialization : function(){
        this.tmplRooms.find(".roomDetails .roomResidentType:not('.tChildrensAges') select").each(function(i, select){
            var $sel = jQuery(select);
            if(utils.getUrlParameter($sel.attr('name')) != ""){
                $sel.val(utils.decode(utils.getUrlParameter($sel.attr('name'))));
                if($sel.hasClass('tChildren') /*&& $sel.val() != 0*/){
                    $sel.change();
                }
            }
        });
        this.tmplRooms.find(".roomDetails .tChildrensAges:not('.off') .childrensAge:not('.off')  select").each(function(i, select){
            var $sel = jQuery(select);
            if(utils.getUrlParameter($sel.attr('name')) != ""){
                $sel.val(utils.decode(utils.getUrlParameter($sel.attr('name'))));
            }
        });
    },
		
    initBookingEngineToggler : function(){
        /* Initialisation de l'état fermé du div */
        var toggler = false;
        /* Ecouteur du lien plus de critère */
        this.btnCriteria.bind("click", {
            _this : this
        }, function(e){
            if(jQuery(this).parent().hasClass('undeploy')){
                toggler = true;
            }
            var _this = e.data._this;
            if(toggler == true){
                _this.roomOptions.slideUp("slow", function(){
                    jQuery(this).addClass("off").removeClass("on");
                    toggler = false;
                });
                /* Gestion du changement de la puce +/- */
                jQuery(this).parent().addClass("deploy").removeClass("undeploy");
                return false;
            } else {
                _this.roomOptions.slideDown("slow", function(){
                    jQuery(this).addClass("on").removeClass("off");
                    toggler = true;
                });
                /* Gestion du changement de la puce +/- */
                jQuery(this).parent().addClass("undeploy").removeClass("deploy");
                return false;
            }
        });
    },
		  
    /* Gestion d'affichage du bloc "Chambres" */
    showRoom : function(e){
        var $evtSelect = jQuery(e);
        var $fieldset = jQuery(e).parents('fieldset');
        var $roomDetails = this.$currentForm.find(".roomsDetails");
			
        if(this.fakeRoom.val() > 1 || this.fakeChild.val() > 0){
            $roomDetails.slideDown("slow", function(){
                jQuery(this).addClass("on").removeClass("off");
            });
            this.fakeAdult.val(this.fakeAdult.data("initValue"));
            //this.fakeChild.val(this.fakeChild.data("initValue"));
            $fieldset.find('.adults').hide();
            $fieldset.find('.childrens').hide();
				 
        }
        else {
            $roomDetails.slideUp("slow", function(){
                jQuery(this).addClass("off").removeClass("on");
            });
            $fieldset.find('.adults').show();
            //keep hidden children's combo if no children policy
            if (!$fieldset.hasClass('tNoChipol')) {
                $fieldset.find('.childrens').show();
            }
        }
    },
			
    /* Gestion Enfants depuis les fake select */
    showChildrens : function(e){
        if(jQuery(e).val() > 0){
            this.$currentForm.find(".tChildrensAges").addClass("on").removeClass("off");
        }
        else{
            this.$currentForm.find(".tChildrensAges").addClass("off").removeClass("on");
        }
    },
			
    /* Gestion Enfants depuis les rooms criteria */
    showChildrensRooms : function(e){
        if(jQuery(e).val() > 0){
            this.$currentForm.find(".roomsDetails").find(".tChildrensAges").addClass("on").removeClass("off");
        }
        else{
            this.$currentForm.find(".roomsDetails").find(".tChildrensAges").addClass("off").removeClass("on");
        }
    }
}
/** < /scripts-v66/booking/common/booking-engine.js **/
