dt_appr_calculate = function()
{
	var pPrice, cPrice, d1, m1, y1, d2, m2, y2;
	try
	{
		pPrice = DT_F.getFormFloat("dt_appr_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_appr_cprice", "Please enter the current price", "Please enter the current price as a number" );
		if ( cPrice < 0 ) {
			throw("Please enter a current price >= 0");
		}
		y1 = DT_F.getFormInt("dt_year1", "Please enter the year that you bought the house", "Please enter, as a number, the year that you bought the house", "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_month1").value );
		d1 = DT_F.getFormInt("dt_day1", "Please enter the day of the month that you bought the house", "Please enter, as a number, the day of the month that you bought the house", "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_year2", "Please enter the current year", "Please enter, as a number, the current", "The current year was not valid.  We rounded it to" );
		if ( y2 < 0 || y2 > 3000 ) {
			throw("Please enter a current year between 0 and 3000");
		}
		m2 = parseInt( document.getElementById("dt_month2").value );
		d2 = DT_F.getFormInt("dt_day2", "Please enter the current day of the month", "Please enter, as a number, the current day of the month", "The current day was not valid.  We rounded it to" );
		if ( d2 < 1 || d2 > DT_F.getDaysInMonth(m2,y2) ) {
			throw("The current 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("1", DT_V.date1);
		DT_F.setDateElements("2", DT_V.date2);

		if ( DT_F.dateLater(DT_V.date1, DT_V.date2) >= 0 ) {
			throw("The purchase date must be earlier than today's 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_appr_results");
	var results = "You have owned your house for " + years.toFixed(2) + " years.";
	results += "<br><br>During that time, its value has changed at an annual rate of <b>" + pct.toFixed(2) + "%</b>.";
	x.innerHTML = results;
	x.style.display = "block";
};

dt_appr_load = function()
{
	DT_V.date1 = new Date("2000", "0", "1");
	DT_V.date2 = new Date();
	DT_F.setDateElements("1", DT_V.date1);
	DT_F.setDateElements("2", DT_V.date2);
};
