/* Cookie object for reading and writing cookies 
    Copyright (c)  2006 Stephen Cox 
    mail@stephencox.net
    
    Free for use as long as this message is left intact.
    
    Last updated 8.03.06
*/

// Cookie object
function Cookie(name, value, expires, path, domain, secure) {
    this.name = name;
    this.value = value;
    if (expires) this.expires = expires; else this.expires = null;
    if (path) this.path = path; else this.path = null;
    if (domain) this.domain = domain; else this.domain = null;
    if (secure) this.secure = secure; else this.secure = null;
};

// Instances methods for using the cookie

// Store the Cookie object
Cookie.prototype.store = function() {
    var cookie = escape(this.name) + '=' + escape(this.value);
    if (this.expires) cookie += '; expires=' + this.expires.toGMTString();
    if (this.path) cookie += '; path=' + this.path;
    if (this.domain) cookie += '; domain=' + this.domain;
    if (this.secure) cookie += '; secure';
    document.cookie = cookie;
};


// Class methods for creating and destroying Cookie objects

// Return a Cookie object with cookie name, if it doen't exist return null
Cookie.read = function(cookieName) {
    var name, value, expires, path, domain, secure;
    var cookies = document.cookie;
    var start = cookies.indexOf(escape(cookieName) + '=');
    if (start == -1)
        return null;
    else {
        name = cookieName;
        start += cookieName.length + 1;
        var end = cookies.indexOf(';', start);
        if (end == -1) end =  cookies.length;
        value = unescape(cookies.substring(start, end));
        return new Cookie(name, value);
    }
};

// Delete the cookie with cookieName
Cookie.remove = function(cookieName) {

};



















