$(document).ready(function(){
	$('#calculate').click(function() {
		var price = $('#price').asNumber();
		var down = $('#down').asNumber();
		var years = $('#years').val();
		var int = $('#int').val();

		if (price <= 0 || price.length == 0) {
			$('#results').slideUp('fast');
			$('#error').html("ERROR: Please enter a price").slideDown('slow');
			}
		else if(down > price) {
			$('#results').slideUp('fast');
			$('#error').html("ERROR: The down payment amount must be less than the price").slideDown('slow');
			}
		else if (years <= 0 || years.length == 0) {
			$('#results').slideUp('fast');
			$('#error').html("ERROR: Please enter the loan term").slideDown('slow');
			}
		else if (int <= 0 || price.length == 0) {
			$('#results').slideUp('fast');
			$('#error').html("ERROR: Please enter an interest rate").slideDown('slow');
			}
        else {
			$('#error').html("").slideUp('slow');
			princ = price-down;
			intRate = (int/100) / 12;
			months = years * 12;
            var pmt = Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100;
			$('#monthly_payment').html(pmt).formatCurrency();
			$('#results').slideDown('slow');
		}
	})
}); //end doc ready

