// Cookie.js
// 2008-02-20
// Chieh Cheng

function Cookie (name)
{
  this.name = name;
  this.path = "/";
  this.time = 3600 * 24 * 30;   // 30 Days in seconds
  this.value = "";
}

Cookie.prototype.name;
Cookie.prototype.path;
Cookie.prototype.time;
Cookie.prototype.value;

Cookie.prototype.deliver = function ()
{
  var expires = '';
  var date = new Date ();
  date.setTime (date.getTime () + this.time * 1000);
  expires = "; expires=" + date.toGMTString ();
  document.cookie = this.name + "=" + escape (this.value) + expires + "; path=" + this.path;  
}

Cookie.prototype.getName = function ()
{
  return this.name;
}

Cookie.prototype.getPath = function ()
{
  return this.path;
}

Cookie.prototype.getTime = function ()
{
  return this.time;
}

Cookie.prototype.getValue = function ()
{
  return this.value;
}

Cookie.prototype.retrieve = function ()
{
  var regex = new RegExp (this.name + "s*=s*(.*?)(;|$)");
  var cookies = document.cookie.toString ();
  var match = cookies.match (regex);
  var result = "";

  if (match)
  {
    result = unescape (match [1]);
    this.value = result;
  }

  return result;
}

Cookie.prototype.setName = function (name)
{
  this.name = name;
}

Cookie.prototype.setPath = function (path)
{
  this.path = path;
}

Cookie.prototype.setTime = function (time)
{
  this.time = time;
}

Cookie.prototype.setValue = function (value)
{
  this.value = value;
}

Cookie.prototype.trash = function ()
{
  this.value = "";
  this.time = -1  
  this.deliver ();
}

