
function HOTS(){
    this.alreadySubmited=false;
    this.initialisation=0;
    this.divTabsCmp=null;
    this.divCASearchUnderPop=null;
    this.hotelSearchType=null;
    this.curCountry="";
    this.curCity="";
    this.curDistance="";
    this.divNightsCmp=null;
    this.maxAllowedNights=100;
    this.visibilityType=["hidden","visible"];
    this.displayType=["none","block"];
    this.show=1;
    this.hide=0;
    this.popDestSearchId="pop_dest_search";
    this.pDest=new Array;
    this.currentPopDestSelected=null;
    this.currentRefineMode=0;
    this.viewOptionsLabel="";
    this.closeOptionsLabel="";
    this.refineYourSearchCmp=null;
    this.tabPrices=null;
    this.pageOnLoad=HOTS_pageOnLoad;
    this.check=HOTS_check;
    this.preCheck=HOTS_preCheck;
    this.applyStyle=HOTS_applyStyle;
    this.refreshNights=HOTS_refreshNights;
    this.force3Facilities=HOTS_force3Facilities;
    this.getNbNights=HOTS_getNbNights;
    this.popInit=HOTS_popInit;
    this.testPopDestEqCityAirportField=HOTS_testPopDestEqCityAirportField;
    this.setValue=HOTS_setValue;
    this.refineYourSearch=HOTS_refineYourSearch;
    this.getParamsToString=HOTS_getParamsToString;
    this.setErrMsg106=HOTS_setErrMsg106;
    this.displayPanel=HOTS_displayPanel;
}

var HOTS=new HOTS();
function HOTS_check(){
    if(HOTS.alreadySubmited){
    }else{
	HOTS.alreadySubmited=true;
	WDSError.init();
	this.preCheck();
	if(WDSError.hasError()){
	    WDSError.show();
	    HOTS.alreadySubmited=false;
	}else{
	    document.HOTSForm.submit();
	    WDSWaitingImage.pleaseWait("wait");
	}
    }
}

