<!-- // Hide from stupid browsers

function stripCharacter(words,character) {
	//documentation for this script at http://www.shawnolson.net/a/499/
	  var spaces = words.length;
	  for(var x = 1; x<spaces; ++x){
	   words = words.replace(character, "");   
	 }
	 return words;
}

function JSRecalc( form, downpay )
{

if (downpay == undefined)
downpay = 'notdefined';

LoanAmount= form.LoanAmount.value;
LoanAmount = LoanAmount.replace(/[^0-9 .]+/g,'');

DownPayment = form.DownPayment.value;
DownPayment = DownPayment.replace(/[^0-9 .]+/g,'');

InterestRate = form.InterestRate.value
InterestRate = InterestRate.replace(/[^0-9 .]+/g,'');
AnnualInterestRate = InterestRate/100;

Years = form.NumberOfYears.value;
Years = Years.replace(/[^0-9 .]+/g,'');

MonthRate=AnnualInterestRate/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=addCommas(MonthPayment);
}


function defaultDownPayment(percent) {
	// accepts a percent (as decimal multiplier e.g. .2, not 20 or 20%)
	// recalculates form using down payment which is x% of the listing price
	// this script isn't very portable, but should get the job done -sn
	snLoanAmount = document.getElementById('loanamount').value;
	snLoanAmount = stripCharacter(snLoanAmount,'$');
	snLoanAmount = stripCharacter(snLoanAmount,',');

	newDownPayment = Math.floor(snLoanAmount * percent);
	
	document.getElementById("downpayment").value = newDownPayment;
}

if (typeof(document.getElementById('loanamount')) != "undefined") {
	setTimeout("defaultDownPayment(.2)",1000);
}

function calculateDownPayment(x){
	// Some rmif forms are calling this even though it doesn't exist.
	// this is a do-nothing function that will prevent errors and can be overridden
	// in case it's in use elsewhere in the system.  The previous function and conditional
	// should make this superfluous anyway, but just in case...
	
	return 1;
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d\d\d)/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	if(x2.length == 2) x2 = x2 + "0";
	if(x2.length <= 1) x2 = ".00";
	return x1 + x2;
}


// -->
