//DO NOT REMOVE THIS COPYWRITE INFO! //Car Cost Comparison Calculator //By Daniel C. Peterson //Web Winder Website Services, 1997-2006 All Rights Reserved. //Distribution, editing or reselling of this script is strictyly prohibited //without expressed written permission from Daniel C. Peterson. //For commercial grade (professional) versions of this and many other //calculators, visit http://www.webwinder.com.
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)
function computeForm(form)
{
//Tax, License, and warranty Costs
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 = 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; } }
form.depreCost1.value = accumDeprec1 / 100 * form.priceTag1.value;
//Finance Costs
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 = 0; } else {
var int1 = form.intRate1.value;
if (int1 > 1.0) {int1 = int1 / 100.0; form.intRate1.value = int1; }
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) {form.intCost1.value = parseInt((pmt1 * form.nPer1.value) - prin1,10); } 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; }
}
form.intCost1.value = parseInt(accumInt1,10); } }
//Operating Costs
form.gas1.value = parseInt(form.miles1.value * form.lifeExpect1.value / form.mpg1.value * form.perGal1.value,10);
//Maintenance & Repair Costs
form.maintCost1.value = parseInt(form.maint1.value * 12 * form.lifeExpect1.value,10);
//Insurance Costs
form.insCost1.value = parseInt(form.insure1.value * form.lifeExpect1.value,10);
//Total Costs #1
form.totCost1.value = parseInt(eval(totPurch1) + eval(form.depreCost1.value) + eval(form.intCost1.value) + eval(form.gas1.value) + eval(form.maintCost1.value) + eval(form.insCost1.value),10);
form.annCost1.value = parseInt(form.totCost1.value / form.lifeExpect1.value,10);
form.mileCost1.value = form.annCost1.value / form.miles1.value;
//Scenario #2
//100 //Purchase Costs 2
if(form.priceTag2.value == 0) { form.salesTax2.value = form.salesTax1.value; form.warranty2.value = form.warranty1.value; form.license2.value = form.license1.value; form.purchCost2.value = form.purchCost1.value; } else {
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 = totPurch2;
}
//Depreciation Costs #2
if(form.priceTag2.value == 0) { form.age2.value = form.age1.value; form.lifeExpect2.value = form.lifeExpect1.value; form.depreCost2.value = form.depreCost1.value; } else {
var timePass2 = eval(form.age2.value); var accumDeprec2 = ageFact[form.age2.value];
while(timePass2 < eval(form.lifeExpect2.value) + eval(form.age2.value) - eval(1)) { timePass2 = eval(timePass2 + 1); accumDeprec2 = accumDeprec2 + ageFact[eval(timePass2 * 1)]; if(timePass2 > 50) {break; } else {continue; } }
form.depreCost2.value = accumDeprec2 / 100 * form.priceTag2.value; }
//Interest Costs #2
if(form.priceTag2.value == 0) { form.finance2.value = form.finance1.value; form.intRate2.value = form.intRate1.value; form.downPay2.value = form.downPay1.value; form.nPer2.value = form.nPer1.value; form.intCost2.value = form.intCost1.value; } else {
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; form.intRate2.value = int2; }
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) {form.intCost2.value = parseInt((pmt2 * form.nPer2.value) - prin2,10); } 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; }
}
form.intCost2.value = parseInt(accumInt2,10); } } }
//Fuel Costs #2
if(form.priceTag2.value == 0) { form.gas2.value = form.gas1.value; form.miles2.value = form.miles1.value; form.perGal2.value = form.perGal1.value; form.mpg2.value = form.mpg1.value; } else {
form.gas2.value = parseInt(form.miles2.value * form.lifeExpect2.value / form.mpg2.value * form.perGal2.value,10);
}
//Maint Costs #2
if(form.priceTag2.value == 0) { form.maintCost2.value = form.maintCost1.value; form.maint2.value = form.maint1.value; } else {
form.maintCost2.value = parseInt(form.maint2.value * 12 * form.lifeExpect2.value,10);
}
//Insurance Costs #2
if(form.priceTag2.value == 0) { form.insCost2.value = form.insCost1.value; form.insure2.value = form.insure1.value; } else {
form.insCost2.value = parseInt(form.insure2.value * form.lifeExpect2.value,10);
}
//Total Costs #2
if(form.priceTag2.value == 0) { form.totCost2.value = form.totCost1.value; form.annCost2.value = form.annCost1.value; form.priceTag2.value = form.priceTag1.value; form.mileCost2.value = form.mileCost1.value; } else {
form.totCost2.value = parseInt(eval(totPurch2) + eval(form.depreCost2.value) + eval(form.intCost2.value) + eval(form.gas2.value) + eval(form.maintCost2.value) + eval(form.insCost2.value),10);
form.annCost2.value = parseInt(form.totCost2.value / form.lifeExpect2.value,10);
form.mileCost2.value = form.annCost2.value / form.miles2.value;
}
var fsummary = 0; var scenario = "";
if(form.annCost1.value > form.annCost2.value) { fsummary = eval(form.annCost1.value) - eval(form.annCost2.value); scenario = "Scenario #2"; } else { fsummary = eval(form.annCost2.value) - eval(form.annCost1.value); scenario = "Scenario #1"; }
form.summary.value = (scenario + " will save you $" + parseInt(fsummary,10) + " per year.");
}
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 = "";
}