<!--

function raisePower(x,y) {

  return Math.pow(x,y)

}



function CalcHome(form) {



  var intPerFin=0

  var intAmtFin=0  



  var intPayPer = 0

  var intMthPay = 0

  var intMthInt = 0

  var intTotAmt = 0

  var intInterest= 0

  var intLoanAmt = 0

  var intIntRate = 0 

  var intAnnCost = 0

  var intVal = 0

// variables for calculating other home cost

	var intTotOth=0

	var intTotMisc=0

	var intInt=0

	var intTaxRed=0

	var intAppr=0

// variables for calculating annual rent and diff in cost

	var intTotAnnRent=0

 	var intDiff=0

  var intTotHomeCost = 0

// txtSalePrice formatted

	var salePrice = ""

	var strMthRent = ""

// only perform calc if no blank fields and sale price is a valid number

if ((IsBlank(form)==false) && (ValidForm(form)==true))

	{

// STRIP "$" or ","

	salePrice = StripChars(form.txtSalePrice.value,"$,")

// $ and , are fine but must be stripped for calculation

  if (form.radFinType[1].value == "1") {	 

   intPerFin = eval(form.txtPerFin.value / 100)

   intAmtFin = salePrice - eval(salePrice * intPerFin)

  }

  else 					

   intAmtFin = salePrice - eval(form.txtPerFin.value)

// PayPer is number of pay periods = no. of years x 12 months/per year-->

  intPayPer = eval(form.txtTermLoan.value * 12)

// convert interest rate to numerical value -->

  intIntRate = eval(form.txtIntRate.value)

// --calculate mthly interest in decimal form -->

  intMthInt = intIntRate / (12 * 100) 

// -- call raise power function to get parameter for calculation -->

  intVal = raisePower(1+intMthInt, -intPayPer)

// -- calculate mthly payment -->

  intMthPay = intAmtFin * (intMthInt / (1 - intVal))   

  intAnnCost = intMthPay * 12 

	form.txtAmtFin.value = Math.round(intAmtFin)

  form.txtMthPay.value = Math.round(intMthPay)

  form.txtAnnCost.value = Math.round(intAnnCost)

// -- old CalcOther function for other Home Ownership Costs -->

// -- convert interest rate to numerical value -->

  intTotMisc = eval(form.txtPropTax.value) + eval(form.txtInsPrem.value) + eval(form.txtAssnFees.value) + eval(form.txtMaint.value) 	

	intInt = .85 * eval(form.txtAnnCost.value)

	form.txtInt.value = Math.round(intInt)

	intTaxRed = (intInt * form.txtTaxRate.value) / 100

	intAppr = eval(.02 * eval(form.txtAmtFin.value))

	form.txtTaxRed.value = Math.round(intTaxRed)

	intTotOth = eval(form.txtAnnCost.value) - intAppr - intTaxRed 

	form.txtAnnOth.value = Math.round(intTotMisc + intTotOth) 

// -- old CalcDiff function to get Rent vs. Own amount -->

	strMthRent = StripChars(form.txtMthRent.value,"$,")

  intTotAnnRent = eval(strMthRent * 12)

  intTotHomeCost = eval(form.txtAnnOth.value)

	intDiff=intTotAnnRent - intTotHomeCost

	form.txtAnnRent.value = intTotAnnRent

	form.txtDiff.value=intDiff

    }

} // -- end function CalcHOme -->

function ClearHome(form) {

  form.txtSalePrice.value=""

  form.txtPerFin.value=""

  form.txtTermLoan.value=""

  form.txtIntRate.value=""

  form.txtMthPay.value=""

  form.txtAnnCost.value=""

  form.txtAmtFin.value=""

  form.txtPropTax.value=""

  form.txtInsPrem.value=""

  form.txtAssnFees.value=""

  form.txtMaint.value=""

  form.txtTaxRed.value=""

  form.txtAnnOth.value=""

  form.txtTaxRate.value=""

  form.txtInt.value=""

  form.txtMthRent.value=""

  form.txtAnnRent.value=""

  form.txtDiff.value=""

} // end ClearHome

