function calculateEDU()
 {
 
   	 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 hide()
   {
     // hid.style.display = 'none';
     document.getElementById("emi").value="";
   }
   
function show()
   {
      hid.style.display = '';
   } 
function calculateWED() 
{
    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;
    }
}
function cl_calculateSAV()
	{
	  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.form1.CL_age.value,10);
	  //alert(CL_age);
	  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 more 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.getElementById("emi").value=Math.round((CL_remain*CL_roi)/(Math.pow((1+CL_roi),CL_tenure*12)-1));
		document.layers['result'].document.getElementById("CL_fv").value=Math.round(CL_fv);
		document.layers['result'].document.getElementById("CL_current1").value=Math.round(CL_tp+CL_current*Math.pow((1+CL_roi1),CL_tenure));


		}
		else
		{
		document.getElementById("emi").value=Math.round((CL_remain*CL_roi)/(Math.pow((1+CL_roi),CL_tenure*12)-1));
		document.getElementById("CL_fv").value=Math.round(CL_fv);
		document.getElementById("CL_current1").value=Math.round(CL_tp+CL_current*Math.pow((1+CL_roi1),CL_tenure));
       }
	}
}

var CL_viewHide;
if (document.layers) {
visible = 'show';

hidden = 'hide';

} else if (document.all) {

visible = 'visible';

hidden = 'hidden';

}

function cl_check(fld,typ)
{
if(typ=="int")
{
	if(isNaN(fld.value))
	{
	alert('Please enter a Number in the given field');
	fld.focus();
	}
}
}

function CL_display(viewShow)
 {
   if (document.layers) 
   {
      content = document.layers[viewShow];
   }
  else if (document.all) 
 {
   content = document.all(viewShow).style;
 }
//alert(content.visibility)

content.visibility = visible;



}

function CL_hid(viewShow) {
if (document.layers) {

content = document.layers[viewShow];

} else if (document.all) {

content = document.all(viewShow).style;

}


content.visibility = hidden;



}

function cl_validateSAV(frm)
{
   	if(isNaN(parseFloat(document.getElementById("CL_age").value))||parseFloat(document.getElementById("CL_age").value)<=0)
	{
	alert('Your age should be greater than 0 years');
	document.getElementById("CL_age").focus();
	return false;
	}
	if(isNaN(parseFloat(document.getElementById("CL_ret").value))||parseFloat(document.getElementById("CL_ret").value)<=parseFloat(document.getElementById("CL_age").value))
	{
	alert('Retirement age should be greater than your current age');
	frm.CL_ret.focus();
	return false;
	}
	if(isNaN(parseFloat(document.getElementById("CL_current").value))||parseFloat(parseFloat(document.getElementById("CL_current").value))<0)
	{
		alert('Your current savings should be greater than 0');
		document.getElementById("current").focus();
		return false;
	}
	if(isNaN(parseFloat(document.getElementById("CL_retamt").value))||parseFloat(parseFloat(document.getElementById("CL_retamt").value))<0)
	{
		alert('Your retirement amount should be greater than or equal to 0');
		document.getElementById("CL_retamt").focus();
		return false;
	}
	if(isNaN(parseFloat(document.getElementById("CL_msav").value))||parseFloat(parseFloat(document.getElementById("CL_msav").value))<0)
	{
		alert('Monthly savings should be greater than or equal to 0');
		document.getElementById("CL_msav").focus();
		return false;
	}

	if(isNaN(parseFloat(document.getElementById("CL_roi").value))||parseFloat(parseFloat(document.getElementById("CL_roi").value))<0)
	{
		alert('Rate of return on your investment should be greater than 0');
		document.getElementById("CL_roi").focus();
		return false;
	}
	if(isNaN(parseFloat(document.getElementById("CL_inf").value))||parseFloat(parseFloat(document.getElementById("CL_inf").value))<0)
	{
		alert('Rate of inflation should be greater than 0');
		document.getElementById("CL_inf").focus();
		return false;
	}

	return true;
}

