document.write ('<scr' + 'ipt src="/navigation/Javascript/controles.js">' + '<\/script>');


function MM_validateForm() { //v5.0
  var i,p,q,nm,pswd,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { 
  	test=args[i+2]; 
	val=MM_findObj(args[i]); 
	val2=MM_findObj(args[i+1]);
	val2arr=args[i+1].split("|");
	valchk=args[i];
    if (val) { 
		nm=val.name; 
		if(test.indexOf('array')!=-1){
			p=test.indexOf("array");
			q=test.indexOf(":");
			r=test.indexOf("|");
			formu=test.substring(r+1);
			var required=false;
			if(p>0 && test.substring(0,p)=='R') required=true;
			if(!nm) nm=valchk;
			//alert("rnm=document.forms['"+formu+"'].elements['"+valchk+"'];");
			eval("rnm=document.forms['"+formu+"'].elements['"+valchk+"'];");
			//alert(rnm.id);
			if(rnm && rnm.length && !rnm.id){

				for(k=0;k<rnm.length;k++){
					if(rnm[k].tagName.toLowerCase()=='select') valx=rnm[k].options[rnm[k].options.selectedIndex].value;
					else valx=rnm[k].value;
					if(valx=='' && required) {
						errors+='- Les champs '+nm+' sont obligatoires.\n';
						break;
					}
					else if(test.substring(q+1,r)=='isNum' && isNaN(valx)) {
						errors+='- L\'un des champs '+nm+' ne contient pas un nombre.\n';
						break;
					}

				}
			}
			else{
				if(rnm.tagName.toLowerCase()=='select') valx=rnm.options[rnm.options.selectedIndex].value;
				else valx=rnm.value;
				if(valx=='' && required) {
					errors+='- Les champs '+nm+' sont obligatoires.\n';
				}
				else if(test.substring(q+1,r)=='isNum' && isNaN(valx)) {
					errors+='- L\'un des champs '+nm+' ne contient pas un nombre.\n';
				}
			}


		}
		else if ((val=val.value)!="") {

			if (test.indexOf('isEmail')!=-1) { 
				if (!echeck(val)) errors+='- Le champ '+nm+' doit contenir une adresse e-mail correcte.\n';
      		} 
			else if(test.indexOf('chk')!=-1){
				p=test.indexOf(':');
				f=test.indexOf('|');
				form=test.substring(f+1);
				
				damin=test.substring(4,p);
				damax=test.substring(p+1,f);
				tmpcpt=0;
				if(document.forms[''+form+''].elements[''+valchk+''].length){
					for (var y=0;y<document.forms[''+form+''].elements[''+valchk+''].length;y++){
						if(document.forms[''+form+''].elements[''+valchk+''][y].checked) {
							tmpcpt++;
						}
					}
				}
				else{
					if(document.forms[''+form+''].elements[''+valchk+''].checked) {
							tmpcpt++;
					}
				}
				
				if(tmpcpt<damin || (tmpcpt>damax && damax>0)){
					if(damax==0) errors+='- Vous devez cocher au moins '+damin+' cases pour le champ '+valchk+'.\n';
					else if(damin==0 ) errors+='- Vous devez cocher au plus '+damax+' cases pour le champ '+valchk+'.\n';
					else errors+='- Vous devez cocher entre '+damin+' et '+damax+' cases pour le champ '+valchk+'.\n';
				}
				
			}
			else if (test.indexOf('same') != -1 && val2) {

				if (val2.value=="") errors += '- Le champ '+val2.name+' est obligatoire.\n'; 
				else if (val2.value!=val) errors += '- Les champs '+nm+' et '+val2.name+' doivent être identiques.\n'; 
			}
			else if (test.indexOf('dateF') != -1){
				 myarraydate=val.split("/");
				 thisDate=new Date();
				 if(myarraydate.length!=3 || isNaN(myarraydate[0]) || isNaN(myarraydate[1]) || isNaN(myarraydate[2]) || myarraydate[2].length!=4 || !checkDate(myarraydate[0],myarraydate[1],myarraydate[2])) errors += '- Le champ '+nm+' doit contenir une date valide au format JJ/MM/AAAA.\n'; 
			}
			else if (test.indexOf('dateE') != -1){
				 myarraydate=val.split("/");
				 thisDate=new Date();
				 if(myarraydate.length!=3 || isNaN(myarraydate[0]) || isNaN(myarraydate[1]) || isNaN(myarraydate[2]) || myarraydate[0].length!=4 || !checkDate(myarraydate[2],myarraydate[1],myarraydate[0])) errors += '- Le champ '+nm+' doit contenir une date valide au format AAAA/MM/JJ.\n'; 
			}
			else if (test.indexOf('timeF') != -1){
				 myarrayheure=val.split(":");
				// alert(myarrayheure.length);
				 if((myarrayheure.length!=3 && myarrayheure.length!=2) || (myarrayheure.length==3 && (isNaN(myarrayheure[0]) || isNaN(myarrayheure[1]) || isNaN(myarrayheure[2])) ) || (myarrayheure.length==2 && (isNaN(myarrayheure[0]) || isNaN(myarrayheure[1])) ) || !checkTime(val)) errors += '- Le champ '+nm+' doit contenir une heure valide au format hh:mm[:ss].\n'; 
/*				 if((myarrayheure.length!=3 && myarrayheure.length!=2)) alert('1');
				 if((myarrayheure.length==3 && (isNaN(myarrayheure[0]) || isNaN(myarrayheure[1]) || isNaN(myarrayheure[2])) )) alert('2');
				 if((myarrayheure.length==2 && (isNaN(myarrayheure[0]) || isNaN(myarrayheure[1])) ) ) alert('3');*/
			}
			else if(test.indexOf('mini') != -1 ){
				if(val.length<test.substring(test.indexOf('mini')+4)) errors+='- Le champ '+nm+' doit contenir au moins '+test.substring(test.indexOf('mini')+4)+' caractères.\n';
			}
			else if (test!='R') {
				
        		if (isNaN(val)) errors+='- Le champ '+nm+' doit contenir un nombre.\n';
        		if (test.indexOf('inRange') != -1) { 
					p=test.indexOf(':');
          			min=test.substring(8,p);
					max=test.substring(p+1);
          			if (val<min || max<val) errors+='- Le champ '+nm+' doit être un nombre entre '+min+' et '+max+'.\n';
    			}
			}
			
			/*if(test.indexOf('mini') != -1 ){
				if(val.length<test.substring(test.indexOf('mini')+4)) errors+='- Le champ '+nm+' doit contenir au moins '+test.substring(test.indexOf('mini')+4)+' caractères.\n';
			}*/
		}
		else if (val2 && test.charAt(0) == 'R' && test.indexOf('same') != -1) {
			if(val=="" && val2.value=="") errors += '- Les champs '+nm+' et '+val2.name+' sont obligatoires.\n'; 
			else if (val=="") errors += '- Le champ '+nm+' est obligatoire.\n'; 
			if(!(val=="" && val2.value=="")&&test.indexOf('mini') != -1 ){
				if(val2.value.length<test.substring(test.indexOf('mini')+4)) errors+='- Le champ '+val2.name+' doit contenir au moins '+test.substring(test.indexOf('mini')+4)+' caractères.\n';
			}
		}
		else if (val2&&val2.value=="" && test.charAt(0) == 'R') errors += '- L\'un des champs '+nm+' et '+val2.name+' est obligatoire.\n'; 
		else if (!val2 && test.charAt(0) == 'R') errors += '- Le champ '+nm+' est obligatoire.\n'; 
		
	}
	else if(val2arr.length>0 && test.indexOf(':')!=-1 && test.indexOf('array')==-1 && test.indexOf('|')!=-1){
		p=test.indexOf(':');
		f=test.indexOf('|');
		form=test.substring(f+1);
		damin=test.substring(1,p);
		damax=test.substring(p+1,f);
		
		tmpcpt=0;
		allthings=val2arr.length;
		for(z=0;z<val2arr.length;z++){
			if(document.forms[''+form+''].elements[''+val2arr[z]+''].value!='') {
				tmpcpt++;
			}
		}

		if(isNaN(parseInt(damax))){
			if(tmpcpt<allthings) errors+='- Vous devez saisir toutes les valeurs pour le champ '+valchk+'.\n';
		}
		else if(tmpcpt<damin || (tmpcpt>damax && damax>0)){
			if(damax==0) errors+='- Vous devez saisir au moins '+damin+' valeur(s) pour le champ '+valchk+'.\n';
			else if(damin==0 ) errors+='- Vous devez saisir au plus '+damax+' valeur(s) pour le champ '+valchk+'.\n';
			else if(damin==damax && tmpcpt!=damax) {errors+='- Vous devez saisir '+damin+' valeur(s) pour le champ '+valchk+'.\n';}
			else errors+='- Vous devez saisir entre '+damin+' et '+damax+' valeur(s) pour le champ '+valchk+'.\n';
		}

	}
	else if(test.indexOf('array')!=-1){
			p=test.indexOf("array");
			q=test.indexOf(":");
			r=test.indexOf("|");
			formu=test.substring(r+1);
			var required=false;
			if(p>0 && test.substring(0,p)=='R') required=true;
			eval("var rnm=document.forms['"+formu+"'].elements['"+valchk+"'];");
			//alert("rnm=document.forms['"+formu+"'].elements['"+valchk+"'];");
			if(rnm){
				if(rnm.length){
					for(k=0;k<rnm.length;k++){
						valx=rnm[k].value;
						if(valx=='' && required) {
							errors+='- Les champs '+valchk+' sont obligatoires.\n';
							break;
						}
						else if(test.substring(q+1,r)=='isNum' && isNaN(valx)) {
							errors+='- L\'un des champs '+valchk+' ne contient pas un nombre.\n';
							break;
						}

					}
				}
				else{
					valx=rnm.value;
					if(valx=='' && required) {
						errors+='- Les champs '+valchk+' sont obligatoires.\n';
					}
					else if(test.substring(q+1,r)=='isNum' && isNaN(valx)) {
						errors+='- L\'un des champs '+valchk+' ne contient pas un nombre.\n';
					}
				}
			}else{
				for(k=0;k<document.forms[formu].elements.length;k++){
					if(document.forms[formu].elements[k].name==valchk){
						if(document.forms[formu].elements[k].value==''  && required){
								errors+='- Les champs '+valchk+' sont obligatoires.\n';
								break;
						}
						else if(test.substring(q+1,r)=='isNum' && isNaN(document.forms[formu].elements[k].value)) {
								errors+='- L\'un des champs '+valchk+' ne contient pas un nombre.\n';
								break;
						}
					}
					
				}
			}

		
	}
  } 

  if (errors) alert('Les erreurs suivantes sont apparues :\n\n'+errors);
  document.MM_returnValue = (errors == '');
}







