
//-------------- Cookie ---------------
// A Cookie-manipulation class
 
// Cookie constructor (A baker?)
function Cookie(document, name, hours, path, domain, secure)
{
   this.Xdocument = document;
   this.Xname = name;
   if (hours)
            this.Xexpiration = new Date((new Date()).getTime() + hours * 3600000);
    else this.Xexpiration = null;
    if (path) this.Xpath = path; else this.Xpath = null;
    if (domain) this.Xdomain = domain; //else this.Xdomain = null;
    if (secure) this.Xsecure = true; else this.Xsecure = false;
}//end function Cookie


function _Cookie_store()
{
    var cookieval = '';
    for (var prop in this) {
        if ((prop.charAt(0) == 'X') || ((typeof this[prop]) == 'function'))
                continue;
        if (cookieval != '') cookieval += '&';

        cookieval += prop + ':' + escape(this[prop]);
    }//endfor
    var cookie = this.Xname + '=' + cookieval;
    if (this.Xexpiration)
        cookie += '; expires=' + this.Xexpiration.toGMTString();
    if (this.Xpath) cookie += '; path=' + this.Xpath;
   
    // there's something awry with this next statement -- shows a bug
    // whereby domain gets set to current server no matter what.  this may be a Netscape problem.   
    //if (this.Xdomain) cookie += '; domain =' + this.Xdomain;
    cookie += '; domain=law.cornell.edu'
    if (this.Xsecure) cookie += '; secure';
    this.Xdocument.cookie = cookie;

}//end function _Cookie_store()

function _Cookie_load()
{
    var allcookies = this.Xdocument.cookie;
    if (allcookies == ""){
    return false;
    }
    
    var start = allcookies.indexOf(this.Xname + '=');
    if (start == -1){

     return false;
     }
    start += this.Xname.length + 1;
    var end = allcookies.indexOf(';', start);
    if (end == -1) end = allcookies.length;
    var cookieval = allcookies.substring(start, end);
    var a = cookieval.split('&');
    for (var i=0; i<a.length; i++)
        a[i] = a[i].split(':');
    for (var i=0; i<a.length; i++){
        this[a[i][0]] = unescape(a[i][1]);
    }//endfor

    return true;

}//endfunc _Cookie_load

function _Cookie_remove()
{
    var cookie;
    cookie = this.Xname + '=';
    if (this.Xpath) cookie += '; path=' + this.Xpath;
    if (this.Xdomain) cookie += '; domain=' + this.Xdomain;
    cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
    this.Xdocument.cookie = cookie;
}//endfunc _Cookie_remove

// prototype creation

new Cookie();
Cookie.prototype.store = _Cookie_store;
Cookie.prototype.load = _Cookie_load;
Cookie.prototype.remove = _Cookie_remove;

