// globallinks.js
// This js contains the functions for creating html links
// author Rajib Das < rajirdas@in.ibm.com >
//
// Note: Pls take extreme care while modyfying 
//
	//create the links in the header 
	//get the host
	var TempHost=location.host;
	
	var hasLoginCookie = document.cookie.indexOf("UserID=Yes");
	var hasClientIDCookie = document.cookie.indexOf("ClientId=");
	var hasNameCookie = document.cookie.indexOf("WelcomeName=");
	var hasknownCookie = document.cookie.indexOf("AnonymousClientId=N");
	
	
	var dividerHTML = "<td width=\"1\" valign=\"bottom\"><img src=\"/images/g_divider_topnav.gif\" width=\"1\" height=\"10\" alt=\"\"></td>";
	
	if (hasNameCookie != -1)
	{
		var start = hasNameCookie + 12;		             // Start of cookie value
		var end = document.cookie.indexOf(";", start);            // End of cookie value
		if (end == -1) end = document.cookie.length;
		var WelcomeName = document.cookie.substring(start, end);  //Extract the value.
		WelcomeName = decodeURI(WelcomeName);
		WelcomeName = replaceString(WelcomeName, "+").toUpperCase();
		if (hasLoginCookie == -1)
		{
			//Not Logged in - Known Users (cookie detected)
			document.write("<td>Welcome <b>"+ WelcomeName + "</b></td>");
			document.write(dividerHTML);
			document.write("<td><a href=\"https://"+TempHost + buildWcsUrl("LiteLogoff", "11001")+ "\"  title=\"Not You?\">Not You?</a></td>");
			document.write(dividerHTML);
			document.write("<td><a href=\"https://"+TempHost + buildWcsUrl("LogonForm","11001" )+  "\"  title=\"Login\">Login</a></td>");
			document.write(dividerHTML);
			document.write("<td><a href=\"https://"+TempHost+ buildWcsUrl("UserProfileNavigation","11001")+ "\"  title=\"My Profile\">My Profile</a></td>");
			document.write(dividerHTML);
			document.write("<td><a href=\"https://"+TempHost+ buildWcsUrl("FavoriteListDisplayView" ,"11001" ) + "\"  title=\"Favorite Products\">Favorite Products</a></td>");
		}
		else
		{
			//Logged in - Authenticated Users
			document.write("<td>Welcome <b>"+ WelcomeName + "</b></td>");
			document.write(dividerHTML);
			document.write("<td><a href=\"https://"+TempHost+ buildWcsUrl("Logoff", "11001")+ "\" title=\"Logout\">Logout</a></td>");
			document.write(dividerHTML);
			document.write("<td><a href=\"https://"+TempHost+ buildWcsUrl("UserProfileNavigation", "11001")+ "\"  title=\"My Profile\">My Profile</a></td>");
			document.write(dividerHTML);
			document.write("<td><a href=\"https://"+TempHost+ buildWcsUrl("FavoriteListDisplayView" ,"11001" ) + "\"  title=\"Favorite Products\">Favorite Products</a></td>");
		}
	}
	else if (hasLoginCookie != -1)
	{
		//Logged in - Authenticated Users but there in no nameCookie
		document.write("<td>Welcome</td>");
		document.write(dividerHTML);
		document.write("<td><a href=\"https://"+TempHost + buildWcsUrl("Logoff", "11001")+ "\"  title=\"Logout\">Logout</a></td>");
		document.write(dividerHTML);
		document.write("<td><a href=\"https://"+TempHost + buildWcsUrl("UserProfileNavigation", "11001")+ "\"  title=\"My Profile\">My Profile</a></td>");
		document.write(dividerHTML);
		document.write("<td><a href=\"https://"+TempHost + buildWcsUrl("FavoriteListDisplayView" ,"11001" ) + "\"  title=\"Favorite Products\">Favorite Products</a></td>");
	}
	else
	{
		//Not Logged in - Unknown Users
		document.write("<td><a href=\"https://"+TempHost+ buildWcsUrl("LogonForm" , "11001" ) + "\" title=\"Login\">Login</a></td>");
		document.write(dividerHTML);
		document.write("<td><a href=\"https://"+TempHost + buildWcsUrl("UserRegNavigation" , "11001" )+ "\" title=\"Register\">Register</a></td>");
		document.write(dividerHTML);
		document.write("<td><a href=\"https://"+TempHost + buildWcsUrl("UserProfileNavigation", "11001")+ "\" title=\"My Profile\">My Profile</a></td>");
		if (hasknownCookie != -1)
		{
			document.write(dividerHTML);
			document.write("<td><a href=\"https://"+TempHost + buildWcsUrl("FavoriteListDisplayView" ,"11001" ) + "\" title=\"Favorite Products\">Favorite Products</a></td>");
		}
	}
	

