/**
 *	Attache une fonction à un évenement d'un objet du DOM
 *	@param oElt object : objet du DOM
 *	@param sEvt string : évènement
 *	@param fFct reference : fonction à associer
 *
 */
function globalAttachEvent(oElt, sEvt, fFct) {
	if ( typeof(oElt)=='object' && sEvt.length ) {
		if (document.all) {
			oElt.attachEvent(sEvt, fFct);
		} else {
			sEvt = sEvt.replace(/^on/, '') ;
			oElt.addEventListener(sEvt, fFct, false);
		}
	}
}

/**
 *	Remplace les virgules par des points
 *	@param oInput object : objet input du DOM
 */
comma2dot = function(oInput) {
	oInput.value = oInput.value.replace(/\,/g, '.') ;
}

/**
 *	Ajoute des anti-slash dans une chaîne
 *	@param str string : chaîne de caractères
 */
addslashes = function(str) {
	str = str?str:'' ;
	str = str.replace(/\\/g, '\\\\') ;
	str = str.replace(/\'/g, '\\\'') ;
	str = str.replace(/\"/g, '\\"') ;
	str = str.replace(/\0/g, '\\0') ;
	return str ;
}

/**
 *	Supprime les anti-slash d'une chaîne
 *	@param str string : chaîne de caractères
 */
stripslashes = function(str) {
	str = str?str:'' ;
	str = str.replace(/\\\\/g, '\\') ;
	str = str.replace(/\\'/g, '\'') ;
	str = str.replace(/\\"/g, '"') ;
	str = str.replace(/\\0/g, '\0') ;
	return str ;
}


/**
 *	Affiche un bloc HTML au centre de l'écran
 *
 */
function displayOnScreenCenter(id, iWidth, iHeight) {
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number') {windowHeight=window.innerHeight;}
	else {
		if (document.documentElement&&document.documentElement.clientHeight) {windowHeight = document.documentElement.clientHeight;}
		else {if (document.body&&document.body.clientHeight) {windowHeight=document.body.clientHeight;}}
	}
	var windowWidth=0;
	if (typeof(window.innerWidth)=='number') {
		windowWidth=window.innerWidth;
	}else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth=document.documentElement.clientWidth;
		}else{
			if(document.body&&document.body.clientWidth) {windowWidth=document.body.clientWidth;}
		}
	}
	popup = document.getElementById(id);
	if (popup) {
		popup.style.display='block';
		iWidth = typeof(iWidth)=='undefined' ? popup.offsetWidth : iWidth ;
		iHeight = typeof(iHeight)=='undefined' ? popup.offsetHeight : iHeight ;

		popup.style.left = ((windowWidth/2)-(iWidth/2))+'px' ;
		popup.style.top = ((windowHeight/2)-(iHeight/2))+'px' ;
	}
	return popup ;
}



/**
*	fonction de comparaison des mots de passe
*	@param: inputName1 inputName2
*	@return boolean : true si les mots de passes sont définis et qu'ils sont identiques, false sinon.
*/
function validePass( name1, name2, errorMsg ){
	pass1 = document.getElementById(name1) ;
	if(!pass1){return true;}
	pass2 = document.getElementById(name2) ;
	if(pass1.value.length>0){
		if (pass1.value!=pass2.value) {
			if (errorMsg.length>0)
				alert(errorMsg);
			pass1.value='';
			pass2.value='';
			pass1.focus();
			return false;
		}
	}
	return true;
}


function fermePopup(id){
	document.getElementById(id).style.display='none';
	return false;
}


function generatePassword( idPop, passLength ) {
	var input = document.getElementById(idPop);
	if(!input) return false ;
	input.style.color = 'red';
	var password = '';
	var chars = new Array(	'1','2','3','4','5','6','7','8','9',
											'a','b','c','d','e','f','g','h','j','k',
											'm','n','p','q','r','s','t','u','v','w',
											'x','y','z');
	for(var i=0; i<passLength; i++) password += chars[Math.floor(Math.random()*chars.length)];
	input.value = password;
	return false ;
}
