﻿/*
Description        Contains common event functions
Dependancies    Common.js, Browser.js
*/

function Event() {}

/*
Adds an event listener to an object
Params:elm	- The element to which events are being attached to
eventName	- The name of the event (without the on keyword)
eventHandler - The name of the function who is handling the event
useCapture	- Firefox specific
*/
Event.addEventListener=function(elm, eventName, eventHandler, useCapture) {
	if (Browser.isIE()) 
		elm.attachEvent('on' + eventName, eventHandler);
	else {
		if (Common.isUndefined(useCapture)) useCapture=false;
		elm.addEventListener(eventName, eventHandler, useCapture);
	}
}

/*
Returns the source of the event - that is the element which raised the event
Parameters    evt   - The event object
*/
Event.getEventSource=function(evt) {
    var e=null;
	if (Browser.isIE()) 
		e=evt.srcElement;
	else 
		e=evt.currentTarget;	
	return e;
}

/*
Cancels the event, it stops it from propogating further up the hierarchy
Parameters    evt   - The event object
*/
Event.cancelEvent=function(evt) {
	if (Browser.isIE()) 
		evt.returnValue=false;
	else 
        evt.preventDefault();
}
