/**
 * Library of event based functions.
 * 
 * DEPRECATED: Use Prototype Event object instead
 */

/**
 * Attach an event listener to an HTML element
 *
 * @author D.Spurr
 * @version 1.0 06-01-05
 * @static
 * @access public
 * @param object HTML element
 * @param string Event type to attach (e.g. 'click')
 * @param function Function to run when event fires
 * @param boolean Stop event bubbling (usually false should be used)
 * @return boolean Success of attaching the listener
 */
function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener) {
    obj.addEventListener(evType, fn, useCapture);
	return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn); 
    return r;
  } else return false;
}

/**
 * Removes an event listener to an HTML element
 *
 * @author D.Spurr
 * @version 1.0 06-01-05
 * @static
 * @access public
 * @param object HTML element
 * @param string Event type to detach (e.g. 'click')
 * @param function Function to remove
 * @param boolean Is using capture
 * @return boolean Success of attaching the listener
 */
function removeEvent(obj, evType, fn, isCapture) {
	if (obj.removeEventListener) {
		obj.removeEventListener(evType, fn, isCapture);
		return true;
	}	else if (obj.detachEvent) {
		return obj.detachEvent("on"+evType, fn);
	}	else return false;
}

/**
 * Add a function to the onload event, or the custom _onDOMLoad event
 *
 * @author D.Spurr
 * @version 1.0 31-05-05
 * @static
 * @access public
 * @param function Function to run when event fires
 * @param boolean Whether to use the onDOMLoad (1) event or onLoad event (0) default 0
 * @return void
 */
function addLoadEvent(fn,useDOM) {
	if(useDOM) var old = window._onDOMLoad;
	else var old = window.onload;
	
	if(typeof old != 'function') {
		if(useDOM) window._onDOMLoad = fn;
		else window.onload = fn;
	} else {
		var thisFn = function() {
			old();
			fn();
		};
		if(useDOM) window._onDOMLoad = thisFn;
		else window.onload = thisFn;
	}
}

/**
 * Gets the target element from the event
 *
 * @author D.Spurr
 * @version 1.0 01-06-05
 * @static
 * @access public
 * @param event
 * @return element
 */
function getTarg(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) targ = targ.parentNode; // defeat Safari bug
	return targ;
}


