// Name: Handle External Links
// Language: JavaScript
// Author: Travis Beckham | squidfingers.com
// Description: Opens a new window for external links.
// --------------------------------------------------


// ||||||||||||||||||||||||||||||||||||||||||||||||||
// onLoadListener

onLoadFuncs = new Array();
function addOnLoad(func){
	onLoadFuncs[onLoadFuncs.length] = func;
}
function runOnLoad(){
	for(i in onLoadFuncs){
		eval(onLoadFuncs[i]+"()");
	}
}
window.onload = runOnLoad;

// Example: addOnLoad("someFunction");

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// Open external links in a new window

function handleExternalLinks(){
	var anchors = document.getElementsByTagName("a");
	var i, href;
	for(i=0; i < anchors.length; i++){
		if(!anchors[i].href) continue;
		href = anchors[i].href;
		
		if(href.indexOf("formichaelburke.com") == -1){ // Href is not a file on my server
			if(href.indexOf("javascript:") == -1){ // Href is not a javascript call
				if(!anchors[i].onclick){ // Href does not have an onclick event
					if(href.indexOf("mailto:") == -1){ // Href is not a mailto:
						if(href.indexOf("http://") != -1){ // Href is not relative (for Safari)
							anchors[i].setAttribute("target","_blank");
						}
					}
				}
			}
		}

	}
}
if(document.getElementsByTagName){
	addOnLoad("handleExternalLinks");
}