extgraphic = 'graphics/external.png';

function tagExternalLinks(divid)
{
	var protocol = window.location.protocol;
	if (protocol.indexOf("http") == -1)
		return;			// do not handle non-web requests

	// Match domain name
	var domainRE = /^.*?(\.[^\.]*\.[^\.]*)$/i;

	// Host name of the server
	var thisHostName = window.location.host;

	// Domain name of the server
	var thisDomain;
	if ((thisDomain = domainRE.exec(thisHostName)) == null)
		thisDomain = "." + thisHostName;
	else
		thisDomain = thisDomain[1];

	var div = document.getElementById(divid);
	if (div != null)
	{ 
		var links = div.getElementsByTagName("a");

		// Traverse the links in the document and do stuff...
		for (var i = 0; i < links.length; i++) 
		{
			// skip named anchors
			if (links[i].href == null || links[i].href.length == 0)
				continue;

			// Skip non-HTTP links
			if (links[i].protocol.indexOf("http") == -1)
				continue;

			// Skip image links (image first in link text)
//			if (links[i].hasChildNodes() && links[i].firstChild.nodeType == 1)
			if (links[i].childNodes.length == 1 && links[i].firstChild.nodeType == 1)
				continue;

			// This link is an external one (not even a sub-domain), and this
			// doesn't have some background defined already.
			var linkDomain = domainRE.exec(links[i].host);
			if (linkDomain == null)
				linkDomain = "." + links[i].hostname;
			else
				linkDomain = linkDomain[1];

//strip off port number if it's on the end
linkDomain = linkDomain.replace(/:\d+$/, "");

			if (linkDomain != thisDomain && links[i].style.background == "") 
			{
				links[i].style.background = "url(" + extgraphic + ") right top no-repeat";
				links[i].style.paddingRight = "13px";
			}
		}
	} 
}
