function jumpBox(list) {
   location.href = list.options[list.selectedIndex].value
   }

//<!--license number 13110010--!>


function formatNum(Vnum) {

   if(Vnum > 99000000) {
   alert("Sorry, this will not generate numbers larger that 99 million.");
   focus();
   } else {
   
   var V10million = parseInt(Vnum / 10000000);

   var V1million = (Vnum % 10000000)  / 1000000;
      if(V1million / 1000000 == 1) {
      V1million = 1;
      } else
      if(V1million < 1) {
      V1million = "0";
     } else {
      V1million = parseInt(V1million,10);
     }

    var V100thousand = (Vnum % 1000000)  / 100000;
      if(V100thousand / 100000 == 1) {
      V100thousand = 1;
      } else
      if(V100thousand < 1) {
      V100thousand = "0";
     } else {
      V100thousand = parseInt(V100thousand,10);
     }

   var V10thousand = (Vnum % 100000)  / 10000;
      if(V10thousand / 10000 == 1) {
      V10thousand = 1;
      } else
      if(V10thousand < 1) {
      V10thousand = "0";
      } else {
      V10thousand = parseInt(V10thousand,10);
      }

   var V1thousand = (Vnum % 10000)  / 1000;
      if(V1thousand / 1000 == 1) {
      V1thousand = 1;
      } else
      if(V1thousand < 1) {
      V1thousand = "0";
     } else {
      V1thousand = parseInt(V1thousand,10);
     }

   var Vhundreds = (Vnum % 1000)  / 100;
      if(Vhundreds / 100 == 1) {
      Vhundreds = 1;
      } else
      if(Vhundreds < 1) {
      Vhundreds = "0";
     } else {
      Vhundreds = parseInt(Vhundreds,10);
     }

   var Vtens = (Vnum % 100)  / 10;
      if(Vtens / 10 == 1) {
      Vtens = 1;
      } else
      if(Vtens < 1) {
      Vtens = "0";
     } else {
      Vtens = parseInt(Vtens,10);
     }

   var Vones = (Vnum % 10)  / 1;
      if(Vones / 1 == 1) {
      Vones = 1;
      } else
      if(Vones < 1) {
      Vones = "0";
     } else {
      Vones = parseInt(Vones,10);
     }

  //START UPGRADE
var Vcents = 0;

if(Vnum % 1 * 100 < 1) {
   Vcents = 0;
   } else {
   Vcents = parseInt(((eval(Vnum % 1) * 100)),10);
   }
//END UPGRADE

 if(Vcents < 1) {
  Vcents = "00";
  }
  else
  if(Vcents % 10 == 0) {
  Vcents = Vcents + "0";
  }
  else
  if(Vcents % 10 == Vcents) {
  Vcents = "0" + Vcents;
  } else {
  Vcents = Vcents;
  }

  if(Vcents == "900") {
  Vcents = "90";
  } else
  if(Vcents == "800") {
  Vcents = "80";
  } else 
  if(Vcents == "700") {
  Vcents = "70";
  } else 
  if(Vcents == "600") {
  Vcents = "60";
  } else 
  if(Vcents == "500") {
  Vcents = "50";
  } else 
  if(Vcents == "400") {
  Vcents = "40";
  } else 
  if(Vcents == "300") {
  Vcents = "30";
  } else
  if(Vcents == "200") {
  Vcents = "20";
  } else
  if(Vcents == "100") {
  Vcents = "10";
  } else {
  Vcents = Vcents;
  }

   
   var Vformat = "";

   if(Vnum >= 10000000) {
   Vformat = (V10million + "" + V1million + "," + V100thousand + "" + V10thousand + "" + V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones + "." + Vcents);
   }
   else
   if(Vnum >= 1000000) {
   Vformat = (V1million + "," + V100thousand + "" + V10thousand + "" + V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones + "." + Vcents);
   }
   else
   if(Vnum >= 100000) {
   Vformat = (V100thousand + "" + V10thousand + "" + V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones + "." + Vcents);
   }
   else
   if(Vnum >= 10000) {
   Vformat = (V10thousand + "" + V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones + "." + Vcents);
   }
   else
   if(Vnum >= 1000) {
   Vformat = (V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones + "." + Vcents);
   }
   else
   if(Vnum >= 100) {
   Vformat = (Vhundreds + "" + Vtens + "" + Vones + "." + Vcents);
   }
   else
   if(Vnum >= 10) {
   Vformat = (Vtens + "" + Vones + "." + Vcents);
   }
   else
   if(Vnum >= 1) {
   Vformat = (Vones + "." + Vcents);
   } else {
   Vformat = ("0." + Vcents);
   }

  return Vformat;

  }
}

