function VerifEmail(valeur)	{
	if (valeur.length == 0) return true;
	var verif1=false;
	var verif2=false;
	for (var k = 0;k<valeur.length;k++) {
		var c=valeur.substring(k,k+1);
		if (c=='@') verif1=true;
		if (c=='.')
			{verif2 = (verif1==true)?true:false;}
		}
	if (verif2)
		{return true;}
	else
		{alert('Adresse Email invalide !');
		return false;}
	}	

function Entier(contenu){
	var charliste;
	charliste='0123456789';
	for (i=0;i<contenu.length;i++) {
		for (j=0;j<charliste.length;j++) {
			if (contenu.charAt(i)==charliste.charAt(j)) {
				break;
			}
		}
		if (j==charliste.length) {
			break;
		}
		charliste='0123456789';
	}
	if (i==contenu.length && contenu.length!=0) {
		return true;
	}
	else{
		return false;
	}

}



function phone(contenu){
	var charliste;
	charliste='+-( )0123456789';
	for (i=0;i<contenu.length;i++) {
		for (j=0;j<charliste.length;j++) {
			if (contenu.charAt(i)==charliste.charAt(j)) {
				break;
			}
		}
		if (j==charliste.length) {
			break;
		}
		charliste='+-( )0123456789';
	}
	if (i==contenu.length ) {
		return true;
	}
	else{
		return false;
	}

}



function VerifDateMMAAAA(Valeur){
	var DateValide=-1;	
	if (Valeur!='') {
		if (Valeur.length != 7) DateValide=0;
		if (Valeur.charAt(2) != '/') DateValide=0;
		
		if (DateValide==-1){		
			for (i=0;i<Valeur.length;i++) {
				var	charliste='0123456789/';
				for (j=0;j<charliste.length;j++) {
					if (Valeur.charAt(i)==charliste.charAt(j)) 	break;
					}
				if (j==charliste.length) DateValide=0;
			}
		}
		
		if (DateValide==-1){
			var mois = parseInt(Valeur.substring(0,2))
			var annee = parseInt(Valeur.substring(3,8))
			if (! (( mois >0 && mois <13) && (annee > 1900)))  {
				alert('Le Date saisie est invalide !');
				return false;
				}
			else 
				{
				return true;
				}	
			}
			else 
			{
			alert('Le format du champ Date doit être du type MM/AAAA !');
			return false;
			}
	}
	return true;	
}



function VerifType(Valeur,Format,Intitule,Taille){
	
	var Ok = true;
	switch(Format){
		case 'Entier' :
		
				if (Entier(Valeur))
					if (Valeur.length > Taille){
						alert('Le champ '+Intitule +' ne doit pas contenir plus de '+ Taille + ' caractères');
						return false;											
					}
					else return true;
				else
				{
					alert('Le champ '+Intitule+' doit être un entier !');
					return false;
				}
				break;
		
		case 'CodePostal' :
			if (Valeur.length > 0){
				if (Entier(Valeur))
					if (Valeur.length != 5){
						alert('Le champ '+Intitule +' doit contenir 5 chiffres');
						return false;											
					}
					else return true;
				else
				{
					alert('Le champ '+Intitule+' doit contenir 5 chiffres !');
					return false;
				}
			}else return true;	
			break;
				
		case 'Phone' :
		
				if (phone(Valeur))
					if (Valeur.length > Taille){
						alert('Le champ '+Intitule +' ne doit pas contenir plus de '+ Taille + ' caractères');
						return false;											
					}
					else return true;
				else
				{
					alert('Le champ '+Intitule+' doit être un numéro valide !\nles caractères autorisés sont : +-( )0123456789');
					return false;
				}
				break;
				
		case 'EntierVideOk' :
			if (Valeur.length > 0){
				if (Entier(Valeur))
					if (Valeur.length > Taille){
						alert('Le champ '+Intitule +' ne doit pas contenir plus de '+ Taille + ' caractères');
						return false;											
					}
					else return true;
				else
				{
					alert('Le champ '+Intitule+' doit être un entier !');
					return false;
				}
			}
			else return true;	
			break;
		
			
		case 'Chaine' :
				
				if (Valeur.length!=0){
					if (Valeur.length>Taille){
						alert('Le champ '+Intitule +' ne doit pas contenir plus de '+ Taille + ' caractères');
						Ok=false;
					}												
					return Ok;
				}	
				else
				{
					alert('Le champ '+Intitule +' ne peut être une chaine vide.');
					return false;
				}
		
				break;
				
		case 'ChaineVideOk' :
				
			if (Valeur.length<Taille){					
					return Ok;
				}	
				else{
					alert('Le champ '+Intitule +' ne doit pas contenir plus de '+ Taille + ' caractères.');
					return false;
				}
		
				break;	
		
		
		case 'DateVideOK' :
		
			
			if ((jsCheckDateFormat(Valeur, 'dd/mm/yyyy')) || (Valeur.length==0)) {
				return true;
				} else {
				alert('Le format du champ ' + Intitule + ' doit être jj/mm/aaaa et doit être une date valide !');
				return false;
				}
			break;					
		
		
		case 'Date':
			
			if (jsCheckDateFormat(Valeur, 'dd/mm/yyyy')) {
				return true;
				} else {
				alert('Le format du champ ' + Intitule + ' doit être jj/mm/aaaa, doit être une date valide et ne peut être vide !');
				return false;
				}
			break;	
							
	}	
}


