function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

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("rel") == "external")) {
			anchor.onclick = function() {
				var popup = makePopup(this.href, 800, 600, 'both');
				return false;
			}
		}
		if ((anchor.getAttribute("href") && anchor.getAttribute("rel") == "popup")) {
			anchor.onclick = function() {
				var popup = makePopup(this.href, 276, 276, 'both');
				return false;
			}
		}
	}
} 

function makePopup(url, width, height, overflow) {
	if (width > 800) { 
		width = 800; 
	}
	if (height > 600) { 
		height = 600; 
	}
	if (overflow == '' || !/^(scroll|resize|both)$/.test(overflow)) {
		overflow = 'both';
	}
	
	var win = window.open(
		url, 
		'', 
		'width=' + width + 
		',height=' + height +
		',scrollbars=' + (/^(scroll|both)$/.test(overflow) ? 'yes' : 'no') + 
		',resizable=' + (/^(resize|both)$/.test(overflow) ? 'yes' : 'no') + 
		',status=yes,toolbar=yes,menubar=yes,location=yes'
	);
	
	return win;
}

addLoadEvent(externalLinks);
