/******************************************************************

Copyright © Global Knowledge Software LLC 2006.  All Rights Reserved.

This program is protected by U.S. and International Copyright and
Patent Laws.  Unauthorized duplication and/or distribution of this
program is strictly prohibited. Distribution and duplication of this
program are limited by license. If you do not currently have a valid
license from Global Knowledge for this program, any copying or
distribution of the program is unauthorized.  If you do have a current
license from Global Knowledge to utilize this program, your use is
strictly limited by the terms of that license.

Patent Pending.

******************************************************************/

var systemEnableCookies = true;

function Cookie(doc,name,exp,path,domain,secure)
{
	this.$document=doc;
	this.$name=name;
	if (exp)
		this.$exp=new Date((new Date()).getTime()+exp*3600000*24);
	else
		this.$exp=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;
}

Cookie.prototype.Store = function()
{
	if (!systemEnableCookies)
		return;

	var cookieval="";
	for (var prop in this)
	{
		if ((prop.charAt(0)=="$") || ((typeof this[prop])=='function'))
			continue;
		if (cookieval!="")	cookieval+="&";
		cookieval+=prop+":"+escape(this[prop]);
	}
	
	var cookie=this.$name+"="+cookieval;
	if (this.$exp)
		cookie+="; expires="+this.$exp.toGMTString();
	if (this.$path)	cookie+="; path="+this.$path;
	if (this.$domain)	cookie+="; domain="+this.$domain;
	if (this.$secure)	cookie+="; secure=";
	
	this.$document.cookie=cookie;
}

Cookie.prototype.Load = function()
{
	if (!systemEnableCookies)
		return false;

	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++)
	{
		var p=a[i].split(":");
		this[p[0]]=unescape(p[1]);
	}
	
	return true;	
}

Cookie.prototype.Remove = function()
{
	if (!systemEnableCookies)
		return;

	var 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;
}
