dt_lunch_calculate = function()
{
	var sack, out, days, years, rate;

	try
	{
		sack = DT_F.getFormFloat( "dt_lunch_sack", "Please enter the cost of your sack lunch", "Please enter the cost of your sack lunch as a number" );
		if ( sack < 0 ) {
			throw("Please enter a sack lunch cost >= 0");
		}
		out = DT_F.getFormFloat( "dt_lunch_out", "Please enter the cost of going out to lunch", "Please enter the cost of going out to lunch as a number" );
		if ( out < 0 ) {
			throw("Please enter a cost of going out >= 0");
		}
		days = DT_F.getFormFloat( "dt_lunch_days", "Please enter the number of days per week you go out to eat", "Please enter a valid number of days per week you go out to eat");
		if ( days <= 0 ) {
			throw("The number of days you go out to lunch must be > 0");
		}
		if ( days > 7 ) {
			throw("The number of days you go out to lunch must not be more than 7");
		}
		years = DT_F.getFormInt( "dt_lunch_years", "Please enter the number of years to calculate", "Please enter the number of years to calculate as a number", "The number of years to calculate was rounded down to" );
		if ( years <= 0 ) {
			throw("Please enter a number of years > 0");
		}
		rate = DT_F.getFormFloat( "dt_lunch_rate", "Please enter an interest rate", "Please enter the interest rate as a number" );
		if ( rate < -100 ) {
			throw("Please enter an interest rate >= -100%");
		}
		if ( sack >= out )
		{
			throw("The cost of your sack lunch is greater or equal to the cost of going out.  You won't save any money.");
			return;
		}
	}
	catch ( err )
	{
		alert(err);
		return;
	}

	var r = 1 + (rate / 100);
	var yearlySavings = ( out - sack ) * ( days * 50 );
	var totalSavings; 
	if ( rate == 0 ) {
		totalSavings = yearlySavings * years;
	}
	else {
		totalSavings = yearlySavings * ( 1 - Math.pow(r, years) ) / ( 1 - r ); 
	}

	var currAmount = 0;
	var tableYears = years;
	if ( tableYears > 10 ) {
		tableYears = 10;
	}
	var table = [];
	if ( years != tableYears ) {
		table.push("Here is how	your savings will grow over the first " + tableYears + " years:");
	} 
	else {
		table.push("Here is how your savings will grow over time:");
	}
	table.push("<br><table cellpadding='0' cellspacing='0'>");
	table.push("<tr><th>Year</th><th>Interest</th><th>Savings</th><th>Balance</th></tr>");
	table.push("<tr><td>start</td><td>$0</td><td>$0</td><td>$0</td></tr>");

	for ( var y=1; y<=tableYears; y++ )
	{
		var interest = ( currAmount * r ) - currAmount;
		currAmount = ( currAmount * r ) + yearlySavings;
		table.push("<tr><td>" + y + "</td><td>" + DT_F.formatDollars(interest) + "</td><td>" + DT_F.formatDollars(yearlySavings) + "</td><td>" + DT_F.formatDollars(currAmount) + "</td></tr>");
	}
	table.push("</table>");
	var results = "By bringing your lunch, you will save " + DT_F.formatDollars(yearlySavings) + " per year.<br><br>After " + years + " years, your savings will have grown to <b>" +  DT_F.formatDollars(totalSavings) + "</b>";
	results += "<br><br>" + table.join('');
	 
	var x = document.getElementById("dt_lunch_results");
	x.innerHTML = results;
	x.style.display = "block";
};