/*
Programmer: Darryl Ballard
Date created: 2007-10-08
Last updated: 2007-10-09
Version: 1.0

Requires:
	addLoadEvent()
*/

function replaceExternalLinks()
{
	var k;
	var links = document.getElementsByTagName('a');
	var urlBeginning;
	
	if( location.protocol == "http:" )
	{
		//alert(location.protocol + "//" + location.host);
		urlBeginning = location.protocol + "//" + location.host;
	}
	
	for(k = 0; k < links.length; k++)
	{
		//alert("getAtt('href') = " + links[k].getAttribute('href') + "\n"
		//+ "href = " + links[k].href);
		
		// Does this link have an href attribute
		if( links[k].href )
		{
			// Is this an external link
			// (The href property returns the full address, whether relative or absolute,
			// and any links not starting with this page's domain are external)
			if( links[k].href.indexOf(urlBeginning) != 0 )
			{
				// Set the external class
				if( links[k].className )
				{
					links[k].className += " external";
				}
				else
				{
					links[k].className = "external";
				}
				
				links[k].onclick = function() {
					window.open(this.href, "externalWindow");
					return false;
				}
			}
		}
	}
}

addLoadEvent(replaceExternalLinks);
