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

function popUp(winURL) {
	window.open(winURL, "www.diopa.org - External Link");
}

function prepareLinks() {
	//if older browser without getElementsByTagName return false
	if (!document.getElementsByTagName) return false;
	//otherwise carry-on with launching new window with external link
	var links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
		if (links[i].getAttribute("class") == "external") {
			links[i].onclick = function() {
				popUp(this.getAttribute("href"));
				return false;
			}
		}
	}
}

/* Show/Hide via Scriptaculous */
function toggleVisible(element) {
    element = document.getElementById(element);
    if(element.style.display == "none") { 
        Effect.BlindDown(element, {duration: 0.2});
    } else { 
        Effect.BlindUp(element, {duration: 0.2});
    }
}

function toggleHighlight(element) {
/*	console.log(element);*/
/*	element = document.getElementById(element);
*/	Element.extend(element);
	if( element.hasClassName("highlight") ) {
		element.removeClassName("hightlight");
	} else {
		element.addClassName("hightlight");
	}
}

addLoadEvent(prepareLinks);

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

