 	 
 	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';

 	function Get_Cookie() {

			var a_all_cookies = document.cookie.split( ';' );
			var a_temp_cookie = '';
			var cookie_name = '';
			var cookie_value = '';
			var b_cookie_found = false; // set boolean t/f default f
			
			for ( i = 0; i < a_all_cookies.length; i++ )
			{
				a_temp_cookie = a_all_cookies[i].split( '=' );
				
				
				cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
			
					if ( cookie_name == "ext" )
				{
					// window.alert("we found this cookie");
					b_cookie_found = true;
					if ( a_temp_cookie.length > 1 )
					{
						cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
					}
					return cookie_value;
					break;
				}
				
				a_temp_cookie = null;
				cookie_name ='';
			}
			if ( !b_cookie_found )
			{
				return null;
			}
}		

function checkDocument()
 {
		var url = document.URL;
   		var url1 = url.split("/");
   		var appUrl = url1[2];
		var instanceName = appUrl.split(".");
		var inStance = instanceName[0];
		var mydomain="my.sportsnet.ca";
		var targetDomain = "";
		if ( inStance == "rsndev" ){
			mydomain = "my.sportsnet.ca";
			targetDomain = "rsndev.sportsnet.ca";
		}
		if ( inStance == "rsnstage" ){
			mydomain = "my.sportsnet.ca";
			targetDomain = "rsnstage.sportsnet.ca";
		}
		if ( inStance == "www" || inStance == "my"){
			mydomain = "my.sportsnet.ca";
			targetDomain = "www.sportsnet.ca";
		}
		if ( inStance == "qa" ){
			mydomain = mydomain.replace(/qa/,"");
			mydomain = 'qa'+ mydomain ;
			targetDomain = "qa.sportsnet.ca";
		}
		if ( inStance == "dev" ){
			targetDomain = "dev.sportsnet.ca";
		}

		if ( inStance == "communities" ){
			targetDomain = "www.sportsnet.ca";
			
		}
    
document.write("<!--"+mydomain+":"+inStance+":"+targetDomain+"-->");


var or="or";
var  val = Get_Cookie();

var userId = Get_UserID();

  if(val== null){
	//alert("mydomain :"+mydomain);
	//alert("appUrl :"+appUrl);
	//alert("appUrl :" +inStance);
	
document.write("<div class=\"greeting\"><span>Hello, "+"<a href='http://" +mydomain+"/uumsweb/login.do?property=100010&target="+escape(document.location.toString())+"' class='sign-in-link'>Login</a></span>"+" "+or +" <a href='http://"+mydomain+"/uumsweb/displayLiteSignup.do?property=100010&tier=1&target="+escape(document.location.toString())+"' title='Register with sportsnet.ca to post comments to our news articles, columnists, blogs and community forums.'>Register</a></div><div><a style=\"text-decoration:none\" title=\"Register with sportsnet.ca to post comments to our news articles, columnists, blogs and community forums.\">Why should I register </a><a href='#' title='Register with sportsnet.ca to post comments to our news articles, columnists, blogs and community forums.' style=\"font-weight:bold\">[?]</a></div>");

  
  }else{
	  if(val==""){
		
		document.write("<div class=\"greeting\"><span>Welcome! " + val + "<br /><a href='http://"+mydomain+"/uumsweb/displayProfile.do?property=100010&tier=2&target="+escape(document.location.toString())+"'>" + " "+"Profile"+"  |" + "</a><a href='http://"+mydomain+"/uumsweb/logout.jsp?property=100010&target=http://"+targetDomain+"/index.jsp'> Sign out</a></div>");
	  }else{
			var x = val;
			var y = x.split("|");
			screenName = y[5];

			if( screenName == "")
			  {
				screenName = y[2];	
			  }
		
			document.write("<div class=\"greeting\"><span>Welcome, " + screenName + "<br /><a href='http://"+mydomain+"/uumsweb/displayProfile.do?property=100010&tier=2&target="+escape(document.location.toString())+"'>Profile</a> | <a href='http://"+mydomain+"/uumsweb/logout.jsp?property=100010&target="+escape(document.location.toString())+"'> Sign out</a></div>");	

		 
	  }
  }
  }

 function removeCookie()
 {
 if(cookie_name=="NEW_COOKIE1")
 {
 	cookie_name=="";
 	cookie_value=="";
 	
 }
 }

 function Get_UserID(){

			var a_all_cookies = document.cookie.split( ';' );
			var a_temp_cookie = '';
			var cookie_name = '';
			var cookie_value = '';
			var b_cookie_found = false; // set boolean t/f default f
			
			for ( i = 0; i < a_all_cookies.length; i++ )
			{
				a_temp_cookie = a_all_cookies[i].split( '=' );
				
				//window.alert("we found this cookie"+ a_temp_cookie);
				cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
			
				if ( cookie_name == "uid" )
				{
					//window.alert("we found the UID cookie");
					b_cookie_found = true;
					if ( a_temp_cookie.length > 1 )
					{
						cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
					}
					//window.alert("Returning +"+cookie_value);
					return cookie_value;
					break;
				}
				
				a_temp_cookie = null;
				cookie_name ='';
			}
			if ( !b_cookie_found )
			{
				return null;
			}
 }
