// @author Stafford

function initExternalLinks()
{
	var arrLinks = document.getElementsByTagName('a');
	var thisSiteURL = document.location.href.substring(0, document.location.href.indexOf('/' ,7));

	for (var i = arrLinks.length; i > 0; i--) // loop through the elements in reverse order for speed
	{
		var a = arrLinks[i - 1];
		var rel = a.getAttribute('rel');
		if (a.href && a.href.indexOf("http://") == 0 && !a.href.indexOf(thisSiteURL) == 0 && !(rel != null && rel.indexOf('internal') != -1) || (rel != null && rel.indexOf('external') != -1))
			a.target = '_blank';
	
		// these are the boolean statements:
		// a.href... check if the anchor has a link attribute, i.e. is a hyperlink
		// a.href.indexOf("http://") == 0... this is for the Safari (Mac) and Konqueror (Linux) browsers, which do not put a http:// in front of local links, and unless we perform this check the link will not contain the current domain and seem external
		// !a.href.indexOf(thisSiteURL) == 0... check if the URL of the link contains the domain name of the current site
		// !(a.rel && a.rel.indexOf('internal') != -1)... check if the link has a "rel" tag, and if it is "internal" the link should not open a window regardless of the target
		// (a.rel && a.rel.indexOf('external') != -1)... check if the link has a "rel" tag of "external", in which case we should make the link open a new window regardless of the target
	}

	var arrForms = document.getElementsByTagName('form');

	for (var i = arrForms.length; i > 0; i--) // loop through the elements in reverse order for speed
	{
		var f = arrForms[i - 1];
		var rel = f.getAttribute('rel');
		if (rel != null && rel.indexOf('external') != -1)
			f.target = '_blank';
	}
}
