
function GetCookie(name)
{
	var cookiefound = 0;
	var start = 0;
	var end = 0;
	
	var cookiestring = document.cookie;
	
	var i = 0;
	while(i < cookiestring.length)
	{
		start = i;
		end = start + name.length;
		if (cookiestring.substring(start, end) == name)
		{
			cookiefound = true;
			break;
		}
		i++;
	}	
	if (cookiefound)
	{
		start = end + 1;
		end = document.cookie.indexOf(';', start);
		if (end != -1 || start != document.cookie.length)
		{
			if (end < start)
				end = document.cookie.length;

		
			return document.cookie.substring(start, end);
		}
		else
		{
			end = cookiestring.length;
			return document.cookie.substring(start, end);
		}

	}
	return '';	
}

function IsLoggedIn()
{
	myString = document.cookie;
	crosssite = GetCookie('email');
	xflag = GetCookie('xflag');
	exists = myString.indexOf('email=');
	existsNet = myString.indexOf('email=;');
	if (exists == -1){return false;} 
	else if(existsNet != -1){return false;}
	else if (xflag == 'y' && exists == 0){return false;}
	else if (xflag == 'y'){return false;} 
	else{return true;}
}

function checkbutton()
{
	button = GetCookie('button');
	if (button == 't'){return true;}
	else {return false;}	
}

function LoggedLink(link) {
	myString = document.cookie;
	exists = myString.indexOf('email=');	
	if (exists == -1 | existsNet == -1) {location.href  = link + '?opcode=login'} 
	else if(existsNet != -1){location.href  = link + '?opcode=login'}	
	else {location.href  = link + '?opcode=logout'}
}
