﻿	function airdeptformchange () {
		ihotelierformchange();
//		document.getElementById("airdept").style.visibility = "visible";
//		document.getElementById("airdept").style.display = "inline";
//		document.getElementById("ihotelier").style.visibility = "hidden";
//		document.getElementById("ihotelier").style.display = "none"; 
	}
	
	function ihotelierformchange () {
		document.getElementById("ihotelier").style.visibility = "visible";
		document.getElementById("ihotelier").style.display = "inline";
		

//		if (document.getElementById('airdept') == null) {
//			document.getElementById("airdept").style.visibility = "hidden";
//			document.getElementById("airdept").style.display = "none"; 
//		}
	}

	function ihotelierOnly () {
		document.getElementById("ihotelier").style.visibility = "visible";
		document.getElementById("ihotelier").style.display = "inline";
	}
	function airdepthotel_code () {
  select_option = airdeptform.area2;
  prop_id = select_option.selectedIndex;
  if (prop_id == 0) {
   airdeptform.supplierid.value = "564";
  airdeptform.track.value = "3777";
  }
  else if (prop_id == 1) { 
   airdeptform.supplierid.value = "572";
  airdeptform.track.value = "3778";  
  }
  else if (prop_id == 2) {
   airdeptform.supplierid.value = "574";
  airdeptform.track.value = "3779";      
  }
  else if (prop_id == 3) {
   airdeptform.supplierid.value = "569";
  airdeptform.track.value = "3845";      
  }
  else if (prop_id == 4) {
   airdeptform.supplierid.value = "570";
  airdeptform.track.value = "3781";         
  }
  else if (prop_id == 5) {
   airdeptform.supplierid.value = "571";
  airdeptform.track.value = "3782";              
  }
  else if (prop_id == 6) {
   airdeptform.supplierid.value = "573";
  airdeptform.track.value = "3783";                   
  }
  else if (prop_id == 7) {
   airdeptform.supplierid.value = "565";
  airdeptform.track.value = "3784";                      
  }
 }

	
	function ihotelier_id () {
		select_option = ihotelierform.area2;
		hotel_id = select_option.selectedIndex;
		if (hotel_id == 0) {
			ihotelierform.HotelID.value = "2550";
		}
		else if (hotel_id == 1) {	
			ihotelierform.HotelID.value = "2549";
		}
		else if (hotel_id == 2) {
			ihotelierform.HotelID.value = "2551";				
		}
		else if (hotel_id == 3) {
			ihotelierform.HotelID.value = "2554";				
		}
		else if (hotel_id == 4) {
			ihotelierform.HotelID.value = "2555";								
		}
		else if (hotel_id == 5) {
			ihotelierform.HotelID.value = "2556";												
		}
		else if (hotel_id == 6) {
			ihotelierform.HotelID.value = "2558";																	
		}
		else if (hotel_id == 7) {
			ihotelierform.HotelID.value = "2559";																				
		}
	}	

// removed includes went here


