// Clears forms on page
function myFormClear(what) {
    for (var i=0, j=what.elements.length; i<j; i++) {
        myType = what.elements[i].type;
		//alert(myType);
        if (myType == 'checkbox' || myType == 'radio'){
            what.elements[i].checked = 0;
			//alert(what.elements[i].checked);
		}
        //if (myType == 'hidden' || myType == 'password' || myType == 'text' || myType == 'textarea')
        //    what.elements[i].value = what.elements[i].defaultValue;
        if (myType == 'select-one' || myType == 'select-multiple'){
			what.elements[i].selectedIndex = 0;
            //alert(what.elements[i].selectedIndex);
		}
			//for (var k=0, l=what.elements[i].options.length; k<l; k++)
            //   what.elements[i].options[k].selected = what.elements[i].options[0].selected;
    }
}


function jumpPage() {

    var Current = document.Navigation.Page.selectedIndex;



    if( document.Navigation.Page.options[Current].value ){

        window.location.href=document.Navigation.Page.options[Current].value;

    }

    else {

        return false;

    }

}




function openAvailPopup(url) {
	myPopup = '';
    myPopup = window.open(url,'popupWindow','width=416,height=480');
    if (!myPopup.opener)
         myPopup.opener = self; 
}


function MM_openBrWindow(theURL,winName,features) { //v3.0 fixes URLchopping
  var myLocation = location.href;
  //alert("Location" + myLocation);
  var newLoc;

  newLoc = theURL + "?REFERER=" + escape(myLocation);

  //alert("newLoc" + newLoc);
  window.open(newLoc,winName,features);
}



function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}



function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}



function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}



function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}


function MM_jumpMenu(targ,selObj,restore){ //v3.0

  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");

  if (restore) selObj.selectedIndex=0;

}

// Check browser version

var isNav4 = false, isNav5 = false, isIE4 = false

var strSeperator = "/"; 

// If you are using any Java validation on the back side you will want to use the / because 

// Java date validations do not recognize the dash as a valid date separator.

var vDateType = 3; // Global value for type of date format

//                1 = mm/dd/yyyy

//                2 = yyyy/dd/mm  (Unable to do date check at this time)

//                3 = dd/mm/yyyy

var vYearType = 4; //Set to 2 or 4 for number of digits in the year for Netscape

var vYearLength = 2; // Set to 4 if you want to force the user to enter 4 digits for the year before validating.

var err = 0; // Set the error code to a default of zero

if(navigator.appName == "Netscape") {

if (navigator.appVersion < "5") {

isNav4 = true;

isNav5 = false;

}

else

if (navigator.appVersion > "4") {

isNav4 = false;

isNav5 = true;

   }

}

else {

isIE4 = true;

}

function DateFormat(vDateName, vDateValue, e, dateCheck, dateType) {

vDateType = dateType;

// vDateName = object name

// vDateValue = value in the field being checked

// e = event

// dateCheck 

// True  = Verify that the vDateValue is a valid date

// False = Format values being entered into vDateValue only

// vDateType

// 1 = mm/dd/yyyy

// 2 = yyyy/mm/dd

// 3 = dd/mm/yyyy

//Enter a tilde sign for the first number and you can check the variable information.

if (vDateValue == "~") {

alert("AppVersion = "+navigator.appVersion+" \nNav. 4 Version = "+isNav4+" \nNav. 5 Version = "+isNav5+" \nIE Version = "+isIE4+" \nYear Type = "+vYearType+" \nDate Type = "+vDateType+" \nSeparator = "+strSeperator);

vDateName.value = "";

vDateName.focus();

return true;

}

var whichCode = (window.Event) ? e.which : e.keyCode;

// Check to see if a seperator is already present.

// bypass the date if a seperator is present and the length greater than 8

if (vDateValue.length > 8 && isNav4) {

if ((vDateValue.indexOf("-") >= 1) || (vDateValue.indexOf("/") >= 1))

return true;

}

//Eliminate all the ASCII codes that are not valid

var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-";

if (alphaCheck.indexOf(vDateValue) >= 1) {

if (isNav4) {

vDateName.value = "";

vDateName.focus();

vDateName.select();

return false;

}

else {

vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));

return false;

   }

}

if (whichCode == 8) //Ignore the Netscape value for backspace. IE has no value

return false;

