/*******************************************************************************************
 * windowOpener
 * Goes through the page and puts 'target="_blank"' or JS onclick on all elements class "external" or "popupLink"
 *******************************************************************************************/

addLoadEvent (function() {
	if (document.getElementsByTagName) {
		// return a reference to all links on the page
		var anchors = document.getElementsByTagName('a');
		// loop through all links, and search for any which any which have the the relevant class attributes
		for (var i=0; i<anchors.length; i++) {
			if (cssjs('check', anchors[i], 'external')) {
				anchors[i].target = "_blank";
			} else if (cssjs('check', anchors[i], 'popupLink')) {
				anchors[i].onclick = function () {
					// try to open the window
					oWin = window.open(this.href);
					// create a reference for the popup to access the opener window
					oWin.opener = self;
					// if the popup was sucessfully created, then return false (dont use normal href link), otherwise return true (so the browser links as normal)
					if ((oWin == null) || (typeof(oWin) == 'undefined')) {
						return(true);
					} else {
						oWin.focus();
						return(false);
					}
				}
			}
		}
	}
});

