var xmlHttp;
var AbsolutePath = "/";

/* -------------------------------------------------------------------------- */

function GetXmlHttpObject() {
  var xmlHttp=null;

  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e) {
    //Internet Explorer
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }

  return xmlHttp;
}

/* -------------------------------------------------------------------------- */

function ajaxShowCart() {
  var url = AbsolutePath+"cart/index.php?action=show_cart";

  xmlHttp = GetXmlHttpObject();
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = function () {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
      document.getElementById("ajax_cart").innerHTML = xmlHttp.responseText;
    }
  };
  xmlHttp.send(null);
}

/* -------------------------------------------------------------------------- */

function ajaxRefreshCart() {
  var url = AbsolutePath+"cart/index.php?action=refresh_cart";

  xmlHttp = GetXmlHttpObject();
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = function () {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
      document.getElementById("ajax_cart").innerHTML = xmlHttp.responseText;
    }
  };
  xmlHttp.send(null);
}

/* -------------------------------------------------------------------------- */

function ajaxUpdateCart(Count, ProductId, From) {
  var url = AbsolutePath+"cart/index.php?action=update_cart&count="+Count+"&product_id="+ProductId+"&from="+From;

  xmlHttp = GetXmlHttpObject();
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = function () {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
      if (From == 'parent') {
        window.opener.document.getElementById("ajax_cart").innerHTML = xmlHttp.responseText;
      }
      else {
        document.getElementById("ajax_cart").innerHTML = xmlHttp.responseText;
      }
    }
  };
  xmlHttp.send(null);
}

/* -------------------------------------------------------------------------- */

function ajaxAddSelectedItems() {
  var items = document.getElementsByName('products');
  var items_count = items.length;
  var pairs = '';
  var id = '';
  var count_ = 0;

  for (var i = 0; i < items_count; i++) {
    if (items[i].value > 0) {
      id = items[i].id;
      count_ = items[i].value;
      pairs += id.replace('list_count', '')+'-'+count_+',';
    }
  }

  pairs = pairs.substr(0, pairs.length - 1);
  var url = AbsolutePath+"cart/index.php?action=update_cart_multi&pairs="+pairs;
  xmlHttp = GetXmlHttpObject();
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = function () {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
      document.getElementById("ajax_cart").innerHTML = xmlHttp.responseText;
    }
  };
  xmlHttp.send(null);
}

/* -------------------------------------------------------------------------- */

function ajaxDeleteFromCart() {
  var boxes = document.getElementsByName('item_id');
  var boxes_length = boxes.length;
  var ids = '';

  for(var i = 0; i < boxes_length; i++) {
    if (boxes[i].checked) {
      ids += boxes[i].value+',';
    }
  }

  ids = ids.substr(0, ids.length - 1);
  var url = AbsolutePath+"cart/index.php?action=delete_cart&ids="+ids;
  xmlHttp = GetXmlHttpObject();
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = function () {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
      document.getElementById("ajax_cart").innerHTML = xmlHttp.responseText;
    }
  };
  xmlHttp.send(null);
}

/* -------------------------------------------------------------------------- */

function SplashMessage(miliseconds) {
  splash = document.getElementById("overlay");
  splash.style.visibility = "visible";
  var t = setTimeout("document.getElementById('overlay').style.visibility = 'hidden'", miliseconds);
}