

// Posting & package configuration


<!-- The next two functions round numbers to numerical formatting. They do not need to be altered when adding or removing products. -->
function roundOff(value, precision)
{
	return places(value,1,precision);
}

function places(X, M, N) 
{
	var T, S=new String(Math.round(X*Number("1e"+N)))

	while (S.length<M+N) S='0'+S
	var y = S.substr(0, T=(S.length-N));
	if(N>0) 
	{
		y += '.' + S.substr(T, N);
	}

	return y;
}

<!-- This function checks for empty quantities. It does not need to be altered when adding or removing products. -->

function CheckNull(value)
{
	if (value == "")
	{
		value = "0";
	}

	return value;
}

<!-- This function defines the postage and packaging location. It does not need to be altered when adding or removing products. -->

function typeOfCarriage(x,whereabouts)
{
	x.carriage_amount.value = whereabouts;
}

<!-- This function addeds the postage and packaging to the total price of the products. Add new postage rates here, and also edit further down the page to add them to the table. -->

function calculate(x,postage_price)
{
	basicprice = calc(x);
	//alert(basicprice);
	if(Number(basicprice) > 0)
		x.amount.value = Number(basicprice) + Number(postage_price);
	else
		x.amount.value = "0";

	x.amount.value = roundOff(x.amount.value,2);
}

function getChecked(x) {
	var result = 0;
	for (i=0;i<x.postage_and_packaging.length;i++){
		if (x.postage_and_packaging[i].checked) {
			checked_value=Number(x.postage_and_packaging[i].value);
			result = x.postage_and_packaging[i].value;
		}
	}	
	return result;
}
<!-- The standard price, exluding postage and packaging is calculated here. It does not need to be altered when adding or removing products. -->
function calc(x)
{
	x.amount.value = 0;
	var y = x.bookprice.length;
	var z = x.qty.length;
	var a = Number(x.amount.value);
	var b,c;

	while(y > 0)
	{
		b = Number(CheckNull(x.bookprice[y-1].value));
		c = Number(CheckNull(x.qty[y-1].value));
		a += (b * c);
		y--;
	}
	if (y==undefined) {
		b = Number(CheckNull(x.bookprice.value));
		c = Number(CheckNull(x.qty.value));
		a += (b * c);
	}
	
	return a;
}

