// <script>

/* developer: todd watts */
/* file: search.js */
/* function: hold javascript functions for search pages */

/* ********************************************************************* */
/* validate keypress and only allow characters 0 through 9 to be entered */
/* ********************************************************************* */

function NumericValidate() {
 if ((event.keyCode < 48) || (event.keyCode > 57)) event.returnValue = false;
}

/* ********************************************************************* */
/* validate keypress and only allow characters 0 through 9 and the "." to be entered */
/* ********************************************************************* */

function NumericValidate_acreage() {
//var keyclick
// keyclick = event.keyCode
// alert(keyclick);
 if ((event.keyCode < 46) || (event.keyCode > 57) || (event.keyCode == 47)) event.returnValue = false;
}


/* ********************************************************************* */
// used to refresh the forms page to show the correct cities
/* ********************************************************************* */

function CountyRefresh()
{
top.location.href = '/content/home.php?county=' + document.frmSearch.county.options[document.frmSearch.county.selectedIndex].value;
}

function CountyRefresh2()
{
top.location.href = '/content/agent.php?agent_id='+document.frmSearch.agent_id.value+'&agent_page_id=' + document.frmSearch.agent_page_id.value + '&county=' + document.frmSearch.county.options[document.frmSearch.county.selectedIndex].value;
}

function AdvCountyRefresh()
{
location.href = '/content/propertysearch/index.php?county=' + document.frmSearch.county.options[document.frmSearch.county.selectedIndex].value;
}
function AccountsRefresh()
{
top.location.href = '/content/accounts/main.php?county=' + document.frmSearch.county.options[document.frmSearch.county.selectedIndex].value;
}
function AdvRentalRefresh()
{
location.href = '/content/propertysearch/rental.php?county=' + document.frmSearch.county.options[document.frmSearch.county.selectedIndex].value;
}

function BusoCountyRefresh()
{
top.location.href = '/content/propertysearch/buso.php?county=' + document.frmSearch.county.options[document.frmSearch.county.selectedIndex].value;
}

/* ********************************************************************* */
// Validate then the main search form and them submit
/* ********************************************************************* */

function doSubmit() {
	if (document.frmSearch.selSearchArea.value.length==0)
	{
	alert("Please select one or more areas to search.");
	document.frmSearch.selSearchArea.focus();
	return false;
	}

	if (document.frmSearch.txtSearchMinPrice.value.length==0)
	{
	    window.alert("Please enter the low end of the price range you want to search.");
	    document.frmSearch.txtSearchMinPrice.focus();
	    return false;
	}

	if (document.frmSearch.txtSearchMaxPrice.value.length==0)
	{
	    window.alert("Please enter the high end of the price range you want to search.");
	    document.frmSearch.txtSearchMaxPrice.focus();
	    return false;
	}
	maxprice = (document.frmSearch.txtSearchMaxPrice.value);
	minprice = (document.frmSearch.txtSearchMinPrice.value);
	if ((Math.abs(maxprice) <= Math.abs(minprice)) || (maxprice == minprice))
	{
		window.alert("Please make the maximum price range higher than the minimum price range.");
		document.frmSearch.txtSearchMaxPrice.focus();
	    return false;
	}
	return true;
}


/* ********************************************************************* */
// validate the zip search fields
/* ********************************************************************* */

function doSubmitZip() {
	if (document.frmZipSearch.txtSearchZipNumber.value.length < 5)
	{
	    window.alert("Please enter the ZIP code of the area where you want to find homes for sale.");
	    document.frmZipSearch.txtSearchZipNumber.focus();
	    return false;
	}

	if (document.frmZipSearch.txtZipSearchMin.value.length==0)
	{
	    window.alert("Please enter the low end of the price range you want to search.");
	    document.frmSearch.txtSearchMinPrice.focus();
	    return false;
	}

	if (document.frmZipSearch.txtZipSearchMax.value.length==0)
	{
	    window.alert("Please enter the high end of the price range you want to search.");
	    document.frmZipSearch.txtZipSearchMax.focus();
	    return false;
	}
	
	maxprice = (document.frmZipSearch.txtZipSearchMax.value);
	minprice = (document.frmZipSearch.txtZipSearchMin.value);

	if ((Math.abs(maxprice) < Math.abs(minprice)) || (maxprice == minprice))
	{
		window.alert("Please make the maximum price range higher than the minimum price range.");
		document.frmZipSearch.txtZipSearchMax.focus();
	    return false;
	}
	return true;
}


/* ********************************************************************* */
// validate the Refnum search fields
/* ********************************************************************* */

function doSubmitRefnum() {

	if (document.frmRefSearch.txtSearchRefNumber.value.length==0)
	{
	    window.alert("Please enter the reference number you want to search.");
	    document.frmRefSearch.txtSearchRefNumber.focus();
	    return false;
	}
	return true;
}


/* ********************************************************************* */
// get map items and open new window for map
/* ********************************************************************* */

function map(zip,str)
		{
		var URL
		URL = "../maps/default.asp?mapUrl=http://www.mapblast.com/mblast/map.mb%3fCMD=GEO%26GMI=1%26IC=1%26AD2=" + escape(str) + "%26AD3=" + zip + "%26LV=4";
//		URL = "http://www.mapblast.com/mblast/map.mb?CMD=GEO&GMI=1&IC=1&AD2=" + escape(str) + "&AD3=" + zip + "&LV=4";
		window.open(URL, '_blank', 'width=640,height=475,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
		}


/* ********************************************************************* */
// calculate the mortgage
/* ********************************************************************* */

function MortCalc()
{
	form = document.mortgage
	LoanAmount= form.LoanAmount.value
	DownPayment= form.DownPayment.value
	if (DownPayment == "")  
	{
		DownPayment = "0"
	}	

	AnnIR = form.InterestRate.value/100

	Years= form.NumOfYrs.value
	
	MonthRate=AnnIR/12
	NumPayments=Years*12
	Prin=LoanAmount-DownPayment
	
	MonthPayment=Math.floor((Prin*MonthRate)/(1-Math.pow((1+MonthRate),(-1*NumPayments)))*100)/100
	
	form.NumberOfPayments.value=NumPayments
	form.MonthlyPayment.value=MonthPayment

  // Show amortization schedule?
}
function openWindow (url)
{ 
  NewWindow = window.open(url,'moreinfo','toolbar=0,menubar=0,location=0,scrollbars=1,width=500,height=500,RESIZABLE=1');
}