	function readCookie(name) 
	{
    	var nameEQ = name + "=";
    	var ca = document.cookie.split(';');
    	for(var i=0;i < ca.length;i++) 
    	{
    		var c = ca[i];
    		while (c.charAt(0)==' ') c = c.substring(1,c.length);
    		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    	}
    	return null;
	}
	
	function userLoggedIn()
	{
		//return readCookie('userloggedin');
		return (readCookie('userloggedin') || readCookie('venda') != null || readCookie('VLUID') != null);
	}
	
	function textSize()
	{
		//return readCookie('userloggedin');
		var iTextSize = readCookie('tsz');
		
		if (iTextSize != null && iTextSize > 0)
		{
			document.write('<style type="text/css" media="screen"><!--body { font-size: '+iTextSize+'px; }--></style>');
		}
		
	}	
	
	function getProfileLink(link)
	{
		var href = ''; var text = '';
		
		if (link == 0)
		{
			href = (userLoggedIn()) ? '/myprofile?mode=logout':'/login';
			text = (userLoggedIn()) ? 'Logout':'Login';
		}
		else if (link == 1)
		{
			href = (userLoggedIn()) ? '/myprofile':'/registration';
			text = (userLoggedIn()) ? 'Profile':'Register';
		}else if (link == 2)
        {
			href = (userLoggedIn()) ? '/usa/myprofile?mode=logout':'/usa/login';
			text = (userLoggedIn()) ? 'Logout':'Login';
        }
		else if (link == 3)
		{
			href = (userLoggedIn()) ? '/usa/myprofile':'/usa/register';
			text = (userLoggedIn()) ? 'Profile':'Register';
        }
		document.write('<a id="loginLink" href="'+href+'" class="login">'+text+'</a>');
	}
	
	function toggleShowHide(sDiv)
	{
		if (document.getElementById(sDiv).style.display == "block")
		{
			document.getElementById(sDiv).style.display = "none";
		}else{
			document.getElementById(sDiv).style.display = "block";
		}
	}	
	
	function popup(name, sUrl, width, height) {
		window.open(sUrl, name,'width='+width+'px,height='+height+'px,menubar=no,status=yes,scrollbars=no,toolbar=no,location=no,directories=no,resizable=yes,top=25,left=30'); 
		return false; //necessary so it doesn't follow href 
	}
	
	function externalLinks()
	{
		 if (!document.getElementsByTagName) return;
		 var anchors = document.getElementsByTagName("a");
		
		 for (var i=0; i<anchors.length; i++) {
		   var anchor = anchors[i];
		   if (anchor.getAttribute("id") == 'loginLink' || anchor.getAttribute("id") == 'registerLink') continue;
		   
			//if (anchor.getAttribute("href") == 'http://tv.arsenal.com' || anchor.getAttribute("href") == 'http://tv.arsenal.com/'){ 
			if (anchor.getAttribute("href").toLowerCase().indexOf('http://tv.arsenal.com') > -1 || anchor.getAttribute("href").toLowerCase().indexOf('http://usatv.arsenal.com') > -1){
		   		anchor.setAttribute('onclick', "return popup('arsenaltv', '"+anchor.getAttribute("href")+"', 990, 691);");
		   		//IE 6 requires this.
		   		anchor.parentNode.innerHTML = anchor.parentNode.innerHTML
		    }
		    else if (anchor.getAttribute("href").toLowerCase().indexOf('http://www.arsenal.com/webforms') > -1) { 
		   		anchor.setAttribute('onclick', "return popup('webforms','"+anchor.getAttribute("href")+"', 800, 455);");
		   		//IE 6 requires this.
		   		anchor.parentNode.innerHTML = anchor.parentNode.innerHTML
		    }
		    else if (anchor.getAttribute("href").toLowerCase().indexOf('http://www.arsenal.com/christmasgiftguide') > -1) {
		   		anchor.setAttribute('onclick', "return popup('christmasgiftguide','"+anchor.getAttribute("href")+"', 760, 600);");
		   		//IE 6 requires this.
		   		anchor.parentNode.innerHTML = anchor.parentNode.innerHTML
		    }
		    else if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external"){
		     anchor.target = "_blank";
		   }//end if else
		 }//end for  
	}//end function

	window.onload =  externalLinks;