// AJB 1/11/2001, cookie.js
// (very) Simple cookie handling

// Example usage:
// var Xcookie = new obiCookie( "LimitArchive", 365 );
// ( First Param is cookie name, second is desired expirey time in days)
//
// 1. Read Cookie
// var theCookie = Xcookie.GetCookie();
// if ( null == theCookie )
//        // Cookie does not exist
// else
//        // the cookie value can be taken either
//        // from the return value or from the .cookieVal property
//        var x = theCookie;
//        var x = Xcookie.cookieVal;
//
// 2. Write Cookie (Expiry time as in object initialisation)
// Xcookie.SetCookie( "106" );
//
// 3. Delete Cookie
// Xcookie.KillCookie();
//

// My Type 'obiCookie'

// Constructor
function obiCookie( theCookieName, theExpireTimeInDays ){
    this.CookieName = theCookieName;
    this.cookieVal = null;
    this.expireTimeInMs = theExpireTimeInDays * 1000 * 60 * 60 * 24;
}

// Methods
obiCookie.prototype.GetCookie = function(){  
    // Look for our named cookie
    var i = document.cookie.indexOf( this.CookieName + "=" );
    if ( -1 != i ){
        var e = document.cookie.slice( i ).indexOf( ";" );
        this.cookieVal = document.cookie.slice( 
            i+this.CookieName.length+1,
            (-1 != e)?e:document.cookie.length );
        return this.cookieVal;}
    return null;
}

obiCookie.prototype.SetCookie = function( Value ){
    var expireDate = new Date(); 
    expireDate.setTime( expireDate.getTime() + this.expireTimeInMs );

    var cookietext = this.CookieName + "=" + Value + 
        "; expires=" + expireDate.toGMTString();
    document.cookie = cookietext;
    this.cookieVal = Value; 
}

obiCookie.prototype.KillCookie = function(){
    var expireDate = new Date(); 
    document.cookie = this.CookieName + "=0" + 
        "; expires=" + expireDate.toGMTString();
    this.cookieVal = null; 
}

obiCookie.prototype.GetValue = function(){
    return this.cookieVal;
}
