function formVerif(nomform,champs)
{
	leForm = eval(document.forms[nomform]);
	
	tabChamps = champs.split(",");
	erreur="";
	i=0;
	for(i=0;i<tabChamps.length;i++)
	//while(i < tabChamps.length)
	{
		for(f=0;f<leForm.length;f++)
		{
			//alert(tabChamps[i] + " - " + leForm.elements[f].name);
			if(tabChamps[i] == leForm.elements[f].name)
			{
				if(leForm.elements[tabChamps[i]].value=="") { erreur=erreur+"Veuillez renseigner le champs \'"+tabChamps[i]+"\'\n"; }
				
				if(tabChamps[i]=="email" || tabChamps[i]=="mail_expediteur" || tabChamps[i]=="mail_reponse")
				{
					//var maReg = new RegExp ( "^\\w[\\w+\.\-]*@[\\w\-]+\.\\w[\\w+\.\-]*\\w$", "gi" );
					var maReg = new RegExp ( "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,3}" );
					//Si l'email n'est pas conforme
					if ( leForm.elements[tabChamps[i]].value.search( maReg ) == -1 )
					{
						erreur=erreur+"Votre email n\'est pas valide\n";
					}
				}
				
			}
		}
		//i=i+1;
	}
	if(erreur!="")
	{
		alert(erreur);
	}
	else
	{
		leForm.submit();
	}
}

//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------

function checkall(formname,checkname,thestate)
{
	var el_collection=eval("document.forms."+formname+"."+checkname)
	for (c=0;c<el_collection.length;c++)
	el_collection[c].checked=thestate
}

//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------

function checkInverse(formname,checkname)
{
	var el_collection=eval("document.forms."+formname+"."+checkname)
	var txt="";
	for (i=0; i<el_collection.length; i++)
	{
		txt = txt+"\n"+i+"="+ el_collection[i].status;
		
		if (el_collection[i].checked != true) 
		{ 
			el_collection[i].checked = true; 
		}
		else
		{ 
			el_collection[i].checked = false; 
		}
		
	}
	//alert(txt);
}

//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------

function envoiSel(formname,pageencours,EnrPosition,checkname,envoi)
{
	var el_collection=eval("document.forms."+formname+"."+checkname)
	var txt="";
	ids = "";
	for (i=0; i<el_collection.length; i++)
	{
		txt = txt+"\n"+i+"="+ el_collection[i].status;
		
		if (el_collection[i].checked == true) 
		{ 
			ids = ids + el_collection[i].value+"=1, "; 
		}
		else
		{
			ids = ids + el_collection[i].value+"=0, "; 
		}
	}
	
	if(envoi!='')
	{
		document.forms[formname].envoi.value = envoi;
	}
	document.forms[formname].lesIds.value = ids;
	document.forms[formname].EnrPosition.value = EnrPosition;
	document.forms[formname].pageencours.value = pageencours;
	//document.forms[formname].target = "_self";
	document.forms[formname].action = "contacts_liste.asp";
	//alert(document.forms[formname].EnrPosition.value);
	document.forms[formname].submit();
}

//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------

function VerifNombre(val)
{
	//alert(val);
	var mikExp = new RegExp ("^[0-9]+$");
	var strPass = val.value;
	var strLength = strPass.length;
	var lchar = strPass.charAt((strLength) - 1);
	if(strPass.search(mikExp) == -1) 
	{
		var tst = val.value.substring(0, (strLength) - 1);
		val.value = tst;
		//strPass = strPass.replace(mikExp," ");
	}
}

//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------

function EnleverIds()
{
	laListe=document.form1.groupe_ids;
	for(i=0; i<laListe.options.length; i++)
	{
		//alert(i);
		if(laListe.options[i].selected==true)
		{
			//alert("i="+i);
			//alert("index="+laListe.options[laListe.selectedIndex].index);
			/*var newOpt = document.createElement("OPTION");
			newOpt.text=document.form1.groupe_ids.options[i].text;
			newOpt.value=document.form1.groupe_ids.options[i].value;
			document.form1.liste_ids.add(newOpt);*/
			laListe.remove(i);
			i=i-1; // --> i-1 car l'option, une fois supprimée, donne son index à l'option suivante 
		}
	}
}

//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------

function AjoutIds()
{
	laListe=document.form1.liste_ids;
	for(i=0; i<laListe.options.length; i++)
	{
		if(laListe.options[i].selected==true)
		{
			existe=0;
			for(g=0; g<document.form1.groupe_ids.length; g++)
			{
			if(document.form1.groupe_ids.options[g].value==laListe.options[i].value){existe=1;}
			}
			if(existe==0)
			{
				var newOpt = document.createElement("OPTION");
				newOpt.text=laListe.options[i].text;
				newOpt.value=laListe.options[i].value;
				document.form1.groupe_ids.add(newOpt);
				document.form1.groupe_ids.options[i].label=laListe.options[i].label;
			}
			laListe.options[i].selected=false;
		}
	}
}

