function calculate()
{
	var income = document.getElementById("income").value;
	if ( income.length == 0 )
	{
		alert("Please enter a yearly income");
		return;
	}
	income = fixNumber(income);
	income = parseFloat(income);
	if ( isNaN(income) )
	{
		alert("Please enter the yearly income as a number");
		return;
	}
	if ( income < 0 )
	{
		alert("Please enter a yearly income >= 0");
		return;
	}
	
	var rate = document.getElementById("rate").value;
	if ( rate.length == 0 )
	{
		alert("Please enter an interest rate");
		return;
	}
	rate = fixNumber(rate);
	rate = parseFloat(rate);
	if ( isNaN(rate) )
	{
		alert("Please enter the interest rate as a number");
		return;
	}
	if ( rate <= 0 || rate >= 20 )
	{
		alert("Please enter a interest rate greater than 0 and less than 20");
		return;
	}

	var years = parseInt( document.getElementById("duration").value);

	var pforh = document.getElementById("pforh").value;
	if ( pforh.length == 0 )
	{
		alert("Please enter the percentage of your pre-tax income that you are able to spend on housing");
		return;
	}
	pforh = fixNumber(pforh);
	pforh = parseFloat(pforh);
	if ( isNaN(pforh) )
	{
		alert("Please enter the percentage of income for housing as a number");
		return;
	}
	if ( pforh <= 0 || pforh >= 100 )
	{
		alert("Please enter the percentage of income for housing as a number greater than 0 and less than 100");
		return;
	}

	var downpayment = document.getElementById("down").value;
	if ( downpayment.length == 0 )
	{
		alert("Please enter a down payment");
		return;
	}
	downpayment = fixNumber(downpayment);
	downpayment = parseFloat(downpayment);
	if ( isNaN(downpayment) )
	{
		alert("Please enter the down payment as a number");
		return;
	}
	if ( downpayment < 0 )
	{
		alert("Please enter a down payment >= 0");
		return;
	}

	var mrate = rate / 1200;
	var maxpayment = ( income / 12 ) * ( pforh / 100 );

	var loanamount;
	if ( years == -1 )
	{
		loanamount = maxpayment / mrate;
	}
	else
	{
		var factor = Math.pow(1 + mrate, years * 12 );
		loanamount = maxpayment / ( mrate / (1 - 1/factor) );
	}

	var houseprice = loanamount + downpayment;

	var x = document.getElementById("results");

	var results = "With the parameters you selected, the most expensive house you can afford costs <b>" + formatDollars(houseprice) + "</b>.";

	results += "<p>Your monthly payment would be <b>" + formatDollars(maxpayment) + "</b>.";

	if ( pforh > 28 )
		results += "<p>28% is the standard banking figure for income devoted to housing.  Depending on your debt, income, and other factors, it might not be prudent to exceed this percentage.";
	
	if ( years == -1 )
		results += "<p>With an interest only mortgage, you will never own your house outright.</span>";

	x.innerHTML = results;
	x.style.display = "block";
}