function cl_validate1(frm)
{
if(isNaN(parseFloat(document.getElementById("age").value))||parseFloat(document.getElementById("age").value)<=0)
{
alert('Age should be greater than 0');
document.getElementById("age").focus();
return false;
}
if(isNaN(parseFloat(document.getElementById("ret").value))||parseFloat(document.getElementById("ret").value)<=parseFloat(document.getElementById("age").value))
{
alert('Retirement age should be greater than your age');
document.getElementById("ret").focus();
return false;
}
if(isNaN(parseFloat(document.getElementById("CL_current").value))||parseFloat(document.getElementById("CL_current").value)<0)
{
alert('Your current savings should be greater than or equal to 0');
document.getElementById("CL_current").focus();
return false;
}
if(isNaN(parseFloat(document.getElementById("mon").value))||parseFloat(document.getElementById("mon").value)<0)
{
alert('Monthly savings should be greater than or equal to 0');
document.getElementById("mon").focus();
return false;
}
if(isNaN(parseFloat(document.getElementById("CL_roi").value))||parseFloat(document.getElementById("CL_roi").value)<=0)
{
alert('Return on your investment should be greater than 0');
document.getElementById("CL_roi").focus();
return false;
}
return true;
}
	function cl_calculate1()
     {
        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 cl_check');
    	}

    }
	function draw()
	{
		var ary=Array()
        CL_roi=5/1200;
		cl_calculate1();
        var CL_val8=CL_val;
        var divide=1;
        divide=CL_val/15;
        CL_roi=21/1200;
        cl_calculate1();
        var CL_val21=CL_val;
        var ht=400;
        CL_roi=parseFloat(document.getElementById("CL_roi").value,10)/1200;
        cl_calculate1();
        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_calculate1();
      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 color=#000000>Back</font></a></td></tr></table>');
CL_win.document.write('<table><tr><td><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>');

}

var CL_viewHide;
if (document.layers) {
visible = 'show';

hidden = 'hide';

} else if (document.all) {

visible = 'visible';

hidden = 'hidden';

}

//costofliving
function CL_vlidatecost(frm)
{
	if(isNaN(parseFloat(document.getElementById("CL_infexp").value))||parseFloat(document.getElementById("CL_infexp").value)<=0)
    {
        alert('Expenses should be greater than 0');
        document.getElementById("CL_infexp").focus();
        return false;
    }
    if(isNaN(parseFloat(document.getElementById("CL_ninfexp").value))||parseFloat(document.getElementById("CL_ninfexp").value)<0)
    {
        alert('Expenses should be greater than or equal to 0');
        document.getElementById("CL_ninfexp").focus();
        return false;
    }
    if(isNaN(parseFloat(document.getElementById("CL_col").value))||parseFloat(document.getElementById("CL_col").value)<0)
    {
        alert('Year should be greater than or equal to 0');
        document.getElementById("CL_col").focus();
        return false;
    }   
    if(isNaN(parseFloat(document.getElementById("CL_incinf").value))||parseFloat(document.getElementById("CL_incinf").value)<0)
    {
        alert('Increase should be greater than or equal to 0');
        document.getElementById("CL_incinf").focus();
        return false;
    }
    if(isNaN(parseFloat(document.getElementById("CL_decinf").value))||parseFloat(document.getElementById("CL_decinf").value)<0)
    {
        alert('Decrease should be greater than or equal to 0');
        document.getElementById("CL_decinf").focus();
        return false;
    }
    if(isNaN(parseFloat(document.getElementById("CL_nincinf").value))||parseFloat(document.getElementById("CL_nincinf").value)<0)
    {
        alert('Increase should be greater than or equal to 0');
        document.getElementById("CL_nincinf").focus();
        return false;
    }
    if(isNaN(parseFloat(document.getElementById("CL_ndecinf").value))||parseFloat(document.getElementById("CL_ndecinf").value)<0)
    {
        alert('Decrease should be greater than or equal to 0');
        document.getElementById("CL_ndecinf").focus();
        return false;
    }
    if(isNaN(parseFloat(document.getElementById("CL_inf").value))||parseFloat(document.getElementById("CL_inf").value)<0)
    {
        alert('Decrease should be greater than or equal to 0');
        document.getElementById("CL_inf").focus();
        return false;
    }
    return true;
}


function cl_calculatecost()           
{
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;
}
if(document.all)
{
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);
}
if (document.layers)
{

}
}