function getMissing(form) {

var filled = 0;


//195

if(form.principal.value.length > 0) {
   filled = filled + 1;
   }
if(form.interest.value.length > 0) {
   filled = filled + 1;
   }
if(form.payments.value.length > 0) {
   filled = filled + 1;
   }
if(form.payment.value.length > 0) {
   filled = filled + 1;
   }
if(filled < 3) {
   alert("Three of the four fields must contain a value in order to calculate the missing loan term.");
clearTerms(form);
   } else {
//213

if(form.principal.value.length > 0) {
   Vprincipal = eval(form.principal.value);
   } else {
   Vprincipal = 0;
   }
if(form.interest.value.length > 0) {
   Vinterest = eval(form.interest.value);
   } else {
   Vinterest = 0;
   }
if(form.payments.value.length > 0) {
  Vpayments = eval(form.payments.value);
   } else {
   Vpayments = 0;
   }
if(form.payment.value.length > 0) {
  Vpayment = eval(form.payment.value);
   } else {
   Vpayment = 0;
   }

if(Vprincipal > 0 && Vinterest > 0 && Vpayments > 0 && Vpayment > 0) {
   alert("One empty field please.");
   } else
if(form.payment.value == "" || form.payment.value == 0) {
    getPmt(form);
    } else
if(form.principal.value == "" || form.principal.value == 0) {
    getPrin(form);
    } else
if(form.payments.value == "" || form.payments.value == 0) {
    getPmts(form);
    } else
if(form.interest.value == "" || form.interest.value == 0) {
    getInt(form);
    }

 }

}


function getPmt(form) {

var i = form.interest.value;
  if (i > 1.0) {
  i = i / 100.0;
  }
  i /= 12;

var noMonths = form.payments.value;
var pow = 1;

for (var j = 0; j < noMonths; j++)
    pow = pow * (1 + i);

var Rpayment = (Vprincipal * pow * i) / (pow - 1);

form.termAmt.value = "$" + formatNum(Rpayment);
form.termName.value = "Monthly Payment:";

}


function getPrin(form) {

var i = form.interest.value;
  if (i > 1.0) {
  i = i / 100.0;
  }
  i /= 12;

var noMonths = form.payments.value;
var pow = 1;

for (var j = 0; j < noMonths; j++)
    pow = pow * (1 + i);

var Rprincipal = ((pow - 1) * Vpayment) / (pow * i);

form.termAmt.value = "$" + formatNum(Rprincipal);
form.termName.value = "Principal Balance:";

}

function getPmts(form) {

var i = form.interest.value;
  if (i > 1.0) {
  i = i / 100.0;
  }
  i /= 12;

var prin = form.principal.value;
var count = 0;
var prinPort = 0;
var intPort = 0;
var pmt = form.payment.value;

while(eval(prin) > eval(pmt)) {
   intPort = prin * i;
   prinPort = pmt - intPort;
   prin = prin - prinPort;
   count = count +1;
   }

var Rcount = count;
var pmtPart = parseInt(prin / pmt * 100, 10);

form.termAmt.value = Rcount + "." + pmtPart;
form.termName.value = "Payments Remaining:";

}

function getInt(form) {

var prin = form.principal.value;
var pmt = form.payment.value;
var nPer = form.payments.value;
var count = 0;
var intPort = 0;
var prinPort = 0;
if(form.intGuess.selectedIndex == 0) {
   var i = .10;
   } else {
   var i = eval(form.intGuess.selectedIndex) + eval(3);
   if(i > 1) {
      i = i /100
      }
   }
var i2 = i / 12;
var iterate = 0;

while(count < nPer) {
   intPort = prin * i2;
   prinPort = pmt - intPort;
   prin = prin - prinPort;
   count = count +1;
   if(count == nPer && prin < -1) {
      prin = form.principal.value;
      count = 0;
      i = i + .0001;
      i2 = i / 12;
      } else
   if(count == nPer && prin > 1) {
      prin = form.principal.value;
      count = 0;
      i = i - .0001;
      i2 = i / 12;
      } else {
      prin = prin;
      count = count;
      i2 = i2;
      }
   
  iterate = iterate + 1;
//   if(iterate > 10000) {
//      break;
//      } else {
//      continue;
//      }
   }

i = i * 100;

form.termAmt.value = i;
//form.termAmt.value = iterate;
form.termName.value = "Interest Rate:";

}

function clearPrin(form) {

    form.principal.value = "";
}

function clearInt(form) {

    form.interest.value = "";
}

function clearPmts(form) {

    form.payments.value = "";
}

function clearPmt(form) {

    form.payment.value = "";
}

function clearTerms(form) {

    form.termAmt.value = "";
    form.termName.value = "";
}



function clearForm(form)

{

    form.payments.value = "";

    form.interest.value = "";

    form.principal.value = "";

}