/* COOKIES.JS - JavaScript Cookies Library (version 1.1)
** =====================================================
** Copyright 1999, Richard Scott (version 1.1). All rights reserved.
**   Streamlined Cookie(), Cookie_store(), Cookie_get(), Cookie_del().
**   Removed document parameter from Cookie() constructor function.
**   Removed CookieTable() diagnostic tool.
**   Added explanatory comments.
**
** Copyright 1997, Christopher Doemel (version 1.0). All rights reserved.
**   There are several good JavaScript cookie libraries around.
**   One is Bill Dortch's public domain cookie functions
**   (at http://www.hidaho.com/cookies/cookie.txt), and another is David 
**   Flanagan's cookie example in JavaScript: The Definitive Guide, 
**   published by O'Reilly Press. This library combines the best features 
**   of both: The thoroughness of Dortch's cookie functions, and the 
**   object-oriented design of Flanagan's cookie example.
*/

function Cookie(name, expires, domain, path, isSecure)
  {
  this.name     = name;
  this.expires  = expires;
  this.domain   = domain;
  this.path     = path;
  this.isSecure = isSecure;

  if (this.expires)
    fixCookieDate(this.expires);
  }
  
function fixCookieDate(theDate)
  {
  var testDate = new Date(0); 
  var skew = testDate.getTime();
  if (skew > 0)
    theDate.setTime(theDate.getTime() - skew);
  }

function Cookie_get()
  {
  var theWholeCookie = document.cookie;
  var cookieStart = theWholeCookie.indexOf(this.name);

  if (cookieStart == -1)
    return "";
  else
    cookieStart += this.name.length + 1;  

  var cookieEnd = theWholeCookie.indexOf(";", cookieStart);
   
  if (cookieEnd == -1)
    cookieEnd = theWholeCookie.length;
  var theCookie = theWholeCookie.substring(cookieStart, cookieEnd);

  return unescape(theCookie);
  }

function Cookie_store(string)
  {
  document.cookie = 
    this.name + "=" + escape(string) + 
    ((this.expires) ? "; expires=" + this.expires.toGMTString() : "") + 
    ((this.path) ? "; path=" + this.path : "") + 
    ((this.domain) ? "; domain="  + this.domain : "") + 
    ((this.isSecure) ? "; secure" : "");
  }

function Cookie_del()
  {
  document.cookie = 
    this.name + "=" +
    ((this.expires) ? "; expires=" + (new Date(0)).toGMTString() : "") + 
    ((this.path) ? "; path=" + this.path : "") + 
    ((this.domain) ? "; domain=" + this.domain : "");
  }

new Cookie();  // need to create a "dummy" Cookie object first
Cookie.prototype.store = Cookie_store;
Cookie.prototype.get   = Cookie_get;
Cookie.prototype.del   = Cookie_del;

