// "Internal" function to return the decoded value of a cookie
function getCookieVal(offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

// Function to return the value of the cookie specified by "name" or null if
// the cookie does not exist.
function GetCookie(name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

function getElementsByClass(node, className, tag) {
    var classElements = new Array();
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)" + className + "(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}

function addClass(e,c) {
	e.className = e.className + ' ' + c;
}

function removeClass(e,c) {
	cn = e.className;
	p = cn.indexOf(c);
	if (p != -1) {
	  e.className = cn.substr(0,p) + cn.substr(p+c.length);
	}
}

function checkPollMultivoting(pollId) {
  if (pollId == GetCookie("poll")) {
    alert("Nelze hlasovat vícekrát.");
    return false;
  } else {
  	return true;
  }
}

// Automagically load Lightbox on Page Load
function autoFireLightbox() {
  //Check if location.hash matches a lightbox-anchor. If so, trigger popup of image.
  setTimeout(function() {
    if(document.location.hash && $(document.location.hash.substr(1)).rel.indexOf('lightbox')!=-1) {
      myLightbox.start($(document.location.hash.substr(1)));
    }},
    250
  );
}

