function AddToCart (itemCode) {
	var noSpaceItemCode = "";
	var temp = itemCode.split (" ");
	var len = temp.length;
	for (var i = 0; i < len; i++)	// clunky way to change spaces to "_".
	{								// I can't get string.replace to work.
		noSpaceItemCode += temp[i];
		if ((i + 1) < len)
			noSpaceItemCode += "_";
	}
	var key = "cart_" + noSpaceItemCode;
	var numUnits = 1;
	MySetCookie (key,numUnits,null,"/");
//	alert ("key "+key+" = "+numUnits);
}

function UpdateCart (numUnits, itemCode)
{
	var key = "cart_" + itemCode;
	MySetCookie (key, numUnits, null, "/");
//	alert ("You have " + numUnits + " " + itemCode + ((numUnits == 1) ? " " : "s ") + "in your cart");
}

function ItemsInCart () {
	var itemStr = '<font face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif"><font size="1">';
	var numItems = CountItemsInCart ();
	if (numItems == 1)
		itemStr += "There is <b>1</b> item in your cart";
	else
		itemStr += "There are <b>" + numItems + "</b> items in your cart";
	itemStr += "</font></font>\n";
	return itemStr;
}

function whiteItemsInCart () {
	var itemStr = '<font face="Helvetica, Geneva, Arial, SunSans-Regular, sans-serif" size="1" color="white">';
	var numItems = CountItemsInCart ();
	if (numItems == 1)
		itemStr += "There is <b>1</b> item in your cart";
	else
		itemStr += "There are <b>" + numItems + "</b> items in your cart";
	itemStr += "</font></font>\n";
	return itemStr;
}

function CreateAddToCartButton (itemCode, itemName)
{
	var itemCount = GetCookie ("cart_" + itemCode);
	var another = "";
	if (itemCount)
		another = "another ";
	document.write ("<input type='button' name='addToCart' value='Add " + another + itemName + " to Cart'" + " onclick=\"AddToCart('" + itemCode + "')\">");
}

function CountItemsInCart ()
{
	var itemCount = 0;
	var name;
	var arg = "cart_";
	var alen = arg.length;
	var clen = document.cookie.length;
	var pos = 0;

	while ((pos + alen) < clen) {
		var j = pos + alen;
		var startVal = document.cookie.indexOf("=", pos) + 1;
		if (startVal == 0)
			break;
		var endVal = document.cookie.indexOf(";", startVal + 1);
		if (endVal == -1)
			endVal = document.cookie.length;
		if (startVal >= endVal)
			break;

		if (document.cookie.substring(pos, j) == arg) {
			valStr = document.cookie.substring(startVal, endVal);
			itemCount += parseInt (document.cookie.substring(startVal, endVal));
		}
		pos = document.cookie.indexOf(" ", endVal);
		if ((pos == -1) || (pos > (endVal + 1)))
			pos = endVal + 1;
		else
			++pos;
    }

	return itemCount;	
}
