var xmlhttp;
var dex;
xmlhttp=GetXmlHttpObject();

function addItem(indx,pid,osCsid){
	dex = indx;
	if (xmlhttp==null){
		alert ("Seu browser não supporte AJAX! por favor usa um browser mais atualizado.");
		return;
	}
	var url="addcart.php";
	url=url + "?pid=" + pid + osCsid;
	xmlhttp.onreadystatechange = stateChanged;
	xmlhttp.open("POST",url,true);
	xmlhttp.send(null);
}

function stateChanged(){
	if (xmlhttp.readyState==4){
		//alert(xmlhttp.responseText);
		total = xmlhttp.responseText.split(",")[0];
		part = xmlhttp.responseText.split(",")[1];
		if (document.getElementById("carrinho")) document.getElementById("carrinho").innerHTML = total + " | Ver Carrinho";
		if (document.getElementById("added" + dex)){
			document.getElementById("added" + dex).innerHTML="Produto adicionado! Ha " + part + " deste produto na sacola";
			document.getElementById("added" + dex).style.display="block";
		}
	}
}

function GetXmlHttpObject(){
	if (window.XMLHttpRequest){
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject){
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}
