function calculate_loan_amount() {
var form = document.mortgage_calc_form;
form.loan.value = (form.total_property_value.value - form.deposit.value);
}
function calculate_mortgage() {
var form = document.mortgage_calc_form;
// do field validation
if (form.loan.value == ""){
alert( "Loan amount is required." );
} else if (form.duration.value == ""){
alert( "Duration is required." );
} else if (form.interest_rate.value == ""){
alert( "Interest rate is required." );
} else {
var loan = form.loan.value;
loan = loan.replace(",",""); // Remove commas
//Round instead of replace decimal
//loan = loan.replace(".",""); // Remove preiods
loan = Math.round(loan);
form.loan.value = loan; // refresh loan amount in form without commas or periods
var duration = form.duration.value; // in months
var interest_rate = form.interest_rate.value.replace(",","."); // Replace comma with period
form.interest_rate.value = interest_rate; // refresh duration in form without commas
interest_rate = ((interest_rate/12)/100); // monthly
var m_value = interest_rate + 1;
var m_pow = Math.pow(m_value,duration);
var m_powsub = 1.0 / m_pow;
var m_powsub2 = 1.0 - m_powsub;
var m_quote = interest_rate/ m_powsub2;
var quote = loan * m_quote;
//
//
//var quote = interest_rate / mpowsub2;
//var quote = (loan * interest_rate) / (( 1 - Math.pow ( ( 1 + (interest_rate/100) ), -duration ) ) );
if (quote.toFixed) { //if browser supports toFixed() method
quote = quote.toFixed(2);
}
form.quote.value = quote; // monthly
// Calculate total to be repaid
var total = (quote * duration);
form.total.value = total; // total
}
}
var mortgage_calc_popUpWin=0;
function mortgage_calc_popUpWindow(URLStr, left, top, width, height) {
if(mortgage_calc_popUpWin) {
if(!mortgage_calc_popUpWin.closed) mortgage_calc_popUpWin.close();
}
mortgage_calc_popUpWin = open(URLStr, 'mortgage_calc_popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
JDF Loan Calculator