﻿function getCookie(cookieName) {
  if (document.cookie.length>0) {
    cookieStart=document.cookie.indexOf(cookieName + "=");
    // if cookie exists
    if (cookieStart!=-1) { 
      cookieStart=cookieStart + cookieName.length+1; 
      // set index of beginning of value
      cookieEnd=document.cookie.indexOf(";",cookieStart);
      // set index of end of cookie value
      if (cookieEnd==-1) cookieEnd=document.cookie.length;
      return unescape(document.cookie.substring(cookieStart,cookieEnd));
    } 
  }
  return "";
}

function setCookie(cookieName,value) {
  document.cookie=cookieName+ "=" +escape(value);
}

function checkCookie(cookieName,value) {
  cookie=getCookie(cookieName);
  // if cookie exists, return cookie value
  if (cookie==value) {
    return cookie;
  }
  // else set cookie
  else {
    setCookie(cookieName,value);
    return "";
  }
}
