
<!--  Hide from non-JavaScript Browsers
//Copyright 1999 - FISI Madison Financial
//All Rights Reserved. May not be copied without express written consent.
//Write to webmaster@fisi.cendant.com
//Programmed by Gregory A. Beamer, webmaster FISI Madison Financial
//Original Program created for Mercantile Trust & Savings Bank

var cost,tax,down,principal,tradein,tradeowe,netcost,rate,term,payment,tester,temp3,temp4,intIndex;
tester=1;

function GBCheckVals() 
{
	//check to see if the amount is correct
	cost = (document.formapp.cost.value);
		if (isNaN(cost)) {
			tester = 0;
			alert("Enter numbers and decimals only.")
			document.formapp.cost.value = ""; 
		}
		if (cost == "") {
			tester = 0;
			alert("Car Cost cannot be empty.")
			document.formapp.cost.value = "";
		}

	//intIndex = document.formapp.tax.selectedIndex;

	tax = document.formapp.tax.value;
		


	down = (document.formapp.down.value);
		if (isNaN(down)) {
			alert("Enter numbers and decimals only.")
			tester = 0;
			document.formapp.down.value = "";
			down = 0;
		}
		if (down == "") {
			down = 0;
		}

	intIndex = document.formapp.rate.selectedIndex;
	rate = (document.formapp.rate.options[intIndex].value);
		/*if (isNaN(rate)) {
			//alert("Enter numbers and decimals only.")
			tester = 0;
			document.formapp.rate.options[intIndex].value = "6.25";
			down = "";
		}*/
		/*if (rate == "") {
			//alert("Interest Rate Cannot Be Empty.")
			tester = 0;
			document.formapp.rate.options[intIndex].value = "";
			rate = "";
		}*/
	intIndex = document.formapp.term.selectedIndex;
	term = (document.formapp.term.options[intIndex].value);
		/*if (isNaN(term)) {
			//alert("Enter numbers and decimals only.")
			tester = 0;
			document.formapp.term.options[intIndex].value = "";
			down = "";
		}
		if (term == "") {
			//alert("Term of Loan Cannot Be Empty.")
			tester = 0;
			document.formapp.term.options[intIndex].value = "";
			rate = "";
		}*/
		
	tradein = (document.formapp.tradein.value);
		if (isNaN(tradein)) {
			alert("Enter numbers and decimals only.")
			tester = 0;
			document.formapp.tradein.value = "";
		}
		if (tradein == "") {
			tradein = 0;
		}

	tradeowe = (document.formapp.tradeowe.value);
		if (isNaN(tradeowe)) {
			alert("Enter numbers and decimals only.")
			tester = 0;
			document.formapp.tradeowe.value = "";
		}
		if (tradeowe == "") {
			tradeowe = 0;
		}		
	
	if (tester == 1) {
		cost = (cost*1);
		tradein = (tradein*1);
		netcost = (cost - tradein);
		
		if (tax > 1.0) {
			tax = (tax/100);
		}
		
		down = (down*1);
		term = (term*1);
		rate = (rate*1);
		tradeowe = (tradeowe*1);
		
		principal = ((netcost+(netcost*tax)) - down + tradeowe);
		document.formapp.principal.value = Math.round(principal);
		GBAddForm(); }
	else tester = 1;		
}

function GBAddForm()
{	
	if (rate > 1.0) {
		rate = (rate/100); }

	//var i = rate;
    	rate /= 12;

    	var raise = 1;
    	for (var calctemp = 0; calctemp < term; calctemp++)
        	raise = raise * (1 + rate);
    	payment = (principal * raise * rate)/(raise - 1);

	var temp1, temp2;
	temp1 = parseInt(payment);
	temp2 = (parseInt((payment - temp1)*100)/100);
	
	payment = ((temp1*1)+(temp2*1))
	
	document.formapp.payment.value = payment;
}

function loadrate(temp3,temp4) 
{
	document.formapp.term.options[intIndex].value = temp3;
	document.formapp.rate.options[intIndex].value = temp4;
	GBCheckVals();
}


//-->

