var xmlHttp;
var xmlHttpQty;

var posx = 0;
var posy = 0;
var msg = "";
    
function addCart(id)
{ 
  xmlHttp = GetXmlHttpObject();
  
  if(xmlHttp == null)
  {
    alert("Your browser does not support AJAX!");
    return;
  } 
  
  var url = "carrello_shopping_cart.php";
  var params = "id=" + id + "&action=add_item&qty=1";
       
  xmlHttp.onreadystatechange = stateChanged;
  xmlHttp.open("POST",url,true);

  //Send the proper header information along with the request
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=utf-8"); // text/html; charset:ISO-8859-1
  xmlHttp.setRequestHeader("Content-length", params.length);
  xmlHttp.setRequestHeader("Connection", "close");
  
  xmlHttp.send(params);
} 

function stateChanged() 
{ 
 if(xmlHttp.readyState == 4)
 { 
   if(xmlHttp.responseText.length != 0)
   { 
     msg = document.getElementById("msg").innerHTML = xmlHttp.responseText;
     updCart();
   }
   else
     msg = "Errore";
 }
}

/* Added on 02.01.2010 to update SC */
function updCart()
{ 
  xmlHttpQty = GetXmlHttpObject();
  
  if(xmlHttpQty == null)
  {
    alert("Your browser does not support AJAX!");
    return;
  } 
  
  var url    = "carrello_quantity.php";
  var params = "qt=1";
       
  xmlHttpQty.onreadystatechange = stateChangedQty;
  xmlHttpQty.open("POST",url,true);

  //Send the proper header information along with the request
  xmlHttpQty.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=utf-8"); // text/html; charset:ISO-8859-1
  xmlHttpQty.setRequestHeader("Content-length", params.length);
  xmlHttpQty.setRequestHeader("Connection", "close");
  
  xmlHttpQty.send(params);
} 

function stateChangedQty() 
{ 
 if(xmlHttpQty.readyState == 4)
 { 
   if(xmlHttpQty.responseText.length != 0)
   {
     if(document.getElementById("scqty"))
       document.getElementById("scqty").innerHTML = xmlHttpQty.responseText;
     else
       window.opener.document.getElementById("scqty").innerHTML = xmlHttpQty.responseText;
   }
   /*else
     window.parent.document.getElementById("scqty").innerHTML = "0";
   */
 }
}
/* Added on 02.01.2010 to update SC */

function GetXmlHttpObject()
{
  var xml_Http = null;
  try
  {
   // Firefox, Opera 8.0+, Safari
   xml_Http = new XMLHttpRequest();
  }
  catch (e)
  {
   // Internet Explorer
   try
   {
     xml_Http = new ActiveXObject("Msxml2.XMLHTTP");
   }
   catch (e)
   {
     xml_Http = new ActiveXObject("Microsoft.XMLHTTP");
   }
  }
  return xml_Http;
}

function showMsg(event)
{
  var e = null;
  
  if (!event) 
    e = window.event;
  else
    e = event;
 
  if (e.pageX || e.pageY) 	
  {
    posx = e.pageX;
	posy = e.pageY;
  }
  else if (e.clientX || e.clientY)
  {
     posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	 posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
  }
  
  posx = posx-250; // 550
  posy = posy+40;
  
  posx = posx+"px";
  posy = posy+"px"
  
  document.getElementById("msg").style.display = "block";
  document.getElementById("msg").innerHTML = msg;
  
  hideMsg(3000);
}

function hide()
{
  document.getElementById("msg").style.display = "none";
}

function hideMsg(delay)
{
  // document.getElementById("msg").style.visibility = "hidden";
  var t = setTimeout("hide()",delay);
}