// Add a function to the window onload event so it's called when the page is fully loaded
function addLoadEvent(func) {
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') { 
		window.onload = func;
	} 
	else { 
		window.onload = function() {
			if (oldonload) {
				oldonload(); 
			} 
			func(); 
		} 
	} 
}

// Get an XMLHttpObject
function getHTTPObject() {
	var xhr = false;
	if(window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				xhr = false;
			}
		}
	}
	return xhr;
}

// Open external links in a new window
// Add class="external" to any link to launch new window
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("class") == "external") {
			anchor.target = "_blank";
		}
		// For IE
		else if(anchor.href && anchor.className) {
			anchor.target = "_blank";
		}
	}
}
