 /**
 * Script is used to manipulate cookies.
 *
 * @version 1.3
 * @title ObjectCookie
 * @author Ilya Lebedev ilya@lebedev.net, (c) 2004,2005
 *
 *
 *  v1.3
 *
 *  + supports Expire parameter as number of seconds in the future
 *
 *  v1.2
 *
 *  % changed script from Function to Object for shared usage
 *
 *  v1.1
 *
 *  % error in cookie name parsing
 *
 *  v1.0
 *
 *  + public release
 *
 *
 **/

(Cookie = {
  REVISION : 1.3,          // script revision
  c        : {},           // hash of cookies
  init : function () {
    if (""!=document.cookie) {
      var p = document.cookie.split(/\s*;\s*/);
      var pL = p.length;
      for (i=0;i<pL;i++) {
        var parts = p[i].split(/\s*=\s*/);
        Cookie.c[parts[0]] = parts[1]?unescape(parts[1]):"";
      }
    }
  },
  get : function (name) {
    return Cookie.c[name]?Cookie.c[name]:'';
  },
  set : function (name, value, expire, path, domain, secure) {
    if (""!=name) {
      document.cookie = name + "=" + escape(value) +
      ((path == null) ? "" : ";path=" + path) +
      ((expire == null) ? "" : "; expires=" + ((typeof(expire)=='object')?expire.toGMTString():new Date(new Date().getTime()+expire*1000).toGMTString())) +
      ((domain == null) ? "" : ";domain=" + domain) +
      ((secure == null) ? "" : ";secure");
      Cookie.c[name] = escape(value);
      return true;
    }
    return false;
  },
  isSet : function (name) {
    return Cookie.c[name]?true:false;
  },
  del : function (name,path,domain) {
    if (Cookie.isSet(name)) {
      document.cookie = name + "=" +
      ((path == null) ? "" : "; path=" + path) +
      ((domain == null) ? "" : "; domain=" + domain) +
      "; NoExp=Thu, 01-Jan-70 00:00:01 GMT";
      delete Cookie.c[name];
      return true;
    }
    return false;
  },
  delAll : function () {
    var i;
    for (i in Cookie.c) {
      Cookie.del(i);
    }
    return true;
  }
}).init();
