//By Daniel C. Peterson, 1998  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 AddDecimal(number) {

var zero = "0";
var zeros = ".00";
var withdecimal = "";
var num = number;
if(num == 0) {
  withdecimal = "0.00";
 } else if (num < .10) {
  withdecimal = "0" + num;
 } else if (num < 1 && num % .10 == 0) {
  withdecimal = "0" + num;
 } else if (num < 1 && num % .10 > 0) {
  withdecimal = "0." + parseInt(num * 100,10);
 } else if (num % 1 == 0) {
  withdecimal = parseInt(num,10) + "" + zeros;
 } else if (num % .10 == 0) {
   withdecimal = num + "" + zero;
 } else { 
   withdecimal = parseInt(num,10) + "." + parseInt(num % 1 * 100,10);
 }
 return withdecimal;
}


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);
   }
   else
   if(Vnum >= 1000000) {
   Vformat = (V1million + "," + V100thousand + "" + V10thousand + "" + V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones);
   }
   else
   if(Vnum >= 100000) {
   Vformat = (V100thousand + "" + V10thousand + "" + V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones);
   }
   else
   if(Vnum >= 10000) {
   Vformat = (V10thousand + "" + V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones);
   }
   else
   if(Vnum >= 1000) {
   Vformat = (V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones);
   }
   else
   if(Vnum >= 100) {
   Vformat = (Vhundreds + "" + Vtens + "" + Vones);
   }
   else
   if(Vnum >= 10) {
   Vformat = (Vtens + "" + Vones);
   }
   else
   if(Vnum >= 1) {
   Vformat = (Vones);
   } else {
   Vformat = ("0");
   }

  return Vformat;

  }
}


function computeForm(form)