// add trim to the string object
if (typeof(String.prototype.trim) == "undefined") {
String.prototype.trim = function() {

// skip leading and trailing whitespace
// and return everything in between
  var x=this;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}
}

	function disableForm() {
		airdeptform.submit.disabled = true;
		return true;
	}

        // Helper function to shift a Javascript date by a number of days.
        function modifyDate (d, offsetDays) {
        	d.setTime(d.getTime()+(offsetDays*1000*60*60*24));
        }

        // Helper function to nicely format a Javascript date into mm/dd/yyyy.
        // Handles putting a zero in front of single-digit months, days, and years.
        //
        // HOWEVER, NOTE:
        //   It currently ses a 2-digit year because that's what EzRez does by default.
        //   It currently has PAD_MONTH and PAD_DAY set to false because EzRez has its
        //   calendar defaultly using non-padded values (e.g., "3/2/05" instead of "03/02/05").
        // -RP 06/14/2005
        var UNENTERED_DATE_STRING = "mm/dd/yy";
        var PAD_MONTH = false;
        var PAD_DAY = false;
        function getDateString (d) {
            var sMonth = "" + (d.getMonth() + 1);
            if (sMonth.length == 1 && PAD_MONTH)
                sMonth = "0" + sMonth;
            var sDay = "" + d.getDate();
            if (sDay.length == 1 && PAD_DAY)
                sDay = "0" + sDay;
            var sYear = "" + (d.getFullYear() % 100);
            if (sYear.length == 1)
                sYear = "0" + sYear;
            return sMonth + "/" + sDay + "/" + sYear;
        }


	var now = new Date();
        modifyDate(now, 1);   // earliest we can book is 1 day out
	var earliestYear = now.getFullYear();
	var earliestMonth = now.getMonth()+1;
	var earliestDay = now.getDate();

        var earliestCheckoutYear = earliestYear;
        var earliestCheckoutMonth = earliestMonth; // already has the +1
        var earliestCheckoutDay = earliestDay;

        function parseDateCorrectly(datestring) {
            var d = new Date(datestring);
            // Handle Y2K issue.
            if (d.getFullYear() < 1970)
                d.setYear(d.getFullYear() + 100);
            return d;
        }

// some dates come back as a Date object but with invalid contents.
// e.g.,  Date("06") or Date("06/85")
// only 
        function isValidDate (datestring) {
          try {
            dateobj = new Date(datestring);
            m = dateobj.getMonth();
            if (m >= 0)
              return true;
          }
          catch (e) { }
          return false;
        }
    

        function setEarliestCheckout(sCheckinDate) {
            EARLIEST_CHECKOUT_OFFSET = 1  // number of days later
            try {
                debugHB("sEC: sCheckinDate=" + sCheckinDate);
                var dateCheckin = parseDateCorrectly(sCheckinDate);
                debugHB("sEC: dateCheckin=" + dateCheckin);
                if (dateCheckin.getMonth() >= 0) {
                    modifyDate(dateCheckin, EARLIEST_CHECKOUT_OFFSET);
                    earliestCheckoutYear = dateCheckin.getFullYear();
                    earliestCheckoutMonth = dateCheckin.getMonth()+1;
                    earliestCheckoutDay = dateCheckin.getDate();
                }
            }
            catch (e) {
                debugHB("failure in setEarliestCheckout: " + e);
            }
        }

        now = new Date(); // reset it
        modifyDate(now, 330);  // latest we can book is 330 days out
	var latestYear = now.getFullYear();
	var latestMonth = now.getMonth()+1;
	var latestDay = now.getDate();


        now = new Date(); // reset it
modifyDate(now, 3);    // default start date is 3 days out
var defaultStartDateString = getDateString(now);
 
now = new Date();
modifyDate(now, 1);
var defaultStartDateString2 = getDateString(now);
 
now = new Date(); // reset it
modifyDate(now, 10);    // default end date is 10 days out (per RG email 06/30/2005)
var defaultEndDateString = getDateString(now);

        // Helper function that takes a string representation
        // of the date, plus an offset in days, and returns
        // the appropriately-offset date string. -- RP 06/14/2005
        function getOffsetDateString (datestring, offsetDays) {
            var bHaveRealDate = false;
            try {
                if ((datestring == "") || (datestring == UNENTERED_DATE_STRING))
                    d = new Date();
                else {
                    d = parseDateCorrectly(datestring);
                    
                    bHaveRealDate = true;
                }
                modifyDate(d, offsetDays);
                return getDateString(d);
            }
            catch (e) {
                // if we have an error, just return a safe string
                if (bHaveRealDate)
                    return datestring;
                else
                    return UNENTERED_DATE_STRING;
            }
        }

        // Set to true to force end date to always get changed if start date does.
        ALWAYS_CHANGE_END_DATE = true;

        // Called from our hook function. --RP 06/14/2005
        function reviseEndDateIfNeeded(ctlStart, ctlEnd, offsetDays) {
            try {
                var bNeedsRevision = false;
                var startDate = parseDateCorrectly(ctlStart.value);
                var endDate = parseDateCorrectly(0);


                // Three ways we need revision:
                // (1) the "always change end date" flag is on
                if (ALWAYS_CHANGE_END_DATE == true)
                    bNeedsRevision = true;
                // (2) the end date is blank
                else if (ctlEnd.value == "")
                    bNeedsRevision = true;
                // (3) the end date is invalid
                else if (!isValidDate(ctlEnd.value))
                    bNeedsRevision = true;                  
                else {
                    // (4) the end date is equal to or before the start date
                    endDate = parseDateCorrectly(ctlEnd.value);
                    if (endDate <= startDate)
                        bNeedsRevision = true;
                }

                if (bNeedsRevision) {
                    // set the end date to at least offsetDays later.
                    endDate = parseDateCorrectly(startDate);
                    modifyDate(endDate, offsetDays);
                    ctlEnd.value = getDateString(endDate);
                }
            }
            catch (e) {
                // don't do anything, we've got an error
            }
        }



