var xmlHttp;

function GetCartInfo(script_url) {
  xmlHttp = GetXmlHttpObject();
  if (xmlHttp == null) {
    alert("Извините, Ваш браузер не поддерживает HTTPRequest");
    return;
  } 
  var url = script_url + "cartinfo/index/sid_" + Math.random();
  xmlHttp.onreadystatechange = stateChanged;
  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);
} 

function AddItem(id, name) {
  var reply = prompt(name + "\nСколько добавить?", "1");
  if (reply != null) {
    //var count = reply - 0;
    var count = parseInt(reply, 10) 
    if (count != NaN && count > 0) {
      xmlHttp = GetXmlHttpObject();
      if (xmlHttp == null) {
        alert("Извините, Ваш браузер не поддерживает HTTPRequest");
        return;
      } 
      var url = add_item_url + "add_item/" + id + "/" + count + "/" + "sid_" + Math.random();
      xmlHttp.onreadystatechange = stateChanged;
      xmlHttp.open("GET", url, true);
      xmlHttp.send(null);
      
    }
  }
}

var timerID;

function HideTimedLayer(id) {
  if (document.getElementById(id)) {  
    document.getElementById(id).style.display = "none";
  }
  clearTimeout(timerID);
}

function stateChanged() { 
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") { 
    document.getElementById("cart").innerHTML = xmlHttp.responseText;
    //document.getElementById("added").style.display = "block";
    //timerID = setTimeout("HideTimedLayer('added')", 3000);
    alert("Товар добавлен в корзину");
  } 
} 

function GetXmlHttpObject() { 
  var objXMLHttp = null;

  if (window.XMLHttpRequest) {
    try {
      objXMLHttp = new XMLHttpRequest();
    } catch (e) {
    }
  } else if (window.ActiveXObject) {
    try {
      objXMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    }
  }
  return objXMLHttp;
}

function OpenWin(path, width, height) {
  if (width == 0 || height == 0) {
    width = 740;
    height = 560;
  }
  window.open(path, 'wnd', 'left=60,top=20,height=' + height + ',width=' + width + ',menubar=no,resizable=yes,status=no,scrollbars=auto,toolbar=no,directories=no');
}



