var _debugEventsManager=false;

function addEvent(target,type,handler,bubbles) 
{
	try
	{
		if (document.addEventListener) target.addEventListener(type,handler,bubbles);
		else if (document.attachEvent) target.attachEvent("on"+type,handler,bubbles);
		else target["on"+type] = handler;
	}
	catch(e){if (_debugEventsManager) alert("Message:"+(e?e.message:"<null>")+"\ntarget="+target+"\ntype="+type+"\nhandler="+handler+"\nbubbles="+bubbles);}
}
function removeEvent(target,type,handler,bubbles) 
{
	try
	{
		if (document.removeEventListener) target.removeEventListener(type,handler,bubbles);
		else if (document.detachEvent) target.detachEvent("on"+type,handler,bubbles);
		else target["on"+type] = null;
	}
	catch(e){if (_debugEventsManager) alert("Message:"+(e?e.message:"<null>")+"\ntarget="+target+"\ntype="+type+"\nhandler="+handler+"\nbubbles="+bubbles);}
}

function Evt(evt) 
{
	this.evt=evt?evt:window.event;
	this.type=this.evt.type;
	this.keyCode=this.evt.which?this.evt.which:this.evt.keyCode;
	this.source=this.evt.target?this.evt.target:this.evt.srcElement;
	if (!this.source) this.source=document;
	this.clientX=this.evt.clientX;
	this.clientY=this.evt.clientY;
	this.pageX=this.evt.pageX?this.evt.pageX:this.clientX+(document.documentElement.scrollLeft>document.body.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft);
	this.pageY=this.evt.pageY?this.evt.pageY:this.clientY+(document.documentElement.scrollTop>document.body.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);
	this.x=this.pageX;
	this.y=this.pageY;
	this.button=this.evt.button;
	if (this.button && window.event)
	{
		if (this.button==1) this.button=0;
		else if (this.button==4) this.button=1;
	}
	if (this.evt.offsetX)
	{
		this.offsetX=this.evt.offsetX;
		this.offsetY=this.evt.offsetY;
	}
	else
	{
		this.offsetX=this.x-getRealLeft(this.source);
		this.offsetY=this.y-getRealTop(this.source);
	}
	this.toString=Evt_ToString;
	this.consume=Evt_Consume;
}
function Evt_ToString(){ return "Source: "+this.source+", type: "+this.type+" {x: "+this.x+"; y: "+this.y+"}"; }
function Evt_Consume()
{
	if (this.evt.stopPropagation) 
	{
		this.evt.stopPropagation();
		this.evt.preventDefault();
	} 
	else if (this.evt.cancelBubble) 
	{
		this.evt.cancelBubble = true;
		this.evt.returnValue  = false;
	}
}