function calculateA() {
  var price = parseNumber(document.Mortgage.salesPrice.value);
  var downpmt = parseNumber(document.Mortgage.downPayment.value);
  var rate = parseNumber(document.Mortgage.annualInterestRate.value);
  var years = parseNumber(document.Mortgage.numberOfYears.value);
  var loanamt = price - downpmt;
  var nopmts = years*12;
  var morate = rate/1200;
  var mopmt = Math.round((loanamt*(morate/(1-Math.pow((1+morate), -nopmts))))*100)/100;
  document.Mortgage.loanAmount.value = commify(loanamt);
  document.Mortgage.numberOfPayments.value = commify(nopmts);
  document.Mortgage.monthlyPrincipleAndInterestPayment.value = commify(mopmt);
}
function calculateB()
{
  var PI = parseNumber(document.Mortgage.monthlyPrincipleAndInterestPayment.value);
  var SP = parseNumber(document.Mortgage.salesPrice.value);
  var LA = parseNumber(document.Mortgage.loanAmount.value);
  var MHIR = parseNumber(document.Mortgage.estimatedAnnualHomeownersInsuranceRate.value)/12;
  var MPTR = parseNumber(document.Mortgage.estimatedAnnualPropertyTaxRate.value)/12;
  var MHAF = parseNumber(document.Mortgage.estimatedMonthlyHomeownersAssociationFees.value)/12;
  var LTV = Math.round(100*LA/SP)/100;
  var J = 0;
  if((LTV <= .97) && (LTV >= .9501)) 
  {
    J = Math.round(LA * .9 / 12)/100; 
  }  
  else if((LTV <= .95) && (LTV >= .9001))
  {
    J = Math.round(LA * .78 / 12)/100;
  }
  else if((LTV <= .9) && (LTV >= .8501))
  {
    J = Math.round(LA * .52 / 12)/100;
  }
  else if((LTV <= .85) && (LTV >= .8001))
  {
    J = Math.round(LA * .32 / 12)/100;
  }
  document.Mortgage.totalEstimatedMonthlyPayment.value = commify(PI + J + MHAF + MHIR + MPTR );
}
function parseNumber(value)
{
  value = new String(value);
  value = value.replace(/[^0-9.]/g,"");
  if(value.length == 0)
  {
    return 0;
  }
  return parseFloat(value);
}
function commify(value)
{
  value = new String(value);
  value = reverse(value);
  value = value.replace(/(ddd)/,"$1,");
  value = value.replace(/,$/,"");
  return reverse(value);
}
function reverse(value)
{
  value = new String(value);
  var i;
  var reversed = new String();
  for(i = value.length-1; i >= 0; i--)
  {
    reversed = reversed.concat(value.charAt(i));
  }
  return reversed;
}

function formsystem_family(){
	document.search_home.price.options[0]=null;
	document.search_home.price.options[1]=null;
	document.search_home.price.options[2]=null;
	document.search_home.price.options[3]=null;
	document.search_home.price.options[4]=null;
	document.search_home.price.options[5]=null;
	document.search_home.price.options[6]=null;
	if(document.search_home.price.options[7]){
		document.search_home.price.options[7]=null;
	}
	document.search_home.price.options[0]=new Option('Any','any');
	document.search_home.price.options[1]=new Option('25,000 - 1,000,000','25');
	document.search_home.price.options[2]=new Option('1,000,000 - 1,500,000','1000');
	document.search_home.price.options[3]=new Option('1,500,000 - 2,000,000','1500');
	document.search_home.price.options[4]=new Option('2,000,000 - 5,000,000','2000');
	document.search_home.price.options[5]=new Option('5,000,000 - 10,000,000','5000');
	document.search_home.price.options[6]=new Option('10,000,000 - 20,000,000','10000');
}
function formsystem_condos(){
	document.search_home.price.options[0]=null;
	document.search_home.price.options[1]=null;
	document.search_home.price.options[2]=null;
	document.search_home.price.options[3]=null;
	document.search_home.price.options[4]=null;
	document.search_home.price.options[5]=null;
	document.search_home.price.options[6]=null;
	if(document.search_home.price.options[7]){
		document.search_home.price.options[7]=null;
	}
	document.search_home.price.options[0]=new Option('Any','any');
	document.search_home.price.options[1]=new Option('25,000 - 500,000','25');
	document.search_home.price.options[2]=new Option('500,000 - 1,000,000','500');
	document.search_home.price.options[3]=new Option('1,000,000 - 1,500,000','1000');
	document.search_home.price.options[4]=new Option('1,500,000 - 2,000,000','1500');
	document.search_home.price.options[5]=new Option('2,000,000 - 5,000,000','2000');
	document.search_home.price.options[6]=new Option('5,000,000 - 10,000,000','5000');
	document.search_home.price.options[7]=new Option('10,000,000 - 20,000,000','10000');
}
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;
}
