//Fontion sur les touches pressées
function codeTouche(evenement)
{
        for (prop in evenement)
        {
                if(prop == 'which') return(evenement.which);
        }
        return(evenement.keyCode);
}

function scanTouche(evenement, expression)
{
        //var reCarValides = /\w/;
        var reCarValides = expression;

        var codeDecimal  = codeTouche(evenement);
        var car = String.fromCharCode(codeDecimal);
        
		if (codeTouche(evenement) != 8 && codeTouche(evenement) != 0)
			var autorisation = reCarValides.test(car);
		else
			var autorisation = true;

        return autorisation;
}

//Fonction d'activation/desactivation d'éléments
function activ() 
{
	var args=activ.arguments;
   
	for (i=0; i<(args.length); i++) 
	{
		if (document.getElementById(args[i]).disabled == true)
			document.getElementById(args[i]).disabled = false;
		else
			document.getElementById(args[i]).disabled = true;
	}
}

function limitcar(texte, nb, maxi) {
 if (texte.value.length > maxi)
   texte.value = texte.value.substring(0, maxi);
 else 
   nb.value = maxi - texte.value.length;
}

function storeCaret(text)
{ // voided
}

function AddText(startTag,defaultText,endTag,champ) 
{

 if (champ.createTextRange) 
 {
  var text;
  champ.focus(champ.caretPos);
  champ.caretPos = document.selection.createRange().duplicate();
  if(champ.caretPos.text.length>0)
  {
   champ.caretPos.text = startTag + champ.caretPos.text + endTag;
  }
  else
  {
   champ.caretPos.text = startTag+defaultText+endTag;
  }
 }
 else champ.value += startTag+defaultText+endTag;
}

function afficheMaxi(chemin)
	{
	i1 = new Image;
	i1.src = chemin;
	html = '<HTML><HEAD><TITLE>TROUILLET</TITLE></HEAD><BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><CENTER><IMG SRC="'+chemin+'" BORDER=0 NAME=imageTest onLoad="window.resizeTo(document.imageTest.width+33,document.imageTest.height+61)"></CENTER></BODY></HTML>';
	popupImage = window.open('','_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1');
	popupImage.document.open();
	popupImage.document.write(html);
	popupImage.document.close()
	};


/********************************************************************
	Fonctions pour crypter les emails afin d'éviter le spam
********************************************************************/

var keyNoSpam='mfl52idp3n@zm7lvnc@-ds58';

function f_init()
{
f_decode_all_email(keyNoSpam,'emailATraduire');
return;
}


var avaibleCharList='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-.@_';
function f_decode_all_email(key,styleSheetRestriction)
{
	var tabs=document.getElementsByTagName('a');  //on rÃ©cupÃ¨re tous les liens de la page
	var i;
	for(i=0 ; i<tabs.length ; i++)
	{
		if(tabs[i].href)  // on filtre les ancres
		{
			if(tabs[i].href.toLowerCase().indexOf('mailto')==0)   //filtrage des liens de type url, etc...
			{
				if(styleSheetRestriction==null || (styleSheetRestriction!=null && tabs[i].className==styleSheetRestriction))
				//si styleSheetRestriction a Ã©tÃ© prcisÃ© on filtre les liens emails en fonction de leur class CSS,
				//permet de ne pas appliquer le dÃ©codage sur tous les liens
				{
					//on decrypte l'email
					var str=nospam_decrypte(tabs[i].href.replace('mailto:',''),key);  //email decrypte
					tabs[i].href='mailto:'+str; //on met Ã  jour le lien href
					
					//document.write(str.length);
					if (str.length<40)
					{
						tabs[i].innerHTML=str;		//on met Ã§ jour ce qui est affichÃ©
					}
					else
					{
						tabs[i].innerHTML=str.substr(0,40)+"...";		//on met Ã§ jour ce qui est affichÃ©
					}					
				}
			}
		}
	}
	return;
}

function nospam_decrypte(txt,key)
{
	var resu='';
	var i;
	for(i=0 ; i<txt.length ; i++) //decodage caracteres aprÃ¨s caractÃ¨res
	{	//selon l'Algorithme de cryptage de Blaise de VigÃ©nÃ¨re.
		//http://www.chez.com/algor/vigenere.htm
		var ch=txt.charAt(i);
		var index=avaibleCharList.indexOf(ch);
		var chK=key.charAt(i%key.length);
		var indexK=avaibleCharList.indexOf(chK);
		var jj=(index-indexK)%avaibleCharList.length;
		if(jj<0) { jj+=avaibleCharList.length; }
		var chResu=avaibleCharList.charAt(jj);
		resu+=''+chResu;
	}
	return resu; 
}