{
   
//Tax, License, and warranty Costs


   ageFact = new Array(28,20,16,8,6,5,4,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
 
   var tax1 = 0;
   var taxCost1 = 0;

   if(form.salesTax1.value >1) {tax1 = form.salesTax1.value / 100; } else {tax1 = form.salesTax1.value; }

   if(tax1 > 0) {taxCost1 = form.priceTag1.value * tax1; } else {taxCost1 = 0; }

   var licCost1 = 0;
   var warCost1 = form.warranty1.value;
   var totPurch1 = 0;

   licCost1 = form.license1.value * form.lifeExpect1.value;

   totPurch1 = eval(taxCost1) + eval(licCost1) + eval(warCost1);

   form.purchCost1.value = formatNum(totPurch1);


//Depreciation Costs

   var timePass1 = eval(form.age1.value);
   var accumDeprec1 = ageFact[form.age1.value]; 

   while(timePass1 < eval(form.lifeExpect1.value) + eval(form.age1.value) - eval(1)) {
       timePass1 = eval(timePass1 + 1);
       accumDeprec1 = accumDeprec1 + ageFact[eval(timePass1 * 1)];
       if(timePass1 > 50) {break; } else {continue; }
   }
 
//newVar
   var VdepreCost1 = accumDeprec1 / 100 * form.priceTag1.value;
   form.depreCost1.value = formatNum(VdepreCost1);
      

//Finance Costs

//newVar
var VintCost1 = 0;

   if(form.finance1.value == "n" || form.finance1.value == "N" || form.downPay1.value == 0 || form.intRate1.value == 0 || form.nPer1.value == 0) {
       form.downPay1.value = 0;
       form.intRate1.value = 0;
       form.nPer1.value = 0;
       form.intCost1.value = VintCost1; } else {

   var int1 = form.intRate1.value;

    if (int1 > 1.0) {int1 = int1 / 100.0; }

    int1 /= 12;

    var prin1 = eval(form.priceTag1.value) + eval(taxCost1) + eval(form.license1.value) + eval(form.warranty1.value) - eval(form.downPay1.value);

    var pmt1 = 0;

    var pow1 = 1;

    for (var j1 = 0; j1 < form.nPer1.value; j1++)

        pow1 = pow1 * (1 + int1);

    pmt1 = (prin1 * pow1 * int1) / (eval(pow1) - eval(1));
		
		if(form.nPer1.value / 12 <= form.lifeExpect1.value) {
    VintCost1 = parseInt((pmt1 * form.nPer1.value) - prin1,10);
    form.intCost1.value =  formatNum(VintCost1);
    } else {

        var intPort1 = 0;
        var PrinPort1 = 0;
        var count1 = 0;
        var accumPrin1 = 0;
        var accumInt1 =0;

    while(count1 < form.lifeExpect1.value * 12) {

           intPort1 = prin1 * int1;

           prinPort1 = pmt1 - intPort1;

           prin1 = prin1 - prinPort1;

           accumPrin1 = accumPrin1 + prinPort1;

           accumInt1 = accumInt1 + intPort1;

           count1 = count1 + 1;

           if(count1 > 600) {break; } else {continue; }

          }
     
     VintCost1 = accumInt1;
     form.intCost1.value = formatNum(VintCost1);
       }
     }

//Operating Costs

//newVar
   var Vgas1 = form.miles1.value * form.lifeExpect1.value / form.mpg1.value * form.perGal1.value;
   form.gas1.value = formatNum(Vgas1);

//Maintenance & Repair Costs

   var VmaintCost1 = form.maint1.value * 12 * form.lifeExpect1.value;
   form.maintCost1.value = formatNum(VmaintCost1);


//Insurance Costs
 
   var VinsCost1 = form.insure1.value * form.lifeExpect1.value;
   form.insCost1.value = formatNum(VinsCost1);

   
//Total Costs #1

   var VtotCost1 = eval(totPurch1) + eval(VdepreCost1) + eval(VintCost1) + eval(Vgas1) + eval(VmaintCost1) + eval(VinsCost1);
 form.totCost1.value = formatNum(VtotCost1);

   var VannCost1 = VtotCost1 / form.lifeExpect1.value;
   form.annCost1.value = formatNum(VannCost1);

   var VmileCost1 = VannCost1 / form.miles1.value;
   form.mileCost1.value = AddDecimal(VmileCost1);

//Scenario #2

//100
//Purchase Costs 2

   var tax2 = 0;
   var taxCost2 = 0;

   if(form.salesTax2.value >1) {tax2 = form.salesTax2.value / 100; } else {tax2 = form.salesTax2.value; }

   if(tax2 > 0) {taxCost2 = form.priceTag2.value * tax2; } else {taxCost2 = 0; }

   var licCost2 = 0;
   var warCost2 = form.warranty2.value;
   var totPurch2 = 0;

   licCost2 = form.license2.value * form.lifeExpect2.value;

   totPurch2 = eval(taxCost2) + eval(licCost2) + eval(warCost2);

   form.purchCost2.value = formatNum(totPurch2);


//Depreciation Costs #2

    var timePass2 = eval(form.age2.value);
   var accumDeprec2 = ageFact[eval(form.age2.value)]; 

   while(timePass2 < (eval(form.lifeExpect2.value) + eval(form.age2.value) - eval(1))) {
       timePass2 = eval(timePass2) + eval(1);
       accumDeprec2 = eval(accumDeprec2) + ageFact[eval(timePass2 * 1)];
       if(timePass2 > 50) {break; } else {continue; }
       }

    var VdepreCost2 = accumDeprec2 / 100 * form.priceTag2.value;
    form.depreCost2.value = formatNum(VdepreCost2);

//Interest Costs #2

var VintCost2 = 0;


   if(form.finance2.value == "n" || form.finance2.value == "N" || form.finance2.value == "") {
       form.downPay2.value = "n/a";
       form.intRate2.value = "n/a";
       form.nPer2.value = "n/a";
       form.intCost2.value = 0; } else {
   
    var int2 = form.intRate2.value;

    if (int2 > 1.0) {int2 = int2 / 100.0; }

    int2 /= 12;

    var prin2 = eval(form.priceTag2.value) + eval(taxCost2) + eval(form.license2.value) + eval(form.warranty2.value) - eval(form.downPay2.value);

    var pmt2 = 0;

    var pow2 = 1;

    for (var j2 = 0; j2 < form.nPer2.value; j2++)

        pow2 = pow2 * (1 + int2);

    pmt2 = (prin2 * pow2 * int2) / (eval(pow2) - eval(1));
		
		if(form.nPer2.value / 12 <= form.lifeExpect2.value) {
    VintCost2 = (pmt2 * form.nPer2.value) - prin2;
    form.intCost2.value = formatNum(VintCost2);
    } else {

        var intPort2 = 0;
        var PrinPort2 = 0;
        var count2 = 0;
        var accumPrin2 = 0;
        var accumInt2 =0;

    while(count2 < form.lifeExpect2.value * 12) {

           intPort2 = prin2 * int2;

           prinPort2 = pmt2 - intPort2;

           prin2 = prin2 - prinPort2;

           accumPrin2 = accumPrin2 + prinPort2;

           accumInt2 = accumInt2 + intPort2;

           count2 = count2 + 1;

           if(count2 > 600) {break; } else {continue; }

          }

       VintCost2 = accumInt2;
       form.intCost2.value = formatNum(VintCost2);
        
      }
    }

//Fuel Costs #2

   var Vgas2 = form.miles2.value * form.lifeExpect2.value / form.mpg2.value * form.perGal2.value;
   form.gas2.value = formatNum(Vgas2);

//Maint Costs #2

   var VmaintCost2 = form.maint2.value * 12 * form.lifeExpect2.value;
   form.maintCost2.value = formatNum(VmaintCost2);

//Insurance Costs #2

   var VinsCost2 = form.insure2.value * form.lifeExpect2.value;
   form.insCost2.value = formatNum(VinsCost2);

//Total Costs #2

   var VtotCost2 = eval(totPurch2) + eval(VdepreCost2) + eval(VintCost2) + eval(Vgas2) + eval(VmaintCost2) + eval(VinsCost2)
   form.totCost2.value = formatNum(VtotCost2);

   var VannCost2 = VtotCost2 / form.lifeExpect2.value;
   form.annCost2.value = formatNum(VannCost2);

   var VmileCost2 = VannCost2 / form.miles2.value
   form.mileCost2.value = AddDecimal(VmileCost2);


   var fsummary = 0;
   var scenario = "";

   if(eval(VannCost1) - eval(VannCost2) < .01 && eval(VannCost2) - eval(VannCost1) < .01) {
   form.summary.value = ("You will not save money");
   } else {

   if(VannCost1 > VannCost2) {
   fsummary = eval(VannCost1) - eval(VannCost2);
   scenario = "scenario d'achat 2";
   } else {
   fsummary = eval(VannCost2) - eval(VannCost1);
   scenario = "scenario d'achat 1"; 
   }

   form.summary.value = ("The " + scenario + " will save you $ " + formatNum(fsummary) + "each year.");
   }
 
}

function copyValues(form) {

    form.priceTag2.value = form.priceTag1.value;
    form.salesTax2.value =  form.salesTax1.value;
    form.warranty2.value = form.warranty1.value;
    form.license2.value = form.license1.value;
    form.downPay2.value = form.downPay1.value;
    form.insure2.value = form.insure1.value;
    form.finance2.value = form.finance1.value;
    form.intRate2.value = form.intRate1.value;
    form.nPer2.value = form.nPer1.value;
    form.miles2.value = form.miles1.value;
    form.mpg2.value = form.mpg1.value;
    form.perGal2.value = form.perGal1.value;
    form.maint2.value = form.maint1.value;
    form.age2.value = form.age1.value;
    form.lifeExpect2.value = form.lifeExpect1.value;
    form.purchCost2.value = form.purchCost1.value;
    form.depreCost2.value = form.depreCost1.value;
    form.intCost2.value = form.intCost1.value;
    form.insCost2.value = form.insCost1.value;
    form.maintCost2.value = form.maintCost1.value;
    form.totCost2.value = form.totCost1.value;
    form.annCost2.value = form.annCost1.value;
    form.mileCost2.value = form.mileCost1.value;

form.summary.value = "Change the variables in each scenario and compute";
}


function clearForm(form)

{

    
    form.priceTag1.value = "";
    form.salesTax1.value = "";
    form.warranty1.value = "";
    form.license1.value = "";
    form.downPay1.value = "";
    form.insure1.value = "";
    form.finance1.value = "";
    form.intRate1.value = "";
    form.nPer1.value = "";
    form.miles1.value = "";
    form.mpg1.value = "";
    form.perGal1.value = "";
    form.maint1.value = "";
    form.age1.value = "";
    form.lifeExpect1.value = "";
    form.purchCost1.value = "";
    form.depreCost1.value = "";
    form.intCost1.value = "";
    form.insCost1.value = "";
    form.maintCost1.value = "";
    form.totCost1.value = "";
    form.annCost1.value = "";
    form.mileCost1.value = "";

    form.priceTag2.value = "";
    form.salesTax2.value = "";
    form.warranty2.value = "";
    form.license2.value = "";
    form.finance2.value = "";
    form.downPay2.value = "";
    form.insure2.value = "";
    form.intRate2.value = "";
    form.nPer2.value = "";
    form.miles2.value = "";
    form.mpg2.value = "";
    form.perGal2.value = "";
    form.maint2.value = "";
    form.age2.value = "";
    form.lifeExpect2.value = "";
    form.purchCost2.value = "";
    form.depreCost2.value = "";
    form.intCost2.value = "";
    form.insCost2.value = "";
    form.maintCost2.value = "";
    form.totCost2.value = "";
    form.annCost2.value = "";
    form.mileCost2.value = "";
    
    form.summary.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);
   }
   else
   if(Vnum >= 1000000) {
   Vformat = (V1million + "," + V100thousand + "" + V10thousand + "" + V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones);
   }
   else
   if(Vnum >= 100000) {
   Vformat = (V100thousand + "" + V10thousand + "" + V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones);
   }
   else
   if(Vnum >= 10000) {
   Vformat = (V10thousand + "" + V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones);
   }
   else
   if(Vnum >= 1000) {
   Vformat = (V1thousand + "," + Vhundreds + "" + Vtens + "" + Vones);
   }
   else
   if(Vnum >= 100) {
   Vformat = (Vhundreds + "" + Vtens + "" + Vones);
   }
   else
   if(Vnum >= 10) {
   Vformat = (Vtens + "" + Vones);
   }
   else
   if(Vnum >= 1) {
   Vformat = (Vones);
   } else {
   Vformat = ("0");
   }

  return Vformat;

  }
}

