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

  var defObj = selObj.options[selObj.selectedIndex].value;

  	eval(targ+".location='" + defObj + "'");

  	if (restore) selObj.selectedIndex=0;

}


function jumpMenu_new(name,selObj){ //v3.0

  var defObj = selObj.options[selObj.selectedIndex].value;

	parent.location.href=defObj
}



// FOR ANY POPUP WINDOWS

function popUp(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


// EMAIL A FRIEND

function MM_openBrWindow(theURL,winName,features) { //v3.0
	features += "resizable=yes,toolbar=yes,menubar=yes,scrollbars=yes";

  var myLocation = location.href;

  //alert("Location" + myLocation);

  var newLoc;

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

  //alert("newLoc" + newLoc);

  window.open(newLoc,winName,features);

}

// checkContactInfo - used to check the dropdown on the property pages.
function checkContactInfo(object){
	controller = 0
	warning = "The following corrections are required:\n"
	if (object.Weekend.value=="Any"){
		controller ++
		warning += controller+". Please enter an arrival date.\n"
	}
	if (object.Stay.value=="Any"){
		controller ++
		warning += controller+". Please enter a length of stay.\n"
		
	}
	if (controller > 0){
		alert(warning)
		return false;
	}

}

// PRINTPROP
function printPropH(controller, prop, proptype, complexnum){
	

		if(controller == "house"){

			var url = "/book/house.html?print=Y&pn="+prop+"&cn="+complexnum+"&Type="+proptype+"&Instruct=Y";

			newWindow = window.open(url,"printpropcompare", "resizable=yes,toolbar=yes,menubar=yes,scrollbars=yes,height=600 width=620");

		

		}

		else{

			var url = "/book/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 printProp(controller, prop, proptype, complexnum){
	

		if(controller == "house"){

			var url = "/book/house.html?print=Y&pn="+prop+"&cn="+complexnum+"&Type="+proptype+"&Instruct=Y";

			newWindow = window.open(url,"printpropcompare", "resizable=yes,toolbar=yes,menubar=yes,scrollbars=yes,height=600 width=620");

		

		}

		else{

			var url = "/book/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 preview_printPropH(controller, prop, proptype, complexnum){

                if(controller == "house"){

                        var url = "/book/house.html?print=Y&pn="+prop+"&cn="+complexnum+"&Type="+proptype+"&Instruct=Y";

                        newWindow = window.open(url,"printpropcompare", "resizable=yes,toolbar=yes,menubar=yes,scrollbars=yes,height=600 width=620");



                }
		else if(controller == "baywatchresorts")
		{
                        var url = "/book/baywatchresorts.html?print=Y&pn="+prop+"&cn="+complexnum+"&Type="+proptype+"&Instruct=Y";
                        newWindow = window.open(url,"printpropcompare", "resizable=yes,toolbar=yes,menubar=yes,scrollbars=yes,height=600 width=620");
		}
                else{

                        var url = "/book/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");

                }

}


// FOR COMPARISON PAGE



function deleteProp(){

	document.compare.submit();

}





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');

			}

		}

	}

}







//########################################ADDEDD 1/17/03
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 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) { //v3.0

  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); 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];}

}



/* Original Turned Off
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 LeapYear(intYear) {

	if ((intYear % 4) == 0) {
        	if (intYear % 100 == 0) {
            		if (intYear % 400 == 0) { 
                		return true; 
			}
			else{
		   		return false;
			}
        	}
        	else{ return true; }
    	}
    	else {
         	return false; 
    	}
	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 getJulian(day,month,year) {

    if (LeapYear(year))

        return (day + accumulateLY[month]);

    else

        return (day + accumulate[month]);

}

/* Original
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
}
*/

function numberOfDays(month,year) {

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

	n = numDays[month]

	//alert ("N ="+n+" Month="+month+" year="+year);
	if(month == 02){
		 if(year % 4 == 0){
			if(year % 100 == 0){
				if(year % 400 == 0){
					++n;
				}
				else{ 
					return n; 
				}
			}
			else{ 
				++n; 
			}
		}
		else{
			return n
		}
	}

	return n;

}