var CL_viewHide;
if (document.layers) {
visible = 'show';

hidden = 'hide';

} else if (document.all) {

visible = 'visible';

hidden = 'hidden';

}
//Wealthretire

 function cl_calculatewealth()
{                                      
var CL_current;
var CL_roi;
var CL_tenure;
var CL_vl;

CL_tenure=(parseFloat(document.getElementById("ret").value,10)-parseFloat(document.getElementById("age").value,10));
CL_current=parseFloat(document.getElementById("CL_current").value,10);
CL_roi=Math.pow(parseFloat(document.getElementById("CL_roi").value,10)/100 +1,1/12)-1;
if (CL_roi==0) CL_roi=0.00000001;
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);
	if(isNaN(CL_vl))
	{
		alert('One or more of the numeric fields are wrong. Please Check');
	}
	else
	{
		if(document.all)
		{
		document.getElementById("CL_emi").value=Math.round(CL_vl);
		}
		if(document.layers)
		{
		document.layers['result'].document.getElementById("CL_emi").value=Math.round(CL_vl);
		}
	}

}

var CL_viewHide;
if (document.layers) {
visible = 'show';

hidden = 'hide';

} 
else if (document.all) {

visible = 'visible';

hidden = 'hidden';

}

function CL_vlidatewealth(frm)
{
if(isNaN(parseFloat(document.getElementById("age").value))||parseFloat(document.getElementById("age").value)<=0)
{
alert('Your age should be greater than 0');
document.getElementById("age").focus();
return false;
}
if(isNaN(parseFloat(document.getElementById("ret").value))||parseFloat(document.getElementById("ret").value)<=parseFloat(document.getElementById("age").value))
{
alert('Your retirement age should be greater than your present age');
document.getElementById("ret").focus();
return false;
}
if(isNaN(parseFloat(document.getElementById("ret").value))||parseFloat(document.getElementById("ret").value)<=parseFloat(document.getElementById("age").value))
{
alert('Your retirement age should be greater than your present age');
document.getElementById("ret").focus();
return false;
}
if(isNaN(parseFloat(document.getElementById("CL_current").value))||parseFloat(document.getElementById("CL_current").value)<0)
{
alert('Current savings should be greater than or equal to 0');
document.getElementById("CL_current").focus();
return false;
}
if(isNaN(parseFloat(document.getElementById("CL_mon").value))||parseFloat(document.getElementById("CL_mon").value)<0)
{
alert('Monthly savings should be greater than or equal to 0');
document.getElementById("CL_mon").focus();
return false;
}
if(isNaN(parseFloat(document.getElementById("CL_roi").value))||parseFloat(document.getElementById("CL_roi").value)<0)
{
alert('Return on your investments should be greater than or equal to 0');
document.getElementById("CL_roi").focus();
return false;
}

return true;
}


function cl_validateHRA(frm)
{
	if(isNaN(parseFloat(document.getElementById("CL_rent").value))||parseFloat(document.getElementById("CL_rent").value)<0)
	{
		alert('Rent should be greater than or equal to 0.');
		document.getElementById("CL_rent").focus();
		return false;
	}
	if(isNaN(parseFloat(document.getElementById("CL_basic").value))||parseFloat(document.getElementById("CL_basic").value)<=0)
	{
		alert('Basic salary should be greater than or equal to 0');
		document.getElementById("CL_basic").focus();
		return false;
	}
	if(isNaN(parseFloat(document.getElementById("CL_da").value))||parseFloat(document.getElementById("CL_da").value)<0)
	{
		alert('DA should be greater than or equal to 0.');
		document.getElementById("CL_da").focus();
		return false;
	}
	if(isNaN(parseFloat(document.getElementById("CL_hra").value))||parseFloat(document.getElementById("CL_hra").value)<0)
	{
		alert('HRA should be greater than or equal to 0.');
		document.getElementById("CL_hra").focus();
		return false;
	}

	return true;
}


function cl_calculateHRA()
{

var CL_hra=parseFloat(document.getElementById("CL_hra").value);
var CL_rent=parseFloat(document.getElementById("CL_rent").value);
var CL_basic=parseFloat(document.getElementById("CL_basic").value);
var CL_da=parseFloat(document.getElementById("CL_da").value);
var CL_metro=0.5;
var CL_sav=0;                          

//if(document.getElementById("CL_city").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.all)
{

document.borrow.hra.value=CL_sav;
}
if(document.layers)
{

document.layers['result'].document.borrow.hra.value=CL_sav;

}

}

