function trimall(sString) 
{
    while (sString.substring(0,1) ==" ")
    {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}
function replaceAll( str, replacements ) 
{
	for ( i = 0; i < replacements.length; i++ ) 
	{
		var idx = str.indexOf( replacements[i][0] );
		while ( idx > -1 ) 
		{
			str = str.replace( replacements[i][0], replacements[i][1] ); 
			idx = str.indexOf( replacements[i][0] );
		}
	}
	return str;
}
function Menuchose(id)
{
    for(var j=1; j<=11; j++)
    {
        if(document.getElementById("Menucon"+j)!=null)
            document.getElementById("Menucon"+j).style.display="none";
        document.getElementById("MenuTit"+j).className="UnSelMenuHead";
        document.getElementById("img"+j).src="../images/Spacer.gif";
    }
    
    if(document.getElementById("Menucon"+id)!=null)
        document.getElementById("Menucon"+id).style.display="inline";
    document.getElementById("MenuTit"+id).className="SelMenuHead";
    document.getElementById("img"+id).src="../images/arrowseletion.gif";
}
    
function changeContent(opt)
{
    //  changeSubmenuStyle(opt); 
    var finurl="";
    var secname="";
    if(opt=="101")
    {
        finurl="frmSavingEnough.aspx";
        secname="Saving Enough?";
    }
    else if(opt=="102")
    {
        finurl="frmEffectROI.aspx";
        secname="Effect of Rate of Interest";
    }
    else if(opt=="103")
    {
        finurl="frmCostOfliving.aspx";
        secname="Cost of Living";
    }
    else if(opt=="104")
    {
        finurl="frmWealthRetirement.aspx";
        secname="Wealth at Retirement";
    }
    else if(opt=="201")
    {
        finurl="frmRiskAnalyzer.aspx";
        secname="Risk Analyser";
    }
    else if(opt=="202")
    {
        finurl="frmAssetAllocator.aspx";
        secname="Asset Allocator";
    }
    else if(opt=="301")
    {
        finurl="frmHRAExemption.aspx";
        secname="HRA Exemption";
    }
    else if(opt=="302")
    {
        finurl="frmCapitalGains.aspx";
        secname="Capital Gains Tax Calculator";
    }
    else if(opt=="303")
    {
        finurl="frmTaxFreeTax.aspx";
        secname="Tax v/s Tax-free Investment";
    }
    else if(opt=="401")
    {
        finurl="frmSavingMillion.aspx";
        secname="Saving a Million";
    }
    else if(opt=="402")
    {
        finurl="frmMakingMillion.aspx";
        secname="Making a Million";
    }
    else if(opt=="403")
    {
        finurl="frmSaving.aspx";
        secname="Saving Enough";
    }
    else if(opt=="404")
    {
        finurl="frmMakingCrore.aspx";
        secname="Making a Crore";
    }
    else if(opt=="405")
    {
        finurl="frmAmountSaved.aspx";
        secname="Amount to be Saved";
    }
    else if(opt=="406")
    {
        finurl="frmSpendLessSave.aspx";
        secname="Spend less and Save";
    }
    else if(opt=="407")
    {
        finurl="frmSavingsWorth.aspx";
        secname="Saving Worth";
    }
    else if(opt=="408")
    {
        finurl="frmInflationImpact.aspx";
        secname="Inflation Impact ";
    }
    else if(opt=="409")
    {
        finurl="frmReturnSavings.aspx";
        secname="Returns on Savings";
    }
    else if(opt=="410")
    {
        finurl="frmCompoundingMagic.aspx";
        secname="Compounding Magic";
    }
    else if(opt=="501")
    {
        finurl="frmDebtCalculator.aspx";
        secname="Debt Calculator";
    }
    else if(opt=="502")
    {
        finurl="frmExpenseSheet.aspx";
        secname="My Expense Sheet";
    }
    else if(opt=="503")
    {
        finurl="frmSettleDebt.aspx";
        secname="Settle Debt or not";
    }
    else if(opt=="504")
    {
        finurl="frmMyNetworth.aspx";
        secname="My Networth";
    }
    else if(opt=="601")
    {
        finurl="frmBondYield.aspx";
        secname="Bond Yield ";
    }
    else if(opt=="602")
    {
        finurl="frmCurrentBondYield.aspx";
        secname="Current Bond Yield";
    }
    else if(opt=="603")
    {
        finurl="frmImpliedBondYield.aspx";
        secname="Implied Bond Yield";
    }
    else if(opt=="604")
    {
        finurl="frmFDCalculator.aspx";
        secname="Fixed Deposit Calculator";
    }
    else if(opt=="605")
    {
        finurl="frmPPFWithdrawal.aspx";
        secname="PPF Withdrawal Calculator";
    }
    else if(opt=="606")
    {
        finurl="frmPPFSimpCalc.aspx";
        secname="PPF Returns Calculator";
    }
    else if(opt=="607")
    {
        finurl="frmPPFLoan.aspx";
        secname="PPF Loan Calculator";
    }
    else if(opt=="701")
    {
        finurl="frmEMIAdv.aspx";
        secname="Auto EMI Calculator";
    }
    else if(opt=="702")
    {
        finurl="frmFirr.aspx";
        secname=" Flat Rate Cost";
    }
    else if(opt=="801")
    {
        finurl="frmEMI.aspx";
        secname="EMI Calculator";
    }
    else if(opt=="802")
    {
        finurl="frmTaxSave.aspx";
        secname="Tax Saving on Housing Loan";
    }
    else if(opt=="901")
    {
        finurl="frmChildEducation.aspx";
        secname="Child's Education";
    }
    else if(opt=="1001")
    {
        finurl="frmChildWedding.aspx";
        secname="Child's Wedding";
    }
    else if(opt=="1101")
    {
        finurl="frmSipNeed.aspx";
        secname="SIP as per need ";
    }
    else if(opt=="1102")
    {
        finurl="frmSipTable.aspx";
        secname="SIP Table";
    }
    else if(opt=="1103")
    {
        finurl="frmSipCalculator.aspx";
        secname="SIP Need Calculator";
    }
    else if(opt=="1104")
    {
        finurl="frmSipCost.aspx";
        secname="SIP + Delay cost calculator";
    }
    else if(opt=="1105")
    {
        finurl="frmPVSingleAmt.aspx";
        secname="Present Value Single Amount";
    }
    else if(opt=="1106")
    {
        finurl="frmPVAnnuity.aspx";
        secname="Present Value of an Annuity";
    }
    else if(opt=="1107")
    {
        finurl="frmPVCashflows.aspx";
        secname="Present Value Irregular Cash Flows";
    }
    else if(opt=="1108")
    {
        finurl="frmSystematic.aspx";
        secname="Systematic Investment Plan (SIP)";
    }
    else if(opt=="1109")
    {
        finurl="FVGrowing.aspx";
        secname="Future Value Calculator (Growing)";
    }
    else if(opt=="1110")
    {
        finurl="frmFVDecreasing.aspx";
        secname="Future Value Calculator (Decreasing)";
    }
    if(finurl=="") finurl="frmPPFSimpCalc.aspx";
    document.getElementById("tdSection").innerHTML=secname;
    document.getElementById("tdFinTools").innerHTML="<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td align=center><img src='../images/loading1.gif'></td></tr></table>";  
    document.getElementById("tdFinTools").src="../FinancialTools/"+finurl;
    var ajax = new Ajax.Updater('tdFinTools',finurl,{evalScripts: true});        
}

function changeSubmenuStyle(subid)
{
    if(parseInt(subid)>=1101&&parseInt(subid)<=1110)
    {
        Menuchose('11');
        for(var i=1;i<=10;i++)
        {
            var idsub="";
            var subopt=subid.substring(2); 
            if(i<=9)
                idsub="0"+i.toString();
            else 
                idsub=i;
              
            if(idsub!=subopt)
                document.getElementById("M11"+idsub).className=" UnSelMenuSub BotMenulin";
            else
                document.getElementById("M11"+idsub).className=" SelMenuSub BotMenulin";
        }
    }
    else if(subid=="1001")
    {            
        Menuchose('10');            
    }
    else
    {
        var mainopt=subid.substring(0,1); 
        Menuchose(mainopt);   
            
        for(var i=1;i<=15;i++)
        {
            var idsub="";
            var subopt=subid.substring(1); 
            if(i<=9)
                idsub="0"+i;
            else 
                idsub=i;
                    
            if(idsub!=subopt)
            {
                if(document.getElementById("M"+mainopt+idsub)!=null)
                    document.getElementById("M"+mainopt+idsub).className=" UnSelMenuSub BotMenulin";
            }
            else
            {
                if(document.getElementById("M"+mainopt+idsub)!=null)
                    document.getElementById("M"+mainopt+idsub).className=" SelMenuSub BotMenulin";
            }
        }
    }
}

/* For Saving Enough, Wealth at Retirement */
function CL_display(viewShow)
{
    if (document.layers) 
    {
        content = document.layers[viewShow];
    }
    else if (document.all) 
    {
        content = document.all(viewShow).style;
    }
    document.getElementById("result").style.display = "inline";
}

function cl_calculate()
{
    var CL_current;
	var CL_roi;
	var CL_tenure;                 
	var CL_remain;
	var CL_fv;
	var CL_inf;
	var CL_tp;
	var CL_sav;
	var CL_age;
	var CL_ret;
	var CL_retamt;
	    
	CL_age=parseFloat(document.getElementById("CL_age").value,10);
	CL_ret=parseFloat(document.getElementById("CL_ret").value,10);
	CL_retamt=parseFloat(document.getElementById("CL_retamt").value,10);
	CL_tenure=CL_ret-CL_age;
	  
	if(CL_tenure<0)
	{
	    alert('Retirement age should be greater than your current age');
	    return false;
    }
	    
	CL_current=parseFloat(document.getElementById("CL_current").value,10);
	CL_roi=Math.pow(1+parseFloat(document.getElementById("CL_roi").value,10)/100,1/12)-1;
    CL_roi1=parseFloat(document.getElementById("CL_roi").value,10)/100;
    CL_inf=parseFloat(document.getElementById("CL_inf").value)/100;
    CL_fv=CL_retamt*Math.pow(1+CL_inf,CL_tenure);
    CL_remain=CL_fv-CL_current*Math.pow((1+CL_roi1),CL_tenure);
    CL_msav=parseFloat(document.getElementById("CL_msav").value);
    CL_tp=CL_msav*(Math.pow(1+CL_roi,CL_tenure*12)-1)/CL_roi;

    if(isNaN(Math.round((CL_remain*CL_roi)/(Math.pow((1+CL_roi),CL_tenure*12)-1))))
	{
	    alert('One or more of the numeric fields is wrong. Please Check');
	}
	else
	{
		if(document.layers)
		{
		    document.layers['result'].document.borrow.emi.value=Math.round((CL_remain*CL_roi)/(Math.pow((1+CL_roi),CL_tenure*12)-1));
		    document.layers['result'].document.borrow.CL_fv.value=Math.round(CL_fv);
		    document.layers['result'].document.borrow.CL_current.value=Math.round(CL_tp+CL_current*Math.pow((1+CL_roi1),CL_tenure));
    	}
	    else
    	{
	        document.borrow.emi.value=Math.round((CL_remain*CL_roi)/(Math.pow((1+CL_roi),CL_tenure*12)-1));
		    document.borrow.CL_fv.value=Math.round(CL_fv);
		    document.borrow.CL_current.value=Math.round(CL_tp+CL_current*Math.pow((1+CL_roi1),CL_tenure));
    	}
    }
}

function CL_hid(viewShow)
{
    if (document.layers)
    {
        content = document.layers[viewShow];
    }
    else if (document.all)
    {
        content = document.all(viewShow).style;
    }
    document.getElementById("result").style.display = "none";
}
/* For Saving Enough */


/* For Effect of ROI */
function cl_validate()
{
    var age=document.getElementById('age');
    var ret=document.getElementById('ret');
    var CL_retamt=document.getElementById('CL_retamt');
    var CL_current=document.getElementById('CL_current');
    var mon=document.getElementById('mon');
    var CL_roi=document.getElementById('CL_roi');
    
    if(isNaN(parseFloat(age.value))||parseFloat(age.value)<=0)
    {
        alert('Age should be greater than 0');
        age.focus();
        return false;
    }
    if(isNaN(parseFloat(ret.value))||parseFloat(ret.value)<=parseFloat(age.value))
    {
        alert('Retirement age should be greater than your age');
        ret.focus();
        return false;
    }
    if(isNaN(parseFloat(CL_retamt.value)))
    {
        alert('The Amount you want to retire with should be greater than 0');
        CL_retamt.focus();
        return false;
    }
    if(isNaN(parseFloat(CL_current.value))||parseFloat(CL_current.value)<0)
    {
        alert('Your current savings should be greater than or equal to 0');
        CL_current.focus();
        return false;
    }
    if(isNaN(parseFloat(mon.value))||parseFloat(mon.value)<0)
    {
        alert('Monthly savings should be greater than or equal to 0');
        mon.focus();
        return false;
    }
    if(isNaN(parseFloat(CL_roi.value))||parseFloat(CL_roi.value)<=0)
    {
        alert('Return on your investment should be greater than 0');
        CL_roi.focus();
        return false;
    }
    if(parseFloat(CL_roi.value)>100)
    {
        alert('Invalid Return on Interest Percentage');
        CL_roi.focus();
        return false;
    }
    return true;
}

function draw()
{
    var ary=Array()
    CL_roi=5/1200;
	cl_calculateROI();
    var CL_val8=CL_val;
    var divide=1;
    divide=CL_val/15;
    CL_roi=21/1200;
    cl_calculateROI();
    var CL_val21=CL_val;
    var ht=400;
    CL_roi=parseFloat(document.getElementById('CL_roi').value,10)/1200;
    cl_calculateROI();
    var interest=parseFloat(document.getElementById('CL_roi').value,10);
    ary[0]=CL_val/CL_val21*400;
    
    for(i=1;i<14;i++)
    {
        CL_roi=(8+i)/1200;
        cl_calculateROI();
        ary[i]=400/CL_val21*CL_val;
    }
    
    CL_win=window.open("",'ash1','scrollbars=yes,toolbar=no,menubar=no,resizable=yes,height=600,width=700','replace');
    CL_win.document.open();
	CL_win.focus();
	var bkcolor='ffffff';
	CL_win.document.write('<body bgcolor=#' + bkcolor + '>') ;
	CL_win.document.write('<table><tr><td><table><tr><td height='+ 40 + ' valign=top><font face=verdana size=1>Rs ' + Math.round(CL_val21/1000) + ' Thousands</font></td><td bgcolor=#000000 width=2><font face=verdana size=1>&nbsp;</font></td></tr>');
    CL_win.document.write('<tr><td height='+ 40 + ' valign=top><font face=verdana size=1>Rs ' + Math.round((9/10*(CL_val21))/1000) + ' Thousands</font></td><td bgcolor=#000000 width=2><font face=verdana size=1>&nbsp;</font></td></tr>');
	CL_win.document.write('<tr><td height='+ 40 + ' valign=top><font face=verdana size=1>Rs ' + Math.round((8/10*(CL_val21))/1000) + ' Thousands</font></td><td bgcolor=#000000 width=2><font face=verdana size=1>&nbsp;</font></td></tr>');
	CL_win.document.write('<tr><td height='+ 40 + ' valign=top><font face=verdana size=1>Rs ' + Math.round((7/10*(CL_val21))/1000) + ' Thousands</font></td><td bgcolor=#000000 width=2><font face=verdana size=1>&nbsp;</font></td></tr>');
	CL_win.document.write('<tr><td height='+ 40 + ' valign=top><font face=verdana size=1>Rs ' + Math.round((6/10*(CL_val21))/1000) + ' Thousands</font></td><td bgcolor=#000000 width=2><font face=verdana size=1>&nbsp;</font></td></tr>');
	CL_win.document.write('<tr><td height='+ 40 + ' valign=top><font face=verdana size=1>Rs ' + Math.round((5/10*(CL_val21))/1000) + ' Thousands</font></td><td bgcolor=#000000 width=2><font face=verdana size=1>&nbsp;</font></td></tr>');
	CL_win.document.write('<tr><td height='+ 40 + ' valign=top><font face=verdana size=1>Rs ' + Math.round((4/10*(CL_val21))/1000) + ' Thousands</font></td><td bgcolor=#000000 width=2><font face=verdana size=1>&nbsp;</font></td></tr>');
    CL_win.document.write('<tr><td height='+ 40 + ' valign=top><font face=verdana size=1>Rs ' + Math.round((3/10*(CL_val21))/1000) + ' Thousands</font></td><td bgcolor=#000000 width=2><font face=verdana size=1>&nbsp;</font></td></tr>');
    CL_win.document.write('<tr><td height='+ 40 + ' valign=top><font face=verdana size=1>Rs ' + Math.round((2/10*(CL_val21))/1000) + ' Thousands</font></td><td bgcolor=#000000 width=2><font face=verdana size=1>&nbsp;</font></td></tr>');
    CL_win.document.write('<tr><td height='+ 40 + ' valign=top><font face=verdana size=1>Rs ' + Math.round((1/10*(CL_val21))/1000) + ' Thousands</font></td><td bgcolor=#000000 width=2><font face=verdana size=1>&nbsp;</font></td></tr>');

    CL_win.document.write('</table></td>');
    CL_win.document.writeln('<td><font size=1>&nbsp;</font></td><td valign=bottom><table><tr><td valign=bottom bgcolor=#00aa00 width=4 height=' + Math.round(ary[0]) + '>&nbsp;</td></tr></table></td>');
    
    for(i=1;i<14;i++)
    {
        CL_win.document.writeln('<td><font size=1>&nbsp;</font></td><td valign=bottom><table><tr><td valign=bottom bgcolor=#aaaaaa width=2 height=' + Math.round(ary[i]) + '>&nbsp;</td></tr></table></td>');
    }
    CL_win.document.writeln('</tr><tr><td></td><td bgcolor=#000000 height=1 colspan=28></td>');
    CL_win.document.writeln('</tr><tr><td></td><td></td><td><font face=verdana size=1><b>' + interest + '%</b></font></td>');
    
    for(i=9;i<22;+i++)
    {
        CL_win.document.write('<td></td><td><font face=verdana size=1>' + i + '%</font></td>');
    }
    CL_win.document.write('</tr></table>');
    CL_win.document.writeln('<table><tr><td align=middle width=100%><font face=arial size=1><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Return on investment in %</b></font></td></tr></table>');
    CL_win.document.writeln('<table><tr><td><a href="#" onClick="javascript:top.window.close()"><font face=arial size=2>Back</font></a></td></tr></table>');
    CL_win.document.write('<table><tr><td Class="Blacktext"><font face=verdana size=2>With your current savings rate of <b>' + interest + '%</b> you should be able to save <b>Rs' + Math.round(ary[0]*CL_val21/400) + '</b><br></td></tr></table>');
}

function cl_calculateROI()
{
    var CL_current;                
    var CL_tenure;
    CL_tenure=(parseFloat(document.getElementById('ret').value,10)-parseFloat(document.getElementById('age').value,10));
    CL_current=parseFloat(document.getElementById('CL_current').value,10);
    CL_val=CL_current*Math.pow((1+CL_roi),CL_tenure*12);
    CL_val+=parseFloat(document.getElementById('mon').value,10)*((Math.pow((1+CL_roi),CL_tenure*12)-1)/CL_roi);
    if(isNaN(CL_val))
	{
	    alert('One or more of the numeric fields are wrong. Please check');
    }
}
/* For Effect of ROI */


/* For Cost of Living */
function CL_vlidate()
{
    var CL_infexp=document.getElementById('CL_infexp');
    var CL_ninfexp=document.getElementById('CL_ninfexp');
    var CL_col=document.getElementById('CL_col');
    var CL_incinf=document.getElementById('CL_incinf');
    var CL_decinf=document.getElementById('CL_decinf');
    var CL_nincinf=document.getElementById('CL_nincinf');
    var CL_ndecinf=document.getElementById('CL_ndecinf');
    var CL_inf=document.getElementById('CL_inf');
    
    if(isNaN(parseFloat(CL_infexp.value))||parseFloat(CL_infexp.value)<=0)
    {
        alert('Expenses should be greater than 0');
        CL_infexp.focus();
        return false;
    }
    if(isNaN(parseFloat(CL_ninfexp.value))||parseFloat(CL_ninfexp.value)<0)
    {
        alert('Expenses should be greater than or equal to 0');
        CL_ninfexp.focus();
        return false;
    }
    if(isNaN(parseFloat(CL_col.value))||parseFloat(CL_col.value)<0)
    {
        alert('Year should be greater than or equal to 0');
        CL_col.focus();
        return false;
    }
    if(isNaN(parseFloat(CL_incinf.value))||parseFloat(CL_incinf.value)<0)
    {
        alert('Increase should be greater than or equal to 0');
        CL_incinf.focus();
        return false;
    }
    if(isNaN(parseFloat(CL_decinf.value))||parseFloat(CL_decinf.value)<0)
    {
        alert('Decrease should be greater than or equal to 0');
        CL_decinf.focus();
        return false;
    }
    if(isNaN(parseFloat(CL_nincinf.value))||parseFloat(CL_nincinf.value)<0)
    {
        alert('Increase should be greater than or equal to 0');
        CL_nincinf.focus();
        return false;
    }
    if(isNaN(parseFloat(CL_ndecinf.value))||parseFloat(CL_ndecinf.value)<0)
    {
        alert('Decrease should be greater than or equal to 0');
        CL_ndecinf.focus();
        return false;
    }
    if(isNaN(parseFloat(CL_inf.value))||parseFloat(CL_inf.value)<0)
    {
        alert('Decrease should be greater than or equal to 0');
        CL_inf.focus();
        return false;
    }
    if(parseFloat(CL_inf.value)>100)
    {
        alert('Invalid Annual Inflation Percentage');
        CL_inf.focus();
        return false;
    }
    return true;
}

function CL_displayCOL(viewShow)
{
    if (document.layers) {
        content = document.layers[viewShow];
    }
    else if (document.all) {
        content = document.all(viewShow).style;
    }
    document.getElementById("result").style.display = "inline";
}

function cl_calculateCOL()           
{
    var CL_infexp= parseFloat(document.getElementById('CL_infexp').value);
    var CL_ninfexp=parseFloat(document.getElementById('CL_ninfexp').value);
    var CL_col=parseFloat(document.getElementById('CL_col').value);
    var CL_incinf=parseFloat(document.getElementById('CL_incinf').value);
    var CL_decinf=parseFloat(document.getElementById('CL_decinf').value);
    var CL_nincinf=parseFloat(document.getElementById('CL_nincinf').value);
    var CL_ndecinf=parseFloat(document.getElementById('CL_ndecinf').value);
    var CL_inf=parseFloat(document.getElementById('CL_inf').value)/100;

    var CL_iexp=CL_infexp;
    CL_iexp=CL_iexp*Math.pow(1+	CL_inf,CL_col);
    var CL_future=CL_incinf-CL_decinf;
    CL_future=CL_future*Math.pow(1+	CL_inf,CL_col);
    CL_iexp+=CL_future;
    CL_nexp=CL_ninfexp+CL_nincinf-CL_ndecinf;
    
    if(CL_iexp<0)
    {
        alert('Check inflationary expenses');
        return;
    }
    if(CL_nexp<0)
    {
        alert('Check Non Inflationaey expenses');
        return;
    }

    document.borrow.CL_inf.value=Math.round(CL_iexp);
    document.borrow.CL_ninf.value=Math.round(CL_nexp);
    document.borrow.CL_exp.value=Math.round(CL_iexp+CL_nexp);
}
/* For Cost of Living */

/* Wealth at Retirement */
function CL_vlidateWR()
{
    age=document.getElementById('age');
    ret=document.getElementById('ret');
    CL_current=document.getElementById('CL_current');
    CL_mon=document.getElementById('CL_mon');
    CL_roi=document.getElementById('CL_roi');
    
    if(isNaN(parseFloat(age.value))||parseFloat(age.value)<=0)
    {
        alert('Your age should be greater than 0');
        age.focus();
        return false;
    }
    if(isNaN(parseFloat(ret.value))||parseFloat(ret.value)<=parseFloat(age.value))
    {
        alert('Your retirement age should be greater than your present age');
        ret.focus();
        return false;
    }
    if(isNaN(parseFloat(ret.value))||parseFloat(ret.value)<=parseFloat(age.value))
    {
        alert('Your retirement age should be greater than your present age');
        ret.focus();
        return false;
    }
    if(isNaN(parseFloat(CL_current.value))||parseFloat(CL_current.value)<0)
    {
        alert('Current savings should be greater than or equal to 0');
        CL_current.focus();
        return false;
    }
    if(isNaN(parseFloat(CL_mon.value))||parseFloat(CL_mon.value)<0)
    {
        alert('Monthly savings should be greater than or equal to 0');
        CL_mon.focus();
        return false;
    }
    if(isNaN(parseFloat(CL_roi.value))||parseFloat(CL_roi.value)<0)
    {
        alert('Return on your investments should be greater than or equal to 0');
        CL_roi.focus();
        return false;
    }
    if(parseFloat(CL_roi.value)>100)
    {
        alert('Invalid Return on Investments Percentage');
        CL_roi.focus();
        return false;
    }
    return true;
}

function cl_calculateWR()
{
    var CL_current;
    var CL_mon;
    var CL_roi;
    var CL_tenure;
    var CL_vl;
    var CL_val;
    var cl_tool = document.forms[0];
    var borrow = document.forms[0];
    CL_tenure=(parseFloat(document.getElementById('ret').value,10)-parseFloat(document.getElementById('age').value,10));
    A = CL_tenure * 12;
    CL_current=parseFloat(document.getElementById('CL_current').value,10);
    CL_mon=parseFloat(cl_tool.CL_mon.value,10);
    
    //CL_roi=Math.pow(parseFloat(document.getElementById('CL_roi').value,10)/100 +1,1/12)-1;
    //CL_vl=CL_current*Math.pow((1+CL_roi*12),CL_tenure);
    //CL_vl+=parseFloat(document.getElementById('CL_mon').value,10)*((Math.pow((1+CL_roi),CL_tenure*12)-1)/CL_roi);
    
    
    CL_roi = (parseFloat(document.getElementById('CL_roi').value,10)/12);
    if (CL_roi==0) CL_roi=0.00000001;
    B = CL_roi / 100;
    
    CL_vl = CL_current + CL_mon;

     for(var i=1; i<=A; i++)
     {
        CL_val = CL_vl * B;
        CL_vl = CL_vl + CL_val;
        if(i!=A) CL_vl = CL_vl + CL_mon;
     }


    if(isNaN(CL_vl))
    {
	    alert('One or more of the numeric fields are wrong. Please Check');
	}
	else
	{
	    if(document.layers)
        {
            document.layers['result'].document.borrow.CL_emi.value=Math.round(CL_vl);
		}
		else
		{
		    borrow.CL_emi.value=Math.round(CL_vl);
		}
	}
}
/* Wealth at Retirement */


/* Child's Planning, Child's Wedding */
function hide()
{
    document.getElementById("hid").style.display = 'none';
}

function validate()
{
    var year=document.getElementById('year');
    var edu_term=document.getElementById('edu_term');
    var edu_value=document.getElementById('edu_value');
    var edu_loan=document.getElementById('edu_loan');        
        
	if(year.value=="")
    {
        alert('Please select Education Commencement Year');
        year.focus();
        return false;
    }
    else if(edu_term.value=="")
    {
        alert('Please select Expected Period of Education');
        edu_term.focus();
        return false;
    }
    else if(trimall(edu_value.value)=="")
    {
        alert('Please enter the Cost of Education');
        edu_value.focus();
        return false;
    }
    else if(trimall(edu_loan.value)=="")
    {
        alert('Please enter the Education Loan Amount');
        edu_loan.focus();
        return false;
    }
    calculate();
    show();
}

function calculate()
{
	var income=document.getElementById('edu_loan').value
	var expen=document.getElementById('loan_pri').value

    if ((income == null || income == 0) ||(expen == null || expen == 0))
    { 
	    document.getElementById('emi').value = 0;
    }
    else
    {
        var princ = income;
        var term  = expen;
        var intr  = document.getElementById('int').value/ 1200;
        document.getElementById('emi').value = parseInt(princ * intr / (1 - (Math.pow(1/(1 + intr), term))))+1;	     
    }
}

function show()
{
    document.getElementById("hid").style.display = 'inline';
}
/* Child's Planning */

/* Child's Wedding */
function validateCW()
{
    var year=document.getElementById('year');
    var exp=document.getElementById('exp');
    var loan=document.getElementById('loan');
    
    if(year.value=="")
    {
        alert('Please select Expected Year of wedding');
        year.focus();
        return false;
    }
    else if(trimall(exp.value)=="")
    {
        alert('Please Enter Expected Cost of Wedding');
        exp.focus();
        return false;
    }
    else if(trimall(loan.value)=="")
    {
        alert('Please enter the Loan Amount');
        loan.focus();
        return false;
    }       
    calculateCW();
    show();
}

function calculateCW()
{
    hid.style.display = "inline";
    var income=document.getElementById('loan').value
    var expen=document.getElementById('loan_pri').value
    if ((income == null || income == 0) || (expen == null || expen == 0))
    { 
        document.getElementById('emi').value = 0;
    }
    else
    {
        var princ = income;
        var term  = expen;
        var intr   =  document.getElementById('int').value/ 1200;
	    document.getElementById('emi').value = parseInt(princ * intr / (1 - (Math.pow(1/(1 + intr), term))))+1;
    }
}
/* Child's Wedding */

/* Risk Analyzer */
function compute()
{
    if(document.getElementById('age1').checked){agepoints=40;}
	if(document.getElementById('age2').checked){agepoints=30;}
	if(document.getElementById('age3').checked){agepoints=20;}
	if(document.getElementById('age4').checked){agepoints=10;}
	if(document.getElementById('age5').checked){agepoints=0;}
    //alert("agepoints = " +agepoints)

	if(document.getElementById('takeHomeIncome1').checked){takeHomeIncomepoints=0;}
	if(document.getElementById('takeHomeIncome2').checked){takeHomeIncomepoints=10;}
	if(document.getElementById('takeHomeIncome3').checked){takeHomeIncomepoints=20;}
	if(document.getElementById('takeHomeIncome4').checked){takeHomeIncomepoints=30;}
	if(document.getElementById('takeHomeIncome5').checked){takeHomeIncomepoints=40;}
    //alert("takeHomeIncomepoints = " + takeHomeIncomepoints)

	if(document.getElementById('noYearstoRet1').checked){noYearstoRetpoints=0;}
	if(document.getElementById('noYearstoRet2').checked){noYearstoRetpoints=10;}
	if(document.getElementById('noYearstoRet3').checked){noYearstoRetpoints=20;}
	if(document.getElementById('noYearstoRet4').checked){noYearstoRetpoints=30;}
	if(document.getElementById('noYearstoRet5').checked){noYearstoRetpoints=40;}
    //alert("noYearstoRetpoints = " + noYearstoRetpoints)

	if(document.getElementById('presentJob1').checked){presentJobpoints=0;}
	if(document.getElementById('presentJob2').checked){presentJobpoints=20;}
	if(document.getElementById('presentJob3').checked){presentJobpoints=40;}
	if(document.getElementById('presentJob4').checked){presentJobpoints=40;}
	if(document.getElementById('presentJob5').checked){presentJobpoints=30;}
    //alert("presentJobpoints = " + presentJobpoints)

	if(document.getElementById('futureEarnings1').checked){futureEarningspoints=30;}
	if(document.getElementById('futureEarnings2').checked){futureEarningspoints=25;}
	if(document.getElementById('futureEarnings3').checked){futureEarningspoints=20;}
	if(document.getElementById('futureEarnings4').checked){futureEarningspoints=5;}
    //alert("futureEarnings = " + futureEarningspoints)

	if(document.getElementById('riskTaking1').checked){riskTakingpoints=40;}
	if(document.getElementById('riskTaking2').checked){riskTakingpoints=30;}
	if(document.getElementById('riskTaking3').checked){riskTakingpoints=20;}
	if(document.getElementById('riskTaking4').checked){riskTakingpoints=10;}
	if(document.getElementById('riskTaking5').checked){riskTakingpoints=0;}
    //alert("riskTaking = " + riskTakingpoints)

	if(document.getElementById('knowledgeFinance1').checked){knowledgeFinancepoints=30;}
	if(document.getElementById('knowledgeFinance2').checked){knowledgeFinancepoints=25;}
	if(document.getElementById('knowledgeFinance3').checked){knowledgeFinancepoints=20;}
	if(document.getElementById('knowledgeFinance4').checked){knowledgeFinancepoints=15;}
	if(document.getElementById('knowledgeFinance5').checked){knowledgeFinancepoints=5;}
    //alert("knowledgeFinance =" + knowledgeFinancepoints)

	if(document.getElementById('savings1').checked){savingspoints=0;}
	if(document.getElementById('savings2').checked){savingspoints=10;}
	if(document.getElementById('savings3').checked){savingspoints=20;}
	if(document.getElementById('savings4').checked){savingspoints=30;}
	if(document.getElementById('savings5').checked){savingspoints=40;}
    //alert("savings =" + savingspoints)

	if(document.getElementById('investin1').checked){investinpoints=0;}
	if(document.getElementById('investin2').checked){investinpoints=20;}
	if(document.getElementById('investin3').checked){investinpoints=40;}
	if(document.getElementById('investin4').checked){investinpoints=10;}
	if(document.getElementById('investin5').checked){investinpoints=30;}
    //alert("investinpoints" + investinpoints)

    if(document.getElementById('marketTip1').checked){marketTippoints=40;}
	if(document.getElementById('marketTip2').checked){marketTippoints=30;}
	if(document.getElementById('marketTip3').checked){marketTippoints=20;}
	if(document.getElementById('marketTip4').checked){marketTippoints=10;}
	if(document.getElementById('marketTip5').checked){marketTippoints=0;}
    //alert("marketTippoints" + marketTippoints)

	if(document.getElementById('tvShow1').checked){tvShowpoints=5;}
	if(document.getElementById('tvShow2').checked){tvShowpoints=20;}
	if(document.getElementById('tvShow3').checked){tvShowpoints=25;}
	if(document.getElementById('tvShow4').checked){tvShowpoints=30;}
    //alert("tvShowpoints" + tvShowpoints)

	if(document.getElementById('feelingInvestment1').checked){feelingInvestmentpoints=30;}
	if(document.getElementById('feelingInvestment2').checked){feelingInvestmentpoints=25;}
	if(document.getElementById('feelingInvestment3').checked){feelingInvestmentpoints=20;}
	if(document.getElementById('feelingInvestment4').checked){feelingInvestmentpoints=15;}
	if(document.getElementById('feelingInvestment5').checked){feelingInvestmentpoints=5;}
    //alert("feelingInvestmentpoints" + feelingInvestmentpoints)

	if(document.getElementById('shares1').checked){sharespoints=0;}
	if(document.getElementById('shares2').checked){sharespoints=10;}
	if(document.getElementById('shares3').checked){sharespoints=40;}
	if(document.getElementById('shares4').checked){sharespoints=30;}
	if(document.getElementById('shares5').checked){sharespoints=10;}
    //alert("sharespoints" + sharespoints)

	if(document.getElementById('expensiveCar1').checked){expensiveCarpoints=5}
    if(document.getElementById('expensiveCar2').checked){expensiveCarpoints=25}
    if(document.getElementById('expensiveCar3').checked){expensiveCarpoints=30}
    if(document.getElementById('expensiveCar4').checked){expensiveCarpoints=20}
    if(document.getElementById('expensiveCar5').checked){expensiveCarpoints=15}
    //alert("expensiveCarpoints" + expensiveCarpoints)

	if(document.getElementById('responsibility1').checked){responsibilitypoints=30;}
	if(document.getElementById('responsibility2').checked){responsibilitypoints=25;}
	if(document.getElementById('responsibility3').checked){responsibilitypoints=20;}
	if(document.getElementById('responsibility4').checked){responsibilitypoints=15;}
	if(document.getElementById('responsibility5').checked){responsibilitypoints=5;}
    //alert("responsibilitypoints" + responsibilitypoints)

	riskCapacityPoints = agepoints + takeHomeIncomepoints + noYearstoRetpoints + presentJobpoints +
	    futureEarningspoints + knowledgeFinancepoints + savingspoints +
		responsibilitypoints;

    riskBehaviourPoints = riskTakingpoints + investinpoints + marketTippoints + tvShowpoints +
	    feelingInvestmentpoints + sharespoints + expensiveCarpoints;

    riskBehaviourPoints *= 8/7;

    aggregateScore = riskBehaviourPoints + riskCapacityPoints;

	/* Computation for the RiskCapacity */
	if (riskCapacityPoints>=0 && riskCapacityPoints<=60)
    {
        riskCapacity = "Low" ;
		riskCapacityValue = 1;
    }
	else
	{
	    if (riskCapacityPoints>=61 && riskCapacityPoints<=130)
		{	riskCapacity = "Low-Medium";
				riskCapacityValue = 2;
		}
		else
		{
		    if(riskCapacityPoints>=131 && riskCapacityPoints<=190)
			{	riskCapacity = "Medium";
			    riskCapacityValue = 3;
            }
		    else
			{
			    if(riskCapacityPoints>=191 && riskCapacityPoints<=250)
				{	riskCapacity = "High";
				    riskCapacityValue = 4;
                }
				else
				{
				    if(riskCapacityPoints>=251 && riskCapacityPoints<=290)
					{	riskCapacity = "Very High";
					    riskCapacityValue = 5;
                    }
                }
            }
        }
    }

	document.getElementById('riskC').value = riskCapacityValue;

    /* Computation for Risk Behaviour */
	if (riskBehaviourPoints>=0 && riskBehaviourPoints<=50)
	{	riskBehaviour = "Conservative(low risk)" ;
	    riskBehaviourValue = 1;
    }
	else
	{
	    if (riskBehaviourPoints>=51 && riskBehaviourPoints<=120)
		{	riskBehaviour = "Moderate (low-medium risk)" ;
		    riskBehaviourValue = 2;
        }
		else
		{
		    if(riskBehaviourPoints>=121 && riskBehaviourPoints<=190)
			{	riskBehaviour = "Balanced (medium risk)" ;
			    riskBehaviourValue = 3;
            }
			else
			{
			    if(riskBehaviourPoints>=191 && riskBehaviourPoints<=255)
				{	riskBehaviour = "Aggressive (high risk)" ;
				    riskBehaviourValue = 4;
                }
				else
				{
				    if(riskBehaviourPoints>=256 && riskBehaviourPoints<=286)
					{	riskBehaviour = "Highly Aggressive (very high risk)";
					    riskBehaviourValue = 5;
                    }
                }
            }
        }
    }
	document.getElementById('riskB').value = riskBehaviourValue;
    
    /* Computation for overall Risk Profile */
	if(aggregateScore>=0 && aggregateScore<=110)
	{	 riskProfile = "Conservative (low risk)" ;
	    riskProfileValue = 1;
    }
	else
	{
	    if (aggregateScore>=111 && aggregateScore<=250)
		{	riskProfile = "Moderate (low-medium risk)" ;
		    riskProfileValue = 2;
        }
		else
		{
		    if (aggregateScore>=251 && aggregateScore<=380)
		    {
		        riskProfile = "Balanced (medium risk)";
				riskProfileValue = 3;
            }
			else
			{
			    if (aggregateScore>=381 && aggregateScore<=505)
				{	riskProfile = "Aggressive (high risk)";
				    riskProfileValue = 4;
                }
				else
				{
				    if (aggregateScore>=506 && aggregateScore<=576)
					{	riskProfile = "Highly Aggressive (very high risk)";
					    riskProfileValue = 5;
                    }
                }
            }
        }
    }
	document.getElementById('riskP').value = riskProfileValue;
	window.open('RiskDisplay.aspx?riskB='+riskBehaviourValue+'&riskC='+riskCapacityValue+'&riskP='+riskProfileValue,"","scrollbars=yes,height=400,width=500,status=no,toolbar=no,menubar=no,location=no,left=10,top=30");
}
/* Risk Analyzer */


/* Asset Allocator */
function Val(x)
{
//    alert(document.forms[0].plan1.value);
    if(isNaN(document.forms[0].plan1.value))
	{
	    alert("Please Enter a Numeric Value");
		document.forms[0].plan1.value="";
		document.forms[0].plan1.focus();
	}
	else if(isNaN(document.forms[0].plan2.value))
	{
	    alert("Please Enter a Numeric Value");
		document.forms[0].plan2.value="";
		document.forms[0].plan2.focus();
	}
	else if(isNaN(document.forms[0].plan3.value))
	{
	    alert("Please Enter a Numeric Value");
		document.forms[0].plan3.value="";
		document.forms[0].plan3.focus();
	}
    else
	{
	    var val='00';
		//var sumFlag="FALSE";
//		for(i=0;i<=2;i++)
//		{  
//		    if(!isBlank(document.form1.elements[i].value))
//			{
//			    val = parseInt(val,10)+ parseInt(document.form1.elements[i].value,10);
//				sumFlag="TRUE";
//            }
//        }
         //val = parseInt(document.forms[0].plan1.value,10) + parseInt(document.forms[0].plan2.value,10) +parseInt(document.forms[0].plan3.value,10);
         if(document.forms[0].plan1.value != "")
           {
             val = parseInt(val,10)+ parseInt(document.forms[0].plan1.value,10);
           } 
          if(document.forms[0].plan2.value != "") 
          {
            val = parseInt(val,10)+ parseInt(document.forms[0].plan2.value,10);
          }
          if(document.forms[0].plan3.value != "") 
          {
            val = parseInt(val,10)+ parseInt(document.forms[0].plan2.value,10);
          } 
		 //sumFlag="TRUE";
		 if(parseInt(val,10)!='00')
		{
		    document.forms[0].total.value=val; 
        }
		else
		{
		    if(sumFlag !="TRUE")
			{
			    document.forms[0].total.value="";
            }
			else
			{
			    document.forms[0].total.value=val;
            }
        }
        // window.location = "AssetResult.aspx?plan1="+val+"&risk="+1;
    }
}
function CheckAssetalocator()
{
  if((document.forms[0].plan1.value == null || document.forms[0].plan1.value=="") && (document.forms[0].plan2.value == null || document.forms[0].plan2.value=="") && (document.forms[0].plan3.value == null || document.forms[0].plan3.value==""))
    {
            alert("Please enter amount in one of the periods" );
		    document.forms[0].plan1.focus();
		    return(false);
    }
    var val='00';
    var plan1 = "";
    var plan2 = "";
    var plan3 = "";
    var risk = "";
    if(document.forms[0].plan1.value != "")
       {
         val = parseInt(val,10)+ parseInt(document.forms[0].plan1.value,10);
         plan1 = parseInt(document.forms[0].plan1.value,10);
       } 
      if(document.forms[0].plan2.value != "") 
      {
        val = parseInt(val,10)+ parseInt(document.forms[0].plan2.value,10);
        plan2 = parseInt(document.forms[0].plan2.value,10);
      }
      if(document.forms[0].plan3.value != "") 
      {
        val = parseInt(val,10)+ parseInt(document.forms[0].plan2.value,10);
        plan3 = parseInt(document.forms[0].plan3.value,10);
      } 
	 //sumFlag="TRUE";
	 if(parseInt(val,10)!='00')
	 {
	    document.forms[0].total.value=val; 
     }
     if(document.getElementById('risk5').checked)
     {
      risk = document.getElementById('risk5').value;
     }
     else if(document.getElementById('risk4').checked)
     {
      risk = document.getElementById('risk4').value;
     }
     else if(document.getElementById('risk3').checked)
     {
      risk = document.getElementById('risk3').value;
     }
     else if(document.getElementById('risk2').checked)
     {
      risk = document.getElementById('risk2').value;
     }
     else if(document.getElementById('risk1').checked)
     {
      risk = document.getElementById('risk1').value;
     }
     window.location = "AssetResult.aspx?plan1="+plan1+"&plan2="+plan2+"&plan3="+plan3+"&total="+val+"&risk="+risk;
}
function isBlank(s)
{
	var len=s.length
	var i;
	for(i=0;i<len;i++)
	{
	    if(s.charAt(i) !=" ") return false;
	}
    return true;
}
		
/*function Check()
{
    var elem= new Array();
	var cnt=0;
	for(i=0;i<=2;i++)
	{
        if(document.form1.elements[i].value ==null || document.form1.elements[i].value=="")
		{
		    elem[cnt]=i;
			cnt++;
        }
    }
    if(elem.length == 3)
	{
	    alert("Please enter amount in one of the periods" );
		return(false);
    }
	else
	{
	    return true;
    }
}*/
/* Asset Allocator */


/* Saving a Million */
function cl_validateMillion()
{
    var frm = document.forms[0];
    if(isNaN(parseFloat(frm.CL_current.value))||parseFloat(frm.CL_current.value)<0)
	{
		alert('Your savings should be greater than or equal to 0.');
		frm.CL_current.focus();
		return false;
	}
	if(isNaN(parseFloat(frm.CL_tenure.value))||parseFloat(frm.CL_tenure.value)<=0)
	{
		alert('The period should be greater than 0.');
		frm.CL_tenure.focus();
		return false;
	}
	if(isNaN(parseFloat(frm.CL_roi.value))||parseFloat(frm.CL_roi.value)<=0)
	{
		alert('Rate of interest should be greater than 0.');
		frm.CL_roi.focus();
		return false;
	}
	if(parseFloat(frm.CL_roi.value)>100)
	{
		alert(' Please enter valid Rate of interest');
		frm.CL_roi.focus();
		return false;
	}
	return true;
}

function cl_calculateMillion()
{
    var CL_current;
    var CL_roi;
    var CL_tenure;
    var CL_remain;
    var cl_tool = document.forms[0];
    var borrow = document.forms[0];
    CL_tenure=parseFloat(cl_tool.CL_tenure.value,10);
    CL_current=parseFloat(cl_tool.CL_current.value,10);
    CL_roi=Math.pow(1+parseFloat(cl_tool.CL_roi.value,10)/100,1/12)-1;
    
    if(CL_current>=1000000)
    {
        alert('Congratulations you are already a millionaire');
        CL_hid('result');
        CL_hid('explain');
        return
    }
    
    CL_remain=1000000-CL_current*Math.pow((1+CL_roi),CL_tenure*12);
    
    if(isNaN(Math.round((CL_remain*CL_roi)/(Math.pow((1+CL_roi),CL_tenure*12)-1))))
	{
		alert('One or more of the numeric fields is wrong. Please Check');
	}
	else
	{
		if(document.layers)
		{
		document.layers['result'].borrow.CL_emi.value=Math.round((CL_remain*CL_roi)/(Math.pow((1+CL_roi),CL_tenure*12)-1));
		}
		else
		{
		borrow.CL_emi.value=Math.round((CL_remain*CL_roi)/(Math.pow((1+CL_roi),CL_tenure*12)-1));
		}
	}
}
/* Saving a Million */


/* Making a Million */
function cl_validateMakeM()
{
    var frm = document.forms[0];
    var cl_tool = document.forms[0];
    if(isNaN(parseFloat(cl_tool.CL_current.value))||parseFloat(cl_tool.CL_current.value)<0)
	{
		alert('Savings should be greater tah or equal to 0.');
		cl_tool.CL_current.focus();
		return false;
	}
	if(isNaN(parseFloat(cl_tool.CL_sav.value))||parseFloat(cl_tool.CL_sav.value)<=0)
	{
		alert('Your savings should be greater than 0');
		cl_tool.CL_sav.focus();
		return false;
	}
	if(isNaN(parseFloat(cl_tool.CL_roi.value))||parseFloat(cl_tool.CL_roi.value)<=0)
	{
		alert('Return on you savings should be greater than 0');
		cl_tool.CL_roi.focus();
		return false;
	}
	if(parseFloat(cl_tool.CL_roi.value)>100)
	{
		alert(' Please enter valid Rate of interest');
		cl_tool.CL_roi.focus();
		return false;
	}
	return true;
}

function cl_calculateMakeM()
{
    var CL_current;
    var CL_amt;
    var CL_roi;
    var CL_sav;
    var CL_tim;
    var borrow = document.forms[0];
    CL_sav=parseFloat(document.getElementById("CL_sav").value,10);
    CL_current=parseFloat(document.getElementById("CL_current").value,10);
    CL_roi=parseFloat(document.getElementById("CL_roi").value,10)/100;
    CL_roi=Math.pow(1+CL_roi,1/12)-1;
    CL_roi=CL_roi+1;
    CL_tim=0;
    
    if(CL_roi<0 ||CL_sav<0)
    {
        alert('You can not give negetive figures in your Monthly Savings Interest on your savings');
        return false;
    }
    if(CL_current>=1000000)
    {
        alert('Congratulations you are already a millionaire');
        CL_hid('result');CL_hid('explain');
        return
    }
    CL_amt=CL_sav*(Math.pow(CL_roi,CL_tim)-1)/(CL_roi-1);
    
    do
    {
        CL_tim+=1;
        CL_amt=CL_sav*(Math.pow(CL_roi,CL_tim)-1)/(CL_roi-1)+CL_current*(Math.pow(CL_roi,CL_tim));
    }
    while(CL_amt<1000000)

    if(CL_tim/12<1)
	{
		CL_tim= CL_tim + ' months';
	}
	else
	{
		CL_tim=Math.round(CL_tim/12) + ' years';
	}

	if(document.layers)
	{
		document.layers['result'].borrow.emi.value=CL_tim;
	}
	else
	{
		borrow.emi.value=CL_tim;
	}
}
/* Making a Million */


/* Compounding Magic */
function CL_vlidateCMagic()
{
    frmCMagic = document.forms[0];
    if(isNaN(parseFloat(frmCMagic.CL_time.value))||parseFloat(frmCMagic.CL_time.value)<=0)
    {
        alert('Investment horizon should be greater than 0');
        frmCMagic.age.focus();
        return false;
    }
    if(isNaN(parseFloat(frmCMagic.CL_current.value))||parseFloat(frmCMagic.CL_current.value)<0)
    {
        alert('Current savings should be greater than or equal to 0');
        frmCMagic.CL_current.focus();
        return false;
    }
    if(isNaN(parseFloat(frmCMagic.CL_mon.value))||parseFloat(frmCMagic.CL_mon.value)<0)
    {
        alert('Monthly savings should be greater than or equal to 0');
        frmCMagic.CL_mon.focus();
        return false;
    }
    if(isNaN(parseFloat(frmCMagic.CL_roi.value))||parseFloat(frmCMagic.CL_roi.value)<0)
    {
        alert('Return on your investments should be greater than or equal to 0');
        frmCMagic.CL_roi.focus();
        return false;
    }
    if(parseFloat(frmCMagic.CL_roi.value)>100)
	{
	    alert('Please enter valid return on investment');
		frmCMagic.CL_roi.focus();
		return false;
	}
    return true;
}

function cl_calculateCMagic()
{
    var CL_current;
    var CL_mon;
    var CL_roi;
    var CL_tenure;
    var CL_vl;
    var cl_tool = document.forms[0];
    var borrow = document.forms[0];
    CL_mon=parseFloat(cl_tool.CL_mon.value,10);
    CL_tenure=parseFloat(cl_tool.CL_time.value,10);
    CL_current=parseFloat(cl_tool.CL_current.value,10);
    CL_roi=1+parseFloat(cl_tool.CL_roi.value,10)/100;
    
    if (CL_roi==0) CL_roi=0.00000001;
    //CL_vl=CL_current*Math.pow((1+CL_roi),CL_tenure);
    //CL_vl+=parseFloat(document.cl_tool.CL_mon.value,10)*((Math.pow((1+CL_roi),CL_tenure)-1)/CL_roi);
    
    CL_vl = CL_current + CL_mon;

    for(var i=1; i<=CL_tenure; i++)
    {
        CL_vl = CL_vl * CL_roi;
        if(i!=CL_tenure) CL_vl = CL_vl + CL_mon;
    }

    if(isNaN(CL_vl))
	{
		alert('One or more of the numeric fields are wrong. Please Check');
	}
	else
	{
		if(document.layers)
		{
    		document.layers['result'].borrow.CL_emi.value=Math.round(CL_vl);
		}
		else
		{
            borrow.CL_emi.value=Math.round(CL_vl);
		}
	}
}

function cl_check(fld,typ)
{
    if(typ=="int")
    {
	    if(isNaN(fld.value))
	    {
	        alert('Please enter a Number in the given field');
	        fld.focus();
	    }
    }
}
/* Compounding Magic */


/* Saving - Saving Enough */
function cl_validateSaving(frm)
{
    var CL_age=document.getElementById("CL_age"); 
    var CL_ret=document.getElementById("CL_ret"); 
    var CL_current=document.getElementById("CL_current"); 
    var CL_retamt=document.getElementById("CL_retamt"); 
    var CL_msav=document.getElementById("CL_msav"); 
    var CL_roi=document.getElementById("CL_roi"); 
    var CL_inf=document.getElementById("CL_inf"); 
    
	if(isNaN(parseFloat(CL_age.value))||parseFloat(CL_age.value)<=0)
	{
	    alert('Your age should be greater than 0 years');
	    CL_age.focus();
	    return false;
	}
	if(isNaN(parseFloat(CL_ret.value))||parseFloat(CL_ret.value)<=parseFloat(CL_age.value))
	{
	    alert('Retirement age should be greater than your current age');
	    CL_ret.focus();
	    return false;
	}
	if(isNaN(parseFloat(CL_current.value))||parseFloat(parseFloat(CL_current.value))<0)
	{
		alert('Your current savings should be greater than 0');
		current.focus();
		return false;
	}
	if(isNaN(parseFloat(CL_retamt.value))||parseFloat(parseFloat(CL_retamt.value))<0)
	{
		alert('Your retirement amount should be greater than or equal to 0');
		CL_retamt.focus();
		return false;
	}
	if(isNaN(parseFloat(CL_msav.value))||parseFloat(parseFloat(CL_msav.value))<0)
	{
		alert('Monthly savings should be greater than or equal to 0');
		CL_msav.focus();
		return false;
	}
	if(isNaN(parseFloat(CL_roi.value))||parseFloat(parseFloat(CL_roi.value))<0)
	{
		alert('Rate of return on your investment should be greater than 0');
		CL_roi.focus();
		return false;
	}
	if(isNaN(parseFloat(CL_inf.value))||parseFloat(parseFloat(CL_inf.value))<0)
	{
		alert('Rate of inflation should be greater than 0');
		CL_inf.focus();
		return false;
	}
	return true;
}
/* Saving - Saving Enough */


/* Making a Crore */
function cl_validateCrore()
{
    var frm = document.forms[0];
    var cl_tool = document.forms[0];
    var CL_age,CL_cursav,CL_inc,CL_inf,CL_leave,CL_live,CL_savinc;
	var CL_incgrow25,CL_incgrow35,CL_incgrow50;
	var CL_roi25,CL_roi35,CL_roi50;
	var CL_savinc25,CL_savinc35,CL_savinc50;
	
	CL_age=parseInt(cl_tool.CL_age.value);
	CL_cursav=parseInt(cl_tool.CL_cursav.value);
	CL_inc=parseInt(cl_tool.CL_inc.value);

	CL_incgrow25=parseInt(cl_tool.CL_incgrow25.value);
	CL_incgrow35=parseInt(cl_tool.CL_incgrow35.value);
	CL_incgrow50=parseInt(cl_tool.CL_incgrow50.value);

	CL_roi25=parseInt(cl_tool.CL_roi25.value);
	CL_roi35=parseInt(cl_tool.CL_roi35.value);
	CL_roi50=parseInt(cl_tool.CL_roi50.value);

	CL_savinc25=parseInt(cl_tool.CL_savinc25.value);
	CL_savinc35=parseInt(cl_tool.CL_savinc35.value);
	CL_savinc50=parseInt(cl_tool.CL_savinc50.value);

    if(CL_incgrow25==0 && CL_incgrow35==0 && CL_incgrow50==0 && CL_roi25==0 && CL_roi35==0 && CL_roi50==0 && CL_savinc25==0 && CL_savinc35==0 && CL_savinc50==0)
    {
        alert('All fields cannot be zero');
        document.getElementById("CL_incgrow25").focus();
        return false;
    }
    if(isNaN(CL_incgrow25) || isNaN(CL_incgrow35) || isNaN(CL_incgrow50) || isNaN(CL_roi25) || isNaN(CL_roi35) || isNaN(CL_roi50) || isNaN(CL_savinc25) || isNaN(CL_savinc35) || isNaN(CL_savinc50))
    {
        alert('Please Enter Valid Data');
        return false;
    }
    
	/*if(isNaN(CL_age) || isNaN(CL_inc) || isNaN(CL_roi25)||isNaN(CL_roi35)||isNaN(CL_roi50))
	{
	    alert('Please fill all the fields');
	    return false;
	}
	if(parseFloat(CL_roi25)>100)
	{
	    alert('Invalid Rate of Returns');
		CL_roi25.focus();
		return false;
	}

	for(i=0;i<document.cl_tool.length-2;i++)
	{
		if(isNaN(parseInt(document.cl_tool.elements[i].value))&& !document.cl_tool.elements[i].value)
		{
			document.cl_tool.elements[i].value=0;
		}
	}

	if(100 < CL_savinc25 ||100 < CL_savinc35||100 < CL_savinc50)
	{
		alert('You cannot save more than you earn.');
		if(100 < CL_savinc25) document.cl_tool.CL_savinc25.focus();
		if(100 < CL_savinc35) document.cl_tool.CL_savinc35.focus();
		if(100 < CL_savinc50) document.cl_tool.CL_savinc50.focus();
		return false;
	}*/
	return true;
}

function cl_calculateCrore()
{
    var cl_tool = document.forms[0];
    var cl_borrow = document.forms[0];
    CL_age=parseFloat(cl_tool.CL_age.value);
    CL_cursav1=parseFloat(cl_tool.CL_cursav.value);
    CL_inc=parseFloat(cl_tool.CL_inc.value);
    CL_incgrow25=parseFloat(cl_tool.CL_incgrow25.value);
    CL_incgrow35=parseFloat(cl_tool.CL_incgrow35.value);
    CL_incgrow50=parseFloat(cl_tool.CL_incgrow50.value);
    CL_roi25=parseFloat(cl_tool.CL_roi25.value);
    CL_roi35=parseFloat(cl_tool.CL_roi35.value);
    CL_roi50=parseFloat(cl_tool.CL_roi50.value);
    CL_savinc25=parseFloat(cl_tool.CL_savinc25.value);
    CL_savinc35=parseFloat(cl_tool.CL_savinc35.value);
    CL_savinc50=parseFloat(cl_tool.CL_savinc50.value);

    CL_diff=1;
    CL_ret=CL_age+1;
    CL_crore=0;
//    if(CL_roi25!="" && CL_roi35!="" && CL_roi50!="")
//    {
        CL_r25=1+(CL_roi25/100)
        CL_r35=1+(CL_roi35/100)
        CL_r50=1+(CL_roi50/100)
        CL_igrow25=1+(CL_incgrow25/100)
        CL_igrow35=1+(CL_incgrow35/100)
        CL_igrow50=1+(CL_incgrow50/100)
        //CL_inflate=1+(CL_inf/100)

        CL_savinc25=CL_savinc25/100/12;
        CL_savinc35=CL_savinc35/100/12
        CL_savinc50=CL_savinc50/100/12

        CL_monrate25=Math.pow(CL_r25,1/12);
        CL_monrate35=Math.pow(CL_r35,1/12)
        CL_monrate50=Math.pow(CL_r50,1/12)

        if(CL_monrate25!=1)  CL_savinc25=CL_savinc25*((Math.pow(CL_monrate25,12)-1)/(CL_monrate25-1));
        if(CL_monrate35!=1)  CL_savinc35=CL_savinc35*((Math.pow(CL_monrate35,12)-1)/(CL_monrate35-1));
        if(CL_monrate50!=1)  CL_savinc50=CL_savinc50*((Math.pow(CL_monrate50,12)-1)/(CL_monrate50-1));

        CL_cursav=CL_cursav1;

        do
        {
            CL_Ncursav=CL_cursav1;
            CL_k= CL_igrow25/CL_r25;

            CL_income=CL_inc;
            if(CL_age<35)
            {
                CL_Ninc=CL_income*(Math.pow(CL_r25,Math.min(CL_diff-1,35-CL_age-1)));
                CL_Ncursav=CL_Ncursav*(Math.pow(CL_r25,Math.min(CL_diff,35-CL_age)));
            
                if(CL_k!=1)
                {
                    CL_Ninc=CL_Ninc*((Math.pow(CL_k,Math.min(CL_diff,35-CL_age))-1)/(CL_k-1));
                }
                else
                {
                    CL_Ninc=CL_Ninc*Math.min(CL_diff,35-CL_age)
                }

                CL_Ninc=CL_Ninc*CL_savinc25
                CL_Ncursav=CL_Ninc + CL_Ncursav
                CL_income=CL_income*(Math.pow(CL_igrow25,Math.min(CL_diff-1,35-CL_age-1)))
                CL_income=CL_income*CL_igrow35
            }

            CL_k= CL_igrow35/CL_r35
            if(CL_age<50)
            {
                if(CL_ret>35)
                {
                	CL_Ncursav=CL_Ncursav*Math.pow(CL_r35,Math.min(CL_ret-Math.max(CL_age,35),50-Math.max(CL_age,35)));
	                CL_Ninc=CL_income*Math.pow(CL_r35,Math.min(CL_ret-Math.max(CL_age,35)-1,50-Math.max(CL_age,35)-1));

                    if(CL_k!=1)
	                {
	                    CL_Ninc=CL_Ninc*((Math.pow(CL_k,Math.min(CL_ret-Math.max(CL_age,35),50-Math.max(CL_age,35)))-1)/(CL_k-1));
	                }
	                else
	                {
	                    CL_Ninc=CL_Ninc*Math.min(CL_ret-Math.max(CL_age,35),50-Math.max(CL_age,35));
	                }

                    CL_Ninc=CL_Ninc*CL_savinc35 ;

	                CL_Ncursav=CL_Ninc + CL_Ncursav;
	                CL_income=CL_income*Math.pow(CL_igrow35,Math.min(CL_ret-Math.max(CL_age,35)-1,50-Math.max(CL_age,35))-1);
	                CL_income=CL_income*CL_igrow50;
                }
            }

            CL_k= CL_igrow50/CL_r50

            CL_Ninc=CL_income*Math.pow(CL_r50,Math.max(0,CL_ret-Math.max(CL_age,50)-1));
            CL_Ncursav=CL_Ncursav*(Math.pow(CL_r50,Math.max(0,CL_ret-Math.max(CL_age,50))));

            if(CL_k!=1)
            {
                CL_Ninc=CL_Ninc*(Math.pow(CL_k,Math.max(0,CL_ret-Math.max(CL_age,50)))-1)/(CL_k-1);
            }
            else
            {
                CL_Ninc=CL_Ninc*Math.max(0,CL_ret-Math.max(CL_age,50))
            }
            CL_Ninc=CL_Ninc*CL_savinc50;
            CL_Ncursav=CL_Ninc + CL_Ncursav ;


            CL_ret=CL_ret+1
            CL_diff=CL_diff+1
            CL_crore=CL_Ncursav
        } while (CL_crore<10000000)
//    }

    if(document.layers)
    {
        document.layers['result'].cl_borrow.cl_emi.value=CL_diff-1;
    }
    else
    {
        cl_borrow.cl_emi.value=CL_diff-1;
    }
}
/* Making a Crore */


/* Amount Saved */
function CL_hidAmtSaved(viewShow)
{
    if (document.layers)
    {
        content = document.layers[viewShow];
    }
    else if (document.all)
    {
        content = document.all(viewShow).style;
    }
    if(viewShow=="explain")
    {
        document.getElementById("explain").style.display='none';
    }
    document.getElementById("result").style.display = "none";
}

function cl_validateAmtSaved()
{
    
    CL_current = document.getElementById("CL_current");
    CL_cst =  document.getElementById("CL_cst");
    CL_tenure = document.getElementById("CL_tenure");
    CL_roi  = document.getElementById("CL_roi");
    CL_sav  = document.getElementById("CL_sav");
    CL_inf = document.getElementById("CL_inf");
    if(isNaN(parseFloat(CL_current.value))||parseFloat(CL_current.value)<0)
	{
		alert('Savings should be greater than or equal to 0.');
		CL_current.focus();
		return false;
	}
	if(isNaN(parseFloat(CL_cst.value))||parseFloat(CL_cst.value)<=0)
	{
		alert('Cost should be greater than or equal to 0');
		CL_cst.focus();
		return false;
	}
	if(isNaN(parseFloat(CL_tenure.value))||parseFloat(CL_tenure.value)<=0)
	{
		alert('Period should be greater than 0.');
		CL_tenure.focus();
		return false;
	}
	if(isNaN(parseFloat(CL_roi.value))||parseFloat(CL_roi.value)<=0)
	{
		alert('Return on investment should be greater than 0.');
		CL_roi.focus();
		return false;
	}
	if(isNaN(parseFloat(CL_sav.value))||parseFloat(CL_sav.value)<0)
	{
		alert('Your monthly savings should be greater than or equal to 0.');
		CL_sav.focus();
		return false;
	}
	if(isNaN(parseFloat(CL_inf.value))||parseFloat(CL_inf.value)<0)
	{
		alert('Inflation should be greater than or equal to 0');
		CL_inf.focus();
		return false;
	}
	return true;
}

function CL_displayAmtSaved(viewShow)
{
    if (document.layers)
    {
        content = document.layers[viewShow];
    }
    else if (document.all)
    {
        content = document.all(viewShow).style;
    }
    if(viewShow=="explain")
    {
        document.getElementById("explain").style.display='inline';
    }
    document.getElementById("result").style.display = "inline";
}

function cl_calculateAmtSaved()
{
    var CL_current =document.getElementById("CL_current");
    var CL_roi = document.getElementById("CL_roi");
    var CL_tenure;
    var CL_remain;
    var CL_fv;
    var CL_cst = document.getElementById("CL_cst");
    var CL_inf = document.getElementById("CL_inf");
    var CL_tp;
    var CL_sav = document.getElementById("CL_sav");
    var cl_tool = document.forms[0];
    var borrow = document.forms[0];
    CL_tenure=parseFloat(cl_tool.CL_tenure.value,10);
    CL_current=parseFloat(CL_current.value,10);
    CL_roi=parseFloat(CL_roi.value,10)/1200;
    CL_cst=parseFloat(CL_cst.value);
    CL_inf=parseFloat(CL_inf.value)/100;
    CL_fv=CL_cst*Math.pow(1+CL_inf,CL_tenure)
    CL_remain=CL_fv-CL_current*Math.pow((1+CL_roi*12),CL_tenure);
    CL_sav=parseFloat(CL_sav.value)
    CL_tp=CL_sav*(Math.pow(1+CL_roi,CL_tenure*12)-1)/CL_roi;
    if(isNaN(Math.round((CL_remain*CL_roi)/(Math.pow((1+CL_roi),CL_tenure*12)-1))))
	{
		alert('One or more of the numeric fields is wrong. Please Check');
	}
	else
	{
		if(document.layers)
		{
		    document.layers['result'].borrow.CL_emi.value=Math.max(Math.round((CL_remain*CL_roi)/(Math.pow((1+CL_roi),CL_tenure*12)-1)),0);
		    document.layers['result'].borrow.CL_fv.value=Math.round(CL_fv);
		    document.layers['result'].borrow.CL_current.value=Math.round(CL_tp+CL_current*Math.pow((1+CL_roi*12),CL_tenure));
		    
		    if(CL_tp+CL_current*Math.pow((1+CL_roi*12),CL_tenure)<CL_fv)
		    {
		        document.layers['result'].borrow.extra.value=Math.round(CL_fv-CL_tp-CL_current*Math.pow((1+CL_roi*12),CL_tenure));
		    }
		    else
		    {
		        document.layers['result'].borrow.extra.value=0
		    }
		}
		else
		{   
		    borrow.CL_emi.value=Math.max(Math.round((CL_remain*CL_roi)/(Math.pow((1+CL_roi),CL_tenure*12)-1)),0);
		    borrow.CL_fv.value=Math.round(CL_fv);
		   // borrow.CL_current.value=Math.round(CL_tp+CL_current*Math.pow((1+CL_roi*12),CL_tenure));
		    borrow.test.value = Math.round(CL_tp+CL_current*Math.pow((1+CL_roi*12),CL_tenure));
		    if(CL_tp+CL_current*Math.pow((1+CL_roi*12),CL_tenure)<CL_fv)
		    {
		        borrow.extra.value=Math.round(CL_fv-CL_tp-CL_current*Math.pow((1+CL_roi*12),CL_tenure));
		    }
		    else
		    {
		        borrow.extra.value=0;
		    }
		}
	}
}
/* Amount Saved */


/* Spend Less & Save */
function cl_checkSpendLess(fld,typ)
{
    if(typ=="int")
    {
	    if(isNaN(fld.value))
	    {
	        alert('Please enter a Number in the given field');
	        fld.focus();
	        return false;
	    }
        return true;
    }
}

function cl_validateSpendLess(frm)
{
    return true;
}

function cl_calculateSpendLess()
{
    var CL_roi;                            
    var CL_sav;
    var CL_t=0;
    var cl_tool = document.forms[0];
    var borrow = document.forms[0];
    if(cl_tool.t1.value && !isNaN(parseFloat(cl_tool.t1.value)))
    {
        CL_t+=parseFloat(cl_tool.t1.value);
    }
    if(cl_tool.t2.value && !isNaN(parseFloat(cl_tool.t2.value)))
    {
        CL_t+=parseFloat(cl_tool.t2.value);
    }
    if(cl_tool.t3.value && !isNaN(parseFloat(cl_tool.t3.value)))
    {
        CL_t+=parseFloat(cl_tool.t3.value);
    }
    if(cl_tool.t4.value && !isNaN(parseFloat(cl_tool.t4.value)))
    {
        CL_t+=parseFloat(cl_tool.t4.value);
    }
    if(cl_tool.t5.value && !isNaN(parseFloat(cl_tool.t5.value)))
    {
        CL_t+=parseFloat(cl_tool.t5.value);
    }
    if(cl_tool.t6.value && !isNaN(parseFloat(cl_tool.t6.value)))
    {
        CL_t+=parseFloat(cl_tool.t6.value);
    }
    if(cl_tool.t7.value && !isNaN(parseFloat(cl_tool.t7.value)))
    {
        CL_t+=parseFloat(cl_tool.t7.value);
    }
    
    if(!cl_tool.CL_roi.value || !(cl_tool.CL_roi.value))
    {
        alert('Enter your annual return');
        cl_tool.CL_roi.focus();
        return false;
    }
    if(parseFloat(cl_tool.CL_roi.value)>100)
    {
        alert(' Please Enter valid annual return');
        cl_tool.CL_roi.focus();
        return false;
    }
    if(!cl_tool.retage.value || !(cl_tool.retage.value))
    {
        alert('Enter your retirement age');
        cl_tool.retage.focus();
        return false;
    }
    if(!cl_tool.age.value || !(cl_tool.age.value))
    {
        alert('Enter your age');
        cl_tool.age.focus();
        return false;
    }
    if(cl_tool.age.value>cl_tool.retage.value)
    {
        alert('It appears you have already retired');
        return false;
    }
    var diff= parseFloat(cl_tool.retage.value)- parseFloat(cl_tool.age.value);
    
    CL_roi=Math.pow(1+parseFloat(cl_tool.CL_roi.value,10)/100,1/12)-1;
    CL_roi=CL_roi+1;
    CL_t=Math.round(CL_t*(Math.pow(CL_roi,diff*12)-1)/(CL_roi-1));
    
    if(document.layers)
    {
		document.layers['result'].borrow.emi.value=Math.round(CL_t);
	}
	else
	{
		borrow.emi.value=Math.round(CL_t);
	}
}
/* Spend Less & Save */


/* Savings Worth */
function CL_vlidateWorth()
{
     var frm = document.forms[0];
     var cl_tool = document.forms[0];
    if(isNaN(parseFloat(frm.CL_time.value))||parseFloat(frm.CL_time.value)<=0)
    {
        alert('Investment horizon should be greater than 0');
        frm.CL_time.focus();
        return false;
    }
    if(isNaN(parseFloat(frm.CL_current.value))||parseFloat(frm.CL_current.value)<0)
    {
        alert('Current savings should be greater than or equal to 0');
        frm.CL_current.focus();
        return false;
    }
    if(isNaN(parseFloat(frm.CL_tax.value))||parseFloat(frm.CL_tax.value)<0)
    {
        alert('Monthly savings should be greater than or equal to 0');
        frm.CL_tax.focus();
        return false;
    }
    if(parseFloat(cl_tool.CL_tax.value)>100)
    {
        alert(' Please Enter valid Tax rate');
        cl_tool.v.focus();
        return false;
    }
    if(isNaN(parseFloat(frm.CL_roi.value))||parseFloat(frm.CL_roi.value)<0)
    {
        alert('Return on your investments should be greater than or equal to 0');
        frm.CL_roi.focus();
        return false;
    }
    if(parseFloat(cl_tool.CL_roi.value)>100)
    {
        alert(' Please Enter valid return On Investments');
        cl_tool.CL_roi.focus();
        return false;
    }
    return true;
}

function cl_calculateWorth()
{
    var CL_current;
    var CL_roi;
    var CL_tenure;
    var CL_vl;
    var cl_tool = document.forms[0];
    var borrow = document.forms[0];
    CL_tenure=parseFloat(cl_tool.CL_time.value,10);
    CL_current=parseFloat(cl_tool.CL_current.value,10);
    CL_roi=parseFloat(cl_tool.CL_roi.value,10)/100;
    CL_tax=parseFloat(cl_tool.CL_tax.value,10)/100;
    CL_roi=CL_roi*(1-CL_tax);
    CL_mon=parseFloat(cl_tool.CL_mon.value,10);
    
    if (CL_roi==0) CL_roi=0.00000001;
    CL_vl=CL_current*(Math.pow((1+CL_roi),CL_tenure));
    CL_vl+=parseFloat(cl_tool.CL_mon.value,10)*((Math.pow((1+CL_roi),CL_tenure)-1)/CL_roi);
    
    if(isNaN(CL_vl))
	{
		alert('One or more of the numeric fields are wrong. Please Check');
	}
	else
	{
		if(document.layers)
		{
            document.layers['result'].borrow.CL_emi.value=Math.round(CL_vl);
		}
		else
		{
		    borrow.CL_emi.value=Math.round(CL_vl);
		}
	}
}
/* Savings Worth */


/* Inflation Impact */
function CL_vlidateIImpact()
{
    var frm = document.forms[0];
    if(isNaN(parseFloat(frm.CL_time.value))||parseFloat(frm.CL_time.value)<=0)
    {
        alert('Investment horizon should be greater than 0');
        frm.age.focus();
        return false;
    }
    if(isNaN(parseFloat(frm.CL_current.value))||parseFloat(frm.CL_current.value)<0)
    {
        alert('Current savings should be greater than or equal to 0');
        frm.CL_current.focus();
        return false;
    }
    if(isNaN(parseFloat(frm.CL_tax.value))||parseFloat(frm.CL_tax.value)<0)
    {
        alert('Monthly savings should be greater than or equal to 0');
        frm.CL_tax.focus();
        return false;
    }
    if(isNaN(parseFloat(frm.CL_roi.value))||parseFloat(frm.CL_roi.value)<0)
    {
        alert('Return on your investments should be greater than or equal to 0');
        frm.CL_roi.focus();
        return false;
    }
    if(isNaN(parseFloat(frm.CL_inf.value))||parseFloat(frm.CL_inf.value)<0)
    {
        alert('Please enter rate of inflation');
        frm.CL_inf.focus();
        return false;
    }
    if(parseFloat(frm.CL_roi.value)>100)
    {
        alert(' Please Enter valid Return on your investments');
        frm.CL_roi.focus();
        return false;
    }
    if(parseFloat(frm.CL_roi.value)>100)
    {
        alert(' Please Enter valid Return on your investments');
        frm.CL_roi.focus();
        return false;
    }

    if(parseFloat(frm.CL_tax.value)>100)
    {
        alert(' Please Enter valid Tax rate');
        frm.CL_tax.focus();
        return false;
    }
    if(parseFloat(frm.CL_inf.value)>100)
    {
        alert(' Please Enter valid rate of inflation');
        frm.CL_inf.focus();
        return false;
    }
    return true;
}

var CL_fact=1;

function cl_calculateIImpact()
{
    var CL_current;
    var CL_roi;
    var CL_tenure;
    var CL_vl;
    var CL_type;
    var CL_inf;
    var CL_real;
    var cl_tool = document.forms[0];
    var borrow  = document.forms[0];
    CL_tenure=parseFloat(cl_tool.CL_time.value,10);
    CL_tenure*=CL_fact;
    CL_current=parseFloat(cl_tool.CL_current.value,10);
    CL_roi=parseFloat(cl_tool.CL_roi.value,10)/100;
    CL_inf=parseFloat(cl_tool.CL_inf.value,10)/100;
    CL_tax=parseFloat(cl_tool.CL_tax.value,10)/100;
    CL_roi=CL_roi*(1-CL_tax);
    CL_mon=parseFloat(cl_tool.CL_mon.value,10);

    if (CL_roi==0) CL_roi=0.00000001;
    CL_roi=Math.pow((1+CL_roi),1/CL_fact)-1;
    CL_vl=CL_current*(Math.pow((1+CL_roi),CL_tenure));
    CL_vl+=parseFloat(cl_tool.CL_mon.value,10)*((Math.pow((1+CL_roi),CL_tenure)-1)/CL_roi);

    CL_real=CL_vl/Math.pow(1+CL_inf,CL_tenure/CL_fact);
    
    if(isNaN(CL_vl))
	{
		alert('One or more of the numeric fields are wrong. Please Check');
	}
	else
	{
	    if(document.layers)
		{
		    document.layers['result'].borrow.CL_emi.value=Math.round(CL_vl);
		    document.layers['result'].borrow.CL_real.value=Math.round(CL_real);
		}
		else
		{
    		borrow.CL_emi.value=Math.round(CL_vl);
	    	borrow.CL_real.value=Math.round(CL_real);
		}
	}
}

function cl_validateRetSave()
{
     var frm = document.forms[0];
    if(isNaN(parseFloat(frm.CL_amt.value))||parseFloat(frm.CL_amt.value)<=0)
	{
		alert('Invested amount should be greater than 0');
		frm.CL_amt.focus();
		return false;
	}
	if(isNaN(parseFloat(frm.CL_t2.value))||parseFloat(frm.CL_t2.value)<=0)
	{
		alert('The period should be greater than 0.');
		frm.CL_t2.focus();
		return false;
	}
	if(isNaN(parseFloat(frm.CL_roi2.value))||parseFloat(frm.CL_roi2.value)<=0)
	{
		alert('Rate of interest should be greater than 0.');
		frm.CL_roi2.focus();
		return false;
	}
	
	if(parseFloat(frm.CL_roi2.value)>100)
	{
	    alert('Please enter valid rate of interest');
		frm.CL_roi2.focus();
		return false;
	}
	return true;
}

function cl_calculateRetSave()
{
    var cl_tool = document.forms[0];
    var borrow =  document.forms[0];
    var CL_amount=cl_tool.CL_amt.value;
    var CL_t2=parseFloat(cl_tool.CL_t2.value);
    var CL_roi2=parseFloat(cl_tool.CL_roi2.value)/100;
    var CL_comp=parseFloat(cl_tool.CL_comp.options[cl_tool.CL_comp.options.selectedIndex].value);
    
    if(CL_comp>0)
    {
        var CL_rt=Math.pow(1+CL_roi2/CL_comp,CL_comp);
        var CL_income=CL_amount*CL_roi2/CL_comp
    }
    else
    {
        var CL_rt=Math.pow(1+CL_t2*CL_roi2,1/CL_t2);
        var CL_income= CL_amount*CL_t2*CL_roi2
    }
    
    var CL_inc;
    if(CL_comp<0)CL_inc=  "simple"
    if(CL_comp==1)CL_inc=  "annual"
    if(CL_comp==2)CL_inc=  "semi annual"
    if(CL_comp==4)CL_inc=  "quarterly"
    if(CL_comp==12)CL_inc= "monthly"
    
    if (document.layers)
    {
        document.layers['result'].borrow.CL_tframe.value = CL_inc;
        document.layers['result'].borrow.CL_inc.value = Math.round(CL_income);
        document.layers['result'].borrow.CL_irate.value = Math.round((CL_rt-1)*10000)/100;
    }
    else
    {
        borrow.CL_tframe.value = CL_inc;
        borrow.CL_inc.value = Math.round(CL_income);
        borrow.CL_irate.value = Math.round((CL_rt-1)*10000)/100;
    }
}
/* Inflation Impact */


/* HRA Exemption */
function cl_validateHRA()
{
    frm  = document.forms[0];
	if(isNaN(parseFloat(frm.CL_rent.value))||parseFloat(frm.CL_rent.value)<0)
	{
		alert('Rent should be greater than or equal to 0.');
		frm.CL_rent.focus();
		return false;
	}
	if(isNaN(parseFloat(frm.CL_basic.value))||parseFloat(frm.CL_basic.value)<=0)
	{
		alert('Basic salary should be greater than or equal to 0');
		frm.CL_basic.focus();
		return false;
	}
	if(isNaN(parseFloat(frm.CL_da.value))||parseFloat(frm.CL_da.value)<0)
	{
		alert('DA should be greater than or equal to 0.');
		frm.CL_da.focus();
		return false;
	}
	if(isNaN(parseFloat(frm.CL_hra.value))||parseFloat(frm.CL_hra.value)<0)
	{
		alert('HRA should be greater than or equal to 0.');
		frm.CL_hra.focus();
		return false;
	}
	return true;
}

function cl_calculateHRA()
{
    var cl_tool = document.forms[0];
    var borrow = document.forms[0];
    var CL_hra=parseFloat(cl_tool.CL_hra.value);
    var CL_rent=parseFloat(cl_tool.CL_rent.value);
    var CL_basic=parseFloat(cl_tool.CL_basic.value);
    var CL_da=parseFloat(cl_tool.CL_da.value);
    var CL_metro=0.5;
    var CL_sav=0;                          

    if(cl_tool.CL_city[1].checked) CL_metro=0.4;
    CL_sav=Math.min((CL_basic+CL_da)*CL_metro,CL_hra);
    CL_sav=Math.min(CL_sav,CL_rent-0.1*(CL_basic+CL_da));
    CL_sav=Math.max(CL_sav,0);

    if(document.layers)
    {
        document.layers['result'].borrow.hra.value=CL_sav;
    }
    else
    {
	    borrow.hra.value=CL_sav;
    }
}
/* HRA Exemption */


/* Capital Gains */
function cl_validateCG()
{   
    var frm = document.forms[0];
    var cl_tool = document.forms[0];
	if(!cl_tool.ival.value||cl_tool.ival.value<=0)
	{
		alert('Investment value should be greater than 0.');
		cl_tool.ival.focus();
		return false;
	}
	if(!cl_tool.CL_sval.value||cl_tool.CL_sval.value<=0)
	{
		alert('Sale / Maturity value should be greater than 0');
		cl_tool.CL_sval.focus();
		return false;
	}
	return true;
}

function CL_displayCG(viewShow)
{
    if (document.layers)
    {
        content = document.layers[viewShow];
    }
    else if (document.all)
    {
        content = document.all(viewShow).style;
    }
    if(viewShow=="explain")
    {
        document.getElementById("explain").style.display='inline';
    }
//    else
//    {
//        document.all(viewShow).style.display = "inline";
//    }
    document.getElementById("result").style.display = "inline";
}

function cl_calculateCG()
{   
    var CL_ival;
    var CL_byr;
    var CL_sval;
    var CL_syr;
    var CL_itax=0;
    var CL_tax=0;
    var cl_borrow = document.forms[0];
    CL_ival=document.getElementById("ival").value;
    CL_ival=parseFloat(CL_ival,10);
    CL_byr=document.getElementById("CL_byr");
    CL_byr=parseFloat(CL_byr.options[CL_byr.selectedIndex].value,10);
    CL_sval=document.getElementById("CL_sval").value;
    CL_sval=parseFloat(CL_sval,10);
    CL_syr=document.getElementById("CL_syr");
    CL_syr=parseFloat(CL_syr.options[CL_syr.selectedIndex].value,10);
    
    if (CL_syr==CL_byr)
    {
        alert('As the buying and the selling year are same, the gains will be added to your regular income');
        CL_hid('result');
        CL_hid('explain');
    }
    if (CL_syr.value<CL_byr.value)
    {
        alert('the sale year should come after the investment year');
        return ;
    }
    
    CL_tax=((CL_sval-CL_ival)*0.1)*1.1;
    CL_itax=(CL_sval-(CL_syr/CL_byr)*CL_ival)*0.2*1.1;
    CL_tax=Math.min(CL_tax,CL_itax);
    CL_tax=Math.max(0,CL_tax);
    
    if(isNaN(CL_tax))
	{
		alert('One or more of the numeric fields is wrong. Please Check');
	}
	else
	{
		if(document.layers)
		{
	    	document.layers['result'].cl_borrow.cl_emi.value=Math.round(CL_tax);
    		document.layers['result'].cl_borrow.cl_emi1.value=Math.round(CL_sval-CL_ival);
		}
		else
		{
	    	cl_borrow.cl_emi.value=Math.round(CL_tax);
		    cl_borrow.cl_emi1.value=Math.round(CL_sval-CL_ival);
		}
	}
}
/* Capital Gains */


/* Tax-free of Tax */
function cl_validateTaxFree()
{
    var frm = document.forms[0];
    var cl_tool = document.forms[0];
    var CL_amount=cl_tool.amt.value;

	if(!(CL_amount)||CL_amount<0)
	{
	    alert('Investment amount should be greater than 0');
	    cl_tool.amt.focus();
	    return false;
	}
	
	var CL_roi1=cl_tool.CL_roi1.value;
    if(!(CL_roi1)||CL_roi1<=0)
    {
	    alert('Return on Investment should be greater than 0');
	    cl_tool.CL_roi1.focus();
	    return false;
    }
    var CL_roi1=cl_tool.CL_roi1;
    if(parseFloat(CL_roi1.value)>100)
    {
        alert("Please enter valid Rate of Intrerest earned");
        CL_roi1.focus();
        return false;
    }
    
    var CL_roi2=cl_tool.CL_roi2.value;
    if(!(CL_roi2)||CL_roi2<=0)
    {
	    alert('Return on Investment should be greater than 0');
	    cl_tool.CL_roi2.focus();
	    return false;
    }
    var CL_roi2=cl_tool.CL_roi2;
    if(parseFloat(CL_roi2.value)>100)
    {
        alert("Please enter valid Rate of Intrerest earned");
        CL_roi2.focus();
        return false;
    }
    
    var CL_t2=cl_tool.CL_t2.value;

    if(!(CL_t2)||CL_t2<=0)
    {
	    alert('Tenure of Investment should be greater than 0');
	    cl_tool.CL_t2.focus();
	    return false;
    }
    var CL_tax=parseFloat(document.getElementById("CL_tax").value);
    if(!(CL_tax)||CL_tax<0||CL_tax>35)
    {
	    alert('Tax should be greater than 0 or less than 36');
	    cl_tool.CL_tax.focus();
	    return false;
    }
    return true;
}

function cl_calculateTaxFree()
{
    var cl_tool = document.forms[0];
    var borrow = document.forms[0];
    var CL_amount=cl_tool.amt.value;
    var CL_t2=parseFloat(cl_tool.CL_t2.value);
    var CL_roi2=parseFloat(cl_tool.CL_roi2.value)/100;
    var CL_roi1=parseFloat(cl_tool.CL_roi1.value)/100;
    var CL_comp1=parseFloat(cl_tool.CL_comp1.options[cl_tool.CL_comp1.options.selectedIndex].value);
    var CL_comp2=parseFloat(cl_tool.CL_comp2.options[cl_tool.CL_comp2.options.selectedIndex].value);
    var CL_tax=parseFloat(document.getElementById("CL_tax").value)/100;
    
    if(CL_comp1>0)
    {
        var CL_rt1=Math.pow(1+CL_roi1/CL_comp1,CL_comp1);
        var income1=CL_amount*CL_roi1/CL_comp1*(1-CL_tax)
    }
    else
    {
        var CL_rt1=Math.pow(1+CL_t2*CL_roi1,1/CL_t2);
        var income1= CL_amount*CL_t2*CL_roi1*(1-CL_tax)
    }
    CL_rt1=(CL_rt1-1)*(1-CL_tax);
    if(CL_comp2>0)
    {
        var CL_rt2=Math.pow(1+CL_roi2/CL_comp2,CL_comp2);
        var CL_income2=CL_amount*CL_roi2/CL_comp2
    }
    else
    {
        var CL_rt2=Math.pow(1+CL_t2*CL_roi2,1/CL_t2);
        var CL_income2= CL_amount*CL_t2*CL_roi2
    }
    
    if(CL_rt2-1>CL_rt1)
    {
        var CL_material1="Tax-Free";
    }
    else
    {
        var CL_material1="Taxed";
    }
    
    if (document.layers)
    {
        document.layers['result'].borrow.CL_avn.value=CL_material1;
        document.layers['result'].borrow.CL_tax1.value=Math.round((CL_rt1)*10000)/100;
        document.layers['result'].borrow.CL_ntax.value=Math.round((CL_rt2-1)*10000)/100;
    }
    else
    {
        borrow.CL_avn.value=CL_material1;
        borrow.CL_tax1.value=Math.round((CL_rt1)*10000)/100;
        borrow.CL_ntax.value=Math.round((CL_rt2-1)*10000)/100;
    }
    
}
/* Tax-free of Tax */


/* FV Decreasing */
function validateFVDec()
{
    var pvalue=document.getElementById("pvalue"); 
    var tenure=document.getElementById("tenure");
    var disrate=document.getElementById("disrate");
    
    if(pvalue.value=="")
    {
        alert("Please enter Present Value in Rs.");
        pvalue.focus();
        return false;
    }
    else  if(tenure.value=="")
    {
        alert("Please enter the years of investment");
        tenure.focus();
        return false;
    }
    else  if(disrate.value=="")
    {
        alert("Please enter Discounting Rate - Ann");
        disrate.focus();
        return false;
    }
    else
    {
        calculateFVDec();      
    }
}

function calculateFVDec()
{
    var cl_tools = document.forms[0];
    hid.style.display = "inline";
    var A = cl_tools.pvalue.value;
    A = A.replace(/,/,"");
    var B = cl_tools.tenure.value;
    B = B.replace(/,/,"");
    var C = cl_tools.disrate.value;
    C = C.replace(/,/,"");
    cl_tools.fvalue.value = Math.round(A/Math.pow(1+C/100,B));
    formatNumber('pvalue');
    formatNumber('disrate');
    formatNumber('fvalue');
}

function formatNumber(id)                                       
{
    var obj = document.getElementById(id);
    var num = new NumberFormat();
    num.setInputDecimal('.');
    num.setNumber(obj.value); // obj.value is '100000'
    num.setPlaces('2', false);
    num.setCurrencyValue('');
    num.setCurrency(true);
    num.setCurrencyPosition(num.LEFT_OUTSIDE);
    num.setNegativeFormat(num.LEFT_DASH);
    num.setNegativeRed(false);
    num.setSeparators(true, ',', ',');
    obj.value = num.toFormatted();     
}
/* FV Decreasing */

/* FV Growing */
function validateFVGrow()
{
    var pvalue=document.getElementById("pvalue"); 
    var tenure=document.getElementById("tenure");
    var comprate=document.getElementById("comprate");
    
    if(pvalue.value=="")
    {
        alert("Please enter Present Value in Rs.");
        pvalue.focus();
        return false;
    }
    else  if(tenure.value=="")
    {
        alert("Please enter the years of investment");
        tenure.focus();
        return false;
    }
    else  if(comprate.value=="")
    {
        alert("Please enter Compoundong Rate - Ann");
        comprate.focus();
        return false;
    }   
    else
    {
        calculateFVGrow();
    }
}

function calculateFVGrow()
{
    
    var cl_tools = document.forms[0];
    hid.style.display = "inline";
    var A = cl_tools.pvalue.value;
    A = A.replace(/,/,"");
	var B = cl_tools.tenure.value;
	var C = cl_tools.comprate.value;
	C = C.replace(/,/,"");
	cl_tools.fvalue.value = Math.round(A*Math.pow(1+C/100,B));
	formatNumber('pvalue');
	formatNumber('comprate');
	formatNumber('fvalue');
}
/* FV Growing */

/* SIP PV & FV */
function validateSIP()
{
    var moninvest=document.getElementById("moninvest"); 
    var tenure=document.getElementById("tenure");
    var return1=document.getElementById("return1");
    var discounting=document.getElementById("discounting");
    
    if(moninvest.value=="")
    {
        alert("Please enter the monthly investment amount");
        moninvest.focus();
        return false;
    }
    else  if(tenure.value=="")
    {
        alert("Please enter the years of investment");
        tenure.focus();
        return false;
    }
    else  if(return1.value=="")
    {
        alert("Please enter the expected rate of returns");
        return1.focus();
        return false;
    }
    else  if(parseFloat(return1.value)>100)
    {
        alert("Please enter valid expected rate of returns");
        return1.focus();
        return false;
    }
    else  if(discounting.value=="")
    {
        alert("Please enter the Discounting Rate");
        discounting.focus();
        return false;
    }
    else  if(parseFloat(discounting.value)>100)
    {
        alert("Please enter valid Discounting rate");
        discounting.focus();
        return false;
    }
    else
    {
        calculateSIP();              
    }
}

function calculateSIP()
{
    hid.style.display = "inline";
    var cl_tools = document.forms[0];
	var A = (cl_tools.moninvest.value);
	A = A.replace(/,/,"")
	var B = (cl_tools.tenure.value);
	var C = (cl_tools.return1.value);
	C = C.replace(/,/,"")
	var D = (cl_tools.discounting.value);
	D = D.replace(/,/,"")
	
	var A_A = (B*12);
	var B_B = parseFloat(C/12);
	
	//var E = (futurevalue(C,1/12,0,-100,1)-100);
	//document.cl_tools.futureval.value = Math.round(parseFloat(futurevalue(E,B*12,-A,0,1)))
	
	var E = (-futurevalue(B_B,A_A,A,0,1));
	cl_tools.futureval.value = Math.round(E);
	cl_tools.pval.value = Math.round(parseFloat(cl_tools.futureval.value)/Math.pow(1+D/100,B)) 	    
	formatNumber('moninvest');
	formatNumber('return1');
	formatNumber('discounting');
	formatNumber('futureval');
	formatNumber('pval');
}

function futurevalue(returnspercent,nper,PMT,pv,type)
{
    var rate = returnspercent/100;
	var fv;
	fv =(PMT*(1+rate*type)*(1- Math.pow(1+ rate,nper))/rate)-pv*Math.pow(1+rate,nper);
	return (fv);
}
/* SIP PV & FV */


/* PV Cash Flows */
function validatePVCash()
{
    var Discounting=document.getElementById("Discounting");  
    if(parseFloat(Discounting.value)>100)
	{
	    alert("Please enter valid Discounting rate");
        Discounting.focus();
        return false;
	}
	else
    {
        calculatePVCash();      
    }
}

function calculatePVCash()
{
    var cl_tools = document.forms[0];
    hid.style.display = "inline";
    if (cl_tools.firstyear.value == '')
    {
        cl_tools.firstyear.value = 0.00;
    }
    if (cl_tools.secondyear.value == '')
	{
	    cl_tools.secondyear.value = 0.00;
    }
    if (cl_tools.thirdyear.value == '')
    {
	    cl_tools.thirdyear.value = 0.00;
	}
	if (cl_tools.fourthyear.value == '')
	{
	    cl_tools.fourthyear.value = 0.00;
	}
	if (cl_tools.fifthyear.value == '')
	{
	    cl_tools.fifthyear.value = 0.00;
	}
	if (cl_tools.sixthyear.value == '')
	{
	    cl_tools.sixthyear.value = 0.00;
	}
	if (cl_tools.seventhyear.value == '')
    {
	    cl_tools.seventhyear.value = 0.00;
	}
    if (cl_tools.eigthyear.value == '')
	{
	    cl_tools.eigthyear.value = 0.00;
	}
	if (cl_tools.ninthyear.value == '')
	{
	    cl_tools.ninthyear.value = 0.00;
	}
	if (cl_tools.tenthyear.value == '')
	{
	    cl_tools.tenthyear.value = 0.00;
	}
	if (cl_tools.eleventhyear.value == '')
    {
	    cl_tools.eleventhyear.value = 0.00;
	}
	if (cl_tools.twelthyear.value == '')
	{
	    cl_tools.twelthyear.value = 0.00;
	}
	if (cl_tools.thirteenthyear.value == '')
	{
	    cl_tools.thirteenthyear.value = 0.00;
	}
	if (cl_tools.fourteenthyear.value == '')
	{
	    cl_tools.fourteenthyear.value = 0.00;
	}
	if (cl_tools.fifteenthyear.value == '')
	{
	    cl_tools.fifteenthyear.value = 0.00;
    }
    
    var t1 = cl_tools.firstyear.value ;
    t1 = replaceAll(t1,[[",",""]]);
	var t2 = cl_tools.secondyear.value; 
	t2 = replaceAll(t2,[[",",""]]);
	var t3 = cl_tools.thirdyear.value; 
	t3 = replaceAll(t3,[[",",""]]);
	var t4 = cl_tools.fourthyear.value;
	t4 = replaceAll(t4,[[",",""]]);
	var t5 = cl_tools.fifthyear.value; 
	t5 = replaceAll(t5,[[",",""]]);
	var t6 = cl_tools.sixthyear.value; 
	t6 = replaceAll(t6,[[",",""]]);
	var t7 = cl_tools.seventhyear.value;
	t7 = replaceAll(t7,[[",",""]]);
	var t8 = cl_tools.eigthyear.value; 
	t8 = replaceAll(t8,[[",",""]]);
	var t9 = cl_tools.ninthyear.value; 
	t9 = replaceAll(t9,[[",",""]]);
	var t10 = cl_tools.tenthyear.value;
	t10 = replaceAll(t10,[[",",""]]);
	var t11 = cl_tools.eleventhyear.value ;
    t11 = replaceAll(t11,[[",",""]]);
	var t12 = cl_tools.twelthyear.value ;
	t12 = replaceAll(t12,[[",",""]]);
	var t13 = cl_tools.thirteenthyear.value ;
	t13 = replaceAll(t13,[[",",""]]);
	var t14 = cl_tools.fourteenthyear.value ;
	t14 = replaceAll(t14,[[",",""]]);
	var t15 = cl_tools.fifteenthyear.value ;
	t15 = replaceAll(t15,[[",",""]]);
	
	cl_tools.Total.value =  parseFloat(t1)+parseFloat(t2)+parseFloat(t3)+parseFloat(t4)+parseFloat(t5)+parseFloat(t6)+
									  parseFloat(t7)+parseFloat(t8)+parseFloat(t9)+parseFloat(t10)+parseFloat(t11)+
									  parseFloat(t12)+parseFloat(t13)+parseFloat(t14)+parseFloat(t15);
									  
    var value1 = t1/Math.pow(1+cl_tools.Discounting.value/100,document.getElementById('one').firstChild.innerHTML); 
    var value2 = t2/Math.pow(1+cl_tools.Discounting.value/100,document.getElementById('two').firstChild.innerHTML);
	var value3 = t3/Math.pow(1+cl_tools.Discounting.value/100,document.getElementById('three').firstChild.innerHTML); 
	var value4 = t4/Math.pow(1+cl_tools.Discounting.value/100,document.getElementById('four').firstChild.innerHTML); 
	var value5 = t5/Math.pow(1+cl_tools.Discounting.value/100,document.getElementById('five').firstChild.innerHTML); 
	var value6 = t6/Math.pow(1+cl_tools.Discounting.value/100,document.getElementById('six').firstChild.innerHTML); 
	var value7 = t7/Math.pow(1+cl_tools.Discounting.value/100,document.getElementById('seven').firstChild.innerHTML); 
	var value8 = t8/Math.pow(1+cl_tools.Discounting.value/100,document.getElementById('eight').firstChild.innerHTML); 
	var value9 = t9/Math.pow(1+cl_tools.Discounting.value/100,document.getElementById('nine').firstChild.innerHTML); 
	var value10 = t10/Math.pow(1+cl_tools.Discounting.value/100,document.getElementById('ten').firstChild.innerHTML); 
	var value11 = t11/Math.pow(1+cl_tools.Discounting.value/100,document.getElementById('eleven').firstChild.innerHTML); 
	var value12 = t12/Math.pow(1+cl_tools.Discounting.value/100,document.getElementById('twelve').firstChild.innerHTML); 
	var value13 = t13/Math.pow(1+cl_tools.Discounting.value/100,document.getElementById('thirteen').firstChild.innerHTML); 
	var value14 = t14/Math.pow(1+cl_tools.Discounting.value/100,document.getElementById('fourteen').firstChild.innerHTML);
	var value15 = t15/Math.pow(1+cl_tools.Discounting.value/100,document.getElementById('fifteen').firstChild.innerHTML);
	
    cl_tools.Present.value = Math.round(
	                                              parseFloat(value1)+parseFloat(value2)+parseFloat(value3)+parseFloat(value4)+
												  parseFloat(value5)+parseFloat(value6)+parseFloat(value7)+parseFloat(value8)+
												  parseFloat(value9)+parseFloat(value10)+parseFloat(value11)+parseFloat(value12)+
												  parseFloat(value13)+parseFloat(value14)+parseFloat(value15)
												 );
												 
    
    formatNumber('firstyear');
    formatNumber('secondyear');
	formatNumber('thirdyear');
	formatNumber('fourthyear');
	formatNumber('fifthyear');
	formatNumber('sixthyear');
	formatNumber('seventhyear');
	formatNumber('eigthyear');
	formatNumber('ninthyear');
	formatNumber('tenthyear');
	formatNumber('eleventhyear');
	formatNumber('twelthyear');
	formatNumber('thirteenthyear');
	formatNumber('fourteenthyear');
	formatNumber('fifteenthyear');
	formatNumber('Discounting');
	formatNumber('Total');
	formatNumber('Present');
}
/* PV Cash Flows */


/* PV of Annuity */
function validateAnnuity()
{
    var annuityamt=document.getElementById("annuityamt");
    var Frequency=document.getElementById("Frequency");
    var annruns=document.getElementById("annruns");
    var annstart=document.getElementById("annstart");
    var discounting=document.getElementById("discounting");
    
    if(annuityamt.value=="")
    {
        alert("Please enter the Annuity amount");
        annuityamt.focus();
        return false;
    }
    else if(Frequency.value=="")
    {
        alert("Please enter the frequency in year");
        Frequency.focus();
        return false;
    }
    else if(annruns.value=="")
    {
        alert("Please enter the number of years annuity runs");
        annruns.focus();
        return false;
    }
    else if(annstart.value=="")
    {
        alert("Please enter the number of years after which annuity starts");
        annstart.focus();
        return false;
    }
    else if(discounting.value=="")
    {
        alert("Please enter discounting rate");
        discounting.focus();
        return false;
    }
    else if(parseFloat(discounting.value)>100)
    {
        alert("Please enter valid discounting rate");
        discounting.focus();
        return false;
    }
    else
    {
        calculateAnnuity();show();     
    }
}

function calculateAnnuity()
{
    var cl_tools = document.forms[0];
    hid.style.display = "inline";
    var A = cl_tools.annuityamt.value;
    A = A.replace(/,/,"");
	var B = cl_tools.Frequency.value;
	B = B.replace(/,/,"");
	var C = cl_tools.annruns.value;
	
	var totAmt = A*B*C;
	cl_tools.totalamt.value= totAmt;
	
//    var D =  futurevalue(document.cl_tools.discounting.value/100,1/ document.cl_tools.Frequency.value,0,-100,1)-100;
//    var E =  (document.cl_tools.Frequency.value)* (document.cl_tools.annruns.value);
//    var F = Math.pow(1+D,-E);
//    var G = 1-F;
//    var H = (G/D)*A
//    document.cl_tools.presentval.value = Math.round(H/Math.pow(1+document.cl_tools.discounting.value/100, document.cl_tools.annstart.value ))

	var Disc = cl_tools.discounting.value;
	var Denom = Math.pow((1 + ((Disc)/100)),cl_tools.annstart.value);
    cl_tools.presentval.value = totAmt/Denom;
	
	formatNumber('totalamt');
    formatNumber('annuityamt');
	formatNumber('Frequency');
	formatNumber('discounting');
	formatNumber('annuityamt');
	formatNumber('presentval');
}
/* PV of Annuity */


/* PV Single Amount */
function validatePVSingle()
{
    var fvvalue=document.getElementById("fvvalue"); 
    var tenure=document.getElementById("tenure");
    var rate=document.getElementById("rate");
    
    if(fvvalue.value=="")
    {
        alert("Please enter Future Value");
        fvvalue.focus();
        return false;
    }
    else if(tenure.value=="")
    {
        alert("Please enter the years of investment");
        tenure.focus();
        return false;
    }
    else if(rate.value=="")
    {
        alert("Please enter the Discounting Rate");
        rate.focus();
        return false;
    }
    else  if(parseFloat(rate.value)>100)
    {
        alert("Please enter valid Discounting Rate");
        rate.focus();
        return false;
    }
    else
    {
        calculatePVSingle();show();
    }
}

function calculatePVSingle()
{
    hid.style.display = "inline";
    var cl_tools = document.forms[0];
    var cl_futureval = cl_tools.fvvalue.value;
	cl_futureval = cl_futureval.replace(/,/,"");
	var cl_tenure = cl_tools.tenure.value;
	var cl_discounting = cl_tools.rate.value;
	cl_discounting = cl_discounting.replace(/,/,"");
	cl_tools.PresentValue.value = Math.round(cl_futureval/Math.pow(1+cl_discounting/100,cl_tenure)); 
	formatNumber('fvvalue');
	formatNumber('rate');
	formatNumber('PresentValue');
}
/* PV Single Amount */


/* Delay Cost in SIP */
function validateSIPCost()
{
    var moninst=document.getElementById("moninst"); 
    var tenure=document.getElementById("tenure");
    var rateofretun=document.getElementById("rateofretun");
    var delay=document.getElementById("delay");
    
    if(moninst.value=="")
    {
        alert("Please enter the monthly investment amount");
        moninst.focus();
        return false;
    }
    else  if(tenure.value=="")
    {
        alert("Please enter the years of investment");
        tenure.focus();
        return false;
    }
    else  if(rateofretun.value=="")
    {
        alert("Please enter the expected rate of returns");
        rateofretun.focus();
        return false;
    }
    else  if(parseFloat(rateofretun.value)>100)
    {
        alert("Please enter valid expected rate of returns");
        rateofretun.focus();
        return false;
    }
    else  if(delay.value=="")
    {
        alert("Please enter the delay in starting the SIP");
        delay.focus();
        return false;
    }
    else
    {
        calculateSIPCost();      
    }
}

function calculateSIPCost()
{
    hid.style.display = "inline";
    var cl_tools = document.forms[0];
    var cl_moninst = (cl_tools.moninst.value);
    cl_moninst = cl_moninst.replace(/,/,"")
	var cl_tenure = (cl_tools.tenure.value); 
	cl_tenure = cl_tenure.replace(/,/,"")
	var cl_rateofretun = (cl_tools.rateofretun.value); 
	cl_rateofretun = cl_rateofretun.replace(/,/,"")
	var delay = (cl_tools.delay.value); 
	delay = delay.replace(/,/,"")
	var A = (cl_tools.tenure.value*12);
	
	//Changed calculation for B as it was showing wrong result
	//var B = parseFloat(futurevalue(cl_rateofretun,1/12,0,-100,1)-100);
	var B = parseFloat(cl_rateofretun/12);
	
	var C = parseFloat(-futurevalue(B,A,cl_moninst,0,1));
	cl_tools.invvaluetoday.value = Math.round(C);
	D = (A - delay);
	E = (-futurevalue(B,D,cl_moninst,0,1));
    cl_tools.invvaluedelay.value = Math.round(E);
	cl_tools.delaycost.value = Math.round(C-E);

	//F = Math.round(Math.round(C-E)/Math.pow((1+0.06),cl_tenure));
	//document.cl_tools.lostmoney.value = (F); 
	
	formatNumber('moninst');
	formatNumber('rateofretun');
	formatNumber('invvaluetoday');
	formatNumber('invvaluedelay');
	formatNumber('delaycost');
	//formatNumber('lostmoney');
}
/* Delay Cost id SIP */


/* SIP Need Calculator */
function hideSIPNeed()
{
    document.getElementById("hid").style.display = 'none';
    document.getElementById("hid1").style.display = 'none';
    document.getElementById("hid2").style.display = 'none';
}

function validateSIPNeed()
{
    var fvamt=document.getElementById("fvamt");
    var tenure=document.getElementById("tenure");
//    var growthrate=document.getElementById("growthrate");
    var returns=document.getElementById("returns");
    
    if(fvamt.value=="")
    {
        alert("Please enter target amount");
        fvamt.focus();
        return false;
    }
    else if(tenure.value=="")
    {
        alert("Please enter the tenure");
        tenure.focus();
        return false;
    }
//    else if(growthrate.value=="")
//    {
//        alert("Please enter Annual increase in Investible Amount");
//        growthrate.focus();
//        return false;
//    }
//    else if(isNaN(parseFloat(growthrate.value))||parseFloat(growthrate.value)<0||parseFloat(growthrate.value)>100)
//    {
//        alert("Please enter valid Annual increase in Investible Amount");
//        growthrate.focus();
//        return false;
//    }
    else if(returns.value=="")
    {
        alert("Please enter Expected Return");
        returns.focus();
        return false;
    }
    else if(isNaN(parseFloat(returns.value))||parseFloat(returns.value)<0||parseFloat(returns.value)>100)
    {
        alert("Please enter valid Expected Return");
        returns.focus();
        return false;
    }
    else
    {
        calculateSIPNeed();
        callSIPNeed();
        call2SIPNeed();
        showSIPNeed();
    }
}

function calculateSIPNeed()
{ 
    document.getElementById("hid").style.display = "inline";
    document.getElementById("hid1").style.display = "inline";
	document.getElementById("hid2").style.display = "inline";
	var cl_tool = document.forms[0]; 
	var cl_famt = cl_tool.fvamt.value;
    cl_famt = replaceAll(cl_famt,[[",",""]]);
	var cl_tenure = cl_tool.tenure.value;
//	var cl_growth = document.cl_tool.growthrate.value;
//	cl_growth = replaceAll(cl_growth,[[",",""]]);
	var cl_returns = cl_tool.returns.value;
	cl_returns = replaceAll(cl_returns,[[",",""]]);

//	if (cl_growth!=0)
//	{
//	    var A = Math.pow(1+(cl_returns/100),cl_tenure);
//	    var B = Math.pow(1+(cl_growth/100),cl_tenure);
//	    var C = A - B;
//	    var D = cl_returns - cl_growth;
//	    var E = C/(D/100);
//	    var F = 1+(cl_returns/100);
//	    var G = E*F;
//	    var H = cl_famt/G;
//	    var cl_sipcalculated = H/12;
//	    document.cl_tool.sip.value= Math.round(cl_sipcalculated);
//	    formatNumber('sip');
//	}
//	else
//	{


//	    var A = (1+(cl_returns/100))* (((Math.pow(1+(cl_returns/100),cl_tenure)-1)))/ ((1+(cl_returns/100))-1);
//        var B = (futurevalueSIPNeed(cl_returns))-100;
//		var C = (1+(B/100))* (((Math.pow(1+(B/100),12*cl_tenure)-1)))/ ((1+(B/100))-1);
//		var D = cl_famt/A;
//		var cl_sipcalculated = cl_famt/C;
//		document.cl_tool.sip.value= Math.round(cl_sipcalculated);
//		formatNumber('sip');
		
		mnth = (cl_tenure * 12);
        retrate = parseFloat(cl_returns/12);
		cl_tool.sip.value = Math.round(-PreVal(retrate,mnth,cl_famt,0,1));
		formatNumber('sip');
		
//	}
}

function PreVal(intrate,totperiod,finval,pv,type)
{
    var SIPAmt;
    intrate1=intrate/100;
    SIPAmt = ((finval + (pv * Math.pow(1+intrate1,totperiod))) * intrate1)/((1+intrate1*type) * (1-(Math.pow(1+intrate1,totperiod))))
    return (SIPAmt);
}

function callSIPNeed()
{
    //document.getElementById('t2').firstChild.innerHTML
    document.getElementById("hid").style.display = "inline";
	document.getElementById("hid1").style.display = "inline";
	document.getElementById("hid2").style.display = "inline";
	
	var sip;
	
	if(navigator.userAgent.indexOf("MSIE")!=-1)
	{   
	    sip= calculate1(document.getElementById('t1').firstChild.innerHTML);
	    sip=Math.round(sip);
	    sip = Comma(sip)
	    document.getElementById('r2t1').innerText = sip;
        sip= calculate1(document.getElementById('t2').firstChild.innerHTML);
	    sip=Math.round(sip);
	    sip = Comma(sip)
	    document.getElementById('r2t2').innerText = sip;
	  
	    sip= calculate1(document.getElementById('t3').firstChild.innerHTML);
	    sip=Math.round(sip);
	    sip = Comma(sip)
	    document.getElementById('r2t3').innerText = sip;
	  
	    sip= calculate1(document.getElementById('t4').firstChild.innerHTML);
	    sip=Math.round(sip);
	    sip = Comma(sip)
	    document.getElementById('r2t4').innerText = sip;
	  
	    sip= calculate1(document.getElementById('t5').firstChild.innerHTML);
	    sip=Math.round(sip);
	    sip = Comma(sip)
	    document.getElementById('r2t5').innerText = sip;
	    
	    sip= calculate1(document.getElementById('t6').firstChild.innerHTML);
	    sip=Math.round(sip);
	    sip = Comma(sip)
	    document.getElementById('r2t6').innerText = sip;
	}
	else
	{
	    sip= calculate1(t1.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip)
	    r2t1.textContent = sip;
	    
	    sip= calculate1(t2.textContent);	 
	    sip=Math.round(sip);
	    sip = Comma(sip)	  
	    r2t2.textContent = sip;	
	  
	    sip= calculate1(t3.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    r2t3.textContent = sip;
	  
	    sip= calculate1(t4.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    r2t4.textContent = sip;
	  
	    sip= calculate1(t5.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip)
	    r2t5.textContent = sip;
	    
	    sip= calculate1(t6.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    r2t6.textContent = sip;
	}
}

function call2SIPNeed()
{
    document.getElementById("hid").style.display = "inline";
    document.getElementById("hid1").style.display = "inline";
	document.getElementById("hid2").style.display = "inline";
	
	var sip;
	//alert("ok");
	if(navigator.userAgent.indexOf("MSIE")!=-1)
	{
	    sip= calculate2(document.getElementById('tab2t1').firstChild.innerHTML,document.getElementById('tab2r1t0').innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip);
	     
        document.getElementById('tab2r1t1').innerText = sip;
       
	    sip= calculate2(document.getElementById('tab2t2').firstChild.innerHTML,document.getElementById('tab2r1t0').innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    document.getElementById('tab2r1t2').innerText= sip;
	  
	    sip= calculate2(document.getElementById('tab2t3').firstChild.innerHTML,document.getElementById('tab2r1t0').innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    document.getElementById('tab2r1t3').innerText= sip;
	    
	    sip= calculate2(document.getElementById('tab2t4').firstChild.innerHTML,document.getElementById('tab2r1t0').innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    document.getElementById('tab2r1t4').innerText= sip;
	  
	    sip= calculate2(document.getElementById('tab2t5').firstChild.innerHTML,document.getElementById('tab2r1t0').innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    document.getElementById('tab2r1t5').innerText= sip;
	  
	    sip= calculate2(document.getElementById('tab2t6').firstChild.innerHTML,document.getElementById('tab2r1t0').innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    document.getElementById('tab2r1t6').innerText= sip;
	    //>>>>>>>>>>>>>>>>>>>>>>>>>>//
	    
	    sip= calculate2(document.getElementById('tab2t1').firstChild.innerHTML,document.getElementById('tab2r2t0').innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    document.getElementById('tab2r2t1').innerText= sip;
	  
	    sip= calculate2(document.getElementById('tab2t2').firstChild.innerHTML,document.getElementById('tab2r2t0').innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    document.getElementById('tab2r2t2').innerText= sip;
	  
	    sip= calculate2(document.getElementById('tab2t3').firstChild.innerHTML,document.getElementById('tab2r2t0').innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    document.getElementById('tab2r2t3').innerText= sip;
	    
	    sip= calculate2(document.getElementById('tab2t4').firstChild.innerHTML,document.getElementById('tab2r2t0').innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    document.getElementById('tab2r2t4').innerText= sip;
	    
	    sip= calculate2(document.getElementById('tab2t5').firstChild.innerHTML,document.getElementById('tab2r2t0').innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    document.getElementById('tab2r2t5').innerText= sip;
	    
	    sip= calculate2(document.getElementById('tab2t6').firstChild.innerHTML,document.getElementById('tab2r2t0').innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    document.getElementById('tab2r2t6').innerText= sip;
	    //>>>>>>>>>>>>>>>>>>>
	    
	    sip= calculate2(document.getElementById('tab2t1').firstChild.innerHTML,tab2r3t0.innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r3t1.innerText = sip;
	  
	    sip= calculate2(document.getElementById('tab2t2').firstChild.innerHTML,tab2r3t0.innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r3t2.innerText = sip;
	    
	    sip= calculate2(document.getElementById('tab2t3').firstChild.innerHTML,tab2r3t0.innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r3t3.innerText = sip;
	  
	    sip= calculate2(document.getElementById('tab2t4').firstChild.innerHTML,tab2r3t0.innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r3t4.innerText = sip;
	  
	    sip= calculate2(document.getElementById('tab2t5').firstChild.innerHTML,tab2r3t0.innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r3t5.innerText = sip;
	  
	    sip= calculate2(document.getElementById('tab2t6').firstChild.innerHTML,tab2r3t0.innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r3t6.innerText = sip;
	    //>>>>>>>>>>>>>>>>>>>>>>>>..
	    
	    sip= calculate2(document.getElementById('tab2t1').firstChild.innerHTML,tab2r4t0.innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r4t1.innerText = sip;
	  
	    sip= calculate2(document.getElementById('tab2t2').firstChild.innerHTML,tab2r4t0.innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r4t2.innerText = sip;
	  
	    sip= calculate2(document.getElementById('tab2t3').firstChild.innerHTML,tab2r4t0.innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r4t3.innerText = sip;
	    
	    sip= calculate2(document.getElementById('tab2t4').firstChild.innerHTML,tab2r4t0.innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r4t4.innerText = sip;
	  
	    sip= calculate2(document.getElementById('tab2t5').firstChild.innerHTML,tab2r4t0.innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r4t5.innerText = sip;
	  
	    sip= calculate2(document.getElementById('tab2t6').firstChild.innerHTML,tab2r4t0.innerText);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r4t6.innerText = sip;
	    //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	}
	else
	{
	    sip= calculate2(tab2t1.textContent,tab2r1t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r1t1.textContent = sip;

        sip= calculate2(tab2t2.textContent,tab2r1t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r1t2.textContent = sip;
	    
	    sip= calculate2(tab2t3.textContent,tab2r1t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r1t3.textContent = sip;
	  
	    sip= calculate2(tab2t4.textContent,tab2r1t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r1t4.textContent = sip;
	  
	    sip= calculate2(tab2t5.textContent,tab2r1t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r1t5.textContent = sip;
	    
	    sip= calculate2(tab2t6.textContent,tab2r1t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r1t6.textContent = sip;
	    //>>>>>>>>>>>>>>>>>>>>>>>>>>//
	    
	    sip= calculate2(tab2t1.textContent,tab2r2t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r2t1.textContent = sip;
	  
	    sip= calculate2(tab2t2.textContent,tab2r2t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r2t2.textContent = sip;
	  
	    sip= calculate2(tab2t3.textContent,tab2r2t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r2t3.textContent = sip;
	  
	    sip= calculate2(tab2t4.textContent,tab2r2t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r2t4.textContent = sip;
	    
	    sip= calculate2(tab2t5.textContent,tab2r2t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r2t5.textContent = sip;
	  
	    sip= calculate2(tab2t6.textContent,tab2r2t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r2t6.textContent = sip;
	    //>>>>>>>>>>>>>>>>>>>
	    
	    sip= calculate2(tab2t1.textContent,tab2r3t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r3t1.textContent = sip;
	  
	    sip= calculate2(tab2t2.textContent,tab2r3t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r3t2.textContent = sip;
	  
	    sip= calculate2(tab2t3.textContent,tab2r3t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r3t3.textContent = sip;
	  
	    sip= calculate2(tab2t4.textContent,tab2r3t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r3t4.textContent = sip;
	    
	    sip= calculate2(tab2t5.textContent,tab2r3t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r3t5.textContent = sip;
	  
	    sip= calculate2(tab2t6.textContent,tab2r3t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r3t6.textContent = sip;
	    //>>>>>>>>>>>>>>>>>>>>>>>>..
	    
	    sip= calculate2(tab2t1.textContent,tab2r4t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r4t1.textContent = sip;
	  
	    sip= calculate2(tab2t2.textContent,tab2r4t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r4t2.textContent = sip;
	  
	    sip= calculate2(tab2t3.textContent,tab2r4t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r4t3.textContent = sip;
	  
	    sip= calculate2(tab2t4.textContent,tab2r4t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r4t4.textContent = sip;
	    
	    sip= calculate2(tab2t5.textContent,tab2r4t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r4t5.textContent = sip;
	  
	    sip= calculate2(tab2t6.textContent,tab2r4t0.textContent);
	    sip=Math.round(sip);
	    sip = Comma(sip) 
	    tab2r4t6.textContent = sip;
	    //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	}
}

function showSIPNeed()
{
    document.getElementById("hid").style.display = 'inline';
    document.getElementById("hid1").style.display = 'inline';
	document.getElementById("hid2").style.display = 'inline';
}

function Comma(number)
{
    number = '' + number;
    if (number.length > 3) 
    {
        var mod = number.length % 3;
        var output = (mod > 0 ? (number.substring(0,mod)) : '');
        for (i=0 ; i < Math.floor(number.length / 3); i++) 
		{
            if ((mod == 0) && (i == 0))
                output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
            else 
                output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
        }
        return (output);
    }
    else return number;
}

function calculate2(tenure,returns)
{
     var cl_tool = document.forms[0];
     var cl_famt = cl_tool.fvamt.value;
     cl_famt = replaceAll(cl_famt,[[",",""]]);
	//var cl_famt = 10000000;
	
//	var A = (1+(returns/100))* (((Math.pow(1+(returns/100),tenure)-1)))/ ((1+(returns/100))-1);
//    var B = (futurevalueSIPNeed(returns))-100;
//	var C = (1+(B/100))* (((Math.pow(1+(B/100),12*tenure)-1)))/ ((1+(B/100))-1);
//	var D = parseFloat(cl_famt)/A;
//	var cl_sipcalculated = cl_famt/C;

    mnth = (tenure * 12);
    retrate = parseFloat(returns/12);
	var cl_sipcalculated = Math.round(-PreVal(retrate,mnth,cl_famt,0,1));
	formatNumber('sip');
		
	return (cl_sipcalculated);
}

function calculate1(expretunvalue)
{
    document.getElementById("hid").style.display = "inline";
    document.getElementById("hid1").style.display = "inline";
	document.getElementById("hid2").style.display = "inline";
	var cl_tool = document.forms[0];
	var cl_famt = cl_tool.fvamt.value;
    cl_famt = replaceAll(cl_famt,[[",",""]]);
	var cl_tenure = cl_tool.tenure.value;
//	var cl_growth = document.cl_tool.growthrate.value; 
//	cl_growth = replaceAll(cl_growth,[[",",""]]);
	
//	if (cl_growth!=0) 
//    {
//	    var A = Math.pow(1+(expretunvalue/100),cl_tenure);
//	    var B = Math.pow(1+(cl_growth/100),cl_tenure);
//	    var C = A - B;
//	    var D = expretunvalue - cl_growth;
//	    var E = C/(D/100);
//	    var F = 1+(expretunvalue/100);
//    	var G = E*F;
//	    var H = cl_famt/G;
//	    var cl_sipcalculated = H/12;
//	}
//	else
//    {
	    
	    
	    //var A = (1+(expretunvalue/100))* (((Math.pow(1+(expretunvalue/100),cl_tenure)-1)))/ ((1+(expretunvalue/100))-1);
        //var B = (futurevalueSIPNeed(expretunvalue))-100;
		//var C = (1+(B/100))* (((Math.pow(1+(B/100),12*cl_tenure)-1)))/ ((1+(B/100))-1);
		//var D = cl_famt/A;
		//var cl_sipcalculated = cl_famt/C;
		
		mnth = (cl_tenure * 12);
		retrate = parseFloat(expretunvalue/12);
		var cl_sipcalculated = -PreVal(retrate,mnth,cl_famt,0,1);
//    }
    return cl_sipcalculated;
}

function futurevalueSIPNeed(returnspercent)
{
    var rate = returnspercent/100;
    var nper = 1/12;
	var PMT= 0;
	var pv = -100;
	var type = 1;
	var fv;
	fv =(PMT*(1+rate*type)*(1- Math.pow(1+ rate,nper))/rate)-pv*Math.pow(1+rate,nper);
	return (fv);
}
/* SIP Need Calculator */


/* SIP Table */
function cl_call()
{
    var emi;
    var cl_tool = document.forms[0];
    var sipvalue = cl_tool.sipamt.value;
    //alert(document.getElementById('t1').firstChild.innerHTML);
    if(sipvalue=="")
    {
        alert("Please enter SIP Amount");
        cl_tool.sipamt.focus();
        return false;
    }
    else
    {   
        sipvalue = sipvalue.replace(/,/,"");
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t1').firstChild.innerHTML,document.getElementById('r1').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r1t1').innerHTML= emi;
        
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t2').firstChild.innerHTML,document.getElementById('r1').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r1t2').innerHTML= emi;
   
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t3').firstChild.innerHTML,document.getElementById('r1').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r1t3').innerHTML= emi;
   
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t4').firstChild.innerHTML,document.getElementById('r1').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r1t4').innerHTML= emi;
   
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t5').firstChild.innerHTML,document.getElementById('r1').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r1t5').innerHTML= emi;
        
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t6').firstChild.innerHTML,document.getElementById('r1').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r1t6').innerHTML= emi;
        
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t1').firstChild.innerHTML,document.getElementById('r2').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r2t1').innerHTML = emi;
   
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t2').firstChild.innerHTML,document.getElementById('r2').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r2t2').innerHTML = emi;
   
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t3').firstChild.innerHTML,document.getElementById('r2').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r2t3').innerHTML = emi;
        
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t4').firstChild.innerHTML,document.getElementById('r2').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r2t4').innerHTML= emi;
        
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t5').firstChild.innerHTML,document.getElementById('r2').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r2t5').innerHTML = emi;
   
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t6').firstChild.innerHTML,document.getElementById('r2').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r2t6').innerHTML = emi;
   
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t1').firstChild.innerHTML,document.getElementById('r3').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r3t1').innerHTML = emi;
   
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t2').firstChild.innerHTML,document.getElementById('r3').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r3t2').innerHTML = emi;
   
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t3').firstChild.innerHTML,document.getElementById('r3').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r3t3').innerHTML = emi;
        
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t4').firstChild.innerHTML,document.getElementById('r3').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r3t4').innerHTML = emi;
   
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t5').firstChild.innerHTML,document.getElementById('r3').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r3t5').innerHTML = emi;
   
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t6').firstChild.innerHTML,document.getElementById('r3').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r3t6').innerHTML = emi;
        
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t1').firstChild.innerHTML,document.getElementById('r4').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r4t1').innerHTML = emi;
   
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t2').firstChild.innerHTML,document.getElementById('r4').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r4t2').innerHTML = emi;
   
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t3').firstChild.innerHTML,document.getElementById('r4').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r4t3').innerHTML = emi;
   
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t4').firstChild.innerHTML,document.getElementById('r4').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r4t4').innerHTML = emi;
   
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t5').firstChild.innerHTML,document.getElementById('r4').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r4t5').innerHTML = emi;
        
        emi = cl_calculateSIPTab(sipvalue,document.getElementById('t6').firstChild.innerHTML,document.getElementById('r4').firstChild.innerHTML);
        emi = Comma(emi)
        document.getElementById('r4t6').innerHTML = emi;
   
        show();
    }
}

function cl_calculateSIPTab(cl_amtpermonth,cl_tenure,cl_returns)
{
    var rate = cl_returns/100;
    var nper = 1/12;
	var PMT= 0;
	var pv = -100;
	var type = 1;
	var fv;
	fv =(PMT*(1+rate*type)*(1- Math.pow(1+ rate,nper))/rate)-pv*Math.pow(1+rate,nper);
	fv = fv-100;
	
	var fv1=fv/100;
    var newtenure= cl_tenure*12;
	var newcl_amtpermonth =cl_amtpermonth;
	pv = 0;
	type =1;
	var famt= Math.round(newcl_amtpermonth*(1+fv1*type)*(1- Math.pow(1+fv1,newtenure))/fv1 - pv*Math.pow(1+fv1,newtenure));
	return (-famt);
}
/* SIP Table */


/* SIP as per need */
function cl_calculateSIPNeed()
{
    var amtpermonth=document.getElementById('amtpermonth');
    var tenure=document.getElementById('tenure');
	var returns=document.getElementById('returns');
	var cl_tool = document.forms[0];
	if(!amtpermonth.value||parseFloat(amtpermonth.value)<=0)
    {
	    alert("Please enter monthly investment amount");
	    amtpermonth.focus();
	    return false;
	}
	else if(!tenure.value||parseFloat(tenure.value)<=0)
	{
	    alert("Please enter Investment Periods");
	    tenure.focus();
	    return false;
	}
	else if(!returns.value||parseFloat(returns.value)<=0)
	{
	    alert("Please enter valid returns percentage");
	    returns.focus();
	    return false;
    }
    else if(parseFloat(returns.value)>100)
	{
	    alert("Please enter valid returns percentage");
	    returns.focus();
	    return false;
    }
    else
    {
        var cl_amtpermonth = (cl_tool.amtpermonth.value);
	    cl_amtpermonth = cl_amtpermonth.replace(/,/,"");
	    var cl_tenure = (cl_tool.tenure.value);
	    var cl_returns = (cl_tool.returns.value); 
	    cl_returns =  cl_returns.replace(/,/,"");
	    
	    var A = (cl_tenure*12);
    	var B = parseFloat(cl_returns/12);
    	var C = parseFloat(-futurevalue(B,A,cl_amtpermonth,0,1));
    	
    	cl_tool.emi.value = Math.round(C);
    	
    	var famt1= (cl_tenure*12*cl_amtpermonth);
	    cl_tool.CL_fv.value = famt1;
	
	    var fv = futurevalue(cl_returns,1/12,0,-100,1)-100;
	    var famt = Math.round(futurevalue(fv,cl_tenure*12,cl_amtpermonth,0,1));
//	    document.cl_tool.emi.value= -famt;
	    //var finalvalue = -(famt/famt1) +'';
	    var finalvalue = (Math.round(C)/famt1) +'';
	    cl_tool.CL_current.value= finalvalue.substring(0,4);
	    
	    show();
    }
}
/* SIP as per need */


/* Bond Yield */
function cl_validateBY()
{
    var frm=document.forms[0];
    if(isNaN(parseFloat(frm.CL_amt.value))||parseFloat(frm.CL_amt.value)<=0)
    {
        alert('Invested amount should be greater than 0');
        frm.CL_amt.focus();
        return false;
    }
    if(isNaN(parseFloat(frm.CL_t2.value))||parseFloat(frm.CL_t2.value)<=0)
    {
        alert('The period should be greater than 0.');
        frm.CL_t2.focus();
        return false;
    }
    if(isNaN(parseFloat(frm.CL_roi2.value))||parseFloat(frm.CL_roi2.value)<=0)
    {
        alert('Rate of interest should be greater than 0.');
        frm.CL_roi2.focus();
        return false;
    }
    if(parseFloat(frm.CL_roi2.value)>100)
    {
        alert(' Please enter valid Rate of interest');
        frm.CL_roi2.focus();
        return false;
    }
    return true;
}

function cl_calculateBY()
{
   cl_tool= document.forms[0];
   borrow = document.forms[0];
    var CL_amount=cl_tool.CL_amt.value;
    var CL_t2=parseFloat(cl_tool.CL_t2.value);
    var CL_roi2=parseFloat(cl_tool.CL_roi2.value)/100;
    var CL_comp=parseFloat(cl_tool.CL_comp.options[cl_tool.CL_comp.options.selectedIndex].value);
    
    if(CL_comp>0)
    {
        var CL_rt=Math.pow(1+CL_roi2/CL_comp,CL_comp);
        var CL_income=CL_amount*CL_roi2/CL_comp
    }
    else
    {
        var CL_rt=Math.pow(1+CL_t2*CL_roi2,1/CL_t2);
        var CL_income= CL_amount*CL_t2*CL_roi2
    }
    
    var CL_inc;
    if(CL_comp<0)CL_inc=  "simple"
    if(CL_comp==1)CL_inc=  "annual"
    if(CL_comp==2)CL_inc=  "semi annual"
    if(CL_comp==4)CL_inc=  "quarterly"
    if(CL_comp==12)CL_inc= "monthly"
    
    if (document.layers)
    {
        document.layers['result'].borrow.CL_tframe.value = CL_inc;
        document.layers['result'].borrow.CL_inc.value = Math.round(CL_income);
        document.layers['result'].borrow.CL_irate.value = Math.round((CL_rt-1)*10000)/100;
    }
    else
    {
        borrow.CL_tframe.value = CL_inc;
        borrow.CL_inc.value = Math.round(CL_income);
        borrow.CL_irate.value = Math.round((CL_rt-1)*10000)/100;
    }
}
/* Bond Yield */


/* Current Bond Yield */
function cl_validateCBY()
{
     var cl_tool = document.forms[0];   
    if (!cl_tool.CL_fvb.value || parseFloat(cl_tool.CL_fvb.value)<=0)
    {
	    alert('The face value of bond should be greater than or equal to 0');
	    cl_tool.CL_fvb.focus();
	    return false;
    }
    else if (!cl_tool.CL_price.value || parseFloat(cl_tool.CL_price.value)<=0)
    {
	    alert('The price of bond should be greater than or equal to 0');
	    cl_tool.CL_price.focus();
	    return false;
    }
    else if (!cl_tool.CL_coupon.value || parseFloat(cl_tool.CL_coupon.value)<=0)
    {
	    alert('Please Enter the coupon rate');
	    cl_tool.CL_coupon.focus();
	    return false;
    }
    else
    {
        cl_calculateCBY();
    }
}

function cl_calculateCBY()
{
    var cl_tool = document.forms[0];
    var borrow = document.forms[0];
    CL_fvb=parseFloat(cl_tool.CL_fvb.value)
    CL_price=parseFloat(cl_tool.CL_price.value)
    CL_coupon=parseFloat(cl_tool.CL_coupon.value)
    
    var CL_currate=CL_fvb*CL_coupon/CL_price/100;
    CL_currate=Math.round(CL_currate*10000)/100;
    
    if (document.layers)
    {
        document.layers['result'].borrow.CL_yld.value=CL_currate
    }
    else
    {
        borrow.CL_yld.value=CL_currate
    }
}
/* Current Bond Yield */


/* Implied Bond Yield */
function cl_validateIBY()
{
    var frm = document.forms[0];
    if (!frm.CL_fvb.value || parseFloat(frm.CL_fvb.value)<=0)
    {
	    alert('The face value of bond should be greater than or equal to 0');
	    frm.CL_fvb.focus();
	    return false;
    }
    if (!frm.CL_ryr1.value || parseFloat(frm.CL_ryr1.value)<1900 ||parseFloat(frm.CL_ryr1.value)>=2100)
    {
	    alert('The format for year is yyyy');
	    frm.CL_ryr1.focus();
	    return false;
    }
    if (!frm.CL_ryr.value || parseFloat(frm.CL_ryr.value)<1900 ||parseFloat(frm.CL_ryr.value)>=2100)
    {
	    alert('The format for year is yyyy');
	    frm.CL_ryr.focus();
	    return false;
    }
    if (!frm.CL_price.value || parseFloat(frm.CL_price.value)<=0)
    {
	    alert('The price of bond should be greater than or equal to 0');
	    frm.CL_price.focus();
	    return false;
    }
	return true;
}

function cl_calculateIBY()
{
    var cl_tool = document.forms[0];
    var borrow = document.forms[0];
    CL_fvb=parseFloat(cl_tool.CL_fvb.value)
    CL_price=parseFloat(cl_tool.CL_price.value)
    CL_rday1=parseFloat(cl_tool.CL_rdy1.options[cl_tool.CL_rdy1.selectedIndex].value)
    CL_rday=parseFloat(cl_tool.CL_rdy.options[cl_tool.CL_rdy.selectedIndex].value)
    CL_rmon1=parseFloat(cl_tool.CL_rmon1.options[cl_tool.CL_rmon1.selectedIndex].value)
    CL_rmon=parseFloat(cl_tool.CL_rmon.options[cl_tool.CL_rmon.selectedIndex].value)
    CL_ryr1=parseFloat(cl_tool.CL_ryr1.value)
    CL_ryr=parseFloat(cl_tool.CL_ryr.value)
    
    var CL_pdt=new Date(CL_ryr1,CL_rmon1,CL_rday1)
    var CL_mdt=new Date(CL_ryr,CL_rmon,CL_rday)
    
   //frm =document.cl_tool;
    
    if(cl_tool.CL_rdy1.selectedIndex==0)
    {
        alert('Choose a Day' );
        cl_tool.CL_rdy1.focus();
        return false;
    }
    else if(cl_tool.CL_rmon1.selectedIndex==0)
    {
        alert('Choose a Month' );
        cl_tool.CL_rmon1.focus();
        return false ;
    }
    else if(cl_tool.CL_rdy.selectedIndex==0)
    {
        alert('Choose a Day' );
        cl_tool.CL_rdy.focus();
        return  false;
    }
    else if(cl_tool.CL_rmon.selectedIndex==0)
    {
        alert('Choose a Month' );
        cl_tool.CL_rmon.focus();
        return false ;
    }
    else if(CL_pdt-CL_mdt>0)
    {
        alert('Purchase Date should be before Maturity Date');
        cl_tool.CL_ryr.focus();
        return  false;
    }
    else
    {
        CL_display('result');
    }
    
    var CL_timediff=(CL_mdt-CL_pdt)/365/24/60/60/1000;
    var CL_pergain=(CL_fvb-CL_price)/CL_price;
    var CL_anngain=Math.pow((1+CL_pergain),(1/CL_timediff))-1;
    CL_anngain=Math.round(CL_anngain*10000)/100;
    
    if (document.layers)
    {
        document.layers['result'].borrow.yld.value=CL_anngain
    }
    else
    {
        borrow.yld.value=CL_anngain
    }
}
/* Implied Bond Yield */


/* FD Calculator */
function getfdMatVal()
{
   fdMatValForm = document.forms[0];
    var principalVal = fdMatValForm.principal.value;
    
    if(isNaN(principalVal) || (parseFloat(principalVal) <= 0)){
		alert("Principal value invalid!!!");
		fdMatValForm.principal.focus();
		return(false);
	}
	
	var interestVal  = fdMatValForm.interest.value;
	if(isNaN(interestVal) || (parseFloat(interestVal) <= 0) || (parseFloat(interestVal) > 100) ){
		alert("Rate of Interest value invalid!!!");
		fdMatValForm.interest.focus();
		return(false);
	}
	
	var tenureVal  =   fdMatValForm.tenure.value;
    if(isNaN(tenureVal) || (parseFloat(tenureVal) <= 0)){
        alert("Tenure value invalid!!!");
        fdMatValForm.tenure.focus();
        return(false);
    }

    var tenurePeriodVal = getSelectedValue(fdMatValForm.tenurePeriod);
    if(isNaN(tenurePeriodVal)){
        alert("Tenure Period value invalid!!!");
        fdMatValForm.tenurePeriod.focus();
        return(false);
    }
    
    var frequencyVal = getSelectedValue(fdMatValForm.frequency);
    if(isNaN(frequencyVal)){
        alert("Frequency value invalid!!!");
        fdMatValForm.frequency.focus();
        return(false);
    }
    
    //Get computable values
    principalVal = parseFloat(principalVal);
    interestVal  = parseFloat(interestVal);
    tenureVal  =   parseFloat(tenureVal);
    tenurePeriodVal = parseFloat(tenurePeriodVal);
    frequencyVal = parseFloat(frequencyVal);


    var retStr  =
		calMatVal(principalVal, interestVal, tenureVal, tenurePeriodVal, frequencyVal)

    fdMatValForm.fdMatValResult.value = retStr;

    return(false);
}

function getSelectedValue(formElement) {
    var pointer = formElement.selectedIndex;
    var selectedValue = formElement.options[pointer].value;

	return (selectedValue);
}

function calMatVal(principalVal, interestVal, tenureVal, tenurePeriodVal, frequencyVal)
{
    var fdMatVal=0;
    var retStr="";
    
    //If Simple interest
    if(frequencyVal == 0){
        fdMatVal =
            principalVal * (1 + ((interestVal * tenureVal) / (tenurePeriodVal*100)));

        //retStr = retStr + "Simple Interest = " +fdMatVal;

    }//if simple interest ends
    else {
        //Cal Compound interest
            var val1 = 1 + interestVal/(100 * frequencyVal);
            var val2 = tenureVal * frequencyVal / tenurePeriodVal;
            var val3 = 0;

            val3 = Math.pow(val1, val2);
            fdMatVal = principalVal * val3;

            //retStr = retStr + "Compund Interest = " +fdMatVal;
    }//if compound interest ends

    retStr = retStr + Math.round(fdMatVal);
    return(retStr);
}
/* FD Calculator */


/* PPF Withdrawal */

var chkdt_gl_flag ="TRUE";
var gl_flag       ="TRUE";//flag for checkdate()
var gl_flagi	  ="TRUE";//flag for checkdate1()
var chkdate ;

function chkday()
{
    var withdrawalcal = document.forms[0];
    var d = withdrawalcal.day.options[withdrawalcal.day.selectedIndex].value;
    var m = withdrawalcal.mon.options[withdrawalcal.mon.selectedIndex].value;
    var y = withdrawalcal.year.value;
   	var mnd;
   	
   	if (parseInt(d) < 10)
   	{
        d = "0" + d;
    }
    if(parseInt(m) < 10)
    {
        m = "0" + m;
    }
    var concdate = m +"/"+ d +"/"+  y;
	if (m == "None")
    {
        withdrawalcal.mon.focus();
        return false;
    }
    if ((m == 4 || m == 6 || m == 9 || m == 11) && d == 31)
    {
	    if (m== 4) {mnd="April"}
	    if (m== 6) {mnd="June" }
	    if (m==9) {mnd="September"}
	    if (m==11) {mnd="November"}
	    window.alert("Month " + mnd +" doesn't have 31 days!")
        withdrawalcal.withdate.value="";
	    withdrawalcal.year.value="";
        withdrawalcal.year.focus();
        return false;
    }
    if (m == 2)
    { // check for february 29th
        var isleap = (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));
        if (d > 29 || (d == 29 && !isleap))
        {
            window.alert("February " + y + " doesn't have " + d + " days!");
            withdrawalcal.withdate.value="";
            withdrawalcal.day.focus();
            return false;
        }
    }
    if (isNaN(y))
    {
        window.alert("Year can only be numeric");
        withdrawalcal.year.value="";
        withdrawalcal.year.focus();
        return false;
    }
    if (y == "0")
    {
        window.alert("Year cannot be Zero");
        withdrawalcal.year.value="";
        withdrawalcal.year.focus();
        return false;
    }
    if (y == "")
    {
        withdrawalcal.year.value="";
        withdrawalcal.year.focus();
        return false;
    }
    valid(y, m, d);
}

//This function calculates the valid PPF withdrawal dates
function valid(y, m, d)
{
    if(m > 3)
	{
		year = parseInt(y) + 6;
		newDate = "01" + "-Apr-" + year;
		withdrawalcal.withdate.value = newDate;
	}
	else
	{
		year = parseInt(y) + 5;
		newDate = "01" + "-Apr-" + year;
		withdrawalcal.withdate.value = newDate;
	}
    chkdate = "04/01/"+year;
}

function ckmonth()
{
    var withdrawalcal = document.forms[0];
    var d = withdrawalcal.day.options[withdrawalcal.day.selectedIndex].value;
    var m = withdrawalcal.mon.options[withdrawalcal.mon.selectedIndex].value;
    var y = withdrawalcal.year.value;
    var mnm;
    
    if (parseInt(d) < 10)
    {
        d = "0" + d;
    }
    if(parseInt(m) < 10)
    {
        m = "0" + m;
    }
    var concdate = m +"/"+ d +"/"+  y;
    
    if (m == 2)
    { // check for february 29th
        var isleap = (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));
        if (d > 29 || (d == 29 && !isleap))
        {
            window.alert("February " + y + " doesn't have " + d + " days!");
            withdrawalcal.withdate.value="";
            withdrawalcal.mon.focus();
		    return false;
        }
    }
    if (m == "None")
    {
        window.alert("Month needs to have a value");
   	    withdrawalcal.mon.focus();
	    return false;
    }
    if (y == "")
    {
	    withdrawalcal.year.focus();
	    return false;
    }
    if ((m == 4 || m == 6 || m == 9 || m == 11) && d == 31)
    {
   	    if (m==4) {mnm="April"}
	    if (m==6) {mnm="June"}
	    if (m==9) {mnm="September"}
	    if (m==11) {mnm="November"}
	    window.alert("Month "+ mnm +" doesn't have 31 days!")
        withdrawalcal.withdate.value="";
	    withdrawalcal.mon.focus();
	    return false;
    }
    if (m == 2)
    { // check for february 29th
        var isleap = (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));
        if (d > 29 || (d == 29 && !isleap))
        {
            window.alert("February " + y + " doesn't have " + d + " days!");
            withdrawalcal.withdate.value="";
		    return false;
        }
    }
    if (isNaN(y))
    {
        window.alert("Year can only be numeric");
        withdrawalcal.year.focus();
	    return false;
    }
    if(y <  1980 || y > 2050)
    {
        window.alert( "The date should be after 1980 and before 2050");
        withdrawalcal.year.focus();
        withdrawalcal.year.select();
        gl_flag="FALSE";
        return false;
    }
    if(m > 3)
    {
        year = parseInt(y) + 6;
    }
    else
    {
        year = parseInt(y) + 5;
    }
    newDate = "01" + "-Apr-" + year;
    withdrawalcal.withdate.value = newDate;
}

//validations for the first date entered using the drop down boxes
function checkdate()
{
    var withdrawalcal = document.forms[0];
    var d = withdrawalcal.day.options[withdrawalcal.day.selectedIndex].value;
	var m = withdrawalcal.mon.options[withdrawalcal.mon.selectedIndex].value;
	var y = withdrawalcal.year.value;
	
	if (parseInt(d) < 10)
	{
	    d = "0" + d;
	}
	if(parseInt(m) < 10)
	{
	    m = "0" + m;
	}
	var concdate = m +"/"+ d +"/"+  y;
	
	if(y <  1980 || y > 2050)
    {
        window.alert( "The date should be after 1980 and before 2050");
   		withdrawalcal.year.value="";
        withdrawalcal.year.focus();
        return false;
    }

    date3 = new Date(concdate)
    
    if (m == "None")
	{
	    window.alert("Month needs to have a value");
	    withdrawalcal.mon.focus();
	    return false;
	}
	if (isNaN(y))
	{
	    window.alert("Year can only be numeric");
	    withdrawalcal.year.value="";
	    withdrawalcal.year.focus();
	    return false;
	}
	if (y == "0")
	{
	    window.alert("Year cannot be Zero");
	    withdrawalcal.year.value="";
	    withdrawalcal.year.focus();
	    return false;
	}
	if (y == "")
	{
	    window.alert("Year cannot be left blank");
	    withdrawalcal.year.value="";
	    withdrawalcal.year.focus();
	    return false;
	}
	if ((m == 4 || m == 6 || m == 9 || m == 11) && d == 31)
	{
	    window.alert("Month "+ m +" doesn't have 31 days!")
        withdrawalcal.year.value="";
	    withdrawalcal.year.focus();
	    return false;
	}
	if (m == 2)
	{ // check for february 29th
        var isleap = (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));
		if (d > 29 || (d == 29 && !isleap))
		{
		    window.alert("February " + y + " doesn't have " + d + " days!");
		    return false;
		}
    }
    valid(y, m, d);
}

function chkday1()
{
    var withdrawalcal = document.forms[0]; 
    var d =withdrawalcal.day.options[withdrawalcal.day.selectedIndex].value;
    var m =withdrawalcal.mon.options[withdrawalcal.mon.selectedIndex].value;
    var y =withdrawalcal.year.value;
	var mnd1;
	
	if (parseInt(d) < 10)
	{
        d = "0" + d;
    }
    if(parseInt(m) < 10)
    {
        m = "0" + m ;
    }
    var concdate = m +"/"+ d +"/"+  y;

    var d1 = withdrawalcal.day1.options[withdrawalcal.day1.selectedIndex].value;
    var m1 = withdrawalcal.mon1.options[withdrawalcal.mon1.selectedIndex].value;
    var y1 = withdrawalcal.year1.value;
    
    if (parseInt(d1) < 10)
    {
        d1 = "0" + d1;
    }
    if(parseInt(m1) < 10)
    {
        m1 = "0" + m1 ;
    }
    var conc1 = m1 +"/"+ d1 +"/" + y1;
    var dt2 = dateDiff(conc1,chkdate);
    
    if(m1=="None")
    {
        withdrawalcal.mon1.focus();
        return false;
    }
    if(dt2 <= 0)
    {
	    alert("Date needs to be after  " + withdrawalcal.withdate.value);
        withdrawalcal.startdate.value="";
        withdrawalcal.balstart.value="";
        withdrawalcal.enddate.value="";
        withdrawalcal.endbal.value="";
        withdrawalcal.year1.focus();
        return false;
    }
    if ((m1 == 4 || m1 == 6 || m1 == 9 || m1 == 11) && d1 == 31)
    {
   		if (m1==4) {mnd1="April"}
		if (m1==6) {mnd1="June"}
		if (m1==9) {mnd1="September"}
		if (m1==11) {mnd1="November"}
		window.alert("Month "+ mnd1 +" doesn't have 31 days!")
        withdrawalcal.startdate.value="";
        withdrawalcal.balstart.value="";
        withdrawalcal.enddate.value="";
        withdrawalcal.endbal.value="";
        withdrawalcal.mon1.focus();
        return false;
    }
    if (m1 == 2)
    { // check for february 29th
        var isleap = (y1 % 4 == 0 && (y1 % 100 != 0 || y1 % 400 == 0));
        if (d1 > 29 || (d1 == 29 && !isleap))
        {
            window.alert("February " + y1 + " doesn't have " + d1 + " days!");
            withdrawalcal.startdate.value="";
            withdrawalcal.balstart.value="";
            withdrawalcal.enddate.value="";
            withdrawalcal.endbal.value="";
            withdrawalcal.mon1.focus();
            return false;
        }
    }
    chkval(y1,m1,d1);
}

function chkval(y1,m1,d1)
{
    var withdrawalcal = document.forms[0];
    if (isNaN(y1))
    {
        window.alert("Year can only be numeric");
        withdrawalcal.year1.focus();
		return false;
    }
    if (y1 == "")
    {
		withdrawalcal.year1.focus();
        return false;
    }
    if(m1 > 3)
    {
        year1 = parseInt(y1);
        newDate2 = "31" + "-Mar-" + year1;
        withdrawalcal.startdate.value = newDate2;
    }
    else if(m1==1 || m1==2)
    {
        year1 = parseInt(y1) - 1;
        newDate2 = "31" + "-Mar-" + year1;
        withdrawalcal.startdate.value = newDate2;
    }
    newdate3 = withdrawalcal.startdate.value;
    newdate4 = newdate3.substring(6);
    newdate5 = parseInt(newdate4) + 3;
    newdate6 = "31" + "-Mar-" + newdate5;
    withdrawalcal.enddate.value = newdate6;
}

function valid1(y1, m1, d1)
{
    var withdrawalcal = document.forms[0];
    if(m1 > 3)
	{
		year1 = parseInt(y1);
		newDate2 = "31" + "-Mar-" + year1;
		withdrawalcal.startdate.value = newDate2;
	}
	else if(m1==1 || m1 ==2 || m1==3)
	{
		year1 = parseInt(y1) - 1;
		newDate2 = "31" + "-Mar-" + year1;
		withdrawalcal.startdate.value = newDate2;
	}
	newdate3 = withdrawalcal.startdate.value;
    newdate4 = newdate3.substring(6);
	newdate5 = parseInt(newdate4) + 3;
	newdate6 = "31" + "-Mar-" + newdate5;
	withdrawalcal.enddate.value = newdate6;
}

function chkmth()
{
    var withdrawalcal = document.forms[0];
    var d = withdrawalcal.day.options[withdrawalcal.day.selectedIndex].value;
    var m = withdrawalcal.mon.options[withdrawalcal.mon.selectedIndex].value;
	var y = withdrawalcal.year.value;
	
	if (parseInt(d) < 10)
	{
	    d = "0" + d;
	}
	if(parseInt(m) < 10)
	{
		m = "0" + m ;
	}
	
	var concdate = m +"/"+ d +"/"+  y;
	
	var d1 = withdrawalcal.day1.options[withdrawalcal.day1.selectedIndex].value;
	var m1 = withdrawalcal.mon1.options[withdrawalcal.mon1.selectedIndex].value;
	var y1 = withdrawalcal.year1.value;
	var mnm1;
	
    if (parseInt(d1) < 10)
    {
        d1 = "0" + d1;
    }
    if(parseInt(m1) < 10)
    {
        m1 = "0" + m1 ;
    }
    var conc1 = m1 +"/"+ d1 +"/" + y1;
    var dt2 = dateDiff(conc1,chkdate);
    
    if(m1=="None")
    {
        window.alert("Please enter the month");
        withdrawalcal.mon1.focus();
        return false;
    }
    if(dt2 <= 0)
    {
        alert("Date needs to be after  " + withdrawalcal.withdate.value);
        withdrawalcal.startdate.value="";
		withdrawalcal.balstart.value="";
		withdrawalcal.enddate.value="";
		withdrawalcal.endbal.value="";
		withdrawalcal.year1.focus();
        return false;
    }
    if ((m1 == 4 || m1 == 6 || m1 == 9 || m1 == 11) && d1 == 31)
    {
        if (m1==4) {mnm1="April"}
	    if (m1==6) {mnm1="June"}
	    if (m1==9) {mnm1="September"}
	    if (m1==4) {mnm1="November"}
	    window.alert("Month "+ mnm1 +" doesn't have 31 days!")
	    withdrawalcal.startdate.value="";
        withdrawalcal.balstart.value="";
		withdrawalcal.enddate.value="";
    	withdrawalcal.endbal.value="";
		withdrawalcal.mon1.focus();
		return false;
    }
    if (m1 == 2)
    {// check for february 29th
        var isleap = (y1 % 4 == 0 && (y1 % 100 != 0 || y1 % 400 == 0));
        if (d1 > 29 || (d1 == 29 && !isleap))
        {
            window.alert("February " + y1 + " doesn't have " + d1 + " days!");
            withdrawalcal.startdate.value="";
            withdrawalcal.balstart.value="";
		    withdrawalcal.enddate.value="";
		    withdrawalcal.endbal.value="";
		    withdrawalcal.mon1.focus();
		    return false;
        }
    }
    chkval(y1,m1,d1);
}

//function to calculate the amount eligible to be withdrawn
function withamt()
{
    var withdrawalcal = document.forms[0];
    var d = withdrawalcal.day.options[withdrawalcal.day.selectedIndex].value;
	var m = withdrawalcal.mon.options[withdrawalcal.mon.selectedIndex].value;
	var y = withdrawalcal.year.value;

    var d1 = withdrawalcal.day1.options[withdrawalcal.day1.selectedIndex].value;
    var m1 =         withdrawalcal.mon1.options[withdrawalcal.mon1.selectedIndex].value;
    var y1 = withdrawalcal.year1.value;
    
    //ALERTS
    if(withdrawalcal.day.options[withdrawalcal.day.selectedIndex].value==0)
    {
        alert("Date Field cannot be empty");
        withdrawalcal.day.focus();
        return false;
    }
    if(withdrawalcal.mon.options[withdrawalcal.mon.selectedIndex].value=="None")
    {
        alert("Please enter the Month Field for opening your PPF Account");
        withdrawalcal.mon.focus();
        return false;
    }
	balstart1 = withdrawalcal.balstart.value;
    endbal1 = withdrawalcal.endbal.value;
    
    if(y == "" &&( balstart1 == "" || endbal1 == ""))
   	{
   	    window.alert("Please enter the date of opening your PPF Account");
   	    withdrawalcal.year.focus();
  	    return false;
   	}
   	if(withdrawalcal.day1.options[withdrawalcal.day1.selectedIndex].value==0)
    {
        alert("Date Field cannot be empty");
        withdrawalcal.day1.focus();
        return false;
    }
    if(withdrawalcal.mon1.options[withdrawalcal.mon1.selectedIndex].value=="None")
    {
        alert("Please enter the Month of withdrawal");
        withdrawalcal.mon1.focus();
        return false;
    }
    if(endbal1==""&&isNaN(balstart1))
    {
        alert("Please enter a positive numerical value and do not leave any field blank") ;
        withdrawalcal.balstart.value = "";
        withdrawalcal.balstart.focus();
        return false;
    }
    if(balstart1==""&&isNaN(endbal1))
    {
        alert("Please enter a positive numerical value and do not leave any field blank") ;
        withdrawalcal.balstart.value="";
        withdrawalcal.balstart.focus();
        return false;
    }
    if(y1==""&&(balstart1 == "" || endbal1 == ""))
    {
        window.alert("Please enter the date of withdrawal");
        withdrawalcal.year1.focus();
        return false;
    }
    if(balstart1 == "" )
    {
        window.alert("Please enter PPF balance amount");
        withdrawalcal.balstart.focus();
        return false;
    }
    if(endbal1 == "")
    {
        window.alert("Please enter PPF balance amount");
        withdrawalcal.endbal.focus();
        return false;
    }
    if(isNaN(balstart1) || balstart1<="0")
    {
        window.alert("PPF Amount can only be positive and numeric");
        withdrawalcal.balstart.value="";
		withdrawalcal.balstart.focus();
        return false;
    }
	if(isNaN(endbal1) || endbal1<="0")
    {
        window.alert("PPF Amount can only be positive and numeric");
        withdrawalcal.endbal.value="";
		withdrawalcal.endbal.focus();
        return false;
    }
    
    m1 = parseInt(m1);
    var monVal = "";
    
    switch(m1)
    {
        case 1:
            monVal = "Jan";
            break;
        case 2:
            monVal = "Feb";
            break;
        case 3:
            monVal = "Mar";
            break;
        case 4:
            monVal = "Apr";
            break;
       case 5:
            monVal = "May";
            break;
        case 6:
            monVal = "Jun";
            break;
        case 7:
            monVal = "Jul";
            break;
        case 8:
            monVal = "Aug";
            break;
        case 9:
            monVal = "Sep";
            break;
        case 10:
            monVal = "Oct";
            break;
        case 11:
            monVal = "Nov";
            break;
        case 12:
            monVal = "Dec";
            break
        default:
    }
    
    var conc1 = d1 +"-"+ monVal +"-" + y1;

    //balstart1 = document.withdrawalcal.balstart.value;
	//endbal1 = document.withdrawalcal.endbal.value;
	
	if( balstart1 > endbal1)
	{
	    newamt = endbal1 * 0.5;
	    withdrawalcal.amount.value = newamt;    
	    dtwith1 = conc1;
	    withdrawalcal.dtwith.value = dtwith1;
	}
	else
	{
	    newamt = balstart1 * 0.5;
	    withdrawalcal.amount.value = newamt;
	    dtwith2 = conc1;
	    withdrawalcal.dtwith.value = dtwith2;
	}
}

function dateDiff(dob,dob1)
{
    date1 = new Date(dob);
    date2 = new Date(dob1);
    diff  = new Date();
    diff.setTime((date1.getTime() - date2.getTime()));
    
    timediff = diff.getTime();
    
    weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
    timediff -= weeks * (1000 * 60 * 60 * 24 * 7);
    
    days = Math.floor(timediff / (1000 * 60 * 60 * 24));
    timediff -= days * (1000 * 60 * 60 * 24);

    hours = Math.floor(timediff / (1000 * 60 * 60));
    timediff -= hours * (1000 * 60 * 60);

    mins = Math.floor(timediff / (1000 * 60));
    timediff -= mins * (1000 * 60);

    secs = Math.floor(timediff / 1000);
    timediff -= secs * 1000;

    difference = (weeks*7 + days)/365
    
    return difference; // form should never submit, returns false
}

function checkdate1()
{
    var withdrawalcal = document.forms[0];
    var d = withdrawalcal.day.options[withdrawalcal.day.selectedIndex].value;
	var m = withdrawalcal.mon.options[withdrawalcal.mon.selectedIndex].value;
	var y = withdrawalcal.year.value;

	if (parseInt(d) < 10)
	{
	    d = "0" + d;
	}
	if(parseInt(m) < 10)
	{
	    m = "0" + m ;
	}
	var concdate = m +"/"+ d +"/"+  y;
	
	var d1 = withdrawalcal.day1.options[withdrawalcal.day1.selectedIndex].value;
	var m1 = withdrawalcal.mon1.options[withdrawalcal.mon1.selectedIndex].value;
	var y1 = withdrawalcal.year1.value;

    if (parseInt(d1) < 10)
    {
        d1 = "0" + d1;
    }
    if(parseInt(m1) < 10)
    {
        m1 = "0" + m1 ;
    }
    var conc1 = m1 +"/"+ d1 +"/" + y1;
    var dt2 = dateDiff(conc1,chkdate);
    
    if(m1=="None")
    {
        window.alert("Please enter the month");
        withdrawalcal.mon1.focus();
        return false;
    }

    if(dt2 <=0)
    {
        alert("Date needs to be after  " + withdrawalcal.withdate.value);
        withdrawalcal.startdate.value="";
		withdrawalcal.balstart.value="";
		withdrawalcal.enddate.value="";
    	withdrawalcal.endbal.value="";
		withdrawalcal.year1.value="";
		withdrawalcal.year1.focus();
        return false;
    }
   
    //calculation for date validation
	x = dateDiff(conc1,concdate);

	if (isNaN(y1))
	{
	    window.alert("Year can only be numeric");
        withdrawalcal.year1.focus();
	    return false;
	}
	if (y1 == "0")
    {
        window.alert("Year cannot be Zero");
   	    withdrawalcal.year1.focus();
	    return false;
    }
	if (y1 == "")
	{
	    window.alert("Year cannot be left blank");
	    withdrawalcal.year1.focus();
	    return false;
	}
	if ((m1 == 4 || m1 == 6 || m1 == 9 || m1 == 11) && d1 == 31)
	{
	    window.alert("Month "+ m1 +" doesn't have 31 days!")
	    withdrawalcal.startdate.value="";
        withdrawalcal.balstart.value="";
        withdrawalcal.enddate.value="";
	    withdrawalcal.endbal.value="";
	    withdrawalcal.mon1.focus();
	    return false;
	}
	if (m1 == 2)
	{ // check for february 29th
	    var isleap = (y1 % 4 == 0 && (y1 % 100 != 0 || y1 % 400 == 0));
		if (d1 > 29 || (d1 == 29 && !isleap))
		    window.alert("February " + y1 + " doesn't have " + d1 + " days!");
		withdrawalcal.startdate.value="";
        withdrawalcal.balstart.value="";
		withdrawalcal.enddate.value="";
    	withdrawalcal.endbal.value="";
		withdrawalcal.mon1.focus();
		return false;
	}
	if (x <= 0.0)
	{
		window.alert("The date should be after account opening date");
		withdrawalcal.year1.focus();
		gl_flagi = "FALSE";
		valid1(y1, m1, d1);
		return false;
	}
	else
	{
        if(x >= 16.0)
        {
            chkdt_gl_flag = "FALSE";
            withdrawalcal.submit();
            return false;
        }
        //on clicking of 1 href
	}
    valid1(y1, m1, d1);
}
/* PPF Withdrawal */


/* PPF Maturity */
function checkamt(list)
{
    var len1=list.value.length;
    var str1=list.value;
    
    for(var i=0;i<len1;i++)
    {
        if(str1.charAt(i)=="0")
        {
            eval(mystr);
        }
        else
        {
            break;
        }
    }
}

//Check month for 2000
function checkmonth()
{
    var ppffrm = document.forms[0];
    if(ppffrm.years.options[ppffrm.years.selectedIndex].value== 2001)
    {
        if((ppffrm.months.options[ppffrm.months.selectedIndex].value)==1 ||(ppffrm.months.options[ppffrm.months.selectedIndex].value)==2 ||(ppffrm.months.options[ppffrm.months.selectedIndex].value)==3)
        {
		    alert("The amount need to be deposited after March 31, 2001");
			ppffrm.months.focus();
		}
    }
}

function cal()
{
   var ppffrm = document.forms[0];
    if (!nullvalue(ppffrm.text1) || isNaN(ppffrm.text1.value))
    {
        alert("Please enter the amount you intend to deposit every year");
        ppffrm.text1.focus();
        return false;
    }
    if (parseInt(ppffrm.text1.value)>60000)
    {
        alert("Amount deposited should not exceed Rs. 60,000");
        ppffrm.text1.focus();
        return false;
    }
    if (ppffrm.text1.value < 100)
    {
        alert("Amount deposited should not be less than Rs.100");
        ppffrm.text1.focus();
        return false;
    }
    if(((ppffrm.text1.value)%5)!=0)
    {
        alert("Amount deposited should be in the multiples of Rs. 5");
        ppffrm.text1.focus();
        return false;
    }
    else
    {
        varText1 = ppffrm.text1.value;
        ls_mon      = ppffrm.months.selectedIndex;
        ls_mon_val  = ppffrm.months.options[ls_mon].value;
        ls_day      = ppffrm.days.selectedIndex;
        ls_day_val  = ppffrm.days.options[ls_day].value;
        ls_year      =ppffrm.years.selectedIndex;
        ls_year_val  = ppffrm.years.options[ls_year].value;
        dat =  ls_day_val+"-"+ls_mon_val+"-"+ls_year_val;
        ppffrm.f_hid_date.value = dat;
        
        if(chk_date(ls_day_val,ls_mon_val,ls_year_val)==true)
        {
//            document.getElementById("tdFinTools").innerHTML="<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td align=center><img src='../images/loading1.gif'></td></tr></table>";  
//            document.getElementById("tdFinTools").src="../FinancialTools/";
//            strURL="../FinancialTools/frmSimpleCalc1.aspx";
//            strURL = "frmSimpleCalc1.aspx?text1="+varText1+"&days="+ls_day_val+"&months="+ls_mon_val+"&years="+ls_year_val;
//            alert(strURL);
//            var ajax = new Ajax.Updater('tdFinTools',strURL,{evalScripts: true});
	        //ppffrm.method="post"
	        //ppffrm.action = 'SimpleCalc1.aspx';
	       // ppffrm.action = 'SimpleCalcTest.aspx';
	        //ppffrm.submit();
	        window.location= "SimpleCalc1.aspx?text1="+varText1+"&days="+ls_day_val+"&months="+ls_mon_val+"&years="+ls_year_val;
	        //document.open = "SimpleCalc1.aspx?text1="+varText1+"&days="+ls_day_val+"&months="+ls_mon_val+"&years="+ls_year_val;
        }
        else
        {
            ppffrm.months.focus();
            return false;
        }
    }
}

function openwindow1()
{
    var valid=("012345678");
     var ppffrm = document.forms[0];
      varText1 = ppffrm.text1.value;
    if (!nullvalue(ppffrm.text1)|| isNaN(ppffrm.text1.value))
    {
        alert("Please enter the amount you intend to deposit")
        ppffrm.text1.focus();
        return false;
    }
    else
    {
        var string=ppffrm.text1.value;
        var length=string.length;
        
        for (var i=0;  i<=length; i++)
        {
            var substring=string.substr(i,1);
        }
    }
    if (parseInt(ppffrm.text1.value)>60000)
    {
        alert("Amount deposited should not exceed Rs. 60,000");
        ppffrm.text1.focus();
        return false;
    }
    if (ppffrm.text1.value <= 0)
    {
        alert("Please enter the amount you intend to deposit every year");
        ppffrm.text1.focus();
        return false;
    }
    if (ppffrm.text1.value < 100)
    {
        alert("Amount deposited should not be less than Rs.100");
        ppffrm.text1.focus();
        return false;
    }
    if(((ppffrm.text1.value)%5)!=0)
    {
        alert("Amount deposited should be in the multiples of Rs. 5");
        ppffrm.text1.focus();
        return false;
    }
    else
    {
        ls_mon      = ppffrm.months.selectedIndex;
        ls_mon_val  = ppffrm.months.options[ls_mon].value;
        
        ls_day      = ppffrm.days.selectedIndex;
        ls_day_val  = ppffrm.days.options[ls_day].value;

        ls_year      = ppffrm.years.selectedIndex;
        ls_year_val  = ppffrm.years.options[ls_year].value;
        
        dat =  ls_day_val+"-"+ls_mon_val+"-"+ls_year_val;
        ppffrm.f_hid_date.value = dat;
        
        if(chk_date(ls_day_val,ls_mon_val,ls_year_val)==true)
        {
	        //document.ppffrm.method= "post"
	        //document.ppffrm.action = 'PPFChange.aspx';
	        //document.ppffrm.submit();
	        window.location = "PPFChange.aspx?text1="+varText1+"&days="+ls_day_val+"&months="+ls_mon_val+"&years="+ls_year_val;
        }
        else
        {
            ppffrm.months.focus();
            return false;
        }
    }
}

function date()
{
    currentDate =  Date();
    var theCurMonth=currentDate.getMonth();
    var theCurDay=currentDate.getDay();
    var theCurYear = currentDate.getYear();
    
    if (theLength==4)
    {
        var theYear = theInput.substring(2,4);
        if (theYear < theCurYear)
        {
            alert("please enter current year")
        }
        else
        {
            var theMonth=theInput.substring(0,1);
            if (theMonth < theCurMonth)
            {
                alert("please enter current date");
            }
            else
            {
                var theDay= theInput.substring(0,1);
                if (theDay < theCurDay)
                {
                    alert("please enter current day");
                }
            }
        }
    }
}

function nullvalue(nv)
{
    var lencalc=0;
    for(i=0 ;i<nv.value.length ; i++)
    {
        if(nv.value.charAt(i)==" ")
        {
            lencalc=parseInt(lencalc)+1;
        }
    }
    if (lencalc==nv.value.length)
    {
        //alert("Field should not be empty");
        nv.focus();
        return false;
    }
    else
    {
        return true;
    }
}

//------------------------check date
function chk_date(day,month,year)
{
    if (year % 400 == 0)
        yeararray = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
    
    else
    {
	    if ((year %4 == 0) && (year % 100 != 0))
		    yeararray = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
		else
		    yeararray = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	}
	validmonth=parseInt(month,10);
	totaldays=yeararray[validmonth-1];
	
	if (day <= totaldays)
    {
        return true;
		myval1=0;
	}
	else
	{
	    alert("Date is invalid. Please correct.");
		return false;
    }
}

//Function to check whether entered value is numeric.
function validatenumber()
{
    var list = document.forms[0];
    checkamtMat(document.form1.cont[list-1],list-1);
    
    var check;
    if (!nullvalue(document.form1.cont[list-1]))
    {
        alert("You can't leave this field blank.");
        document.form1.cont[list-1].focus();
    }
    else if (isNaN(document.form1.cont[list-1].value))
    {
        alert("Please enter numeric value.");
        document.form1.cont[(list-1)].value="";
        document.form1.cont[(list-1)].focus();
        return false;
    }
    else if((document.form1.cont[list-1].value)>60000)
    {
        alert("Amount should not exceed 60,000");
        document.form1.cont[list-1].value="";
        document.form1.cont[list-1].focus();
    }
    else if((document.form1.cont[list-1].value)<100)
    {
        alert("Amount deposited should not be less than Rs. 100");
        document.form1.cont[list-1].value="";
        document.form1.cont[list-1].focus();
    }
    else if(((document.form1.cont[list-1].value)%5)!=0)
    {
        alert("Amount deposited should be in the multiples of Rs. 5");
        document.form1.cont[list-1].value="";
        document.form1.cont[list-1].focus();
    }
    else
    {
        checkamount(list);
        return true;
    }
}

function checkamtMat(list10,indlist)
{
    var len1=list10.value.length;
    var str1=list10.value;
    
    for(var zi=0;zi<len1;zi++)
	{
		if(str1.charAt(zi)=="0")
		{
			mystr="document.ppffrm."+ list10.name +"[" + indlist+ "]" + ".value=str1.substr(1+zi)";
			eval(mystr);
		}
		else
		{
			break;
		}
	}
}

//Function to check the entered amount.
function checkamount(list)
{
    var name;
    for(var i=list;i<16;i++)
    {
        document.form1.cont[i].value= document.form1.cont[(list-1)].value;
    }
}
//End of amount check function.

function raj1(list,day,year)
{
    var count1 = list.name;
	var count3 = parseInt(list.options[list.selectedIndex].value-1);
	var count2 = parseInt(count1.substring(count1.indexOf("h")+1));
	var month=list.options[list.selectedIndex].value;
	
	if( month>3)
	{
		if(chk_date(day,list.options[list.selectedIndex].value,year)==false)
        {
			var path = "document.form1." + list.name +  ".focus();";
			eval(path);

			return false;
		}
	}
	else
	{
        if(chk_date(day,list.options[list.selectedIndex].value,(parseInt(year)+1))==false)
		{
			var path = "document.form1." + list.name +  ".focus();";
			eval(path);
			return false;
		}
	}
	if((list.options[list.selectedIndex].value==29 && month==2)==false)
	{
	    if (count2==1)
	    {
		    document.form1.month2.selectedIndex=count3;
		    document.form1.month3.selectedIndex=count3;
		    document.form1.month4.selectedIndex=count3;
		    document.form1.month5.selectedIndex=count3;
		    document.form1.month6.selectedIndex=count3;
		    document.form1.month7.selectedIndex=count3;
		    document.form1.month8.selectedIndex=count3;
		    document.form1.month9.selectedIndex=count3;
		    document.form1.month10.selectedIndex=count3;
		    document.form1.month11.selectedIndex=count3;
		    document.form1.month12.selectedIndex=count3;
		    document.form1.month13.selectedIndex=count3;
		    document.form1.month14.selectedIndex=count3;
		    document.form1.month15.selectedIndex=count3;
		    document.form1.month16.selectedIndex=count3;
	    }
	    if (count2==2)
	    {
		    document.form1.month3.selectedIndex=count3;
		    document.form1.month4.selectedIndex=count3;
		    document.form1.month5.selectedIndex=count3;
		    document.form1.month6.selectedIndex=count3;
		    document.form1.month7.selectedIndex=count3;
		    document.form1.month8.selectedIndex=count3;
		    document.form1.month9.selectedIndex=count3;
		    document.form1.month10.selectedIndex=count3;
		    document.form1.month11.selectedIndex=count3;
		    document.form1.month12.selectedIndex=count3;
		    document.form1.month13.selectedIndex=count3;
		    document.form1.month14.selectedIndex=count3;
		    document.form1.month15.selectedIndex=count3;
		    document.form1.month16.selectedIndex=count3;
	    }
	    if (count2==3)
	    {
		    document.form1.month4.selectedIndex=count3;
		    document.form1.month5.selectedIndex=count3;
		    document.form1.month6.selectedIndex=count3;
		    document.form1.month7.selectedIndex=count3;
		    document.form1.month8.selectedIndex=count3;
		    document.form1.month9.selectedIndex=count3;
		    document.form1.month10.selectedIndex=count3;
		    document.form1.month11.selectedIndex=count3;
		    document.form1.month12.selectedIndex=count3;
		    document.form1.month13.selectedIndex=count3;
		    document.form1.month14.selectedIndex=count3;
		    document.form1.month15.selectedIndex=count3;
		    document.form1.month16.selectedIndex=count3;
	    }
	    if (count2==4)
	    {
		    document.form1.month5.selectedIndex=count3;
		    document.form1.month6.selectedIndex=count3;
		    document.form1.month7.selectedIndex=count3;
		    document.form1.month8.selectedIndex=count3;
		    document.form1.month9.selectedIndex=count3;
		    document.form1.month10.selectedIndex=count3;
		    document.form1.month11.selectedIndex=count3;
		    document.form1.month12.selectedIndex=count3;
		    document.form1.month13.selectedIndex=count3;
		    document.form1.month14.selectedIndex=count3;
		    document.form1.month15.selectedIndex=count3;
		    document.form1.month16.selectedIndex=count3;
	    }
	    if (count2==5)
	    {
		    document.form1.month6.selectedIndex=count3;
		    document.form1.month7.selectedIndex=count3;
		    document.form1.month8.selectedIndex=count3;
		    document.form1.month9.selectedIndex=count3;
		    document.form1.month10.selectedIndex=count3;
		    document.form1.month11.selectedIndex=count3;
		    document.form1.month12.selectedIndex=count3;
		    document.form1.month13.selectedIndex=count3;
		    document.form1.month14.selectedIndex=count3;
		    document.form1.month15.selectedIndex=count3;
		    document.form1.month16.selectedIndex=count3;
	    }
	    if (count2==6)
	    {
		    document.form1.month7.selectedIndex=count3;
		    document.form1.month8.selectedIndex=count3;
		    document.form1.month9.selectedIndex=count3;
		    document.form1.month10.selectedIndex=count3;
		    document.form1.month11.selectedIndex=count3;
		    document.form1.month12.selectedIndex=count3;
		    document.form1.month13.selectedIndex=count3;
		    document.form1.month14.selectedIndex=count3;
		    document.form1.month15.selectedIndex=count3;
		    document.form1.month16.selectedIndex=count3;
	    }
	    if (count2==7)
	    {
		    document.form1.month8.selectedIndex=count3;
		    document.form1.month9.selectedIndex=count3;
		    document.form1.month10.selectedIndex=count3;
		    document.form1.month11.selectedIndex=count3;
		    document.form1.month12.selectedIndex=count3;
		    document.form1.month13.selectedIndex=count3;
		    document.form1.month14.selectedIndex=count3;
		    document.form1.month15.selectedIndex=count3;
		    document.form1.month16.selectedIndex=count3;
	    }
	    if (count2==8)
	    {
		    document.form1.month9.selectedIndex=count3;
		    document.form1.month10.selectedIndex=count3;
		    document.form1.month11.selectedIndex=count3;
		    document.form1.month12.selectedIndex=count3;
		    document.form1.month13.selectedIndex=count3;
		    document.form1.month14.selectedIndex=count3;
		    document.form1.month15.selectedIndex=count3;
		    document.form1.month16.selectedIndex=count3;
	    }
	    if (count2==9)
	    {
		    document.form1.month10.selectedIndex=count3;
		    document.form1.month11.selectedIndex=count3;
		    document.form1.month12.selectedIndex=count3;
		    document.form1.month13.selectedIndex=count3;
		    document.form1.month14.selectedIndex=count3;
		    document.form1.month15.selectedIndex=count3;
		    document.form1.month16.selectedIndex=count3;
	    }
	    if (count2==10)
	    {
		    document.form1.month11.selectedIndex=count3;
		    document.form1.month12.selectedIndex=count3;
		    document.form1.month13.selectedIndex=count3;
		    document.form1.month14.selectedIndex=count3;
		    document.form1.month15.selectedIndex=count3;
		    document.form1.month16.selectedIndex=count3;
	    }
	    if (count2==11)
	    {
		    document.form1.month12.selectedIndex=count3;
		    document.form1.month13.selectedIndex=count3;
		    document.form1.month14.selectedIndex=count3;
		    document.form1.month15.selectedIndex=count3;
		    document.form1.month16.selectedIndex=count3;
	    }
	    if (count2==12)
	    {
		    document.form1.month13.selectedIndex=count3;
		    document.form1.month14.selectedIndex=count3;
		    document.form1.month15.selectedIndex=count3;
		    document.form1.month16.selectedIndex=count3;
	    }
	    if (count2==13)
	    {
		    document.form1.month14.selectedIndex=count3;
		    document.form1.month15.selectedIndex=count3;
		    document.form1.month16.selectedIndex=count3;
	    }
	    if (count2==14)
	    {
		    document.form1.month15.selectedIndex=count3;
		    document.form1.month16.selectedIndex=count3;
	    }
	    if (count2==15)
	    {
		    document.form1.month16.selectedIndex=count3;
	    }
	}
	else
	{alert("else");
	    if (count2==1)
	    {
	        document.form1.day2.selectedIndex=31;
		    document.form1.day3.selectedIndex=31;
		    document.form1.day4.selectedIndex=31;
		    document.form1.day5.selectedIndex=31;
		    document.form1.day6.selectedIndex=31;
		    document.form1.day7.selectedIndex=31;
		    document.form1.day8.selectedIndex=31;
		    document.form1.day9.selectedIndex=31;
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month2.selectedIndex=3;
		    document.form1.month3.selectedIndex=3;
		    document.form1.month4.selectedIndex=3;
		    document.form1.month5.selectedIndex=3;
		    document.form1.month6.selectedIndex=3;
		    document.form1.month7.selectedIndex=3;
		    document.form1.month8.selectedIndex=3;
		    document.form1.month9.selectedIndex=3;
		    document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
        }
	    if (count2==2)
	    {
		    document.form1.day3.selectedIndex=31;
		    document.form1.day4.selectedIndex=31;
		    document.form1.day5.selectedIndex=31;
		    document.form1.day6.selectedIndex=31;
		    document.form1.day7.selectedIndex=31;
		    document.form1.day8.selectedIndex=31;
		    document.form1.day9.selectedIndex=31;
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month3.selectedIndex=3;
		    document.form1.month4.selectedIndex=3;
		    document.form1.month5.selectedIndex=3;
		    document.form1.month6.selectedIndex=3;
		    document.form1.month7.selectedIndex=3;
		    document.form1.month8.selectedIndex=3;
		    document.form1.month9.selectedIndex=3;
		    document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
        }
	    if (count2==3)
	    {
		    document.form1.day4.selectedIndex=31;
		    document.form1.day5.selectedIndex=31;
		    document.form1.day6.selectedIndex=31;
		    document.form1.day7.selectedIndex=31;
		    document.form1.day8.selectedIndex=31;
		    document.form1.day9.selectedIndex=31;
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month4.selectedIndex=3;
		    document.form1.month5.selectedIndex=3;
		    document.form1.month6.selectedIndex=3;
		    document.form1.month7.selectedIndex=3;
		    document.form1.month8.selectedIndex=3;
		    document.form1.month9.selectedIndex=3;
		    document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
        }
	    if (count2==4)
	    {
		    document.form1.day5.selectedIndex=31;
		    document.form1.day6.selectedIndex=31;
		    document.form1.day7.selectedIndex=31;
		    document.form1.day8.selectedIndex=31;
		    document.form1.day9.selectedIndex=31;
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month5.selectedIndex=3;
		    document.form1.month6.selectedIndex=3;
		    document.form1.month7.selectedIndex=3;
		    document.form1.month8.selectedIndex=3;
		    document.form1.month9.selectedIndex=3;
            document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
        }
	    if (count2==5)
	    {
		    document.form1.day6.selectedIndex=31;
		    document.form1.day7.selectedIndex=31;
		    document.form1.day8.selectedIndex=31;
		    document.form1.day9.selectedIndex=31;
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month6.selectedIndex=3;
		    document.form1.month7.selectedIndex=3;
		    document.form1.month8.selectedIndex=3;
		    document.form1.month9.selectedIndex=3;
		    document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
        }
	    if (count2==6)
	    {
		    document.form1.day7.selectedIndex=31;
		    document.form1.day8.selectedIndex=31;
		    document.form1.day9.selectedIndex=31;
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month7.selectedIndex=3;
		    document.form1.month8.selectedIndex=3;
		    document.form1.month9.selectedIndex=3;
		    document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
        }
	    if (count2==7)
	    {
		    document.form1.day8.selectedIndex=31;
		    document.form1.day9.selectedIndex=31;
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month8.selectedIndex=3;
		    document.form1.month9.selectedIndex=3;
		    document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
        }
	    if (count2==8)
	    {
		    document.form1.day9.selectedIndex=31;
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month9.selectedIndex=3;
		    document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
        }
	    if (count2==9)
	    {
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
            document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
        }
	    if (count2==10)
	    {
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
        }
	    if (count2==11)
	    {
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month12.selectedIndex=3;
            document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
        }
	    if (count2==12)
	    {
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
        }
	    if (count2==13)
	    {
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
        }
	    if (count2==14)
	    {
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
        }
	    if (count2==15)
	    {
		    document.form1.day16.selectedIndex=31;
		    document.form1.month16.selectedIndex=3;
        }
    }
}

function raj2(list,month,year)
{
    var count1 = list.name;
	var count3 = list.options[list.selectedIndex].value-1;
	var count2 = parseInt(count1.substring(count1.indexOf("y")+1));
	
	if( month>3)
	{
        if(chk_date(list.options[list.selectedIndex].value,month,year)==false)
		{
			var path = "document.form1." + list.name +  ".focus();";
			eval(path);

			return false;
		}
	}
	else
	{
	    if(chk_date(list.options[list.selectedIndex].value,month,(parseInt(year)+1))==false)
		{
			var path = "document.form1." + list.name +  ".focus();";
			eval(path);
			return false;
		}
	}
	if((list.options[list.selectedIndex].value==29 && month==2)==false)
	{
	    if (count2==1)
	    {
		    document.form1.day2.selectedIndex=count3;
		    document.form1.day3.selectedIndex=count3;
		    document.form1.day4.selectedIndex=count3;
		    document.form1.day5.selectedIndex=count3;
		    document.form1.day6.selectedIndex=count3;
		    document.form1.day7.selectedIndex=count3;
		    document.form1.day8.selectedIndex=count3;
		    document.form1.day9.selectedIndex=count3;
		    document.form1.day10.selectedIndex=count3;
		    document.form1.day11.selectedIndex=count3;
		    document.form1.day12.selectedIndex=count3;
		    document.form1.day13.selectedIndex=count3;
		    document.form1.day14.selectedIndex=count3;
		    document.form1.day15.selectedIndex=count3;
		    document.form1.day16.selectedIndex=count3;
	    }
	    if (count2==2)
	    {
		    document.form1.day3.selectedIndex=count3;
		    document.form1.day4.selectedIndex=count3;
		    document.form1.day5.selectedIndex=count3;
		    document.form1.day6.selectedIndex=count3;
		    document.form1.day7.selectedIndex=count3;
		    document.form1.day8.selectedIndex=count3;
		    document.form1.day9.selectedIndex=count3;
		    document.form1.day10.selectedIndex=count3;
		    document.form1.day11.selectedIndex=count3;
		    document.form1.day12.selectedIndex=count3;
		    document.form1.day13.selectedIndex=count3;
		    document.form1.day14.selectedIndex=count3;
		    document.form1.day15.selectedIndex=count3;
		    document.form1.day16.selectedIndex=count3;
	    }
	    if (count2==3)
	    {
		    document.form1.day4.selectedIndex=count3;
		    document.form1.day5.selectedIndex=count3;
		    document.form1.day6.selectedIndex=count3;
		    document.form1.day7.selectedIndex=count3;
		    document.form1.day8.selectedIndex=count3;
		    document.form1.day9.selectedIndex=count3;
		    document.form1.day10.selectedIndex=count3;
		    document.form1.day11.selectedIndex=count3;
		    document.form1.day12.selectedIndex=count3;
		    document.form1.day13.selectedIndex=count3;
		    document.form1.day14.selectedIndex=count3;
		    document.form1.day15.selectedIndex=count3;
		    document.form1.day16.selectedIndex=count3;
	    }
	    if (count2==4)
	    {
		    document.form1.day5.selectedIndex=count3;
		    document.form1.day6.selectedIndex=count3;
		    document.form1.day7.selectedIndex=count3;
		    document.form1.day8.selectedIndex=count3;
		    document.form1.day9.selectedIndex=count3;
		    document.form1.day10.selectedIndex=count3;
		    document.form1.day11.selectedIndex=count3;
		    document.form1.day12.selectedIndex=count3;
		    document.form1.day13.selectedIndex=count3;
		    document.form1.day14.selectedIndex=count3;
		    document.form1.day15.selectedIndex=count3;
		    document.form1.day16.selectedIndex=count3;
	    }
	    if (count2==5)
	    {
		    document.form1.day6.selectedIndex=count3;
		    document.form1.day7.selectedIndex=count3;
		    document.form1.day8.selectedIndex=count3;
		    document.form1.day9.selectedIndex=count3;
		    document.form1.day10.selectedIndex=count3;
		    document.form1.day11.selectedIndex=count3;
		    document.form1.day12.selectedIndex=count3;
		    document.form1.day13.selectedIndex=count3;
		    document.form1.day14.selectedIndex=count3;
		    document.form1.day15.selectedIndex=count3;
		    document.form1.day16.selectedIndex=count3;
	    }
	    if (count2==6)
	    {
		    document.form1.day7.selectedIndex=count3;
		    document.form1.day8.selectedIndex=count3;
		    document.form1.day9.selectedIndex=count3;
		    document.form1.day10.selectedIndex=count3;
		    document.form1.day11.selectedIndex=count3;
		    document.form1.day12.selectedIndex=count3;
		    document.form1.day13.selectedIndex=count3;
		    document.form1.day14.selectedIndex=count3;
		    document.form1.day15.selectedIndex=count3;
		    document.form1.day16.selectedIndex=count3;
	    }
	    if (count2==7)
	    {
		    document.form1.day8.selectedIndex=count3;
		    document.form1.day9.selectedIndex=count3;
		    document.form1.day10.selectedIndex=count3;
		    document.form1.day11.selectedIndex=count3;
		    document.form1.day12.selectedIndex=count3;
		    document.form1.day13.selectedIndex=count3;
		    document.form1.day14.selectedIndex=count3;
		    document.form1.day15.selectedIndex=count3;
		    document.form1.day16.selectedIndex=count3;
	    }
	    if (count2==8)
	    {
		    document.form1.day9.selectedIndex=count3;
		    document.form1.day10.selectedIndex=count3;
		    document.form1.day11.selectedIndex=count3;
		    document.form1.day12.selectedIndex=count3;
		    document.form1.day13.selectedIndex=count3;
		    document.form1.day14.selectedIndex=count3;
		    document.form1.day15.selectedIndex=count3;
		    document.form1.day16.selectedIndex=count3;
	    }
	    if (count2==9)
	    {
		    document.form1.day10.selectedIndex=count3;
		    document.form1.day11.selectedIndex=count3;
		    document.form1.day12.selectedIndex=count3;
		    document.form1.day13.selectedIndex=count3;
		    document.form1.day14.selectedIndex=count3;
		    document.form1.day15.selectedIndex=count3;
		    document.form1.day16.selectedIndex=count3;
	    }
	    if (count2==10)
	    {
		    document.form1.day11.selectedIndex=count3;
		    document.form1.day12.selectedIndex=count3;
		    document.form1.day13.selectedIndex=count3;
		    document.form1.day14.selectedIndex=count3;
		    document.form1.day15.selectedIndex=count3;
		    document.form1.day16.selectedIndex=count3;
	    }
	    if (count2==11)
	    {
		    document.form1.day12.selectedIndex=count3;
		    document.form1.day13.selectedIndex=count3;
		    document.form1.day14.selectedIndex=count3;
		    document.form1.day15.selectedIndex=count3;
		    document.form1.day16.selectedIndex=count3;
	    }
	    if (count2==12)
	    {
		    document.form1.day13.selectedIndex=count3;
		    document.form1.day14.selectedIndex=count3;
		    document.form1.day15.selectedIndex=count3;
		    document.form1.day16.selectedIndex=count3;
	    }
	    if (count2==13)
	    {
		    document.form1.day14.selectedIndex=count3;
		    document.form1.day15.selectedIndex=count3;
		    document.form1.day16.selectedIndex=count3;
	    }
	    if (count2==14)
	    {
		    document.form1.day15.selectedIndex=count3;
		    document.form1.day16.selectedIndex=count3;
	    }
	    if (count2==15)
	    {
		    document.form1.day16.selectedIndex=count3;
	    }
	}
	else
	{
	    if (count2==1)
	    {
	        document.form1.day2.selectedIndex=31;
		    document.form1.day3.selectedIndex=31;
		    document.form1.day4.selectedIndex=31;
		    document.form1.day5.selectedIndex=31;
		    document.form1.day6.selectedIndex=31;
		    document.form1.day7.selectedIndex=31;
		    document.form1.day8.selectedIndex=31;
		    document.form1.day9.selectedIndex=31;
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month2.selectedIndex=3;
		    document.form1.month3.selectedIndex=3;
		    document.form1.month4.selectedIndex=3;
		    document.form1.month5.selectedIndex=3;
		    document.form1.month6.selectedIndex=3;
		    document.form1.month7.selectedIndex=3;
		    document.form1.month8.selectedIndex=3;
		    document.form1.month9.selectedIndex=3;
		    document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
	    }
	    if (count2==2)
	    {
		    document.form1.day3.selectedIndex=31;
		    document.form1.day4.selectedIndex=31;
		    document.form1.day5.selectedIndex=31;
		    document.form1.day6.selectedIndex=31;
		    document.form1.day7.selectedIndex=31;
		    document.form1.day8.selectedIndex=31;
		    document.form1.day9.selectedIndex=31;
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month3.selectedIndex=3;
		    document.form1.month4.selectedIndex=3;
		    document.form1.month5.selectedIndex=3;
		    document.form1.month6.selectedIndex=3;
		    document.form1.month7.selectedIndex=3;
		    document.form1.month8.selectedIndex=3;
		    document.form1.month9.selectedIndex=3;
		    document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
	    }
	    if (count2==3)
	    {
		    document.form1.day4.selectedIndex=31;
		    document.form1.day5.selectedIndex=31;
		    document.form1.day6.selectedIndex=31;
		    document.form1.day7.selectedIndex=31;
		    document.form1.day8.selectedIndex=31;
		    document.form1.day9.selectedIndex=31;
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month4.selectedIndex=3;
		    document.form1.month5.selectedIndex=3;
		    document.form1.month6.selectedIndex=3;
		    document.form1.month7.selectedIndex=3;
		    document.form1.month8.selectedIndex=3;
		    document.form1.month9.selectedIndex=3;
		    document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
	    }
	    if (count2==4)
	    {
		    document.form1.day5.selectedIndex=31;
		    document.form1.day6.selectedIndex=31;
		    document.form1.day7.selectedIndex=31;
		    document.form1.day8.selectedIndex=31;
		    document.form1.day9.selectedIndex=31;
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month5.selectedIndex=3;
		    document.form1.month6.selectedIndex=3;
		    document.form1.month7.selectedIndex=3;
		    document.form1.month8.selectedIndex=3;
		    document.form1.month9.selectedIndex=3;
		    document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
	    }
	    if (count2==5)
	    {
		    document.form1.day6.selectedIndex=31;
		    document.form1.day7.selectedIndex=31;
		    document.form1.day8.selectedIndex=31;
		    document.form1.day9.selectedIndex=31;
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month6.selectedIndex=3;
		    document.form1.month7.selectedIndex=3;
		    document.form1.month8.selectedIndex=3;
		    document.form1.month9.selectedIndex=3;
		    document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
	    }
	    if (count2==6)
	    {
		    document.form1.day7.selectedIndex=31;
		    document.form1.day8.selectedIndex=31;
		    document.form1.day9.selectedIndex=31;
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month7.selectedIndex=3;
		    document.form1.month8.selectedIndex=3;
		    document.form1.month9.selectedIndex=3;
		    document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
	    }
	    if (count2==7)
	    {
		    document.form1.day8.selectedIndex=31;
		    document.form1.day9.selectedIndex=31;
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month8.selectedIndex=3;
		    document.form1.month9.selectedIndex=3;
		    document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
	    }
	    if (count2==8)
	    {
		    document.form1.day9.selectedIndex=31;
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month9.selectedIndex=3;
		    document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
	    }
	    if (count2==9)
	    {
		    document.form1.day10.selectedIndex=31;
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month10.selectedIndex=3;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
	    }
	    if (count2==10)
	    {
		    document.form1.day11.selectedIndex=31;
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month11.selectedIndex=3;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
	    }
	    if (count2==11)
	    {
		    document.form1.day12.selectedIndex=31;
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month12.selectedIndex=3;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
	    }
	    if (count2==12)
	    {
		    document.form1.day13.selectedIndex=31;
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month13.selectedIndex=3;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
	    }
	    if (count2==13)
	    {
		    document.form1.day14.selectedIndex=31;
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month14.selectedIndex=3;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
	    }
	    if (count2==14)
	    {
		    document.form1.day15.selectedIndex=31;
		    document.form1.day16.selectedIndex=31;
		    document.form1.month15.selectedIndex=3;
		    document.form1.month16.selectedIndex=3;
	    }
	    if (count2==15)
	    {
		    document.form1.day16.selectedIndex=31;
		    document.form1.month16.selectedIndex=3;
	    }
	}
}

function calMat()
{
    var z;
    for(z=0;z<16;z++)
    { 
        var valid=("0123456789");
        if (!nullvalue(document.forms[0].cont[z]))
        {
            alert("Please enter amount")
            document.forms[0].cont[z].focus();
            return false;
        }
        else
        {
            var string=document.forms[0].cont[z].value;
            var length=string.length;
            for (var i=0; i<=length; i++)
            {
                var substring=string.substr(i,1);
                if (valid.indexOf(substring)==-1)
                {
                    alert("Please enter amount");
                    document.forms[0].cont[z].focus();
                    return false;
                }
            }
        }
        if (parseInt(document.forms[0].cont[z].value)  > 60000)
        {
            alert("Amount should be less than or equal to 60000");
            document.forms[0].cont[z].focus();
            return false;
        }
    }
    var pyears = parseInt(2007); 
    if(document.forms[0].month1.value<3)
    {
        if(chk_date(document.forms[0].day1.options[document.forms[0].day1.selectedIndex].value,document.forms[0].month1.options[document.forms[0].month1.selectedIndex].value,pyears)==false)
		{
			document.forms[0].day1.focus();
			return false;
	    }
    }
    else
	{
	    pyears = parseInt(2006); 
        if(chk_date(document.forms[0].day1.options[document.forms[0].day1.selectedIndex].value,document.forms[0].month1.options[document.forms[0].month1.selectedIndex].value,pyears)==false)
        {
		    document.forms[0].day1.focus();
			return false;
        }
    }
    if(document.forms[0].month2.value<3)
    {
	    pyears = parseInt(2008); 
        if(chk_date(document.forms[0].day2.options[document.forms[0].day2.selectedIndex].value,document.forms[0].month2.options[document.forms[0].month2.selectedIndex].value,pyears)==false)
		{
			document.forms[0].day2.focus();
			return false;
		}
	}
	else
    {
	    pyears = parseInt(2007); 
        if(chk_date(document.forms[0].day2.options[document.forms[0].day2.selectedIndex].value,document.forms[0].month2.options[document.forms[0].month2.selectedIndex].value,pyears)==false)
        {
		    document.forms[0].day2.focus();
			return false;
        }
    }
    if(document.forms[0].month3.value<3)
    {
        pyears = parseInt(2009); 
        if(chk_date(document.forms[0].day3.options[document.forms[0].day3.selectedIndex].value,document.forms[0].month3.options[document.forms[0].month3.selectedIndex].value,pyears)==false)
		{
			document.forms[0].day3.focus();
			return false;
		}
    }
    else
    {
	    pyears = parseInt(2008); 
        if(chk_date(document.forms[0].day3.options[document.forms[0].day3.selectedIndex].value,document.forms[0].month3.options[document.forms[0].month3.selectedIndex].value,pyears)==false)
	    {
		    document.forms[0].day3.focus();
			return false;
        }
    }
    if(document.forms[0].month4.value<3)
    {
	    pyears = parseInt(2010); 
        if(chk_date(document.forms[0].day4.options[document.forms[0].day4.selectedIndex].value,document.forms[0].month4.options[document.forms[0].month4.selectedIndex].value,pyears)==false)
		{
			document.forms[0].day4.focus();
			return false;
		}
	}
	else
    {
	    pyears = parseInt(2009); 
        if(chk_date(document.forms[0].day4.options[document.forms[0].day4.selectedIndex].value,document.forms[0].month4.options[document.forms[0].month4.selectedIndex].value,pyears)==false)
	    {
		    document.forms[0].day4.focus();
			return false;
        }
    }
    if(document.forms[0].month5.value<3)
    {
	    pyears = parseInt(2011); 
        if(chk_date(document.forms[0].day5.options[document.forms[0].day5.selectedIndex].value,document.forms[0].month5.options[document.forms[0].month5.selectedIndex].value,pyears)==false)
		{
			document.forms[0].day5.focus();
			return false;
		}
	}
    else
	{
	    pyears = parseInt(2011); 
        if(chk_date(document.forms[0].day5.options[document.forms[0].day5.selectedIndex].value,document.forms[0].month5.options[document.forms[0].month5.selectedIndex].value,pyears)==false)
        {
		    document.forms[0].day5.focus();
			return false;
        }
    }
    if(document.forms[0].month6.value<3)
    {
	    pyears = parseInt(2012); 
	    if(chk_date(document.forms[0].day6.options[document.forms[0].day6.selectedIndex].value,document.forms[0].month6.options[document.forms[0].month6.selectedIndex].value,pyears)==false)
		{
			document.forms[0].day6.focus();
			return false;
		}
	}
    else
	{
  	    pyears = parseInt(2011); 
        if(chk_date(document.forms[0].day6.options[document.forms[0].day6.selectedIndex].value,document.forms[0].month6.options[document.forms[0].month6.selectedIndex].value,pyears)==false)
        {
		    document.forms[0].day6.focus();
			return false;
        }
    }
    if(document.forms[0].month7.value<3)
    {
		pyears = parseInt(2013); 
		if(chk_date(document.forms[0].day7.options[document.forms[0].day7.selectedIndex].value,document.forms[0].month7.options[document.forms[0].month7.selectedIndex].value,pyears)==false)
		{
			document.forms[0].day7.focus();
			return false;
		}
	}
	else
	{
	    pyears = parseInt(2012); 
        if(chk_date(document.forms[0].day7.options[document.forms[0].day7.selectedIndex].value,document.forms[0].month7.options[document.forms[0].month7.selectedIndex].value,pyears)==false)
        {
		    document.forms[0].day7.focus();
			return false;
        }
    }
    if(document.forms[0].month8.value<3)
    {
	    pyears = parseInt(2014); 
	    if(chk_date(document.forms[0].day8.options[document.forms[0].day8.selectedIndex].value,document.forms[0].month8.options[document.forms[0].month8.selectedIndex].value,pyears)==false)
		{
			document.forms[0].day8.focus();
			return false;
		}
	}
    else
	{
  	    pyears = parseInt(2013); 
        if(chk_date(document.forms[0].day8.options[document.forms[0].day8.selectedIndex].value,document.forms[0].month8.options[document.forms[0].month8.selectedIndex].value,pyears)==false)
        {
		    document.forms[0].day8.focus();
			return false;
	   }
    }
    if(document.forms[0].month9.value<3)
    {
	    pyears = parseInt(2015); 
        if(chk_date(document.forms[0].day9.options[document.forms[0].day9.selectedIndex].value,document.forms[0].month9.options[document.forms[0].month9.selectedIndex].value,pyears)==false)
        {
			document.forms[0].day9.focus();
			return false;
		}
	}
	else
    {
 	    pyears = parseInt(2014); 
        if(chk_date(document.forms[0].day9.options[document.forms[0].day9.selectedIndex].value,document.forms[0].month9.options[document.forms[0].month9.selectedIndex].value,pyears)==false)
        {
		    document.forms[0].day9.focus();
			return false;
	    }
    }
    if(document.forms[0].month10.value<3)
    {
	    pyears = parseInt(2016); 
        if(chk_date(document.forms[0].day10.options[document.forms[0].day10.selectedIndex].value,document.forms[0].month10.options[document.forms[0].month10.selectedIndex].value,pyears)==false)
        {
			document.forms[0].day10.focus();
			return false;
		}
	}
	else
	{
	    pyears = parseInt(2015); 
        if(chk_date(document.forms[0].day10.options[document.forms[0].day10.selectedIndex].value,document.forms[0].month10.options[document.forms[0].month10.selectedIndex].value,pyears)==false)
        {
		    document.forms[0].day10.focus();
			return false;
        }
    }
    if(document.forms[0].month11.value<3)
    {
	    pyears = parseInt(2017); 
        if(chk_date(document.forms[0].day11.options[document.forms[0].day11.selectedIndex].value,document.forms[0].month11.options[document.forms[0].month11.selectedIndex].value,pyears)==false)
        {
			document.forms[0].day11.focus();
			return false;
		}
	}
    else
	{
  	    pyears = parseInt(2016); 
	    if(chk_date(document.forms[0].day11.options[document.forms[0].day11.selectedIndex].value,document.forms[0].month11.options[document.forms[0].month11.selectedIndex].value,pyears)==false)
        {
		    document.forms[0].day11.focus();
			return false;
	    }
    } 
    if(document.forms[0].month12.value<3)
    {
  	    pyears = parseInt(2018); 
		if(chk_date(document.forms[0].day12.options[document.forms[0].day12.selectedIndex].value,document.forms[0].month12.options[document.forms[0].month12.selectedIndex].value,pyears)==false)
		{
			document.forms[0].day12.focus();
			return false;
		}
	}
	else
    {
 	    pyears = parseInt(2017); 
        if(chk_date(document.forms[0].day12.options[document.forms[0].day12.selectedIndex].value,document.forms[0].month12.options[document.forms[0].month12.selectedIndex].value,pyears)==false)
        {
		    document.forms[0].day12.focus();
			return false;
        }
    }
    if(document.forms[0].month13.value<3)
    {
  	    pyears = parseInt(2019); 
		if(chk_date(document.forms[0].day13.options[document.forms[0].day13.selectedIndex].value,document.forms[0].month13.options[document.forms[0].month13.selectedIndex].value,pyears)==false)
		{
			document.forms[0].day13.focus();
			return false;
		}
	}
	else
    {
  	    pyears = parseInt(2018); 
	    if(chk_date(document.forms[0].day13.options[document.forms[0].day13.selectedIndex].value,document.forms[0].month13.options[document.forms[0].month13.selectedIndex].value,pyears)==false)
	    {
		    document.forms[0].day13.focus();
			return false;
	   }
    }
    if(document.forms[0].month14.value<3)
    {
  	    pyears = parseInt(2020); 
	    if(chk_date(document.forms[0].day14.options[document.forms[0].day14.selectedIndex].value,document.forms[0].month14.options[document.forms[0].month14.selectedIndex].value,pyears)==false)
		{
			document.forms[0].day14.focus();
			return false;
		}
	}
	else
    {
  	    pyears = parseInt(2019); 
	    if(chk_date(document.forms[0].day14.options[document.forms[0].day14.selectedIndex].value,document.forms[0].month14.options[document.forms[0].month14.selectedIndex].value,pyears)==false)
	    {
		    document.forms[0].day14.focus();
			return false;
        }
    }
    if(document.forms[0].month15.value<3)
    {
  	    pyears = parseInt(2021); 
		if(chk_date(document.forms[0].day15.options[document.forms[0].day15.selectedIndex].value,document.forms[0].month15.options[document.forms[0].month15.selectedIndex].value,pyears)==false)
		{
			document.forms[0].day15.focus();
			return false;
		}
	}
    else
	{
  	    pyears = parseInt(2020); 
	    if(chk_date(document.forms[0].day15.options[document.forms[0].day15.selectedIndex].value,document.forms[0].month15.options[document.forms[0].month15.selectedIndex].value,pyears)==false)
	    {
		    document.forms[0].day15.focus();
			return false;
	    }
    }
    if(document.forms[0].month16.value<3)
    {
 	    pyears = parseInt(2022); 
		if(chk_date(document.forms[0].day16.options[document.forms[0].day16.selectedIndex].value,document.forms[0].month16.options[document.forms[0].month16.selectedIndex].value,pyears)==false)
		{
			document.form1.day16.focus();
			return false;
		}
	}
	else
	{
        pyears = parseInt(2021); 
        if(chk_date(document.forms[0].day16.options[document.forms[0].day16.selectedIndex].value,document.forms[0].month16.options[document.forms[0].month16.selectedIndex].value,pyears)==false)
	    {
		    document.forms[0].day16.focus();
			return false;
	    }
    }

    //document.form1.method="post";
	//document.form1.action = 'frmPPFAdvCalc.aspx'
	//document.form1.submit();
	window.location = "PPFAdvCalc.aspx?month1="+document.forms[0].month1.value+"&month2="+document.forms[0].month2.value+"&month3="+document.forms[0].month3.value+"&month4="+document.forms[0].month4.value+"&month5="+document.forms[0].month5.value+"&month6="+document.forms[0].month6.value+"&month7="+document.forms[0].month7.value+"&month8="+document.forms[0].month8.value+"&month9="+document.forms[0].month9.value+"&month10="+document.forms[0].month10.value+"&month11="+document.forms[0].month11.value+"&month12="+document.forms[0].month12.value+"&month13="+document.forms[0].month13.value+"&month14="+document.forms[0].month14.value+"&month15="+document.forms[0].month15.value+"&month16="+document.forms[0].month16.value+"&day1="+document.forms[0].day1.value+"&day2="+document.forms[0].day2.value+"&day3="+document.forms[0].day3.value+"&day4="+document.forms[0].day4.value+"&day5="+document.forms[0].day5.value+"&day6="+document.forms[0].day6.value+"&day7="+document.forms[0].day7.value+"&day8="+document.forms[0].day8.value+"&day9="+document.forms[0].day9.value+"&day10="+document.forms[0].day10.value+"&day11="+document.forms[0].day11.value+"&day12="+document.forms[0].day12.value+"&day13="+document.forms[0].day13.value+"&day14="+document.forms[0].day14.value+"&day15="+document.forms[0].day15.value+"&day16="+document.forms[0].day16.value;
   // return true;
}

/* PPF Maturity */

/* Auto EMI Calculator */
function validateEMI()
{
   frm = document.forms[0];
    if(!frm.p.value||frm.p.value<=0)
	{
	    alert("Loan Amount should be greater than 0");
	    frm.p.focus();
	    return false;
	}
	else if(!frm.i.value||frm.i.value<=0)
	{
	    alert("Rate of Interest should be greater than 0");
	    frm.i.focus();
	    return false;
	}
	else if(frm.i.value>100)
	{
	    alert("Rate of Interest should be less than 100");
	    frm.i.focus();
	    return false;
	}
	else if(!frm.tenure.value||parseFloat(frm.tenure.value)<=0)
	{
	    alert("Repayment period should be greater than 0");
	    frm.tenure.focus();
	    return false;
	}
	else if(!frm.adv.value||parseFloat(frm.adv.value)<0||10<parseFloat(frm.adv.value))
	{
	    alert("Advance EMIs should be between 0 and 10");
	    frm.adv.focus();
	    return false;
	}
	else if(!frm.dep.value||parseFloat(frm.dep.value)<0)
	{
	    alert("Deposit (%) should be greater than or equal to 0");
	    frm.dep.focus();
	    return false;
	}
	else if(parseFloat(frm.dep.value)>100)
	{
	    alert("Deposit (%) should be less than or equal to 100");
	    frm.dep.focus();
	    return false;
	}
	else if(!frm.idep.value||parseFloat(frm.idep.value)<0)
	{
	    alert("Interest on deposit should be greater than or equal to 0");
	    frm.idep.focus();
	    return false;
	}
	else if(parseFloat(frm.idep.value)>100)
	{
	    alert("Interest on deposit should be less than or equal to 100");
	    frm.idep.focus();
	    return false;
	}
	else
	{
        calculateEMI(); 
        show();
	}
}

function calculateEMI()
{
    var breakup = document.forms[0];
    var p=parseFloat(breakup.p.value);
	if(!p) p=0;
	var i=parseFloat(breakup.i.value)/100;
	if(!i) i=0;
	var tenure=parseFloat(breakup.tenure.value);
	if(!tenure) tenure=0;
	var timetype=breakup.timetype.options[breakup.timetype.options.selectedIndex].value;
	var reset=parseFloat(breakup.reset.options[breakup.reset.options.selectedIndex].value);
	var adv=parseFloat(breakup.adv.value);
	if(!adv) adv=0;
	var dep=parseFloat(breakup.dep.value)/100;
	if(!dep) dep=0;
	var idep=parseFloat(breakup.idep.value)/100;
	if(!idep) idep=0;
	var comp=parseFloat(breakup.comp.options[breakup.comp.options.selectedIndex].value);
	if(!comp) comp=0;
	if (timetype=='yr') tenure=tenure*12;
	var k=1/(1+i*reset/12)
	var x=tenure/reset;
	var fvsc=0;
	
	if(dep && !isNaN(dep))
    {
	    if(comp<=-1)
		{		
		    fvsc=dep*p*(1+tenure/12*idep);
		}
		else 
		{
		    fvsc=dep*p*Math.pow(1+comp*idep/12,tenure/comp)
		}
		fvsc=fvsc*Math.pow(k,x);
    }
    var amt=p+fvsc-dep*p;
	x=(tenure-adv)/reset;
	var gp=(Math.pow(k,x)-1)/(k-1)*k
	gp+=adv/reset;
	var emi=amt/gp/reset;
	breakup.emi.value=Math.round(emi);
}
/* Auto EMI Calculator */

/* Flat Rate Cost */
function validateFIRR()
{
    var tools = document.forms[0];
    if(!tools.tenure.value||parseFloat(tools.tenure.value)<=0)
	{
	    alert('Tenure should be greater than 0');
	    tools.tenure.focus();
	    return false;
	}
	if(!tools.interest.value||parseFloat(tools.interest.value)<0)
	{
	    alert('Interest should be greater than or equal to 0');
	    tools.tenure.focus();
	    return false;
	}
	if(parseFloat(tools.interest.value)>100)
	{
	    alert('Interest should be less than or equal to 100');
	    tools.interest.focus();
	    return false;
	}
	if(!tools.charge.value||parseFloat(tools.charge.value)<0)
	{
	    alert('Charges should be greater than or equal to 0');
	    tools.charge.focus();
	    return false;
	}
	if(parseFloat(tools.charge.value)>100)
	{
	    alert('Charges should be less than or equal to 100');
	    tools.charge.focus();
	    return false;
	}
	return true;
}

function calculateFIRR()
{
    var tools = document.forms[0];
    var amount=100000;
    var tenure =tools.tenure.value*12;
    var interest=tools.interest.value/100;
    var charge=parseFloat(tools.charge.value/100);
    var amount=100000
    var pay=amount*(1+tenure/12*interest);
    var strt=(pay-amount)/amount/tenure;
    var emi =pay/tenure;
    amount=100000*(1-charge)
    var r=1/(1+strt);
    var res= emi*((Math.pow(r,tenure)-1)/(r-1))*r-amount;
    
    if(res>0)
    {
        do 
        {
            strt=strt+0.00001;
            r=1/(1+strt);
            res=emi*((Math.pow(r,tenure)-1)/(r-1))*r-amount;
        } while( res > 0 )
    }
    else
    {
        alert('Please check the input numbers');
    }
    
    var eirr1=(Math.pow(1+strt,12)-1)*10000;
    var eirr=((strt)*12)*10000;
    eirr=Math.round(eirr);
    eirr1=Math.round(eirr1);
    eirr/=100;
    eirr1/=100;
    tools.emi.value=eirr;
    tools.irr.value=eirr1;
}
/* Flat Rate Cost */

/* Housing Loan - EMI Calculator */
function calculateHEMI()
{
var breakup = document.forms[0];
    var pamount = parseInt(breakup.pamount.value);
	var intrate = parseFloat(breakup.intrate.value,2);
	var tenure = parseInt(breakup.tenure.value);
	
	if (isNaN(parseInt(pamount)))
	{
		alert("Please enter a valid Principal Amount !");
		breakup.pamount.focus();
		return false;
	}
	else if (isNaN(parseFloat(intrate)))
	{
		alert("Please enter a valid Interest Rate !");
		breakup.intrate.focus();
		return false;
	}
	else if (intrate>100)
	{
		alert("Please enter a valid Interest Rate !");
		breakup.intrate.focus();
		return false;
	}
	else if (isNaN(parseInt(tenure)))
	{
		alert("Please enter a Valid Tenure !");
		breakup.tenure.focus();
		return false;
	}
	else
	{
	    var tmonths = parseInt((breakup.tenure.value) * 12)
	    var i = breakup.intrate.value;
	    if (i > 1.0) {
		    i = i / 100;
	    }
	    i /= 12;
	    var pow = 1;
	    for (var j = 0; j < tmonths; j++)
		    pow = pow * (1 + i);
		    money = "" + .01* Math.round(100*(breakup.pamount.value * pow * i) / (pow - 1));
		    dec = money.indexOf(".");
		    if(dec!=-1){
			    dollars = money.substring(0,dec); 
			    cents = money.substring(dec+1,dec+3);
			    cents = (cents.length < 2) ? cents + "0" : cents;
			    money = dollars + "." + cents;
		    }
		    else{
	    }
	        breakup.emiamt.value = money;
	    show();
	}
}
/* Housing Loan - EMI Calculator */


/* Housing Loan - Tax Save */
function validateTaxSave(frm)
{
    if(!frm.amount.value||parseFloat(frm.amount)<=0)
	{
		alert('Loan amount should be greater than 0');
		frm.amount.focus();
		return false;
	}
	if(!frm.tenure.value||parseFloat(frm.tenure.value)<=0||isNaN(parseFloat(frm.tenure.value)))
	{
		alert('Tenure should be greater than 0');
		frm.tenure.focus();
		return false;
	}
	if(!frm.roi.value||parseFloat(frm.roi.value)<=0)
	{
		alert('Rate of interest should be greater than 0');
		frm.roi.focus();
		return false;
	}
	if(parseFloat(frm.roi.value)>100)
	{
		alert('Rate of interest should be less than 100');
		frm.roi.focus();
		return false;
	}
	if(!frm.tax.value||parseFloat(frm.tax.value)<0||parseFloat(frm.tax.value)>35)
	{
		alert('Tax Rate of interest should be between 0 and 35');
		frm.roi.focus();
		return false;
	}
	return true;
}

function display(viewShow)
{
    if (document.layers)
    {
        content = document.layers[viewShow];
    }
    else if (document.all)
    {
    }
}

function calculateTaxSave()
{
    var amount;
    var yr
    var mon;
    var roi;
    var tenure;
    var reset;
    var tax;
    var tools =document.forms[0];
    tenure=parseFloat(tools.tenure.value,10)*12;
    amount=parseFloat(tools.amount.value,10);
    yr=parseFloat(tools.yr.options[tools.yr.selectedIndex].value,10);
    mon=parseFloat(tools.mon.options[tools.mon.selectedIndex].value,10);
    roi=parseFloat(tools.roi.value,10)/1200;
    reset=parseFloat(tools.reset.options[tools.reset.selectedIndex].value,10);
    tax=parseFloat(tools.tax.value,10)/100;
    var emi=(amount*12*roi*(Math.pow( (roi*reset+1),tenure/reset))) /((Math.pow((1+roi*reset),tenure/reset) - 1)*12);
    var k=(1+roi*reset);
    var n=0;
    
    if( reset==12)
    {
    }
    else
    {
        n=12- mon + 1
        var p=amount;
    }
    
    var cyr=parseFloat(tools.yr.options[tools.yr.selectedIndex].text,10);
    if(mon>9)
    {
        cyr-=1;
    }
    var interest=0;
    var principal=0;
    var cprincipal=0;
    var cinterest=0;
    var intr=0;
    plast=p;
    var bgc='';
    CL_win=window.open("",'ash1','scrollbars=yes,toolbar=no,menubar=no,resizable=yes,height=600,width=700','replace');
    CL_win.document.open();
    CL_win.focus();
    
    CL_win.document.write('<html>');
    CL_win.document.write('<head>');

    CL_win.document.write('<link href="../ITradeStyle.css" rel="stylesheet" type="text/css">');
    CL_win.document.write('</head>');
    CL_win.document.write('<body>');
    CL_win.document.write('<P><TABLE border=0 cellPadding=0 cellSpacing=0 width=100%><TR style=height:28px;><TD align=center class=GridHeadL><font size=2><b>Year</b></font></TD><TD class=GridHeadC><font  size=2><b>Principal Paid</b></font></TD><TD class=GridHeadC><font  size=2><b>Interest Paid</b></font></TD><TD class=GridHeadC><font  size=2><b>Tax saved on Principal</b></font></TD><TD class=GridHeadC><font  size=2><b>Tax saved on Interest</b></font></TD><TD class=GridHeadC><font  size=2><b>Total Tax Saved</b></font></TD></TR>')

    if(reset==1)
    {
        for(i=mon;i<13;i++)
        {
            if (interest<100000) interest+=p*(roi);
            intr+=p*roi;
            if (principal<20000) principal+=(emi-p*(roi));
            p=p-(emi-p*(roi))
            if(p<1) i=13
        }
        
        interest=Math.min(interest,100000);
        principal=Math.min(principal,20000);
        CL_win.document.write('<TR style=height:30px;><TD align=center class=GridDataCPlain><font  size=2>'+ cyr + '-' + Math.round(cyr+1) + '</font></TD><TD class=GridDataRPlain><font size=2>' + Math.round(plast-p) + '</font></TD><TD class=GridDataRPlain><font size=2>'+ Math.round(intr) + '</font></TD><TD class=GridDataRPlain><font size=2>'+ Math.round(principal*0.2) + '</font></TD><TD class=GridDataRPlain><font size=2>' +Math.round(interest*tax) + '</font></TD><TD class=GridDataRPlain><font size=2>'+ Math.round(principal*0.2 +interest*tax)+ '</font></TD></TR>')

        plast=p;
        cinterest+=interest;
        cprincipal+=principal;
        interest=0;
        principal=0;
        cyr+=1;
        intr=0;
        
        do
        {
            for(i=1;i<13;i++)
            {
                if (interest<100000) interest+=p*(roi);
                intr+=p*roi;
                if (principal<20000) principal+=(emi-p*(roi));
                p=p-(emi-p*(roi))
                if(p<1) i=13
            }
            interest=Math.min(interest,100000);
            principal=Math.min(principal,20000);
            CL_win.document.write('<TR style=height:30px;><TD align=center class=GridDataCPlain><font size=2>'+ cyr + '-' + Math.round(cyr+1) + '</font></TD><TD class=GridDataRPlain><font size=2>' + Math.round(plast-p) + '</font></TD><TD class=GridDataRPlain><font size=2>'+ Math.round(intr) + '</font></TD><TD class=GridDataRPlain><font size=2>'+ Math.round(principal*0.2) + '</font></TD><TD class=GridDataRPlain><font size=2>' +Math.round(interest*tax) + '</font></TD><TD class=GridDataRPlain><font size=2>'+ Math.round(principal*0.2 +interest*tax)+ '</font></TD></TR>')

            plast=p;
            cinterest+=interest;
            cprincipal+=principal;
            interest=0;
            principal=0;
            cyr+=1;
            intr=0;
        } while(p>1)
        CL_win.document.write('</table>')
    }
    else
    {
        var plast=amount;
        n=12;
        var p=amount*Math.pow(k,n/reset)-(emi*reset)*(Math.pow(k,n/reset)-1)/(k-1);
        var pemi=0;
        if((plast-p)!=0) 
        {
            pemi=(plast-p)/12;
        }

        var iemi=emi-pemi
        var prin=0;
        
        for(i=mon;i<13;i++)
        {
		    if (interest<100000) interest+=iemi;
		    intr+=iemi;
		    if (principal<20000) principal+=pemi;
		    prin+=pemi;
        }

        interest=Math.min(interest,100000);
        principal=Math.min(principal,20000);
        CL_win.document.write('<TR style=height:30px;><TD align=center class=GridDataCPlain><font size=2>'+ cyr + '-' + Math.round(cyr+1) + '</font></TD><TD class=GridDataRPlain><font size=2>' + Math.round(prin) + '</font></TD><TD class=GridDataRPlain><font size=2>'+ Math.round(intr) + '</font></TD><TD class=GridDataRPlain><font size=2>'+ Math.round(principal*0.2) + '</font></TD><TD class=GridDataRPlain><font size=2>' +Math.round(interest*tax) + '</font></TD><TD class=GridDataRPlain><font size=2>'+ Math.round(principal*0.2 +interest*tax)+ '</font></TD></TR>')

        cinterest+=interest;
        cprincipal+=principal;
        interest=0;
        principal=0;
        cyr+=1;
        intr=0;
        prin=0;
        
        do
        {
            for(i=1;i<mon;i++)
	        {
	            if (interest<100000) interest+=iemi;
	            intr+=iemi;
	            if (principal<20000) principal+=pemi;
	            prin+=pemi;
	            if(p<1) i=13
            }
            interest=Math.min(interest,100000);
            principal=Math.min(principal,20000);
            plast=p
            n+=12;
            p=amount*Math.pow(k,n/reset)-(emi*reset)*(Math.pow(k,n/reset)-1)/(k-1);
            pemi=(plast-p)/12
            iemi=emi-pemi
            
            if(plast>10)
	        {
		        for(i=mon;i<13;i++)
		        {
		            if (interest<100000) interest+=iemi;
		            intr+=iemi;
		            if (principal<20000) principal+=pemi;
		            prin+=pemi;
		        }
	        }
            interest=Math.min(interest,100000);
            principal=Math.min(principal,20000);
            CL_win.document.write('<TR style=height:30px;><TD align=center class=GridDataCPlain><font size=2>'+ cyr + '-' + Math.round(cyr+1) + '</font></TD><TD class=GridDataRPlain><font size=2>' + Math.round(prin) + '</font></TD><TD class=GridDataRPlain><font size=2>'+ Math.round(intr) + '</font></TD><TD class=GridDataRPlain><font size=2>'+ Math.round(principal*0.2) + '</font></TD><TD class=GridDataRPlain><font size=2>' +Math.round(interest*tax) + '</font></TD><TD class=GridDataRPlain><font size=2>'+ Math.round(principal*0.2 +interest*tax)+ '</font></TD></TR>')

            cinterest+=interest;
            cprincipal+=principal;
            interest=0;
            principal=0;
            cyr+=1;
            intr=0;
            prin=0;
        } while(p>1)
        
        if(mon>1)
        {
            for(i=1;i<mon;i++)
	        {
	            if (interest<100000) interest+=iemi;
	            intr+=iemi;
	            if (principal<20000) principal+=pemi;
	            prin+=pemi;
	        }
            interest=Math.min(interest,100000);
            principal=Math.min(principal,20000);
            cinterest+=interest;
            cprincipal+=principal;
            
            CL_win.document.write('<TR style=height:30px;><TD align=center class=GridDataCPlain><font size=2>'+ cyr + '-' + Math.round(cyr+1) + '</font></TD><TD class=GridDataRPlain><font size=2>' + Math.round(prin) + '</font></TD><TD class=GridDataRPlain><font size=2>'+ Math.round(intr) + '</font></TD><TD class=GridDataRPlain><font size=2>'+ Math.round(principal*0.2) + '</font></TD><TD class=GridDataRPlain><font size=2>' +Math.round(interest*tax) + '</font></TD><TD class=GridDataRPlain><font size=2>'+ Math.round(principal*0.2 +interest*tax)+ '</font></TD></TR>')
        }
    }
    CL_win.document.write('<tr style=height:30px;><td align=left colspan=6><table><tr><td class=blackhead1><font  size=2><b>Total Tax Saving: Rs. '+Math.round(cprincipal*0.2+cinterest*tax)+'<b></td></tr></table></td></tr>')
    CL_win.document.write('</table></body></html>')
}
/* Housing Loan - Tax Save */


/* My Networth */
function cl_checkNetWorth(fld,typ)
{
    if(typ=="int")
    {
	    if(isNaN(fld.value))
	    {
	        alert('Please enter a Number in the given field');
	        fld.focus();
	        return false;
	    }
        return true;
    }
}

function cl_calculateNetWorth()
{
    var CL_ta=0;
    var CL_tl=0;
    var CL_mon;
    var cl_tool = document.forms[0];
    var borrow =  document.forms[0];
    for(i=1;i<16;i++)                       
    {
        CL_mon=eval('cl_tool.a'+i)
        if (isNaN(CL_mon.value)||!CL_mon.value) CL_mon.value=0;
        if(CL_mon.value && !isNaN(CL_mon.value) )
        {
            CL_ta+=parseFloat(CL_mon.value);
        }
    }
    for(i=1;i<9;i++)
    {
        CL_mon=eval('cl_tool.l'+i)
        if (isNaN(CL_mon.value)||!CL_mon.value) CL_mon.value=0;
        if(CL_mon.value && !isNaN(CL_mon.value) )
        {
            CL_tl+=parseFloat(CL_mon.value);
        }
    }

    cl_tool.CL_ta.value=CL_ta;
    cl_tool.CL_tl.value=CL_tl;
    cl_tool.nw.value=CL_ta-CL_tl;
     borrow.CL_mon.value=CL_ta-CL_tl;
    if(document.all)
    {
        borrow.CL_mon.value=CL_ta-CL_tl;
        CL_display('result');
    }
    if(document.layers)
    {
        document.layers['result'].borrow.CL_mon.value=CL_ta-CL_tl;
        CL_display('result');
    }
}

function cl_validateNetWorth(frm)
{
    var cl_tool = document.forms[0];
    var a1=cl_tool.a1.value;
   	return true;
}
/* My Networth */


/* Settle Debt or not */
function cl_validateSettleDebt(frm)
{
   var cl_tool = document.forms[0];
    var CL_amount=cl_tool.amt.value;
    
    if(isNaN(CL_amount)||!CL_amount)
	{
	    alert('Enter the loan amount');
	    cl_tool.amt.focus();
	    return false;
	}
	if(!cl_tool.CL_tenure.value)
	{
	    alert('Please enter the repayment period.');
	    cl_tool.CL_tenure.focus();
	    return false;
	}
	
    var CL_emi =cl_tool.CL_emi.value;
    if(isNaN(CL_emi))
    {
        alert('Enter the emi');
        cl_tool.CL_emi.focus();
        return false;
    }
    if(!CL_emi)
    {
        alert('please enter the emi.');
        cl_tool.CL_emi.focus();
        return false;
    }
    
    var CL_tenure =cl_tool.CL_tenure.value;
    if(!(CL_tenure))
    {
        alert('Enter the CL_tenure of loan');
        cl_tool.CL_tenure.focus();
        return false;
    }
    
    var CL_paid =cl_tool.CL_paid.value;
    if(!(CL_paid))
    {
        alert('Enter the Installments paid');
        cl_tool.CL_paid.focus();
        return false;
    }
    
    var CL_adv=cl_tool.CL_adv.value;
    if(!(CL_adv))
    {
        alert("Please enter the Advance installments paid");  
        cl_tool.CL_adv.focus();
        return false;
    }
   
    var CL_prepay=cl_tool.CL_prepay.value;
    if(!(CL_prepay))
    {
        alert("Please enter the Prepayment charges");  
        cl_tool.CL_prepay.focus();
        return false;
    }
    
    var CL_prepay=cl_tool.CL_prepay;
    if(parseFloat(CL_prepay.value)>100)
    {
        alert("Please enter valid Prepayment charges");  
        cl_tool.CL_prepay.focus();
        return false;
    }
    
    var CL_t2=cl_tool.CL_t2.value;
    if(!(CL_t2))
    {
        alert("Please enter the Tenure of investment");
        cl_tool.CL_t2.focus();
        return false;
    }
    
    var CL_roi2=cl_tool.CL_roi2.value;
    if(!(CL_roi2))
    {
        alert("Please enter the Interest earned");  
        cl_tool.CL_roi2.focus();
        return false;
    }
    if(CL_emi*(CL_tenure*12)< CL_amount)
    {
        alert('The emi you enter does not appear to be correct. Please check.');
        cl_tool.CL_emi.focus();
        return false;
    }
    return true;
}

function cl_calculateSettleDebt()
{
    var cl_tool = document.forms[0];
    var borrow =  document.forms[0];
    var CL_amount=cl_tool.amt.value;
    var CL_emi=cl_tool.CL_emi.value;
    var CL_reset1=cl_tool.CL_reset.options[cl_tool.CL_reset.selectedIndex].value;
    var CL_tenure=cl_tool.CL_tenure.value*CL_reset1;
    var CL_tenure1=cl_tool.CL_tenure.value;
    var CL_pay=CL_tenure*CL_emi*12/CL_reset1;
    var CL_strt=(CL_pay-CL_amount)/CL_amount/CL_tenure;
    
    var CL_adv=cl_tool.CL_adv.value;
    var CL_t2=parseFloat(cl_tool.CL_t2.value);
    var CL_roi2=parseFloat(cl_tool.CL_roi2.value)/100;
    var CL_comp=parseFloat(cl_tool.CL_comp.options[cl_tool.CL_comp.options.selectedIndex].value);
    var CL_strt2
    CL_amount= CL_amount- CL_adv*CL_emi;
    CL_tenure-=CL_adv*CL_reset1/12;
    
    var CL_r=1/(1+CL_strt);
    var CL_res= (CL_emi*12/CL_reset1)*((Math.pow(CL_r,CL_tenure)-1)/(CL_r-1))*CL_r-CL_amount;
    
    if(CL_res>0)
    {   
        do
        {
            CL_strt=CL_strt+0.00001;
            CL_r=1/(1+CL_strt);
            CL_res=(CL_emi*12/CL_reset1)*((Math.pow(CL_r,CL_tenure)-1)/(CL_r-1))*CL_r-CL_amount;
        } while( CL_res > 0 )
    }
    else
    {
        alert('Please check the input numbers');
    }
    
    var CL_eirr=((CL_strt)*CL_reset1)*10000;
    CL_eirr=Math.round(CL_eirr)
    CL_eirr/=100;

    var CL_paid=parseInt(cl_tool.CL_paid.value);
    
    var CL_r=1+CL_eirr/100/CL_reset1;
    var CL_junk=CL_paid*CL_reset1%12;
    var CL_paid1=Math.round(CL_paid*CL_reset1/12+0.499999999999);
    var p=((CL_amount)*Math.pow(CL_r,CL_paid1) -(CL_emi*12/CL_reset1)*(Math.pow(CL_r,CL_paid1)-1)/(CL_r-1));

    CL_paid1=Math.round(CL_paid*CL_reset1/12-0.499999999999);

    var CL_p1=((CL_amount)*Math.pow(CL_r,CL_paid1) -(CL_emi*12/CL_reset1)*(Math.pow(CL_r,CL_paid1)-1)/(CL_r-1));
    var CL_po=p;
    p=CL_p1-(CL_p1-p)*CL_junk/12*CL_reset1;
    
    if(CL_comp>0)
    {
        var CL_rt=Math.pow(Math.pow(1+CL_roi2/CL_comp,CL_comp),1/12);
    }
    else
    {
        var CL_rt=Math.pow(Math.pow(1+CL_t2*CL_roi2,1/CL_t2),1/12);
    }
    CL_r=1/CL_rt;
    var CL_pv2= CL_emi*CL_r*(Math.pow(CL_r,CL_tenure*12/CL_reset1-CL_paid)-1)/(CL_r-1)
    
    var CL_npv=CL_pv2-p-Math.round(p*cl_tool.CL_prepay.value/100)
    CL_npv=Math.round(CL_npv)
    
    if (document.layers)
    {
        if(CL_npv>0)
        {
            document.layers['result'].borrow.CL_remloan.value=Math.round(p);
            document.layers['result'].borrow.CL_op.value='Repaying loan';
            document.layers['result'].borrow.CL_sav.value=CL_npv;
        }
        else
        {
            CL_npv=-CL_npv;
            document.layers['result'].borrow.CL_remloan.value=Math.round(p);
            document.layers['result'].borrow.CL_op.value='Investing';
            document.layers['result'].borrow.CL_sav.value=CL_npv;
        }
        document.layers['result'].document.close();
    }
    else
    {
	    if (CL_npv>0)
	    {
		    borrow.CL_remloan.value=Math.round(p);
		    borrow.CL_op.value='Repaying loan';
		    borrow.CL_sav.value=CL_npv;
	    }
	    else
	    {
	        CL_npv=-CL_npv
		    borrow.CL_remloan.value=Math.round(p);
		    borrow.CL_op.value='Investing';
		    borrow.CL_sav.value=CL_npv;
	    }
    }
}
/* Settle Debt or not */


/* My Expense Sheet */
function cl_checkExp(fld,typ)
{
    if(typ=="int")
    {
	    if(isNaN(fld.value)||!fld.value||parseFloat(fld.value)<0)
	    {
	        alert('Value should be greater than or equal to 0');
	        fld.focus();
	        return false;
	    }
    }

    var nam=fld.name;
    
    if(nam.indexOf("xm")!=-1)
    {
        var ot=eval('document.cl_tool.xa' + nam.substring(2,6))
        ot.value=parseFloat(fld.value)*12;
    }
    if(nam.indexOf("xa")!=-1)
    {
        var ot=eval('document.cl_tool.xm' + nam.substring(2,6))
        ot.value=parseFloat(fld.value)/12;
    }
    if(nam.indexOf("im")!=-1)
    {
        var ot=eval('document.cl_tool.ia' + nam.substring(2,6))
        ot.value=parseFloat(fld.value)*12;
    }
    if(nam.indexOf("ia")!=-1)
    {
        var ot=eval('document.cl_tool.im' + nam.substring(2,6))
        ot.value=parseFloat(fld.value)/12;
    }
    cl_calculateExp();
}

function cl_calculateExp()
{
    var CL_tmon=0;
    var CL_tyr=0;                        
    var CL_timon=0;
    var CL_tiyr=0;
    var cl_tool= document.forms[0];
    var borrow  = document.forms[0];
    for(i=1;i<30;i++)
    {
        var CL_mon=eval('cl_tool.xm'+i)
        var CL_yr=eval('cl_tool.xa'+i)
        if(CL_mon.value && !isNaN(CL_mon.value) && CL_yr.value && !isNaN(CL_yr.value))
        {
            CL_tmon+=parseFloat(CL_mon.value);
            CL_tyr+=parseFloat(CL_yr.value);
        }
    }
    
    for(i=1;i<6;i++)
    {
        var CL_imon=eval('cl_tool.im'+i)
        var CL_iyr=eval('cl_tool.ia'+i)
        if(CL_imon.value && !isNaN(CL_imon.value) && CL_iyr.value && !isNaN(CL_iyr.value))
        {
            CL_timon+=parseFloat(CL_imon.value);
            CL_tiyr+=parseFloat(CL_iyr.value);
        }
    }
   
    cl_tool.CL_mexp.value=CL_tmon;
    cl_tool.CL_yrexp.value=CL_tyr;
    cl_tool.CL_imt.value=CL_timon;
    cl_tool.CL_iat.value=CL_tiyr;
        
    borrow.CL_dmon.value=CL_timon-CL_tmon;
    borrow.CL_dyr.value=CL_tiyr-CL_tyr;
    CL_display('result');
    borrow.CL_dyr.focus();
    if(document.all)
    {   
        borrow.CL_dmon.value=CL_timon-CL_tmon;
        borrow.CL_dyr.value=CL_tiyr-CL_tyr;
        CL_display('result');
        borrow.CL_dyr.focus();
    }
    if(document.layers)
    {
        document.layers['result'].borrow.CL_dmon.value=CL_timon-CL_tmon; 
        document.layers['result'].borrow.CL_dyr.value=CL_tiyr-CL_tyr;
        CL_display('result');
    }
}

function cl_validateExp(frm)
{
    var frm = document.forms[0];
    var i=0;
	var temp;
	var n=0;
	
	for(n=0;n<frm.elements.length;n++)
	{
	    temp=frm.elements[n].name;

	    if(temp.indexOf("ia")!=-1||temp.indexOf("xa")!=-1||temp.indexOf("im")!=-1||temp.indexOf("ia")!=-1)
	    {
		    if(!frm.elements[n].value||isNaN(frm.elements[n].value)||parseFloat(frm.elements[n].value)<0)
		    {
		        alert("Enter a value Greater than or equal to 0");
		        frm.elements[n].focus();
		        return false;
		    }
	    }
	}
	return true;
}

function cl_View()
{
    if(document.layers)
        document.layers['result'].document.borrow.CL_dyr.focus();
    if(document.all)
        document.borrow.CL_dyr.focus();
}
/* My Expense Sheet */


/* Debt Calculator */
function cl_validateDebt()
{
    var cl_tool = document.forms[0];
    var CL_autoamt= cl_tool.CL_autoamt.value;
    var CL_autotenure = cl_tool.CL_autotenure.value;
    var CL_autoemi = cl_tool.CL_autoemi.value; 
    var CL_padv = cl_tool.CL_padv.value; 
    var CL_ppaid = cl_tool.CL_ppaid.value;    
    var CL_pemi =cl_tool.CL_pemi.value; 
    var CL_ptenure =cl_tool.CL_ptenure.value; 
    var CL_pamt =cl_tool.CL_pamt.value; 
    var CL_homepaid =cl_tool.CL_homepaid.value; 
    var CL_homeemi =cl_tool.CL_homeemi.value; 
    var CL_hometenure =cl_tool.CL_hometenure.value; 
    var CL_homeamt =cl_tool.CL_homeamt.value;
    var CL_autointerest =cl_tool.CL_autointerest.value; 
    var CL_automat =cl_tool.CL_automat.value; 
    var CL_autodp =cl_tool.CL_autodp.value; 
    var CL_autoadv =cl_tool.CL_autoadv.value;    
    var CL_autopaid =cl_tool.CL_autopaid.value;
    
    if(CL_autoamt=="")
	{
	    alert('Enter the auto loan amount');
	    cl_tool.CL_autoamt.focus();
	    return false;
	}
	else if(CL_autotenure=="")
	{
	    alert('Repayment period should be greater than 0');
	    cl_tool.CL_autotenure.focus();
	    return false;
	}
	else if(CL_autoemi=="")
    {
        alert('Please enter Monthly Instalment');
        cl_tool.CL_autoemi.focus();
        return false;
    }
    else if(CL_autopaid=="")
    {
        alert('Please Enter the  paid instalment');
        cl_tool.CL_autopaid.focus();
        return false;
    }
    else if(CL_autoadv=="")
    {
        alert('Enter the number of advance installments');
        cl_tool.CL_autoadv.focus();
        return false;
    }
    else if(CL_autodp=="")
    {
        alert('Please enter amount deposit');
        cl_tool.CL_autodp.focus();
        return false;
    }
    else if(CL_automat=="")
    {
        alert('Please enter Amount at maturity');
        cl_tool.CL_automat.focus();
        return false;
    }
    else if(CL_autointerest=="")
    {
        alert('Please enter Rate of interest on the deposit');
        cl_tool.CL_autointerest.focus();
        return false;
    }
    else if(CL_homeamt=="")
    {
        alert('Please enter Home loan amount');
        cl_tool.CL_homeamt.focus();
        return false;
    }
    else if(CL_hometenure=="")
    {
        alert('Please enter repayment period');
        cl_tool.CL_hometenure.focus();
        return false;
    }
    else if(CL_homeemi=="")
    {
        alert('Please enter Monthly Instalment');
        cl_tool.CL_homeemi.focus();
        return false;
    }
    else if(CL_homepaid=="")
    {
        alert('Please enter Paid Instalment');
        cl_tool.CL_homepaid.focus();
        return false;
    }
    else if(CL_pamt=="")
    {
        alert('Please enter personal loan amount');
        cl_tool.CL_pamt.focus();
        return false;
    }
    else if(CL_ptenure=="")
    {
        alert('Please enter Repayment period');
        cl_tool.CL_ptenure.focus();
        return false;
    }
    else if(CL_pemi=="")
    {
        alert('Please enter Monthly instalment');
        cl_tool.CL_pemi.focus();
        return false;
    }
    else if(CL_ppaid=="")
    {
        alert('Please enter paid instalment');
        cl_tool.CL_ppaid.focus();
        return false;
    }
    else if(CL_padv=="")
    {
        alert('Please enter number of advance instalment');
        cl_tool.CL_padv.focus();
        return false;
    }
    return true;
}

function cl_calculateDebt()
{
    var  cl_tool = document.forms[0];
    var borrow = document.forms[0];
    var CL_amount=cl_tool.CL_autoamt.value;
    var CL_emi =cl_tool.CL_autoemi.value;
    var CL_reset1=cl_tool.CL_autoreset.options[cl_tool.CL_autoreset.selectedIndex].value;
    var CL_tenure =cl_tool.CL_autotenure.value*CL_reset1;
    var CL_tenure1 =cl_tool.CL_autotenure.value;
    var CL_reset =cl_tool.CL_autoitype.value;
    var CL_paid=parseInt(cl_tool.CL_autopaid.value);
    
    var CL_dp = cl_tool.CL_autodp.value;
    var CL_adv=cl_tool.CL_autoadv.value;
    var CL_interest=cl_tool.CL_autointerest.value/100;
    var CL_mat=cl_tool.CL_automat.value;
    var CL_loanary =new Array();
    var CL_loanary1 =new Array();
    CL_p=0;
    if(CL_amount && CL_amount>0)CL_p=remloan(CL_amount,CL_emi,CL_reset1,CL_tenure1,CL_reset, CL_dp,CL_adv,CL_interest,CL_mat,CL_paid);

    CL_loanary[0]=CL_p;
    CL_loanary1[0]=CL_paid;
    
    CL_amount=cl_tool.CL_homeamt.value;
    CL_emi =cl_tool.CL_homeemi.value;
    CL_reset1=cl_tool.CL_homereset.options[cl_tool.CL_homereset.selectedIndex].value;
    CL_tenure =cl_tool.CL_hometenure.value*CL_reset1;
    CL_tenure1 =cl_tool.CL_hometenure.value;
    CL_paid=parseInt(cl_tool.CL_homepaid.value);

    CL_p=0;

    if(CL_amount && CL_amount>0)CL_p=remloan(CL_amount,CL_emi,CL_reset1,CL_tenure1,1, 0,0,0,0,CL_paid);
    CL_loanary[1]=CL_p
    CL_loanary1[1]=CL_paid;
    
    CL_amount=cl_tool.CL_pamt.value;
    CL_emi =cl_tool.CL_pemi.value;
    CL_reset1=cl_tool.CL_preset.options[cl_tool.CL_preset.selectedIndex].value;
    CL_tenure =cl_tool.CL_ptenure.value*CL_reset1;
    CL_tenure1 =cl_tool.CL_ptenure.value;
    CL_adv=parseInt(cl_tool.CL_padv.value);
    CL_paid=parseInt(cl_tool.CL_ppaid.value);

    CL_p=0;
    if(CL_amount && CL_amount>0)CL_p=remloan(CL_amount,CL_emi,CL_reset1,CL_tenure1,1, 0,CL_adv,0,0,CL_paid);
    CL_loanary[2]=CL_p
    CL_loanary1[2]=CL_paid;
    
    CL_amount=cl_tool.amt.value;
    CL_emi =cl_tool.CL_emi.value;
    CL_reset1=cl_tool.CL_reset.options[cl_tool.CL_reset.selectedIndex].value;
    CL_tenure =cl_tool.CL_tenure.value*CL_reset1;
    CL_tenure1 =cl_tool.CL_tenure.value;
    CL_adv=parseInt(cl_tool.CL_adv.value);
    CL_paid=parseInt(cl_tool.CL_paid.value);

    CL_p=0;
    if(CL_amount && CL_amount>0)CL_p=remloan(CL_amount,CL_emi,CL_reset1,CL_tenure1,1, 0,CL_adv,0,0,CL_paid);
    CL_loanary[3]=CL_p
    CL_loanary1[3]=CL_paid;
    
    if (document.layers)
    {
        document.layers['result'].borrow.CL_auto.value=Math.round(CL_loanary[0]);
        document.layers['result'].borrow.CL_home.value=Math.round(CL_loanary[1]);
        document.layers['result'].borrow.CL_personal.value=Math.round(CL_loanary[2]);
        document.layers['result'].borrow.other.value=Math.round(CL_loanary[3]);

        document.layers['result'].borrow.CL_autoper.value=CL_loanary1[0];
        document.layers['result'].borrow.CL_homeper.value=CL_loanary1[1];
        document.layers['result'].borrow.CL_pper.value=CL_loanary1[2];
        document.layers['result'].borrow.otherper.value=CL_loanary1[3];
        document.layers['result'].borrow.total.value=Math.round(CL_loanary[0]+ CL_loanary[1] +CL_loanary[2]+CL_loanary[3]);
        document.layers['result'].borrow.CL_auto.focus();
    }
    else
    {
        borrow.CL_auto.value=Math.round(CL_loanary[0]);
        borrow.CL_home.value=Math.round(CL_loanary[1]);
        borrow.CL_personal.value=Math.round(CL_loanary[2]);
        borrow.other.value=Math.round(CL_loanary[3]);

        borrow.CL_autoper.value=CL_loanary1[0];
        borrow.CL_homeper.value=CL_loanary1[1];
        borrow.CL_pper.value=CL_loanary1[2];
        borrow.otherper.value=CL_loanary1[3];

        borrow.total.value=Math.round(CL_loanary[0]+ CL_loanary[1] +CL_loanary[2]+CL_loanary[3]);
        borrow.CL_auto.focus();;
    }
}

function remloan(CL_amount,CL_emi,CL_reset1,CL_tenure1,CL_reset, CL_dp,CL_adv,CL_interest,CL_mat,CL_paid)
{
    var CL_tenure=CL_tenure1*CL_reset1;
    var CL_pay=CL_tenure*CL_emi*12/CL_reset1;
    var CL_strt=(CL_pay-CL_amount)/CL_amount/CL_tenure;
    CL_amount= CL_amount- CL_adv*CL_emi -CL_dp;
    CL_tenure-=CL_adv*CL_reset1/12;
    
    var CL_r=1/(1+CL_strt);
    var CL_res= (CL_emi*12/CL_reset1)*((Math.pow(CL_r,CL_tenure)-1)/(CL_r-1))*CL_r-CL_amount;
    if(CL_res>0)
    {
        do
        {
            CL_strt=CL_strt+0.00001;
            CL_r=1/(1+CL_strt);
            CL_res=(CL_emi*12/CL_reset1)*((Math.pow(CL_r,CL_tenure)-1)/(CL_r-1))*CL_r-CL_amount;
        } while( CL_res > 0 )
    }
    else
    {
        alert('Please check the input numbers');
    }
    
    if(CL_dp>0)
    {
        if(CL_mat==0)
        {
	        if(document.cl_tool.itype.options[document.cl_tool.itype.selectedIndex].value=='s')
	        {
	            CL_mat=CL_dp*(1 + CL_interest*parseInt(document.cl_tool.CL_tenure.value));
	        }
	        else
	        {
	            CL_mat=CL_dp*Math.pow((1+CL_interest/12*CL_reset),parseInt(document.cl_tool.CL_tenure.value)/CL_reset);
	        }
        }
        
        var CL_k=(1+CL_strt);
	    var fv= (CL_amount*Math.pow(CL_k,CL_tenure) -CL_emi*12/CL_reset1*(Math.pow(CL_k,CL_tenure)-1)/(CL_k-1))*CL_k+CL_mat/Math.pow(CL_k,(CL_adv)/12*CL_reset1-1);
		do
		{
		    CL_strt=CL_strt-0.00001;
		    CL_k=(1+CL_strt);
		    fv= (CL_amount*Math.pow(CL_k,CL_tenure) -CL_emi*12/CL_reset1*(Math.pow(CL_k,CL_tenure)-1)/(CL_k-1))*CL_k+CL_mat/Math.pow(CL_k,(CL_adv)/12*CL_reset1-1);
		} while( fv > 0 )
    }
    
    var eirr=((CL_strt)*CL_reset1)*10000;
    eirr=Math.round(eirr);
    eirr/=100;
    
    var CL_pvdp=CL_mat/Math.pow(1+eirr/100/CL_reset1,CL_tenure1*CL_reset1)

    var CL_r=1+eirr/100/CL_reset1;
    var junk=CL_paid*CL_reset1%12;
    var CL_paid1=Math.round(CL_paid*CL_reset1/12+0.499999999999);
    var CL_p=((CL_amount+CL_pvdp)*Math.pow(CL_r,CL_paid1) -(CL_emi*12/CL_reset1)*(Math.pow(CL_r,CL_paid1)-1)/(CL_r-1));

    CL_paid1=Math.round(CL_paid*CL_reset1/12-0.499999999999);

    var CL_p1=((CL_amount+CL_pvdp)*Math.pow(CL_r,CL_paid1) -(CL_emi*12/CL_reset1)*(Math.pow(CL_r,CL_paid1)-1)/(CL_r-1));
    var CL_po=CL_p;
    CL_p=CL_p1-(CL_p1-CL_p)*junk/12*CL_reset1;

    CL_pvdp=CL_mat/Math.pow(1+eirr/100/CL_reset1,CL_tenure1*CL_reset1-(CL_paid+1)*CL_reset1/12)
    
    if(CL_reset1==12)
    {
        CL_po+=(CL_r-1)*CL_p
    }
    else
    {
        CL_po+=(CL_p1-CL_po)/12*CL_reset1
    }
    return CL_p;
}
/* Debt Calculator */

/* PPF Loan */

var gl_flagD       = "TRUE";  //global variable for checkdate()
var gl_flagiD      ="TRUE";//flag for checkdate1()
var x;
var y;
var nardate1;
var nardate2;
var nardiff1;
var nardiff2;
var myval1;

function checkday()
{
    var loancal = document.forms[0];
    var d = loancal.day.options[loancal.day.selectedIndex].value;
    var m = loancal.mon.options[loancal.mon.selectedIndex].value;
    var y = loancal.year.value;
	var mnd;
	
	if (parseInt(d) < 10)
	{
        d = "0" + d;
    }
    if(parseInt(m) < 10)
    {
        m = "0" + m ;
    }

    concDate = m  +"/"+ d +"/"+ y;
    
    if(y < 1980 || y > 2050)
    {
        window.alert( "The date should be after 1980 and before 2050");
        loancal.year.focus();
        loancal.year.select();
        gl_flagD="FALSE";
        return false;
    }
    if ((m == 4 || m == 6 || m == 9 || m == 11) && d == 31)
    {
        if (m==4) {mnd="April"}
	    if (m==6) {mnd="June"}
	    if (m==9) {mnd="September"}
	    if (m==11) {mnd="November"}
	    window.alert("Month "+ mnd +" doesn't have 31 days!")
        loancal.start.value="";
        loancal.end.value="";
        loancal.day.focus();
        return false;
    }
    if (m == 2)
    { // check for february 29th
        var isleap = (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));
        if (d > 29 || (d == 29 && !isleap))
        {
            window.alert("February " + y + " doesn't have " + d + " days!");
            loancal.start.value="";
            loancal.end.value="";
            loancal.day.focus();
            return false;
        }
    }
    validDebt(y, m, d);
}

function validDebt(y, m, d)
{
    var loancal = document.forms[0];
    if(m > 3)
	{
		year = parseInt(y) + 2;
		/*newDate = "01" + "-Apr-" + year;
		document.loancal.start.value = newDate;*/
	}
	else
	{
		year = parseInt(y) + 1;
	    /*newDate = "01" + "-Apr-" + year;
		document.loancal.start.value = newDate;*/
	}
	
	newDate = "01" + "-Apr-" + year;
    loancal.start.value = newDate;
    edDate = "31" + "-Mar-" + (year + 4);
    loancal.end.value = edDate;
	x1 = "04/01/"+year
	y1 = "03/31/"+parseInt(year+4)
	nardate1 = x1;
	nardate2= y1;
	nardiff1 = dateDiffDebt(nardate2,nardate1);
}

function checkmonthDebt()
{
    var loancal = document.forms[0];
    var d = loancal.day.options[loancal.day.selectedIndex].value;
    var m = loancal.mon.options[loancal.mon.selectedIndex].value;
    var y = loancal.year.value;
	var mnm;
	
	if (parseInt(d) < 10)
	{
        d = "0" + d;
    }
    if(parseInt(m) < 10)
    {
        m = "0" + m ;
    }

    concDate = m  +"/"+ d +"/"+ y;

    if (m == "None")
    {
        window.alert("Month needs to have a value");
        return false;
    }
    if (y == "")
    {
        loancal.year.focus();
        return false;
    }
    if ((m == 4 || m == 6 || m == 9 || m == 11) && d == 31)
    {
   	    if (m==4) {mnm="April"}
        if (m==6) {mnm="June"}
        if (m==9) {mnm="September"}
        if (m==11) {mnm="November"}

	    window.alert("Month "+ mnm +" doesn't have 31 days!")
        loancal.start.value="";
        loancal.end.value="";
	    loancal.day.focus();
	    return false;
    }
    if (m == 2)
    { // check for february 29th
        var isleap = (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));
        if (d > 29 || (d == 29 && !isleap))
        {
            window.alert("February " + y + " doesn't have " + d + " days!");
            loancal.start.value="";
    	    loancal.end.value="";
		    loancal.day.focus();
		    return false;
        }
    }
    valid2(y, m, d);
}

function valid2(y, m, d)
{
   var loancal = document.forms[0];
    if (isNaN(y))
    {
        window.alert("Year can only be numeric");
        return false;
    }

    if(m > 3)
    {
        year = parseInt(y) + 2;
        /*newDate = "01" + "-Apr-" + year;
        document.loancal.start.value = newDate;*/
    }
    else
    {
        year = parseInt(y) + 1;
        /*newDate = "01" + "-Apr-" + year;
        document.loancal.start.value = newDate;*/
    }
    newDate = "01" + "-" + "Apr" + "-" + year;
    newDate2 = "04" + "/" + "01" + "/" + year;

   loancal.start.value = newDate;
    edDate = "31" + "-" + "Mar" +"-" + (year + 4);
    edDate2 = "03" + "/" + "31" + "/" + parseInt(year + 4);

    loancal.end.value = edDate;
}

//Function to validate first date entered
function checkdateDebt()
{
    var loancal = document.forms[0];
    var d = loancal.day.options[loancal.day.selectedIndex].value;
	var m = loancal.mon.options[loancal.mon.selectedIndex].value;
	var y = loancal.year.value;
	
	if (parseInt(d) < 10)
	{
        d = "0" + d;
    }
    if(parseInt(m) < 10)
    {
        m = "0" + m ;
    }
    
    concDate = m  +"/"+ d +"/"+ y;
    
    if(y < 1980 || y > 2050)
    {
        window.alert( "The date should be after 1980 and before 2050");
        loancal.year.focus();
        loancal.year.select();
        gl_flagD="FALSE";
        return false;
    }
    if((!nullvalue(loancal.year) || ((loancal.year.value).length !=4) || (loancal.year.value<=0) || isNaN(loancal.year.value)))
    {
        alert("Please enter the year of opening of your PPF account properly");
        loancal.year.focus();
        return false;
    }
    if (m == "None")
	{
	    window.alert("Month needs to have a value");
	    return false;
	}
	if (isNaN(y))
	{
	    window.alert("Year can only be numeric");
	    return false;
	}
	if (y == "")
	{
	    window.alert("Year cannot be left blank");
	    return false;
	}
	if ((m == 4 || m == 6 || m == 9 || m == 11) && d == 31)
	{
	    window.alert("Month "+ m +" doesn't have 31 days!")
	    return false;
	}
	{
	if (m == 2)
	{ // check for february 29th
	    var isleap = (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));
		if (d > 29 || (d == 29 && !isleap))
		{
		    window.alert("February " + y + " doesn't have " + d + " days!");
		    return false;
		}
	}
	}
	validDebt(y, m, d);
}

function checkday1()
{
    var loancal = document.forms[0];
    var d = loancal.day.options[loancal.day.selectedIndex].value;
    var m = loancal.mon.options[loancal.mon.selectedIndex].value;
    var y = loancal.year.value;
    
    if (parseInt(d) < 10)
    {
        d = "0" + d;
    }
    if(parseInt(m) < 10)
    {
        m = "0" + m ;
    }
    concDate = m  +"/"+ d +"/"+ y;
    
    var d1 = loancal.day1.options[loancal.day1.selectedIndex].value;
    var m1 = loancal.mon1.options[loancal.mon1.selectedIndex].value;
    var y1 = loancal.year1.value;
	var mnd1;
	
    if (parseInt(d1) < 10)
    {
        d1 = "0" + d1;
	}
    if(parseInt(m1) < 10)
    {
        m1 = "0" + m1 ;
    }
    concDate1 = m1 +"/"+ d1 +"/" + y1;
    
    if ((m1 == 4 || m1 == 6 || m1 == 9 || m1 == 11) && d1 == 31)
    {
   	    if (m1==4) {mnd1="April"}
        if (m1==6) {mnd1="June"}
        if (m1==9) {mnd1="September"}
        if (m1==11) {mnd1="November"}

	    window.alert("Month "+ mnd1 +" doesn't have 31 days!")
        loancal.fixdate.value="";
        loancal.day1.focus();
        return false;
    }
    
    {
    if (m1 == 2)
    { // check for february 29th
        var isleap = (y1 % 4 == 0 && (y1 % 100 != 0 || y1 % 400 == 0));
        if (d1 > 29 || (d1 == 29 && !isleap))
        {
            window.alert("February " + y1 + " doesn't have " + d1 + " days!");
            loancal.fixdate.value="";
            loancal.day1.focus();
            return false;
        }
    }
    }
    
    nardiff2 = dateDiffDebt(concDate1,nardate1)
    
    if((nardiff2>nardiff1)||(nardiff2<0))
    {
        alert("The date entered should be in the range " + loancal.start.value + " and " + loancal.end.value);
        return false;
        loancal.year1.focus();
		loancal.year1.select();
    }

    x11 = dateDiffDebt(concDate1, concDate)
    if (x11 <= 0)
    {
        window.alert(" Date should be after account opening date");
        gl_flagiD = "FALSE";
        return false;
    }
    
    //Check for date entered within range
    newDte = loancal.start.value;
    edDte = loancal.end.value;

    if (isNaN(y1))
    {
        window.alert("Year can only be numeric");
        loancal.year1.value="";
        loancal.year1.focus();
		return false;
    }
    if (m1 == "None")
    {
        window.alert("Month needs to have a value");
        loancal.mon1.focus();
        return false;
    }
    valid1Debt(y1, m1, d1);
}

function valid1Debt(y1, m1, d1)
{
    var loancal = document.forms[0];
    if(m1 > 3)
	{
		year1 = parseInt(y1) - 1;
		newDate2 = "31" + "-" + "Mar" + "-" + year1;
		loancal.fixdate.value = newDate2;
	}
	else
	{
		year1 = parseInt(y1) - 2;
		newDate2 = "31" + "-" + "Mar" + "-" + year1;
		loancal.fixdate.value = newDate2;
	}
}

//Function for validating mon1
function checkmonth2()
{
    var loancal = document.forms[0];
    var d1 = loancal.day1.options[loancal.day1.selectedIndex].value;
    var m1 = loancal.mon1.options[loancal.mon1.selectedIndex].value;
    var y1 = loancal.year1.value;
	var mnm1;
	
 	if (parseInt(d1) < 10)
 	{
        d1 = "0" + d1;
    }
    if(parseInt(m1) < 10)
    {
        m1 = "0" + m1 ;
    }

    if (m1 == "None")
    {
        window.alert("Month needs to have a value");
	    loancal.mon1.focus();
        return false;
    }
    if ((m1 == 4 || m1 == 6 || m1 == 9 || m1 == 11) && d1 == 31)
    {
   	    if (m1==4) {mnm1="April"}
        if (m1==6) {mnm1="June"}
        if (m1==9) {mnm1="September"}
        if (m1==11) {mnm1="November"}

	    window.alert("Month "+ mnm1 +" doesn't have 31 days!")
        loancal.fixdate.value="";
        loancal.day1.focus();
        return false;
    }
    
    {
        if (m1 == 2)
        { // check for february 29th
            var isleap = (y1 % 4 == 0 && (y1 % 100 != 0 || y1 % 400 == 0));
        	if (d1 > 29 || (d1 == 29 && !isleap))
            {
                window.alert("February " + y1 + " doesn't have " + d1 + " days!");
                loancal.fixdate.value="";
                loancal.day1.focus();
	            return false;
	        }
	    }
	}
}

//Function to validate second date
function checkdate1Debt()
{
    var loancal = document.forms[0];
    var d = loancal.day.options[loancal.day.selectedIndex].value;
    var m = loancal.mon.options[loancal.mon.selectedIndex].value;
    var y = loancal.year.value;

    if (parseInt(d) < 10)
    {
        d = "0" + d;
    }
    if(parseInt(m) < 10)
    {
        m = "0" + m ;
    }
    concDate = m  +"/"+ d +"/"+ y;
    
    var d1 = loancal.day1.options[loancal.day1.selectedIndex].value;
	var m1 = loancal.mon1.options[loancal.mon1.selectedIndex].value;
	var y1 = loancal.year1.value;
    
    if (parseInt(d1) < 10)
    {
        d1 = "0" + d1;
    }
    if(parseInt(m1) < 10)
    {
        m1 = "0" + m1 ;
    }
    concDate1 = m1 +"/"+ d1 +"/" + y1;
	nardiff2 = dateDiffDebt(concDate1,nardate1)
	
	if((nardiff2>nardiff1)||(nardiff2<0))
	{
		alert("The date entered should be in the range " +loancal.start.value + " and " + loancal.end.value);
        return false;
        loancal.year1.focus();
        loancal.year1.select();
	}

    x11 = dateDiffDebt(concDate1, concDate)
    if (x11 <= 0)
    {
        window.alert(" Date should be after account opening date");
        gl_flagiD = "FALSE";
        return false;
    }
    
    //Check for date entered within range
    newDte = loancal.start.value;
    edDte = loancal.end.value;
    if (isNaN(y1))
    {
	    window.alert("Year can only be numeric");
	    loancal.year1.value="";
		loancal.year1.focus();
	    return false;
	}
	if (m1 == "None")
	{
	    window.alert("Month needs to have a value");
        loancal.mon1.focus();
	    return false;
	}
	if ((m1 == 4 || m1 == 6 || m1 == 9 || m1 == 11) && d1 == 31)
	{
	    window.alert("Month "+ m1 +" doesn't have 31 days!")
        loancal.fixdate.value="";
	    loancal.day1.focus();
	    return false;
	}
	
	{
	if (m1 == 2)
	{ // check for february 29th
	    var isleap = (y1 % 4 == 0 && (y1 % 100 != 0 || y1 % 400 == 0));
	    if (d1 > 29 || (d1 == 29 && !isleap))
	    {
	        window.alert("February " + y1 + " doesn't have " + d1 + " days!");
            loancal.fixdate.value="";
            loancal.day1.focus();
	        return false;
	    }
	}
	}
	valid1Debt(y1, m1, d1);
}

//function to validate amount
function valAmt()
{
    var loancal = document.forms[0];
    var fd1 = loancal.amount.value;
    if (isNaN(fd1)|| fd1<="0")
    {
        window.alert("Amount can only be positive and numeric");
        loancal.amount.value="";
		loancal.amount.focus();
        return false;
    }
}

//function to calculate loan percentage and date
function loanperc()
{  
    var loancal = document.forms[0];
    var d = loancal.day.options[loancal.day.selectedIndex].value;
    var m = loancal.mon.options[loancal.mon.selectedIndex].value;
    var y = loancal.year.value;
    
    var d1 = loancal.day1.options[loancal.day1.selectedIndex].value;
	var m1 = loancal.mon1.options[loancal.mon1.selectedIndex].value;
    var y1 = loancal.year1.value;
    var fd1 = parseInt(loancal.amount.value);
    
    if(loancal.day.options[loancal.day.selectedIndex].value==0)
    {
        alert("Date Field cannot be empty");
        loancal.day.focus();
        return false;
    }
    if(loancal.mon.options[loancal.mon.selectedIndex].value==0)
    {
        alert("Month Field cannot be empty ");
        loancal.mon.focus();
        return false;
    }
    if ((m == 4 || m == 6 || m == 9 || m == 11) && d == 31)
    {
        window.alert("Month "+ m +" doesn't have 31 days!")
        loancal.start.value="";
        loancal.end.value="";
        loancal.day.focus();
        return false;
    }
    if (m == 2)
    { // check for february 29th
        var isleap = (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));
        if (d > 29 || (d == 29 && !isleap))
        {
            window.alert("February " + y + " doesn't have " + d + " days!");
            loancal.start.value="";
            loancal.end.value="";
            loancal.day.focus();
            return false;
        }
    }
    if ((m1 == 4 || m1 == 6 || m1 == 9 || m1 == 11) && d1 == 31)
    {
        window.alert("Month "+ m1 +" doesn't have 31 days!")
        loancal.fixdate.value="";
        loancal.day1.focus();
        return false;
    }
    {
    if (m1 == 2)
    { // check for february 29th
        var isleap = (y1 % 4 == 0 && (y1 % 100 != 0 || y1 % 400 == 0));

        if (d1 > 29 || (d1 == 29 && !isleap))
        {
            window.alert("February " + y1 + " doesn't have " + d1 + " days!");
            loancal.fixdate.value="";
            loancal.day1.focus();
            return false;
        }
    }
    }
    
    if((!nullvalue(loancal.year) || ((loancal.year.value).length !=4) || (loancal.year.value<=0) || isNaN(loancal.year.value)))
    {
        alert("Please enter the year of opening of your PPF account");
        loancal.year.focus();
        return false;
    }
    if(parseInt(loancal.year.value)<1980 || parseInt(loancal.year.value)>2050)
    {
        alert("Year Field should be between 1980-2050");
        loancal.year.focus();
        return false;
    }
    if((!nullvalue(loancal.year1) || ((loancal.year1.value).length !=4) || (loancal.year1.value<=0) || isNaN(loancal.year1.value)))
    {
        alert("Please enter the date on which you wish to avail of a loan");
        loancal.year1.focus();
        return false;
    }
    if (isNaN(fd1))
    {
        alert("Please enter the balance in your PPF account");
        loancal.amount.focus();
        loancal.amount.select();
        return false;
    }
    
    m1 = parseInt(m1);
    var monVal = "";
	switch(m1){
	case 1:
		monVal = "Jan";
		break;
	case 2:
		monVal = "Feb";
		break;
	case 3:
		monVal = "Mar";
		break;
	case 4:
		monVal = "Apr";
		break;
	case 5:
		monVal = "May";
		break;
	case 6:
		monVal = "Jun";
		break;
	case 7:
		monVal = "Jul";
		break;
	case 8:
		monVal = "Aug";
		break;
	case 9:
		monVal = "Sep";
		break;
	case 10:
		monVal = "Oct";
		break;
	case 11:
		monVal = "Nov";
		break;
	case 12:
		monVal = "Dec";
		break
	default:
	}
	
	concDate1 = d1 +"-"+ monVal +"-" + y1;
    document.getElementById("PrecCal").style.display='inline';
	loancal.fixdate1.value = concDate1;
    loancal.LOAN.value = (0.25 * parseInt(loancal.amount.value));
}

//function to calculate date differences
function dateDiffDebt(dob,dob1)
{
    date1 = new Date(dob);
    date2 = new Date(dob1);
    diff  = new Date();
    diff.setTime((date1.getTime() - date2.getTime()));
    
    timediff = diff.getTime();
    weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
    timediff = weeks  * ( 1000 * 60 * 60 * 24 * 7);

    days  = Math.floor(timediff / (1000 * 60 * 60 * 24));
    timediff -= days * (1000 * 60 * 60 * 24);

    hours = Math.floor(timediff / (1000 * 60 * 60));
    timediff -= hours * (1000 * 60 * 60);

    mins = Math.floor(timediff / (1000 * 60));
    timediff -= mins * (1000 * 60);

    secs = Math.floor(timediff / 1000);
    timediff -= secs * 1000;

    difference = (weeks*7 + days)/365

    return difference; // form should never submit, returns false
}
/* PPF Loan */
function Riskpage()
{
 window.location = "RiskAnalyzer.aspx";
}

