var curexpenses=0;
var inflation=0;
var timeperiod=0;

function validate()
{
 curexpenses =document.getElementById("curexpenses");
 inflation =document.getElementById("inflation");
 timeperiod =document.getElementById("timeperiod");

//  Current Expenses Validation




	
if(isEmpty(curexpenses.value)==true)
		{
			alert('Please enter your current Expenses Amount');
			curexpenses.focus();
			return false;
	   	}


	if((curexpenses.value.length > 0))
	{
			if(isInteger(curexpenses.value) == false){
			alert("Please enter valid current Expenses Amount");
			curexpenses.focus();
			curexpenses.select();
			return false;
			} 
	}


//validation for Inflation

   if(inflation.value.length >6){
	alert("Inflation Rate Field should not exceed 5 digits");
	inflation.focus();
	inflation.select();
	return false;
}else if(isNaN(inflation.value)){
	alert("Please enter only numbers in Inflation Rate field");
	inflation.focus();
	inflation.select();
	return false;
}
if(isEmpty(inflation.value)==true)
		{
			alert('Please enter Inflation Rate');
			inflation.focus();
			return false;
	   	}





//Time Period validation


	if(isEmpty(timeperiod.value)==true)
		{
			alert('Please enter your Time Period');
			timeperiod.focus();
			return false;
	   	}




	if((timeperiod.value.length > 0))
	{
			if(isInteger(timeperiod.value) == false){
			alert("Please enter valid Time Period");
			timeperiod.focus();
			timeperiod.select();
			return false;
			} 
	}


		if(timeperiod.value >99){
		alert('Please enter valid Time Period');
		timeperiod.select();
		timeperiod.focus();
		return false;
		}


currentexpenses();

}

function currentexpenses()
{

	curval=document.getElementById("curexpenses").value;
	indexval=document.getElementById("inflation").value;
	timeval=document.getElementById("timeperiod").value;

	var curtot=curval;
	indexval = indexval/100;	
	//calulates the rate after period of time
	 indexval = 1 + indexval;	

	indexval = Math.pow(indexval,timeval)
	curtot=curval*indexval;
	curtot=Math.round(curtot);
	document.getElementById("result").style.display="";
	futexptot.innerHTML="<b class='success'> Rs."+curtot+"</b>";
    inflationid.innerHTML="<b class='success'>"+document.getElementById("inflation").value+"%&nbsp;</b>";
	yearid.innerHTML="<b class='success'>"+document.getElementById("timeperiod").value+"</b>";
}

/* Additional Sum Assured Required
var cpro=0;
function Addionalsumassured()
{

 Acashinflows.innerHTML = cashinflow; 
 totliability.innerHTML = liabilitys; 
 totassets.innerHTML = asset; 

  
var insincome=document.getElementById("increaseincome").value;

var income=parseInt(insincome)/100;



if(parseInt(insincome) < 8)
	{
cpro=Math.round((((Math.pow(((1+income)/1.08),25))-1)/(((1+income)/1.08)-1))*cashinflow,0);
	}
 else
	{

	var CII=parseInt(retireage.value)-parseInt(age.value);
     cpro =Math.round(CII*cashinflow);
	}

 cpros.innerHTML = cpro; 




}


function AddisumFinal()
{

var exsumassure=document.getElementById("exsumassured").value;

var Addisumassure=Math.round(cpro+liabilitys-asset-exsumassure);

nameid.innerHTML=name.value;
addisumassured.innerHTML=Addisumassure;
totsumassuredreq.innerHTML=Addisumassure;
}*/

//Empty Text validation

function isEmpty(s){ 
	return ((s == null) || (s.length == 0))
}
var reInteger = /^\d+$/
function isInteger(s){
	var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    return reInteger.test(s)
}


// Number Validation

function isInteger(s){
	var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    return reInteger.test(s)
}

function test1(str) {
str = alltrim(str);
return /^[-+]?[0-9]+(\.[0-9]+)?$/.test(str);
}
