document.write("<html>");
document.write("<head>");
document.write("<title>House Affordability Calculator</title>");


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

function total_loan_calc(){
	
	var total_loan = document.total_loan.p.value;
	var interest  = document.total_loan.i.value;
	var noy 	  = document.total_loan.noy.value;
	
	if (total_loan == '') { total_loan = '0'; }
	if (interest == '')  { interest = '0'; }
	if (noy == '') 		 { noy = '0'; }
	
	if (total_loan == "0"){ 
		var display = 'Please enter "Loan Amount" field.'; 
		document.getElementById("status").innerHTML = display; 
		}
		
	if (interest == "0"){ 
		var display = 'Please enter "Interest Rate" field.'; 
		document.getElementById("status").innerHTML = display; 
		}
	
	if (noy == "0"){ 
		var display = 'Please enter "Length of Loan" field.'; 
		document.getElementById("status").innerHTML = display; 
		}
		
	if (total_loan != "0" && interest != "0" && noy != "0" ){ 
		var str = total_loan 
		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 ='The monthly repayments based on the above are : $'+total+'<br> (<small>Enter new figures for a new calculation</small>)'; 
		
		document.getElementById("status").innerHTML = display; 
	
	}
		
}
document.write("</script>  \n");

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

 document.write("<form id=\"total_loan\" name=\"total_loan\" method=\"post\" action=\"\"> \n ");
 document.write("<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"210px\" style=\"font-size: 1em; font-family: Arial, Helvetica, sans-serif; background-color: #fff; font-size: .75em; border:4px solid #EBF1FD\"> \n ");
 document.write("<tr> \n ");
 document.write("<td colspan=\"2\" id=\"header\"><a href=\"http://www.selfhelparticles.net/house-afford/\"><img src=\"/mortgage-calculator.gif\" alt=\"House affordability calculator\"  border=\"0\" /></a></td> \n ");
 document.write("</tr><tr><td colspan=\"2\" style=\"background-color: #EBF1FD; font-weight: bold; color: #000080;\">Your Mortgage Information</td> \n ");
 document.write("</tr><tr> \n ");
 document.write("<td width=\"60%\"><b>Loan Amount</b></td><td> \n ");
 document.write("<input name=\"p\" type=\"text\" id=\"p\" value=\"175,000\" size=\"8\" onchange=\"javascript:total_loan_calc();\" /> \n ");
 document.write("</td></tr><tr> \n ");
 document.write("<td width=\"60%\"><b>Interest Rate (%)</b></td><td> \n ");
 document.write("<input name=\"i\" type=\"text\" id=\"i\" value=\"4.50\" size=\"8\" onchange=\"javascript:total_loan_calc();\" /> \n ");
 document.write("</td></tr><tr> \n ");
 document.write("<td width=\"60%\"><b>Loan Term (Years)</td><td> \n ");
 document.write("</b> \n ");
 document.write("<input name=\"noy\" type=\"text\" id=\"noy\" value=\"25\" size=\"3\" maxlength=\"3\" onchange=\"javascript:total_loan_calc();\" /> \n ");
 document.write("</td></tr><tr><td colspan=\"2\"> \n ");
 document.write("<div align=\"center\"> \n ");
 document.write("<input type=\"button\" name=\"button\" id=\"btn\" value=\"Calculate\" onclick=\"javascript:total_loan_calc();\" /> \n ");
 document.write("</div></td></tr> \n ");
 document.write("<tr><td colspan=\"2\" style=\"background-color: #EBF1FD; font-weight: bold; color: #000080;\">Results :</td></tr> \n ");
 document.write("<tr> \n ");
 document.write("<td colspan=\"2\"><div id=\"status\">The monthly repayments based on the above are : $972.71 <br> (<small>Enter new figures for a new calculation</small>)</div></form></td> \n ");
 document.write("</tr> </table> \n ");


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










