/******************************************
* Structure for handling cookies
******************************************/

function getCookie(name)
{
	cookies = document.cookie.split(/\s*;\s*/);
	for(var i = 0; i < cookies.length; i++)
	{
		cookie = cookies[i].split("=");
		if(cookie[0] == name)
		{
			return cookie[1];
		}
	}
	return null;
}

function setCookie(name, value, domain, path, expires)
{
	var cookieString = name + "=" + value + ";";
	if(domain)
	{
		cookieString += " domain="+ domain + ";";
	}
	if(path)
	{
		cookieString += " path=" + path + ";";
	}
	if(expires)
	{
		cookieString += " expires=" + expires.toGMTString() + ";";
	}
	document.cookie = cookieString;
}

function deleteCookie(name, domain, path)
{
	setCookie(name, null, domain, path, new Date());
}

function cookiesEnabled()
{
	setCookie("cookieTest", "now", null, null, new Date((new Date()).getTime()+10000));
	if(getCookie("cookieTest") != null)
	{
		deleteCookie("cookieTest", null, null);
		return true;
	}
	else
	{
		return false;
	}
}