else {

//Create numeric string values for 0123456789/

//The codes provided include both keyboard and keypad values

var strCheck = '47,48,49,50,51,52,53,54,55,56,57,58,59,95,96,97,98,99,100,101,102,103,104,105';

if (strCheck.indexOf(whichCode) != -1) {

if (isNav4) {

if (((vDateValue.length < 6 && dateCheck) || (vDateValue.length == 7 && dateCheck)) && (vDateValue.length >=1)) {

alert("Invalid Date\nPlease Re-Enter");

vDateName.value = "";

vDateName.focus();

vDateName.select();

return false;

}

if (vDateValue.length == 6 && dateCheck) {

var mDay = vDateName.value.substr(2,2);

var mMonth = vDateName.value.substr(0,2);

var mYear = vDateName.value.substr(4,4)

//Turn a two digit year into a 4 digit year

if (mYear.length == 2 && vYearType == 4) {

var mToday = new Date();

//If the year is greater than 30 years from now use 19, otherwise use 20

var checkYear = mToday.getFullYear() + 30; 

var mCheckYear = '20' + mYear;

if (mCheckYear >= checkYear)

mYear = '19' + mYear;

else

mYear = '20' + mYear;

}

var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;

if (!dateValid(vDateValueCheck)) {

alert("Invalid Date\nPlease Re-Enter");

vDateName.value = "";

vDateName.focus();

vDateName.select();

return false;

}

return true;

}

else {

// Reformat the date for validation and set date type to a 1

if (vDateValue.length >= 8  && dateCheck) {

if (vDateType == 1) // mmddyyyy

{

var mDay = vDateName.value.substr(2,2);

var mMonth = vDateName.value.substr(0,2);

var mYear = vDateName.value.substr(4,4)

vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;

}

if (vDateType == 2) // yyyymmdd

{

var mYear = vDateName.value.substr(0,4)

var mMonth = vDateName.value.substr(4,2);

var mDay = vDateName.value.substr(6,2);

vDateName.value = mYear+strSeperator+mMonth+strSeperator+mDay;

}

if (vDateType == 3) // ddmmyyyy

{

var mMonth = vDateName.value.substr(2,2);

var mDay = vDateName.value.substr(0,2);

var mYear = vDateName.value.substr(4,4)

vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;

}

//Create a temporary variable for storing the DateType and change

//the DateType to a 1 for validation.

var vDateTypeTemp = vDateType;

vDateType = 1;

var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;

if (!dateValid(vDateValueCheck)) {

alert("Invalid Date\nPlease Re-Enter");

vDateType = vDateTypeTemp;

vDateName.value = "";

vDateName.focus();

vDateName.select();

return false;

}

vDateType = vDateTypeTemp;

return true;

}

else {

if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) {

alert("Invalid Date\nPlease Re-Enter");

vDateName.value = "";

vDateName.focus();

vDateName.select();

return false;

         }

      }

   }

}

else {

// Non isNav Check

if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) {

alert("Invalid Date\nPlease Re-Enter");

vDateName.value = "";

vDateName.focus();

return true;

}

// Reformat date to format that can be validated. mm/dd/yyyy

if (vDateValue.length >= 8 && dateCheck) {

// Additional date formats can be entered here and parsed out to

// a valid date format that the validation routine will recognize.

if (vDateType == 1) // mm/dd/yyyy

{

var mMonth = vDateName.value.substr(0,2);

var mDay = vDateName.value.substr(3,2);

var mYear = vDateName.value.substr(6,4)

}

if (vDateType == 2) // yyyy/mm/dd

{

var mYear = vDateName.value.substr(0,4)

var mMonth = vDateName.value.substr(5,2);

var mDay = vDateName.value.substr(8,2);

}

if (vDateType == 3) // dd/mm/yyyy

{

var mDay = vDateName.value.substr(0,2);

var mMonth = vDateName.value.substr(3,2);

var mYear = vDateName.value.substr(6,4)

}

if (vYearLength == 4) {

if (mYear.length < 4) {

alert("Invalid Date\nPlease Re-Enter");

vDateName.value = "";

vDateName.focus();

return true;

   }

}

// Create temp. variable for storing the current vDateType

var vDateTypeTemp = vDateType;

// Change vDateType to a 1 for standard date format for validation

// Type will be changed back when validation is completed.

vDateType = 1;

// Store reformatted date to new variable for validation.

var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;

if (mYear.length == 2 && vYearType == 4 && dateCheck) {

//Turn a two digit year into a 4 digit year

var mToday = new Date();

//If the year is greater than 30 years from now use 19, otherwise use 20

var checkYear = mToday.getFullYear() + 30; 

var mCheckYear = '20' + mYear;

if (mCheckYear >= checkYear)

mYear = '19' + mYear;

else

mYear = '20' + mYear;

vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;

// Store the new value back to the field.  This function will

// not work with date type of 2 since the year is entered first.

if (vDateTypeTemp == 1) // mm/dd/yyyy

vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;

if (vDateTypeTemp == 3) // dd/mm/yyyy

vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;

} 

if (!dateValid(vDateValueCheck)) {

alert("Invalid Date\nPlease Re-Enter");

vDateType = vDateTypeTemp;

vDateName.value = "";

vDateName.focus();

return true;

}

vDateType = vDateTypeTemp;

return true;

}

else {

if (vDateType == 1) {

if (vDateValue.length == 2) {

vDateName.value = vDateValue+strSeperator;

}

if (vDateValue.length == 5) {

vDateName.value = vDateValue+strSeperator;

   }

}

if (vDateType == 2) {

if (vDateValue.length == 4) {

vDateName.value = vDateValue+strSeperator;

}

if (vDateValue.length == 7) {

vDateName.value = vDateValue+strSeperator;

   }

} 

if (vDateType == 3) {

if (vDateValue.length == 2) {

vDateName.value = vDateValue+strSeperator;

}

if (vDateValue.length == 5) {

vDateName.value = vDateValue+strSeperator;

   }

}

return true;

   }

}

