/*
EJR - 11/13/2006
general dhtml functions.

*/
function supportsDHTML() {
	return document.getElementById && (window.attachEvent || window.addEventListener);
}

function getEventSrc(e) {
	// get a reference to the IE/windows event object
	if (!e) e = window.event;
	
	// DOM-compliant name of event source property
	if (e.target)
	return e. target;
	// IE/windows name of event source property
	else if (e.srcElement)
	return e.srcElement;
}

function ShowNodeInfo(inNode){
	var nodeVals = "Name: " + inNode.nodeName;
	nodeVals += "\nValue: " + inNode.nodeValue;
	nodeVals += "\nId: " + inNode.id;
	nodeVals += "\nClass: " + inNode.className;
	nodeVals += "\nType: " + inNode.nodeType;
	nodeVals += "\n (1=Element, 3=Text, 8=Comment, 9=Document)"
	nodeVals += "\nHas Children?: " + inNode.hasChildNodes();
	alert(nodeVals);
}


/*
NOTE: The this keyword does not work properly in Microsoft's attachEvent. Instead of referring to the element the event handler is defined on, as it does in the W3C model, it refers to the window object
*/

function addEvent( obj, type, fn ) {
	if (obj.addEventListener) { //W3C
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) { //MSIE
		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];
	}
}

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;
			};
		}
	};
}();
addEvent(window,'unload',EventCache.flush);