function getelem(sElem){
	return document.getElementById(sElem);
 }
 
function verifier_taille(oTxt,iZone){
	var oZone = getelem("txt_max_"+iZone);
	if(oTxt!=null){
		var iMax = oTxt.getAttribute("max");
		if(oTxt.value.length>iMax)
			oTxt.value = gauche(oTxt.value,iMax);
		if(oZone!=null)
			oZone.value = iMax-parseInt(oTxt.value.length);
	 }
 }

function nopx(sChaine){
	if(sChaine==null) sChaine = "";
	return parseInt(remplacer(sChaine.toString(),"px",""));
 }
 
function position_reelle(obj){
	var result_X = 0;
	var result_Y = 0;
	var oldLeft = -1;
	var oldTop = -1;
	var old = obj.id;
	obj = obj.parentNode;
	while(obj!=null){
		if(typeof(obj.style)!="undefined"){
			if(obj.style.position!="absolute" && obj.style.position!="relative"){
				if(obj.offsetLeft!=oldLeft){
					result_X += nopx(obj.offsetLeft);
					result_X -= nopx(obj.scrollLeft);
				 }
				if(obj.offsetTop != oldTop){
					result_Y += nopx(obj.offsetTop);
					result_Y -= nopx(obj.scrollTop);
				 }
				oldLeft = obj.offsetLeft;
				oldTop = obj.offsetTop;
			 }
		 }
		obj = obj.parentNode;
	 }
	return Array(result_X,result_Y);
 }

function add_action(sEvenement,sCode){
	var bTest;
	eval("var oEvent = " + sEvenement + ";");
	eval("bTest = (typeof " + sEvenement + " == 'function');");
	if(!bTest)
		eval(sEvenement+" = function(){ " + sCode + "}");
	else
		eval(sEvenement + " = function(){ oEvent(); " + sCode + "}");
 }

// Obtenir la partie droite d'une chaîne
function droite(sChaine,iPosition){
	if(typeof(sChaine)=="string")
   		return sChaine.substr(sChaine.length-iPosition);
	else
		return "";
 }

// Obtenir la partie gauche d'une chaîne
function gauche(sChaine,iPosition){
	if(typeof(sChaine)=="string")
   		return sChaine.substr(0,iPosition);
	else
		return "";
 }

function remplacer(sChaine,sTrouve,sRemplace){
  	var w=0
	if(typeof(sChaine)=="string"){
		while (w!=-1) {
			w=sChaine.indexOf(sTrouve,w);
			if (w>=0) {
				sChaine=sChaine.substring(0,w)+sRemplace+sChaine.substring(w+sTrouve.length);
				w+=sRemplace.length;
			 }
		 }
	 }
	return sChaine;
 }

// Supprimer les espaces devant et derrière une chaîne
function espace(sChaine){
	var vide;
	
	if(sChaine==undefined || sChaine==vide || sChaine==null)
		sChaine = "";
	else{
		while(sChaine.length > 0 && gauche(sChaine,1) == " ")
			sChaine = droite(sChaine,sChaine.length-1);
			
		while(sChaine.length > 0 && droite(sChaine,1) == " ")
			sChaine = gauche(sChaine,sChaine.length-1);
	 }
	
	return(sChaine);
 }
