var totalw;
var totalm;
var exptotalw;
var exptotalm;

function process()
{
	totalw = 0;
	totalm = 0;
	exptotalw = 0;
	exptotalm = 0;
	
	incomeWeek();
	incomeMonth();
	expWeek();
	expMonth();
	calculator();
}

function incomeWeek()
{

//weekly income calculation
var allEls=document.getElementsByName("incomeweek[]");
var number = allEls.length;
//var total=0;
for(var j=0;j<number;j++)
{
	if(isNaN (allEls[j].value))
	{
		alert('Please enter a valid amount');
		allEls[j].focus();
	}
	else
	{
	totalw += new Number (allEls[j].value);
	}
}
document.inexp.totalw.value = totalw;

}

function incomeMonth()
{
//monthly income calculation
var allEls=document.getElementsByName("incomemonth[]");
var number = allEls.length;
//var total=0;
for(var j=0;j<number;j++)
{
	if(isNaN (allEls[j].value))
	{
		alert('Please enter a valid amount');
		allEls[j].focus();
	}
	else
	{
	totalm += new Number (allEls[j].value);
	}
}
document.inexp.totalm.value = totalm;
}

function expWeek()
{
//weekly expenditure calculation
var allEls=document.getElementsByName("expweek[]");
var number = allEls.length;
//var total=0;
for(var j=0;j<number;j++)
{
	if(isNaN (allEls[j].value))
	{
		alert('Please enter a valid amount');
		allEls[j].focus();
	}
	else
	{
	exptotalw += new Number (allEls[j].value);
	}
}
document.inexp.totalexpw.value = exptotalw;
}

function expMonth()
{
//weekly expenditure calculation
var allEls=document.getElementsByName("expmonth[]");
var number = allEls.length;
//var total=0;
for(var j=0;j<number;j++)
{
	if(isNaN (allEls[j].value))
	{
		alert('Please enter a valid amount');
		allEls[j].focus();
	}
	else
	{
	exptotalm += new Number (allEls[j].value);
	}
}
document.inexp.totalexpm.value = exptotalm;
}

function calculator()
{
totincome = ((totalw*4.13)+totalm);
totincome = totincome.toFixed(2);
document.inexp.totincome.value = totincome;

totExp = ((exptotalw*4.13)+exptotalm);
totExp = totExp.toFixed(2);
document.inexp.totExp.value = totExp;

disIncome = (totincome-totExp);
disIncome = disIncome.toFixed(2);
document.inexp.disIncome.value = disIncome;
}