//<!-- This function rounds numbers to numerical formatting. It does not need to be altered when adding or removing products. -->
function roundOff(value)

{
	if (value == 0)
	{
		return "0";
		exit;
	}

	precision = 2;
	value = "" + value //convert value to string
	precision = parseInt(precision);
	var whole = "" + Math.round(value * Math.pow(10, precision));
	var decPoint = whole.length - precision;

	if(decPoint != 0)
	{
		result = whole.substring(0, decPoint);
		result += ".";
		result += whole.substring(decPoint, whole.length);
	}
	else
	{
		result = whole;
	}

	return result;
}

//<!-- 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 is used to calculate the cost of the whole order. Product prices need to be added here, but edit further down the page to add the actual product aswell. -->
function calculate()
{
	//<!-- Add new product prices in here. Copy one of the three lines below and change the cost'NUMBER' ie `document.BuyForm3.cost5.value` and the price at the end. -->
	document.BuyForm3.cost1.value = 186.12;
	document.BuyForm3.cost2.value = 232.65;
	document.BuyForm3.cost3.value = 930.60;
	document.BuyForm3.cost4.value = 95.00;

	basicprice = roundOff(Number(CheckNull(document.BuyForm3.qty1.value) * document.BuyForm3.cost1.value)
		+ Number(CheckNull(document.BuyForm3.qty2.value) * document.BuyForm3.cost2.value)
		+ Number(CheckNull(document.BuyForm3.qty3.value) * document.BuyForm3.cost3.value)
		+ Number(CheckNull(document.BuyForm3.qty4.value) * document.BuyForm3.cost4.value)
	);
		//<!-- When adding a new product you need to copy from here... -->
		//+ Number(CheckNull(document.BuyForm3.qty3.value) * document.BuyForm3.cost3.value)
		//<!-- ...to here, and paste in a new line line before the bracket directly above. Changing both the quantity and cost numbers to the new product. -->


	//	<!-- To add a new product description copy this: '+ (document.BuyForm3.qty2.value) + " x Product 2, "' , and place it at the end of this line before the ';'. You will need to edit the qty'NUMBER' and the Product 'NUMBER'. -->
	document.BuyForm3.desc.value = (document.BuyForm3.qty1.value) + " x Single Delegate - Early Bird Booking,<br> " + 
(document.BuyForm3.qty2.value) + " x Single Delegate - Normal Booking,<br> " + 
(document.BuyForm3.qty3.value) + " x Group deal – 5 for 4,<br> " +
(document.BuyForm3.qty4.value) + " x Speakers’ Notes and Presentations.<br> ";

	document.BuyForm3.cost.value = roundOff(Number(basicprice));
}