function computeForm_fr(form)

{
   
//Tax, License, and warranty Costs

   ageFact = new Array(28,20,16,8,6,5,4,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);

   var tax1 = 0;
   var taxCost1 = 0;

   if(form.salesTax1.value >1) {tax1 = form.salesTax1.value / 100; } else {tax1 = form.salesTax1.value; }

   if(tax1 > 0) {taxCost1 = form.priceTag1.value * tax1; } else {taxCost1 = 0; }

   var licCost1 = 0;
   var warCost1 = form.warranty1.value;
   var totPurch1 = 0;

   licCost1 = form.license1.value * form.lifeExpect1.value;

   totPurch1 = eval(taxCost1) + eval(licCost1) + eval(warCost1);

   form.purchCost1.value = formatNum_fr(totPurch1);


//Depreciation Costs

   var timePass1 = eval(form.age1.value);
   var accumDeprec1 = ageFact[form.age1.value]; 

   while(timePass1 < eval(form.lifeExpect1.value) + eval(form.age1.value) - eval(1)) {
       timePass1 = eval(timePass1 + 1);
       accumDeprec1 = accumDeprec1 + ageFact[eval(timePass1 * 1)];
       if(timePass1 > 50) {break; } else {continue; }
   }
 
//newVar
   var VdepreCost1 = accumDeprec1 / 100 * form.priceTag1.value;
   form.depreCost1.value = formatNum_fr(VdepreCost1);
      

//Finance Costs

//newVar
var VintCost1 = 0;

   if(form.finance1.value == "n" || form.finance1.value == "N" || form.downPay1.value == 0 || form.intRate1.value == 0 || form.nPer1.value == 0) {
       form.downPay1.value = 0;
       form.intRate1.value = 0;
       form.nPer1.value = 0;
       form.intCost1.value = VintCost1; } else {

   var int1 = form.intRate1.value;

    if (int1 > 1.0) {int1 = int1 / 100.0; }

    int1 /= 12;

    var prin1 = eval(form.priceTag1.value) + eval(taxCost1) + eval(form.license1.value) + eval(form.warranty1.value) - eval(form.downPay1.value);

    var pmt1 = 0;

    var pow1 = 1;

    for (var j1 = 0; j1 < form.nPer1.value; j1++)

        pow1 = pow1 * (1 + int1);

    pmt1 = (prin1 * pow1 * int1) / (eval(pow1) - eval(1));
		
		if(form.nPer1.value / 12 <= form.lifeExpect1.value) {
    VintCost1 = parseInt((pmt1 * form.nPer1.value) - prin1,10);
    form.intCost1.value =  formatNum_fr(VintCost1);
    } else {

        var intPort1 = 0;
        var PrinPort1 = 0;
        var count1 = 0;
        var accumPrin1 = 0;
        var accumInt1 =0;

    while(count1 < form.lifeExpect1.value * 12) {

           intPort1 = prin1 * int1;

           prinPort1 = pmt1 - intPort1;

           prin1 = prin1 - prinPort1;

           accumPrin1 = accumPrin1 + prinPort1;

           accumInt1 = accumInt1 + intPort1;

           count1 = count1 + 1;

           if(count1 > 600) {break; } else {continue; }

          }
     
     VintCost1 = accumInt1;
     form.intCost1.value = formatNum_fr(VintCost1);
       }
     }

//Operating Costs

//newVar
   var Vgas1 = form.miles1.value * form.lifeExpect1.value / form.mpg1.value * form.perGal1.value;
   form.gas1.value = formatNum_fr(Vgas1);

//Maintenance & Repair Costs

   var VmaintCost1 = form.maint1.value * 12 * form.lifeExpect1.value;
   form.maintCost1.value = formatNum_fr(VmaintCost1);


//Insurance Costs
 
   var VinsCost1 = form.insure1.value * form.lifeExpect1.value;
   form.insCost1.value = formatNum_fr(VinsCost1);

   
//Total Costs #1

   var VtotCost1 = eval(totPurch1) + eval(VdepreCost1) + eval(VintCost1) + eval(Vgas1) + eval(VmaintCost1) + eval(VinsCost1);
 form.totCost1.value = formatNum_fr(VtotCost1);

   var VannCost1 = VtotCost1 / form.lifeExpect1.value;
   form.annCost1.value = formatNum_fr(VannCost1);

   var VmileCost1 = VannCost1 / form.miles1.value;
   form.mileCost1.value = AddDecimal(VmileCost1);

//Scenario #2

//100
//Purchase Costs 2

   var tax2 = 0;
   var taxCost2 = 0;

   if(form.salesTax2.value >1) {tax2 = form.salesTax2.value / 100; } else {tax2 = form.salesTax2.value; }

   if(tax2 > 0) {taxCost2 = form.priceTag2.value * tax2; } else {taxCost2 = 0; }

   var licCost2 = 0;
   var warCost2 = form.warranty2.value;
   var totPurch2 = 0;

   licCost2 = form.license2.value * form.lifeExpect2.value;

   totPurch2 = eval(taxCost2) + eval(licCost2) + eval(warCost2);

   form.purchCost2.value = formatNum_fr(totPurch2);


//Depreciation Costs #2

    var timePass2 = eval(form.age2.value);
   var accumDeprec2 = ageFact[eval(form.age2.value)]; 

   while(timePass2 < (eval(form.lifeExpect2.value) + eval(form.age2.value) - eval(1))) {
       timePass2 = eval(timePass2) + eval(1);
       accumDeprec2 = eval(accumDeprec2) + ageFact[eval(timePass2 * 1)];
       if(timePass2 > 50) {break; } else {continue; }
       }

    var VdepreCost2 = accumDeprec2 / 100 * form.priceTag2.value;
    form.depreCost2.value = formatNum_fr(VdepreCost2);

//Interest Costs #2

var VintCost2 = 0;


   if(form.finance2.value == "n" || form.finance2.value == "N" || form.finance2.value == "") {
       form.downPay2.value = "n/a";
       form.intRate2.value = "n/a";
       form.nPer2.value = "n/a";
       form.intCost2.value = 0; } else {
   
    var int2 = form.intRate2.value;

    if (int2 > 1.0) {int2 = int2 / 100.0; }

    int2 /= 12;

    var prin2 = eval(form.priceTag2.value) + eval(taxCost2) + eval(form.license2.value) + eval(form.warranty2.value) - eval(form.downPay2.value);

    var pmt2 = 0;

    var pow2 = 1;

    for (var j2 = 0; j2 < form.nPer2.value; j2++)

        pow2 = pow2 * (1 + int2);

    pmt2 = (prin2 * pow2 * int2) / (eval(pow2) - eval(1));
		
		if(form.nPer2.value / 12 <= form.lifeExpect2.value) {
    VintCost2 = (pmt2 * form.nPer2.value) - prin2;
    form.intCost2.value = formatNum_fr(VintCost2);
    } else {

        var intPort2 = 0;
        var PrinPort2 = 0;
        var count2 = 0;
        var accumPrin2 = 0;
        var accumInt2 =0;

    while(count2 < form.lifeExpect2.value * 12) {

           intPort2 = prin2 * int2;

           prinPort2 = pmt2 - intPort2;

           prin2 = prin2 - prinPort2;

           accumPrin2 = accumPrin2 + prinPort2;

           accumInt2 = accumInt2 + intPort2;

           count2 = count2 + 1;

           if(count2 > 600) {break; } else {continue; }

          }

       VintCost2 = accumInt2;
       form.intCost2.value = formatNum_fr(VintCost2);
        
      }
    }

//Fuel Costs #2

   var Vgas2 = form.miles2.value * form.lifeExpect2.value / form.mpg2.value * form.perGal2.value;
   form.gas2.value = formatNum_fr(Vgas2);

//Maint Costs #2

   var VmaintCost2 = form.maint2.value * 12 * form.lifeExpect2.value;
   form.maintCost2.value = formatNum_fr(VmaintCost2);

//Insurance Costs #2

   var VinsCost2 = form.insure2.value * form.lifeExpect2.value;
   form.insCost2.value = formatNum_fr(VinsCost2);

//Total Costs #2

   var VtotCost2 = eval(totPurch2) + eval(VdepreCost2) + eval(VintCost2) + eval(Vgas2) + eval(VmaintCost2) + eval(VinsCost2)
   form.totCost2.value = formatNum_fr(VtotCost2);

   var VannCost2 = VtotCost2 / form.lifeExpect2.value;
   form.annCost2.value = formatNum_fr(VannCost2);

   var VmileCost2 = VannCost2 / form.miles2.value
   form.mileCost2.value = AddDecimal(VmileCost2);


   var fsummary = 0;
   var scenario = "";

   if(eval(VannCost1) - eval(VannCost2) < .01 && eval(VannCost2) - eval(VannCost1) < .01) {
   form.summary.value = ("Il n'y aura aucune économie");
   } else {

   if(VannCost1 > VannCost2) {
   fsummary = eval(VannCost1) - eval(VannCost2);
   scenario = "scenario d'achat 2";
   } else {
   fsummary = eval(VannCost2) - eval(VannCost1);
   scenario = "scenario d'achat 1"; 
   }

   form.summary.value = ("Le " + scenario + " vous fera économiser " + formatNum_fr(fsummary) + "$ par an.");
   }
 
}

function copyValues_fr(form) {

    form.priceTag2.value = form.priceTag1.value;
    form.salesTax2.value =  form.salesTax1.value;
    form.warranty2.value = form.warranty1.value;
    form.license2.value = form.license1.value;
    form.downPay2.value = form.downPay1.value;
    form.insure2.value = form.insure1.value;
    form.finance2.value = form.finance1.value;
    form.intRate2.value = form.intRate1.value;
    form.nPer2.value = form.nPer1.value;
    form.miles2.value = form.miles1.value;
    form.mpg2.value = form.mpg1.value;
    form.perGal2.value = form.perGal1.value;
    form.maint2.value = form.maint1.value;
    form.age2.value = form.age1.value;
    form.lifeExpect2.value = form.lifeExpect1.value;
    form.purchCost2.value = form.purchCost1.value;
    form.depreCost2.value = form.depreCost1.value;
    form.intCost2.value = form.intCost1.value;
    form.insCost2.value = form.insCost1.value;
    form.maintCost2.value = form.maintCost1.value;
    form.totCost2.value = form.totCost1.value;
    form.annCost2.value = form.annCost1.value;
    form.mileCost2.value = form.mileCost1.value;

form.summary.value = "Changer les variables dans chaque scénario et calculez";
}

