function doPopUps() {

if (!document.getElementsByTagName) return false;
var links = document.getElementsByTagName("a");
for (var i=0; i < links.length; i++) {
if (links[i].className && links[i].className.match("popUp")) {
links[i].setAttribute("title", "This link will open in a new window");
}
// attributes if single page only, e.g. end session - named 'popUp1'
if (links[i].className && (' ' + links[i].className + ' ').indexOf(' popUp1 ') != -1) {
links[i].onclick = function() {
window.open(this.href,'PopUp1','menubar=yes,resizable=yes,status=yes,width=480,height=320');
return false;
}
} 
// attributes for multiple page Help popup - named 'PopUpHelp'
else if (links[i].className && (' ' + links[i].className + ' ').indexOf(' popUpHelp ') != -1) {
links[i].onclick = function() {
window.open(this.href,'PopUpHelp','toolbar=yes,menubar=yes,resizable=yes,status=yes,scrollbars=yes,width=518,height=480');
return false;
}
} 
// attributes for any other multiple page popup- named 'PopUpMulti'
else if (links[i].className && (' ' + links[i].className + ' ').indexOf(' popUpMulti ') != -1) {
links[i].onclick = function() {
	window.open(this.href,'PopUpMulti','toolbar=yes,menubar=yes,resizable=yes,status=yes,scrollbars=yes,width=500,height=480');
return false;
}
}

}
}

window.onload = doPopUps;

/* add Array.push if needed (for IE5.x) */
if (Array.prototype.push == null) {
	Array.prototype.push = function(item) {
		this[this.length] = item; return this.length;
	}
}

/* Add Event function taken from http://www.dustindiaz.com/rock-solid-addevent/ */

function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

/*	EventCache Version 1.0
	Copyright 2005 Mark Wubben

	Provides a way for automagically removing events from nodes and thus preventing memory leakage.
	See <http://novemberborn.net/javascript/event-cache> for more information.
	
	This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/
	
var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();

/* doTheLinks manages all links in document with specific class names */

function doTheLinks() {
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (var i=0; i < links.length; i++) {
		if (links[i].className && links[i].className.match("popUp")) {
			hideSpan = document.createElement('span');
			hideSpan.className = 'hiddenText';
			hideText = document.createTextNode(' - this link will open in a new window. PolicyFile will remain open in the original window.');
			hideSpan.appendChild(hideText);
			links[i].setAttribute("title", "This link will open in a new window. PolicyFile will remain open in the original window.");
			links[i].appendChild(hideSpan);
		}
		if (links[i].className && links[i].className.match("externalLink")) {
			hideSpan = document.createElement('span');
			hideSpan.className = 'hiddenText';
			hideText = document.createTextNode(' - link to external site');
			hideSpan.appendChild(hideText);
			links[i].setAttribute("title", "Link to external site");
			links[i].appendChild(hideSpan);
		}
		// attributes if single page only e.g. end session - named 'popUpSmall'
		// change PRODUCT for your product name and add attributes as required
		if (links[i].className && (' ' + links[i].className + ' ').indexOf(' popUpSingle ') != -1) {
			links[i].onclick = function() {
window.open(this.href,'POLICYFILEPopUpSingle','width=525,height=350,resizable=1,toolbar=1,location=0,directories=0,addressbar=1,scrollbars=1,status=0,menubar=1');
				return false;
			}
		} 
		// attributes if medium popup - named 'popUpHelp'
// change PRODUCT for your product name and add attributes as required
		else if (links[i].className && (' ' + links[i].className + ' ').indexOf(' popUpHelp ') != -1) {
			links[i].onclick = function() {
window.open(this.href,'POLICYFILEPopUpHelp','width=550,height=480,resizable=1,toolbar=1,location=0,directories=0,addressbar=1,scrollbars=1,status=0,menubar=0');
				return false;
			}
		} 
		// attributes if medium popup - named 'popUpHelpImg'
// change PRODUCT for your product name and add attributes as required
		else if (links[i].className && (' ' + links[i].className + ' ').indexOf(' popUpHelpImg ') != -1) {
			links[i].onclick = function() {
window.open(this.href,'POLICYFILEPopUpHelpImg','width=550,height=480,resizable=1,toolbar=1,location=0,directories=0,addressbar=1,scrollbars=1,status=0,menubar=0');
				return false;
			}
		} 
		// attributes if large popup - named 'popUpMulti'
		// change PRODUCT for your product name and add attributes as required
		else if (links[i].className && (' ' + links[i].className + ' ').indexOf(' popUpMulti ') != -1) {
			links[i].onclick = function() {
window.open(this.href,'POLICYFILEPopUpMulti','width=500,height=480,resizable=1,toolbar=1,location=0,directories=0,addressbar=1,scrollbars=1,status=0,menubar=0');
				return false;
			}
		}
	}
}

/* Focus any window as it loads */

function doFocus() {
	window.focus();
}

/* Calls for above functions */

addEvent(window,'load',doFocus);
addEvent(window,'load',doTheLinks);
addEvent(window,'unload',EventCache.flush);

