

//--------------------------all javascript functions---------------------

function go_back()
 {
  window.history.go(-1); 
 }

function print_win()
 {
  window.print();
 }
 
function makePopUp(whereTo, winWidth, winHeight) 
 {
  remote = window.open("","remotewin","width="+winWidth+",height="+winHeight+",menubar=0,toolbar=no,scrollbars=yes,resizable=1");
  remote.location.href = whereTo; 
  remote.focus();
 }
 
function mort_calc(LP,LN)
{
  remote = window.open("","remotewin","width=250,height=325,menubar=0,toolbar=no,scrollbars=yes");
  remote.location.href = "pop_mort_calc.asp?LP="+LP+"&LN="+LN; 
  remote.focus();
 }

function submit_form(form_name, form_action)
 {
  window.document.forms[form_name].action = form_action; 
  window.document.forms[form_name].submit(); 
 }
 
function close_win()
 {
  window.close(); 
 }
 
//--price updates on searches--

function PriceChanged(id)//id-which changed
	{
		var minSelectedIndex = document.getElementById('ddlLP_min').selectedIndex;
		var maxSelectedIndex = document.getElementById('ddlLP_max').selectedIndex;
		if(id == "ddlLP_min" && parseInt(minSelectedIndex) >= parseInt(maxSelectedIndex))
		{
			if(minSelectedIndex < (document.getElementById('ddlLP_max').length-2))
				document.getElementById('ddlLP_max').selectedIndex = minSelectedIndex + 1;
			else
				document.getElementById('ddlLP_max').selectedIndex = document.getElementById('ddlLP_max').length-1;
		}
		else
			if(id == "ddlLP_max" && parseInt(maxSelectedIndex) <= parseInt(minSelectedIndex))
			{
				if(parseInt(maxSelectedIndex) > 0)
					document.getElementById('ddlLP_min').selectedIndex = maxSelectedIndex-1;
				else
					document.getElementById('ddlLP_min').selectedIndex = 0;
			}
	}


 
//--quotes--


function set_quote()
{

 arQuotes= new Array();
	 
	 arQuotes[0] = "Search for Chicago Real Estate." 
                   + " <a href='/re/default.aspx'>View thousands of listings now</a>.";
                   
     arQuotes[1] = "Looking for a mortgage?  Use our <a href='/mortgage.aspx'>mortgage area</a>" 
                   + " for more information."
                   
     arQuotes[2] = "Home buyers tax credit extended to April 2010. <a href='/contact.aspx'>Learn more</a>."
     
     arQuotes[3] = "Get a <a href='/CMA.aspx'>analysis</a> of your current home value with a CMA report."

var strAt_home_info = "<br/><br/><div style='font-size:12pt;'>Martello Realty Groups commitment is to our clients," +
                       " serving their best interests throughout and after the real estate transaction." +
                       " As an advisor to you during your home purchase or sale, the Martello Realty" +
                       " Group works to makes our clients satisfied.<br/><br/>" + 
                        " By serving as your agent when you purchase your home, the Martello Realty" +
                        " Group will work step-by-step with you to locate your perfect house.<br/><br/>By" +
                        " representing solely you, the buyer, you can feel assured that your interests" +
                        " are being protected as there is no conflict of interest. This undivided loyalty," +
                        " along with the confidentiality and full disclosure our agents provide, separate" +
                        " Martello Realty Group from our competitors. Also, more than three quarters of our" +
                        " licensed real estate agents are Accredited Buyer Representative certified.</div><br/><br/>" 

document.getElementById('div_quote').innerHTML= arQuotes[ select_quote() ] + "\n\n" + strAt_home_info;

if (document.getElementById('mapDiv')) 
 {
   initMap();
 }
 
if(document.getElementById('map_canvas_c'))
 {
   initialize();
 }
 
}

var maxHeaders = 4; 

function select_quote() 
 {
 
	var randomInt = Math.floor(Math.random() * maxHeaders);

	return randomInt;
 }


//--area textboxes--

