
//By Daniel C. Peterson, 1999  All Rights Reserved.
//This script may not be copied or redistributed without express
//written permission from Daniel C. Peterson of Web Winder Website Services.
//For commercial use rates please visit http://www.webwinder.com
//or send email to:  webmaster@webwinder.com.
// Commercial User Fee: #13039909

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 calcInt(p,i) {

if(i >= 1) {
   i = i / 100;
}

i = i /12;

var moInt = p * i

return moInt;
}



function computeForm(form) {

var accumPrin = 0;
var accumInt = 0;
var debtCount = 0;

//LINE #1
if(form.prin1.value > 0 || form.prin1.value != "") {
var debt1int = calcInt(eval(form.prin1.value),eval(form.IntRate1.value));
form.intCost1.value = formatNum(debt1int);
accumPrin = eval(accumPrin) + eval(form.prin1.value);
accumInt = eval(accumInt) + eval(debt1int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin2.value > 0 || form.prin2.value != "") {
var debt2int = calcInt(eval(form.prin2.value),eval(form.IntRate2.value));
form.intCost2.value = formatNum(debt2int);
accumPrin = eval(accumPrin) + eval(form.prin2.value);
accumInt = eval(accumInt) + eval(debt2int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin3.value > 0 || form.prin3.value != "") {
var debt3int = calcInt(eval(form.prin3.value),eval(form.IntRate3.value));
form.intCost3.value = formatNum(debt3int);
accumPrin = eval(accumPrin) + eval(form.prin3.value);
accumInt = eval(accumInt) + eval(debt3int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin4.value > 0 || form.prin4.value != "") {
var debt4int = calcInt(eval(form.prin4.value),eval(form.IntRate4.value));
form.intCost4.value = formatNum(debt4int);
accumPrin = eval(accumPrin) + eval(form.prin4.value);
accumInt = eval(accumInt) + eval(debt4int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin5.value > 0 || form.prin5.value != "") {
var debt5int = calcInt(eval(form.prin5.value),eval(form.IntRate5.value));
form.intCost5.value = formatNum(debt5int);
accumPrin = eval(accumPrin) + eval(form.prin5.value);
accumInt = eval(accumInt) + eval(debt5int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin6.value > 0 || form.prin6.value != "") {
var debt6int = calcInt(eval(form.prin6.value),eval(form.IntRate6.value));
form.intCost6.value = formatNum(debt6int);
accumPrin = eval(accumPrin) + eval(form.prin6.value);
accumInt = eval(accumInt) + eval(debt6int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin7.value > 0 || form.prin7.value != "") {
var debt7int = calcInt(eval(form.prin7.value),eval(form.IntRate7.value));
form.intCost7.value = formatNum(debt7int);
accumPrin = eval(accumPrin) + eval(form.prin7.value);
accumInt = eval(accumInt) + eval(debt7int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin8.value > 0 || form.prin8.value != "") {
var debt8int = calcInt(eval(form.prin8.value),eval(form.IntRate8.value));
form.intCost8.value = formatNum(debt8int);
accumPrin = eval(accumPrin) + eval(form.prin8.value);
accumInt = eval(accumInt) + eval(debt8int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin9.value > 0 || form.prin9.value != "") {
var debt9int = calcInt(eval(form.prin9.value),eval(form.IntRate9.value));
form.intCost9.value = formatNum(debt9int);
accumPrin = eval(accumPrin) + eval(form.prin9.value);
accumInt = eval(accumInt) + eval(debt9int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin10.value > 0 || form.prin10.value != "") {
var debt10int = calcInt(eval(form.prin10.value),eval(form.IntRate10.value));
form.intCost10.value = formatNum(debt10int);
accumPrin = eval(accumPrin) + eval(form.prin10.value);
accumInt = eval(accumInt) + eval(debt10int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin11.value > 0 || form.prin11.value != "") {
var debt11int = calcInt(eval(form.prin11.value),eval(form.IntRate11.value));
form.intCost11.value = formatNum(debt11int);
accumPrin = eval(accumPrin) + eval(form.prin11.value);
accumInt = eval(accumInt) + eval(debt11int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin12.value > 0 || form.prin12.value != "") {
var debt12int = calcInt(eval(form.prin12.value),eval(form.IntRate12.value));
form.intCost12.value = formatNum(debt12int);
accumPrin = eval(accumPrin) + eval(form.prin12.value);
accumInt = eval(accumInt) + eval(debt12int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin13.value > 0 || form.prin13.value != "") {
var debt13int = calcInt(eval(form.prin13.value),eval(form.IntRate13.value));
form.intCost13.value = formatNum(debt13int);
accumPrin = eval(accumPrin) + eval(form.prin13.value);
accumInt = eval(accumInt) + eval(debt13int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin14.value > 0 || form.prin14.value != "") {
var debt14int = calcInt(eval(form.prin14.value),eval(form.IntRate14.value));
form.intCost14.value = formatNum(debt14int);
accumPrin = eval(accumPrin) + eval(form.prin14.value);
accumInt = eval(accumInt) + eval(debt14int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin15.value > 0 || form.prin15.value != "") {
var debt15int = calcInt(eval(form.prin15.value),eval(form.IntRate15.value));
form.intCost15.value = formatNum(debt15int);
accumPrin = eval(accumPrin) + eval(form.prin15.value);
accumInt = eval(accumInt) + eval(debt15int);
debtCount = eval(debtCount) + eval(1);
}

form.totalPrin.value = formatNum(accumPrin);
form.totalInt.value = formatNum(accumInt);
form.avgRate.value = formatNum(accumInt / accumPrin * 12 * 100) + "%";
}


function ClearForm(form)  {
   
form.Debt1.value = "";
form.prin1.value = "";
form.IntRate1.value = "";
form.intCost1.value = "";
form.Debt2.value = "";
form.prin2.value = "";
form.IntRate2.value = "";
form.intCost2.value = "";
form.Debt3.value = "";
form.prin3.value = "";
form.IntRate3.value = "";
form.intCost3.value = "";
form.Debt4.value = "";
form.prin4.value = "";
form.IntRate4.value = "";
form.intCost4.value = "";
form.Debt5.value = "";
form.prin5.value = "";
form.IntRate5.value = "";
form.intCost5.value = "";
form.Debt6.value = "";
form.prin6.value = "";
form.IntRate6.value = "";
form.intCost6.value = "";
form.Debt7.value = "";
form.prin7.value = "";
form.IntRate7.value = "";
form.intCost7.value = "";
form.Debt8.value = "";
form.prin8.value = "";
form.IntRate8.value = "";
form.intCost8.value = "";
form.Debt9.value = "";
form.prin9.value = "";
form.IntRate9.value = "";
form.intCost9.value = "";
form.Debt10.value = "";
form.prin10.value = "";
form.IntRate10.value = "";
form.intCost10.value = "";
form.Debt12.value = "";
form.prin12.value = "";
form.IntRate12.value = "";
form.intCost12.value = "";
form.Debt13.value = "";
form.prin13.value = "";
form.IntRate13.value = "";
form.intCost13value = "";
form.Debt14.value = "";
form.prin14.value = "";
form.IntRate14.value = "";
form.intCost14.value = "";
form.Debt15.value = "";
form.prin15.value = "";
form.IntRate15.value = "";
form.intCost15.value = "";

form.totalInt.value = "";
form.totalPrin.value = "";
form.avgRate.value = "";
}

function formatNum_fr(Vnum) {

   if(Vnum > 99000000) {
   alert("Nous sommes désolés, l'opération telle que demandée générera des montants qui excéderont 99 millions.");
   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 computeForm_fr(form) {

var accumPrin = 0;
var accumInt = 0;
var debtCount = 0;

//LINE #1
if(form.prin1.value > 0 || form.prin1.value != "") {
var debt1int = calcInt(eval(form.prin1.value),eval(form.IntRate1.value));
form.intCost1.value = formatNum_fr(debt1int);
accumPrin = eval(accumPrin) + eval(form.prin1.value);
accumInt = eval(accumInt) + eval(debt1int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin2.value > 0 || form.prin2.value != "") {
var debt2int = calcInt(eval(form.prin2.value),eval(form.IntRate2.value));
form.intCost2.value = formatNum_fr(debt2int);
accumPrin = eval(accumPrin) + eval(form.prin2.value);
accumInt = eval(accumInt) + eval(debt2int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin3.value > 0 || form.prin3.value != "") {
var debt3int = calcInt(eval(form.prin3.value),eval(form.IntRate3.value));
form.intCost3.value = formatNum_fr(debt3int);
accumPrin = eval(accumPrin) + eval(form.prin3.value);
accumInt = eval(accumInt) + eval(debt3int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin4.value > 0 || form.prin4.value != "") {
var debt4int = calcInt(eval(form.prin4.value),eval(form.IntRate4.value));
form.intCost4.value = formatNum_fr(debt4int);
accumPrin = eval(accumPrin) + eval(form.prin4.value);
accumInt = eval(accumInt) + eval(debt4int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin5.value > 0 || form.prin5.value != "") {
var debt5int = calcInt(eval(form.prin5.value),eval(form.IntRate5.value));
form.intCost5.value = formatNum_fr(debt5int);
accumPrin = eval(accumPrin) + eval(form.prin5.value);
accumInt = eval(accumInt) + eval(debt5int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin6.value > 0 || form.prin6.value != "") {
var debt6int = calcInt(eval(form.prin6.value),eval(form.IntRate6.value));
form.intCost6.value = formatNum_fr(debt6int);
accumPrin = eval(accumPrin) + eval(form.prin6.value);
accumInt = eval(accumInt) + eval(debt6int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin7.value > 0 || form.prin7.value != "") {
var debt7int = calcInt(eval(form.prin7.value),eval(form.IntRate7.value));
form.intCost7.value = formatNum_fr(debt7int);
accumPrin = eval(accumPrin) + eval(form.prin7.value);
accumInt = eval(accumInt) + eval(debt7int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin8.value > 0 || form.prin8.value != "") {
var debt8int = calcInt(eval(form.prin8.value),eval(form.IntRate8.value));
form.intCost8.value = formatNum_fr(debt8int);
accumPrin = eval(accumPrin) + eval(form.prin8.value);
accumInt = eval(accumInt) + eval(debt8int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin9.value > 0 || form.prin9.value != "") {
var debt9int = calcInt(eval(form.prin9.value),eval(form.IntRate9.value));
form.intCost9.value = formatNum_fr(debt9int);
accumPrin = eval(accumPrin) + eval(form.prin9.value);
accumInt = eval(accumInt) + eval(debt9int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin10.value > 0 || form.prin10.value != "") {
var debt10int = calcInt(eval(form.prin10.value),eval(form.IntRate10.value));
form.intCost10.value = formatNum_fr(debt10int);
accumPrin = eval(accumPrin) + eval(form.prin10.value);
accumInt = eval(accumInt) + eval(debt10int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin11.value > 0 || form.prin11.value != "") {
var debt11int = calcInt(eval(form.prin11.value),eval(form.IntRate11.value));
form.intCost11.value = formatNum_fr(debt11int);
accumPrin = eval(accumPrin) + eval(form.prin11.value);
accumInt = eval(accumInt) + eval(debt11int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin12.value > 0 || form.prin12.value != "") {
var debt12int = calcInt(eval(form.prin12.value),eval(form.IntRate12.value));
form.intCost12.value = formatNum_fr(debt12int);
accumPrin = eval(accumPrin) + eval(form.prin12.value);
accumInt = eval(accumInt) + eval(debt12int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin13.value > 0 || form.prin13.value != "") {
var debt13int = calcInt(eval(form.prin13.value),eval(form.IntRate13.value));
form.intCost13.value = formatNum_fr(debt13int);
accumPrin = eval(accumPrin) + eval(form.prin13.value);
accumInt = eval(accumInt) + eval(debt13int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin14.value > 0 || form.prin14.value != "") {
var debt14int = calcInt(eval(form.prin14.value),eval(form.IntRate14.value));
form.intCost14.value = formatNum_fr(debt14int);
accumPrin = eval(accumPrin) + eval(form.prin14.value);
accumInt = eval(accumInt) + eval(debt14int);
debtCount = eval(debtCount) + eval(1);
}

if(form.prin15.value > 0 || form.prin15.value != "") {
var debt15int = calcInt(eval(form.prin15.value),eval(form.IntRate15.value));
form.intCost15.value = formatNum_fr(debt15int);
accumPrin = eval(accumPrin) + eval(form.prin15.value);
accumInt = eval(accumInt) + eval(debt15int);
debtCount = eval(debtCount) + eval(1);
}

form.totalPrin.value = formatNum_fr(accumPrin);
form.totalInt.value = formatNum_fr(accumInt);
form.avgRate.value = formatNum_fr(accumInt / accumPrin * 12 * 100) + "%";
}

