// JavaScript Document

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


theObjects = document.getElementsByTagName("object"); 
for (var i = 0; i < theObjects.length; i++) { 
theObjects[i].outerHTML = theObjects[i].outerHTML; 
}

// Advanced Map Search Function

function SubmitSearch(){
      var strcity;
      len = document.the_form.tempcity.length;
	i = 0
      j = 0


      if (document.the_form.autosearch_signup.checked == false) {
	for (i = 0; i < len; i++) {
	document.the_form.tempcity[i].selected = true;       
	}
	//document.the_form.submit();
      }

      else if (document.the_form.autosearch_signup.checked == true) {
      	if (ValidateEmail(document.the_form.email.value)) {
		
                for (i = 0; i < len; i++) {
		document.the_form.tempcity[i].selected = true;       
		}

                strcity = document.the_form.tempcity[0].value;
      		for(j=document.the_form.tempcity.length-1;j>=1;j--)
      		{
      		strcity = strcity + ', ' + document.the_form.tempcity[j].value;
      		}

      		strcity = strcity.replace(/Snedens Landing/,"Palisades");
      		document.the_form.city.value = strcity;

      		if (strcity == '0') {
      		strcity = '';
      		}

		// set the autosearch fields...
                document.the_form.autosearch_period.value = '1';
                document.the_form.autosearch_format.value = 'HTML';
                document.the_form.autosearch_length.value = '90';

      		document.the_form.submit();


      	}
		return;
      }


      strcity = document.the_form.tempcity[0].value;
      for(j=document.the_form.tempcity.length-1;j>=1;j--)
      {
      strcity = strcity + ', ' + document.the_form.tempcity[j].value;
      }

      // Correction for Snedens Landing
      strcity = strcity.replace(/Snedens Landing/,"Palisades");
      document.the_form.city.value = strcity;

      if (strcity == '0') {
      strcity = '';
      }
      //document.write(strcity);
      //tempcity = '';
      document.the_form.submit();

}

function AddRemoveProp(i){
	if (document.the_form.hometypes[i].selected) {
		document.the_form.hometypes[i].selected = false; 
	}else{        
		document.the_form.hometypes[i].selected = true; 
	}
}

function ClearDefaultEmail() {

if (document.the_form.email.value == 'Enter Email Address') {
document.the_form.email.value = '';
}

}

// End Advanced Map Search Function




function addOption(selectbox,text,value )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}

