// Get HttpObject
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;
}

// Add Load Event
function addLoadEvent(func) {
    //alert("addLoadEvent called");
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

// Open links in a  new window
function popupLinks() {
	//alert("popupLinks called");
	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("rel") == "popup") ) {
			anchor.target = "_blank";
		}
	}
}

// Old vertical menu helper function
function startList() {
	//alert("startList called");
	if (document.all && document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i< navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI" || node.nodeName == "li") {
				node.onmouseover=function() {
					this.className+=" over";
  				}
  				node.onmouseout=function() {
  					this.className=this.className.replace(" over", "");
   				}
  		 	}
		}
 	}
}

// Suckerfish function for ie6
function sfHover() {
	if(document.all) {
	    //alert("sfHover called");
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+="sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp("sfhover\\b"), "");
			}
		}
	}
}

// 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";
		}
	}
}


addLoadEvent(popupLinks);
addLoadEvent(startList);
addLoadEvent(sfHover);
addLoadEvent(externalLinks);
