dt_sav_calculate = function()
{
	var investment, rate, years;
	try
	{
		investment = DT_F.getFormFloat( "dt_sav_investment", "Please enter the amount of your initial investment", "Please enter your initial investment as a number" );
		if ( investment <= 0 ) {
			throw("Please enter an initial investment > 0");
		}
		rate = DT_F.getFormFloat( "dt_sav_rate", "Please enter an interest rate", "Please enter the interest rate as a number" );
		if ( rate < -100 ) {
			throw("Please enter an interest rate >= -100%");
		}
		years = DT_F.getFormInt( "dt_sav_years", "Please enter the number of years you will invest your money for", "Please enter the number of years as a number", "The number of years was rounded to " );
		if ( years <= 0 ) {
			throw("Please enter a number of years > 0");
		}
	}
	catch ( err )
	{
		alert(err);
		return;
	}

	var r = 1 + (rate / 100);
	var result = investment * Math.pow(r, years);

	var maxTableYears = years;
	if ( maxTableYears > 10 ) {
		maxTableYears = 10;
	}
	var table = [];
	if ( years != maxTableYears ) {
		table.push("Here is how	your investment will grow over the first " + maxTableYears + " years:");
	} 
	else {
		table.push("Here is how your investment will grow over time:");
	}
	table.push("<br><table cellpadding='0' cellspacing='0'>");
	table.push("<tr><th>Year</th><th>Balance</th></tr>");
	table.push("<tr><td>start</td><td>" + DT_F.formatDollars(investment) + "</td></tr>");
	var currAmount = investment;
	for (var y=1; y<=maxTableYears; y++ ) {
		currAmount = currAmount * r;
		table.push("<tr><td>" + y + "</td><td>" + DT_F.formatDollars(currAmount) + "</td></tr>");
	}
	table.push("</table>");

	var results = "At the end of " + years + " years, your savings will have grown to <b>" + DT_F.formatDollars(result) + "</b>.";

	results += "<br><br>You will have earned " + DT_F.formatDollars(result-investment) + " in interest.";

	results += "<br><br>" + table.join('');

	var x = document.getElementById("dt_sav_results");
	x.innerHTML = results;
	x.style.display = "block";
};
