 	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(divid)
{
		var outputdiv;
		if (divid && document.getElementById(divid)) {
			outputdiv = document.getElementById(divid);
		}
		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";
			
		}
    
if (outputdiv) {
	outputdiv.innerHTML += ("<!--"+mydomain+":"+inStance+":"+targetDomain+"-->");
} else {
	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);
	
	
	outputdiv.innerHTML += ('<li><a href="http://' +mydomain+'/uumsweb/login.do?property=100010&target='+escape(document.location.toString())+'">sign in &gt;</a></li><li><a href="http://'+mydomain+'/uumsweb/displayLiteSignup.do?property=100010&tier=1&target='+escape(document.location.toString())+'">register &gt;</a></li>');

  }else{
		if(val==""){
			outputdiv.innerHTML += ('<li><span><a href="http://'+mydomain+'/uumsweb/displayProfile.do?property=100010&tier=2&target='+escape(document.location.toString())+'">Hello, ' + val + '</a></span></li><li><a href="http://'+mydomain+'/uumsweb/logout.jsp?property=100010&target='+escape('http://'+targetDomain+'/index.jsp')+'">[Sign Out]</a></li>');
		}else{
			var x = val;
			var y = x.split("|");
			screenName = y[5];

			if ( screenName == "") {
				screenName = y[2];	
			}
			
			outputdiv.innerHTML += ('<li><span><a href="http://'+mydomain+'/uumsweb/displayProfile.do?property=100010&tier=2&target='+escape(document.location.toString())+'">Hello, ' + screenName + '</a></span></li><li><a href="http://'+mydomain+'/uumsweb/logout.jsp?property=100010&target='+escape(document.location.toString())+'">[Sign Out]</a></li>');
	  }
  }
  }

 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;
			}
 }
