/*keep JAVASCRIPT COOKIES  Version 1.0
** ==================
**
** Copyright 1997, Christopher Doemel.  All rights reserved.  Use of this
** JavaScript library is permissible as long as this header remains intact.
**
** At least two cookie libraries are already available -- one is Bill Dortch's
** public domain cookie functions (http://www.hidaho.com/cookies/cookie.txt),
** and the second is David Flanagan's cookie example in _JavaScript: The
** Definitive Guide, 2nd Edition_ (ISBN 1-56592-234-4).  This library combines
** the best features of both libraries: the thoroughness of Dortch's cookie
** functions, and the object-oriented design of Flanagan's cookie example.
**
** Creating a new cookie:
**
**    var myCookie = new Cookie(name, document, expires, domain, path, isSecure);
**
** Storing information in a cookie:
**
**    var myInfo = "Hi there!";
**    myCookie.store(myInfo);
**
** Retrieving information from a cookie:
**
**    var cookieInfo = myCookie.get();
**
** Destroying (deleting) a cookie:
**
**    myCookie.destroy();
**
** Displaying a table with all cookies:
**
**    document.write(cookieTable());
keep*/
function Cookie(name, document, expires, domain, path, isSecure)
{
   this.$name = name;
   this.$document = document;
   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_store(string)
{
   var theCookie = this.$name + "=";

   // Use the escape() function to encode our cookie for storage.
   theCookie += escape(string);
   
   // Build the rest of the cookie parameters as necessary.
   theCookie += ((this.$expires) ? ("; expires=" +
      this.$expires.toGMTString()) : "");
   theCookie += ((this.$path) ? ("; path=" + this.$path) : "");
   theCookie += ((this.$domain) ? ("; domain="  + this.$domain) : "");
   theCookie += ((this.$isSecure) ? ("; secure") : "");
   
   this.$document.cookie = theCookie;
}
function Cookie_get()
{
   var theWholeCookie = this.$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_destroy()
{
   var theCookie = this.$name + "=";
   theCookie += ((this.$expires) ? ("; expires=" +
      (new Date(0)).toGMTString()) : "");
   theCookie += ((this.$path) ? ("; path=" + this.$path) : "");
   theCookie += ((this.$domain) ? ("; domain="  + this.$domain) : "");
   this.$document.cookie = theCookie;
}
new Cookie();
Cookie.prototype.store = Cookie_store;
Cookie.prototype.get = Cookie_get;
Cookie.prototype.destroy  = Cookie_destroy;


