function calculatePayment() {
	var amount = parseFloat(document.getElementById("amount").value);
	if(!amount) {
		alert("Please enter an amount.");
		return false;
	}
	var interest = parseFloat(document.getElementById("interest").value);
	if(!interest) {
		alert("Please enter an interest rate.");
		return false;
	}
	var downpayment = parseFloat(document.getElementById("downpayment").value);
	if(!downpayment) {
		alert("Please enter a down payment.");
		return false;
	}
	var term = parseFloat(document.getElementById("term").value);
	var insurance = parseFloat(document.getElementById("insurance").value)/12;
	if(!insurance) {
		insurance = 0;
	}
	var taxes = parseFloat(document.getElementById("taxes").value)/12;
	if(!taxes) {
		taxes = 0;
	}
	interest = interest/1200;
	var monthly = (interest + (interest/((Math.pow(interest+1, 12*term))-1)))*(amount-downpayment);
	
	document.getElementById("payment").innerHTML = '$' + fmtMoney(monthly+insurance+taxes, 2, '.', ',');

}

function fmtMoney( n, c, d, t ) {
	var m = ( c = Math.abs( c ) + 1 ? c : 2, d = d || ",", t = t || ".", /(\d+)(?:(\.\d+)|)/.exec( n + "" ) ), x = m[1].length % 3;
	return ( x ? m[1].substr( 0, x ) + t : "" ) + m[1].substr( x ).replace( /(\d{3})(?=\d)/g, "$1" + t ) + ( c ? d + ( +m[2] ).toFixed( c ).substr( 2 ) : "" );
};
