/*
  Show mortgage payment for a fixed rate interest for a given number of years

  Input from variables on page:

    loan - loan amount (no $ sign or commas allowed)
    year - number of years amortized
    rate - fixed interest rate

  Output to variables on page:

    pay  - payment amount

*/

function showpay() {
  if ((document.calc.loan.value == null || document.calc.loan.value.length == 0) ||
      (document.calc.year.value == null || document.calc.year.value.length == 0) ||
      (document.calc.rate.value == null || document.calc.rate.value.length == 0))
  {
    document.calc.pay.value = "Incomplete data";
  }
  else
  {
    var princ = document.calc.loan.value;
    var year  = document.calc.year.value;
    var term  = year * 12;
    var intr  = document.calc.rate.value / 1200;
    var payamt = princ * intr / (1 - (Math.pow(1/(1 + intr), term)));
    payamt = Math.round(payamt * 100) / 100;
    document.calc.pay.value = payamt;
  }
/*
  Payment formula is

  payment = principle * monthly interest/(1 - (1/(1+MonthlyInterest)*Months))

*/
}


