function ajaxAddToCart(id, quant, variety)
{
	if (variety.length > 0)
	{
		variety = parseInt(variety);
	}

	var ajax = getAJAXObject();
	ajax.open("GET", "addtocart.php?p=" + parseInt(id) + "&q=" + parseInt(quant) + "&v=" + variety, true);
	ajax.onreadystatechange = function()
	{
		if (ajax.readyState == 4)
		{
			if (ajax.status == 200)
			{
				window.open("cart.php", "_self");
			}
			else
			{
				messageDialog("An error occurred whilst adding the item to the cart.", null, "Error"); 
			}
		}
	}
	ajax.send("");
}

function addToCart(id, noHideDialog)
{
	if (noHideDialog == undefined || noHideDialog == 0)
	{
		hideDialog("messageBox2");
	}

	var quant = document.getElementById("quantity").value;
	var variety = document.getElementById("var");
	if (variety != null)
	{
		variety = parseInt(variety.value);
	}
	else
	{
		variety = "";
	}

	ajaxAddToCart(id, quant, variety);
}
