<!-- Hide from old browsers
// Copyright (C) 2001-2007 AngelicHost
// All rights reserved

function doBalloon() {
  initVars();
  
  term = parseInt(document.balloon.term.value);
  pmts = parseInt(document.balloon.payments.value);
  prin = ahparseFloat(document.balloon.principle.value);
  rate = ahparsePercent(document.balloon.rate.value);
  addlPmt = ahparseFloat(document.balloon.addlprin.value);
  freq = document.balloon.addlfreq.value;
  
  if(isNaN(prin) || prin <= 0 || document.balloon.principle.value.length==0) {
    alert("Please enter a loan amount.  Do not include any characters that are not numbers");
    document.balloon.principle.focus();
    document.balloon.principle.select();
    return
  }
  
  if(isNaN(term) || term <= 0 || document.balloon.term.value.length==0) {
    alert("Please Enter a value for the length of the loan");
    document.balloon.term.focus();
    document.balloon.term.select();
    return
  }
  
  if(isNaN(pmts) || pmts < 0 || document.balloon.payments.value.length==0) {
    alert("Please enter a value for the number of payments made");
    document.balloon.payments.focus();
    document.balloon.payments.select();
    return
  }
  
  if(isNaN(rate) || rate <= 0 || document.balloon.rate.value.length==0) {
    alert("Please enter the interest rate");
    document.balloon.rate.focus();
    document.balloon.rate.select();
    return
  }
  
  if(document.balloon.addlfreq.value != "N" && (isNaN(addlPmt) || addlPmt <=0 || document.balloon.addlprin.value.length==0)) {
    alert("Please enter a value for the additional payment amount, or set additional payment frequency to None");
    document.balloon.addlprin.focus();
    document.balloon.addlprin.select();
    return
  }
  
  if(pmts>(term*12)) {
    alert("Number of payments can't be more than the life of the loan!");
    document.balloon.payments.focus();
    document.balloon.payments.select();
    return
  }
  
  pmt = calcPmt(rate,term*12,prin);
  bal = calcBalance();
  document.balloon.balance.value=fmtCurr(bal);
}
//-->

