MiniCMS.Cookie = function( name ) {this.Name = name; this.Test = MiniCMS.CookieLib.GetCookie(this.Name)}
MiniCMS.Cookie.prototype.Get = function( name ) {return MiniCMS.CookieLib.GetCookieAttrib(this.Name,name)}
MiniCMS.Cookie.prototype.Set = function( name, value ) {MiniCMS.CookieLib.SetCookieAttrib(this.Name,name,value)}
MiniCMS.Cookie.prototype.Del = function( name ) {MiniCMS.CookieLib.SetCookieAttrib(this.Name,name,null)}
MiniCMS.Cookie.prototype.All = function() {return MiniCMS.CookieLib.GetCookie(this.Name)}

MiniCMS.CookieLib = new Object();
MiniCMS.CookieLib.COOKIE_DELIM = ";";
MiniCMS.CookieLib.COOKIE_KEYVAL = "=";
MiniCMS.CookieLib.ATTRIB_DELIM = ";";
MiniCMS.CookieLib.ATTRIB_KEYVAL = "=";


MiniCMS.CookieLib.GetRawCookie = function( name ) {
	var search = name + this.COOKIE_KEYVAL;
	if( document.cookie ) {
		if( document.cookie.length > 0 ) {
			offset = document.cookie.indexOf( search );
			if( offset != -1 ) {
				offset += search.length;
				end = document.cookie.indexOf( this.COOKIE_DELIM, offset );
				if( end == -1 )
					end = document.cookie.length;
				return unescape( document.cookie.substring(offset, end) );
			}
		}
	}
	return null;
}


MiniCMS.CookieLib.SetCookieAttrib = function( cookieName, attribName, attribValue ) {
	var attribMap = this.GetCookie( cookieName );
	attribMap[attribName] = attribValue;
	this.SetCookie( cookieName, attribMap );
}


MiniCMS.CookieLib.GetCookieAttrib = function( cookieName, attribName ) {
	var attribMap = this.GetCookie( cookieName );
	return attribMap[attribName];
}


MiniCMS.CookieLib.GetCookie = function( cookieName ) {
	var attribMap = new Array();
	var cookie = this.GetRawCookie( cookieName );
	if( cookie != undefined && cookie != null ) {
		var attribArray = cookie.split( this.ATTRIB_DELIM );
		for( i = 0; i < attribArray.length; i++ ) {
			var index = attribArray[i].indexOf( this.ATTRIB_KEYVAL );
			var name =  attribArray[i].substring( 0, index );
			var value = attribArray[i].substring( index + 1 );
			attribMap[name] = value;
		}
	}
	return attribMap;
}


MiniCMS.CookieLib.SetCookie = function( cookieName, attribMap ) {
	var attrib = "";
	for( name in attribMap ) {
		var value = attribMap[name];
		if( value != undefined && value != null && value != '' )
			if( name.indexOf(this.ATTRIB_KEYVAL) < 0 && value.indexOf(this.ATTRIB_KEYVAL) < 0 &&
				name.indexOf(this.ATTRIB_DELIM) < 0 && value.indexOf(this.ATTRIB_DELIM) < 0 ) {
				attrib += (attrib == '' ? '' : this.ATTRIB_DELIM);
				attrib += name + this.ATTRIB_KEYVAL + value;
			} else {
				alert( 'Cookie attribute name and/or value contains a delimeter (' +
					this.ATTRIB_KEYVAL + ' or ' + this.ATTRIB_DELIM + ').' );
			}
	}
	document.cookie = cookieName + this.COOKIE_KEYVAL + escape( attrib );
}