﻿
var sumRow1 = 0;
var sumRow2 = 0;
var sumRow3 = 0;

function clearAll()
{
	with (document.form1)
	{
		input1a.value = "";
		input1b.value = "";
		input1c.value = "";
		input1d.value = "";
		input1e.value = "";
		
		input2a.value = "";
		input2b.value = "";
		input2c.value = "";
		input2d.value = "";
		input2e.value = "";
		
		input3a.value = "";
		input3b.value = "";
		input3c.value = "";
		input3d.value = "";
		input3e.value = "";
		
		allCleared = 1;
	}
}

function roundOff(x)
{
	x = 1000 * x;
	x = Math.round(x);
	x = x / 1000;
	return x;
}

function calculateRowOne()
{
	with (document.form1)
	{
		sumRow1 = roundOff((input1a.value * input1b.value * input1c.value * input1d.value) / 1000000);
		input1e.value = sumRow1;
	}
	calculateTotal();
}

function calculateRowTwo()
{
	with (document.form1)
	{
		sumRow2 = roundOff((input2a.value * input2b.value * input2c.value * input2d.value) / 1000000);
		input2e.value = sumRow2;
	}
	calculateTotal();
}

function calculateRowThree()
{
	with (document.form1)
	{
		sumRow3 = roundOff((input3a.value * input3b.value * input3c.value * input3d.value) / 1000000);
		input3e.value = sumRow3;
	}
	calculateTotal();
}

function calculateTotal()
{
	with (document.form1)
	{
		inputTotal.value = (input1e.value * 1) + (input2e.value * 1) + (input3e.value * 1);
	}
	calculateChargeableWeight();
}

function calculateChargeableWeight()
{
	with (document.form1)
	{
		if (selectMode.value == "Air")
		{
			inputChargeableWeight.value = roundOff(inputTotal.value * 166.66667);
		}
		if (selectMode.value == "Road")
		{
			inputChargeableWeight.value = roundOff(inputTotal.value * 333.33333);
		}
		if (selectMode.value == "Sea")
		{
			inputChargeableWeight.value = roundOff(inputTotal.value * 1000.0000);
		}
	}
}