function readyForSubmission (frm) {
    //
    // PURPOSE:    Validates search form passed in as frm
    //
    // RETURNS:    "" if ready to submit
    //             otherwise it returns a string to be 
    //             presented to the user describing the
    //             validation problems to be resolved.
    var sReady = "";

    // (1) Make sure the city pairs are both non-empty.
    // if (frm.area1.value.trim() == "")
    //    sReady += "- The departure airport must be specified.\n";

    // (2) Make sure the date boxes are not empty, and
    // (3) Make sure the dates are parsable.
    if (frm.date1.value.trim() == "")
        sReady += "- The checkin date must be specified.\n";
    else if (!isValidDate(frm.date1.value.trim()))
        sReady += "- The checkin date must be properly formatted as mm/dd/yy.\n";

    if (frm.date2.value.trim() == "")
      sReady += "- The checkout date must be specified.\n";
    else if (!isValidDate(frm.date2.value.trim()))
      sReady += "- The checkout date must be properly formatted as mm/dd/yy.\n";

    return sReady;
}


function validateForm (frm) {
  debugHB("validateForm called");
  var sError = readyForSubmission(frm);
  if (sError.length > 0) {
    alert(sError);
    return false;
  }
  else
    return true;
}

function submitIfValid () {
  var frm = document.forms[0];
  if (validateForm(frm))
    frm.submit();
}

        var DEBUGHB_ON = false;
        function debugHB(sDebug) {
            if (DEBUGHB_ON) {
                document.getElementById("debugInfo").style.visibility = "visible";
                document.getElementById("debugInfo").innerHTML += sDebug + "<BR>";            
            }
        }

        // PLUG COMPATIBLE REPLACEMENT FOR COMMENTED OUT FUNCTION BELOW -- RP 06/14/2005
        var calendarField = "";
        
        var END_DATE_DAYS_AFTER_START_DATE = 7;  // in number of days

        var startDateBeforeCalendarPoppedUp = null;

        function popCal(field,min_date_array,max_date_array) {
            calendarField = field;
            // If the start date is improperly formatted, then change both
            // back to well-known safe defaults. - RP 06/30/2005
            if (field == document.airdeptform.date1 &&
                !isValidDate(field.value))
              initDefaultDates();
            // Revise the end date before we pop it up. - RP 06/30/2005
            if (field == document.airdeptform.date2)
              reviseEndDateIfNeeded(document.airdeptform.date1, document.airdeptform.date2, END_DATE_DAYS_AFTER_START_DATE);


            if (("" + self.gfPop.startDateBeforeCalendarPoppedUp == 'undefined') ||
                ("" + self.gfPop.startDateBeforeCalendarPoppedUp == 'null'))
                self.gfPop.startDateBeforeCalendarPoppedUp = document.airdeptform.date1.value;


            // HOOK FUNCTION FOR HIDECAL

            if ("" + self.gfPop.originalHideCal == 'undefined') {
                self.gfPop.originalHideCal = self.gfPop.fHideCal;
                self.gfPop.fHideCal = function() {
                    // OUR HOOK - START
                    // this sets the end date to 7 days after the start date, but only
                    // if the end date is equal to or lower than the start date.
                    // only do it when they are changing the start date -- otherwise
                    // you can get in a state where they change the end date legitimately
                    // to a date before the start date and we set it right back to 7 days
                    // past the start date.
                    if ( (calendarField == document.airdeptform.date1) &&
                         (("" + document.airdeptform.date1.value) != ("" + self.gfPop.startDateBeforeCalendarPoppedUp))
                       ) {
                       //debugHB("first test: " + (calendarField == document.airdeptform.date1));
                       //debugHB("second test: " + (("" + document.airdeptform.date1.value) != ("" + self.gfPop.startDateBeforeCalendarPoppedUp)));
                         
                        // clear saved value

                        //debugHB("calendar field: " + calendarField.id + ", " + "date1: " + document.airdeptform.date1.id);
                        //debugHB("form: " + document.airdeptform.date1.value + ", saved: " + self.gfPop.startDateBeforeCalendarPoppedUp);

                        self.gfPop.startDateBeforeCalendarPoppedUp = null; // clear it so it will be empty at next initial pop up


                        // If the start date is improperly formatted, then change it
                        // back to a well-known safe default. - RP 06/30/2005
                        if (!isValidDate(document.airdeptform.date1.value))
                          initDefaultDates();

                        // This will correct the end date if needed.
                        reviseEndDateIfNeeded(document.airdeptform.date1, document.airdeptform.date2, END_DATE_DAYS_AFTER_START_DATE);

                        setEarliestCheckout(document.airdeptform.date1.value);
                    }

                    // OUR HOOK - END
                    self.gfPop.originalHideCal();
                }
            }

            self.gfPop.fPopCalendar(field, [min_date_array, max_date_array]);
        }            


        function popCal2(field,min_date_array,max_date_array) {
            calendarField = field;

            // If the start date is improperly formatted, then change both
            // back to well-known safe defaults. - RP 06/30/2005
            if (field == document.ihotelierform.DateIn &&
                !isValidDate(field.value))
              initDefaultDates();

            if (("" + self.gfPop.startDateBeforeCalendarPoppedUp == 'undefined') ||
                ("" + self.gfPop.startDateBeforeCalendarPoppedUp == 'null'))
                self.gfPop.startDateBeforeCalendarPoppedUp = document.ihotelierform.DateIn.value;


            // HOOK FUNCTION FOR HIDECAL

            if ("" + self.gfPop.originalHideCal == 'undefined') {
                self.gfPop.originalHideCal = self.gfPop.fHideCal;
                self.gfPop.fHideCal = function() {
                    // OUR HOOK - START
                    // this sets the end date to 7 days after the start date, but only
                    // if the end date is equal to or lower than the start date.
                    // only do it when they are changing the start date -- otherwise
                    // you can get in a state where they change the end date legitimately
                    // to a date before the start date and we set it right back to 7 days
                    // past the start date.
                    if ( (calendarField == document.ihotelierform.DateIn) &&
                         (("" + document.ihotelierform.DateIn.value) != ("" + self.gfPop.startDateBeforeCalendarPoppedUp))
                       ) {

                        self.gfPop.startDateBeforeCalendarPoppedUp = null; // clear it so it will be empty at next initial pop up

                        // If the start date is improperly formatted, then change it
                        // back to a well-known safe default. - RP 06/30/2005
                        if (!isValidDate(document.ihotelierform.DateIn.value))
                          initDefaultDates();

                        setEarliestCheckout(document.ihotelierform.DateIn.value);
                    }

                    // OUR HOOK - END
                    self.gfPop.originalHideCal();
                }
            }



                
            self.gfPop.fPopCalendar(field, [min_date_array, max_date_array]);
        }

        function initDefaultDates() { 
		
			ihotelierformchange();
		
            // Set the defaults. -- RP 06/14/2005
			
            //document.getElementById("date1").value = defaultStartDateString;
			//document.getElementById("date2").value = defaultEndDateString;
			
            document.getElementById("DateIn").value = defaultStartDateString2;			
            
            // and fix the checkout date too -- RP 06/27/2005
            setEarliestCheckout(defaultStartDateString2);
			
			//if(document.air_room_form.air_room_radio[0].checked == true)
			//	airdeptformchange();
			//if(document.air_room_form.air_room_radio[1].checked == true)
				ihotelierformchange();	
        }
		
		function checkSubmit () {
		
   if(airdeptform.area1.value == '' || airdeptform.area1.value == 'enter airport code')
   {
    alert('You must enter a departure airport');
    return false;
   }
   // Per Anne - don't open new window anymore 2007/06/08
   else
   {
   // if(airdeptform.area2.selectedIndex == 0) {
   //  newWindow = window.open('http://www.divivillage.com/divivillage/resort.asp');
   // }
   // else if(airdeptform.area2.selectedIndex == 1) {
   //  newWindow = window.open('http://www.dividutchvillage.com/dividutchvillage/resort.asp');
   // }
   // else if(airdeptform.area2.selectedIndex == 2) {
   //  newWindow = window.open('http://www.diviarubaphoenix.com/diviarubaphoenix/resort.asp');
   // }   
   // else if(airdeptform.area2.selectedIndex == 3) {
   //  newWindow = window.open('http://www.divisouthwinds.com/divisouthwinds/resort.asp');
   // }  
   // else if(airdeptform.area2.selectedIndex == 4) {
   //  newWindow = window.open('http://www.diviheritage.com/diviheritage/resort.asp');
   // }   
   // else if(airdeptform.area2.selectedIndex == 5) {
   //  newWindow = window.open('http://www.diviflamingo.com/diviflamingo/resort.asp');
   // }   
   // else if(airdeptform.area2.selectedIndex == 6) {
   //  newWindow = window.open('http://www.divicarina.com/divicarinabay/resort.asp');
   // }    
   // else if(airdeptform.area2.selectedIndex == 7) {
   //  newWindow = window.open('http://www.divilittlebay.com/divilittlebay/resort.asp');
   // }                 
   // else {
   //  newWindow = window.open('http://www.diviresorts.com');     
   // }
   // newWindow.blur();
    return true;
   }
 }
 
  function checkSubmitihotelier () {
  	// Per Anne - don't open new window anymore 2007/06/08
   //if(ihotelierform.area2.selectedIndex == 0) {
   // newWindow = window.open('http://www.divivillage.com/divivillage/resort.asp');
   //}
   //else if(ihotelierform.area2.selectedIndex == 1) {
   // newWindow = window.open('http://www.dividutchvillage.com/dividutchvillage/resort.asp');
   //}
   //else if(ihotelierform.area2.selectedIndex == 2) {
   // newWindow = window.open('http://www.diviarubaphoenix.com/diviarubaphoenix/resort.asp');
   //}   
   //else if(ihotelierform.area2.selectedIndex == 3) {
   // newWindow = window.open('http://www.divisouthwinds.com/divisouthwinds/resort.asp');
   //}  
   //else if(ihotelierform.area2.selectedIndex == 4) {
   // newWindow = window.open('http://www.diviheritage.com/diviheritage/resort.asp');
   //}   
   //else if(ihotelierform.area2.selectedIndex == 5) {
   // newWindow = window.open('http://www.diviflamingo.com/diviflamingo/resort.asp');
   //}   
   //else if(ihotelierform.area2.selectedIndex == 6) {
   // newWindow = window.open('http://www.divicarina.com/divicarinabay/resort.asp');
   //}    
   //else if(ihotelierform.area2.selectedIndex == 7) {
   // newWindow = window.open('http://www.divilittlebay.com/divilittlebay/resort.asp');
   //}                 
   //else {
   // newWindow = window.open('http://www.diviresorts.com');     
   //}
   //newWindow.blur();
   return true;
  }
  
  
  function valSubmitihotelier(formValues) {
	  
	if(checkSubmitihotelier())
	{
		pageTracker._linkByPost(formValues);
		//alert('hello');
		return true;
		
	}
	return false;
  }