var CL_viewHide;
if (document.layers) {
visible = 'show';

hidden = 'hide';

} else if (document.all) {

visible = 'visible';

hidden = 'hidden';

}
function cl_validatecap(frm)
{
	if(!document.getElementById("ival").value||document.getElementById("ival").value<=0)
	{
		alert('Investment value should be greater than 0.');
		document.getElementById("ival").focus();
		return false;
	}
	if(!document.getElementById("CL_sval").value||document.getElementById("CL_sval").value<=0)
	{
		alert('Sale / Maturity value should be greater than 0');
		document.getElementById("CL_sval").focus();
		return false;
	}

	return true;
}

function cl_calculatecap()
{
var CL_ival;
var CL_byr;            
var CL_sval;
var CL_syr;
var CL_itax=0;
var CL_tax=0;
CL_ival=parseFloat(document.getElementById("ival").value,10);
CL_byr=parseFloat(document.getElementById("CL_byr").options[document.getElementById("CL_byr").selectedIndex].value,10);
CL_sval=parseFloat(document.getElementById("CL_sval").value,10);
CL_syr=parseFloat(document.getElementById("CL_syr").options[document.getElementById("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<CL_byr)
{
alert('the sale year should come after the investment year');
return ;
}
else if(CL_syr =="0" ||CL_byr == "0")
{
    alert("W.e.f 1-10-2004, Securities Transaction Tax (STT) is Applicable...So Long Term Capital Gains tax is NIL ")
    return;
}
else 
{
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'].document.cl_borrow.cl_emi.value=Math.round(CL_tax);
		document.layers['result'].document.cl_borrow.cl_emi1.value=Math.round(CL_sval-CL_ival);
		}
		else
		{
		document.cl_borrow.cl_emi.value=Math.round(CL_tax);
		document.cl_borrow.cl_emi1.value=Math.round(CL_sval-CL_ival);
		}
	}

}
}

var CL_viewHide;
if (document.layers) {
visible = 'show';

hidden = 'hide';

} else if (document.all) {

visible = 'visible';

hidden = 'hidden';

}

function cl_validatetax(frm)
{
	var CL_amount=document.getElementById("amt").value;

	if(isNaN(CL_amount)||CL_amount<0)
	{
	    alert('Investment amount should be greater than 0');
	    document.cl_tool.amt.focus();
	    return false;
	}
    var CL_roi2=document.getElementById("CL_roi2").value;
    if(isNaN(CL_roi2)||CL_roi2<=0)
    {
	    alert('Return on Investment should be greater than 0');
	    document.getElementById("CL_roi2").focus();
	    return false;
    }
    var CL_roi1=document.getElementById("CL_roi1").value;
    if(isNaN(CL_roi1)||CL_roi1<=0)
    {
	    alert('Return on Investment should be greater than 0');
	    document.getElementById("CL_roi2").focus();
	    return false;
    }

    var CL_t2=document.getElementById("CL_t2").value;

    if(isNaN(CL_t2)||CL_t2<=0)
    {
	    alert('Tenure of Investment should be greater than 0');
	    document.getElementById("CL_t2").focus();
	    return false;
    }
    var CL_tax=parseFloat(document.getElementById("CL_tax").value);
    if(isNaN(CL_tax)||CL_tax<0||CL_tax>35)
    {
	    alert('Tax should be greater than 0 or less than 36');
	    document.getElementById("CL_tax").focus();
	    return false;
    }
    return true;
}

function cl_calculatetax()
{                                          
    var CL_amount=document.getElementById("amt").value;

    var CL_t2=parseFloat(document.getElementById("CL_t2").value);
    var CL_roi2=parseFloat(document.getElementById("CL_roi2").value)/100;
    var CL_roi1=parseFloat(document.getElementById("CL_roi1").value)/100;
    var CL_comp1=parseFloat(document.getElementById("CL_comp1").options[document.getElementById("CL_comp1").options.selectedIndex].value);
    var CL_comp2=parseFloat(document.getElementById("CL_comp2").options[document.getElementById("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);
    //alert(CL_rt1*100)
    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'].document.borrow.CL_avn.value=CL_material1;
    document.layers['result'].document.borrow.CL_tax.value=Math.round((CL_rt1)*10000)/100;
    document.layers['result'].document.borrow.CL_ntax.value=Math.round((CL_rt2-1)*10000)/100;
    }
    if (document.all)
    {
    document.borrow.CL_avn.value=CL_material1;
    document.borrow.CL_tax.value=Math.round((CL_rt1)*10000)/100;
    document.borrow.CL_ntax.value=Math.round((CL_rt2-1)*10000)/100;

    }
    }

    var CL_viewHide;
    if (document.layers) {
    visible = 'show';

    hidden = 'hide';

    } else if (document.all) {

    visible = 'visible';

    hidden = 'hidden';

}

	
	 function MM_openBrWindow(theURL,winName,features) {
        window.open(theURL,winName,features);
        }
		function isBlank(s)
		{
			var len=s.length
			var i;
			for(i=0;i<len;i++)
			{
				if(s.charAt(i) !=" ") return false;
			}
	       return true;
		}
		function Val(x)
		{
			if(isNaN(document.form1.elements[x].value))
			{
				alert("Please Enter a Numeric Value");
				document.form1.elements[x].value="";
				document.form1.elements[x].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";
				}
			}
				if(parseInt(val,10)!='00')
				{
					document.form1.total.value=val;
				}
				else
				{
					if(sumFlag !="TRUE")
					{
						document.form1.total.value="";
					}
					else
					{
						document.form1.total.value=val;
					}
				}
			}
		}
		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;
					}
			}
			
	//future value calculator
	
	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();     
   
   
   }
   
   function calculateFVG()
	 {
	   var A = document.getElementById("pvalue").value;
	   A = A.replace(/,/,"");
	   var B = document.getElementById("tenure").value;
	   var C = document.getElementById("comprate").value;
	   C = C.replace(/,/,"");
	  document.getElementById("fvalue").value = Math.round(A*Math.pow(1+C/100,B));
	   formatNumber('pvalue');
	   formatNumber('comprate');
	   formatNumber('fvalue');
	 }		
	 
	 function hideFV()
   {
     // hid.style.display = 'none';
     document.getElementById("fvalue").value="";
   }
   
   //sip need calculator
   
   function formatNumberSN(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();     
   }
  
  
  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);
   } 
  
 function cl_calculateSN()
   {
   	var cl_amtpermonth = (document.getElementById("amtpermonth").value);
	cl_amtpermonth = cl_amtpermonth.replace(/,/,"");
	var cl_tenure = (document.getElementById("tenure").value);
	var cl_returns = (document.getElementById("returns").value); 
	cl_returns =  cl_returns.replace(/,/,"");
	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.getElementById("emi").value= -famt;
	var famt1= (cl_tenure*12*cl_amtpermonth);
	document.getElementById("CL_fv").value = famt1;
	var finalvalue = -(famt/famt1) +'';
	document.getElementById("CL_current").value= finalvalue.substring(0,4);	
	formatNumberSN('amtpermonth');
	formatNumberSN('returns');
	formatNumberSN('emi');
	formatNumberSN('CL_fv');
	formatNumberSN('CL_current');
  }
  
  function hideall()
   {
      hid.style.display = 'none';
   }
   
   //Amount to be saved
   
