dt_ror_calculate = function()
{
	var pPrice, cPrice, d1, m1, y1, d2, m2, y2;
	try
	{
		pPrice = DT_F.getFormFloat("dt_ror_pprice", "Please enter the purchase price", "Please enter the purchase price as a number" );
		if ( pPrice <= 0 ) {
			throw("Please enter a purchase price > 0");
		}
		cPrice = DT_F.getFormFloat("dt_ror_cprice", "Please enter the sale price", "Please enter the sale price as a number" );
		if ( cPrice <= 0 ) {
			throw("Please enter a sale price > 0");
		}
		y1 = DT_F.getFormInt("dt_ror_year1", "Please enter the year that you bought the investment", "Please enter, as a number, the year that you bought the investment", "The purchase year was not valid.  We rounded it to" );
		if ( y1 < 0 || y1 > 3000 ) {
			throw("Please enter a purchase year between 0 and 3000");
		}
		m1 = parseInt( document.getElementById("dt_ror_month1").value, 10 );
		d1 = DT_F.getFormInt("dt_ror_day1", "Please enter the day of the month that you bought the investment", "Please enter, as a number, the day of the month that you bought the investment", "The purchase day was not valid.  We rounded it to" );
		if ( d1 < 1 || d1 > DT_F.getDaysInMonth(m1,y1) ) {
			throw("The purchase date is wrong.  For this month and year, enter a day between 1 and " + DT_F.getDaysInMonth(m1,y1) + ".");
		}

		y2 = DT_F.getFormInt("dt_ror_year2", "Please enter the sale year", "Please enter, as a number, the sale year", "The sale year was not valid.  We rounded it to" );
		if ( y2 < 0 || y2 > 3000 ) {
			throw("Please enter a sale year between 0 and 3000");
		}
		m2 = parseInt( document.getElementById("dt_ror_month2").value, 10 );
		d2 = DT_F.getFormInt("dt_ror_day2", "Please enter the sale day", "Please enter, as a number, the sale day", "The sale day was not valid.  We rounded it to" );
		if ( d2 < 1 || d2 > DT_F.getDaysInMonth(m2,y2) ) {
			throw("The saoe date is wrong.  For this month and year, enter a day between 1 and " + DT_F.getDaysInMonth(m2,y2) + ".");
		}

		DT_V.date1 = new Date(y1, m1, d1);
		DT_V.date2 = new Date(y2, m2, d2);
		DT_F.setDateElements("dt_ror_day1", "dt_ror_month1", "dt_ror_year1", DT_V.date1);
		DT_F.setDateElements("dt_ror_day2", "dt_ror_month2", "dt_ror_year2", DT_V.date2);

		if ( DT_F.dateLater(DT_V.date1, DT_V.date2) >= 0 ) {
			throw("The sale date must be later than the purchase date");
		}
	}
	catch ( err )
	{
		alert(err);
		return;
	}

	var years = DT_F.getYearDifference(DT_V.date1, DT_V.date2);
	var pct = 100 * ( Math.pow(cPrice/pPrice,  1 /years ) - 1 );	
	var x = document.getElementById("dt_ror_results");
	var results = "You owned the investment for " + years.toFixed(2) + " years.";
	results += "<br><br>During that time, its value changed at an annual rate of <b>" + pct.toFixed(2) + "%</b>.";
	x.innerHTML = results;
	x.style.display = "block";
};

dt_ror_load = function()
{
	DT_V.date1 = new Date("2000", "0", "1");
	DT_V.date2 = new Date();
	DT_F.setDateElements("dt_ror_day1", "dt_ror_month1", "dt_ror_year1", DT_V.date1);
	DT_F.setDateElements("dt_ror_day2", "dt_ror_month2", "dt_ror_year2", DT_V.date2);
};