function setRentalRange()
{

var i;
for(i=document.form1.minprice.options.length-1;i>=0;i--)
{
document.form1.minprice.remove(i);
document.form1.maxprice.remove(i);
}


if (document.getElementById("hometypes").value == 8) {
addOption(document.form1.minprice, "Minimum","0");
addOption(document.form1.minprice, "$1,000","1000");
addOption(document.form1.minprice, "$1,500","1500");
addOption(document.form1.minprice, "$2,000","2000");
addOption(document.form1.minprice, "$2,500","2500");
addOption(document.form1.minprice, "$3,000","3000");
addOption(document.form1.minprice, "$4,000","4000");
addOption(document.form1.minprice, "$5,000","5000");
addOption(document.form1.minprice, "$10,000","10000");
addOption(document.form1.minprice, "$20,000","20000");

addOption(document.form1.maxprice, "Maximum","0");
addOption(document.form1.maxprice, "$1,000","1000");
addOption(document.form1.maxprice, "$1,500","1500");
addOption(document.form1.maxprice, "$2,000","2000");
addOption(document.form1.maxprice, "$2,500","2500");
addOption(document.form1.maxprice, "$3,000","3000");
addOption(document.form1.maxprice, "$4,000","4000");
addOption(document.form1.maxprice, "$5,000","5000");
addOption(document.form1.maxprice, "$10,000","10000");
addOption(document.form1.maxprice, "$20,000","20000");
}

else
{
addOption(document.form1.minprice, "Minimum","0");
addOption(document.form1.minprice, "$50,000","50000");
addOption(document.form1.minprice, "$100,000","100000");
addOption(document.form1.minprice, "$150,000","150000");
addOption(document.form1.minprice, "$200,000","200000");
addOption(document.form1.minprice, "$250,000","250000");
addOption(document.form1.minprice, "$300,000","300000");
addOption(document.form1.minprice, "$350,000","350000");
addOption(document.form1.minprice, "$400,000","400000");
addOption(document.form1.minprice, "$450,000","450000");
addOption(document.form1.minprice, "$500,000","500000");
addOption(document.form1.minprice, "$550,000","550000");
addOption(document.form1.minprice, "$600,000","600000");
addOption(document.form1.minprice, "$650,000","650000");
addOption(document.form1.minprice, "$700,000","700000");
addOption(document.form1.minprice, "$750,000","750000");
addOption(document.form1.minprice, "$800,000","800000");
addOption(document.form1.minprice, "$850,000","850000");
addOption(document.form1.minprice, "$900,000","900000");
addOption(document.form1.minprice, "$950,000","950000");
addOption(document.form1.minprice, "$1,000,000","1000000");
addOption(document.form1.minprice, "$1,500,000","1500000");
addOption(document.form1.minprice, "$2,000,000","2000000");
addOption(document.form1.minprice, "$2,500,000","2500000");
addOption(document.form1.minprice, "$3,000,000","3000000");
addOption(document.form1.minprice, "$3,500,000","3500000");
addOption(document.form1.minprice, "$4,000,000","4000000");

addOption(document.form1.maxprice, "Maximum","0");
addOption(document.form1.maxprice, "$50,000","50000");
addOption(document.form1.maxprice, "$100,000","100000");
addOption(document.form1.maxprice, "$150,000","150000");
addOption(document.form1.maxprice, "$200,000","200000");
addOption(document.form1.maxprice, "$250,000","250000");
addOption(document.form1.maxprice, "$300,000","300000");
addOption(document.form1.maxprice, "$350,000","350000");
addOption(document.form1.maxprice, "$400,000","400000");
addOption(document.form1.maxprice, "$450,000","450000");
addOption(document.form1.maxprice, "$500,000","500000");
addOption(document.form1.maxprice, "$550,000","550000");
addOption(document.form1.maxprice, "$600,000","600000");
addOption(document.form1.maxprice, "$650,000","650000");
addOption(document.form1.maxprice, "$700,000","700000");
addOption(document.form1.maxprice, "$750,000","750000");
addOption(document.form1.maxprice, "$800,000","800000");
addOption(document.form1.maxprice, "$850,000","850000");
addOption(document.form1.maxprice, "$900,000","900000");
addOption(document.form1.maxprice, "$950,000","950000");
addOption(document.form1.maxprice, "$1,000,000","1000000");
addOption(document.form1.maxprice, "$1,500,000","1500000");
addOption(document.form1.maxprice, "$2,000,000","2000000");
addOption(document.form1.maxprice, "$2,500,000","2500000");
addOption(document.form1.maxprice, "$3,000,000","3000000");
addOption(document.form1.maxprice, "$3,500,000","3500000");
addOption(document.form1.maxprice, "$4,000,000+","99000000");
}

}

function setMinPrice () {
    var i = document.form1.maxprice.selectedIndex;
    if (i > 0 && i < document.form1.minprice.selectedIndex) {
        document.form1.minprice.options[i-1].selected = true;
    }
}

function setMaxPrice () {
    var i = document.form1.minprice.selectedIndex;
    if (i > 0 && i < (document.form1.minprice.length - 1)) {
        if (i > document.form1.maxprice.selectedIndex) {
            document.form1.maxprice.options[i+1].selected = true;
        }
    } else {
        document.form1.maxprice.options[0].selected = true;
    }
}

function setCityString () {
var strCityString = 'Test!';
len = document.form1.city.length;
i = 0


for (i = 0; i < len; i++) {
if (document.form1.city[i].selected) {
strCityString = strCityString + ', ' + document.form1.city[i].value;
}     
}

strCityString = strCityString.replace(/Test!, /,"");
strCityString = strCityString.replace(/Test!/,"");

return strCityString;
}


function popupCMITI (vhometypes,vbedrooms,vbathrooms,vminprice,vmaxprice,vcity,vschool_district) {

var url;

url = 'http://www.cmiti.com/baer/email-popup.asp?hometypes=' + vhometypes + '&bedrooms=' + vbedrooms + '&bathrooms=' + vbathrooms + '&minprice=' + vminprice + '&maxprice=' + vmaxprice + '&city=' + vcity + '&school_district=' + vschool_district;

day = new Date();
id = day.getTime();

eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=600,left = 540,top = 225');");

}


function submitHomepageSearch() {

if (document.form1.hometypes.options[8].selected == true) {
document.form1.waterfront.value = 't';
} 
else {
document.form1.waterfront.value = '';
}

document.form1.submit();

}








