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

}



// Use for PopUp Windows

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

  window.open(theURL,winName,features);

}



// EMAIL A FRIEND


function VDS_EmailFriend(theURL,winName,features,propID) {
  var myLocation = location.href;
  var newLoc;
  if(propID.length > 0){
        myLocation = propID;
  }
  if(theURL.indexOf("?") != -1){
        newLoc = theURL + "&REFERER=" + escape(myLocation);
  }else{
        newLoc = theURL + "?REFERER=" + escape(myLocation);
  }
  window.open(newLoc,winName,features);
}


function MM_openBrWindow(theURL,winName,features) { //v3.0

  var myLocation = location.href;

  //alert("Location" + myLocation);

  var newLoc;



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

 

  //alert("newLoc" + newLoc);

  window.open(newLoc,winName,features);

}

function show(name,src) {
    if (document.images)
        document.images[name].src = src;
}

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

			}

		}

	}

}




function closeWindow(){
	window.close()
}

// FOR res-pplus.html

function checkAgreement(object){
	//for (var i=0;i<object.elements.length;i++) {
	//	alert("value: "+object.elements[i].value+" Name:"+object.elements[i].name);

		if (object.elements[18].checked != true && object.elements[19].checked != true){
			alert("Please check whether you accept this agreement or not.")
			return false;
		}
		if (object.elements[19].checked){
			//alert ("checked value:"+object.elements[19].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 resform-pplus.html

// CC Section
function ChkCC( pCard ) {
	var nCheckSum = 0,
		nCardNum = "",
		nDigit,
		RefString = "0246813579";
	
	// remove all extra characters from card number
	for ( var i = 0; i < pCard.length; i++) {
		nDigit = pCard.charAt( i );				// don't optimize
        if ( RefString.indexOf( nDigit ) != -1 )  
			 nCardNum += nDigit;
	}

	for ( i = 2; i <= nCardNum.length; i++ ) {			// dont count last digit
		nDigit = parseInt( nCardNum.charAt( nCardNum.length - i ));		// count backwards
		if ( i % 2 != 1 )			// odd digits get converted
			nDigit = parseInt( RefString.charAt( nDigit ));
		nCheckSum += parseInt( nDigit );
	}

	nDigit = nCheckSum % 10;
	if ( nDigit > 0 )
		nDigit = 10 - nDigit;

	return ( nDigit == nCardNum.charAt( nCardNum.length-1 ));
}

function empty( xtxt ) {
    for (var i=0; i < xtxt.length; i++) {
        if (xtxt.charAt(i) != " ")
			return false;
    }

    return true;
}

function isNum( pstr ) {
    if( pstr.length == 0) return false;
	if( empty( pstr )) return false;
    var RefString="1234567890.";
    for ( var ctr=0; ctr < pstr.length; ctr++) {
        if (RefString.indexOf( pstr.substring(ctr, ctr+1)) == -1 )  
        	return false;
    }

	return true;
}

// CC Section

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported)
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function checkContactInfo(object){
	controller = 0
	warning = "The following corrections are required:\n"
	if (object.FIRST.value==""){
		controller ++
		warning += controller+". Please enter your FIRST NAME.\n"
	}
	if (object.LAST.value==""){
		controller ++
		warning += controller+". Please enter your LAST NAME.\n"
	}
	if (object.EMAIL.value==""){
		controller ++
		warning += controller+". Please enter your EMAIL ADDRESS.\n"
	}else if(object.EMAIL.value!=""){
		var address = object.EMAIL.value;
		var verify = isEmail(address);
	//	alert("verify:"+verify)
		if(verify == 0){
			controller ++
			warning += controller+". You have entered an incorrect EMAIL ADDRESS.\n    Please check the address you have entered.\n"
		}
	}
	if (object.HOMEPHONE.value==""){
		controller ++
		warning += controller+". Please enter your HOME PHONE NUMBER.\n"
	}
	if (object.ADDRESS1.value==""){
		controller ++
		warning += controller+". Please enter your STREET ADDRESS.\n"
	}
	if (object.CITY.value==""){
		controller ++
		warning += controller+". Please enter your CITY.\n"
	}
	if (object.STATE.value==""){
		controller ++
		warning += controller+". Please enter your STATE.\n"
	}
	if (object.ZIP.value==""){
		controller ++
		warning += controller+". Please enter your ZIP/POSTAL CODE.\n"
	}
	if (object.ADULTS.value==""){
		controller ++
		warning += controller+". Please enter the number of ADULTS.\n"
	}
	if (object.CHILDREN.value==""){
		controller ++
		warning += controller+". Please enter the number of CHILDREN.\n"
	}

	//Credit card section

	// Now deal with Credit Card

	//First see if they want to pay via check
	//Checkbox for paying via check needs to be last
	//var checkPay = eval(object.elements.length)-1;
	//alert ("Element:" + object.elements[checkPay].checked);

	if ( empty( object.CCNUMBER.value )) {
		controller ++
		warning += "\n"+controller+". Please provide a Credit Card #";
	} else {
		if ( !ChkCC( object.CCNUMBER.value )){
			controller ++
			warning += "\n"+controller+". Credit Card Number has missing or wrong digits, please check";
		}
	}

	if ( object.CCMONTH.selectedIndex == -1 || object.CCYEAR.selectedIndex == -1 ) {
		controller ++
		warning += "\n"+controller+". Please provide a Credit Card Expiration Date";
	} else {
		// check format of exp date
		var mn = parseInt( object.CCMONTH.options[object.CCMONTH.selectedIndex ].value, 10 );
		var yr = parseInt( object.CCYEAR.options[object.CCYEAR.selectedIndex].value, 10 );
		//                 Ja, Fe, Ma, Ap, Ma, Ju, Ju, Au, Se, Oc, No, De
		//alert("mm "+mn+":yr "+yr);
		if ( mn < 1 || mn > 12 ) {
			controller ++
			warning += "\n"+controller+". Please provide a Credit Card Expiration Date";
		} else {
			var mdays = new Object();
			mdays[1] = 31;
			mdays[2] = 28;
			mdays[3] = 31;
			mdays[4] = 30;
			mdays[5] = 31;
			mdays[6] = 30;
			mdays[7] = 31;
			mdays[8] = 31;
			mdays[9] = 30;
			mdays[10] = 31;
			mdays[11] = 30;
			mdays[12] = 31;
			today = new Date();
			xdate = new Date( yr, mn-1, mdays[mn] );
			if ( today.getTime() > xdate.getTime()){
				controller ++
				warning += "\n"+controller+". Credit Card has Expired, please check and re-enter month/year";
			}
		}

			}

		

			if ( empty( object.CCNAME.value )){

				controller ++

				warning += "\n"+controller+". Please provide a Credit Card Name";

			}


	if (controller > 0){
		alert(warning)
		return false;
	}
}


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

		if(controller == "house"){

			var url = "/book/house.html?print=Y&PMSID="+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");

		}

}


//-->
