
document.write("<html>");
document.write("<head>");
document.write("<title>Auto Loan Calculator Widget</title>");
/*
document.write("<style>");
document.write("td {font-size: 12px; text-align:center; } \n ");
document.write("p.calc {font: 12px Arial #000; text-align:center; } \n ");
document.write("form { margin: 0; padding: 0; }  \n");
document.write("input { border: 1px solid #000; background-color: #fff; margin-top: 5px; } \n " );
document.write("#btn { background-color: #155776; color: #fff; }  \n");
document.write(".hot { font-weight: normal; color: #155776; }  \n");
document.write(".key { font-weight: normal; color: #339900; }  \n");
document.write("</style>  \n");
*/

document.write("<script>  \n");

function principal_calc(){
	
	var principal = document.principal.p.value;
	var interest  = document.principal.i.value;
	var noy 	  = document.principal.noy.value;
	
	if (principal == '') { principal = '0'; }
	if (interest == '')  { interest = '0'; }
	if (noy == '') 		 { noy = '0'; }
	
	if (principal == "0"){ 
		var display = 'Please fill "Loan Amount" field.'; 
		document.getElementById("status").innerHTML = display; 
		}
		
	if (interest == "0"){ 
		var display = 'Please fill "Interest Rate" field.'; 
		document.getElementById("status").innerHTML = display; 
		}
	
	if (noy == "0"){ 
		var display = 'Please fill "Length of Loan" field.'; 
		document.getElementById("status").innerHTML = display; 
		}
		
	if (principal != "0" && interest != "0" && noy != "0" ){ 
		var str = principal 
		var a = (str.replace(/,/, "")) 
		var t_years = eval(noy*12) 
		var t_interest = eval(interest/1200); 
		var t = eval(1.0 /(Math.pow((1+t_interest),t_years))); 
			
			if(t < 1){ 
				var payment = eval((a*t_interest)/(1-t)); 
			} else { 
				var payment = eval(amt/$t_years); 
			} 
			
		var total = payment.toFixed(2); 
		var display ='Your payment is <br><span style=\"font-weight: bold; color: #155776;\">$'+total+'</span> per month.'; 
		
		document.getElementById("status").innerHTML = display; 
	
	}
		
}
document.write("</script>  \n");

 //document.write("</head>");
 //document.write("<body>");

 document.write("<form id=\"principal\" name=\"principal\" method=\"post\" action=\"\"> \n ");
 document.write("<td width=\"40%\"><div align=\"center\"><p class=\"calc\">Loan Amount ($)<br /> \n ");
 document.write("<input name=\"p\" type=\"text\" id=\"p\" value=\"15,000\" size=\"10\" onchange=\"javascript:principal_calc();\" /> \n ");
 document.write("</p></div></td> \n ");
 document.write("</tr> \n ");
 document.write("<tr> \n ");
 document.write("<td width=\"40%\"><div align=\"center\"><p class=\"calc\">Interest Rate (%)<br /> \n ");
 document.write("<input name=\"i\" type=\"text\" id=\"i\" value=\"8.50\" size=\"10\" onchange=\"javascript:principal_calc();\" /> \n ");
 document.write("</p></div></td> \n ");
 document.write("</tr> \n ");
 document.write("<tr> \n ");
 document.write("<td width=\"40%\"><div align=\"center\"><p class=\"calc\">Length of Loan (Yrs)<br /> \n ");
 document.write("<input name=\"noy\" type=\"text\" id=\"noy\" value=\"6\" size=\"3\" maxlength=\"3\" onchange=\"javascript:principal_calc();\" /> \n ");
 document.write("</p></div></td> \n ");
 document.write("</tr> \n ");
 document.write("<tr> \n ");
 document.write("<td> \n ");
 document.write("<div align=\"center\"> \n ");
 document.write("<input type=\"button\" name=\"button\" id=\"btn\" value=\"Calculate\" onclick=\"javascript:principal_calc();\" /> <br/><br/> \n ");
 document.write("</div></td></tr> \n ");
 document.write("<tr> \n ");
 document.write("<td><div id=\"status\" align=\"center\"></div></td> \n ");
 document.write("</tr> </table></form> \n ");


 //document.write("</body>");
 //document.write("</html>");