//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------

function CopierIds()
{
	selection_ids="";
	laListe=document.form1.liste_ids;
	for(i=0; i<laListe.options.length; i++)
	{
		if(laListe.options[i].selected==true)
		{
			existe=0;
			for(g=0; g<document.form1.groupe_ids.length; g++)
			{
			if(document.form1.groupe_ids.options[g].value==laListe.options[i].value){existe=1;}
			}
			if(existe==0)
			{
				selection_ids = selection_ids+laListe.options[i].value+"-";
			}
		}
	}
	if(selection_ids!="")
	{
		document.form1.ajout_ids.value = selection_ids;
		//alert(document.form1.ajout_ids.value);
		document.form1.submit();
	}
}

//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------

function EffacerIds()
{
	selection_ids="";
	laListe=document.form1.groupe_ids;
	for(i=0; i<laListe.options.length; i++)
	{
		if(laListe.options[i].selected==true)
		{
			selection_ids = selection_ids+laListe.options[i].value+"-";
		}
	}
	if(selection_ids!="")
	{
		if(confirm('Retirer tous les contacts sélectionnés'))
		{
		document.form1.enlever_ids.value = selection_ids;
		//alert(document.form1.enlever_ids.value);
		document.form1.submit();
		}
	}
}

//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------

function toutselectionner(nomform,formelement)
{
	var lelement=eval("document.forms."+nomform+"."+formelement)
	//nbElements = getOptionValueCount(lelement,1);
	//alert(nbElements);
	for(i=0; i<lelement.length; i++)
	{
		//alert(lelement);
		lelement.options[i].selected=true;
	}
	
}

//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------

function corrigeUTF8(txt,sens)
{
	carateres_err = "Â²,Â°,Âµ,Â§,â‚¬,Â£,Â©,Â®,Ã€,Ã,Ã,Ãƒ,Ã„,Ã…,Ã†,Ã‡,Ãˆ,Ã‰,ÃŠ,Ã‹,ÃŒ,Ã,ÃŽ,Ã,Ã,Ã‘,Ã’,Ã“,Ã”,Ã•,Ã–,Ã˜,Ã™,Ãš,Ã›,Ãœ,Ã,Ãž,ÃŸ,Ã ,Ã¡,Ã¢,Ã£,Ã¤,Ã¥,Ã¦,Ã§,Ã¨,Ã©,Ãª,Ã«,Ã¬,Ã­,Ã®,Ã¯,Ã°,Ã±,Ã²,Ã³,Ã´,Ãµ,Ã¶,Ã¸,Ã¹,Ãº,Ã»,Ã¼,Ã½,Ã¾,Ã¿,Å’,Å“,Å ,Å¡,Å¸"
	carateres_ok = "²,°,µ,§,€,£,©,®,À,Á,Â,Ã,Ä,Å,Æ,Ç,È,É,Ê,Ë,Ì,Í,Î,Ï,Ð,Ñ,Ò,Ó,Ô,Õ,Ö,Ø,Ù,Ú,Û,Ü,Ý,Þ,ß,à,á,â,ã,ä,å,æ,ç,è,é,ê,ë,ì,í,î,ï,ð,ñ,ò,ó,ô,õ,ö,ø,ù,ú,û,ü,ý,þ,ÿ,Œ,œ,Š,š,Ÿ"
	if(txt!="")
	{
		tabErr = carateres_err.split(",")
		tabOk = carateres_ok.split(",")
		for(i=0; i<tabErr.length; i++)
		{
			if(sens=="1")
			{
				txt=txt.replace(tabErr(i),tabOk(i))
			}
			else
			{
				txt=txt.replace(tabOk(i),tabErr(i))
			}
		}
		//corrigeUTF8 = txt
		document.write(txt);
	}
}

//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------

function afficheMaxi(chemin)
{
	w=320;
	i1 = new Image;
	i1.src = chemin;
	html = '<HTML><HEAD><TITLE></TITLE></HEAD><BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><CENTER><IMG SRC="'+chemin+'" BORDER=0 NAME=imageTest onLoad="window.resizeTo('+w+',document.imageTest.height+32)" width='+(w-14)+'></CENTER></BODY></HTML>';
	popupImage = window.open('','_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1,left='+(screen.width-w)/2+', top='+(screen.height-200)/2);
	popupImage.document.open();
	popupImage.document.write(html);
	popupImage.document.close()
}

//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------

