var BodyEvent = new TBodyEvent();

function TBodyEvent () {
//Attributs:	
	this.Events = new Array;
//Methodes:
	this.AddEvent = TAddEvent;
	this.SupEvent = TSupEvent;
	this.FindEvent = TFindEvent;
	this.FindMethode = TFindMethode;
	this.Active = TActiveBody;
	this.Desactive = TDesactiveBody;	
	this.ActiveAll = TActiveAllBody;
	this.DesactiveAll = TDesactiveAllBody;	
	this.GetListeEvent = TGetListeEvent;
	this.Inibe = TInibBodyEvent;
}

function TEvents (type) {
//Attributs:
	this.AType = type;
	this.AEvents = new Array;	
}

function TInibBodyEvent(type) {
	add_event("tagname","body",0,type,"function () {return false;}");
}

function TGetListeEvent() {
	var rep = "";
	var i = 0,j = 0;
	while (this.Events[i]) {
		j = 0;
		rep += "Event : " + this.Events[i].AType + "\n";
		while (this.Events[i].AEvents[j]) 
			rep += "> Fct : " + this.Events[i].AEvents[j++] + "\n";
		i++;
	}
	return rep;
}

function TAddEvent(type,methode) {
	var j = this.FindMethode(type,methode); 
	if (j == -1) this.Events[this.FindEvent(type)].AEvents.push(methode);
}

function TSupEvent(type,methode) {
	var j = this.FindMethode(type,methode);
	if (j != -1) this.Events[this.FindEvent(type)].AEvents.splice(j,1);
}

function TFindEvent(type) {
	var i = 0,rep = -1;
	while (rep == -1 && this.Events[i]) {
		if (this.Events[i].AType == type) rep = i;
		i ++; 
	}	
	if (rep == -1) {
		this.Events[i] = new TEvents(type);
		rep = i;
	}	
	return rep;
}

function TFindMethode(type,methode) {
	var i = this.FindEvent(type),j = 0,rep = -1;
	while (rep == -1 && this.Events[i].AEvents[j]) {
		if (this.Events[i].AEvents[j] == methode) rep = j;
		j++;
	}	
	return rep;
}

function TActiveBody(type) {
	if (type == "mousemove" || 
			type == "click" || 
			type == "contextmenu" || 
			type == "mousedown" || 
			type == "mouseup" ||
			type == "mousedown" ||
			type == "dblclick" ||
			type == "load" ||
			type == "unload" ||
			type == "keydown" ||
			type == "keypress" ||
			type == "keyup") 
		add_event("tagname","body",0,type,"function (e) {AppliqueEvent(BodyEvent.FindEvent(\"" + type + "\"),e);return false;}");
} 

function TDesactiveBody(type) {
	if (type == "mousemove" || 
			type == "click" || 
			type == "contextmenu" || 
			type == "mousedown" || 
			type == "mouseup" ||
			type == "mousedown" ||
			type == "dblclick" ||
			type == "keydown" ||
			type == "keypress" ||
			type == "load" ||
			type == "unload" ||
			type == "keyup")
		remove_event("tagname","body",0,type,"function (e) {AppliqueEvent(BodyEvent.FindEvent(\"" + type + "\"),e);return false;}");
} 

function TActiveAllBody() {
	var i = 0;
	while (this.Events[i]) 
		this.Active(this.Events[i++].AType);
} 

function TDesactiveAllBody() {
	var i = 0;
	while (this.Events[i]) 
		this.Desactive(this.Events[i++].AType);
} 

function AppliqueEvent(i,e) {
	var j = 0;
	while (BodyEvent.Events[i].AEvents[j])
		eval(BodyEvent.Events[i].AEvents[j++]);
}