function Verification(){
	
 var CompteurFormulaire=0;
 var CompteurArguments=0;
 var longueur=document.Information.length;	
 
 while(CompteurArguments<Verification.arguments.length){
 	Format = Verification.arguments[CompteurArguments];
	NumChamp = Verification.arguments[CompteurArguments+1];
	Intitule = Verification.arguments[CompteurArguments+2];
	Taille = Verification.arguments[CompteurArguments+3];
	
		
	while(CompteurFormulaire<longueur){
	
		if (document.all){
			if (document.Information.elements(CompteurFormulaire).name==NumChamp){
				if (!VerifType(document.Information.elements(CompteurFormulaire).value,Format,Intitule,Taille)){
					//alert('pb champ' + document.Information.elements(CompteurFormulaire).value);
				/*	'pointage désactivé car pb si calques pas actifs	
					document.Information.elements(CompteurFormulaire).select();
					document.Information.elements(CompteurFormulaire).focus();*/
					return false;
				}
				break;
			}
		}
		else{
			if (document.Information.elements[CompteurFormulaire].name==NumChamp){
				if (!VerifType(document.Information.elements[CompteurFormulaire].value,Format,Intitule,Taille)){
					return false;
				}
				break;
			}
		}
	CompteurFormulaire++;
	}
	CompteurFormulaire = 0;
	CompteurArguments=CompteurArguments+4;
 }
 return true;
}

function SuppGuillemet(NomChamp){
	eval('document.Information.'+NomChamp+'.value = document.Information.'+NomChamp+'.value.replace(/"/gi,"\'")');
}	
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~ jsCheckDateFormat
//~~~[IN]~~~~	strDate : la date  a tester
//~~~~~~~~~~~	strFormat : format avec /
//~~~[OUT]~~~	true, false
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function jsCheckDateFormat(strDate, strFormat)  {

	var D;
	var M;
	var Y;
	var div4;
	var div100;
	var div400;
	var bTest = false;

	p1 = strDate.indexOf('/');
	p2 = strDate.lastIndexOf('/');
	LenY = strDate.length - p2 - 1;
	bTest = false;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//~~~~ Selon format, initialisation des variables D (Day) M (Month) Y (Year)	
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
	 
	if ((strFormat=='dd/mm/yy') || (strFormat=='d/m/yy')){
		bTest = true;
		D = parseFloat(strDate.substring(0,p1));
		M = parseFloat(strDate.substring(p1+1,p2));
		Y = parseFloat(strDate.substring(p2+1,strDate.length));
		if (LenY!=2) {Y=-1;} 
	}
	if (!bTest && ((strFormat=='mm/dd/yy') || (strFormat=='m/d/yy'))){
		bTest = true;
		M = parseFloat(strDate.substring(0,p1));
		D = parseFloat(strDate.substring(p1+1,p2));
		Y = parseFloat(strDate.substring(p2+1,strDate.length));
		if (LenY!=2) {Y=-1;} 
	}
	if (!bTest && ((strFormat=='mm/dd/yyyy') || (strFormat=='m/d/yyyy'))){
		bTest = true;   		
		M = parseFloat(strDate.substring(0,p1));
		D = parseFloat(strDate.substring(p1+1,p2));
		Y = parseFloat(strDate.substring(p2+1,strDate.length));
		if (LenY!=4) {Y=-1;} 
	}
	if (!bTest && ((strFormat=='dd/mm/yyyy') || (strFormat=='d/m/yyyy'))){
		bTest = true;
		D = parseFloat(strDate.substring(0,p1));
		M = parseFloat(strDate.substring(p1+1,p2));
		Y = parseFloat(strDate.substring(p2+1,strDate.length));
		if (LenY!=4) {Y=-1;} 
	}
	if (!bTest){
	   D = parseFloat(strDate.substring(0,p1));
	   M = parseFloat(strDate.substring(p1+1,p2));
	   Y = parseFloat(strDate.substring(p2+1,strDate.length));
	   if (LenY!=4) {Y=-1;} 
	}
		
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//~~~~ Validite de la date	
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
		
	if ((D==0)||!jsTestCeiljsCheckDateFormat(D)) {D=-1;}
	if ((M==0)||!jsTestCeiljsCheckDateFormat(M)||(M>=13)) {M=-1;}
	if (!jsTestCeiljsCheckDateFormat(Y)) {Y=-1;}
	if (Y==0) {Y=2000;}
	
	div4=jsTestCeiljsCheckDateFormat(Y/4);
	div100=jsTestCeiljsCheckDateFormat(Y/100);
	div400=jsTestCeiljsCheckDateFormat(Y/400);
	
	if ((Y>=0) && (Y<=9999)) { 
	  if ((M==1)||(M==3)||(M==5)||(M==7)||(M==8)||(M==10)||(M==12)) {
	    if ((D>0)&&(D<=31)) { 
	      return true;
	    }
		else{
			return false;
		}
	  }
	  if ((M==4)||(M==6)||(M==9)||(M==11)) {
	    if ((D>0)&&(D<=30)) { 
	      return true; 
	    } else { return false; }
	  }
	  //~~~ Février 
	  
	  if (M==02) {
	    if ((div4)&&!(div100)||(div400)) {
	      if ((D>0)&&(D<=29)) {
	        return true; 
	      }
		  else{ 
		  	return false; 
			}
	    } else {
	      if ((D>0)&&(D<=28)) {
	        return true; 
	      }else { return false; }
	    } 
	  } else { return false; }
	} else { return false; }
	return true;
}
function jsTestCeiljsCheckDateFormat(Nbre){
	if (Nbre==Math.ceil(Nbre)){
	    return true; 
	}
	else{return false;}
}