var xmlhttp;
function GetXmlHttpObject(){
	if (window.XMLHttpRequest)  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	}
	if (window.ActiveXObject){
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}


function stateChanged(){
	if (xmlhttp.readyState==4){
		var str=xmlhttp.responseText;
		var caloriearr = str.split("||");
		if(caloriearr.length==2){
			document.getElementById('paraNotfound').style.display="none";
			document.getElementById('paraServing').style.display="";
		    document.getElementById("paraServing").innerHTML=caloriearr[0]+" Calorias - "+caloriearr[1];
		}else{
			document.getElementById('paraNotfound').style.display="";
			document.getElementById('paraServing').style.display="none";
			document.getElementById('paraNotfound').innerHTML="Não encontrado";
		}
	}
}

function showCalorie(){
	var str=document.getElementById('calorie_search').value;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)  {
	  alert ("Browser does not support HTTP Request");
	  return;
	}
	var url="modules/getCalorie.php";
	url=url+"?cal="+str;
	url=url+"&sid="+Math.random();

	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

