cookies =
{
  // private property
      _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
  
  // public method for encoding
  encode : function (input) {
      var output = "";
      var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
      var i = 0;

      input = cookies._utf8_encode(input);

      while (i < input.length) {

          chr1 = input.charCodeAt(i++);
          chr2 = input.charCodeAt(i++);
          chr3 = input.charCodeAt(i++);

          enc1 = chr1 >> 2;
          enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
          enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
          enc4 = chr3 & 63;

          if (isNaN(chr2)) {
              enc3 = enc4 = 64;
          } else if (isNaN(chr3)) {
              enc4 = 64;
          }

          output = output +
          this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
          this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

      }

      return output;
  },

  // public method for decoding
  decode : function (input) {
      var output = "";
      var chr1, chr2, chr3;
      var enc1, enc2, enc3, enc4;
      var i = 0;

      input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

      while (i < input.length) {

          enc1 = this._keyStr.indexOf(input.charAt(i++));
          enc2 = this._keyStr.indexOf(input.charAt(i++));
          enc3 = this._keyStr.indexOf(input.charAt(i++));
          enc4 = this._keyStr.indexOf(input.charAt(i++));

          chr1 = (enc1 << 2) | (enc2 >> 4);
          chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
          chr3 = ((enc3 & 3) << 6) | enc4;

          output = output + String.fromCharCode(chr1);

          if (enc3 != 64) {
              output = output + String.fromCharCode(chr2);
          }
          if (enc4 != 64) {
              output = output + String.fromCharCode(chr3);
          }

      }

      output = cookies._utf8_decode(output);

      return output;

  },

  // private method for UTF-8 encoding
  _utf8_encode : function (string) {
      string = string.replace(/\r\n/g,"\n");
      var utftext = "";

      for (var n = 0; n < string.length; n++) {

          var c = string.charCodeAt(n);

          if (c < 128) {
              utftext += String.fromCharCode(c);
          }
          else if((c > 127) && (c < 2048)) {
              utftext += String.fromCharCode((c >> 6) | 192);
              utftext += String.fromCharCode((c & 63) | 128);
          }
          else {
              utftext += String.fromCharCode((c >> 12) | 224);
              utftext += String.fromCharCode(((c >> 6) & 63) | 128);
              utftext += String.fromCharCode((c & 63) | 128);
          }

      }

      return utftext;
  },

  // private method for UTF-8 decoding
  _utf8_decode : function (utftext) {
      var string = "";
      var i = 0;
      var c = c1 = c2 = 0;

      while ( i < utftext.length ) {

          c = utftext.charCodeAt(i);

          if (c < 128) {
              string += String.fromCharCode(c);
              i++;
          }
          else if((c > 191) && (c < 224)) {
              c2 = utftext.charCodeAt(i+1);
              string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
              i += 2;
          }
          else {
              c2 = utftext.charCodeAt(i+1);
              c3 = utftext.charCodeAt(i+2);
              string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
              i += 3;
          }

      }

      return string;
  },
  
  /* METHOD: get();
   * PURPOSE: Get the value of a cookie
   * ARGUMENTS: STRING - cookieName - The name of the cookie value you wish to retrieve
   * RETURN: If cookie exists - STRING - the cookie value
   *         If cookie does not exist - null
   */
  get: function(cookieName)
  {
    var cookieNameStart,valueStart,valueEnd,cookieValue,returnValue;
    cookieNameStart = document.cookie.indexOf(cookieName+'=');
    if (cookieNameStart < 0)
    {
      returnValue = null;
    }
    else
    {
      valueStart = document.cookie.indexOf(cookieName+'=') + cookieName.length + 1;
      valueEnd = document.cookie.indexOf(";",valueStart);
      if (valueEnd == -1)
      {
        valueEnd = document.cookie.length;
      }
      cookieValue = document.cookie.substring(valueStart,valueEnd );
      returnValue = (cookieValue == '') ? null : cookies.decode(cookieValue);
    }
    return returnValue;
  },
  /* METHOD: set();
   * PURPOSE: Write (or overwrite) a cookie (with supplemental information such as expiration, path, domain)
   * ARGUMENTS: cookieName - STRING - The name of the cookie value you wish to write
   *            value - STRING - The string you wish to write as the value of the cookie
   *            hoursToLive - INT/FLOAT - The number of hours until the cookie will expire.  If you do not provide
   *                                      this argument, or provide anything that can evaluate to false, or provide
   *                                      anything that can not be interpreted as a number, the expiration field for
   *                                      the cookie will not be set causing it to be deleted the next time the
   *                                      browser is closed (IE referes to this sort of cookie as a 'session' cookie).
   *            path - STRING - (Optional) The path for which the cookie is valid.  Defaults to "/" if not
   *                             passed, or passed empty.
   *            domain - STRING - (Optional) The domain for which the cookie is valid.  Defaults to
   *                              window.location.hostname if not passed, or passed empty.
   *            secure - BOOL - (Optional) This is used to instruct the browser to use SSL when sending the
   *                            cookie to a server.  It is almost never used, and will thus be assumed false
   *                            unless you explicitly pass true.
   * RETURN: VOID
   */
  set: function(cookieName,value,hoursToLive,path,domain,secure)
  {
    var expireString,timerObj,expireAt,pathString,domainString,secureString;
    //If no hoursToLive argument, or it is not numeric, do not set expiration
    if (!hoursToLive || typeof hoursToLive != 'number')
    {
      expireString = '';
    }
    else
    {
      timerObj = new Date();
      timerObj.setTime(timerObj.getTime()+(hoursToLive*60*60*1000));
      expireAt = timerObj.toGMTString();
      expireString = '; expires='+expireAt;
    }
    //If no path argument, or argument is empty string, set path to default of /
    path = (!path || path=='' || path==null) ? '/' : path;
    pathString = '; path='+path;
    //If no domain argument, or argument is empty string, set domain to default of window.location.hostname
    domain = (!domain || domain=='' || domain==null) ? window.location.hostname : domain;
    domainString = '; domain='+domain;
    //If secure argument is the BOOL true, set SSL string accordingly.  Otherwise, do not set it.
    secureString = (secure === true) ? '; secure' : '';
    //escape the value for HTTP transport to server
    value = escape(value);
    //Write the value to the document.cookie string
    document.cookie = cookieName+'='+value+expireString+pathString+domainString;
  },
  /* METHOD: del();
   * PURPOSE: Delete a cookie
   * ARGUMENTS: STRING - cookieName - The name of the cookie value you wish to delete
   *            path - STRING - (Optional) The path for which the cookie was set.  This is necessary if
   *                            the cookie was set with a particular path--you need to delete it with the
   *                            same.  Defaults to "/" if not passed, or passed empty.
   *            domain - STRING - (Optional) The domain for which the cookie was set.  This is necessary if
   *                            the cookie was set with a particular domain--you need to delete it with the
   *                            same.  Defaults to window.location.hostname if not passed, or passed empty.
   * RETURN: VOID
   */
  del: function(cookieName,path,domain)
  {
    path = (!path || !path.length) ? '' : path;
    domain = (!domain || !domain.length) ? '' : domain;
    jimAuld.utils.cookies.set(cookieName,'',-8760,path,domain);
  },
  /* METHOD: test();
   * PURPOSE: Test for cookie acceptance
   * ARGUMENTS: VOID
   * RETURN: If cookies accepted: BOOL - True
   *         If cookies not accepted: BOOL - False
   */
  test: function()
  {
    var returnValue;
    jimAuld.utils.cookies.set('cT','acc');
    var runTest = jimAuld.utils.cookies.get('cT');
    if (runTest == 'acc')
    {
      jimAuld.utils.cookies.del('cT');
      returnValue = true;
    }
    else
    {
      returnValue = false;
    }
    return returnValue;
  }
};