var id;

function getXmlHttpObject(){
	var xmlHttp = null;
	try{
		xmlHttp = new XMLHttpRequest();
	} catch(e){
		try{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e){
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function stateChanged(){
	if(xmlHttp.readyState == 4){
		//alert(xmlHttp.responseText);
		document.getElementById('total_item'+id).value = xmlHttp.responseText;
	}
}



function updValue(item){
	xmlHttp = getXmlHttpObject();
	if(xmlHttp == null){
		alert("Seu browser n�o suporta AJAX!");
		return;
	}
	
	id = item;
	//alert(id);
	var oForm = document.getElementById('carrinho');
	var sBody = criaReqStr(oForm);
	//alert(sBody);
		
	var url = "atualiza_item.php";
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send(sBody);
	
}

function criaReqStr(oForm){
    var aPostStr = new Array();

  	for(var i = 0; i < oForm.elements.length; i++){
        var sValor = encodeURIComponent(oForm.elements[i].name);
        sValor += "=";
		sValor += encodeURIComponent(oForm.elements[i].value);
		aPostStr.push(sValor);
	}
	return aPostStr.join("&id="+id+"&");
}