// JavaScript support routines
// © 4Mation 2007

// expects there to be spans with a class of "hideWithVat" which will be hidden
// expects the price fields to have ids of price<n> where <n> is the index in the product array

var VATrate = 1.2;

function GetParameter(sName)
{
	if (document.location.search.length == 0)
		return null;
		
	var aParams = document.location.search.substring(1).split("&");
	
	for (var i=0; i < aParams.length; i++)
	{
		var aCrumb = aParams[i].split("=");
		if (sName == aCrumb[0]) 
		{
			if (aCrumb[1])
				return unescape(aCrumb[1]);
			return null;
		}
	}
	return null;
}

function showVatPrices()
{
	var showVat = GetParameter("withvat");
	
	if (showVat != null && showVat != 0)
	{
		for (var i=0; i < products.length; i++)
		{
			var dat = document.getElementById("price"+i);
			if (dat != null)
				dat.innerHTML = "&pound;"+toFixed(products[i].cost * VATrate, 2)+ ' <span style="font-size:6pt;">(inc 20% VAT)</span><sup>&dagger;</sup>';
		}
		
		if (document.styleSheets != null)
			document.styleSheets[0].insertRule(".hideWithVat {display:none;}", 0);
	}
}

