// JavaScript Document
/*La fonction IsInteger prend en paramètre une valeur à vérifier et l id de la balise ou il faut afficher le message d erreur*/
		function IsInteger(valeur)
			{
			var expr = new RegExp("^[0-9]*$","gi");
					if ( !expr.test(valeur) )
					{
						return false
					}
					else
					{
						return true;
					}
			}
		/*La fonction $E prend en parametre l id du formulaire et l id de l element et retourne l element */
		
		function $E(form,element)
			{
			return document.forms[form].elements[element];
			}
			
		 function VPeriode(mois_debut,annee_debut,mois_fin,annee_fin)
 			{
		if(mois_debut!='' && mois_fin!='' && annee_debut!='' && annee_fin!='')
		{
			if( parseInt(annee_debut) < parseInt(annee_fin)  )
			{
				return true;
			}
			else if(parseInt(annee_debut)==parseInt(annee_fin))
			{
				if( parseInt(mois_debut) < parseInt(mois_fin) )
					{
						return true;
					}
				else
					{
						return false;
					}
			}
			else
			{
				return false;
			}
		}
			}

		function IsAlpha(valeur)
			{
			var expr = new RegExp("^[a-zA-Z ]*$","gi");
					if ( !expr.test(valeur) )
					{
						return false
					}
					else
					{
						return true;
					}
			}

		function IsAlphaNum(valeur)
			{
			var expr = new RegExp("^[a-z0-9]*$","gi");
					if ( !expr.test(valeur) )
					{
						return false
					}
					else
					{
						return true;
					}
			}
		function VAlphaNum(form,champ,div_error,msg_error)
			{
			var valeur=$F(champ);
			//On vérifie d'abord si le champ n'est pas vide
			if(IsEmpty(form,champ,div_error,'Ce champ est obligatoire'))
				{
				if(!IsAlphaNum(valeur))
					{
					$(div_error).innerHTML='&nbsp;';
					
					$(div_error).innerHTML ='<img src="images/exclamation.gif" alt="'+msg_error+'"/>'+msg_error;	
					
					/*$E(form,champ).style.background='url(images/bg_input_erreur2.gif)';
					$E(form,champ).style.border='1px solid red';
					*/
					$(div_error).style.color ="red";
					$(champ).className='inputError';
					
					return false;
					}
				else
					{
					$(div_error).innerHTML='&nbsp;';
					$(champ).className='inputbox';
					/*$(div_error).innerHTML ='<img src="images/valide.gif" alt="Champ valide">';	
					$E(form,champ).style.background='';
					$E(form,champ).style.border='';
					*/
					$(div_error).style.color ="green";
					return true;
					}
				}
			else
				{
				$(div_error).innerHTML='&nbsp;';
					$(div_error).innerHTML ='<img src="images/exclamation.gif" alt="'+msg_error+'"/>'+msg_error;	
					$(div_error).style.color ="red";
					$(champ).className='inputError';
					
					/*$E(form,champ).style.background='url(images/bg_input_erreur2.gif)';
					$E(form,champ).style.border='1px solid red';
					*/
				return false;
				}
			}
		function IsEmpty(form,champ,div_error,msg_error)
			{
			 var val=$F(champ);
			/*if($F(champ))
				{
				 var val=$F(champ);
				}
			else
				{
				var val=$E(form,champ);
				}*/
			if(val=='')
				{				
				$(div_error).innerHTML='&nbsp;';
				$(div_error).innerHTML ='<img src="images/exclamation.gif" alt="'+msg_error+'"/>';	
					//$E(form,champ).style.background='url(images/bg_input_erreur2.gif)';
					$(champ).className='inputError';
					$(div_error).style.color ="red";
					/*$E(form,champ).style.border='1px solid red';
						*/	
					return false;
				}	
			else
				{
					$(div_error).innerHTML='&nbsp;';
				//	$(div_error).innerHTML ='<img src="images/valide.gif" alt="Champ valide"/>';	
					//$E(form,champ).style.background='';
					$(champ).className='inputbox';
					$(div_error).style.color ="green";
					return true;
				}
			}
			
		function IsEmpty2(champ,div_error,msg_error)
			{
			
			var val=$F(champ);
			if(val=='')
				{				
				$(div_error).innerHTML='&nbsp;';
				$(div_error).innerHTML ='<img src="images/exclamation.gif" alt="'+msg_error+'"/>';	
					//$E(form,champ).style.background='url(images/bg_input_erreur2.gif)';
					$(champ).className='inputError';
					$(div_error).style.color ="red";
					/*$E(form,champ).style.border='1px solid red';
						*/	
					return false;
				}	
			else
				{
					$(div_error).innerHTML='&nbsp;';
				//	$(div_error).innerHTML ='<img src="images/valide.gif" alt="Champ valide"/>';	
					//$E(form,champ).style.background='';
					$(champ).className='inputbox';
					$(div_error).style.color ="green";
					return true;
				}
			}
		/* 	Verification du tel
		 *	parametres
		 *  form:L'id du formulaire
		 *  champ: Nom du champ
		 *	div_error:L'emplassement ou il faut afficher l'erreur
		 * 	msg_error:Message d'erreur a afficher
		 *	Retourne false en cas d'erreur et true si non
  		 */
		function VTel(form,champ,div_error,msg_error,required)
			{
			var expre=new RegExp("^[0-9+]{9,15}$","gi");
			var tel=$F(champ);
			
			if(tel!="")
				{
				if(!expre.test(tel))
					{
					$(div_error).innerHTML='&nbsp;';
					$(div_error).innerHTML ='<img src="images/exclamation.gif" alt="'+msg_error+'"/>'+msg_error;	
					$(div_error).style.color ="red";
					/*
					$E(form,champ).style.background='url(images/bg_input_erreur2.gif)';
					$E(form,champ).style.border='1px solid red';
						*/
					$(champ).className='inputError';
				return false;
					}
				else
					{
					$(div_error).innerHTML='&nbsp;';
					/*$(div_error).innerHTML ='<img src="images/valide.gif" alt="Champ valide"/>';	
					$E(form,champ).style.background='';
					$E(form,champ).style.border='';
					*/
					$(div_error).style.color ="green";
					$(champ).className='inputbox';
				return true;
					}
				}
			else if(required!="" && tel=="")
				{
					$(div_error).innerHTML='&nbsp;';
					$(div_error).innerHTML ='<img src="images/exclamation.gif" alt="'+msg_error+'"/>'+msg_error;	
					$(div_error).style.color ="red";
					$(champ).className='inputError';
					
					/*$E(form,champ).style.background='url(images/bg_input_erreur2.gif)';
					$E(form,champ).style.border='1px solid red';
						*/
					return false;
				}
			else if(required=="" && tel=="")
				{
				$(div_error).innerHTML='&nbsp;';
				$(div_error).style.color ="green";
				$(champ).className='inputbox';
				/*$E(form,champ).style.background='';
				$E(form,champ).style.border='';*/
				return true;
				}
				
			}
			
		function VAlpha(form,champ,div_error,msg_error)
			{
			var text=document.forms[form].elements[champ].value;
				if(IsEmpty(form,champ,div_error,'Champ obligatoire'))
					{
					if ( !IsAlpha(text) )
					{
					$(div_error).innerHTML='&nbsp;';
					$(div_error).innerHTML ='<img src="images/exclamation.gif" alt="'+msg_error+'"/>'+msg_error;	
					/*$E(form,champ).style.background='url(images/bg_input_erreur2.gif)';
					$E(form,champ).style.border='1px solid red';
					$(div_error).style.color ="red";*/
					$(champ).className='inputError';
					return false;			
					}
				else
					{
					$(div_error).innerHTML='&nbsp;';
					/*$(div_error).innerHTML ='<img src="images/valide.gif" alt="Champ valide"/>';	
					$E(form,champ).style.background='';
					$E(form,champ).style.border='';*/
					$(div_error).style.color ="green";
					$(champ).className='inputbox';
					return true;
					}
					}
				
			}
		function VInteger(form,champ,div_error,msg_error)
			{
			var text=$F(champ);
				if(IsEmpty(form,champ,div_error,''))
					{
					if ( !IsInteger(text) )
					{
					$(div_error).innerHTML='&nbsp;';
					$(div_error).innerHTML ='<img src="images/exclamation.gif" alt="'+msg_error+'"/>'+msg_error;	
					$(div_error).style.color ="red";
					/*$E(form,champ).style.background='url(images/bg_input_erreur2.gif)';
					$E(form,champ).style.border='1px solid red';
					*/
					$(champ).className='inputError';
					return false;			
					}
				else
					{
					$(div_error).innerHTML='&nbsp;';
					$(champ).className='inputbox';
					$(div_error).style.color ="green";
					/*$(div_error).innerHTML ='<img src="images/valide.gif" alt="Champ valide"/>';	
					$E(form,champ).style.background='';
					$E(form,champ).style.border='';
					*/
					return true;
					}
					}
			}
		function VInteger2(form,champ,div_error,msg_error)
			{
			var text=$F(champ);
				if(text=='')
						{
							/*Le champ n'est pas obligatoire*/
						$(div_error).innerHTML='&nbsp;';
						$(champ).className='inputbox';
						$(div_error).style.color ="green";
							return true;
						}
				else if ( !IsInteger(text) )
					{
					$(div_error).innerHTML='&nbsp;';
					$(div_error).innerHTML ='<img src="images/exclamation.gif" alt="'+msg_error+'"/>'+msg_error;	
					$(div_error).style.color ="red";
					/*$E(form,champ).style.background='url(images/bg_input_erreur2.gif)';
					$E(form,champ).style.border='1px solid red';
					*/
					$(champ).className='inputError';
					return false;			
					}
				else
					{
					$(div_error).innerHTML='&nbsp;';
					$(champ).className='inputbox';
					$(div_error).style.color ="green";
					/*$(div_error).innerHTML ='<img src="images/valide.gif" alt="Champ valide"/>';	
					$E(form,champ).style.background='';
					$E(form,champ).style.border='';
					*/
					return true;
					}
					
			}
		
		function VEmail(form,champ,div_error,msg_error,required)
			{
			var email = document.forms[form].elements[champ].value;
  			var expre=new RegExp("^[a-z0-9_\-]+(\.[a-z0-9_\-]+)*@[a-z0-9\-]*[a-z0-9](\.[a-z0-9\-]*[a-z0-9])*[\.][a-z]{2,4}$","i");
				if(email!="")
				{
				if(!expre.test(email))
					{ 
					$(div_error).innerHTML='&nbsp;';
					$(div_error).innerHTML ='<img src="images/exclamation.gif" alt="'+msg_error+'"/>'+msg_error;	
					$(div_error).style.color ="red";
				/*	$E(form,champ).style.background='url(images/bg_input_erreur2.gif)';
					$E(form,champ).style.border='1px solid red';
					*/
					$(champ).className='inputError';

					return false;
					}
				else
					{
					$(div_error).innerHTML='&nbsp;';
					$(div_error).style.color ="green";
					/*$(div_error).innerHTML ='<img src="images/valide.gif" alt="Champ valide"/>';	
					$E(form,champ).style.background='';
					$E(form,champ).style.border='';
					*/
					
					$(champ).className='inputbox';

					return true;
					}
				}
				else if(required!="" && email=="")
				{
					$(div_error).innerHTML='&nbsp;';
					$(div_error).innerHTML ='<img src="images/exclamation.gif" alt="'+msg_error+'"/>'+msg_error;	
					$(div_error).style.color ="red";
				/*	$E(form,champ).style.background='url(images/bg_input_erreur2.gif)';
					$E(form,champ).style.border='1px solid red';
						*/
					$(champ).className='inputError';
					return false;
				}
			else if(required=="" && email=="")
				{
				$(div_error).innerHTML='&nbsp;';
			/*	$E(form,champ).style.background='';
				$E(form,champ).style.border='';*/
				$(champ).className='inputbox';
				return true;
				}	
				
			}
		function VIdentique(form,champ1,champ2,div_error,msg_error)
			{
			var valeur1= document.forms[form].elements[champ1].value;
			var valeur2= document.forms[form].elements[champ2].value;
			
				if(valeur1!=valeur2)
					{
					$(div_error).style.color ="red";
					$(div_error).innerHTML ='<img src="images/exclamation.gif" alt="'+msg_error+'"/>'+msg_error;	
					$(champ1).className='inputError';
					$(champ2).className='inputError';
					/*$E(form,champ1).style.background='url(images/bg_input_erreur2.gif)';
					$E(form,champ1).style.border='1px solid red';
					$E(form,champ2).style.background='url(images/bg_input_erreur2.gif)';
					$E(form,champ2).style.border='1px solid red';*/
					
					
					
					return false;
					}
				else
					{
					/*$(div_error).innerHTML ='<img src="images/valide.gif" alt="Champ valide"/>';	
					*/
					$(div_error).style.color ="green";
					$(div_error).innerHTML ='';
					$(champ1).className='inputbox';
					$(champ2).className='inputbox';
					
				/*	$E(form,champ1).style.background='';
					$E(form,champ1).style.border='';
					$E(form,champ2).style.background='';
					$E(form,champ2).style.border='';*/
					
					return true;
					}
			}
		function VPass(form,champ,Lmax,Lmin,div_error,msg_error)
			{
			var pass = document.forms[form].elements[champ].value;
			if( !IsAlphaNum(pass) )
				{
					
					$(div_error).innerHTML ='<img src="images/exclamation.gif" alt="'+msg_error+'"/>[0-9a-zA-Z]';	
					$(div_error).style.color ="red";

					$(champ).className='inputError';
					return false;
				}
			else if( (pass.length<Lmin) || (pass.length>Lmax) )
				{
					$(div_error).innerHTML ='<img src="images/exclamation.gif" alt="'+msg_error+'"/>Entre '+Lmin+' et '+Lmax+' caract&egrave;res';	
				$(div_error).style.color ="red";
				
				$(champ).className='inputError';
					return false;
				}
			else
				{
					
					$(div_error).style.color ="green";
					$(div_error).innerHTML='&nbsp;'; 
					$(champ).className='inputbox';
					return true;
				}
			
			}
		function VCP(form,champ,div_error,msg_error,required)
			{
			var cp=$F(champ);
			if(cp!="")
				{
				if(cp.length==5)
				{
					if(VInteger(form,champ,div_error,'Format incorrect [0-9]'))
						{
						return true;
						}
					else
						{
						return false;
						}
				}
			else
				{
				$(div_error).innerHTML ='<img src="images/exclamation.gif" alt="Longueur incorrect"/>Longueur incorrect ';	
				/*$E(form,champ).style.background='url(images/bg_input_erreur2.gif)';
				$E(form,champ).style.border='1px solid red';
				*/
				$(div_error).style.color ="red";
				$(champ).className='inputError';
				}
				}
			else if(required!="" && cp=="")
				{
					$(div_error).innerHTML='&nbsp;';
					$(div_error).innerHTML ='<img src="images/exclamation.gif" alt="'+msg_error+'"/>'+msg_error;	
					$(div_error).style.color ="red";
					/*$E(form,champ).style.background='url(images/bg_input_erreur2.gif)';
					$E(form,champ).style.border='1px solid red';
					*/
					
					$(champ).className='inputError';
					return false;
				}
			else if(required=="" && cp=="")
				{
				$(div_error).innerHTML='&nbsp;';
				$(champ).className='inputbox';
				/*$E(form,champ).style.background='';
				$E(form,champ).style.border='';*/
				return true;
				}	
			
			}
function VLength(champ,div,max)
		{
			if(parseInt($(champ).value.length)>max)
				{
				$(champ).value=$(champ).value.substring(0,max);
				}
			
			$(div).innerHTML=max-parseInt($(champ).value.length);
			
			return true;
		}
function VPeriode2(jour_debut,mois_debut,annee_debut,jour_fin,mois_fin,annee_fin)
 	{
		if(mois_debut!='' && mois_fin!='' && annee_debut!='' && annee_fin!='')
		{
			if( parseInt(annee_debut) < parseInt(annee_fin)  )
			{
				return true;
			}
			else if(parseInt(annee_debut)==parseInt(annee_fin))
			{
				if( parseInt(mois_debut) < parseInt(mois_fin) )
					{
						return true;
					}
				else if(parseInt(mois_debut)==parseInt(mois_fin))
					{
						if( parseInt(jour_debut) < parseInt(jour_fin) )
						{
							return true;
						}
						else 
						{
							return false;
						}
					}
				else
					{
						return false;
					}
			}
			else
			{
				return false;
			}
		}
	}