/**********************************************************************************
	xCookie	namespace
					Provides some basic javascript methods to setting and getting the cookies and crumbs.
					Crumbs are name value pairs within a cookie.  generally the crumbs are delimited by the
					pipe delimiter and name value pairs delimited by #
	Author:		W.Sietz		Feb 2006

**********************************************************************************/
var xCookie = {

	//SET
	set: function(CookieName, CookieValue, ExpireDate, Path, Domain, Secure)	 {
		//var ExpireDate = new Date ();		//13/06/2003 00:00:00
		//ExpireDate.setTime(ExpireDate.getTime() + ((!expiredays ? 1:expiredays) * 24 * 60 * 60 * 1000));
		var strCookie = 
			(CookieName+'='+escape(CookieValue)+'; ') +
			((ExpireDate) ? 'expires='+ExpireDate.toGMTString()+'; ' : '') + 
			(((Path)&&(Path!='')) ? 'path='+Path+'; ' : '') + 
			(((Domain)&&(Domain!='')) ? 'domain='+Domain+'; ' : '') +
			((Secure) ? 'secure ' : '') ;
		document.cookie=strCookie;
		},


	//SETCRUMB
	setCrumb: function(CookieName, CrumbName, CrumbValue, ExpireDate, Path, Domain, Secure)	 {
		var strCookieValue = this.get(CookieName);
		if (!CrumbName || CrumbName=='')		return;
		if (!strCookieValue || strCookieValue=='')	{
			strCookieValue = CrumbName+"#"+CrumbValue;
			this.set(CookieName, strCookieValue, ExpireDate, Path, Domain, Secure);
			return;
			}
		var Crumbs = strCookieValue.split('|');
		var fnd=false;
		var aCrumb;
		for (var j=0; j < Crumbs.length; j++)	 {
			var aCrumb = Crumbs[j].split('#');
			if (CrumbName == aCrumb[0])		{
				Crumbs[j] = CrumbName+"#"+escape(CrumbValue);
				fnd=true;
				}
			}
		if (fnd==false)	{
			Crumbs[Crumbs.length]=CrumbName+"#"+CrumbValue;
			}
		strCookieValue=Crumbs.join('|');
		this.set(CookieName, strCookieValue, ExpireDate, Path, Domain, Secure);
		},


	//GET			CookieName=CookieValue;    or	CookieName=Crumb|Crumb|Crumb;	where Crumb is  CrumbName#CrumbValue
	get: function(CookieName, CrumbName)	{
		// cookies are separated by semicolons
		if (!document || !document.cookie || document.cookie.length <= 0 || !CookieName || CookieName=='')	return null;
		var CookieValue=null;
		var search=CookieName+'=';
		var offset = document.cookie.indexOf(search);
		if (offset == -1)  return '';

		offset += search.length;
		var end = document.cookie.indexOf(';', offset);
		end = (end == -1 ? document.cookie.length:end);
		CookieValue = unescape(document.cookie.substring(offset, end));
		if (!CrumbName || CrumbName=='')		return CookieValue;
		
		var Crumbs = CookieValue.split('|');
		for (var j=0; j < Crumbs.length; j++)	 {
			var aCrumb = Crumbs[j].split('#');
			if (CrumbName == aCrumb[0])		return unescape(aCrumb[1]);
			}
		},


	//REMOVE
	remove: function(CookieName)	{
		if ( this.get(CookieName) )	{
			//document.cookie = CookieName + '=; path=' + ((!path) ? '/' : path) + '; expires=' + new Date(0).toGMTString();
			document.cookie = CookieName + '=; expires=Thu, 01-Jan-70 00:00:01 GMT';
			}
		},


	//TEST	Test for cookie support
	isSupported: function()	{
		var tf = false;
		//var savecookie = document.cookie;
		this.set('_%_','Y1');
		if ( 'Y1' == this.get('_%_') )	 {
			tf = true;
			this.remove('_%_');
			}
		return tf;
		}


	//
	/*
	this.buildMatrix = function fxBuildMatrix(strCookies){
		var crumbs = 'expires|path|domain|secure';
		var arrCookie;
		var arrCookies=strCookies.split('; ');
		for(var intIndex=0; intIndex<arrCookies.length; intIndex++){
			arrCookie=arrCookies[intIndex].trim().split('=');
			arrCookie[1]=unescape(arrCookie[1]);
			arrCookies[intIndex]=arrCookie;
			}
		return arrCookies;
		}
	*/
}