function MN_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



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;
		}



}

function onChangeArrDay(object) {
	object.DepDay.selectedIndex = object.ArrDay.selectedIndex + 7
}



function onChangeArr(object,inYear,inMonth,currentArrIndex,currentDepIndex) {
    var Current = object.ArrMonth.selectedIndex
    var currentID = object.ArrMonth.options[Current].text
    var currentValue = object.ArrMonth.options[Current].value

	//alert(currentArrIndex + " \ ");

	if(inMonth >= 03){
		inYear = inYear+1;
	}
	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;
		}

	//alert(Current);
	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;
		}

	// For year changes so day does not change
	object.ArrDay.selectedIndex = currentArrIndex
	object.DepDay.selectedIndex = currentDepIndex
}


function onChangeArrYear(object) {

	object.DepYear.selectedIndex = object.ArrYear.selectedIndex
	var currentYear = object.ArrYear.options[object.ArrYear.selectedIndex].value
	var currentArrIndex = object.ArrDay.selectedIndex
	var currentDepIndex = object.DepDay.selectedIndex
	onChangeArr(object,currentYear,'',currentArrIndex,currentDepIndex)
	

}


// CHECK TYPE SELECTED ON QUERY PAGE
function typeCheck(object){

    var CurrentType = object.Type.selectedIndex
    var currentTypeTxt = object.Type.options[CurrentType].text
    var currentTypeValue = object.Type.options[CurrentType].value

	//alert("HELLO");

	if(currentTypeValue == ""){
		alert("You must select a Type of Property, either House or Condo!");
		return false;
	}
	return true;


}


// Following is for checking if Sat or Sun in Summer Seasons

var daysofweek = new makeArray('Sunday',
                               'Monday',
                               'Tuesday',
                               'Wednesday',
                               'Thursday',
                               'Friday',
                               'Saturday')

function DayOfWeek(day,month,year) {
	var a = Math.floor((14 - month)/12);
    var y = year - a;
    var m = month + 12*a - 2;
    var d = (day + y + Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400) + Math.floor((31*m)/12)) % 7;

    return d+1;
}


function dateCheck(object,inYear,inMonth,inDay,formName) {

	// MODIFICATIONS DONE TO THIS TO CHECK OTHER AREAS OF QUERY
	

	// Check for unit type if on query form
	if(formName == "query"){
		var TypeCheck = typeCheck(object);
		if(TypeCheck == 0){
			return false;
		}
	}



	var arrMonth = object.ArrMonth.selectedIndex
	var arrDay = object.ArrDay.selectedIndex
	var arrYearSelect = object.ArrYear.selectedIndex
	if (arrYearSelect != 0 || arrMonth != 0 || arrDay != 0) {
		
		var arrYear = object.ArrYear.options[arrYearSelect].text;
		var arrToJulian = getJulian(arrDay,arrMonth,arrYear)
		var todaysDate = getJulian(inDay,inMonth,inYear)

		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
		}	
		
		 //alert("Arrival: "+arrYear+" "+arrMonth+" "+arrDay+"\nDepart: "+depYear+" "+depMonth+" "+depDay );
		
		// Check that all fields have a value
		if (arrYearSelect <= 0 || arrMonth <= 0 || arrDay <= 0){
			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){
			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 ){
			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){
				alert ("You must select a departure date that is after your arrival date!")
				return false
		}

		if (arrYear == depYear){
			if(arrToJulian >= depToJulian){
				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){
				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
			}
			*/
		}


		// Check Summer months for weekly stays and start day of Sat or Sun
		if(arrMonth == 6 || arrMonth == 7 || arrMonth == 8){
			var errMessage = "";
			if ( (depToJulian-arrToJulian) % 7 != 0){
				errMessage += "A weekly stay is required during June, July, & August!\n"
				//return false
			}

			// Check that they have chosen a Sat date
			dayNum = DayOfWeek(arrDay,arrMonth,arrYear)
			dayReal = daysofweek[dayNum]
			//alert(dayReal)

			if(dayReal != "Saturday" && dayReal != "Sunday"){
				errMessage += "\nYou must select a Saturday or Sunday arrival day in June, July, & August.\nYou selected an arrival day of "+dayReal+". Please select a Saturday or Sunday date."
				//return false;
			}

			if(errMessage != ""){
				alert(errMessage);
				return false;
			}
			
		}
			

	return true
 // alert ("Month:" + arrMonth + "Day:" + arrDay + "Year:" + arrYear + "ArrJulian:" + arrToJulian + "\nMonth:" + depMonth + "Day:" + depDay + "Year:" + depYear + "DepJulian:" + depToJulian);
	}else{
		
		var depMonth = object.DepMonth.selectedIndex
		var depDay = object.DepDay.selectedIndex
		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

		}


	}
}

