/**
* Based on original logic "calculate.js" by Nicole Batten
* Written by CKeen '07
* This function takes a form as a parameter, and uses the fields to calculate the monthlyPayment
* example input:
* <form name="someForm" method="POST">
* <input type="button" name="Calculate" value="Calculate" onClick="monthlyPayment(this.form)">
**/

function monthlyPayment(form){
    var princ = form.loan.value; 
    var princInt = parseFloat(princ);
 	/* restore this to force EU to input a value less than a certian amount.
        if (princInt > 20000) {
		alert ("You must enter in an amount less than $20,000")
	} 
 	else {*/
        var princB = princInt;
        var term  = form.months.value;
        var termInt = parseFloat(term);
        var rate   = form.rate.value 
        var rateInt = parseFloat(rate);
        var intrest = rateInt/100;
        var powerNum = 1 + (intrest/12);
        var negativePower = -1*termInt;
        var powerResult = Math.pow(powerNum,negativePower);
        var payment = (princB * (intrest/12)) / (1 - powerResult);
        //final step rounds off and sticks the value in the field
        form.pay.value = "$"+Math.round(payment*100)/100;
        //form.pay.value = "$"+payment;
	//}  
 }
