function linkEnhance()
{
	// get base domain
	var protocol = window.location.protocol;
	var domain = window.location.host;
	
	var domainRegex = new RegExp( "^" + protocol + "//" + domain );
	
	// get all the link
	var links = document.getElementsByTagName( "a" );
	
	for ( var i = 0; i < links.length; i++ )
	{
		// now process the link
		var href = links[i].getAttribute( "href" );
		if ( href )
		{
			href = href.replace( domainRegex, "" );
			if ( href.match( /^http\:\/\// ) )
			{
				// this is an external link
				// so change the target to be same window
				links[i].setAttribute( "target", "_self" );
				// and disable any open in new window code
				if ( links[i].getAttribute( "onclick" ) )
				{
					var onclick = links[i].getAttribute( "onclick" );
					if ( onclick.match( /.*window\.open.*/i ) )
					{
						links[i].setAttribute( "onclick", "return true;" );
					}
				}
			}
			else
			{
				var documentList = new Array( "doc", "pdf", "xls", "ppt", "zip" );
				for ( var j = 0; j < documentList.length; j++ )
				{
					var docRegEx = new RegExp( ".*\." + documentList[j] + "$", "i" );
					if ( href.match( docRegEx ) )
					{
						// this is a doc so change the target to a new window
						links[i].setAttribute( "target", "_blank" );
						// size the new window
						links[i].setAttribute( "onclick",function() { window.open( this.href, '_blank', 'width=800,height=600,top=50,left=50,screenX=50,screenY=50,menubar=yes,resizable=yes' ); return false; } );
						// warn the customers this will open in a new window
						var newAlt = "This link will open in a new window";
						if ( links[i].getAttribute( "title" ) && links[i].getAttribute( "title" ) != "" )
						{
							newAlt += ": " + links[i].getAttribute( "title" );
						}
						links[i].setAttribute( "title", newAlt );
						// end the loop
						j = documentList.length;
					}
				}
			}
		}
	}
}

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if ( typeof window.onload != 'function' )
	{
		window.onload = func;
	}
	else
	{
		window.onload = function () {
			if (oldonload)
			{
				oldonload();
			}
			func();
		}
	}
}

addLoadEvent( linkEnhance );
