// This script is used by the HMWHYBox control 
// to determine whether to display the personalized
// "Your Content" link and the "Sign Out" link.

var firstName = getCookieValue("FirstName").replace(/\+/g,  " ");
if (firstName != "")
{
	if (isInGlobalChannel() == true)
	{
		setYourContentCaption(firstName);
	}
		
	setSignOutVisibility(true);
}
else
{
	setSignOutVisibility(false);
}

function getCookieValue(cookieName)
{
	var cookieValue = "";
	var searchValue = cookieName + "=";
	
	if(document.cookie.length > 0)
	{ 
		var startIndex = document.cookie.indexOf(searchValue);
		if (startIndex != -1)
		{ 
			startIndex += searchValue.length;
			var endIndex = document.cookie.indexOf(";", startIndex);
			if (endIndex == -1) 
			{
				endIndex = document.cookie.length;
			}				
			cookieValue = unescape(document.cookie.substring(startIndex, endIndex));
		}			
	}
	
	return cookieValue;
}

function isInGlobalChannel()
{
	//NND 11.15.05 Added checking of "countries" string in url as cross checking
	//if page is in country channel.
	var returnValue = false;
	var countriesCheck = "countries";
	
	//RMT 2434 - Removed the querystring from in checking if the current
	//location is in the "Countries" channel
	var currentURL = unescape(document.location.href.toLowerCase());
	var querystringIndex = currentURL.indexOf("?");
	var pageURL = "";	

	//RMT 2434 - This checks if there is query string in the url and strips them
	//before evaluating if they are in the "Countries" channel		
	if (querystringIndex >= 0)
	{
		pageURL = currentURL.substring(0, querystringIndex);
	}
	else
	{
		pageURL = currentURL;
	}

	//NND 07.28.06 isCountry Variable is dropped by HMWHY for search page and 
	//set by search page if posting which initiated search is country channel
	if (isCountry != undefined)
	{
		if (isCountry == true)
		{
			returnValue = false;
		}
	}
	else
	{
		//RMT 2434 - Removed the checking of the UserPref Cookie to fix the 
		//personalization of the Your Content link for aspx pages.
		if (pageURL.indexOf(countriesCheck) == -1)
			{ 
				returnValue = true;	
		}
	}
	return returnValue;
	
}

function setYourContentCaption(firstName)
{	
	var labelObject = getYourContentLabel();			
	if (labelObject != null)
	{ 
		labelObject.innerHTML = "<span style='color:Red'>" + firstName + "'s Content" + "</span>";
	}
		
	var linkObject = getYourContentLink();
	if (linkObject != null)
	{ 
		linkObject.innerHTML = firstName + "'s Content";
	}							
}

function setSignOutVisibility(isVisible)
{
	var labelObject = getSignOutLabel();
	if (labelObject != null)
	{
		setObjectVisibility(labelObject, isVisible);
	}
	
	var linkObject = getSignOutLink();
	if (linkObject != null)
	{
		setObjectVisibility(linkObject, isVisible);
	}
	
	var imageObject = getSignOutImage();
	if (imageObject != null)
	{
		setObjectVisibility(imageObject, isVisible);
	}				
		
	//Hide or show Sign out row
	var signOutRow = getElement("SignOutRow");
	if (signOutRow != null && isVisible == false)
	{
		setObjectVisibility(signOutRow, isVisible);
	}
	
	
}

function setObjectVisibility(targetObject, isVisible)
{
	if (targetObject.style) 
	{ 			
		if (isVisible)
		{
			targetObject.style.display = "inline";				
		}
		else
		{
			targetObject.style.display = "none";
		}					
	} 		
}	
	

function getYourContentLabel()
{	
	var labelObject = getHMWHYBoxElement("lblContent");

	return labelObject;
}


function getYourContentLink()
{	
	var linkObject = getHMWHYBoxElement("lnkContent");

	return linkObject;
}


function getSignOutLabel()
{	
	var labelObject = getHMWHYBoxElement("lblSign");

	return labelObject;
}


function getSignOutLink()
{	
	var linkObject = getHMWHYBoxElement("lnkSign");

	return linkObject;
}

function getSignOutImage()
{	
	var imageObject = getHMWHYBoxElement("imgGASign");

	return imageObject;
}	

function getHMWHYBoxElement(id) 
{	
	
	if (document.getElementById) 
	{
		return document.getElementById(ctrlPrefix + "_" + id);
	}
	else if (document.all) 
	{
		return document.all[ctrlPrefix + "_" + id];
	}
}

function getElement(id) 
{	
	
	if (document.getElementById) 
	{
		return document.getElementById(id);
	}
	else if (document.all) 
	{
		return document.all[id];
	}
}

/*
Function to set alignment of HMWHY arrow images, images are
left aligned(default) if isMouseOver flag is set to false
else images are right aligned
*/
function SetArrowImage(id, isMouseOver)
{
	try
	{
		var imageObject = getHMWHYBoxElement(id);

		if(isMouseOver)
		{
			imageObject.align = 'Right';
		}
		else
		{
			imageObject.align = '';
		}
	}
	catch(e)
	{
	}
}
