var debMess = "Le champ ";
var finMess = " n'est pas valide !\n";
var sAction ="";//redirection
tbFichier= new Array("jpg","bmp","jpeg","png","gif","pdf","zip");

function testFormulaire(num,intitule,type,target) {
	
	sAction = target;
	squal=0;
	var titre=('\nDésolé, le formulaire présente des anomalies\n\n');
	tb= new Array();
	tbIntitule = new Array();tbIntitule = intitule.split(",");
	tbType = new Array();tbType = type.split(",");
	tbValue = new Array();
	tbName = new Array();
			
	for (j=0;j<tbType.length;j++) {		
		tbName[j]=document.forms[num].elements[j].name;
		tbValue[j]=document.forms[num].elements[j].value;
		testChamps (tbType[j],tbIntitule[j],num,j);		
	}
	scanErreur(titre,num);
}

	function testChamps (type,champIntitule,num,j) {
			if (type=="NonVide"){				
				if (''==tbValue[j]){ creerMessage(debMess+champIntitule+finMess,num);}				
			}		
			if (type=="Text"){
				if ((tbValue[j].search(/[\D*]/)==-1)){ creerMessage(debMess+champIntitule+finMess,num);}				
			}
			if (type=="Mail") {		
				if ((tbValue[j].search(/.+@.+\..+/)==-1) || (tbValue[j].search(/ /)!=-1))  { creerMessage(debMess+champIntitule+finMess,num);}
			}
			if (type=="Password") {		
				if (tbValue[j].search(/[\D*\d*]/)==-1) { creerMessage(debMess+champIntitule+finMess,num);}
			}
			if (type=="Confirmation") {				
				if ((tbValue[j])!=(tbValue[j-1])) { creerMessage(debMess+champIntitule+finMess,num); }			
			}
			if (type=="Num") {				
				if (tbValue[j].search(/[\d+]/)==-1) { creerMessage(debMess+champIntitule+finMess,num); }			
			}
			if ((type=="Checkbox") || (type=="Radio")) {				
				if (document.forms[num][tbName[j]].checked==false) { creerMessage(debMess+champIntitule+finMess,num); }			
			}			
			if (type=="Select") {
				if (document.forms[num][tbName[j]].options[document.forms[num][tbName[j]].selectedIndex].value=="default") { creerMessage(debMess+champIntitule+finMess,num); }			
			}
			if (type=="Fichier" && ''!=tbValue[j]){
					var match=0;
					for(i=0;i<tbFichier.length;i++){
						if(tbValue[j].search(tbFichier[i])!=-1){match++;}
					}
					if (0==match){ creerMessage(debMess+champIntitule+finMess,num);}
			}
			if ((type=="Radio")) {
				thisChecked= 0;
				for(i=0;i<document.forms[num][tbName[j]].length;i++){
					if (document.forms[num][tbName[j]][i].checked==true)
						thisChecked++;
				}
				if(0>=thisChecked)
					creerMessage(debMess+champIntitule+finMess,num);
					
				thisChecked= 0;
			}			
}	

function creerMessage(parNom,num) {
	
	squal++;			
	tb[squal]=(parNom);
	return;
}

function scanErreur(titre,num){
	if (tb.length!=0) {
		
		var finalMess =(titre+tb.join(" "));
		showMessage(num,finalMess);
	} else {		
		var finalMess =("");
		//sendMail(num);
		document.forms[num].action=sAction;		
		document.forms[num].submit();
	}
}

function showMessage(num,message) {	
	alert(message);
}