/* This file is called by a <script> element in the <head> of every page on the site.  It is for any JavaScript that can be re-used on multiple pages and would be nice to keep handy. */

/* xxxxxxxxxxxxxxxxxxxxxxx Open a link in a new window xxxxxxxxxxxxxxxxxxxxxx */

/* This function can be called in the "onclick" event handler of a link to cause the link to open in a new window as such:
onclick="newwin(this); return false;"
This is used in place of the "target" attribute, which is deprecated in HTML.
Feel free to edit or replace this script with something more robust or useful. */

function newwin(srclink) {
	var alpha = window.open(srclink.getAttribute('href'), 'bravo');
	alpha.focus();
	return alpha;
};

/* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx */

/* This function adds the newwin() function above to the onclick event of any anchor classed as "document" (e.g. PDF links) or "external" (e.g. any link off of oaug.org). */

function addOnClick() {
	var anchors, i;
	anchors = document.getElementsByTagName('a');
	for(i=0; i<anchors.length; i++) {
		if(/external/.test(anchors[i].className) || /document/.test(anchors[i].className)) {
			anchors[i].onclick = function() {newwin(this); return false;};
			//anchors[i].onkeypress = function() {newwin(this); return false;};
		};
	};
};

/* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx */

/* This calls the addOnClick() function above when the document loads.  The "if" statement is just a check to see if the browser correctly implements the DOM. */

if(document.getElementById && document.createTextNode) {
	window.onload=addOnClick;
};