dt_cctime_calculate = function()
{
	var balance, charges, apr, months;

	try
	{
		balance = DT_F.getFormFloat( "dt_cctime_balance", "Please enter your current credit card balance", "Please enter your current credit card balance as a number" );
		if ( balance <= 0 ) {
			throw("Your current balance must be > 0");
		}
		charges = DT_F.getFormFloat( "dt_cctime_charges", "Please enter your new monthly charges", "Please enter your new monthly charges as a number" );
		if ( charges < 0 ) {
			throw("Your new monthly charges must be >= 0");
		}
		apr = DT_F.getFormFloat( "dt_cctime_apr", "Please enter the interest rate of your credit card", "Please enter the interest rate of your credit card as a number" );
		if ( apr < 0 || apr > 40 ) {
			throw("The interest rate of your credit card must be between 0 and 40");
		}
		months = DT_F.getFormInt( "dt_cctime_months", "Please enter number of months you have to pay off your balance", "Please enter a valid number of months you have to pay off your balance", "The number of months was rounded to " );
		if ( months <= 0 ) {
			throw("The number of months to pay off your balance must be greater than 0");
		}
	}
	catch ( err )
	{
		alert(err);
		return;
	}

	// monthly rate:
	var mRate = apr / 1200;
	
	// calculate
	var nom, denom;
	if ( mRate == 0 ) {
		nom = balance;
		denom = months;
	}
	else {
		nom = balance * mRate;
		denom = 1 - Math.pow(1 + mRate, -1 * months);
	}
	var x = charges + ( nom / denom );
	var interest = (months * x) - balance - ( months * charges );
	
	var html = [];
	html.push( "To pay off your credit card balance in " + months + " months:" );
	html.push(" <p>You must make a monthly payment of <b>" + DT_F.formatDollars(x) + "</b>.</p>" );
	html.push( "<p>You will pay a total of <b>" + DT_F.formatDollars(interest) + "</b> in interest.</p>" );

	var z = document.getElementById("dt_cctime_results");
	z.innerHTML = html.join('');
	z.style.display = "block";
};

