// This next little bit of code tests whether the user accepts cookies.
var acceptsCookies = false;
var strCookieValue;
var strRes;

if(document.cookie == ''){
	document.cookie = 'acceptsCookies=yes'; // Try to set a cookie.
	if(document.cookie.indexOf('acceptsCookies=yes') != -1){	
		acceptsCookies = true;
	}
}
else {
	acceptsCookies = true;
}

function setCookie (name, value, hours, path, domain, secure)
{
	if (acceptsCookies)
	{
		var not_NN2 = (navigator && navigator.appName
			&& (navigator.appName == 'Netscape')
			&& navigator.appVersion
			&& (parseInt(navigator.appVersion) == 2))?false:true;

		if(hours && not_NN2)
		{ // NN2 cannot handle Dates, so skip this part
			if ( (typeof(hours) == 'string') && Date.parse(hours) )
			{ // already a Date string
				var numHours = hours;
			}
			else if (typeof(hours) == 'number')
			{ // calculate Date from number of hours
				var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
			}
		}
		document.cookie = name + '=' + value + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.
	}
} // setCookie

function getCookie(name)
{
	if(document.cookie == '')
	{ // there's no cookie, so go no further
		return '';
	}
	else
	{ // there is a cookie
		var firstChar, lastChar;
		var theBigCookie = document.cookie;
		firstChar = theBigCookie.indexOf(name); // find the start of 'name'
		var NN2Hack = firstChar + name.length;
		if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '='))
		{ // if you found the cookie
			firstChar += name.length + 1; // skip 'name' and '='
			lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
			if(lastChar == -1) lastChar = theBigCookie.length;
			return unescape(theBigCookie.substring(firstChar, lastChar));
		}
		else
		{ // If there was no cookie of that name, return false.
		return '';
		}
	}
} 

function killCookie(name, path, domain)
{
	var theValue = getCookie(name); // We need the value to kill the cookie
	if(theValue)
	{
		document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie
	}
}

//Funcao para alternancia de modo full screen
function setaFullScreen(objWindowToLoad, strAcao, codAluno, codCurso)
{
	var strCookie;
	var query_string;
	var arrLocation;
	var destino = '';
	var strParamFullscreen;
	arrLocation = location.href.split('?');
	if (arrLocation.length > 1)
		query_string = arrLocation[arrLocation.length-1];

	switch (strAcao)
	{
		case 'AtivaFullScreen':
			strParamFullscreen = ',fullscreen=yes';
			if (query_string.indexOf('fullscreen=S') == -1)
			{
				if (query_string.indexOf('fullscreen=N') != -1)
					query_string = query_string.replace('fullscreen=N','fullscreen=S');
				else
					query_string += '&fullscreen=S';
			}
			setCookie('FullScreen_'+codCurso+'_'+codAluno, 'S', '', false, false, false);
			break;
		case 'DesativaFullScreen':
			strParamFullscreen = ',width=800,height=545';
			if (query_string.indexOf('fullscreen=N') == -1)
			{
				if (query_string.indexOf('fullscreen=S') != -1)
					query_string = query_string.replace('fullscreen=S','fullscreen=N');
				else
					query_string += '&fullscreen=N';
			}
			setCookie('FullScreen_'+codCurso+'_'+codAluno, 'N', '', false, false, false);
			break;
		case 'AtivaBarraFlutuante':
			if (query_string.indexOf('barraflutuante=S') == -1)
			{
				if (query_string.indexOf('barraflutuante=N') != -1)
					query_string = query_string.replace('barraflutuante=N','barraflutuante=S');
				else
					query_string += '&barraflutuante=S';
			}
			setCookie('BarraFlutuante_'+codCurso+'_'+codAluno, 'S', '', false, false, false);
			break;
		case 'DesativaBarraFlutuante':
			if (query_string.indexOf('barraflutuante=N') == -1)
			{
				if (query_string.indexOf('barraflutuante=S') != -1)
					query_string = query_string.replace('barraflutuante=S','barraflutuante=N');
				else
					query_string += '&barraflutuante=N';
			}
			setCookie('BarraFlutuante_'+codCurso+'_'+codAluno, 'N', '', false, false, false);
			break;
	}

	destino = top.location.href.substring(0,top.location.href.indexOf('?'));
	destino += '?' + query_string;

	if (strAcao.indexOf('FullScreen') != -1)
	{
		objWindowToLoad.name = "TempTopicos";
		window.open(destino,'Topicos','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,left=0,top=0'+strParamFullscreen);
		objWindowToLoad.top.window.close();
	}
	else
	{
		top.location.href = destino;
	}
	return false;
}
