// 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 = "<span class=\"navspacer\">&nbsp;</span>";
	
	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("<span class=\"userwelcome\">Welcome</span>&nbsp;<span class=\"username\">"+ WelcomeName + "</span>");
			document.write(dividerHTML);
			document.write("<a class=\"userwelcome\" href=\"https://"+TempHost + buildWcsUrl("LiteLogoff", "12001")+ "\"  title=\"Not You?\">Not You?</a>");
			document.write(dividerHTML);
			document.write("<a class=\"userwelcome\" href=\"https://"+TempHost + buildWcsUrl("LogonForm","12001" )+  "\"  title=\"Login\">Login</a>");
			document.write(dividerHTML);
			document.write("<a class=\"userwelcome\" href=\"https://"+TempHost+ buildWcsUrl("UserProfileNavigation","12001")+ "\"  title=\"My Profile\">My Profile</a>");
		}
		else
		{
			//Logged in - Authenticated Users
			document.write("<span class=\"userwelcome\">Welcome</span>&nbsp;<span class=\"username\">"+ WelcomeName + "</span>");
			document.write(dividerHTML);
			document.write("<a class=\"userwelcome\" href=\"https://"+TempHost+ buildWcsUrl("Logoff", "12001")+ "\" title=\"Logout\">Logout</a>");
			document.write(dividerHTML);
			document.write("<a class=\"userwelcome\" href=\"https://"+TempHost+ buildWcsUrl("UserProfileNavigation", "12001")+ "\"  title=\"My Profile\">My Profile</a>");
		}
	}
	else if (hasLoginCookie != -1)
	{
		//Logged in - Authenticated Users but there in no nameCookie
		document.write("<span class=\"userwelcome\">Welcome</span>");
		document.write(dividerHTML);
		document.write("<a class=\"userwelcome\" href=\"https://"+TempHost + buildWcsUrl("Logoff", "12001")+ "\"  title=\"Logout\">Logout</a>");
		document.write(dividerHTML);
		document.write("<a class=\"userwelcome\" href=\"https://"+TempHost + buildWcsUrl("UserProfileNavigation", "12001")+ "\"  title=\"My Profile\">My Profile</a>");
	}
	else
	{
		//Not Logged in - Unknown Users
		document.write("<a class=\"userwelcome\" href=\"https://"+TempHost+ buildWcsUrl("LogonForm" , "12001" ) + "\" title=\"Login\">Login</a>");
		//document.write(dividerHTML);
		//document.write("<a class=\"userwelcome\" href=\"https://"+TempHost + buildWcsUrl("UserRegNavigation" , "12001" )+ "\" title=\"Register\">Register</a>");
		document.write(dividerHTML);
		document.write("<a class=\"userwelcome\" href=\"https://"+TempHost + buildWcsUrl("UserProfileNavigation", "12001")+ "\" title=\"My Profile\">My Profile</a>");
	}
