
// Volunteer Centre Lowestoft Utility Functions

var W3CDOM	= (document.createElement && document.getElementsByTagName);
var CLASSID	= 'external';
var MESSAGE	= '[Opens in a new window]';
var WINID	= 'newWindow';
var WINOPTIONS	= 'height=600,width=800';

//////////////////////////////////

// GENERIC ONLOAD EVENT HANDLER
function addOnLoadEvent(pFunction) {
	var old_event = window.onload;
	window.onload = (typeof window.onload != 'function') ? pFunction : function () { old_event(); pFunction(); };
}

// RANGED RANDOM NUMBER GENERATOR
function randomInteger(pMin, pMax) {
	return Math.floor(Math.random() * (pMax - pMin + 1)) + pMin;
}

//////////////////////////////////

function popupWindow(pUrl, pName, pOptions) {
	window.open(pUrl, pName + randomInteger(1, 1000), pOptions);
	return false;
}

function addPopupLinks() {
	if (!W3CDOM) return false;
	var links = document.getElementsByTagName('A');
	for (var i = 0; i < links.length; i++) {
		if (links[i].className == CLASSID) {
			links[i].onclick = function () { return popupWindow(this.href, WINID, WINOPTIONS); };
			var title = links[i].title;
			links[i].title = ((title.length > 0) ? title + ' ' : '') + MESSAGE;
		}
	}
}

//////////////////////////////////

addOnLoadEvent(addPopupLinks);

// end of file