/*
  © 2005 Thomson Legal & Regulatory Global AG.  All Rights Reserved
  Thomson Legal & Regulatory Global AG Proprietary and Confidential
*/

/****************************************************
* general.js - This should be imported into every  *
* page that uses the standard page wrapper.        *
* Should be used for setting up generic methods to *
* run at page load time.                           *
* Also sets up some reusable methods:              *
* - Cross browser event handling                   *
* - Event caching to solve IE memeory leaks        *
****************************************************/

// General function to be run at page load time
function initPage() {
	if (!document.getElementById || !document.getElementsByTagName) { return; }

	// Find all links in document with classname 'externalLink'
	// Add click event to open these in a new window
	var links = document.getElementsByTagName('a');
	for (var j=0; j < links.length; j++) {
		if (links[j].className.match('externalLink')) {
			addEvent(links[j], 'click', function(e) {
				var thislink;
				if (!e) { var e = window.event; }
				if (e.target) { thislink = e.target; }
				else if (e.srcElement) { thislink = e.srcElement; }
				// defeat Safari bug
				if (thislink.nodeType == 3) { thislink = thislink.parentNode; }
				window.open(thislink.href);

				// Cancel default return value of the link's href attribute
				if (e.returnValue) {
					window.event.returnValue = false;
				}
				if (e.preventDefault) {
					e.preventDefault();
				}
			}, false);
			// Safari hack - doesn't support preventDefault property of the DOM event
			links[j].onclick = function() { return false; };
		}
	}
}

/**************************************************
* MULTI-PURPOSE REUSABLE METHODS LIVE BELOW HERE *
**************************************************/


// Cross-browser event handling for IE5+, NS6+ and Mozilla/Gecko
// By Scott Andrew <http://www.scottandrew.com/weblog/articles/cbs-events>
function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		// Register this event with EventCache
		EventCache.add(elm, evType, fn);
		return r;
	} else { elm['on' + evType] = 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/>
*/

/*	Implement array.push for browsers which don't support it natively. */
if(Array.prototype.push == null){
	Array.prototype.push = function(){
		for(var i = 0; i < arguments.length; i++){
			this[this.length] = arguments[i];
		};
		return this.length;
	};
};

/*	Event Cache uses an anonymous function to create a hidden scope chain.
	This is to prevent scoping issues. */
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]);
				};

				/* From this point on we need the event names to be prefixed with 'on" */
				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;
			};
		}
	};
}();

function initBackLink()
{
	var objLink = document.getElementById("backJS");
	if(objLink)
	{
		objLink.className += "Display";
	}
}
function roll_over (ImageName) {

	// If the browser supports image swapping...
	if (document.images) {

		// ...show the mouse-over image
		document[ImageName].src = eval(ImageName + "ovr").src;
	}
}



/** Show normal image
* @param     Image Name
*/
function roll_out (ImageName) {

	// If the browser supports image swapping...
	if (document.images) {

		// ...show the mormal image
		document[ImageName].src = eval(ImageName + "nrm").src;
	}
}
/***************************************
* ADD ALL WINDOW EVENT LISTENERS HERE *
***************************************/

// Add load event listener to set up default page state
addEvent(window, 'load', initPage, false);

// Add unload event to flush events (required to avoid memory leaks in IE)
addEvent(window, 'unload', EventCache.flush, false);

