var Cookie = {
  set: function(name, value, daysToExpire, apath, cdomain, secure, httpOnly) {
    var expire = '';
    if (daysToExpire != undefined) {
      if(typeof(daysToExpire) === 'number' ||
         (typeof(daysToExpire) == 'string' && daysToExpire.indexOf(' ') == -1)) {
        var d = new Date();
        d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
        expire = '; expires=' + d.toGMTString();
      } else {
        // Preformated date string:
        expire = '; expires=' + daysToExpire;
      }

    }

    if(apath) {
      apath = '; path=' + apath;
    } else {
      apath = '';
    }

    if(cdomain) {
      cdomain = '; domain=' + cdomain;
    } else {
      cdomain = '';
    }

    if(secure) {
      secure = '; secure';
    } else {
      secure = '';
    }

    if(httpOnly) {
      httpOnly = '; HttpOnly;';
    } else {
      httpOnly = '';
    }

    return (document.cookie = escape(name) + '=' + escape(value || '') + expire + apath + cdomain + secure + httpOnly);
  },
  get: function(name) {
    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
    return (cookie ? unescape(cookie[2]) : null);
  },
  erase: function(name) {
    var cookie = Cookie.get(name) || true;
    Cookie.set(name, '', -1);
    return cookie;
  },
  accept: function() {
    if (typeof navigator.cookieEnabled == 'boolean') {
      return navigator.cookieEnabled;
    }
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') === '1');
  }
};
