/**
 * ~ajax_buy.js
 * soubor funkci potrebnych pro ajaxove vkladani do kosiku 
 **/ 
function get_hash() {
  hash = document.location.hash.replace(new RegExp('^(.*)#'), '');
  get = {}
  if (hash) {
    hash = hash.split('&');
    for (i = 0; i < hash.length; i++) {
      hash[i] = (hash[i]).split('=');
      get[hash[i][0]] = (hash[i][1] ? hash[i][1] : null);
    }
  }
  return get;
}

function createRequest(debug) {
  this.httpRequest = null;
  if (window.XMLHttpRequest) {
    this.httpRequest = new XMLHttpRequest();
    if (this.httpRequest.overrideMimeType) {
      this.httpRequest.overrideMimeType('text/html');
    }
  } else if (window.ActiveXObject) {
    try {
      this.httpRequest = new ActiveXObject('Msxml2.XMLHTTP');
    } catch (err) {
      try {
        this.httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
      } catch (err) {
        if (debug !== undefined && debug) {
          alert(getException(err));
        }
      }
    }
  }
  return this.httpRequest;
}



function sendRequest(url, imgId) {
  img = document.getElementById(imgId);
  img.style.display = 'block';
  request.open('GET', url + '&ajax=1', true);
  request.onreadystatechange = function () {
    parseRequest(request, img);
  };
  request.send(null);
}

function parseRequest(request, img) {
  if ((request.readyState == 4) && (request.status == 200)) {
    elem = document.getElementById('success'); 
    elem.style.display = 'block';
    img.style.display = 'none';
    result = document.getElementById('obsah-kosik');
    if (result != null) {
    }
    if (window.location.href == url + '?added=1#success') {
      window.location.reload();
    } else {
      window.location.href = url + '?added=1#success';
    }
  }
}
