<!--
//--------------------------------------------------------------------------||
// FUNCTION:    Event													    ||
// TYPE:		constructor												    ||
// PARAMETERS:  evt		: objet évènement									||
// RETURNS:     null													    ||
// PURPOSE:     Gère les évènements multi-navigateur					    ||
// CALL:		var evt = new Event(event);									||
// VERSION:		v1.31														||
//--------------------------------------------------------------------------||
/*
Exemples :
-----------

-- REM -- appel de getEvent suivant les evenements
document.onmousedown = getEvent ;
document.onclick	 = getEvent ;
document.onkeypress	 = getEvent ;

-- REM -- appel d'une fonction créant la classe Event
document.onmousedown = setEvent ;
document.onclick	 = setEvent ;
document.onkeypress	 = setEvent ;
==> reconnait toutes les touches
==> reconnait les associations de touches (shift, ctrl, alt, altgr) avec les autres touches du clavier
==> ne déclenche pas d'évènement pour les touches spéciales (shift, ctrl, alt, altgr) + Impr.écran + Arrêt défil
==> réagit mais ne reconnait pas les evenement suivants :
	- touche F1 à F12
	- inser
	- suppr
	- début
	- fin
	- pgup
	- pgdown
	- touches directionnelles
	- touche windows
	- touche menu contextuel
	
document.onkeydown	 = setEvent ;
==> clavier normal : reconnait uniquement les lettres tapées mais en majuscules uniquement
==> réagit mais ne reconnait pas les evenement suivants : tout le reste du clavier
	sauf :
	- entrée
	- backspace
	
document.onkeyup	 = setEvent ;

function setEvent(evt, func)
{
	var evt = new Event(evt);
	if (evt.keyCode == 13) { func; }
	return false;
}

onKeyPress="setEvent(event, func)"
*/

function Event(e)
{
	//---- e gives access to the event in all browsers
	if (!e) var e = window.event ;
	
	//---- récupération des parametres de l'evenement
	this.target			= getEventTarget(e);
	this.targetTagName	= this.target ? this.target.tagName : null;
	this.keyCode		= getKeyCode(e);
	this.keyPress		= getKeyPress(this.keyCode);
	this.metaKey		= e.metaKey;
	this.mouseBtnPress	= e.button;
    if (document.all) 
    { 
        this.offsetX = e.offsetX;
        this.offsetY = e.offsetY;
    }
    else 
    { 
        this.offsetX = e.pageX - e.clientX;
        this.offsetY = e.pageY - e.clientY;    
    }
    this.clientX = e.clientX;
    this.clientY = e.clientY;
}


function getEventTarget(e)
{
	var targ ;	
	if (e.target) targ = e.target ;
	else if (e.srcElement) targ = e.srcElement ;
	if (targ)
	{
		if (targ.nodeType == 3) targ = targ.parentNode ; // defeat Safari bug	
	}
	return targ ;
}
function getKeyCode(e)
{	
	var code;
	if (e.keyCode) code = e.keyCode ;
	else if (e.which) code = e.which ;
	else if (e.charCode) code = e.charCode ;
	return code ;
}
function getKeyPress(charCode)
{	
	var key;
	if (charCode == 13) { key = 'enter'; }
	else if (charCode == 8) { key = 'backspace'; }
	else if (charCode == 32) { key = 'space'; }
	else if (charCode == 9) { key = 'tab'; }
	else if (charCode == 27) { key = 'escape'; }
	else if (charCode == 19) { key = 'pause'; }
	else { key = String.fromCharCode(charCode); }
	return key;
}
function detectSpecialKeys(e)
{
	var key;
	if (e.altKey) { key = 'alt'; }
	else if (e.ctrlKey) { key = 'ctrl'; }
	else if (e.shiftKey) { key = 'shift'; }	
	return key;
}
//-->
		