dt_savingslast_calculate = function()
{
	var initial, rate, withdrawal;
	try
	{
		initial = DT_F.getFormFloat( "dt_savingslast_initial", "Please enter your initial savings", "Please enter your initial savings as a number" );
		if ( initial  < 0 ) {
			throw("Please enter initial savings >= 0");
		}
		rate = DT_F.getFormFloat( "dt_savingslast_rate", "Please enter an interest rate", "Please enter the interest rate as a number" );	
		if ( rate < 0 || rate > 100 ) {
			throw("Please enter an interest rate between 0 and 100");
		}
		withdrawal = DT_F.getFormFloat( "dt_savingslast_withdrawal", "Please enter a yearly withdrawal", "Please enter the yearly withdrawal as a number" );
		if ( withdrawal <= 0 ) {
			throw("If your don't withdraw any money, your savings will last forever.  Congrats!");
		}
	}
	catch ( err )
	{
		alert(err);
		return;
	}

	var r = 1 + (rate / 100);
	var mr = Math.pow( r, (1/12) );
	var mw = withdrawal/12;

	if ( (initial - mw) * mr > initial  )
	{
		results = "Your savings are growing faster than your withdrawals.  Your savings will last forever!";
	}
	else
	{
		var savings = initial;

		var table = [];
		table.push("Here is how	your savings will change over time:");
		table.push("<br><table cellpadding='0' cellspacing='0'>");
		table.push("<tr><th>Year</th><th>Savings</th></tr>");
		table.push("<tr><td>start</td><td>" + DT_F.formatDollars(savings) + "</td></tr>");
		for ( m=0; m<1200; )
		{
			savings = ( savings - mw ) * mr ;
			if ( savings <= 0 ) {
				break;
			}
			m++;
			if ( m % 12 == 0 )
			{
				table.push("<tr><td>" + m/12 + "</td><td>" + DT_F.formatDollars(savings) + "</td></tr>");
			}
		}
		table.push("</table>");

		if ( m == 0 )
		{
			results = "Unfortunately, your savings will not last for a single month.";
		}
		else if ( m == 1200 )
		{
			results = "Your savings will last for <b>at least 100 years</b>.  At the end of 100 years, you will have " + DT_F.formatDollars(savings) + ".";
			results += "<br><br>" + table.join('');
		}
		else
		{
			var years = Math.floor(m/12);
			var months = m % 12;
			results = "Your savings will last for <b>" + years + " years and " + months + " months</b>.";
			results += "<br><br>" + table.join('');
		}
	}

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

