//<!--
//\include\travel\js\VacationFormFunctions.js@@\main\3

function DateAdd(startDate,numDays,numMonths,numYears)
{var returnDate=new Date(startDate.getTime());var yearsToAdd=numYears;var month=returnDate.getMonth()+numMonths;if(month>11)
{yearsToAdd=Math.floor((month+1)/12);month-=12*yearsToAdd;yearsToAdd+=numYears;}
returnDate.setMonth(month);returnDate.setFullYear(returnDate.getFullYear()+yearsToAdd);returnDate.setTime(returnDate.getTime()+60000*60*24*numDays);return returnDate;}
function LZ(x)
{return(x<0||x>9?"":"0")+x;}
function formatDate(date,format){var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');format=format+"";var result="";var i_format=0;var c="";var token="";var y=date.getYear()+"";var M=date.getMonth()+1;var d=date.getDate();var H=date.getHours();var m=date.getMinutes();var s=date.getSeconds();var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;var value=new Object();if(y.length<4){y=""+(y-0+1900);}
value["y"]=""+y;value["yyyy"]=y;value["yy"]=y.substring(2,4);value["M"]=M;value["MM"]=LZ(M);value["MMM"]=MONTH_NAMES[M-1];value["d"]=d;value["dd"]=LZ(d);value["H"]=H;value["HH"]=LZ(H);if(H==0){value["h"]=12;}
else if(H>12){value["h"]=H-12;}
else{value["h"]=H;}
value["hh"]=LZ(value["h"]);if(H>11){value["K"]=H-12;}else{value["K"]=H;}
value["k"]=H+1;value["KK"]=LZ(value["K"]);value["kk"]=LZ(value["k"]);if(H>11){value["a"]="PM";}
else{value["a"]="AM";}
value["m"]=m;value["mm"]=LZ(m);value["s"]=s;value["ss"]=LZ(s);while(i_format<format.length){c=format.charAt(i_format);token="";while((format.charAt(i_format)==c)&&(i_format<format.length)){token+=format.charAt(i_format++);}
if(value[token]!=null){result=result+value[token];}
else{result=result+token;}}
return result;}
function loadDates(){var thisDate=new Date();thisDate=DateAdd(thisDate,7,0,0);var thisMonth=thisDate.getMonth()+1;var thisYear=thisDate.getFullYear()
var additionalYear=addYear();removeByValue('departDate_year_month','ph1');removeByValue('departDate_year_month','ph2');removeByValue('departDate_year_month','ph3');removeByValue('departDate_year_month','ph4');removeByValue('returnDate_year_month','ph1');removeByValue('returnDate_year_month','ph2');removeByValue('returnDate_year_month','ph3');removeByValue('returnDate_year_month','ph4');for(var i=thisMonth;i<13;i++){var tmpDate=new Date(i+"/1/"+thisYear);var thisVal=thisYear+"/"+i;var thisText=monthAbbr(i)+" "+thisYear;addByValue('departDate_year_month',thisVal,thisText);addByValue('returnDate_year_month',thisVal,thisText);}
if(additionalYear==1){thisYear=parseInt(thisYear)+1;for(var i=1;i<13;i++){var tmpDate=new Date(i+"/1/"+thisYear);var thisVal=thisYear+"/"+i;var thisText=monthAbbr(i)+" "+formatDate(tmpDate,'yyyy');addByValue('departDate_year_month',thisVal,thisText);addByValue('returnDate_year_month',thisVal,thisText);}}
document.SearchForm.departDate_year_month.selectedIndex=0;document.SearchForm.returnDate_year_month.selectedIndex=0;}
function addYear(){var monthThreshold=7;var thisDate=new Date();var thisMonth=(thisDate.getMonth()+1);var addYear=0;if(parseInt(thisMonth)>monthThreshold){addYear=1;}
return addYear;}
function addByValue(thisEl,optionValue,optionText)
{var formElement=eval('document.SearchForm.'+thisEl);var thisLength=formElement.length;newoption=new Option(optionText,optionValue,false,false);formElement.options[thisLength]=newoption;}
function monthAbbr(ai_value)
{if(ai_value==1)return"Jan";else if(ai_value==2)return"Feb";else if(ai_value==3)return"Mar";else if(ai_value==4)return"Apr";else if(ai_value==5)return"May";else if(ai_value==6)return"Jun";else if(ai_value==7)return"Jul";else if(ai_value==8)return"Aug";else if(ai_value==9)return"Sep";else if(ai_value==10)return"Oct";else if(ai_value==11)return"Nov";else if(ai_value==12)return"Dec";}
function removeByValue(fromEl,sValue)
{var formElement=eval('document.SearchForm.'+fromEl);var fromLength=formElement.length;for(var x=0;x<fromLength;x++)
{if(formElement.options[x].value==sValue)
{formElement.options[x]=null;break;}}}
function destadd()
{var listobject=SearchForm.destinationcode
var doc=document.SearchForm;var x=listobject.options[listobject.selectedIndex].value;var i=x.indexOf("--");listobject.options[i].value=doc.destcodetoadd.value;listobject.options[i].text=doc.desttoadd.value;}
function changedrops()
{var childage=document.all.childageframe;var chil=document.SearchForm.PassengerChildCount.value;var max=3;if(0==chil){childage.style.visibility="hidden";childage.style.display="none";}
else{ShowAges(chil,max);if(childage.style.display=="none"){childage.style.visibility="hidden";childage.style.display="block";}
childage.style.visibility="visible";LapChild();}}
function ShowAges(c,m)
{for(var i=0;i<m;i++)
{if(i<c)d="block";else d="none";eval("document.all.cages"+i+".style.display='"+d+"'");eval("document.all.label"+i+".style.display='"+d+"'");eval("document.all.disclaimer.style.display='none'");}}
function LapChild()
{var m=3;for(var i=0;i<m;i++)
{var lapchild=eval("document.all.childAge_"+parseInt(i+1)+".value")
if(lapchild==0)
{eval("document.all.disclaimer.style.display='block'");break;}
else if(lapchild==1)
{eval("document.all.disclaimer.style.display='block'");break;}
else
{eval("document.all.disclaimer.style.display='none'");}}}
function isValidSearchForm(as_phoneNumber){if(!isValidGateway()){return(false);}
if(!isValidDestination()){return(false);}
if(!isValidReturnDate()){return(false);}
if(!isValidDepartureDate(as_phoneNumber)){return(false);}
if(!isValidNumOfPax()){return(false);}
if(!isValidTIDateRange(as_phoneNumber)){return(false);}
if(!isChildAgeValid(as_phoneNumber)){return(false);}
return(true);}
function isValidBPSearch(as_phoneNumber){if(!isValidGatewayNoDestTest()){return(false);}
if(!isValidReturnDate()){return(false);}
if(!isValidDepartureDate(as_phoneNumber)){return(false);}
if(!isValidNumOfPax()){return(false);}
if(!isValidTIDateRange(as_phoneNumber)){return(false);}
if(!isChildAgeValid(as_phoneNumber)){return(false);}
return(true);}
function isValidActivitySearchForm(){setDestIndex();resumMask2('SearchForm');if(!hasValidActivities()){return(false);}
if(!isValidGateway()){return(false);}
if(!isValidDestination()){return(false);}
return(true);}
function isValidResortSearchForm(){if(!hasValidFormValue()){return(false);}
if(!hasValidChars()){return(false);}
return(true);}
function endOfMonth(adt_date){var li_month=new Date(adt_date).getMonth()+1;switch(parseInt(li_month)){case 1:case 3:case 5:case 7:case 8:case 10:case 12:return 31;case 4:case 6:case 9:case 11:return 30;case 2:return((((new Date(adt_date).getYear())%4)==0)?29:28);}}
function updateDepartMonth(as_formName){monthChange(document.forms[as_formName].departDate_year_month,document.forms[as_formName].departDate_Day);}
function updateReturnMonth(as_formName){monthChange(document.forms[as_formName].returnDate_year_month,document.forms[as_formName].returnDate_Day);}
function monthChange(ao_month,ao_day){var ldt_selectedDate=new Date(ao_month.options[ao_month.selectedIndex].value+'/01');var li_DaysSelectedMonth=endOfMonth(ldt_selectedDate);var li_DaysActiveMonth=ao_day.options[ao_day.length-1].value;var li_difference=li_DaysSelectedMonth-li_DaysActiveMonth;var li_selectedValue=ao_day.options[ao_day.selectedIndex].value;if(li_DaysSelectedMonth>li_DaysActiveMonth){for(var li_counter=1;li_counter<=li_difference;li_counter++){var lo_newOption=new Option(parseInt(li_DaysActiveMonth)+li_counter,parseInt(li_DaysActiveMonth)+li_counter);ao_day.options[ao_day.length]=lo_newOption;}}
if(li_DaysSelectedMonth<li_DaysActiveMonth){for(var li_counter=1;li_counter<=-li_difference;li_counter++){ao_day.options[ao_day.length-1]=null;}}
if(li_selectedValue>li_DaysSelectedMonth){ao_day.selectedIndex=ao_day.length-1;}}
function maxdepartDateLength(as_formName){var ao_day=document.forms[as_formName].departDate_Day;var li_DaysActiveMonth=parseInt(ao_day.options[ao_day.length-1].value);for(var li_counter=1;li_counter<=(31-li_DaysActiveMonth);li_counter++){var lo_newOption=new Option(li_DaysActiveMonth+li_counter,li_DaysActiveMonth+li_counter);ao_day.options[ao_day.length]=lo_newOption;}}
function isValidGateway(){var gatewayInfo;var gatewayCode;gatewayInfo=document.SearchForm.gateway.options[document.SearchForm.gateway.selectedIndex].value;gatewayCode=gatewayInfo.substring(0,3);if(gatewayCode==''){showErrorMsg(document.SearchForm.gateway,'Please select a departure gateway.');return(false);}
if(gatewayCode==document.SearchForm.destinationcode.options[document.SearchForm.destinationcode.selectedIndex].value){showErrorMsg(document.SearchForm.gateway,'Departure gateway must differ from your selected destination.');return(false);}
return(true);}
function isValidGatewayNoDestTest(){var gatewayInfo;var gatewayCode;gatewayInfo=document.SearchForm.gateway.options[document.SearchForm.gateway.selectedIndex].value;gatewayCode=gatewayInfo.substring(0,3);if(gatewayCode==''){showErrorMsg(document.SearchForm.gateway,'Please select a departure gateway.');return(false);}
return(true);}
function isValidDestination(){var destinationCode;var gatewayInfo;var gatewayCode;gatewayInfo=document.SearchForm.gateway.options[document.SearchForm.gateway.selectedIndex].value;gatewayCode=gatewayInfo.substring(0,3);destinationCode=document.SearchForm.destinationcode.options[document.SearchForm.destinationcode.selectedIndex].value
if(gatewayCode==destinationCode){showErrorMsg(document.SearchForm.destinationcode,'Departure destination must differ from your selected gateway.');return(false);}
if(destinationCode==''||destinationCode=='--'){showErrorMsg(document.SearchForm.destinationcode,'Please select a destination.');return(false);}
return(true);}
function isValidReturnDate(){var currentDate;var returnDate;var returnYear;var returnMonth;var returnDay;var returnMonthYear;var midYearDate;var endYearDate;var endOfFollowingYearDate;currentDate=new Date();midYearDate=new Date(currentDate.getFullYear(),6,31);endYearDate=new Date(currentDate.getFullYear(),12,31);endOfFollowingYearDate=new Date(currentDate.getFullYear()+1,12,31);returnMonthYear=document.SearchForm.returnDate_year_month.options[document.SearchForm.returnDate_year_month.selectedIndex].value;returnYear=returnMonthYear.substring(0,4);returnMonth=returnMonthYear.substring(5,returnMonthYear.length);returnDay=document.SearchForm.returnDate_Day.options[document.SearchForm.returnDate_Day.selectedIndex].value;returnDate=new Date(returnYear,returnMonth-1,returnDay);if(currentDate<=midYearDate&&returnDate>endYearDate){showErrorMsg(document.SearchForm.returnDate_year_month,'Return date must be before the end of this year.');return(false);}
else if(currentDate>midYearDate&&returnDate>endOfFollowingYearDate){showErrorMsg(document.SearchForm.returnDate_year_month,'Return date must be before the end of next year.');return(false);}
return(true);}
function isValidDepartureDate(as_phoneNumber){var departMonthYear;var returnMonthYear;var returnDate;var departDate;var currentDate;var dateOffset;dateOffset=1000*60*60*24*7;var temp=new Date()
var year=temp.getYear();if(year<2000)
{year=year+1900;}
var today=new Date(new Date(year,temp.getMonth(),temp.getDate()));var minDepartDate=new Date(today.valueOf()+(dateOffset));currentDate=new Date();departMonthYear=document.SearchForm.departDate_year_month.options[document.SearchForm.departDate_year_month.selectedIndex].value;returnMonthYear=document.SearchForm.returnDate_year_month.options[document.SearchForm.returnDate_year_month.selectedIndex].value;returnDate=new Date(returnMonthYear.substring(0,4),returnMonthYear.substring(5,returnMonthYear.length)-1,document.SearchForm.returnDate_Day.options[document.SearchForm.returnDate_Day.selectedIndex].value);departDate=new Date(departMonthYear.substring(0,4),departMonthYear.substring(5,departMonthYear.length)-1,document.SearchForm.departDate_Day.options[document.SearchForm.departDate_Day.selectedIndex].value);if(currentDate>=departDate){showErrorMsg(document.SearchForm.departDate_year_month,'Departure date cannot be in the past.');return(false);}
else if(departDate<minDepartDate){var message;var formattedDate;formattedDate=formatDate(minDepartDate,'MMM dd, yyyy');message='Date of departure must be on or after '+formattedDate+'.\nPlease call our Travel Specialists at '+as_phoneNumber+' if you\'d like to book prior to this date.';showErrorMsg(document.SearchForm.departDate_year_month,message);return(false);}
else if(departDate>=returnDate){showErrorMsg(document.SearchForm.departDate_year_month,'Departure date must precede return date.');return(false);}
return(true);}
function isValidLapChildToAdultRatio(childNumber)
{adultPaxCount=document.SearchForm.PassengerAdultCount.options[document.SearchForm.PassengerAdultCount.selectedIndex].value;childPaxCount=document.SearchForm.PassengerChildCount.options[document.SearchForm.PassengerChildCount.selectedIndex].value;var childAge;var lapChildCount=0;for(var i=0;i<childPaxCount;i++)
{childAge=eval("document.all.childAge_"+(i+1)+".value");if((childAge==0)||(childAge==1))
{lapChildCount++;}}
if(lapChildCount>adultPaxCount)
{eval("document.all.childAge_"+childNumber+".selectedIndex = 2");showErrorMsg(document.SearchForm.gateway,'There must be at least one adult for each child under the age of one.');}}
function isChildAgeValid(as_phonenumber)
{childPaxCount=document.SearchForm.PassengerChildCount.options[document.SearchForm.PassengerChildCount.selectedIndex].value;var childAge;var childAgeDD;var lapChildCount=0;var j=0;for(var i=0;i<childPaxCount;i++)
{j=(i+1);childAgeDD=("childAge_"+j);childAge=eval("document.SearchForm."+childAgeDD+".options[document.SearchForm."+childAgeDD+".selectedIndex].value");if((childAge==0)||(childAge==1))
{lapChildCount++;showErrorMsg(document.SearchForm.gateway,'Note: Vacation Packages with Children under 2 years old cannot be booked online.  To book your vacation package with a child under 2 years, please call '+as_phonenumber+'.');return(false);}}
return(true);}
function displaychilddisclaimer()
{var childAge;for(var i=0;i<childPaxCount;i++)
{childAge=eval("document.all.childAge_"+(i+1)+".value");if((childAge==0)||(childAge==1))
{document.all.disclaimer.style.display='block';}
else
{eval("document.all.disclaimer.style.display='none'");}}}
function isValidNumOfPax(as_phonenumber){var adultPaxCount;var childPaxCount;adultPaxCount=document.SearchForm.PassengerAdultCount.options[document.SearchForm.PassengerAdultCount.selectedIndex].value;childPaxCount=document.SearchForm.PassengerChildCount.options[document.SearchForm.PassengerChildCount.selectedIndex].value;if(parseInt(adultPaxCount)+parseInt(childPaxCount)>4){showErrorMsg(document.SearchForm.PassengerAdultCount,'The maximum number of total passengers (adults and children) is 4. \r\nPlease call '+as_phonenumber+' to book more than 4 passengers.');document.SearchForm.PassengerAdultCount.selectedIndex=1;document.SearchForm.PassengerChildCount.selectedIndex=0;document.all.cages0.style.display='none';document.all.label0.style.display='none';document.all.disclaimer.style.display='none';document.all.cages1.style.display='none';document.all.label1.style.display='none';document.all.disclaimer.style.display='none';document.all.cages2.style.display='none';document.all.label2.style.display='none';document.all.disclaimer.style.display='none';return(false);}
return(true);}
function showErrorMsg(oField,sMsg)
{_alert(sMsg);oField.focus;}
function adjustReturnDate(as_formName){var departDate;var departMonthYear;var newNewReturnDate;var index=-1;var i;var exceededDateBounds=false;if((''+as_formName+'')=='undefined'){as_formName='SearchForm';}
departMonthYear=document.forms[as_formName].departDate_year_month.options[document.forms[as_formName].departDate_year_month.selectedIndex].value;departDate=new Date(departMonthYear.substring(0,4),departMonthYear.substring(5,departMonthYear.length)-1,document.forms[as_formName].departDate_Day.options[document.forms[as_formName].departDate_Day.selectedIndex].value);newReturnDate=new Date(departDate.getFullYear(),departDate.getMonth(),departDate.getDate()+7)
for(var i=0;i<document.forms[as_formName].returnDate_year_month.length;i++){if(document.forms[as_formName].returnDate_year_month.options[i].value==(newReturnDate.getFullYear()+"/"+(newReturnDate.getMonth()+1))){index=i;}}
if(index==-1){index=(document.forms[as_formName].returnDate_year_month.length-1);exceededDateBounds=true;}
document.forms[as_formName].returnDate_year_month.selectedIndex=index;updateReturnMonth(as_formName);index=-1
for(var i=0;i<document.forms[as_formName].returnDate_Day.length;i++){if(document.forms[as_formName].returnDate_Day.options[i].value==newReturnDate.getDate()){index=i;}}
if((index==-1)||(exceededDateBounds==true)){index=(document.forms[as_formName].returnDate_Day.length-1);}
document.forms[as_formName].returnDate_Day.selectedIndex=index;}
function isValidTIDateRange(as_displayPhone){var departMonthYear;var returnMonthYear;var returnDate;var departDate;departMonthYear=document.SearchForm.departDate_year_month.options[document.SearchForm.departDate_year_month.selectedIndex].value;returnMonthYear=document.SearchForm.returnDate_year_month.options[document.SearchForm.returnDate_year_month.selectedIndex].value;returnDate=new Date(returnMonthYear.substring(0,4),returnMonthYear.substring(5,returnMonthYear.length)-1,document.SearchForm.returnDate_Day.options[document.SearchForm.returnDate_Day.selectedIndex].value);departDate=new Date(departMonthYear.substring(0,4),departMonthYear.substring(5,departMonthYear.length)-1,document.SearchForm.departDate_Day.options[document.SearchForm.departDate_Day.selectedIndex].value);if(Math.floor((returnDate.getTime()-departDate.getTime())/(1000*60*60*24))>21){if((''+as_displayPhone+'')=='undefined'){showErrorMsg(document.SearchForm.returnDate_year_month,'Please call for vacations lasting longer than 21 days.');}else{showErrorMsg(document.SearchForm.returnDate_year_month,'Please call '+as_displayPhone+' to book a vacation lasting longer than 21 days.');}
return(false);}
return(true);}
function hasValidFormValue(){if((document.SearchForm.R.value.length==0)&&(document.SearchForm.C.value.length==0)&&(document.SearchForm.S.value.length==0)){_alert("Please enter at least one search phrase.");document.SearchForm.R.focus();return(false);}
return(true);}
function hasValidChars(){var invalidchars="`~!@#$^&*_=+[{]}\\|;:\"<>/?";for(i=0;i<invalidchars.length;i++)
{badchar=invalidchars.charAt(i);if(document.SearchForm.R.value.indexOf(badchar,0)>=0)
{_alert('No special characters are permitted.\n Use \'%\' as a wildcard, if necessary.');document.SearchForm.R.value="";document.SearchForm.R.focus();return(false);}
if(document.SearchForm.C.value.indexOf(badchar,0)>=0)
{_alert('No special characters are permitted.\n Use \'%\' as a wildcard, if necessary.');document.SearchForm.C.value="";document.SearchForm.C.focus();return(false);}
if(document.SearchForm.S.value.indexOf(badchar,0)>=0)
{_alert('No special characters are permitted.\n Use \'%\' as a wildcard, if necessary.');document.SearchForm.S.value="";document.SearchForm.S.focus();return(false);}}
return(true);}
function hasValidActivities()
{if(document['SearchForm'].maskvalue.value==0)
{_alert("Please select at least one activity");return(false);}
return(true);}
function updateMask(ai_value,ab_checked,as_formName){resumMask2(as_formName);}
function resumMask(ai_value,ab_checked,as_formName){var li_activeValue=parseInt(document[as_formName].maskvalue.value);if(ab_checked){li_activeValue+=parseInt(ai_value);}
document[as_formName].maskvalue.value=li_activeValue;}
function resumMask2(as_formName){document[as_formName].maskvalue.value=0;for(var i=0;i<document[as_formName].elements.length;i++){var thisElement=document[as_formName].elements[i];if(thisElement.type=="checkbox"){if(thisElement.checked){document[as_formName].maskvalue.value=parseInt(document[as_formName].maskvalue.value)+parseInt(thisElement.value);}}}return(true);}
function resetMask(as_formName){document[as_formName].reset();}
function setDestIndex(as_formName){document.SearchForm.dindex.value=document.SearchForm.destinationcode.selectedIndex;}
function checkDepartDate(ai_lastAvailableYear,ai_phone){var selectedYearMonth=document.SearchForm.departDate_year_month.options[document.SearchForm.departDate_year_month.selectedIndex].value;var selectedDay=document.SearchForm.departDate_Day.options[document.SearchForm.departDate_Day.selectedIndex].value;var selectedYear=selectedYearMonth.substr(0,4);var selectedMonth=selectedYearMonth.substr(5,(selectedYearMonth.length+1));var dateRangeErrorMsg="Please note that we can only book vacations online through the end of next year.  Please call "+ai_phone+" to continue booking your vacation with one of our Vacation Specialists, available from 9 am to 12 am EST Monday - Friday and 9 am to 10 pm EST Saturday - Sunday."
if((selectedYear==ai_lastAvailableYear)&&(selectedMonth=="12")){if(parseInt(selectedDay)>24){_alert(dateRangeErrorMsg);}}}
function submitForm(){if(isValidSearchForm('800-754-9733')){return true;}
else
{return false;}}
function showWin(as_dateFieldType,as_dateForMonth,as_formName,htmlpath){window.open(htmlpath+'calendar.html?form='+as_dateFieldType+'&date='+as_dateForMonth+'&formname='+as_formName,'popup','width=190,height=200,resizable=yes,menubar=no,status=yes,scrollbars=no,toolbar=no,directories=no,location=no,top=100,left=100');}
function _alert(str)
{if(typeof(ebay)!="undefined")
ebay.oDocument.messageBox(str);else
alert(str);}
// -->
