
function ADVS(){this.initialisation=0;this.alreadySubmited=false;this.numOfRooms=0;this.backRooms=new Array();this.totalNumOfPax=0;this.from="";this.to="";this.priceLevels=new Array();this.dateList=new DateList();this.divNightsCmp=null;this.nbNights=0;this.maxOfStay=100;this.error5118="";this.minTravellerPerRoom=0;this.minChildAge=0;this.medAdultAge=0;this.maxPax=0;this.init=ADVS_init;this.check=ADVS_check;this.preCheck=ADVS_preCheck;this.checkPax=ADVS_checkPax;this.pageOnLoad=ADVS_pageOnLoad;this.calculateNbNights=ADVS_calculateNbNights;this.refreshNights=ADVS_refreshNights;this.initRooms=ADVS_initRooms;this.ageLimitListInit=ADVS_ageLimitListInit;this.saveB2BParameters=ADVS_saveB2BParameters;this.dateListInit=ADVS_dateListInit;this.updateLocationsList=ADVS_updateLocationsList;this.prepareRoomParams=ADVS_prepareRoomParams;this.preparePriceParams=ADVS_preparePriceParams;this.prepareMiscParams=ADVS_prepareMiscParams;this.submitSearchRequest=ADVS_submitSearchRequest;this.generateFakeBirthdate=ADVS_generateFakeBirthdate;}
var ADVS=new ADVS();function ADVS_check(){if(this.alreadySubmited){}else{this.alreadySubmited=true;WDSError.init();this.preCheck();if(WDSError.hasError()){WDSError.show();CommonTools.displayHolErrorPanel();this.alreadySubmited=false;}else{$("searchLaunched").value="true";this.submitSearchRequest();WDSWaitingImage.pleaseWait("wait");}}}
function ADVS_preCheck(){var from=document.getElementById("B_LOCATION_1").value;if(from==""){WDSError.add(WDSMessage.getMessage(130107),document.ADVSForm.B_LOCATION_1,"E");}
var to=document.getElementById("B_LOCATION_2").value;if(to==""){WDSError.add(WDSMessage.getMessage(130108),document.ADVSForm.B_LOCATION_2,"E");}
if(from==to&&from!=""&&to!=""){WDSError.add(WDSMessage.getMessage(19223),document.ADVSForm.B_LOCATION_2,"E");WDSError.add(WDSMessage.getMessage(19223),document.ADVSForm.B_LOCATION_1,"E",false);}
var checkInDate=this.dateList.getDateTimeComposed(this.dateList.grpStart);var checkOutDate=this.dateList.getDateTimeComposed(this.dateList.grpEnd);if(checkInDate.getTime()>=checkOutDate.getTime()){WDSError.add(WDSMessage.getMessage(10000),document.ADVSForm.B_DATE_1,"E");WDSError.add(WDSMessage.getMessage(10000),document.ADVSForm.B_DATE_2,"E",false);}else{var displayErr=false;if(this.maxOfStay.substr(0,1)=="D"){displayErr=(this.nbNights>this.maxOfStay.substr(1));}else if(this.maxOfStay.substr(0,1)=="W"){displayErr=(this.nbNights>7*this.maxOfStay.substr(1));}else if(this.maxOfStay.substr(0,1)=="M"){var currentDat=checkInDate;var nbMonths=0;while((currentDat.getMonth()!=checkOutDate.getMonth()||currentDat.getYear()!=checkOutDate.getYear())&&currentDat.getTime()<checkOutDate.getTime()){currentDat.setMonth(currentDat.getMonth()+1);nbMonths++;}
if(currentDat.getDate()<checkOutDate.getDate()){nbMonths++;}
displayErr=(nbMonths>this.maxOfStay.substr(1));}
if(displayErr){WDSError.add(WDSMessage.getMessage(106),document.ADVSForm.B_DATE_2,"E");}
var datStart=this.dateList.getDateTimeComposedString(this.dateList.grpStart);WDSCommon.updateTag(document.ADVSForm,"B_DATE_1",datStart);var datEnd=this.dateList.getDateTimeComposedString(this.dateList.grpEnd);WDSCommon.updateTag(document.ADVSForm,"B_DATE_2",datEnd);}
this.checkPax();}
function ADVS_checkPax(){this.numOfRooms=document.ADVSForm.numOfRoomsCombo.value;if(this.numOfRooms!=0){this.totalNumOfPax=0;var totalNumOfAdults=0;var totalNumOfInfants=0;var numOfADT=0;var numOfCHD=0;var numOfINF=0;for(var i=1;i<=this.numOfRooms;i++){holiday.search.computeNumberOfChildrenAndInfants(i,this.minChildAge,this.dateList);numOfADT=document.ADVSForm["room"+i+"_ADT"].value;numOfCHD=document.ADVSForm["room"+i+"_CHD"].value;numOfINF=document.ADVSForm["room"+i+"_INF"].value;this.totalNumOfPax+=parseInt(numOfADT,10);this.totalNumOfPax+=parseInt(numOfCHD,10);this.totalNumOfPax+=parseInt(numOfINF,10);}
if(this.totalNumOfPax==0){WDSError.add(this.errorNoPax,document.getElementById("tdRooms"),"E",true);}else{this.totalNumOfPax=0;totalNumOfAdults=0;totalNumOfInfants=0;numOfADT=0;numOfCHD=0;numOfINF=0;for(var i=1;i<=this.numOfRooms;i++){numOfADT=document.ADVSForm["room"+i+"_ADT"].value;numOfCHD=document.ADVSForm["room"+i+"_CHD"].value;numOfINF=document.ADVSForm["room"+i+"_INF"].value;this.totalNumOfPax+=parseInt(numOfADT,10);this.totalNumOfPax+=parseInt(numOfCHD,10);this.totalNumOfPax+=parseInt(numOfINF,10);totalNumOfAdults+=parseInt(numOfADT,10);totalNumOfInfants+=parseInt(numOfINF,10);if((numOfADT+numOfCHD+numOfINF)==0){var newErrMsg=WDSMessage.getMessage(130126);newErrMsg=newErrMsg.replace(/\^DATA\(MIN_TRAVELLER_PER_ROOM\)/,""+this.minTravellerPerRoom);WDSError.add(newErrMsg,document.getElementById("room"+i+"_ADT"),"E",true);}
if((numOfADT==0)&&(numOfCHD==0)&&(numOfINF!=0)){WDSError.add(WDSMessage.getMessage(130103),document.getElementById("room"+i+"_ADT"),"E",true);}}
if(this.totalNumOfPax>this.maxPax){WDSError.add(this.error5118,document.getElementById("tdRooms"),"E",true);}
if(totalNumOfAdults==0){WDSError.add(WDSMessage.getMessage(5122),document.getElementById("tdRooms"),"E",true);}else{if(totalNumOfInfants>totalNumOfAdults){WDSError.add(WDSMessage.getMessage(5124),document.getElementById("tdRooms"),"E",true);}}}}}
function ADVS_calculateNbNights(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 ADVS_refreshNights(){var checkInDate=this.dateList.getDateTimeComposed(this.dateList.grpStart);var checkOutDate=this.dateList.getDateTimeComposed(this.dateList.grpEnd);var strNbNights="0";if(checkInDate.getTime()<checkOutDate.getTime()){strNbNights=this.calculateNbNights(checkInDate,checkOutDate);}
this.nbNights=strNbNights;this.divNightsCmp.innerHTML=strNbNights;}
function ADVS_submitSearchRequest(){this.prepareRoomParams();this.preparePriceParams();this.prepareMiscParams();holiday.formManager.fillForm(document.searchForm);document.searchForm.submit();}
function ADVS_prepareRoomParams(){var numberOfRoom=parseInt($("numOfRoomsCombo").value,10);var numOfADT=0;var numOfCHD=0;var numOfINF=0;var paxId=1
var adtBirthdate=this.generateFakeBirthdate(this.medAdultAge);for(var i=1;i<=numberOfRoom;i++){numOfADT=parseInt($("room"+i+"_ADT").value,10);numOfCHD=parseInt($("room"+i+"_CHD").value,10);numOfINF=parseInt($("room"+i+"_INF").value,10);var travellerIndexInRoom=0;for(travellerIndexInRoom=1;travellerIndexInRoom<=numOfADT;travellerIndexInRoom++){holiday.formManager.addParameter("HOTEL_1_ROOM_"+i+"_TRAVELLER_"+travellerIndexInRoom+"_ID",paxId);holiday.formManager.addParameter("TRAVELLER_TYPE_"+paxId,"ADT");holiday.formManager.addParameter("DATE_OF_BIRTH_"+paxId,adtBirthdate);paxId++;}
for(var j=1;j<=numOfCHD+numOfINF;j++){var currentChildAge=parseInt($("room"+i+"_child"+j+"_age").value,10);if(currentChildAge>=this.minChildAge){var chdBirthdate=this.generateFakeBirthdate(currentChildAge);holiday.formManager.addParameter("HOTEL_1_ROOM_"+i+"_TRAVELLER_"+travellerIndexInRoom+"_ID",paxId);holiday.formManager.addParameter("TRAVELLER_TYPE_"+paxId,"CHD");holiday.formManager.addParameter("DATE_OF_BIRTH_"+paxId,chdBirthdate);paxId++;travellerIndexInRoom++;}}
for(var j=1;j<=numOfCHD+numOfINF;j++){var currentChildAge=parseInt($("room"+i+"_child"+j+"_age").value,10);if(currentChildAge<this.minChildAge){var chdBirthdate=this.generateFakeBirthdate(currentChildAge);holiday.formManager.addParameter("HOTEL_1_ROOM_"+i+"_TRAVELLER_"+travellerIndexInRoom+"_ID",paxId);holiday.formManager.addParameter("TRAVELLER_TYPE_"+paxId,"INF");holiday.formManager.addParameter("DATE_OF_BIRTH_"+paxId,chdBirthdate);paxId++;travellerIndexInRoom++;}}}}
function ADVS_preparePriceParams(){if($("priceRangeCombo")){var price=parseInt($("priceRangeCombo").value,10);if(price!=0){if(price==parseInt(this.priceLevels[0],10)){holiday.formManager.addParameter("MAX_PRICE_BOUND",price);}
if(price>parseInt(this.priceLevels[0],10)){holiday.formManager.addParameter("MIN_PRICE_BOUND",this.priceLevels[this.priceLevels.length-1]);}
for(var i=1;i<this.priceLevels.length;i++){if(price==this.priceLevels[i]){holiday.formManager.addParameter("MIN_PRICE_BOUND",this.priceLevels[i-1]);holiday.formManager.addParameter("MAX_PRICE_BOUND",this.priceLevels[i]);break;}}}}}
function ADVS_prepareMiscParams(){holiday.formManager.addParameter("B_DATE_1",$("B_DATE_1").value);holiday.formManager.addParameter("B_DATE_2",$("B_DATE_2").value);holiday.formManager.addParameter("B_LOCATION_1",$("B_LOCATION_1").value);holiday.formManager.addParameter("B_LOCATION_2",$("B_LOCATION_2").value);holiday.formManager.addParameter("E_LOCATION_1",$("B_LOCATION_2").value);holiday.formManager.addParameter("E_LOCATION_2",$("B_LOCATION_1").value);if($("flexibleCheckbox")&&$("flexibleCheckbox").checked){holiday.formManager.addParameter("DATE_RANGE_VALUE_1",$("selectStartingFlex").value);holiday.formManager.addParameter("DURATION_RANGE_VALUE_1",$("selectDurationFlex").value);}
if($("chk_directOnlyCheckbox")){holiday.formManager.addParameter("DIRECT_SEARCH",$("chk_directOnlyCheckbox").checked?"TRUE":"FALSE");}
if($("THEME")&&$("THEME").value!=""){holiday.formManager.addParameter("THEME",$("THEME").value);}
if($("BRAND")&&$("BRAND").value!=""){holiday.formManager.addParameter("BRAND",$("BRAND").value);}
if($("PACKAGE_ID")&&$("PACKAGE_ID").value!=""){holiday.formManager.addParameter("PACKAGE_ID",$("PACKAGE_ID").value);}}
function ADVS_generateFakeBirthdate(age){var todayDate=new Date();var checkInDate=this.dateList.getDateTimeComposed(this.dateList.grpStart);checkInDate.setFullYear(checkInDate.getFullYear()-age);if(compare(todayDate,checkInDate)<=0){checkInDate.setTime(todayDate.getTime()-86500000);}
var resDate="";resDate+=checkInDate.getFullYear();if(checkInDate.getMonth()+1<10){resDate+="0";}
resDate+=(checkInDate.getMonth()+1);if(checkInDate.getDate()<10){resDate+="0";}
resDate+=checkInDate.getDate()+"0000";return resDate;}