if (vDateValue.length == 10&& dateCheck) {

if (!dateValid(vDateName)) {

// Un-comment the next line of code for debugging the dateValid() function error messages

//alert(err);  

alert("Invalid Date\nPlease Re-Enter");

vDateName.focus();

vDateName.select();

   }

}

return false;

}

else {

// If the value is not in the string return the string minus the last

// key entered.

if (isNav4) {

vDateName.value = "";

vDateName.focus();

vDateName.select();

return false;

}

else

{

vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));

return false;

         }

      }

   }

}

function dateValid(objName) {

var strDate;

var strDateArray;

var strDay;

var strMonth;

var strYear;

var intday;

var intMonth;

var intYear;

var booFound = false;

var datefield = objName;

var strSeparatorArray = new Array("-"," ","/",".");

var intElementNr;

// var err = 0;

var strMonthArray = new Array(12);

strMonthArray[0] = "Jan";

strMonthArray[1] = "Feb";

strMonthArray[2] = "Mar";

strMonthArray[3] = "Apr";

strMonthArray[4] = "May";

strMonthArray[5] = "Jun";

strMonthArray[6] = "Jul";

strMonthArray[7] = "Aug";

strMonthArray[8] = "Sep";

strMonthArray[9] = "Oct";

strMonthArray[10] = "Nov";

strMonthArray[11] = "Dec";

//strDate = datefield.value;

strDate = objName;

if (strDate.length < 1) {

return true;

}

for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {

if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {

strDateArray = strDate.split(strSeparatorArray[intElementNr]);

if (strDateArray.length != 3) {

err = 1;

return false;

}

else {

strDay = strDateArray[0];

strMonth = strDateArray[1];

strYear = strDateArray[2];

}

booFound = true;

   }

}

if (booFound == false) {

if (strDate.length>5) {

strDay = strDate.substr(0, 2);

strMonth = strDate.substr(2, 2);

strYear = strDate.substr(4);

   }

}

//Adjustment for short years entered

if (strYear.length == 2) {

strYear = '20' + strYear;

}

strTemp = strDay;

strDay = strMonth;

strMonth = strTemp;

intday = parseInt(strDay, 10);

if (isNaN(intday)) {

err = 2;

return false;

}

intMonth = parseInt(strMonth, 10);

if (isNaN(intMonth)) {

for (i = 0;i<12;i++) {

if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {

intMonth = i+1;

strMonth = strMonthArray[i];

i = 12;

   }

}

if (isNaN(intMonth)) {

err = 3;

return false;

   }

}

intYear = parseInt(strYear, 10);

if (isNaN(intYear)) {

err = 4;

return false;

}

if (intMonth>12 || intMonth<1) {

err = 5;

return false;

}

if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {

err = 6;

return false;

}

if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {

err = 7;

return false;

}

if (intMonth == 2) {

if (intday < 1) {

err = 8;

return false;

}

if (LeapYear(intYear) == true) {

if (intday > 29) {

err = 9;

return false;

   }

}

else {

if (intday > 28) {

err = 10;

return false;

      }

   }

}

return true;

}

