function raisePower(x,y) {
  return Math.pow(x,y)
}

function calculate(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
  var salePrice = ""

 // alert(form.name);

if ((IsBlank(form)==false) && (ValidForm(form)==true))
	{
// LINE 50
// STRIP "$" or ","
	salePrice = StripChars(form.txtSalePrice.value,"$,")
    // alert("sale price: " + form.txtSalePrice.value);
// SalePrice=StripChars(form.txtSalePrice.value, "$,")
// CheckString(SalePrice, "0123456789.")

// alert (form.txtPerFin.value)

// PayPer is number of pay periods = no. of years x 12 months/per year-->
  intPayPer = eval(form.txtPerFin.value * 12)
  intAnnualTaxes = eval(form.txtAnnualTaxes.value)
  intAmtFin = eval(form.txtLoanAmount.value);

  intMonthlyTaxes = intAnnualTaxes/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 -->
// if sale amound - loan amount < 20% sale amount then need pmi
// pmi calculated at .00087 of sale value...
  var intPMI;
  if (salePrice-intAmtFin < intAmtFin*.2) {
    intPMI = Math.round(intAmtFin * .00087);
  } else {
    intPMI = 0;
  }

  intMthPay = intAmtFin * (intMthInt / (1 - intVal))   + intMonthlyTaxes
  var intPI =  Math.round(intAmtFin * (intMthInt / (1 - intVal)));
  var intIns = Math.round(eval(form.txtInsurance.value/12));
  var intHOA = Math.round(eval(form.txtHOA.value/12));
  var intMT = Math.round(intMonthlyTaxes);
  var intMI = Math.round(intIns);
  var intMP = intPI + intMT + intMI + intPMI + intHOA;
  intAnnCost = intMthPay * 12

  document.getElementById('principle_interest').innerHTML = '$' + intPI;
  document.getElementById('property_tax').innerHTML = '$' + intMT;
  document.getElementById('insurance').innerHTML = '$' + intMI;
  document.getElementById('hoadues').innerHTML = '$' + intHOA;
  document.getElementById('pmi').innerHTML = '$' + intPMI;

  document.getElementById('monthly_payment').innerHTML = '$' + intMP;
  document.getElementById('instructions').style.display="none";
  document.getElementById('mrtresults').style.display="block";

  }

  return false;
}

function ClearHome(form) {
  form.txtMthPay.value=""
  form.txtAnnCost.value=""
  form.txtAmtFin.value=""
  form.txtLoanAmount.value="";
}


function IsBlank(form) {
  if (form.txtSalePrice.value=="") {
  alert("Please enter a Sale Price before Calculating")
    form.txtSalePrice.focus()
    return true
  }
  if (form.txtLoanAmount.value=="") {
  alert("Please enter a Loan Amount before Calculating")
    form.txtSalePrice.focus()
    return true
  }
  if (form.txtPerFin.value=="") {
  alert("Please enter the term of the Loan (in years) before Calculating")
	form.txtPerFin.focus()
	return true
  }
  if (form.txtIntRate.value=="") {
  alert("Please enter an Interest Rate before Calculating")
	form.txtIntRate.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.  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.txtIntRate.value,form,'0123456789.') == true)
							OK=true
			else form.txtIntRate.focus()
	else form.txtPerFin.focus()
else form.txtSalePrice.focus()
return OK
}

browserVer=parseInt(navigator.appVersion);
browserName=navigator.appName;
             if (browserName == "Netscape" && browserVer >= 3) version = "3";
             else

             if (navigator.appName.indexOf("Microsoft") != -1 && browserVer >= 2) version = "3";
             else version = "2";


function goLoc(form)
         {
           if (version == "3") {
           var a=document.calcsel.calcsel;}
           if(a.options[a.selectedIndex].value=="")
         {
           if (version == "3") {
                   /*  This Next line left out by RT no error box needed?  */
                   /*  alert("That is NOT a valid option!");               */
                           }
         }
         else
             {
               if (version == "3") {
               location.href=a.options[a.selectedIndex].value;}
             }
           }

