var CookieManager = function() { };
	
// Returns the value of the cookie if the cookie exists. Otherwise, it returns
// null.
	
CookieManager.getCookie = function(cookieName)
{
	
	var cookies = document.cookie;
	
	var startOfName = cookies.indexOf(cookieName + '=');
	
	if (startOfName < 0)
	{
		return null;
	}
	
	var startOfValue = startOfName + cookieName.length + 1;
	
	var endOfValue = cookies.indexOf(";", startOfValue);
	
	if (endOfValue == -1)
	{
		endOfValue = cookies.length;
	}
	
	var value = cookies.substring(startOfValue, endOfValue);
	
	value = unescape(value);
	
	if (value == "")
	{
		return null;
	}
	
	return value;
	
};

CookieManager.setCookie = function(name, value, expires, domain, path, secure)
{
	
	// First, deal with the name/value pair. These are separated by an equals
	// sign.
	
	var cookie = name + "=" + escape(value);
	
	// Now, create a function which appends parameters to our cookie.
	
	var append = function(name, value)
	{
		
		cookie += ";" + name;
		
		// The check for an empty string is to address the path issue mentioned
		// below.
		
		if (value || value == "")
		{
			cookie += "=" + value;
		}
		
	}
	
	if (expires)
	{
		append("expires", expires.toGMTString());
	}
	
	if (domain)
	{
		append("domain", domain);
	}
	
	if (path)
	{
		append("path", path);
	}
	else if (path == "")
	{
		
		// If the path is an empty string, then we want to render it as path=
		// to match the behavior of ASP. Internet Explorer is picky about path
		// decarations. The absense of a path attribute is not the same as a
		// path=.
		
		append("path", "");
		
	}
	
	// The secure attribute doesn't have a value.
	
	if (secure)
	{
		append("secure");
	}
	
	document.cookie = cookie;
	
};

CookieManager.deleteCookie = function(name, domain, path)
{
	
	var expires = new Date();
	
	CookieManager.setCookie(name, "", expires, domain, path);
	
};

CookieManager.supportsCookies = function()
{
	
	var name = "ThisIsATesT";
	
	var value = "Yes";
	
	CookieManager.setCookie(name, value);
	
	var retrievedValue = CookieManager.getCookie(name);
	
	if (retrievedValue == value)
	{
		
		CookieManager.deleteCookie(name);
		
		return true;
		
	}
	else
	{
		return false;
	}
	
};