function preview_dateCheck(object,inYear,inMonth,inDay,formName) {

	// MODIFICATIONS DONE TO THIS TO CHECK OTHER AREAS OF QUERY

	// Check for unit type if on query form
	if(formName == "query"){
		var TypeCheck = typeCheck(object);
		if(TypeCheck == 0){
			return false;
		}
	}

	var arrMonth = object.ArrMonth.selectedIndex
	var arrDay = object.ArrDay.selectedIndex
	var arrYearSelect = object.ArrYear.selectedIndex
	if (arrYearSelect != 0 || arrMonth != 0 || arrDay != 0) {
		
		var arrYear = object.ArrYear.options[arrYearSelect].text;
		var arrToJulian = getJulian(arrDay,arrMonth,arrYear)
		var todaysDate = getJulian(inDay,inMonth,inYear)

		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
		}	
		
		 //alert("Arrival: "+arrYear+" "+arrMonth+" "+arrDay+"\nDepart: "+depYear+" "+depMonth+" "+depDay );
		
		// Check that all fields have a value
		if (arrYearSelect <= 0 || arrMonth <= 0 || arrDay <= 0){
			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){
			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 ){
			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){
				alert ("You must select a departure date that is after your arrival date!")
				return false
		}

		if (arrYear == depYear){
			if(arrToJulian >= depToJulian){
				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){
				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
			}
			*/
		}


		// Check Summer months for weekly stays and start day of Sat or Sun
		if(arrMonth == 6 || arrMonth == 7 || arrMonth == 8){
			var errMessage = "";
			if ( (depToJulian-arrToJulian) % 7 != 0){
				errMessage += "A weekly stay is required during June, July, & August!\n"
				//return false
			}

			// Check that they have chosen a Sat date
			dayNum = DayOfWeek(arrDay,arrMonth,arrYear)
			dayReal = daysofweek[dayNum]
			//alert(dayReal)

			if(dayReal != "Saturday" && dayReal != "Sunday"){
				errMessage += "\nYou must select a Saturday or Sunday arrival day in June, July, & August.\nYou selected an arrival day of "+dayReal+". Please select a Saturday or Sunday date."
				//return false;
			}

			if(errMessage != ""){
				alert(errMessage);
				return false;
			}
			
		}
			

	return true
 // alert ("Month:" + arrMonth + "Day:" + arrDay + "Year:" + arrYear + "ArrJulian:" + arrToJulian + "\nMonth:" + depMonth + "Day:" + depDay + "Year:" + depYear + "DepJulian:" + depToJulian);
	}else{
		
		var depMonth = object.DepMonth.selectedIndex
		var depDay = object.DepDay.selectedIndex
		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 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.");
   }
}

// Clears forms on page
function myFormClear(what) {
    for (var i=0, j=what.elements.length; i<j; i++) {
        myType = what.elements[i].type;
		//alert("What:"+what.elements[i]+"Type: "+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 checkEditor(object){
	var descLength='';
	descLength = object.description.value;
	
	if(descLength.length > 750){
		var valDesc = descLength.length;
		alert("You have entered too many characters ("+valDesc+") into the desciption. Please correct and resubmit.");
		return false;
	}
	else{  return true; }

}