function LeapYear(intYear) {

if (intYear % 100 == 0) {

if (intYear % 400 == 0) { return true; }

}

else {

if ((intYear % 4) == 0) { return true; }

}

return false;

}



function show(name,src) {

    if (document.images)

        document.images[name].src = src;

}



// FOR QUERY.HTML



function makeArray() {

    this[0] = makeArray.arguments.length;

    for (i = 0; i<makeArray.arguments.length; i++)

        this[i+1] = makeArray.arguments[i];

}



var accumulate    = new makeArray(0,31,59,90,120,151,181,212,243,273,304,334);

var accumulateLY  = new makeArray(0,31,60,91,121,152,182,213,244,274,305,335);



function LeapYear(year) {

    if ((year/4)   != Math.floor(year/4))   return false;

    if ((year/100) != Math.floor(year/100)) return true;

    if ((year/400) != Math.floor(year/400)) return false;

    return true;

}



function getJulian(day,month,year) {
	//alert(day+'-'+month+'-'+year);
    if (LeapYear(year)){
	//alert(eval(day) + accumulateLY[month]);
        return (eval(day) + accumulateLY[month]);

    }else{

        return (eval(day) + accumulate[month]);
	}
}



function numberOfDays(month,year) {

	var numDays=new Array(0,31,28,31,30,31,30,31,31,30,31,30,31)

	n = numDays[month]

	if(month == 02 && year % 4 == 0) ++n

	return n

}


// Following 2 functions are to determine the number of nights staying on query pg.

// Following 3 functions are to determine the number of nights staying on query pg.

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function daysElapsed(object) {
	var arrMonth = object.ArrMonth.selectedIndex - 1;
	var arrDay = object.ArrDay.selectedIndex;
	var arrYearSelect = object.ArrYear.selectedIndex;
	var arrYear = object.ArrYear.options[arrYearSelect].text;

	var depMonth = object.DepMonth.selectedIndex - 1;
	var depDay = object.DepDay.selectedIndex;
	var depYearSelect = object.DepYear.selectedIndex;
	var depYear = object.DepYear.options[depYearSelect].text;

	var date2 = new Date(arrYear,arrMonth,arrDay);
	var date1 = new Date(depYear,depMonth,depDay);

    var difference =
        Date.UTC(y2k(date1.getYear()),date1.getMonth(),date1.getDate(),0,0,0)
      - Date.UTC(y2k(date2.getYear()),date2.getMonth(),date2.getDate(),0,0,0);
    //return difference/1000/60/60/24;
	
	var nights = difference/1000/60/60/24;

	if(isNaN(nights)){
		nights = 0;
	}

	object.nights.value = nights;
}

function addDays(object) {
	var arrMonth = object.ArrMonth.selectedIndex - 1;
	var arrDay = object.ArrDay.selectedIndex;
	var arrYearSelect = object.ArrYear.selectedIndex;
	var arrYear = object.ArrYear.options[arrYearSelect].text;
	var myDate = new Date(arrYear,arrMonth,arrDay);
	days = object.nights.value;
	newDepDate = new Date(myDate.getTime() + days*24*60*60*1000);
	newDepYear = newDepDate.getYear();
	newDepMonth = newDepDate.getMonth()+1;
	newDepDay = newDepDate.getDate();
	object.DepMonth.selectedIndex = newDepMonth;
	object.DepDay.selectedIndex = newDepDay;
	object.DepYear.options[object.DepYear.selectedIndex].text = newDepYear;
    //alert(newDepMonth+"/"+newDepDay+"/"+newDepYear);
}



function onChangeArr(object,inYear,arrControl) {
	// Month
	if(arrControl == 1){
    	var Current = object.ArrMonth.selectedIndex
	    var currentID = object.ArrMonth.options[Current].text
	    var currentValue = object.ArrMonth.options[Current].value


		totalDays = numberOfDays(currentValue,inYear)

		dcount = 1



		while (dcount <= totalDays){
	
		object.ArrDay.options[dcount] = new Option()

	    object.ArrDay.options[dcount].text = dcount
	
	    object.ArrDay.options[dcount].value = dcount

		++dcount

		}

		var stopDay = totalDays + 1
	
		while( object.ArrDay.options[stopDay] ){  

      		object.ArrDay.options[stopDay] = null;

		}

		object.DepMonth.selectedIndex = Current

	

	 	totalDays = numberOfDays(currentValue,inYear)

		dcount = 1

	 	while (dcount <= totalDays){

	 	object.DepDay.options[dcount] = new Option()

     	object.DepDay.options[dcount].text = dcount
     	object.DepDay.options[dcount].value = dcount

	 	++dcount

		}

	 	var stopDay = totalDays + 1

	 	while( object.DepDay.options[stopDay] ){  

        object.DepDay.options[stopDay] = null;

		}
	}

	// Day
	if(arrControl == 2){
		var Current = object.ArrDay.selectedIndex
		object.DepDay.selectedIndex = Current
	}

	// Year
	if(arrControl == 3){
		var Current = object.ArrYear.selectedIndex
		object.DepYear.selectedIndex = Current
	}



	daysElapsed(object);


}



