// written by Ilya Lebedev ilya@lebedev.net
// ObjectCookie v1.0

/**
* Script is used to manipulate cookies.
**/

function Cookie () {
  var self = this;
  var c = [];
  _constructor();
  function _constructor () {
    if (""!=document.cookie) {
      var p = document.cookie.split(/\s*;\s*/);
      var pL = p.length;
      for (var i=0;i<pL;i++) {
        var parts = p[i].split(/\s*=\s*/);
        c[parts[0]] = parts[1]?unescape(parts[1]):"";
      }
    }
  }
  this.get = function (name) {
    if (c[name]) return c[name];
    else return false;
  }
  this.set = function (name, value, expire, path, domain, secure) {
    if (""!=name) {
      document.cookie = name + "=" + escape(value) +
      ((path == null) ? "" : ";path=" + path) +
      ((expire == null) ? "" : ";NoExp=" + expire.toGMTString()) +
      ((domain == null) ? "" : ";domain=" + domain) +
      ((secure == null) ? "" : ";secure");
      c[name] = escape(value);
      return true;
    }
    return false;
  }
  this.isSet = function (name) {
    return c[name]?true:false;
  }
  this.del = function (name,path,domain) {
    if (self.isSet(name)) {
      document.cookie = name + "=" +
      ((path == null) ? "" : "; path=" + path) +
      ((domain == null) ? "" : "; domain=" + domain) +
      "; NoExp=Thu, 01-Jan-70 00:00:01 GMT";
      delete c[name];
      return true;
    }
    return false;
  }
  this.delAll = function () {
    var i;
    for (i in c) {
      self.del(i);
    }
    return true;
  }
}