function HOTS_preCheck(){
    var checkInDate=HOTSDateList.getDateTimeComposed(HOTSDateList.grpStart);
    var checkOutDate=HOTSDateList.getDateTimeComposed(HOTSDateList.grpEnd);
    if(checkInDate.getTime()>=checkOutDate.getTime()){
	WDSError.add(WDSMessage.getMessage(105),document.HOTSForm.B_DATE);
    }else{
	var DisplayErr=false;
	if(this.maxAllowedNights.substr(0,1)=='D'){
	    DisplayErr=(this.getNbNights(checkInDate,checkOutDate)>this.maxAllowedNights.substr(1));
	}else if(this.maxAllowedNights.substr(0,1)=='W'){
	    DisplayErr=(this.getNbNights(checkInDate,checkOutDate)>7*this.maxAllowedNights.substr(1));
	}else if(this.maxAllowedNights.substr(0,1)=='M'){
	    var currentDat=checkInDate;
	    var nbMonths=0;
	    while(currentDat.getMonth()!=checkOutDate.getMonth()||currentDat.getYear()!=checkOutDate.getYear()){
		currentDat.setMonth(currentDat.getMonth()+1);
		nbMonths++;
	    }
	    if(currentDat.getDate()<checkOutDate.getDate()){
		nbMonths++;
	    }
	    DisplayErr=(nbMonths>this.maxAllowedNights.substr(1));
	}
	if(DisplayErr){
	    WDSError.add(WDSMessage.getMessage(106),document.HOTSForm.B_DATE);
	}
	var datStart=HOTSDateList.getDateTimeComposedString(HOTSDateList.grpStart);
	WDSCommon.updateTag(document.HOTSForm,"B_DATE",datStart);
	WDSCommon.updateTag(document.HOTSForm,"backB_DATE",datStart);
	var datEnd=HOTSDateList.getDateTimeComposedString(HOTSDateList.grpEnd);
	WDSCommon.updateTag(document.HOTSForm,"E_DATE",datEnd);
	WDSCommon.updateTag(document.HOTSForm,"backE_DATE",datEnd);
    }
    document.getElementById("backTab").value=this.divTabsCmp.id;
    document.getElementById("backCountry").value=this.curCountry;
    document.getElementById("backCity").value=this.curCity;
    document.getElementById("backDistance").value=this.curDistance;
    document.getElementById("backRefineMode").value=this.currentRefineMode;
    if(this.currentRefineMode==0){
	for(var i=0;i<document.refineSearchForm.LIST_COMPANY.length;i++){
	    if(document.refineSearchForm.LIST_COMPANY[i]){
		WDSCommon.updateTag(document.refineSearchForm,"LIST_COMPANY["+i+"]","");
	    }
	}
	WDSCommon.updateTag(document.refineSearchForm,"LIST_HOTEL_NAME","");
	WDSCommon.updateTag(document.refineSearchForm,"COMMON_BUDGET","");
	if(document.refineSearchForm.LIST_FACILITY){
	    for(var i=0;i<document.refineSearchForm.LIST_FACILITY.length;i++){
		checkBoxCmp=document.refineSearchForm.LIST_FACILITY[i];
		if(checkBoxCmp){
		    checkBoxCmp.checked=false;
		}
	    }
	}
    }else{
	if(document.refineSearchForm.COMMON_BUDGET){
	    var commonBudget=WDSCommon.getTagValue(document.refineSearchForm.COMMON_BUDGET);
	    if(commonBudget!=""){
		if(document.refineSearchForm.COMMON_BUDGET.tagName.toLowerCase()=="select"){
		    var lastPrice=this.tabPrices[this.tabPrices.length-1];
		    if(commonBudget==lastPrice){
			WDSCommon.updateTag(document.HOTSForm,"MIN_BUDGET",commonBudget);
		    }else{
			WDSCommon.updateTag(document.HOTSForm,"MAX_BUDGET",commonBudget);
		    }
		}else{
		    var otherThanNumeric=false;
		    var numericList="0123456789";
		    for(var i=0;i<commonBudget.length;i++){
			var car=commonBudget.substr(i,1);
			if(numericList.indexOf(car)==-1){
			    otherThanNumeric=true;
			}
		    }
		    if(otherThanNumeric){
			WDSError.add(WDSMessage.getMessage(122),document.refineSearchForm.COMMON_BUDGET);
		    }else{
			WDSCommon.updateTag(document.HOTSForm,"MAX_BUDGET",commonBudget);
		    }
		}
	    }
	}
    }
    var hotTabParams="";
    hotTabParams+="|Tab="+this.divTabsCmp.id;
    hotTabParams+="|RefineYourSearch="+this.currentRefineMode;
    if(this.divTabsCmp.id=="city"){
	if(this.currentPopDestSelected!=null){
	    WDSCommon.updateTag(document.HOTSForm,"B_LOCATION",this.currentPopDestSelected[1]);
	    WDSCommon.updateTag(document.HOTSForm,"COUNTRY_CODE",this.currentPopDestSelected[3]);
	    WDSCommon.updateTag(document.HOTSForm,"AREA",this.currentPopDestSelected[2]);
	}else{
	    if(document.CityHOTSForm){
		var CityBLocation=WDSCommon.getTagValue(document.CityHOTSForm.CityBLocation);
		if(CityBLocation.length>0){
		    WDSCommon.updateTag(document.HOTSForm,"B_LOCATION",CityBLocation);
		}else{
		    WDSError.add(WDSMessage.getMessage(134),document.CityHOTSForm.CityBLocation);
		}
		var CityCountryCode=WDSCommon.getTagValue(document.CityHOTSForm.CityCountryCode);
		if(CityCountryCode.length>0){
		    WDSCommon.updateTag(document.HOTSForm,"COUNTRY_CODE",CityCountryCode);
		}else{
		    WDSError.add(WDSMessage.getMessage(135),document.CityHOTSForm.CityCountryCode);
		}
		var CityRadioCityOrAirport=WDSCommon.getTagValue(document.CityHOTSForm.CityRadioCityOrAirport);
		WDSCommon.updateTag(document.HOTSForm,"AREA",CityRadioCityOrAirport);
	    }else{
		WDSError.add(WDSMessage.getMessage(136));
	    }
	}
	WDSCommon.updateTag(document.HOTSForm,"DISTANCE_VALUE","");
	hotTabParams+=this.getParamsToString("document.CityPopularHOTSForm","radioPopular");
	hotTabParams+=this.getParamsToString("document.CityHOTSForm","CityBLocation|CityCountryCode|CityRadioCityOrAirport");
    }else if(this.divTabsCmp.id=="landmark"){
	var LandmarkLandmark=WDSCommon.getTagValue(document.LandmarkHOTSForm.LandmarkLandmark);
	if(LandmarkLandmark.length>0){
	    WDSCommon.updateTag(document.HOTSForm,"POI_NAME",LandmarkLandmark);
	}else{
	    WDSError.add(WDSMessage.getMessage(137),document.LandmarkHOTSForm.LandmarkLandmark);
	}
	var LandmarkCity=WDSCommon.getTagValue(document.LandmarkHOTSForm.LandmarkCity);
	WDSCommon.updateTag(document.HOTSForm,"B_LOCATION",LandmarkCity);
	var LandmarkCountryCode=WDSCommon.getTagValue(document.LandmarkHOTSForm.LandmarkCountryCode);
	if(LandmarkCountryCode.length>0){
	    WDSCommon.updateTag(document.HOTSForm,"COUNTRY_CODE",LandmarkCountryCode);
	}else{
	    WDSError.add(WDSMessage.getMessage(135),document.LandmarkHOTSForm.LandmarkCountryCode);
	}
	var LandmarkDistance=WDSCommon.getTagValue(document.LandmarkHOTSForm.LandmarkDistance);
	WDSCommon.updateTag(document.HOTSForm,"DISTANCE_VALUE",LandmarkDistance);
	hotTabParams+=this.getParamsToString("document.LandmarkHOTSForm","LandmarkLandmark|LandmarkCity|LandmarkCountryCode|LandmarkDistance");
    }else{
	var AddressStreet=WDSCommon.getTagValue(document.AddressHOTSForm.AddressStreet);
	if(AddressStreet.length>0){
	    WDSCommon.updateTag(document.HOTSForm,"STREET_ADDRESS",AddressStreet);
	}else{
	    WDSError.add(WDSMessage.getMessage(138),document.AddressHOTSForm.AddressStreet);
	}
	var AddressCity=WDSCommon.getTagValue(document.AddressHOTSForm.AddressCity);
	if(AddressCity.length>0){
	    WDSCommon.updateTag(document.HOTSForm,"B_LOCATION",AddressCity);
	}else{
	    WDSError.add(WDSMessage.getMessage(139),document.AddressHOTSForm.AddressCity);
	}
	var AddressCountryCode=WDSCommon.getTagValue(document.AddressHOTSForm.AddressCountryCode);
	if(AddressCountryCode.length>0){
	    WDSCommon.updateTag(document.HOTSForm,"COUNTRY_CODE",AddressCountryCode);
	}else{
	    WDSError.add(WDSMessage.getMessage(135),document.AddressHOTSForm.AddressCountryCode);
	}
	var AddressState=WDSCommon.getTagValue(document.AddressHOTSForm.AddressState);
	WDSCommon.updateTag(document.HOTSForm,"STATE_CODE",AddressState);
	var AddressPostal=WDSCommon.getTagValue(document.AddressHOTSForm.AddressPostal);
	WDSCommon.updateTag(document.HOTSForm,"ZIP_CODE",AddressPostal);
	var AddressDistance=WDSCommon.getTagValue(document.AddressHOTSForm.AddressDistance);
	WDSCommon.updateTag(document.HOTSForm,"DISTANCE_VALUE",AddressDistance);
	hotTabParams+=this.getParamsToString("document.AddressHOTSForm","AddressStreet|AddressCity|AddressCountryCode|AddressState|AddressPostal|AddressDistance");
    }
    hotTabParams+="|";
    document.HOTSForm.HOT_TAB_PARAMS.value=hotTabParams;
    if(this.currentRefineMode===1){
	var companyInput=null;
	var companyNewInput=null;
	var listCompany=document.forms.refineSearchForm.LIST_COMPANY;
	if(listCompany){
	    for(var i=0;i<listCompany.length;i++){
		companyInput=listCompany[i];
		if(companyInput&&companyInput.tagName.toLowerCase()==="input"&&companyInput.value!==""){
		    companyNewInput=document.createElement("input");
		    companyNewInput.type="hidden";
		    companyNewInput.name=companyInput.name;
		    companyNewInput.value=companyInput.value;
		    document.forms.HOTSForm.appendChild(companyNewInput);
		}
	    }
	}
	delete companyInput;
	delete companyNewInput;
	delete listCompany;
	var listHotelInput=document.forms.refineSearchForm.LIST_HOTEL_NAME;
	var listHotelNewInput=null;
	if(listHotelInput&&listHotelInput.tagName.toLowerCase()==="input"&&listHotelInput.value!==""){
	    listHotelNewInput=document.createElement("input");
	    listHotelNewInput.type="hidden";
	    listHotelNewInput.name=listHotelInput.name;
	    listHotelNewInput.value=listHotelInput.value;
	    document.forms.HOTSForm.appendChild(listHotelNewInput);
	}
	delete listHotelInput;
	delete listHotelNewInput;
	var commonBudgetInput=document.forms.refineSearchForm.COMMON_BUDGET;
	var commonBudgetNewInput=null;
	if(commonBudgetInput&&commonBudgetInput.tagName.toLowerCase()==="input"&&commonBudgetInput.value!==""){
	    commonBudgetNewInput=document.createElement("input");
	    commonBudgetNewInput.type="hidden";
	    commonBudgetNewInput.name=commonBudgetInput.name;
	    commonBudgetNewInput.value=commonBudgetInput.value;
	    document.forms.HOTSForm.appendChild(commonBudgetNewInput);
	}
	delete commonBudgetInput;
	delete commonBudgetNewInput;
	var facilityInput=null;
	var facilityNewInput=null;
	var listFacility=document.forms.refineSearchForm.LIST_FACILITY;
	if(listFacility){
	    for(var i=0;i<listFacility.length;i++){
		facilityInput=listFacility[i];
		if(facilityInput&&facilityInput.checked&&facilityInput.tagName.toLowerCase()==="input"&&facilityInput.value!==""){
		    facilityNewInput=document.createElement("input");
		    facilityNewInput.type="hidden";
		    facilityNewInput.name=facilityInput.name;
		    facilityNewInput.value=facilityInput.value;
		    document.forms.HOTSForm.appendChild(facilityNewInput);
		}
	    }
	}
	delete facilityInput;
	delete facilityNewInput;
	delete listFacility;
    }
}
function HOTS_applyStyle(cmpName,visibleCode){
    var cmp=document.getElementById(cmpName);
    if(cmp!=null){
	cmp.style.visibility=this.visibilityType[visibleCode];
	cmp.style.display=this.displayType[visibleCode];
	if(navigator.userAgent.toLowerCase().indexOf('opera')!=-1){
	    if(visibleCode==this.show)
		cmp.style.height="";else
		cmp.style.height="0px";
	}else{
	    cmp.style.height="";
	}
    }
}
function HOTS_getNbNights(datStart,datEnd){
    var nbNights=0;
    var currentDat=datStart;
    while(currentDat.getDate()!=datEnd.getDate()||currentDat.getMonth()!=datEnd.getMonth()||currentDat.getYear()!=datEnd.getYear()){
	currentDat.setDate(currentDat.getDate()+1);
	nbNights++;
    }
    return nbNights;
}
function HOTS_refreshNights(){
    var checkInDate=HOTSDateList.getDateTimeComposed(HOTSDateList.grpStart);
    var checkOutDate=HOTSDateList.getDateTimeComposed(HOTSDateList.grpEnd);
    var nbNights="&nbsp;"
    if(checkInDate.getTime()<checkOutDate.getTime()){
	nbNights=this.getNbNights(checkInDate,checkOutDate);
    }
    this.divNightsCmp.innerHTML=nbNights;
}
function HOTS_force3Facilities(lastCheck){
    var checkBoxCmp;
    var counterChecked=0;
    for(var i=0;i<document.refineSearchForm.LIST_FACILITY.length;i++){
	checkBoxCmp=document.refineSearchForm.LIST_FACILITY[i];
	if(checkBoxCmp&&checkBoxCmp.checked){
	    counterChecked++;
	}
    }
if(counterChecked>3){
    lastCheck.checked=false;
}
}
function HOTS_popInit(id){
    if(id===undefined){
	id=WDSCommon.getTagValue(document.CityPopularHOTSForm.radioPopular);
	if(id!==undefined&&id!==""){
	    var i=0;
	    while(this.pDest[i][1]!=id){
		i++;
	    }
	    id=i;
	}
    }
if(id!==undefined&&id!==""){
    if(this.pDest[id][2]=="D"){
	this.pDest[id][2]="";
    }
    if(document.CityHOTSForm){
	WDSCommon.updateTag(document.CityHOTSForm,"CityBLocation",this.pDest[id][0]);
	WDSCommon.updateTag(document.CityHOTSForm,"CityRadioCityOrAirport",this.pDest[id][2]);
	WDSCommon.updateTag(document.CityHOTSForm,"CityCountryCode",this.pDest[id][3]);
    }
    this.currentPopDestSelected=[this.pDest[id][0],this.pDest[id][1],this.pDest[id][2],this.pDest[id][3]];
    this.curCountry=this.pDest[id][3];
}
}
function HOTS_testPopDestEqCityAirportField(){
    if(this.currentPopDestSelected!=null&&(WDSCommon.getTagValue(document.CityHOTSForm.CityBLocation)!=this.currentPopDestSelected[0]||WDSCommon.getTagValue(document.CityHOTSForm.CityRadioCityOrAirport)!=this.currentPopDestSelected[2]||WDSCommon.getTagValue(document.CityHOTSForm.CityCountryCode)!=this.currentPopDestSelected[3])){
	if(this.pDest.length<=13){
	    var curPopDestRad;
	    for(var i=0;i<this.pDest.length;i++){
		curPopDestRad=document.CityPopularHOTSForm.radioPopular[i];
		if(curPopDestRad){
		    curPopDestRad.checked=false;
		}
	    }
	    }else{
    WDSCommon.updateTag(document.CityPopularHOTSForm,"radioPopular","");
}
this.currentPopDestSelected=null;
}
}
function HOTS_setValue(param,cmp){
    eval("this."+param+" = cmp.value;");
}
function HOTS_refineYourSearch(){
    if(this.refineYourSearchCmp!=null){
	this.currentRefineMode=1-this.currentRefineMode;
	if(this.currentRefineMode==0){
	    this.displayPanel("ExtendedRefineDiv",this.hide);
	    document.getElementById("refineYourSearchLink").innerHTML=this.viewOptionsLabel;
	}else{
	    this.displayPanel("ExtendedRefineDiv",this.show);
	    document.getElementById("refineYourSearchLink").innerHTML=this.closeOptionsLabel;
	}
    }
}
function HOTS_getParamsToString(form,lstParams){
    var stringParams="";
    var params=lstParams.split("|");
    var param,value,cmpExist;
    for(var i=0;i<params.length;i++){
	param=params[i];
	value="";
	eval("cmpExist = "+form);
	if(cmpExist){
	    eval("cmpExist = "+form+"."+param);
	    if(cmpExist){
		eval("value = WDSCommon.getTagValue("+form+"."+param+");");
	    }
	}
    stringParams+="|"+param+"="+value;
    }
return stringParams;
}
function HOTS_setErrMsg106(label,codes){
    var err106Adapted=label;
    var codeLetter=this.maxAllowedNights.substr(0,1);
    var number=this.maxAllowedNights.substr(1);
    var label="";
    for(var i=0;i<codes.length;i++){
	if(codes[i][0]==codeLetter){
	    label=codes[i][1];
	}
    }
var posNumber=err106Adapted.indexOf("^DATA(MAX_STAY_DURATION_NUMBER)");
if(posNumber!=-1){
    err106Adapted=err106Adapted.substr(0,posNumber)+number+err106Adapted.substr(posNumber+31);
}
var posLabel=err106Adapted.indexOf("^DATA(MAX_STAY_DURATION_LABEL)");
if(posLabel!=-1){
    err106Adapted=err106Adapted.substr(0,posLabel)+label+err106Adapted.substr(posLabel+30);
}
WDSMessage.setMessage(106,err106Adapted);
}
function HOTS_displayPanel(id,displayCode){
    var panel=document.getElementById(id);
    if(panel){
	var regexp=/ hidden/gi;
	var name=panel.className;
	if(displayCode===this.hide&&!name.match(regexp)){
	    panel.className+=" hidden";
	}else if(displayCode===this.show){
	    var named=name.replace(regexp,"");
	    panel.className=named;
	}
    }
}