function onChangeDep(object,inYear) {

    var Current = object.DepMonth.selectedIndex

    var currentID = object.DepMonth.options[Current].text

    var currentValue = object.DepMonth.options[Current].value

	

	totalDays = numberOfDays(currentValue,inYear)

	dcount = 1



	while (dcount <= totalDays){

	object.DepDay.options[dcount] = new Option()

    object.DepDay.options[dcount].text = dcount

    object.DepDay.options[dcount].value = dcount

	++dcount

	}

	var stopDay = totalDays + 1

	while( object.DepDay.options[stopDay] ){  

           		object.DepDay.options[stopDay] = null;

		}



	daysElapsed(object);



}



// function onChangeArrDay(object) {

//	object.DepDay.selectedIndex = object.ArrDay.selectedIndex + 2

// }



function onChangeArrYear(object) {

	object.DepYear.selectedIndex = object.ArrYear.selectedIndex

}


function checkCriteria(object,CritNum){
	var checkedCount = 0;
	var lastValue = "";
	for (var i=0;i<object.elements.length;i++) {
		
		currentValue = object.elements[i].name.substring(0,3);
		
		if (object.elements[i].checked == true && currentValue != lastValue ){
			lastValue = object.elements[i].name.substring(0,3);
			checkedCount++;
		}

		if((object.elements[i].name == 'Name' || object.elements[i].name == 'Address') && object.elements[i].value != ''){
			//lastValue = object.elements[i].name.substring(0,3);
			//checkedCount++;
			checkedCount = 100;
			i=10000;
		}

		//alert("Element: "+i+" value: "+object.elements[i].value+" Name:"+object.elements[i].name);
		
		//lastValue = currentValue;
	}
	
	checkedCount = checkedCount - 1;

	//alert("Checked = " + checkedCount + "Required Checked = " + CritNum);
	
	if(checkedCount >= (CritNum-1)){
		return true;
	}else{
		return false;
	}

}


function validDate(month,day,year){

	month = month-1;

	var test = new Date(year,month,day);

	if ( (test.getFullYear() == year) &&
         (month == test.getMonth()) &&
         (day == test.getDate()) )
        return 1;
    else
        return 0;

}