function AddList_new() {
	SL = document.frmSearch.lbAreas;
	ARs = document.frmSearch.lbAreasSelected;
		
	if (SL.selectedIndex==-1) {
		alert('Please make a selection first');
		return false;
	}
	
	for (i=0;i<ARs.length;i++) {
	 if (ARs.options[i].value == SL.options[SL.selectedIndex].value) 
		return false;
	}	

	switch (ARs.length) {
	case 1:
	    if (ARs.options[0].text == "[All Areas]")
			ARs.options[0] = null;
		break;
	case 10:
		alert('Only ten areas are allowed for this search');
		return false;
		break;
	}
	
	if (SL.selectedIndex ==0) {
		
		for(i=0;i<ARs.length;) {
			ARs.options[0] = null;  // eliminate all entries if "All Areas" is selected
		}
	}
	
	ARs.options[ARs.length] = new Option(SL.options[SL.selectedIndex].text,SL.options[SL.selectedIndex].value);
	
	var intSelected = SL.selectedIndex;
	
	document.getElementById('cblSub_' + intSelected ).checked=true;
	return true;
}


function RemList_new() {
  ARs = document.frmSearch.lbAreasSelected;

if (ARs.length > 0 && ARs.selectedIndex != -1) // -1 indicates no selection
	
	   var intValue = ARs.options[ARs.selectedIndex].value;
	   document.getElementById('cblSub_' + intValue ).checked=false;
   
	ARs.options[ARs.selectedIndex] = null;
	
return true;

}



//--------------------------search functions--------------------------------
//-------old searches, still used on the leads landing page-----------------
//------------------suburban clicks between text areas----------------------

function SubmitSearchForm() {  // Called from search page
  
    ARs = document.frmSearch.areas;
	temp = "";
	for (i=0;i<ARs.length;i++) {  // save area selected
	  if(ARs.options[i].value != '') {   //if area not [all areas]
		temp += ARs.options[i].value + ",";
		}
	}
	document.frmSearch.AR.value = temp.substr(0,temp.length-1); //get rid of last comma
	document.frmSearch.submit();
	return false;
 }

function AddList() {
	SL = document.frmSearch.AreaList;
	ARs = document.frmSearch.areas;	
	if (SL.selectedIndex==-1) {
		alert('Please make a selection first');
		return false;
	}
	for (i=0;i<ARs.length;i++) {
	 if (ARs.options[i].value == SL.options[SL.selectedIndex].value) 
		return false;
	}	

	switch (ARs.length) {
	case 1:
	    if (ARs.options[0].text == "[All Areas]")
			ARs.options[0] = null;
		break;
	case 10:
		alert('Only five areas are allowed for this search');
		return false;
		break;
	}
	
	if (SL.selectedIndex ==0) {
		
		for(i=0;i<ARs.length;) {
			ARs.options[0] = null;  // eliminate all entries if "All Areas" is selected
		}
	}
	
	ARs.options[ARs.length] = new Option(SL.options[SL.selectedIndex].text,SL.options[SL.selectedIndex].value);
	return true;
}

function RemList() {
  ARs = document.frmSearch.areas;

if (ARs.length > 0 && ARs.selectedIndex != -1) // -1 indicates no selection
	ARs.options[ARs.selectedIndex] = null;
return true;
}


//-----------------------------end search start page------------------------------- 


   
   
//------------------------------mortgage calculator--------------------------------


function mortgage()
{
form = document.test
dnpmt=form.DownPayment.value
Price= form.Price.value
perc = (dnpmt/100) * Price
prin= Price-perc
tax=Math.floor(form.Taxes.value / 12)
assess=Math.floor(form.Assessment.value)
extra= tax+assess
intRate = (form.InterestRate.value/100) / 12
Term= form.Term.value * 12
MonthPayment=Math.floor((prin*intRate)/(1-Math.pow((1+intRate),(-1*Term)))*100)/100
form.Principle.value=MonthPayment
form.MonthlyTax.value=tax
form.MonthlyAssessment.value=assess
form.MonthlyPayment.value=MonthPayment + extra
}
function Calculate()
{
form = document.test
dnpmt=form.DownPayment.value
Price= form.Price.value
perc = (dnpmt/100) * Price
prin= Price-perc
tax=Math.floor(form.Taxes.value / 12)
assess=Math.floor(form.Assessment.value)
extra= tax+assess
intRate = (form.InterestRate.value/100) / 12
Term= form.Term.value * 12
MonthPayment=Math.floor((prin*intRate)/(1-Math.pow((1+intRate),(-1*Term)))*100)/100
form.Principle.value=MonthPayment
form.MonthlyTax.value=tax
form.MonthlyAssessment.value=assess
form.MonthlyPayment.value=MonthPayment + extra
}



//-----------------------swamp images on LN details pages-------------------------

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];}
}


// --> 






