// JavaScript Document


function calc() {
    var principal = document.forms[1].principal.value;
    var rate = document.forms[1].rate.value / 100 / 12;
    var num_payments = document.forms[1].years.value * 12;
    var exponent = Math.pow(1 + rate, num_payments);
    var pmt = (principal*exponent*rate)/(exponent-1);
        if (!isNaN(pmt) &&
        (pmt != Number.POSITIVE_INFINITY) &&
        (pmt != Number.NEGATIVE_INFINITY)) {
        document.form1.payment.value = round(pmt);
        document.form1.total.value = round(pmt * num_payments)
        document.form1.totalrate.value =
            round((pmt * num_payments) - principal);
    }
    else {
        document.form1.payment.value = "-";
        document.form1.total.value = "-";
        document.form1.totalrate.value = "-";
    }
}
function round(x) {
  return Math.round(x*100)/100;
}
function set_focus(){
document.forms[0].payment.focus();
}