function IsBlank(form) {

  if (form.txtSalePrice.value=="") {

  alert("Please enter a Sale Price before Calculating")

	form.txtSalePrice.focus()

	return true

  } 

  if (form.txtPerFin.value=="") {

  alert("Please enter a percentage or dollar amount financed before Calculating")

	form.txtPerFin.focus()

	return true

  } 

  if (form.txtTermLoan.value=="") {

  alert("Please enter the term of the Loan (in years) before Calculating")

	form.txtTermLoan.focus()

	return true

  } 

  if (form.txtIntRate.value=="") {

  alert("Please enter an Interest Rate before Calculating")

	form.txtIntRate.focus()

	return true

  } 

	if (form.txtPropTax.value=="") {

  alert("Please enter a value or 0 in this field before Calculating")

	form.txtPropTax.focus()

	return true

  } 

	if (form.txtInsPrem.value=="") {

	alert("Please enter a value or 0 in this field before Calculating")

	form.txtInsPrem.focus()

  return true

  } 

	if (form.txtAssnFees.value=="") {

  alert("Please enter a value or 0 in this field before Calculating")

	form.txtAssnFees.focus()

	return true

  }

	if (form.txtMaint.value=="") {

  alert("Please enter a value or 0 in this field before Calculating")

	form.txtMaint.focus()

	return true

  }

	if (form.txtTaxRate.value=="") {

  alert("Please enter a value or 0 in this field before Calculating")

	form.txtTaxRate.focus()

	return true

  } 

	if (form.txtMthRent.value=="") {

  alert("Please enter a Monthly Rental Payment amount before Calculating")

	form.txtMthRent.focus()

	return true

  } 

 return false

}   



function StripChars(inputstring, charstostrip)

{	

	var found=false;

	var returnstring="";

	

	for (var i=0; i<=inputstring.length; i++)

	{

		found=false

		for (var j=0; j<=charstostrip.length; j++)

		{	if (inputstring.charAt(i) == charstostrip.charAt(j))

			{found=true; break}

		// else continue for loop

		}

		if (found==false)

		{	returnstring=returnstring + inputstring.charAt(i)

		}

	// else continue on without adding to string

	}  // for

	return returnstring

} // end StripChars

function CheckField(inputstring,form,validstring)

{	

	var found=false;

	var isValid=true;

//	inputstring=form.elements[x].value;

	for (var i=0; i<=inputstring.length; i++)

	{

		found=false

		for (var j=0; j<=validstring.length; j++)

		{	if (inputstring.charAt(i) == validstring.charAt(j))

			{found=true; break}

		// else continue for loop

		}

		if (found==false)
		{	isValid=false; alert(inputstring.charAt(i) + " is an invalid character for this field.  Please Backspace to remove this character and press Calculate again.");
			 break;
		}

	// else continue on

		}  // for

		return isValid

	} // end CheckField

function ValidForm(form)

{

var OK=false

if (CheckField(form.txtSalePrice.value,form,'0123456789$,') == true)
	if (CheckField(form.txtPerFin.value,form,'0123456789') == true)
		if (CheckField(form.txtTermLoan.value,form,'0123456789') == true)
			if (CheckField(form.txtIntRate.value,form,'0123456789.') == true)
				if (CheckField(form.txtPropTax.value,form,'0123456789') == true)
					if (CheckField(form.txtInsPrem.value,form,'0123456789') == true)
						if (CheckField(form.txtAssnFees.value,form,'0123456789') == true)
							if (CheckField(form.txtMaint.value,form,'0123456789') == true)
								if (CheckField(form.txtTaxRate.value,form,'0123456789') == true)
									if (CheckField(form.txtMthRent.value,form,'0123456789$,') == true)
									OK=true
									else form.txtMthRent.focus()
								else form.txtTaxRate.focus()
							else form.txtMaint.focus()
						else form.txtAssnFees.focus()
					else form.txtInsPrem.focus()
				else form.txtPropTax.focus()
			else form.txtIntRate.focus()
		else form.txtTermLoan.focus()	
	else form.txtPerFin.focus()		
else form.txtSalePrice.focus()

return OK		

}

//-->