function calc_totals(theform, decimalSeparator, thousandSseparator, swapSeparators)
{
	if (swapSeparators)
	{
		var temp = decimalSeparator;
		decimalSeparator = thousandSseparator;
		thousandSseparator = temp;
	}
	var totalInputCost = Number(theform.m2.value * theform.costperm2.value);
	theform.totalcostinput.value = addSeparatror(totalInputCost,decimalSeparator,thousandSseparator);
	
	var totalpercent = 0;
	var totalcost = 0;
	var count;
	var itemCost;
	for (count=1; count<19;count++)
	{
		itemCost = Math.round(eval('theform.item'+count).value * totalInputCost / 100);
		eval('theform.itemcost'+count).value = addSeparatror(itemCost,decimalSeparator,thousandSseparator);
		totalcost = totalcost + itemCost;
	}

	for (count=1; count<19;count++)
	{
		totalpercent = totalpercent + Number(eval('theform.item'+count).value);
	}
	theform.totalpercent.value = totalpercent;
	theform.totalcost.value = addSeparatror(totalcost,decimalSeparator,thousandSseparator);
	
	if (totalpercent != 100)
		document.getElementById('totalpercenttd').style.backgroundColor='red';
	else
		document.getElementById('totalpercenttd').style.backgroundColor='#370CC4';
	return true;
}
function addSeparatror(nStr, decimalSeparator, thousandSseparator)
{
	nStr += '';
	x = nStr.split(decimalSeparator);
	x1 = x[0];
	x2 = x.length > 1 ? decimalSeparator + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + thousandSseparator + '$2');
	}
	return x1 + x2;
}
