/* auteur: DBC TeAM */
/* Date de création: 19/11/2007 */
function CheckEmail2(email, vide, msg) {
           if  (!ChaineVide(email)) {
	          chaine = email;
	          if (chaine.length >= 5) {
	            position = chaine.indexOf('@',1);
	            if (position > 0 && position < chaine.length) {
	              domaine = chaine.substr(position+1);
	              adresse = chaine.substring(0, position);
	              position = domaine.indexOf('.',1);
	              if (position > 0 && position < domaine.length) {
	                if (NoSymbol(adresse) && NoSymbol(domaine)) return '';
	              }
	            }
	          }
	          return msg;
		  }
		  else {
		     if(vide=='0') return '';
			 else {
		           return 'Veuillez S.V.P. renseigner l\'Adresse e-mail.';
		         }
		  }	 	  
        }
		
		function NoSymbol(chaine) {
			symbols = '()<>@,;:\\[] \"';
			for (i = 0; i < chaine.length; i++) {
				if (symbols.indexOf(chaine.substr(i,1)) != -1) return false;
			}
			return true;
		}
		
		function validite(formulaire,champ,format) {

		// Initialisation de la variable
			probleme = 0;
		
		// Les differents tests possibles :
		// On affecte a la variable 'RE' le test d'expression reguliere souhaite
		//	A	: alphabetique
			if ( format == "A" ) { RE = /^([A-Za-z]+[ ]*[-]*[A-Za-z]*)+$/;}
		
		//	AN	: alphanumerique
			//if ( format == "AN" ) { RE = /^[A-Za-zàâäéèêëîïôùûç\s,'0-9\-]+$/;}
			if ( format == "AN" ) { RE = /^[A-Za-z_\s,'0-9\-]+$/;}
		
		//	N	: numerique
			if ( format == "N" ) { RE = /^\d+$/;}
		
		//	CP	: code postal francais (5 chiffres)
			if ( format == "CP" ) { RE = /^\d{5}$/;}
		
		//	D	: Date (xx/xx/xx ou xx/xx/xxxx ou xx-xx-xx ou xx-xx-xxxx)
			if ( format == "D" ) { RE = /^\d{2}([\/]|[\-])+\d{2}([\/]|[\-])+\d{2}(\d{2})*$/;}
		
		//	EMAIL	: email
			if ( format == "EMAIL" ) { RE = /^[A-Za-z0-9\.\-_]+[@][A-Za-z0-9\-\.]+[\.][A-Za-z][A-Za-z][A-Za-z]?$/;}
		
		// Creation d'un raccourci pour manipuler le champ a tester
			var controle = eval('document.' + formulaire + '.' + champ);
		    // Si on ne trouve pas dans le champ l'expression reguliere recherchee
			return RE.test(controle.value);
		}
		
		
		function ChaineVide(chaine) {
		  var ok = false;
		  var j =0;
	      while (chaine.charAt(j)==' ' && j<chaine.length) j++;
	      if(j==chaine.length) ok = true;
		  return ok;
	    }
		
		function changeCouleur(ligne, couleur)
    	 {
			 ligne.bgColor = couleur;
		 }
		 
		 function changebgCouleur(ligne, classe)
    	 {
			 ligne.className = classe;
		 }
		  
		function OpenPop(page,nom,option) {
		  window.open(page,nom,option);
	 	 }
		 
		 function Mineur() {
		  if(!ChaineVide(document.form_test.age.value)) {
		    if(Number(document.form_test.age.value)<18) {
			  return 'Vous ne pouvez vous inscrire car vous êtes encore mineur !';
		    }
		  }	
		 }
		 
		function Cocher(elmt, Nbre) {
	          var ok = 0;
			  var champ = eval(elmt);
			  
			  if(Nbre>1) {
	              for (var i=0; i < champ.length; i++){
	               if(champ[i].checked) ok = 1;
	              }
			  }
			  else if(champ.checked) ok = 1;
			  if(ok==0) return false;
			  else return true;
        }
		
		function Valeur_Options(elmt, Nbre, elmt2) {
				 var champ = eval(elmt);
				 var champ2 = eval(elmt2);
				 var aux = '';
				 
				 if(Nbre>1) {
				   for (var i=0; i < champ.length; i++){
				     if(i) aux  += '::';
				     if(champ[i].checked) aux += champ[i].value;
				     else aux += '';
				   }
				 }
				 else {
				  if(champ.checked) aux = champ.value;
				  else aux = '';
				 } 
				 champ2.value = aux;
				 //alert(aux);
        }
		
		function Valeur_Radio(elmt, Nbre, elmt2) {
	          //var ok = 0;
			  var champ = eval(elmt);
			  var champ2 = eval(elmt2);
			  var aux = '';
			  
			  if(Nbre>1) {
	              for (var i=0; i < champ.length; i++){
	               if(champ[i].checked) aux += champ[i].value;
	              }
			  }
			  else if(champ.checked) aux += champ.value;
			  champ2.value = aux;
			  //alert(aux);
        }
		
		function Controle_Valeur() {
		  if(!ChaineVide(document.form_test.age.value)) {
		    if(Number(document.form_test.age.value)>18) {
			  document.form_test.nom.disabled = true;
			
		    }
			else document.form_test.nom.disabled = false;
		  }
		 }
function Confirm_Suppression(lien, msg) {
			var ok ;
			ok = confirm(msg);
				if (ok == '1') {
				  ok = confirm('Cette opération est irreversible, êtes-vous vraiment certain de poursuivre l\'opération ?'); 
				 if (ok == '1') {
				       location.replace(lien);
				 }
				}
				 }
		
function OpenPop(page,nom,option) {
		  window.open(page,nom,option);
}

function OpenPop_Ajout(control, page,nom,option) {
		  
		  var champ = eval(control);
		  if(champ.value) page = page + '&la_valeur=' + champ.value;
		  window.open(page,nom,option);
}


function OpenPop_Editeur(editeur_form, editeur_champ, editeur_libelle, nom,option) {
		  
		  var control = eval('document.' + editeur_form + '.' + editeur_champ);
		  var control2 = eval('document.' + 'auto_' + editeur_champ+ '.' + 'contenu');
		  var formulaire = eval('window.document.' + 'auto_' + editeur_champ );
		  control2.value = control.value;
		  formulaire.submit();
}

		function Nouvelle_Option(formulaire, champ) {
		        
				var nouvel_element = new Option('','',false,true);
				var controle = eval('document.' + formulaire + '.' + champ);
				controle.length = controle.length+1;
				controle.options[controle.length] = nouvel_element;
		}
		
		function Supp_Option(formulaire, champ) {
		   if(window.opener!=null) {
				var controle = eval('window.opener.document.' + formulaire + '.' + champ);
				var index = controle.length-1;
			    controle.options[index] = null;
				controle.blur();
		   }		
		}
		
	  function Envoi_Form_Get(form, page, id, type) {
		var formulaire = eval('document.' + form);
		var aux = '&num_ajax=0';
		if(type) {		 
		  for (i=0; i < formulaire.elements.length; i++)
			{ 
			  le_type = formulaire.elements[i].type;
			  if(le_type != 'button' && le_type != 'BUTTON') {
			    if(aux) aux += '&';
			    aux += formulaire.elements[i].name + '=' + formulaire.elements[i].value;
			  }	
			}
	    }
		page = page + aux;
		//alert(page);
		Ajax_Lien(page, id); 	
      }