<!--
Pymnts = 0
Pymnts2 = 0

function checkNumber(input, min, max, msg) {
   msg = msg + " Field Has Invalid Data: " + input.value;
   var str = input.value;
   for (var i = 0; i < str.length; i++) {
      var ch = str.substring(i, i + 1)
      if ((ch < "0" || "9" < ch) && ch != '.') {
         alert(msg);
         return false;
      }
   }
   var num = 0 + str
   if (num < min || max < num) {
      alert(msg + " not in range [" + min + ".." + max + "]");
      return false;
   }
   input.value = str;
   return true;
}

function addInt(form) {
   if (!checkNumber(form.interest, .001, 99, "Current Interest Rate") ) {
      form.curpay.value = "Invalid";
      form.newpay.value = "Invalid";
      form.savings.value = "Invalid";
      return;
   }
   var x = eval(form.interest.value)
   if ( x==0 ) {
      form.interest.value = 8
   }
   else {
      x = x + 0.25
      form.interest.value = x
   }
   computeForm(form)
}

function subInt(form) {
   if (!checkNumber(form.interest, .001, 99, "Current Interest Rate") ) {
      form.curpay.value = "Invalid";
      form.newpay.value = "Invalid";
      form.savings.value = "Invalid";
      return;
   }
   var x = eval(form.interest.value);
   if (x > 1) {
      x = x - 0.25
   }
   form.interest.value = x
   computeForm(form)
}

function addInt2(form) {
   if (!checkNumber(form.interest2, .001, 99, "New Interest Rate") ) {
      form.curpay.value = "Invalid";
      form.newpay.value = "Invalid";
      form.savings.value = "Invalid";
      return;
   }
   var x = eval(form.interest2.value)
   x = x + .25
   form.interest2.value = x
   computeForm(form)
}

function subInt2(form) {
   if (!checkNumber(form.interest2, .001, 99, "New Interest Rate") ) {
      form.curpay.value = "Invalid";
      form.newpay.value = "Invalid";
      form.savings.value = "Invalid";
      return;
   }
   var x = eval(form.interest2.value);
   if (x > 1) {
      x = x - .25
   }
   form.interest2.value = x
   computeForm(form)
}

function addPrin(form) {
   if (!checkNumber(form.principal,
                    100,
                    1000000,
                    "Current Principal Balance")) {
      form.curpay.value = "Invalid";
      form.newpay.value = "Invalid";
      form.savings.value = "Invalid";
      return;
   }
   var x = eval(form.principal.value)
   x = x + 1000
   form.principal.value = x
   computeForm(form)
}

function subPrin(form) {
   if (!checkNumber(form.principal,
                    100,
                    1000000,
                    "Current Principal Balance") ) {
      form.curpay.value = "Invalid";
      form.newpay.value = "Invalid";
      form.savings.value = "Invalid";
      return;
   }
   var x = eval(form.principal.value);
   if (x > 0) {
      x = x - 1000
   }
   form.principal.value = x
   computeForm(form)
}

function addPrin2(form) {
   if (!checkNumber(form.principal2,
                    100,
                    1000000,
                    "New Principal Balance") ) {
      form.curpay.value = "Invalid";
      form.newpay.value = "Invalid";
      form.savings.value = "Invalid";
      return;
   }
   var x = eval(form.principal2.value)
   x = x + 1000
   form.principal2.value = x
   computeForm(form)
}

function subPrin2(form) {
   if (!checkNumber(form.principal2,
       100,
       1000000,
       "New Principal Balance") ) {
      form.curpay.value = "Invalid";
      form.newpay.value = "Invalid";
      form.savings.value = "Invalid";
      return;
   }
   var x = eval(form.principal2.value);
   if (x > 0) {
      x = x - 1000
   }
   form.principal2.value = x
   computeForm(form)
}

function subTerm(form) {
   if ((form.term.value != "30 YEAR") && (form.term.value != "15 YEAR")) {
      msg = "Calculations can only be performed on 15 or 30 Year Loans"
      form.curpay.value = "Invalid";
      form.newpay.value = "Invalid";
      form.savings.value = "Invalid";
      alert(msg);
   }
   else {
      if (form.term.value == "30 YEAR") {
         form.term.value = "15 YEAR"
      }
      else {
         form.term.value = "15 YEAR"
      }
      computeForm(form)
   }
}

function addTerm(form) {
   if ((form.term.value != "30 YEAR") && (form.term.value != "15 YEAR")) {
      msg = "Calculations can only be performed on 15 or 30 Year Loans"
      form.curpay.value = "Invalid";
      form.newpay.value = "Invalid";
      form.savings.value = "Invalid";
      alert(msg);
   }
   else {
      if (form.term.value == "15 YEAR") {
         form.term.value = "30 YEAR"
      }
      else {
         form.term.value = "30 YEAR"
      }
      computeForm(form)
   }
}

function computeForm(form) {
   if ((form.test.value == null || form.test.value == 0) ||
       (form.interest.value == null || form.interest.value.length == 0) ||
       (form.interest2.value == null || form.interest2.value.length == 0) ||
       (form.principal.value == null || form.principal.value.length == 0) ||
       (form.principal2.value == null || form.principal2.value.length == 0))  {
      return;
   }
   if (!checkNumber(form.interest,
                    .001,
                    99,
                    "Current Interest Rate") ||
       !checkNumber(form.principal,
                    100,
                    10000000,
                    "Current Principal Balance") ||
       !checkNumber(form.interest2,
                    .001,
                    99,
                    "New Interest Rate") ||
       !checkNumber(form.principal2,
                    100,
                    10000000,
                    "New Principal Balance")) {
      form.curpay.value = "Invalid";
      form.newpay.value = "Invalid";
      form.savings.value = "Invalid";
      return;
   }
   if ((form.term.value != "30 YEAR") && (form.term.value != "15 YEAR")) {
      form.curpay.value = "Invalid";
      form.newpay.value = "Invalid";
      form.savings.value = "Invalid";
      msg = "Calculations can only be performed on 15 or 30 Year Loans"
      alert(msg);
      return;
   }
   
   var i = form.interest.value;
   if (i >= 1.0) {
      i = i / 100.0;
      //form.interest.value = i;
   }
   i /= 12;
   var pow = 1;
        
   if (form.term.value == "15 YEAR") {
      var T = 180
   }
   else {
      var T = 360
   }
    
   for (var j = 0; j < T; j++)
      pow = pow * (1 + i);
   form.curpay.value = Math.round((form.principal.value * pow * i) / (pow - 1))
   i = form.interest.value;
   if (i < 1.0) {
      i = i * 100.0;
      form.interest.value = i;
   }

   var i = form.interest2.value;
   if (i >= 1.0) {
      i = i / 100.0;
      //form.interest.value = i;
   }
   i /= 12;
   var pow = 1;
           
   for (var j = 0; j < T; j++)
      pow = pow * (1 + i);
   form.newpay.value = Math.round((form.principal2.value * pow * i) / (pow - 1))
   i = form.interest2.value;
   if (i < 1.0) {
      i = i * 100.0;
      form.interest2.value = i;
   }
       
   form.savings.value = eval(form.curpay.value) - eval(form.newpay.value)
}
// -->