var xmlhttp;
var currentAction = "";
var cartUrl = "";

function loadXMLDoc(url)
{
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
		xmlhttp.onreadystatechange = xmlhttpChange;
		xmlhttp.open("GET", url, true);
		xmlhttp.send(null);
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp)
		{
			xmlhttp.onreadystatechange=xmlhttpChange;
			xmlhttp.open("GET",url,true);
			xmlhttp.send();
		}
	}
}

function xmlhttpChange()
{
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4)
	{
		//alert(xmlhttp.responseText);
		// if "OK"
		if (xmlhttp.status==200)
		{
			if(currentAction == "clickSageata")
			{
				currentAction = "openCart";
				loadXMLDoc(cartUrl);
			}
			else if(currentAction == "openCart")
			{
				document.getElementById("cartContainer").innerHTML = xmlhttp.responseText;
				currentAction = "";
			}
		}
		else
		{
			//alert("Problem retrieving XML data")
		}
	}
}

function clickSageata(url, newCartUrl, action, htmlInput)
{
	cartUrl = newCartUrl;
	currentAction = "clickSageata";
	var inputValue = htmlInput.value * 1;
	if(action == "plus")
		htmlInput.value = inputValue + 1;
	else if(action == "minus" && inputValue > 0)
		htmlInput.value = inputValue - 1;
	loadXMLDoc(url);
}