// ---------------------------------------------------------------------------------------
function Cookie(aDocument, aName, aHours, path, domain, secure)
{
	this.$document = aDocument;
	this.$name     = aName;

	if (aHours)
	{
		this.$expiration = new Date((new Date()).getTime() + aHours*3600000);
	} else 
	{ 
		this.$expiration = null;
	}
	
	
	
	if (path) 
	{
		this.$path = path; 
	} else
	{
		this.$path = null;
	}
	
	if (domain)
	{
		this.$domain = domain;
	} else 
	{
		this.$domain = null;
	}
	
	if (secure)
	{
		this.$secure = true; 
	} else 
	{ 
		this.$secure = false;
	}
}

// ---------------------------------------------------------------------------------------
function CookieStore()
{
	var CookieVal = "";

	for(var Property in this) 
	{
		if ((Property.charAt(0) == '$') || ((typeof this[Property]) == 'function'))
		{
			continue;
		}

		if (CookieVal != "")
		{
			CookieVal += '&';
		}
		
		CookieVal += Property + ':' + escape(this[Property]);
	}

	var Cookie = this.$name + '=' + CookieVal;

	if (this.$expiration)
	{
		Cookie += '; expires=' + this.$expiration.toGMTString();
	}
	
	if (this.$path)
	{
		Cookie += '; path=' + this.$path;
	}
	
	if (this.$domain) 
	{
		Cookie += '; domain=' + this.$domain;
	}

	if (this.$secure) 
	{	
		Cookie += '; secure';
	}
	
	this.$document.cookie = Cookie;
}

// ---------------------------------------------------------------------------------------
function CookieLoad()
{
	var AllCookies = this.$document.cookie;
	if (AllCookies == "") return false;

	var Start = AllCookies.indexOf(this.$name + '=');
	if (Start == -1)
	{
		return false;  
	}

	Start += this.$name.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]);
	}

	return true;
}

// ---------------------------------------------------------------------------------------
function CookieRemove()
{
	var Cookie;

	Cookie = this.$name + '=';

	if (this.$path) 
	{
		Cookie += '; path=' + this.$path;
	}
	
	if (this.$domain)
	{
		Cookie += '; domain=' + this.$domain;
	}
	
	Cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';

	this.$document.cookie = Cookie;
}



new Cookie();

Cookie.prototype.Store  = CookieStore;
Cookie.prototype.Load   = CookieLoad;
Cookie.prototype.Remove = CookieRemove;

