if(!utilities)
{
	var utilities = {};
}

if(!utilities.cookies)
{
	utilities.cookies = {};

	utilities.cookies.getCookie = function(strName)
	{
		var strCookies = document.cookie;
		var arrCookies = strCookies.split("; ");

		var strValue = undefined;

		for(var nIndex = 0; nIndex < arrCookies.length; ++nIndex)
		{
			var strCookie = arrCookies[nIndex];

			var nNameIndex = strCookie.indexOf(escape(strName) + "=");
			if(nNameIndex != -1)
			{
				nNameIndex += (escape(strName) + "=").length;

				strValue = strCookie.substring(nNameIndex);

				break;
			}
		}

		return strValue;
	}

	utilities.cookies.setCookie = function(strName, strValue, nLifeInDays)
	{
		var strExpirey = "";
		if(nLifeInDays)
		{
			var dDate = new Date();
			dDate.setDate(dDate.getDate() + nLifeInDays);

			strExpirey = "expires=" + dDate.toGMTString() + "; ";
		}

		document.cookie = escape(strName) + "=" + escape(strValue) + "; " + strExpirey + "path = /";
	}

	utilities.cookies.removeCookie = function(strName, strValue)
	{
		document.cookie = escape(strName) + "=" + escape(strValue) + "; expires=Thu, 01-Jan-70 00:00:01 GMT; path = /";
	}
}

function getCookieData(strPageName)
{
	var strPresenter = utilities.cookies.getCookie("presenter");
	var bNewPresenter;
	if(!strPresenter)
	{
		var arrPresenters = 
		[
			"sam",
			"james"
		];

		var nIndex = Math.floor(Math.random() * 2);
		strPresenter = arrPresenters[nIndex];

		utilities.cookies.setCookie("presenter", strPresenter);

		bNewPresenter = true;
	}
	else
	{
		bNewPresenter = false;
	}

	var strVisitorStatus;
	if(utilities.cookies.getCookie("visit_" + strPageName))
	{
		if(bNewPresenter)
		{
			strVisitorStatus = "firsttoday"
		}
		else
		{
			strVisitorStatus = "returntoday";
		}
	}
	else
	{
		strVisitorStatus = "firstever"
	}
	utilities.cookies.setCookie("visit_" + strPageName, "yes", 30);

	var strMute;
	if(!utilities.cookies.getCookie("mute"))
	{
		utilities.cookies.setCookie("mute", "no");
	}

	strMute = utilities.cookies.getCookie("mute");

	var oData = {};
	oData.presenter = strPresenter;
	oData.visitorStatus = strVisitorStatus;
	oData.mute = strMute;

	return oData
}

function setMute(strStatus)
{
	utilities.cookies.setCookie("mute", strStatus);
}

