﻿//
//
//
var pro_event = {};


//
//
//
pro_event.addListener = function(element, name, observer, useCapture)
{
  useCapture = useCapture || false;

	if (element.addEventListener)
	{
		element.addEventListener(name, observer, useCapture);
	}
	else if (element.attachEvent)
	{
		element.attachEvent('on' + name, observer);
	}
}


//
//
//
pro_event.removeListener = function(element, name, observer, useCapture)
{
	useCapture = useCapture || false;
	
	if (element.removeEventListener)
	{
		element.removeEventListener(name, observer, useCapture);
	}
	else if (element.detachEvent)
	{
		element.detachEvent('on' + name, observer);
	}
}


//
//
//
pro_event.getTarget = function(e)
{
	if (e == null)
	  return null;
	
	if (e.target)
	  return e.target;
	else if (e.srcElement)
	  return e.srcElement;

	return null;
}


//
//
//
pro_event.isLeftButton = function(e)
{
	return (e.which) ? 
	       e.which == 1 && e.button == 0 :
	       (e.type == 'click') ? e.button == 0 : e.button == 1;
}


//
//
//
pro_event.isRightButton = function(e)
{
	return e.button == 2;
}


//
//
//
pro_event.stopPropagation = function(e)
{
	if (e.stopPropagation)
	{
	    e.stopPropagation();
	}
	else
	{
	  e.cancelBubble = true;
	}
}


//
//
//
pro_event.preventDefault = function(e)
{
	if (e.preventDefault)
	{
	  e.preventDefault();
	}
	else
	{
	  e.returnValue = false;
	}
}


//
//
//
pro_event.stopEvent = function(e)
{
	pro_event.stopPropagation(e);
	pro_event.preventDefault(e);
}


//
//
//
pro_event.bindAsListener= function(func, obj)
{
	return function()	{
		return func.apply(obj, arguments);
	}
}

