var cookies = new Cookies();

function Cookies() {

  this.load = function() {
    var cookies = document.cookie.split(';');
    for (var i = 0; i < cookies.length; i++) {
      var cookie = cookies[i].split('=');
      var name = cookie[0].replace(/\s/g, '');
      this[name] = cookie[1];
    }
  }

  this.set = function(name, value, persist, domain) {
    var cookieStr = value + '; path=/';

    if (persist) {
      var dt = new Date();
      dt.setTime(dt.getTime() + 1000 * 60 * 60 * 24 * 7 * 4);
      cookieStr += '; expires=' + dt.toGMTString();
    }

    if (domain) cookieStr += '; domain=' + domain;

    this[name] = cookieStr;
    document.cookie = name + '=' + cookieStr;
  }
}

function getNodeText(node) {
  var textNode = node.firstChild;
  while (textNode && textNode.nodeType != 3)
    textNode = textNode.nextSibling;

  if (textNode) return textNode.nodeValue;

  return '';
}

function setNodeText(node, value) {
  while (node.firstChild)
    node.removeChild(node.firstChild);
  textNode = node.ownerDocument.createTextNode(value);
  node.appendChild(textNode);
}

function preloadImages(path) {
  for (var i = 1; i < arguments.length; i++) {
    var img = new Image();
    img.src = path + arguments[i];
  }
}

function checkMail(link) {
  var form = document.forms['cust-login'];
  var email = form.elements['email'].value;
  if (email) {
    link.href = link.href + '?email=' + escape(email);
    return true;
  }
  alert('Niepoprawne pole: email. Popraw i spr\u00f3buj jeszcze raz.')
  return false;
}
