
function MYS(){this.alreadySubmited=false;this.numOfRooms=0;this.minChildAge=0;this.medAdultAge=0;this.isDisplayed=false;this.dateList=new Function();this.check=MYS_check;this.checkDates=MYS_checkDates;this.preCheck=MYS_preCheck;this.SAVDates=MYS_SAVDates;this.pageOnLoad=MYS_pageOnLoad;this.initDateLists=MYS_initDateLists;this.initFlexibility=MYS_initFlexibility;this.initRooms=MYS_initRooms;this.checkRooms=MYS_checkRooms;this.toggleSearchPanel=MYS_toggleSearchPanel;this.prepareRoomParams=MYS_prepareRoomParams;this.prepareMiscParams=MYS_prepareMiscParams;this.submitSearchRequest=MYS_submitSearchRequest;this.nextPage=MYS_nextPage;this.previousPage=MYS_previousPage;this.filterResults=MYS_filterResults;this.sortResults=MYS_sortResults;this.backToPackageResult=MYS_backToPackageResult;this.setActionAndParamsForNextPageForm=MYS_setActionAndParamsForNextPageForm;this.getCurrentAction=MYS_getCurrentAction;this.generateFakeBirthdate=MYS_generateFakeBirthdate;}
var MYS=new MYS();function MYS_toggleSearchPanel(toggleLink){if(toggleLink!=null){var searchPanel=document.getElementById("searchRecapPanel");if(searchPanel!=null){if(searchPanel.style.display=="none"){searchPanel.style.display="block";toggleLink.innerHTML=hideSearchLabel;}else{searchPanel.style.display="none";toggleLink.innerHTML=showSearchLabel;}}}}
function MYS_check(pleaseWaitEnabled){if(!this.alreadySubmited){this.alreadySubmited=true;WDSError.init();this.preCheck();if(WDSError.hasError()){WDSError.show();CommonTools.displayHolErrorPanel();this.alreadySubmited=false;}else{if(this.isDisplayed){var beginDay=document.getElementById("B_DAY");var beginMonth=document.getElementById("B_MONTH");var endDay=document.getElementById("E_DAY");var endMonth=document.getElementById("E_MONTH");if(beginDay.value==""||beginMonth.value==""||endDay.value==""||endMonth.value==""){this.initDateLists();}
this.SAVDates();}
$("searchLaunched").value="true";this.submitSearchRequest();if(pleaseWaitEnabled==true){WDSWaitingImage.pleaseWait("wait");}}}}
function MYS_preCheck(){this.checkDates();this.checkRooms();}
function MYS_checkDates(){if(this.isDisplayed){if(this.dateList.getDateTimeComposed){var beginDate=this.dateList.getDateTimeComposed(this.dateList.grpStart);var endDate=this.dateList.getDateTimeComposed(this.dateList.grpEnd);if(beginDate.getTime()>endDate.getTime()){WDSError.add(WDSMessage.getMessage(10000),document.MYSForm.B_DAY,"E",true);WDSError.add("This message won't be displayed (false)",document.MYSForm.E_DAY,"E",false);}}}}
function MYS_SAVDates(){if(this.isDisplayed&&this.dateList.getDateTimeComposedString){var beginDate=this.dateList.getDateTimeComposedString(this.dateList.grpStart);var endDate=this.dateList.getDateTimeComposedString(this.dateList.grpEnd);document.getElementById("B_DATE_1").value=beginDate;document.getElementById("B_DATE_2").value=endDate;}}
function MYS_nextPage(){if(!this.alreadySubmited){this.alreadySubmited=true;this.setActionAndParamsForNextPageForm();var pageNum=parseInt(document.MYSPreviousNextForm.PAGE_NUMBER.value,10);holiday.formManager.fillForm(document.MYSPreviousNextForm);document.MYSPreviousNextForm.PAGE_NUMBER.value=pageNum+1;document.MYSPreviousNextForm.submit();}}
function MYS_previousPage(){if(!this.alreadySubmited){this.alreadySubmited=true;this.setActionAndParamsForNextPageForm();var pageNum=parseInt(document.MYSPreviousNextForm.PAGE_NUMBER.value,10);holiday.formManager.fillForm(document.MYSPreviousNextForm);document.MYSPreviousNextForm.PAGE_NUMBER.value=pageNum-1;document.MYSPreviousNextForm.submit();}}
function MYS_filterResults(){if(!this.alreadySubmited){this.alreadySubmited=true;document.MYSPreviousNextForm.PAGE_NUMBER.value=1;if($("departureAirportFilter")){holiday.formManager.addParameter("FILTER_BY_DEP_AIRPORT",$("departureAirportFilter").value);}
if($("airlineFilter")){holiday.formManager.addParameter("FILTER_BY_AIRLINE",$("airlineFilter").value);}
if($("destinationAirportFilter")){holiday.formManager.addParameter("FILTER_BY_DEST_AIRPORT",$("destinationAirportFilter").value);}
this.setActionAndParamsForNextPageForm();holiday.formManager.fillForm(document.MYSPreviousNextForm);document.MYSPreviousNextForm.submit();}}
function MYS_sortResults(){if(!this.alreadySubmited){this.alreadySubmited=true;this.setActionAndParamsForNextPageForm();document.MYSPreviousNextForm.PAGE_NUMBER.value=1;holiday.formManager.addParameter("ARRANGE_BY",$("select_sortBy").value);holiday.formManager.fillForm(document.MYSPreviousNextForm);document.MYSPreviousNextForm.submit();}}
function MYS_submitSearchRequest(){this.prepareRoomParams();this.prepareMiscParams();holiday.formManager.fillForm(document.searchForm);document.searchForm.submit();}
function MYS_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 MYS_prepareMiscParams(){holiday.formManager.addParameter("B_DATE_1",$("B_DATE_1").value);holiday.formManager.addParameter("B_DATE_2",$("B_DATE_2").value);if($("B_FLEXIBLE_CHK")&&$("B_FLEXIBLE_CHK").checked){holiday.formManager.addParameter("DATE_RANGE_VALUE_1",$("AvailselectStartingFlex").value);holiday.formManager.addParameter("DURATION_RANGE_VALUE_1",$("AvailselectDurationFlex").value);}
if($("PROMOTION_CODE").value){holiday.formManager.addParameter("PROMOTION_CODE",$("PROMOTION_CODE").value);}}
function MYS_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;}
