
function delCookie(cookie_name)
{
    var exp = new Date();  
    exp.setTime(exp.getTime() - 1);   
	document.cookie = cookie_name + "=" + getCookie(cookie_name) + "; expires=" + exp.toGMTString();
}

function setCookie(cookie_name,cookie_val,cookie_path) 
{
	var	new_cookie = cookie_name + "=" + cookie_val + ";";
	new_cookie += " path=" + ( null != cookie_path ) ? cookie_path : "/";
	document.cookie = new_cookie;
}

function getCookieVal(cookie_text,offset,delim)
{
	var endstr = cookie_text.indexOf(delim,offset);
	if ( endstr == -1 )
	{
		endstr = cookie_text.length;
	}
	return unescape(cookie_text.substring(offset,endstr));
}

function getCookie(cookie_name) 
{
	var arg		= cookie_name.toLowerCase() + "=";
	var alen	= arg.length;
	var clen	= document.cookie.length;
	var i		= 0;
	
	while ( i < clen )
	{
		var j = i + alen;
		if ( document.cookie.substring(i,j).toLowerCase() == arg )
		{
			return getCookieVal(document.cookie,j,';');
		}
		i = document.cookie.indexOf(" ",i) + 1;
		if ( i == 0 )
			break;
	}
	return null;
} 

function getDictionaryCookie(cookie_name,key)
{
	var dictionary = getCookie(cookie_name);
	if ( null == dictionary )
		return null;

	var dict_src = dictionary.toLowerCase();
	var dict_key = key.toLowerCase() + '=';
	var startPos = -1;
	
	do
	{
		startPos = dict_src.indexOf(dict_key,startPos + 1);
		if ( -1 != startPos && (0 == startPos || '&' == dict_src.charAt(startPos-1)) )
		{
			return getCookieVal(dictionary,startPos + dict_key.length,'&');
		}
	}
	while ( -1 != startPos );
	return null;
}

function getVarsCookie(key)
{	// see /include/utility.inc
	return getDictionaryCookie('vars',key);
}

function getVars2Cookie(key)
{	// see /include/utility.inc
	return getDictionaryCookie('varsession',key);
}

function areBrowserCookiesEnabled()
{
	var cookie_name = "cookie_test";
	
	setCookie(cookie_name,"true","/");
	if ( null == getCookie(cookie_name) )
	{
		return false;
	}
	delCookie(cookie_name);
	return true;
}

function isAOLEnvironment()
{
	return (-1 != navigator.userAgent.indexOf("AOL"));
}