     function padVal(valStr)  { // pads single digit strings w. leading zero        valStr=valStr+''        //if(parseInt(valStr) < 10)  {        if(valStr.length < 2)  {             valStr='0'+valStr          }        return valStr      }        //---------- initialize variables                monthDays=new Array(0,31,28,31,30,31,30,31,31,30,31,30,31)                today=new Date                yearStr=today.getFullYear()+""                monthStr=padVal(today.getMonth()+1)                dayStr=padVal(today.getDate())                todayDate=yearStr+monthStr+dayStr                get_month =today.getMonth()                get_day =today.getDate() - 1                arvY=0                arvM=0                arvD=0                depY=0                depM=0                depD=0                los=0                julianArv=0                julianDep=0                totPaxSaved = 0                adult = 0                child = 0                property = ''                cartype = ''                unit_type = ''                unitType = 0                ArvSelM = 0                ArvSelD = 0                ArvSelY = 0                DepSelM = 0                DepSelD = 0                DepSelY = 0        //----------------------------        function populateDays(callField) {                        if(callField=="arv_mon") {                          theMonth =document.CRHAvail.arv_month.selectedIndex                          }                        else {                          theMonth =document.CRHAvail.dep_month.selectedIndex                           }                             //   monthStr = monthChosen.options[monthChosen.selectedIndex].value                             //   theMonth=parseInt(monthStr)                        if (callField=="arv_mon" || callField=="") {                                saveArvDay =document.CRHAvail.arv_day.selectedIndex                               if(saveArvDay==0) {                                        saveArvDay=get_day                                //document.CRHAvail.arv_month.selectedIndex=get_month                                }                               document.CRHAvail.arv_day.options.length =0                         if((document.CRHAvail.arv_year.value-2000)%4==0) {                                monthDays[2]=29                                     }                                else   {                                 monthDays[2]=28                             }                                for(i=0;i<monthDays[theMonth+1];i++) {                                       document.CRHAvail.arv_day.options[i]=new Option(i+1)                                  }                         document.CRHAvail.arv_day.selectedIndex =Math.min(saveArvDay,monthDays[theMonth+1])                          arvD =document.CRHAvail.arv_day.selectedIndex                          }                   //--------- departure date -----------                       if(callField=="dep_mon" || callField=="") {                                saveDepDay = document.CRHAvail.dep_day.selectedIndex                               document.CRHAvail.dep_day.options.length =0                          if((document.CRHAvail.dep_year.value-2000)%4==0) {                                monthDays[2]=29                             }                             else   {                               monthDays[2]=28                             }                               document.CRHAvail.dep_day.options.length =0                                for(i=0;i<monthDays[theMonth+1];i++) {                                       document.CRHAvail.dep_day.options[i] =new Option(i+1)                                     }                    document.CRHAvail.dep_day.selectedIndex =Math.min(saveDepDay,monthDays[theMonth+1]-1)                     depD = document.CRHAvail.dep_day.selectedIndex       }                     dummy=date_checker()                                                return (true)             }        function populateDaysInit() {          dummy=parseCookies()          if(document.cookie != "")  {       //prop cookie found               document.CRHAvail.adult.selectedIndex = adult               document.CRHAvail.child.selectedIndex = child               if (property)  {               document.CRHAvail.property.selectedIndex = property               }               document.CRHAvail.unit_type.selectedIndex = unitType               //document.CRHAvail.cartype.selectedIndex = cartype                dummy=paxLimit()                  }                     theMonth=get_month                     saveArvDay=get_day                        //alert(ArvSelM)                            if(ArvSelM != 0) {                              document.CRHAvail.arv_month.selectedIndex=ArvSelM                               saveArvDay=ArvSelD                               theMonth=ArvSelM                               }                               else {                               document.CRHAvail.arv_month.selectedIndex=get_month                               }                        if(ArvSelY != 0) {                               document.CRHAvail.arv_year.selectedIndex=ArvSelY                            }                        document.CRHAvail.arv_day.options.length =0                              if((document.CRHAvail.arv_year.value-2000)%4==0) {                                 monthDays[2]=29                                     }                                else   {                                 monthDays[2]=28                             }                                for(i=0;i<monthDays[theMonth+1];i++) {                                       document.CRHAvail.arv_day.options[i] =new Option(i+1)                                  }                               document.CRHAvail.arv_day.selectedIndex =Math.min(saveArvDay,monthDays[theMonth+1]-1)         //--------- depart ---------------                            if(ArvSelM != 0) {       // ArvSelM is never reduced by 1                                        saveDepDay=DepSelD                                        theMonth=DepSelM                               }                               else {                                        saveDepDay=get_day+1                               document.CRHAvail.dep_month.selectedIndex=get_month                               document.CRHAvail.dep_year.value=yearStr                                }                        if(ArvSelY != 0) {                               document.CRHAvail.dep_year.selectedIndex=DepSelY                            }                               document.CRHAvail.dep_day.options.length =0                      if((document.CRHAvail.dep_year.value-2000)%4==0) {                                monthDays[2]=29                             }                             else   {                               monthDays[2]=28                             }                         document.CRHAvail.dep_day.options.length =0                                for(i=0;i<monthDays[theMonth+1];i++) {                                       document.CRHAvail.dep_day.options[i] =new Option(i+1)                                     }                    document.CRHAvail.dep_day.selectedIndex =Math.min(saveDepDay,monthDays[theMonth+1]-1)                    depD = document.CRHAvail.dep_day.selectedIndex                    return (date_checker())                }function date_checker(){       arvY = document.CRHAvail.arv_year.selectedIndex       arvM = document.CRHAvail.arv_month.selectedIndex       arvD = document.CRHAvail.arv_day.selectedIndex       depY = document.CRHAvail.dep_year.selectedIndex       depM = document.CRHAvail.dep_month.selectedIndex       depD = document.CRHAvail.dep_day.selectedIndex       arvDate = document.CRHAvail.arv_year.value+padVal(document.CRHAvail.arv_month.value)+padVal(arvD+1)       depDate = document.CRHAvail.dep_year.value+padVal(document.CRHAvail.dep_month.value)+padVal(depD+1)      if(arvDate<todayDate) {        //alert('arvDate=|'+arvDate+'| todayDate=|'+todayDate+'|')        document.CRHAvail.arv_year.selectedIndex=document.CRHAvail.arv_year.selectedIndex + 1        dummy=populateDays('arv_mon')   //to-from leap year        return (false)        }     if(depD<0) {      document.CRHAvail.dep_day.selectedIndex =Math.min(arvD+1,monthDays[theMonth+1]-1)       depD = document.CRHAvail.dep_day.selectedIndex        }    if(arvY>depY){      document.CRHAvail.dep_year.selectedIndex =arvY       depY = document.CRHAvail.dep_year.selectedIndex       dummy=populateDays('dep_mon')   //to-from leap year        }    if(arvY==depY && arvM>depM){       document.CRHAvail.dep_month.selectedIndex =arvM        depM = document.CRHAvail.dep_month.selectedIndex        dummy=populateDays('dep_mon')   //to-from leap year        }     if(arvM==depM && arvD>=depD && arvY==depY){          if((document.CRHAvail.arv_day.selectedIndex+1) == monthDays[theMonth+1] ||document.CRHAvail.arv_month.value==12) {      //spcl case where depart exceeds last day of month             if(document.CRHAvail.dep_month.selectedIndex == 11)  { //test for 12/31/yyyy                 document.CRHAvail.dep_year.selectedIndex = arvY+1                 document.CRHAvail.dep_month.selectedIndex = 0                 document.CRHAvail.dep_day.selectedIndex = 0              }              else {                 document.CRHAvail.dep_month.selectedIndex = 1 +document.CRHAvail.arv_month.selectedIndex                 document.CRHAvail.dep_day.selectedIndex = 0              }           }           else {               document.CRHAvail.dep_day.selectedIndex =Math.min(arvD+1,monthDays[theMonth+1])          }       depM = document.CRHAvail.dep_month.selectedIndex       depD = document.CRHAvail.dep_day.selectedIndex       depY = document.CRHAvail.dep_year.selectedIndex        }       julianDep = new Date(document.CRHAvail.dep_year.value,(depM),(depD+1))       julianArv = new Date(document.CRHAvail.arv_year.value,(arvM),(arvD+1))       los = (julianDep.getTime() - julianArv.getTime())/86400000      document.CRHAvail.los.value=los         return (true)      }      function checkLos() {        if(los > 180) {   //limit on vacation rental days            alert('Please limit your stay to 180 days or call 800 367-5242 for assistance.')            return (false)         }        if(los < 4) {   //min 4-night stay as per Joel 09/14/2007            alert('Minimum stay is 4 nights -- call 800 367-5242 Mon - Sat for possible exceptions.')            return (false)         }            return (date_checker())      }      function paxLimit() {           var totPax = parseInt(document.CRHAvail.adult.value)+parseInt(document.CRHAvail.child.value)         if(totPaxSaved > 0) {        //skip first time in           if (totPax>10)  {                alert('A maximum of 10 people can stay in a unit.')                totPax = totPaxSaved                return (false)             }           if (totPax>4 && document.CRHAvail.unit_type.selectedIndex == 0) {      //max 4 in 1bd  and unit.type not set to two-bed               if (totPax>6) {                  document.CRHAvail.unit_type.selectedIndex=2               }               else {                  document.CRHAvail.unit_type.selectedIndex=1               }                if(totPaxSaved<=4) {                     totPaxSaved = totPax                     alert("A maximum 4 people allowed in a one bedroom unit.")                     }                     else {                     alert("Maximum of 2 people in a studio or 4 in a one bedroom. ")                     }                return (true)             }           if (totPax>8 && (document.CRHAvail.unit_type.selectedIndex != 3 )) {      //max 9 in 3bd  and unit.type not set to two-bed               document.CRHAvail.unit_type.selectedIndex=3                if(totPaxSaved<=8) {                     totPaxSaved = totPax                     alert("A maximum 8 people allowed in a three bedroom unit.")                     }                     else {                     alert("Maximum of 6 people in a two bedroom and 8 in a three bedroom. ")                     }                return (true)             }           if (totPax>6 && (document.CRHAvail.unit_type.selectedIndex != 2  && document.CRHAvail.unit_type.selectedIndex != 3)) {      //max 4 in 1bd  and unit.type not set to two-bed               document.CRHAvail.unit_type.selectedIndex=2                if(totPaxSaved<=6) {                     totPaxSaved = totPax                     alert("A maximum 6 people allowed in a two bedroom unit.")                     }                     else {                     alert("Maximum of 2 people in a studio or 4 in a one bedroom. ")                     }                return (true)             }           if (totPax>2 && document.CRHAvail.unit_type.selectedIndex == 4) {      //max 2 in studio               document.CRHAvail.unit_type.selectedIndex=0                if(totPaxSaved<=2) {                     alert("A maximum 2 people allowed in a studio unit.")                     }                     else {                     alert("Cannot book a studio unit with more than 2 people.")                     }              }           }           totPaxSaved = totPax         return (true)      }function CRHAvail_Validator(theForm){  if (theForm.email.value == "")  {    alert("Please enter a value for the \"Email\" field.");    theForm.email.focus();    return (false);  }  if (theForm.email.value.length < 5)  {    alert("Please enter at least 5 characters in the \"Email\" field.");    theForm.email.focus();    return (false);  }  if (theForm.lname.value == "")  {    alert("Please enter a value for the \"Last Name\" field.");    theForm.lname.focus();    return (false);  }  if (theForm.fname.value == "")  {    alert("Please enter a value for the \"First Name\" field.");    theForm.fname.focus();    return (false);  }  if (theForm.phone.value == "")  {    alert("Please enter a value for the \"Phone\" field.");    theForm.phone.focus();    return (false);  }  if (theForm.arv_month.selectedIndex < 0)  {    alert("Please select one of the \"Arrival Month\" options.");    theForm.arv_month.focus();    return (false);  }  if (theForm.dep_month.selectedIndex < 0)  {    alert("Please select one of the \"Departure Month\" options.");    theForm.dep_month.focus();    return (false);  }  if (theForm.unit_type.selectedIndex < 0)  {    alert("Please select one of the \"Type of Unit\" options.");    theForm.unit_type.focus();    return (false);  }  return checkLos(); }