// JavaScript Document

// Script to create target="_blank" tags for external links
// For this to work add the attribute rel="external" to all links that should open in a new window

// Script based on artical by Kevin Yank at http://www.sitepoint.com/article/standards-compliant-world

// check to make sure that we can get elements by tag name. If not then return without doing anything
// This script will only work in standards complient browsers (of course with JS on)

function ExternalLinks() {
	//alert('here');
	if (!document.getElementsByTagName) return;

	// get a list of all the anchors in the page
	var anchors = document.getElementsByTagName("a");
	//alert(anchors);
	// loop through anchors array to find links with out rel="external" attibute
	for (var i=0; i < anchors.length; i++) {
		var anchor = anchors[i];
		//alert(anchor.getAttribute("rel"));
		// find only a tags with both an href and out rel="external" attributes
		if (anchor.getAttribute("href") &&
			(anchor.getAttribute("rel") == "external" || anchor.getAttribute("rel") == "document")) {
			
			// set the anchors target attribute
			anchor.target = "_blank";
		}
	}
}

// add event listener to install ga on body load
if (window.addEventListener) {
	window.addEventListener('load', ExternalLinks, false);
} else if (window.attachEvent) {
	window.attachEvent('onload', ExternalLinks);
}
// end add event listener