function cl_calculateATS()
{
var CL_current;           
var CL_roi;
var CL_tenure;
var CL_remain;
var CL_fv;
var CL_cst;
var CL_inf;                 
var CL_tp;
var CL_sav;
CL_tenure=parseFloat(document.getElementById("CL_tenure").value,10);
CL_current=parseFloat(document.getElementById("CL_current").value,10);
CL_roi=parseFloat(document.getElementById("CL_roi").value,10)/1200;
CL_cst=parseFloat(document.getElementById("CL_cst").value);
CL_inf=parseFloat(document.getElementById("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(document.getElementById("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'].document.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'].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_roi*12),CL_tenure));
		if(CL_tp+CL_current*Math.pow((1+CL_roi*12),CL_tenure)<CL_fv)
		{
		document.layers['result'].document.borrow.extra.value=Math.round(CL_fv-CL_tp-CL_current*Math.pow((1+CL_roi*12),CL_tenure));
		}
		else
		{
		document.layers['result'].document.borrow.extra.value=0
		}
		}
		else
		{
		document.borrow.CL_emi.value=Math.max(Math.round((CL_remain*CL_roi)/(Math.pow((1+CL_roi),CL_tenure*12)-1)),0);
		document.borrow.CL_fv.value=Math.round(CL_fv);
		document.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.borrow.extra.value=Math.round(CL_fv-CL_tp-CL_current*Math.pow((1+CL_roi*12),CL_tenure));
		}
		else
		{
		document.borrow.extra.value=0;
		}
		}
	}
}

