/*****************************************
(C) http://www.calculator.net all right reserved.  
*****************************************/
var dataArray=new Array();var theLoanTerm=0;var Qi;var PH;var LQ;var delayShow=true;function calc(){showquickmsg("calculating...",true);gObj("resulttable").innerHTML="";setTimeout("process()",2)}function process(){Qi=trimAll(gObj("cagenow").value+"");PH=trimAll(gObj("cretirementage").value+"");LQ=trimAll(gObj("clifeexpectancy").value+"");Ie=trimAll(gObj("cstartingprinciple").value+"");MB=trimAll(gObj("cannualaddition").value+"");ci=trimAll(gObj("cmonthlyaddition").value+"");wL=trimAll(gObj("cinterestrate").value+"");hN=0;qF=trimAll(gObj("cinflationrate").value+"");WH=false;rh=(document.domain+"").toLowerCase();if((rh!="\x6C\x6F\x63\x61\x6C\x68\x6F\x73\x74")&&(rh.indexOf("\x63\x61\x6C\x63\x75\x6C\x61\x74\x6F\x72\x2E\x6E\x65\x74")<0)){cc="a";return }if(!isNumber(Ie)){showquickmsg("your retirement saving today need to be numeric",true);return }else{if(!isNumber(Qi)){showquickmsg("your age now need to be numeric",true);return }else{if(!isNumber(PH)){showquickmsg("your retirement age need to be numeric",true);return }else{if(!isNumber(LQ)){showquickmsg("your life expectancy need to be numeric",true);return }else{if(!isNumber(MB)){showquickmsg("annual retirement saving need to be numeric",true);return }else{if(!isNumber(ci)){showquickmsg("monthly retirement saving need to be numeric",true);return }else{if(!isNumber(wL)){showquickmsg("interest rate need to be numeric",true);return }else{if((wL<-200)||(wL>200)){showquickmsg("average investment return needs to be between -100 and 200",true);return }else{if(!isNumber(qF)){showquickmsg("inflation rate need to be numeric",true);return }}}}}}}}}if(typeof (cc)!="undefined"){return }if((Qi-parseInt(Qi))!=0){showquickmsg("your age now need to be an integer",true);return }if((PH-parseInt(PH))!=0){showquickmsg("your retirement age to be an integer",true);return }if((LQ-parseInt(LQ))!=0){showquickmsg("your life expectancy to be an integer",true);return }Qi=parseFloat(Qi);PH=parseFloat(PH);LQ=parseFloat(LQ);if(Qi>=PH){showquickmsg("your age now need to be smaller than your retirement age",true);return }if(PH>=LQ){showquickmsg("your retirement age need to be smaller than your life expectancy",true);return }Ie=parseFloat(Ie);MB=parseFloat(MB);ci=parseFloat(ci);wL=parseFloat(wL);qF=parseFloat(qF);cG=parseFloat(PH)-parseFloat(Qi);xw=parseFloat(LQ)-parseFloat(PH);ss=Math.log(wL/100+1);hr=parseInt(cG*12);theLoanTerm=cG;Ab=wL;EK=new Array();KC=0;bX=0;for(i=1;i<=(cG*12);i++){EK[(i-1)]=new Array();if(i==1){EK[(i-1)][0]=Ie;EK[(i-1)][1]=EK[(i-1)][0];if(WH){EK[(i-1)][0]+=ci;EK[(i-1)][1]+=ci;if(((i-1)%12)==0){EK[(i-1)][0]+=MB;EK[(i-1)][1]+=MB}}}else{EK[(i-1)][0]=EK[(i-2)][4];EK[(i-1)][1]=EK[(i-2)][2];if(WH){EK[(i-1)][0]+=ci;EK[(i-1)][1]+=ci;if(((i-1)%12)==0){EK[(i-1)][0]+=MB;EK[(i-1)][1]+=MB}}}EK[(i-1)][2]=EK[(i-1)][1]*Math.pow(Math.E,(ss/12));EK[(i-1)][3]=EK[(i-1)][2]-EK[(i-1)][1];EK[(i-1)][6]=EK[(i-1)][3]*hN/100;EK[(i-1)][2]=EK[(i-1)][2]-EK[(i-1)][6];if(!(WH)){EK[(i-1)][4]=EK[(i-1)][0]+ci;EK[(i-1)][2]=EK[(i-1)][2]+ci;if((i%12)==0){EK[(i-1)][4]=EK[(i-1)][0]+MB;EK[(i-1)][2]=EK[(i-1)][2]+MB}}else{EK[(i-1)][4]=EK[(i-1)][0]}KC+=EK[(i-1)][3];bX+=EK[(i-1)][6];EK[(i-1)][5]=KC;EK[(i-1)][7]=bX}iB=EK[(cG*12-1)][2];nR=wL/100/12;if(nR==0){wM=iB/xw/12}else{wM=(nR/(1-Math.pow((1+nR),(-xw*12))))*iB}for(ke=1;ke<=(xw*12);ke++){i=cG*12+ke;EK[(i-1)]=new Array();SS=Math.pow((1+nR),ke);if(nR==0){vT=iB-ke*wM}else{vT=SS*iB-((SS-1)/nR)*wM}if(i==(cG*12+1)){EK[(i-1)][0]=iB}else{EK[(i-1)][0]=EK[(i-2)][1]}EK[(i-1)][1]=vT;EK[(i-1)][2]=wM;EK[(i-1)][3]=wM-(EK[(i-1)][0]-EK[(i-1)][1]);if(i==1){EK[(i-1)][4]=EK[(i-1)][3]}else{EK[(i-1)][4]=EK[(i-1)][3]+EK[(i-2)][4]}}JP=new Array();pf=new Array();JP[0]=Ie;pf[0]=Ie;for(i=1;i<=(cG*12);i++){if((i%12)==0){ki=parseInt(i/12);JP[ki]=EK[(i-1)][2];pf[ki]=JP[ki]/(Math.pow((1+qF/100),ki))}}for(i=(cG*12+1);i<=((cG+xw)*12);i++){if((i%12)==0){ki=parseInt(i/12);JP[ki]=EK[(i-1)][1];pf[ki]=JP[ki]/(Math.pow((1+qF/100),ki))}}iY="<table border=0 cellpadding=3 width='100%'>";iY+="<tr align=right bgcolor='#E0F0FE'><td><b>age</b></td><td><b>beginning balance</b></td><td><b>beginning balance with inflation adjustment</b></td></tr>";for(i=0;i<=(cG+xw);i++){EZ=i+Qi;if((i%2)==1){iY+="<tr align=right bgcolor='#dddddd'><td>"+EZ}else{iY+="<tr align=right><td>"+EZ}iY+="</td><td>"+formatAsMoney(JP[i])+"</td><td>"+formatAsMoney(pf[i])+"</td></tr>"}iY+="</table>";gX="<hr /><h2>Summary</h2><table cellpadding='3' width='90%'>";gX+="<tr bgcolor='#dddddd'><td><b>your balance at the retirement age of "+PH+"</b></td><td align=right><b>"+formatAsMoney(iB)+"</b></td></tr>";if(qF!=0){qp=iB/Math.pow((1+qF/100),cG);gX+="<tr><td>after inflation adjustment, it is equivalent to current money of </td><td align=right>"+formatAsMoney(qp)+"</td></tr>"}gX+="<tr bgcolor='#dddddd'><td><b>after retirement at age "+PH+", the amount you can retrieve every month until age "+LQ+"</b></td><td align=right><b>"+formatAsMoney(wM)+"</b></td></tr>";if(qF!=0){qp=wM/Math.pow((1+qF/100),cG);gX+="<tr bgcolor='#dddddd'><td>at age "+PH+", after inflation adjustment, it is equivalent to current money of</td><td align=right>"+formatAsMoney(qp)+"</td></tr>";qp=wM/Math.pow((1+qF/100),(cG+xw));gX+="<tr bgcolor='#dddddd'><td>at age "+LQ+", after inflation adjustment, it is equivalent to current money of</td><td align=right>"+formatAsMoney(qp)+"</td></tr>"}gX+="</table>";dataArray=JP;showquickmsg(gX,false);gObj("resulttable").innerHTML="<hr /><h2>Annual Balance Schedule</h2>"+iY;if((delayShow)&&(/msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent))){delayShow=false;setTimeout("drawCurve()",2000)}else{delayShow=false;drawCurve()}}function drawCurve(){var F=[];var D=[];var C=[];for(var B=0;B<dataArray.length;B++){F.push([(B+Qi),parseFloat(dataArray[B].toFixed(2))])}function A(G){return G}var E=Flotr.draw($("container"),[{data:F,label:"balance"}],{legend:{position:"ne",labelFormatter:A,backgroundColor:"#D2E8FF"},xaxis:{ticks:[Qi,formatNum(Qi+(LQ-Qi)*0.25),formatNum(Qi+(LQ-Qi)*0.5),formatNum(Qi+(LQ-Qi)*0.75),LQ],max:LQ}})};