car_calculate = function()
{
var price = document.getElementById("car_purchaseprice").value;
if ( price.length == 0 )
{
alert("Please enter the purchase price");
return;
}
price = fixNumber(price);
price = parseFloat(price);
if ( isNaN(price) )
{
alert("Please enter the purchase price as a number");
return;
}
if ( price < 0 )
{
alert("Please enter a purchase price >= 0");
return;
}
var rate = document.getElementById("car_rate").value;
if ( rate.length == 0 )
{
alert("Please enter an interest rate");
return;
}
rate = fixNumber(rate);
rate = parseFloat(rate);
if ( isNaN(rate) )
{
alert("Please enter the interest rate as a number");
return;
}
if ( rate < 0 || rate >= 35 )
{
alert("Please enter a interest rate >= 0 and less than 35");
return;
}
var months = document.getElementById("car_duration").value;
if ( months.length == 0 )
{
alert("Please enter the # of months you loan will last");
return;
}
months = fixNumber(months);
months = parseFloat(months);
if ( isNaN(months) )
{
alert("Please enter the # of months as a number");
return;
}
if ( months <= 0 || months > 120 )
{
alert("Please enter a # of months between 1 and 120");
return;
}
var downpayment = document.getElementById("car_down").value;
if ( downpayment.length == 0 )
{
alert("Please enter a down payment");
return;
}
downpayment = fixNumber(downpayment);
downpayment = parseFloat(downpayment);
if ( isNaN(downpayment) )
{
alert("Please enter the down payment as a number");
return;
}
if ( downpayment < 0 )
{
alert("Please enter a down payment >= 0");
return;
}
if ( downpayment >= price )
{
alert("Your down payment exceeds the car price, so you won't need a loan.");
return;
}
var mrate = rate / 1200;
var loanamount = price - downpayment;
var payment;
if ( rate == 0 )
{
payment = loanamount / months;
}
else
{
var factor = Math.pow(1 + mrate, months );
payment = loanamount * ( mrate / (1 - 1/factor) );
}
var x = document.getElementById("car_dt_results");
var results = "The amount of your loan will be " + formatDollars(loanamount) + ".";
results += "
Your monthly payment will be " + formatDollars(payment) + ".";
results += "
You will pay a total of " + formatDollars(((payment * months) + downpayment) - price) + " in interest.";
x.innerHTML = results;
x.style.display = "block";
}// modified css: http://www.dollartimes.com/calculators/on-your-site/calc-css.php
addJavascript = function(fileName) {
var th = document.getElementsByTagName('head')[0];
var s = document.createElement('script');
s.setAttribute('type','text/javascript');
s.setAttribute('src',fileName);
th.appendChild(s);
}
addStylesheet = function(fileName) {
var th = document.getElementsByTagName('head')[0];
var s = document.createElement('link');
s.setAttribute('type','text/css');
s.setAttribute('title', 'dt-calc-style');
s.setAttribute('rel','stylesheet');
s.setAttribute('href',fileName);
th.appendChild(s);
}
addJavascript('http://www.dollartimes.com/script/calcutil.js');
var out = '\
What will your monthly car payment be? How much interest will you end up paying?
\n\