// Utility function
// Returns a list of child nodes with supplied class name
function getElementsByClassName(classname, node)  {
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

// Popup Window
// multiple links with class = popup
function doPopups() {
	var popups = getElementsByClassName("popup");
	if(popups) {
		for ( var i=0;i<popups.length;i++ ) {			
			popups[i].onclick = function() {
				window.open(this.getAttribute('href'),"blank","toolbar=no,scrollbars=yes,width=750,height=700");
		        return false;
		    }	
		}
	}
}

// Standards compliant target=_blank
function externalLinks() {
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if ( anchor.getAttribute("href") && anchor.getAttribute("rel") == "external" )
			anchor.target = "_blank";
	}
} 

// init - put things to run in here
function init() {
	// check that browser supports DOM1
	if (!document.getElementsByTagName) return false;
	
	doPopups();
	externalLinks();
}

window.onload = init;