

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 <span  style=\"font-weight: bold; color: #339900;\">Monthly Payment</span> for <span style=\"font-weight: bold; color: #155776;\">'+noy+'</span> <span style=\"font-weight: bold; color: #339900;\">Years</span> at an <span style=\"font-weight: bold; color: #339900;\">Interest Rate</span> of <span style=\"font-weight: bold; color: #155776;\">'+interest+'%</span> for a <span style=\"font-weight: bold; color: #339900;\">Loan Amount</span> of <span style=\"font-weight: bold; color: #155776;\">$'+principal+'</span> is <span style=\"font-weight: bold; color: #155776;\">$'+total+'</span> a <span style=\"font-weight: bold; color: #339900;\">Month</span>.'; 
		
		document.getElementById("status").innerHTML = display; 
	
	}
		
}







