function calculate()
{
    var ajaxObj = new Ajax.Request('/Tools/Calculators/Loan_Calculator',
            {method: 'post',
             parameters : 'years='+ encodeURIComponent($('years').value) +'&amount='+ encodeURIComponent($('amount').value) +'&apr='+ encodeURIComponent($('apr').value),
             onComplete: function(originalRequest)
            {
            	if (originalRequest.responseJSON && typeof originalRequest.responseJSON == 'object') {
            		$('txtPeriods').value = originalRequest.responseJSON.periods;
            		$('txtMonthly').value = originalRequest.responseJSON.monthly_pmt;
            		$('txtTotal').value = originalRequest.responseJSON.total_pmt;
            		$('txtInterest').value = originalRequest.responseJSON.total_int;
            	}
            }
    });

    ajaxObj = null;
    return false;
}

function calculatorReset() {
	['txtPeriods', 'txtMonthly', 'txtTotal', 'txtInterest'].each(function (field) {
		$(field).value = '';
	});
	
	$('years').value = '10';
	$('amount').value = '10000.00';
	$('apr').value = '7';
	
	return false;
}