/*============================================================================================
 Fichier Javascript
 Fichier permettant de gerer l'evenementiel du document.
 Attention en cours de développement

 AUTEUR:					Cedric POUYEZ
 CREATION:					08/04/2009
 VARIABLE GLOBALES:			
 MODIFICATIONS:				Alban BALLIEUX - 27/04/2009 - Suppression des méthodes inutilisées et ajout des gestions d'erreurs dans les evenements
===============================================================================================
	copyright 2009 Alban BALLIEUX - ballieuxa@laon.noirot
	http://www.phpmyportal.info

	This file is part of phpMyPortal.

    phpMyPortal is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation; either version 2.1 of the License, or
    any later version.

    phpMyPortal is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with phpMyPortal; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===============================================================================================*/
/**
 * Mets dans la variable global window la position de la souris
 * 
 * @param {Object} e		evenement de la souris
 */
function Sav_Mouse_Pos(e){
	if (!isset(e))e=event;
	window['GPOSX']=e.clientX;
	window['GPOSY']=e.clientY;
}

/**
 * Retour si le bouton gauche est enfoncé
 * 
 * @param {Object} e		evenement d'un clic souris
 */
function Btn_Gauche_Mouse(e){
	if(isset(e.target)){
		//Mozilla et compagnie
		return (e.button == 0);
	}else{
		//IE ...
		return (e.button == 1);
	}
}

/**
 * Permet d'ajouter un evenement sur une page
 * AjouteEvent('onmousedown',DebutDrag)
 * 
 * @param {Object} evenement		Evenement avec on devant
 * @param {Object} action			Function appellé lorsque l'evenement ce produit sans les ''
 * @param {Object} pere				(optionnel - defaut:document.documentElement)Objet sur lequel ajouter l'evenement
 */
function AjouteEvent(evenement,action,pere){
// Initialisation du père
	if(!isset(pere)){
		pere = document.documentElement;
	}
	
// Géstion des erreurs
	try
	{
	// Compatibilité avec IE/W3C ...
		if (isFunction(document.documentElement.addEventListener)) {
			even 	= evenement.substr(2) ;
			pere.addEventListener(even, action ,false);
		}else {
			pere.attachEvent(evenement,action);
		}
		return true;	
	}
	catch(err)
	{	
		return false;
	}
}

/**
 * Permet de retirer un evenement sur une page
 * Exemple d'utilisation
 * RetireEvent('onmousedown',DebutDrag)
 *
 * @param {Object} evenement		evenement avec on devant
 * @param {Object} action			Function appellé lorsque l'evenement ce produit
 * @param {Object} pere				(optionnel - defaut:document.documentElement)Objet sur lequel ajouter l'evenement
 */
function RetireEvent(evenement,action,pere){
// Initialisation du père
	if(!isset(pere)){
		pere = document.documentElement;
	}
// Géstion des erreurs
	try
	{
	// Compatibilité avec IE/W3C ...
		if (isFunction(document.documentElement.removeEventListener)) {
			even 	= evenement.substr(2) ;
			pere.documentElement.removeEventListener(even, action ,false);
		}else {
			pere.documentElement.detachEvent(evenement,action);
		}
	}
	catch(err)
	{	
		return false;
	}
}

