function updateMortgage(){var d=document.getElementById("price").value;var f=document.getElementById("downPayment").value;var b=document.getElementById("loanRate").value;var e=document.getElementById("loanTerm").value;var c=document.getElementById("monthlyPayment");var g=0;var a=0;d=removecomma(d);f=removecomma(f);if(isNaN(d)){alert("Please enter numeric values only in the Principal box.");return}if(isNaN(f)){alert("Please enter numeric values only in the Down Payment box.");return}d=d.length==0?0:parseFloat(d);f=f.length==0?0.2*parseFloat(d):parseFloat(f);if(f>=d){alert("To use this calculator your Principal amount has to be higher than your Down Payment.");return}d=d-f;g=e*12;b=b/1200;fltCompounded=1;for(intCounter=0;intCounter<g;intCounter++){fltCompounded=fltCompounded*(1+b)}a=(d*fltCompounded*b)/(fltCompounded-1);c.value=parseInt(a,10);document.getElementById("price").value=formatCurrency(document.getElementById("price").value);document.getElementById("downPayment").value=formatCurrency(document.getElementById("downPayment").value);document.getElementById("monthlyPayment").value=formatCurrency(document.getElementById("monthlyPayment").value)}function removecomma(e){var b;var f,c,d;var a=e.length;b=e.indexOf(",",0);f="";c=e.substring(0);if(b==-1){return e}while(b!=-1){f=f+c.substring(0,b);c=c.substring(b+1);b=c.indexOf(",",0)}d=f+c;return d}function formatCurrency(a){a=a.toString().replace(/\$|\,/g,"");if(isNaN(a)){a="0"}sign=(a==(a=Math.abs(a)));a=Math.floor(a*100+0.50000000001);a=Math.floor(a/100).toString();for(var b=0;b<Math.floor((a.length-(1+b))/3);b++){a=a.substring(0,a.length-(4*b+3))+","+a.substring(a.length-(4*b+3))}return(((sign)?"":"-")+a)}function BuildOnKeyDownScriptMort(c,b){var a=window.event?c.keyCode:c.which;if(a==13){c.returnValue=false;c.cancel=true;UpdateMortgage()}};