function dateCheckNew(object,inYear,inMonth,inDay,selectCritNum,page) {
	
	// Following is customization to force user to select a certain number of criteria. The number is defined in the OLConfig - CR 2/11/03
	if(selectCritNum){
		if (checkCriteria(object,selectCritNum)){
    	    //alert("We have a WINNER");
	    }else{
	        alert("Please select three or more categories.");
			return false;
		}
	}

	// END MODIFICATION
	

	if(page == 'hn'){ // for new house page in preview
		page = 'h';
		var arrMonth = 0; var arrDay = 0; var arrYear = 0; var arrYearSelect = 0;
		var depMonth = 0; var depDay = 0; var depYear = 0; var depYearSelect = 0;

		var tmpArrival = object.ArrMonth.value+"/"+object.ArrDay.value+"/"+object.ArrYear.value;
		var tmpDepart = object.DepMonth.value+"/"+object.DepDay.value+"/"+object.DepYear.value;

		// Following checks that date is complete and in correct format. 
		if(!tmpArrival.match(/((^(10|12|0?[13578])([/])(3[01]|[12][0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(11|0?[469])([/])(30|[12][0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(0?2)([/])(2[0-8]|1[0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(0?2)([/])(29)([/])([2468][048]00)$)|(^(0?2)([/])(29)([/])([3579][26]00)$)|(^(0?2)([/])(29)([/])([1][89][0][48])$)|(^(0?2)([/])(29)([/])([2-9][0-9][0][48])$)|(^(0?2)([/])(29)([/])([1][89][2468][048])$)|(^(0?2)([/])(29)([/])([2-9][0-9][2468][048])$)|(^(0?2)([/])(29)([/])([1][89][13579][26])$)|(^(0?2)([/])(29)([/])([2-9][0-9][13579][26])$))/)){
			//alert("BAD Arrival") 
			if(page == 'h'){
				displaySubs('sub1');
				return false;
			}
		}
		if(!tmpDepart.match(/((^(10|12|0?[13578])([/])(3[01]|[12][0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(11|0?[469])([/])(30|[12][0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(0?2)([/])(2[0-8]|1[0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(0?2)([/])(29)([/])([2468][048]00)$)|(^(0?2)([/])(29)([/])([3579][26]00)$)|(^(0?2)([/])(29)([/])([1][89][0][48])$)|(^(0?2)([/])(29)([/])([2-9][0-9][0][48])$)|(^(0?2)([/])(29)([/])([1][89][2468][048])$)|(^(0?2)([/])(29)([/])([2-9][0-9][2468][048])$)|(^(0?2)([/])(29)([/])([1][89][13579][26])$)|(^(0?2)([/])(29)([/])([2-9][0-9][13579][26])$))/)){
			//alert("BAD Depart") 
			if(page == 'h'){
				displaySubs('sub3');
				return false;
			}
		}


		if(tmpArrival != 'mm/dd/yyyy' ){
		
			var arrivalItems = tmpArrival.split('/');
			arrMonth = arrivalItems[0];
			arrDay = arrivalItems[1];		
			arrYearSelect = arrivalItems[2];
			arrYear = arrYearSelect;
	
			var departItems = tmpDepart.split('/');
			depMonth = departItems[0];
			depDay = departItems[1];		
			depYearSelect = departItems[2];
			depYear = depYearSelect;
			//return false;
	
			// check for leading zero
			if(arrMonth.indexOf(0) == 0){
				arrMonth = arrMonth.substr(1);
			}
			if(arrDay.indexOf(0) == 0){
				arrDay = arrDay.substr(1);
			}
	
			if(depMonth.indexOf(0) == 0){
				depMonth = depMonth.substr(1);
			}
			if(depDay.indexOf(0) == 0){
				depDay = depDay.substr(1);
			}
		}
	}else{

		var arrMonth = object.ArrMonth.selectedIndex
		var arrDay = object.ArrDay.selectedIndex
		var arrYearSelect = object.ArrYear.selectedIndex
		var arrYear = object.ArrYear.options[arrYearSelect].text;

		var depMonth = object.DepMonth.selectedIndex
		var depDay = object.DepDay.selectedIndex
		if (object.DepYear.selectedIndex != 0){
			var depYearSelect = object.DepYear.selectedIndex
			var depYear = object.DepYear.options[depYearSelect].text;
		}else{
			var depYear = 0
		}	
	}

	if(page == 'h' && arrYearSelect == 0 || arrMonth == 0 || arrDay == 0) {
		displaySubs('sub1');
		return false;
	}


	if (arrYearSelect != 0 || arrMonth != 0 || arrDay != 0) {
		
		// - 031408 var arrYear = object.ArrYear.options[arrYearSelect].text;

		var arrToJulian = getJulian(arrDay,arrMonth,arrYear)
		var todaysDate = getJulian(inDay,inMonth,inYear)

//alert(arrToJulian+':'+arrMonth+':'+arrDay+':'+arrYear+':'+todaysDate+':'+inMonth+':'+inDay+':'+inYear);

		// - 031408 var depMonth = object.DepMonth.selectedIndex
		// - 031408 var depDay = object.DepDay.selectedIndex
		// - 031408 if (object.DepYear.selectedIndex != 0){
		// - 031408 	var depYearSelect = object.DepYear.selectedIndex
		// - 031408 	var depYear = object.DepYear.options[depYearSelect].text;
		// - 031408 }else{
		// - 031408 	var depYear = 0
		// - 031408 }	


		// Make sure real date selected

		if(validDate(arrMonth,arrDay,arrYear)==0){
			if(page == 'h'){
				displaySubs('sub1');
			}else{
				alert ("You have entered an incorrect ARRIVAL DATE!\nPlease check that you have entered a correct month, day and year.")
			}
			return false;
		}

		if(validDate(depMonth,depDay,depYear)==0){
			if(page == 'h'){
				displaySubs('sub7');
			}else{
				alert ("You have entered an incorrect DEPARTURE DATE!\nPlease check that you have entered a correct month, day and year.")
			}
			return false;
		}
		
		// alert("Arrival: "+arrYear+" "+arrMonth+" "+arrDay+"\nDepart: "+depYear+" "+depMonth+" "+depDay );
		
		// Check that all fields have a value
		if (arrYearSelect <= 0 || arrMonth <= 0 || arrDay <= 0){
			if(page == 'h'){
				displaySubs('sub1');
			}else{
				alert ("You have entered an incorrect ARRIVAL DATE!\nPlease check that you have entered a correct month, day and year.")
			}
			return false;
		}

	 	if (inYear == arrYear && arrToJulian < todaysDate){
			if(page == 'h'){
				displaySubs('sub2');
			}else{
				alert ("You have entered an incorrect Arrival Date! The arrival date chosen is before today's date.")
			}
			return false;
		}
			
		if (depMonth <= 0 || depDay <= 0 || depYear <= 0 ){
			if(page == 'h'){
				displaySubs('sub3');
			}else{
				alert ("You have entered an incorrect departure date.\nPlease check that you have entered a correct month, day and year.");
			}
			return false
		}
		var depToJulian = getJulian(depDay,depMonth,depYear)
		
		if (arrYear > depYear){
			if(page == 'h'){
				displaySubs('sub4');
			}else{
				alert ("You must select a departure date that is after your arrival date!")
			}
				return false
		}

		if (arrYear == depYear){
			if(arrToJulian >= depToJulian){
				if(page == 'h'){
					displaySubs('sub5');
				}else{
					alert ("You must select a departure date that is after your arrival date!")
				}
				return false
			}
			/* Turned off for C21T
			if ( (depToJulian-arrToJulian) > 18){
				alert ("For stays longer then 18 days please contact our office by phone")
				return false
			}
						
			if ( (depToJulian-arrToJulian) < 2){
				alert ("A Minimum of 2 nights stay is required!")
				return false
			}
			*/
		}
		if (arrYear < depYear){
			depToJulian = depToJulian + 365

			if(arrToJulian > depToJulian){
				if(page == 'h'){
					displaySubs('sub6');
				}else{
					alert ("You must select a departure date that is after your arrival date!")
				}
				return false
			}

			/* Turned off for C21T
			if ( (depToJulian-arrToJulian) > 18){
				alert ("For stays longer then 18 days please contact our office by phone")
				return false
			}
			
			if ( (depToJulian-arrToJulian) < 2){
				alert ("A Minimum of 2 nights stay is required!")
				return false
			}
			*/
		}			

	return true
 // alert ("Month:" + arrMonth + "Day:" + arrDay + "Year:" + arrYear + "ArrJulian:" + arrToJulian + "\nMonth:" + depMonth + "Day:" + depDay + "Year:" + depYear + "DepJulian:" + depToJulian);
	}else{
		
		// - 031408 var depMonth = object.DepMonth.selectedIndex
		// - 031408 var depDay = object.DepDay.selectedIndex
		// - 031408 var depYearSelect = object.DepYear.selectedIndex
		

		if (depYearSelect != 0 || depMonth != 0 || depDay != 0) {
			alert ("You have entered a departure date but have not entered a correct arrival date.\nPlease reenter your arrival date.")

			return false

		}


	}
}






// FOR ANY POPUP WINDOWS



function popUp(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);

}



// FOR EXTRANET SECURITY WHEN LOGGING OUT

function go(url) {

//	alert("theurl" + url);
    if (document.images)
		location.replace(url);
    else
        location.href = url;

	var username = "logout";
	var password = "NONE";
	var server = url;
	if (username && password && server) {
		var htsite = "http://" + username + ":" + password + "@" + server;
		window.location = htsite;
	}
	else {
		alert("Problem logging out!");
   }



}

// FOR EXTRANET TO PASS INFO INTO HTACCESS
function Login(form) {
	var username = form.username.value;
	var password = form.password.value;
	var server = form.server.value;
	if (username && password && server) {
		var htsite = "http://" + username + ":" + password + "@" + server + "?UserName=" + username + "-" + password;
		window.location = htsite;
	}
	else {
		alert("Please enter a correct username and password.");
   }
}
// For reservation propcess 2/12/03 CR

function checkAgreement(object){
	//for (var i=0;i<object.elements.length;i++) {

	//alert("Element: "+i+" value: "+object.elements[i].value+" Name:"+object.elements[i].name);

		if (object.elements[22].checked != true && object.elements[23].checked != true){
			alert("Please check whether you accept this agreement or not.")
			return false;
		}
    
		if (object.elements[23].checked){
			//alert ("checked value:"+object.elements[17].value)
			if(confirm("You have chosen not to agree to the terms listed.\nIf this is correct press OK and you will be taken to our property search page.")){
				location.href="query.html";
				return false;
			}else{ return false }
		}
	//}

}



// For Compare Feature

// FOR COMPARISON PAGE

function deleteProp(){
	document.compare.submit();
}

function printProp(controller, prop){
		if(controller == "house"){
			var url = "/book/house.html?print=Y&PMSUnitID="+prop+"&Instruct=Y";
			newWindow = window.open(url,"printpropcompare", "resizable=yes,toolbar=yes,menubar=yes,scrollbars=yes,height=600 width=620");
		
		}
		else{
			var url = "propprint.html?propList=" + document.compare.propList.value +"&Instruct=Y";
			newWindow = window.open(url,"printpropcompare", "resizable=yes,toolbar=yes,menubar=yes,scrollbars=yes,height=600 width=620");
		}
}

function back()
{
	var Mainform = document.forms[0];
	if (Mainform.Previous.value == "")
	{	
		alert("These are the first properties in the list.");
	}
	else
	{
		Mainform.Instruct.value = "N";
		Mainform.Next.value = Mainform.Current.value;
		Mainform.CurrentIndex.value = parseInt(Mainform.CurrentIndex.value) - 3 + ''
		Mainform.submit();
	}
}
	
function next()
{
	var Mainform = document.forms[0];
	if (Mainform.Next.value == "")
	{	
		alert("There are no more properties.");
	}
	else
	{
		Mainform.Instruct.value = "N";
		Mainform.Previous.value = Mainform.Current.value;
		Mainform.CurrentIndex.value = parseInt(Mainform.CurrentIndex.value) + 3 + ''
		Mainform.submit();
	}
}

function closeWindow(){
	window.close()
}

function printInstr(controller){
	if(controller == "house"){
		var Mainform = document.forms[0];
		if (window.print){
    		document.write('<a href="javascript:onClick=window.print()"><img src="/images/comp_but_printb.gif" width="135" height="18" border="0" alt="Print This Page"></a>');
			if (Mainform.Instruct.value == "Y"){
				popUp('/book/printinstruct2.html?Button=Y','PropCompare', 'resizable=yes,toolbar=no,menubar=no,scrollbars=yes,height=250,width=425');
			}
		}else{
			if (Mainform.Instruct.value == "Y"){
				popUp('/book/printinstruct2.html?Button=N','PropCompare', 'resizable=yes,toolbar=no,menubar=no,scrollbars=yes,height=250,width=425');
			}
		}

	}else{
		var Mainform = document.forms[0];
		if (window.print){
    		document.write('<a href="javascript:onClick=window.print()"><img src="/images/comp_but_printb.gif" width="135" height="18" border="0" alt="Print This Page"></a>');
			if (Mainform.Instruct.value == "Y"){
				popUp('/book/printinstruct.html?Button=Y','PropCompare', 'resizable=yes,toolbar=no,menubar=no,scrollbars=yes,height=250,width=425');
			}
		}else{
			if (Mainform.Instruct.value == "Y"){
				popUp('/book/printinstruct.html?Button=N','PropCompare', 'resizable=yes,toolbar=no,menubar=no,scrollbars=yes,height=250,width=425');
			}
		}
	}
}




// FOR ALL Pages - Calls Arrow Graphic to Show ON state of page you are on.

                                   
function MM_SwapOnPage(parms) {
	var imgName = MM_SwapOnPage.arguments[0];
	var imgURL = MM_SwapOnPage.arguments[1];
	while(imgURL.length>0 && imgURL.charAt(0)=='.') {
		imgURL=imgURL.substring(1,imgURL.length);
	}
	var imgObj=MM_findObj(imgName);
	if(imgURL==imgObj.src.substring(imgObj.src.length - imgURL.length,imgObj.src.length)) return;
	var thispage=window.location.href;//.split('?')[0];
	for(var i=2;i<MM_SwapOnPage.arguments.length;i++)	{
		if(thispage.indexOf(MM_SwapOnPage.arguments[i]) >= 0) {
			imgObj.src=imgURL;
			return;
		}
	}
}     

