/* imports nécessaires
	<script language="JavaScript" src="../_scripts/util/bDetect.js"></script>
*/

var BROWSER_FAMILY_IE = 'ie4';
var BROWSER_FAMILY_MOZ = 'gecko';
var BROWSER_FAMILY_NETSCAPE = 'nn';

function isIEType() {
	return navigator.family.indexOf(BROWSER_FAMILY_IE) != -1; 
}
function isMozillaType() {
	return navigator.family.indexOf(BROWSER_FAMILY_MOZ) != -1; 
}
function isNetscapeType() {
	return navigator.family.indexOf(BROWSER_FAMILY_NETSCAPE).startsWith(BROWSER_FAMILY_NETSCAPE); 
}
function isMozillaCompatible() {
	return isMozillaType();
			
}

/**
  * Objet contenant toutes les informations sur l'événement survenu dans la page.
  */
function UIEvent(a_eventObject) {
	this.eventObject = a_eventObject;
	//alert("UIEvent : " + _eventObject);
}
// Initialisation de l'objet
UIEvent.prototype.init=function() {
}

UIEvent.prototype.type = function() {
	return this.eventObject.type;
}

UIEvent.prototype.key = function() {
	return null;
}

UIEvent.prototype.shiftKey = function() {
	return this.eventObject.shiftKey;
}


/**
 * Wrapper pour un événement IE 4
 * @param a_eventObject  (Event)  événement
 */
function UIEventIE(a_eventObject) {
	this.inheritFrom(a_eventObject);
}
UIEventIE.prototype = new UIEvent();
UIEventIE.prototype.inheritFrom = UIEvent;

UIEventIE.prototype.sourceElement = function() {
	return this.eventObject.srcElement;
}

UIEventIE.prototype.clientX = function() {
	return this.eventObject.clientX;
}

UIEventIE.prototype.clientY = function() {
	return this.eventObject.clientY;
}

UIEventIE.prototype.realClientX = function() {
	return this.eventObject.clientX + document.body.scrollLeft;
}

UIEventIE.prototype.realClientY = function() {
	return this.eventObject.clientY + document.body.scrollTop;
}

UIEventIE.prototype.cancelPropagation = function() {
	this.eventObject.cancelBubble = true;
	this.eventObject.returnValue = false;
}

UIEventIE.prototype.key = function() {
	return this.eventObject.keyCode;
}

/**
 * Wrapper pour un événement compatible Mozilla
 * @param a_eventObject  (objet)  événement
 */
function UIEventMoz(a_eventObject) {
	this.inheritFrom(a_eventObject);
}
UIEventMoz.prototype = new UIEvent();
UIEventMoz.prototype.inheritFrom = UIEvent;

UIEventMoz.prototype.sourceElement = function() {
	return this.eventObject.target;
}

UIEventMoz.prototype.clientX = function() {
	return this.eventObject.pageX;
}

UIEventMoz.prototype.clientY = function() {
	return this.eventObject.pageY;
}

UIEventMoz.prototype.realClientX = function() {
	return this.eventObject.pageX;	// tient déjà compte du scroll
}

UIEventMoz.prototype.realClientY = function() {
	return this.eventObject.pageY;	// tient déjà compte du scroll
}

UIEventMoz.prototype.cancelPropagation = function() {
	this.eventObject.stopPropagation();
	this.eventObject.preventDefault();
}

UIEventMoz.prototype.key = function() {
	if (this.eventObject) {
		return (this.eventObject.keyCode ||	this.eventObject.which);
	}
	return null;
}


/**
  * Retourne un nouvel objet UIEvent.
  *
  */
function xbGetUIEvent(a_event) {
	//alert("GetUIEvent");
	// Modèle IE
	if (isIEType()) {
		return new UIEventIE(window.event);
	}
	// Modèle DOM2
	else if (isMozillaType()) {
		return new UIEventMoz(a_event);
	}
	return UIEvent(null);
}
	