
function Cookie(sCookieName, sCookieDomain) {
    
    this.sCookieName   = sCookieName || 'defaultCookieName';
    this.nExpires      = 30 //(30*24*60*60*1000); // (3*365*24*60*60*1000) = default expires 3 years
    this.sPath         = '/';                   // default path
    this.sDomain       = sCookieDomain || '';                    // default domain
    this.sDelimiter    = '|';                   // default delimiter
    this.bValidCookie  = false;                 // set true if cookie found
    this.aData         = new Array();           // Associative array of cookie Array[name] => value
    this.zozo           =   '';
    this.readCookie();
}    
    
Cookie.prototype.readCookie = function () {  
    
    // reset vars in case we are re-reading the cookie
    this.bValidCookie = false;
    this.aData   = new Array();
    
    var cName    = this.sCookieName;
    var aAll     = document.cookie.split('; ');
    var sFull    = '';
    if (aAll) {
		for (var i = 0; i < aAll.length; i++) {
			if (aAll[i].substr(0, cName.length) == cName) {
				sFull = aAll[i].substr(cName.length + 1, aAll[i].length - (cName.length - 1));
				break;
			}
		}
        this.zozo = document.cookie;
		this.aData = sFull.split("&");
        this.bValidCookie = true;
    }
}  

Cookie.prototype.getValue = function (key) {  
    var objValues = this.aData;
    if (this.bValidCookie) {
        if (this.aData) {
            for (var i = 0; i < this.aData.length; i++) {
                var skey = this.aData[i].split("=")[0];
                var sval = this.aData[i].split("=")[1];
                if (skey.toString() == key.toString()) {return sval;break;}
            }
        }
    }
    return '';
}  

Cookie.prototype.setValue = function (key, value) {  
    
    var strCookie = '';
    var val = '';
    var isSet = false;
    if (!this.bValidCookie) this.readCookie();
    if (this.aData) {
        for (var i = 0; i < this.aData.length; i++) {
            var skey = this.aData[i].split("=")[0];
            var sval = this.aData[i].split("=")[1];
            if (skey.toString() == key.toString()) {this.aData[i] = skey + '=' + value;isSet=true;break}
        }
        if (!isSet) {this.aData.push(key + "=" + value);}
    }
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+ this.nExpires);
    document.cookie = this.sCookieName + "=" + this.aData.join("&") + ";path=/; domain=" + this.sDomain + '; expires='+exdate.toGMTString() ;
}  


Cookie.prototype.clearCookie = function () {
    aCookie = new Array();
    aCookie.push(this.sCookieName + '=;');
    aCookie.push('expires=Thu, 01-Jan-70 00:00:01 GMT;');
    aCookie.push('path=' + this.sPath + ';');
    if (this.sDomain.length > 0) aCookie.push('domain=' + this.sDomain + ';');
    document.cookie = aCookie.join('');
    this.readCookie();
}

