/*******************************************************************************************************************
* Class Cookie                                                                                                     *
*                                                                                                                  *
* Properties: enabled                                                                                              *
*               Input: -                                                                                           *
*               Output: (Boolean)                                                                                  *
* Methods: get                                                                                                     *
*            Input: (name String)                                                                                  *
*            Output: (String)                                                                                      *
*          remove                                                                                                  *
*            Input: (name String)                                                                                  *
*            Output: -                                                                                             *
*          set                                                                                                     *
*            Input: (name String, value String[, expires Integer[, path String[, domain String[, secure String]]]] *
*            Output: -                                                                                             *
*******************************************************************************************************************/

function Cookie()
{
  this.enabled = navigator.cookieEnabled;

  this.get = function(name)
  {
    var beginposition, endposition;
    var value;
    value = '';
    if (document.cookie.length > 0)
    {
      beginposition = document.cookie.indexOf(name + '=');
      if (beginposition != -1)
      {
        beginposition = beginposition + name.length + 1;
        endposition = document.cookie.indexOf(';', beginposition);
        if (endposition == -1)
          endposition = document.cookie.length;
        value = unescape(document.cookie.substring(beginposition, endposition));
      }
    }
    return value;
  };

  this.remove = function(name)
  {
    var dateobj = new Date();
    if (this.enabled == true)
    {
      dateobj.setTime(dateobj.getTime() - 1);
      document.cookie = name + "=; expires=" + dateobj.toGMTString();
    }
  };

  this.set = function(name, value, expires, path, domain, secure)
  {
    var dateobj = new Date();
    if (this.enabled == true)
    {
      dateobj.setTime(dateobj.getTime() + 86400000 * expires);
      document.cookie = name + '=' + escape(value) + ((expires) ? '; expires=' + dateobj.toGMTString() : '') + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + ((secure) ? '; secure' : '');
    }
  };
}

