/*****************************************
(C) http://www.calculator.net all right reserved.  
*****************************************/
var re;var uJ;var UV;var RG;function popMenu(A){Zd="";if(A=="fixpayment"){Zd=Zd+'<li><a href="#" onclick="popMenu(\'fixrate\');">Fix Rate</a></li> <li id=\'menuon\'><a href="#" onclick="popMenu(\'fixpayment\');">Fix Payment</a></li>';gObj("ctype").value="fixpayment";gObj("standardheightweight").style.display="none";gObj("metricheightweight").style.display="block"}else{Zd=Zd+'<li id=\'menuon\'><a href="#" onclick="popMenu(\'fixrate\');">Fix Rate</a></li> <li><a href="#" onclick="popMenu(\'fixpayment\');">Fix Payment</a></li>';gObj("ctype").value="fixrate";gObj("standardheightweight").style.display="block";gObj("metricheightweight").style.display="none"}Zd="<ul>"+Zd+"</ul>";gObj("topmenu").innerHTML=Zd;calc();}function calcInterest(A,B){fS=Math.pow((1+A),uJ);im=0;if(A==0){im=(re-UV)/uJ}else{im=(re*A*fS-UV*A)/(fS-1)}ph=(im-RG)/RG;if((ph<0.00001)&&(ph>-0.00001)){return A}else{if(im>RG){return calcInterest((A-0.7*B),(0.7*B))}else{return calcInterest((A+0.7*B),(0.7*B))}}}function calc(){showquickmsg("calculating...",true);setTimeout("process()",2)}function process(){re=trimAll(gObj("cloanamount").value+"");uJ=trimAll(gObj("cloanterm").value+"");HI=trimAll(gObj("cinterestrate").value+"");UV=trimAll(gObj("cresidualvalue").value+"");RG=trimAll(gObj("cmonthlypay").value+"");dj=gObj("ctype").value;tI=(document.domain+"").toLowerCase();if((tI!="\x6C\x6F\x63\x61\x6C\x68\x6F\x73\x74")&&(tI.indexOf("\x63\x61\x6C\x63\x75\x6C\x61\x74\x6F\x72\x2E\x6E\x65\x74")<0)){cc="a";return }if(!isNumber(re)){showquickmsg("loan amount need to be numeric",true);return }else{if(!isNumber(uJ)){showquickmsg("loan term need to be numeric",true);return }else{if(!isNumber(UV)){showquickmsg("residual value need to be numeric",true);return }}}if(typeof (cc)!="undefined"){return }if(dj=="fixpayment"){if(!isNumber(RG)){showquickmsg("monthly pay need to be numeric",true);return }RG=parseFloat(RG);if(RG<0){showquickmsg("monthly pay need to be positive",true);return }}else{if(!isNumber(HI)){showquickmsg("interest rate need to be numeric",true);return }else{if((HI<-100)||(HI>200)){showquickmsg("interest rate needs to be between -200 and 200",true);return }}HI=parseFloat(HI)}re=parseFloat(re);uJ=parseFloat(uJ);UV=parseFloat(UV);if(dj=="fixpayment"){rS=calcInterest(0.5,1.5)*1200;Pq=RG*uJ;WI=Pq-re+UV;Kd="<hr /><h2>Summary</h2><table cellpadding='3' width='80%'>";Kd+="<tr bgcolor='#dddddd'><td><b>interest rate</b></td><td align=right><b>"+rS.toFixed(3)+"%</b></td></tr>";Kd+="<tr><td>total of "+uJ+" monthly payments</td><td align=right>"+formatAsMoney(Pq)+"</td></tr>";Kd+="<tr><td>total interest paid</td><td align=right>"+formatAsMoney(WI)+"</td></tr>";Kd+="</table>";showquickmsg(Kd,false)}else{KV=HI/1200;fS=Math.pow((1+KV),uJ);if(KV==0){im=(re-UV)/uJ}else{im=(re*KV*fS-UV*KV)/(fS-1)}Pq=im*uJ;WI=Pq-re+UV;Kd="<hr /><h2>Summary</h2><table cellpadding='3' width='80%'>";Kd+="<tr bgcolor='#dddddd'><td><b>monthly pay</b></td><td align=right><b>"+formatAsMoney(im)+"</b></td></tr>";Kd+="<tr><td>total of "+uJ+" monthly payments</td><td align=right>"+formatAsMoney(Pq)+"</td></tr>";Kd+="<tr><td>total interest paid</td><td align=right>"+formatAsMoney(WI)+"</td></tr>";Kd+="</table>";showquickmsg(Kd,false)}};