// Javascript
var res;

var error_start='<table width="200" border="0" cellspacing="0" cellpadding="0"><tr><td width="20" height="20" valign="top"><img src="images/error.gif" width="16" height="16"></td><td width="5"></td><td class="div_error">';
var error_end='</td></tr></table>';
function time_required(){
	var E = document.frm.a.value;
	var a = document.frm.b.value;
	var z = document.frm.c.value;
	var r = Math.pow((1+z/100),(1/12));
	t = Math.log(1 + E*(r-1)/a)/Math.log(r);
	res = t.toFixed(1);
	//res = Math.round(t);
}
function calc_timereq(){
	if (IsEmpty(document.frm.a,'text'))
		{
			//alert("Please Loan price");document.frm.a.focus();return false;
			is_error=true;
			thorw_error("Please enter the amount required.","div_loanamt");document.frm.timereq.value ='';
		}
		else if(ValidateNo(document.frm.a.value,"0"))
		{
			is_error=true;
			thorw_error("Please enter a valid amount required.","div_loanamt");document.frm.timereq.value ='';
			
		}
		else
		{
			if(!ValidateNo(document.frm.a.value,"1234567890."))
			{
				//alert("Invalid Loan price");document.frm.a.focus();return false;
				is_error=true;
				thorw_error("Please enter a valid amount required.","div_loanamt");document.frm.timereq.value ='';
			}
			else
			{
				hide_div("div_loanamt");	
			}
		}
		
		if (IsEmpty(document.frm.b,'text'))
		{
			is_error=true;
			//alert("Please enter an Rate of interest");document.frm.b.focus();return false;
			thorw_error("Please enter your monthly savings.","div_rateofint");document.frm.timereq.value ='';
		}
		else if(ValidateNo(document.frm.b.value,"0"))
		{
			is_error=true;
			thorw_error("Please enter valid monthly savings.","div_rateofint");document.frm.timereq.value ='';
			
		}
		else
		{
			if(!ValidateNo(document.frm.b.value,"1234567890."))
			{
				is_error=true;
				thorw_error("Please enter valid monthly savings.","div_rateofint");document.frm.timereq.value ='';
				//alert("Invalid Rate of interest");document.frm.b.focus();return false;
			}
			else
			{
				hide_div("div_rateofint");	
			}
		}

		if (IsEmpty(document.frm.c,'text'))
		{
			is_error=true;
			//alert("Please enter loan period ");document.frm.c.focus();return false;
			thorw_error("Please enter the rate of return that you are likely to get on your savings.","div_period");document.frm.timereq.value ='';
		}
		else if(ValidateNo(document.frm.c.value,"0"))
		{
			is_error=true;
			thorw_error("Please enter the valid rate of return that you are likely to get on your savings. ","div_period");document.frm.timereq.value ='';
			
		}
		else
		{
			if(!ValidateNo(document.frm.c.value,"1234567890."))
			{
				is_error=true;
				//alert("Invalid loan period ");document.frm.c.focus();return false;
				thorw_error("Please enter the valid rate of return that you are likely to get on your savings. ","div_period");		document.frm.timereq.value ='';
			}
			else
			{
				hide_div("div_period");	
			}
		} 
		time_required();
		if(res!='NaN' && res!='Infinity'){
		document.frm.timereq.value = res;
		}
	return false;
}
function thorw_error(error_txt,div_id)
{
	var DivObj = (document.getElementById(div_id)) ? document.getElementById(div_id) : new Object;
	DivObj.innerHTML = error_start+error_txt+error_end;
	DivObj.style.display="";
}

function IsNumeric(obj)
   //  check for valid numeric strings 
   {
   var strValidChars = "0123456789";
   var strChar;
   var strChar_int='';
   var blnResult = true;
   var strString=obj.value;	
   var dpos=strString.indexOf(".");
   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
      {
         blnResult = false;
		 strChar_int=strString.substr(0,dpos);
		 obj.value=strChar_int;
		 break;
       }
	   
      }
   //return blnResult;
   }
   
   function hide_div(div_id)
{
	var DivObj = (document.getElementById(div_id)) ? document.getElementById(div_id) : new Object;
	//DivObj.innerHTML = error_start+error_txt+error_end;
	DivObj.style.display='none';
}
