// The basics - navigation rollovers 
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];}
}

function update_calendar_form(DDval,MMval,YYval)
{
	document.frmRes.day.selectedIndex = DDval;
	document.frmRes.month.selectedIndex = MMval;
	document.frmRes.year.selectedIndex = YYval;
}

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

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// Used in OLE to close PopUps and return to opening window
function goBack(object){

 if (window.opener && !window.opener.closed){
  window.opener.location = "/book/"+object;
  window.close();
 }	
}




// FOR NEW IMGVIEW.HTML PAGE - swaps images within page
function show(name,src) {
    if (document.images)
        document.images[name].src = src;
}

// FOR QUERY.HTML - primarily for arrival and depart dates checking

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) {
    if (LeapYear(year))
        return (day + accumulateLY[month]);
    else
        return (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
}

function onChangeArr(object,inYear) {
    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;
		}

}

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 + 1
}

function onChangeArrYear(object) {
	object.DepYear.selectedIndex = object.ArrYear.selectedIndex
}

function dateCheck(object,inYear,inMonth,inDay) {
	var arrMonth = object.ArrMonth.selectedIndex
	var arrDay = object.ArrDay.selectedIndex
	var arrYear = object.ArrYear.selectedIndex
	if (arrYear != 0 && arrMonth != 0 && arrDay != 0) {
		arrYear = 2000 + arrYear;
		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 depYear = 2000 + object.DepYear.selectedIndex
		}else{
			var depYear = 0
		}	
	
		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
			}
			if ( (depToJulian-arrToJulian) > 21){
				alert ("For stays longer then 3 weeks please contact our office by phone")
				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
			}

			if ( (depToJulian-arrToJulian) > 21){
				alert ("For stays longer then 3 weeks please contact our office by phone")
				return false
			}
		}

	return true
 // alert ("Month:" + arrMonth + "Day:" + arrDay + "Year:" + arrYear + "ArrJulian:" + arrToJulian + "\nMonth:" + depMonth + "Day:" + depDay + "Year:" + depYear + "DepJulian:" + depToJulian);
	}
}

// END QUERY PAGE - date checking

// 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 = "/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 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');
			}
		}
	}
}

// EMAIL A FRIEND

function MM_openBrWindow(theURL,winName,features) { //v2.0
  var myLocation = location.href;
  var newLoc;

  //newLoc = theURL + "?REFERER=" + myLocation;
  //window.open(newLoc,winName,features);
  if(theURL.indexOf("?") != -1){
	newLoc = theURL + "&REFERER=" + escape(myLocation);
  }else{
	newLoc = theURL + "?REFERER=" + escape(myLocation);
  }
  window.open(newLoc,winName,features);
}

