
function formatCurrency(num)
{if(num){num=num.toString().replace(/\$|,/g,'');if(isNaN(num))
num="0";sign=(num==(num=Math.abs(num)));num=Math.floor(num*100+0.50000000001);cents=num%100;num=Math.floor(num/100).toString();if(cents<10)
cents="0"+cents;for(var i=0;i<Math.floor((num.length-(1+i))/3);i++)
num=num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));return(((sign)?'':'-')+num+'.'+cents);}}
function calculate_payment(PV,IR,NP){var PMT=(PV*IR)/(1-Math.pow(1+IR,-NP));return round_decimals(PMT,2);}
function round_decimals(original_number,decimals){var result1=original_number*Math.pow(10,decimals);var result2=Math.round(result1);var result3=result2/Math.pow(10,decimals);return(result3);}
function run_calculator(){var present_value=document.loancalc.present_value.value;var loan_term=document.loancalc.loan_term.value/12;var interest_rate=document.loancalc.interest_rate.value/100;var balloon_value_percent=document.loancalc.balloon_value.value;present_value=present_value.replace(/[\s,\$]/g,"");balloon_value_percent=balloon_value_percent.replace(/[\s,\$]/g,"");balloon_value=balloon_value_percent*present_value;var monthly_payment_balloon=calculate_payment(present_value-balloon_value,interest_rate/12,loan_term*12)+(balloon_value*0.075/12);if(isNaN(monthly_payment_balloon)){document.loancalc.result.value=monthly_payment_balloon="Error";}
else{document.loancalc.result.value='$'+formatCurrency(monthly_payment_balloon);}}
function run_calculator2(){var present_value=document.calc.present_value.value;var loan_term=document.calc.loan_term.value/12;var interest_rate=document.calc.interest_rate.value/100;var balloon_value_percent=document.calc.balloon_value.value;present_value=present_value.replace(/[\s,\$]/g,"");balloon_value_percent=balloon_value_percent.replace(/[\s,\$]/g,"");balloon_value=balloon_value_percent*present_value;var monthly_payment_balloon=calculate_payment(present_value-balloon_value,interest_rate/12,loan_term*12)+(balloon_value*0.075/12);if(isNaN(monthly_payment_balloon)){document.calc.result.value=monthly_payment_balloon="Error";}
else{document.calc.result.value=formatCurrency(monthly_payment_balloon);}}