function initCalculator()
{
	obj = findElement('frm_calculator');
	attachEvent('calc_selector','onchange',calculatorSwitch);

	attachEvent('calc_1_length','onkeypress',numberKeyOnly);
	attachEvent('calc_1_width','onkeypress',numberKeyOnly);
	attachEvent('calc_1_gsm','onkeypress',numberKeyOnly);
	attachEvent('calc_1_length','onkeyup',calculatorWeight);
	attachEvent('calc_1_width','onkeyup',calculatorWeight);
	attachEvent('calc_1_gsm','onkeyup',calculatorWeight);

	attachEvent('calc_2_length','onkeypress',numberKeyOnly);
	attachEvent('calc_2_width','onkeypress',numberKeyOnly);
	attachEvent('calc_2_kg','onkeypress',numberKeyOnly);
	attachEvent('calc_2_length','onkeyup',calculatorGrammage);
	attachEvent('calc_2_width','onkeyup',calculatorGrammage);
	attachEvent('calc_2_kg','onkeyup',calculatorGrammage);

	attachEvent('calc_3_sheets','onkeypress',numberKeyOnly);
	attachEvent('calc_3_kg','onkeypress',numberKeyOnly);
	attachEvent('calc_3_sheets','onkeyup',calculatorOrderWeight);
	attachEvent('calc_3_kg','onkeyup',calculatorOrderWeight);

	attachEvent('calc_4_kg','onkeypress',numberKeyOnly);
	attachEvent('calc_4_width','onkeypress',numberKeyOnly);
	attachEvent('calc_4_gsm','onkeypress',numberKeyOnly);
	attachEvent('calc_4_kg','onkeyup',calculatorOrderReel);
	attachEvent('calc_4_width','onkeyup',calculatorOrderReel);
	attachEvent('calc_4_gsm','onkeyup',calculatorOrderReel);

	attachEvent('calc_5_length','onkeypress',numberKeyOnly);
	attachEvent('calc_5_width','onkeypress',numberKeyOnly);
	attachEvent('calc_5_gsm','onkeypress',numberKeyOnly);
	attachEvent('calc_5_length','onkeyup',calculatorOrderSheetsTonne);
	attachEvent('calc_5_width','onkeyup',calculatorOrderSheetsTonne);
	attachEvent('calc_5_gsm','onkeyup',calculatorOrderSheetsTonne);

	attachEvent('calc_6_gsm','onkeypress',numberKeyOnly);
	attachEvent('calc_6_gsm','onkeyup',calculatorOrderSqmTonne);

	attachEvent('calc_7_price','onkeypress',numberKeyOnly);
	attachEvent('calc_7_gsm','onkeypress',numberKeyOnly);
	attachEvent('calc_7_price','onkeyup',calculatorOrderSqmPrice);
	attachEvent('calc_7_gsm','onkeyup',calculatorOrderSqmPrice);

	obj.reset();
}

function calculatorSwitch()
{
	selected = formGetValue('calc_selector');
	options = findFormElement('calc_selector').options;
	for (loop=options.length - 1;loop>=0;loop--)
	{
		value = valNum(options[loop].value);
		if (findElement('form_section_id_'+(value + 1)) && value > 0)
		{
			findElement('form_section_id_'+(value + 1)).style.display = ((value) == selected) ? 'block' : 'none';
		}
	}
}

function calculatorWeight(evt)
{
	obj = findEvtObj(evt);
	name = obj.name;
	orderLength = valNum(formGetValue('calc_1_length'));
	orderWidth = valNum(formGetValue('calc_1_width'));
	orderGSM = valNum(formGetValue('calc_1_gsm'));
	orderWeight = (orderLength * orderWidth * orderGSM) / 1000000;
	orderTotal = (orderGSM && orderLength && orderWidth) ? (orderLength * orderWidth * orderGSM) / 1000000 : '';
	formSetValue('calc_1_total',orderWeight);
	return true;
}

function calculatorGrammage(evt)
{
	obj = findEvtObj(evt);
	name = obj.name;
	orderLength = valNum(formGetValue('calc_2_length'));
	orderWidth = valNum(formGetValue('calc_2_width'));
	orderKg = valNum(formGetValue('calc_2_kg'));
	orderTotal = (orderKg && orderLength && orderWidth) ? (orderKg * 1000000) / (orderLength * orderWidth) : '';
	formSetValue('calc_2_total',orderTotal);
	return true;
}

function calculatorOrderWeight(evt)
{
	obj = findEvtObj(evt);
	name = obj.name;
	orderKg = valNum(formGetValue('calc_3_kg'));
	orderSheets = valNum(formGetValue('calc_3_sheets'));
	orderTotal = (orderKg && orderSheets) ? ((orderKg / 1000) * orderSheets) : '';
	formSetValue('calc_3_total',orderTotal);
	return true;
}

function calculatorOrderReel(evt)
{
	obj = findEvtObj(evt);
	name = obj.name;
	orderWidth = valNum(formGetValue('calc_4_width'));
	orderKg = valNum(formGetValue('calc_4_kg'));
	orderGSM = valNum(formGetValue('calc_4_gsm'));
	orderTotal = (orderKg && orderGSM && orderWidth) ? (orderKg * 1000000) / (orderGSM * orderWidth) : '';
	formSetValue('calc_4_total',orderTotal);
	return true;
}

function calculatorOrderSheetsTonne(evt)
{
	obj = findEvtObj(evt);
	name = obj.name;
	orderLength = valNum(formGetValue('calc_5_length'));
	orderWidth = valNum(formGetValue('calc_5_width'));
	orderGSM = valNum(formGetValue('calc_5_gsm'));
	orderTotal = (orderLength && orderGSM && orderWidth) ? (1000000 * 1000000) / (orderGSM * orderWidth * orderLength) : '';
	formSetValue('calc_5_total',orderTotal);
	return true;
}

function calculatorOrderSqmTonne(evt)
{
	obj = findEvtObj(evt);
	name = obj.name;
	orderGSM = valNum(formGetValue('calc_6_gsm'));
	orderTotal = (orderGSM) ? (1000000) / (orderGSM) : '';
	formSetValue('calc_6_total',orderTotal);
	return true;
}

function calculatorOrderSqmPrice(evt)
{
	obj = findEvtObj(evt);
	name = obj.name;
	orderPrice = valNum(formGetValue('calc_7_price'));
	orderGSM = valNum(formGetValue('calc_7_gsm'));
	orderTotal = (orderGSM && orderPrice) ? (orderPrice * orderGSM) / (1000000) : '';
	formSetValue('calc_7_total',orderTotal);
	return true;
}
