//Copyright 1999 - FISI Madison Financial







//All Rights Reserved. May not be copied without express written consent.







//Write to webmaster@fisi-madison.com















var cost,tax,down,downtemp1,downtemp2,principal,points,pointsamount,closecost,rate,term,payment;







var tester,temp1,temp2,temp3,temp4,temp5;







var cc1,cc2,cc3,cc4,cc5,cc6,cc7,cc8,cc9,cc10,cc11,cctemp1,cctemp2,cctotal,closetemp1,closetemp2;







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("Sales Price cannot be empty.")







			document.formapp.cost.value = "";







		}















	amountfinanced = (document.formapp.amountfinanced.value);







		if (isNaN(amountfinanced)) {







			tester = 0;







			alert("Enter numbers and decimals only.")







			document.formapp.amountfinanced.value = 80; 







		}







		if (amountfinanced == "") {







			tester = 0;







			alert("Amount Financed is 80, 90 or 95.")







			document.formapp.amountfinanced.value = 80;







		}







		if ((amountfinanced*1) < 1) {







			tester = 0;







			alert("Amount Financed is 80, 90 or 95.")







			document.formapp.amountfinanced.value = 80;







		}















	points = (document.formapp.points.value);







		if (isNaN(points)) {







			tester = 0;







			alert("Enter numbers and decimals only.")







			document.formapp.points.value = 0; 







		}







		if (points == "") {







			tester = 0;







			alert("Points cannot be empty.")







			document.formapp.points.value = 0;







		}















	rate = (document.formapp.rate.value);







		if (isNaN(rate)) {







			alert("Enter numbers and decimals only.")







			tester = 0;







			document.formapp.rate.value = 7.625;







		}







		if (rate == "") {







			alert("Interest Rate Cannot Be Empty.")







			tester = 0;







			document.formapp.rate.value = 7.625;







		}















	term = (document.formapp.term.value);







		if (isNaN(term)) {







			alert("Enter numbers and decimals only.")







			tester = 0;







			document.formapp.term.value = 360;







		}







		if (term == "") {







			alert("Term of Loan Cannot Be Empty.")







			tester = 0;







			document.formapp.term.value = 360;







		}















		cc1 = document.formapp.cc1.value;







		cc2 = document.formapp.cc2.value;







		cc3 = document.formapp.cc3.value;







		cc4 = document.formapp.cc4.value;







		cc5 = document.formapp.cc5.value;







		//cc6 = document.formapp.cc6.value;







		cc7 = document.formapp.cc7.value;







		//cc8 = document.formapp.cc8.value;







		//cc9 = document.formapp.cc9.value;







		//cc11 = document.formapp.cc11.value;























	if (tester == 1) {







		amountfinanced = (amountfinanced*1);







		







		//***** figure down payment







		downpercent = ((100 - amountfinanced)/100);







		down = ((cost*1) * (downpercent*1));















		//round to nearest cent







		downtemp1 = parseInt(down);







		downtemp2 = parseInt((down - downtemp1)*100);







		down = (downtemp1 + (downtemp2/100));















		document.formapp.down.value = down;







		//***** end figure down payment







		







		//figure principal







		principal = ((cost*1) - (down*1));







		document.formapp.principal.value = principal;















		//***** figure 15 days interest







		rate = (rate/100);







		cc10 = (((principal * rate)/365)*15);







		







		//round to nearest cent







		cctemp1 = parseInt(cc10);







		cctemp2 = parseInt((cc10 - cctemp1)*100);







		cc10 = (cctemp1 + (cctemp2/100));







		document.formapp.cc10.value = cc10;







		//***** end figure 15 days interest















		//figure cost of points







		points = (points/100);







		pointsamount = ((principal*1)*(points*1));















		//****** figure closing costs







		cctotal = ((cc1*1)+(cc2*1)+(cc3*1)+(cc4*1)+(cc5*1)+(cc7*1)+(cc10*1));







		closecost = (pointsamount + cctotal + down);















		//round to nearest cent







		closetemp1 = parseInt(closecost);







		closetemp2 = parseInt((closecost - closetemp1)*100);







		closecost = (closetemp1 + (closetemp2/100));















		document.formapp.closecost.value = closecost;







		//****** end figure closing costs







		







		GBAddForm();			







	}















		







}















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 GBloadrate(temp3,temp4,temp5) 







{







	document.formapp.term.value = temp4;







	document.formapp.rate.value = temp3;







	document.formapp.points.value = temp5;







	GBCheckVals();







}

















