function CurrencyFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	amount = "£" + amount;
	return amount;
}

function sicknesscalc()
{
	var sector = parseFloat(document.forms[0].sector.value);
	var employees = parseFloat(document.forms[0].employees.value);
	var avgsal = parseFloat(document.forms[0].avgsal.value);
	var bonus = parseFloat(document.forms[0].bonus.value);
	var prp = parseFloat(document.forms[0].prp.value);
	var pension = parseFloat(document.forms[0].pension.value);
	var bens = parseFloat(document.forms[0].bens.value);
	var nic = (avgsal+bonus+prp)-5044.52;
		if (nic<0) {
			nic=0
		} else {
			nic = (nic/100)*12.8;
		}
	document.forms[0].nic.value = CurrencyFormatted(nic.toFixed(2));
	var avgcost = avgsal+bonus+prp+pension+bens+nic;
	document.forms[0].avgcostee.value = CurrencyFormatted(avgcost.toFixed(2));
	var totalcost= avgcost*employees;
	document.forms[0].avgcosttot.value = CurrencyFormatted(totalcost.toFixed(2));
	var totcost = (sector*employees)*(avgcost/365);
	document.forms[0].dayslost.value = sector.toFixed(2);
	document.forms[0].illcosttot.value = CurrencyFormatted(totcost.toFixed(2));
	var costee = totcost/employees;
	document.forms[0].illcostee.value = CurrencyFormatted(costee.toFixed(2));
	var percent = ((costee/avgcost)*100).toFixed(2);
	percent = percent + "%";
	document.forms[0].percost.value = percent;
	document.forms[0].bonus.value = CurrencyFormatted(bonus.toFixed(2));
	document.forms[0].prp.value = CurrencyFormatted(prp.toFixed(2));
	document.forms[0].pension.value = CurrencyFormatted(pension.toFixed(2));
	document.forms[0].bens.value = CurrencyFormatted(bens.toFixed(2));
	document.forms[0].avgsal.value = CurrencyFormatted(avgsal.toFixed(2));
}