var CL_viewHide;
if (document.layers) {
visible = 'show';

hidden = 'hide';

} else if (document.all) {

visible = 'visible';

hidden = 'hidden';

}

function cl_validateATS(frm)
{
	if(isNaN(parseFloat(document.getElementById("CL_current").value))||parseFloat(document.getElementById("CL_current").value)<0)
	{
		alert('Savings should be greater than or equal to 0.');
		document.getElementById("CL_current").focus();
		return false;
	}
	if(isNaN(parseFloat(document.getElementById("CL_cst").value))||parseFloat(document.getElementById("CL_cst").value)<=0)
	{
		alert('Cost should be greater than or equal to 0');
		document.getElementById("CL_cst").focus();
		return false;
	}
	if(isNaN(parseFloat(document.getElementById("CL_tenure").value))||parseFloat(document.getElementById("CL_tenure").value)<=0)
	{
		alert('Period should be greater than 0.');
		document.getElementById("CL_tenure").focus();
		return false;
	}
	if(isNaN(parseFloat(document.getElementById("CL_roi").value))||parseFloat(document.getElementById("CL_roi").value)<=0)
	{
		alert('Return on investment should be greater than 0.');
		document.getElementById("CL_roi").focus();
		return false;
	}
	if(isNaN(parseFloat(document.getElementById("CL_sav").value))||parseFloat(document.getElementById("CL_sav").value)<0)
	{
		alert('Your monthly savings should be greater than or equal to 0.');
		document.getElementById("CL_sav").focus();
		return false;
	}
	if(isNaN(parseFloat(document.getElementById("CL_inf").value))||parseFloat(document.getElementById("CL_inf").value)<0)
	{
		alert('Inflation should be greater than or equal to 0');
		document.getElementById("CL_inf").focus();
		return false;
	}
	return true;
	}
	
	// Saving Million
	
	function cl_calculateSAM()
{
var CL_current;
var CL_roi;                               
var CL_tenure;
var CL_remain;
CL_tenure=parseFloat(document.getElementById("CL_tenure").value,10);
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;
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'].document.getElementById("CL_emi").value=Math.round((CL_remain*CL_roi)/(Math.pow((1+CL_roi),CL_tenure*12)-1));
		}
		else
		{
		document.getElementById("CL_emi").value=Math.round((CL_remain*CL_roi)/(Math.pow((1+CL_roi),CL_tenure*12)-1));
		}
	}
}

var CL_viewHide;
if (document.layers) {
visible = 'show';

hidden = 'hide';

} else if (document.all) {

visible = 'visible';

hidden = 'hidden';

}




function cl_validateSAM(frm)
{
	if(isNaN(parseFloat(document.getElementById("CL_current").value))||parseFloat(document.getElementById("CL_current").value)<0)
	{
		alert('Your savings should be greater than or equal to 0.');
		document.getElementById("CL_current").focus();
		return false;
	}
	if(isNaN(parseFloat(document.getElementById("CL_tenure").value))||parseFloat(document.getElementById("CL_tenure").value)<=0)
	{
		alert('The period should be greater than 0.');
		document.getElementById("CL_tenure").focus();
		return false;
	}
	if(isNaN(parseFloat(document.getElementById("CL_roi").value))||parseFloat(document.getElementById("CL_roi").value)<=0)
	{
		alert('Rate of interest should be greater than 0.');
		document.getElementById("CL_roi").focus();
		return false;
	}
	return true;
}

