  function setCookie(name, value, expires, path, domain, secure) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());

    // if the expires variable is set, make the correct expires time,
    // the current script below will set it for x number of days, to make
    // it for hours, delete * 24, for minutes, delete * 60 * 24
    var expiresDate = null;
    if(expires) { 
      expires *= (1000 * 60 * 60 * 24);
      expiresDate = new Date(today.getTime() + (expires));
    }

    var strCookie = name + '=' + escape(value) +
                    ((expires) ? ';expires=' + expiresDate.toGMTString() : '') + 
                    ((path)    ? ';path='    + path   : '') + 
                    ((domain)  ? ';domain='  + domain : '') +
                    ((secure)  ? ';secure'            : '');
    document.cookie = strCookie;
  }


  function getCookie(name) {
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var allCookies  = document.cookie.split(';');

    var totalCookies = allCookies.length;
    for(var i = 0; i < totalCookies; i++) {
      // now we'll split apart each name=value pair
      var currCookie = allCookies[i].split('=');
      var cookieName = currCookie[0].replace(/^\s+|\s+$/g, '');

      // if the extracted name matches passed name
      if(cookieName == name) {
        // we need to handle case where cookie has no value but exists (no equal [=] sign, that is):
        var cookieValue = (currCookie.length > 1) ? unescape(currCookie[1].replace(/^\s+|\s+$/g, '')) : null

        // note that in cases where cookie is initialized but no value, null is returned
        return cookieValue;
      }
    }
    return null;
  }


  function deleteCookie(name, path, domain) {
    if(getCookie(name)) {
      document.cookie = name + '=' +
                       ((path)   ? ';path='   + path   : '') +
                       ((domain) ? ';domain=' + domain : '') +
                       ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
    }
  }

