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 jumpBox(list) {
   location.href = list.options[list.selectedIndex].value
   }

function computeForm(form) {

if(form.principal.value == "" || form.principal.value == 0) {
   alert("Please enter the amount of your loan's principal balance.");
   form.principal.focus();
   } else
if(form.payment.value == "" || form.payment.value == 0) {
   alert("Please enter the amount of your monthly loan payment.");
   form.payment.focus();
   } else
if(form.intRate.value == "" || form.intRate.value == 0) {
   alert("Please enter your loan's annual interest rate.");
   form.intRate.focus();
   } else {


    var pmt1 = form.payment.value;

    var pmt2 = form.payment.value / 2;

    var prin1 = form.principal.value;

    var prin2 = form.principal.value;

    var intPort1 = 0;

    var intPort2 = 0;

    var prinPort1 = 0;

    var prinPort2 = 0;

    var accumInt1 = 0;

    var accumPrin1 = 0;

    var accumInt2 = 0;

    var accumPrin2 = 0;

    var i = form.intRate.value;

    if (i > 1.0) {

        i = i / 100.0;

        

    }

    var i1  = i  / 12;

    var i2 = i / 26;

    var count1 = 0;

    var count2 = 0;

    while(prin1 > 0) {

        intPort1 = prin1 * i1;

        prinPort1 = pmt1 - intPort1;

        prin1 = prin1 - prinPort1;

        accumPrin1 = accumPrin1 + prinPort1;

        accumInt1 = accumInt1 + intPort1;

        count1 = count1 + 1;

     if(count1 > 600) {
        break;
        } else {
        continue;
        }

       }

if(count1 > 600) {
 alert("Using your entered terms you will never pay off this amount.  Please either lower the principal amount, lower the interest rate, or increase the payment amount.;")
        form.origInt.value = "";
        form.biwkInt.value = "";
        form.intSave.value = "";
        form.time.value = "";
        } else {

    form.origInt.value = "$" + formatNum(accumInt1);
    form.origMonths.value = parseInt(count1,10);

    while(prin2 > 0) {

        intPort2 = prin2 * i2;

        prinPort2 = pmt2 - intPort2;

        prin2 = prin2 - prinPort2;

        accumPrin2 = accumPrin2 + prinPort2;

        accumInt2 = accumInt2 + intPort2;

        count2 = count2 + 1;

        if(count1 > 600) {break; } else {continue; }

       }
    
    form.biwkInt.value = "$" + formatNum(accumInt2);
    form.biwkMonths.value = parseInt(count2 /26*12,10);

    form.intSave.value = "$" + formatNum(accumInt1 - accumInt2);
    form.timeSave.value = parseInt(eval(count1) - eval(form.biwkMonths.value));

    form.time.value = "In essence, what you are really doing is adding a 13th payment to your annual number of payments, and splitting it up between 26 bi-weekly payments. Which in your case means that by coughing up and extra $" + parseInt(pmt1 / 26,10) + " every two weeks you will pay off your loan in " + parseInt(count2 /26*12,10) + " months instead of the current " + count1 + " months, and save $" + formatNum(accumInt1 - accumInt2) + " in interest in the process.  Now I ask you, is there anything else you would rather spend your $" + formatNum(accumInt1 - accumInt2) + " on besides interest?";

   }

  }
		
}



function clearForm(form)

{

    form.principal.value = "";

    form.payment.value = "";

    form.intRate.value = "";

    form.intSave.value = "";

    form.origInt.value = "";

    form.biwkInt.value = "";

    form.time.value = "";

}