
//--- format a float as currency
function FormatCurrency(inFloat)
{
	var pence = String(Math.round(inFloat * 100.0) % 100);
	var pounds = String(Math.floor(inFloat + 0.000001));
	if (pence < 10)
		pence = '0'+pence;
	return pounds+'.'+pence;
}


//--- update the ordering box
function UpdateProduct(prodID)
{
	var prodForm = document.getElementById('prodform'+prodID);
	var qty = parseInt(prodForm.qty.value);
	qty = (qty < 0) ? 0 : qty;
	var packID = parseInt(prodForm.packID.value);
	var packKg = parseFloat(eval('prodForm.pack'+packID+'.value'));
	var priceKg = parseFloat(prodForm.pricekg.value);
	
	prodForm.finalval.value = '0.00';
	if (priceEach = packKg * priceKg)
	{
		priceEach = parseFloat(FormatCurrency(priceEach));
		if (total = priceEach * qty)
			prodForm.finalval.value = FormatCurrency(total);
	}
}


//--- check quantity is greater than zero
function CheckQuantity(prodID)
{
	var prodForm = document.getElementById('prodform'+prodID);
	var qty = parseInt(prodForm.qty.value);
	if (qty > 0)
		return true;
	alert('Please enter a quantity');
	prodForm.qty.focus();
	return false;
}