/*
$ /js/Shop.js | 2008/07/02 11:50 | 2008/08/12 12:45 $
*/

function AJAX() {
  if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest(); // Mozilla, Firefox, Opera, stb.
  }
  else if (window.ActiveXObject) {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // IE
  }
  else {
    xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); // IE
  }

  return xmlhttp;
}


function addToCart(t, id, db) {
  var db = document.getElementById(db).value * 1;

  if (db > 0) {
    dbyet = parseInt(getCookie(t + '|' + id)) * 1;

    if (dbyet > 0)
      db += dbyet;

    setCookie(t + '|' + id, db);

    window.location = '/kosar/';
  }
}


function delFromCart(t, id) {
  delCookie(t + '|' + id);
  window.location = './';
}


function addToCartN(t, id, n) {
  db = parseInt(getCookie(t + '|' + id)) * 1;
  n = parseInt(n);

  if (db > 0)
    db += n;

  setCookie(t + '|' + id, db);

  window.location = location.href;
}


function removeFromCartN(t, id, n) {
  db = parseInt(getCookie(t + '|' + id)) * 1;
  n = parseInt(n);

  if (db > 0)
    db -= n;

  setCookie(t + '|' + id, db);

  window.location = location.href;
}


function setCookie(cookie_name, cookie_value) {
  document.cookie = cookie_name + "=" + escape(cookie_value) + "; path=/";
}


function getCookie(cookie_name) {
  if (document.cookie.length > 0) {
    c_start=document.cookie.indexOf(cookie_name + "=");

    if (c_start != -1) {
      c_start = c_start + cookie_name.length + 1;
      c_end = document.cookie.indexOf(";", c_start);

      if (c_end == -1) c_end = document.cookie.length;

      return unescape(document.cookie.substring(c_start,c_end));
    }
  }
  return "";
}


function delCookie(cookie_name) {
  if (getCookie(cookie_name)) {
    document.cookie = cookie_name + "=0; path=/; expires=Thu, 01-Jan-1970 00:00:01 GMT";
  }
}

