function printPage()
{
	window.focus()
	window.print()
}

function controle ()
{		
	// 1er argument = identifiant du formulaire

	// obli#idcontrolejs#nominput
	
	//idcontrolejs
	// 0 : aucun controle
	// 1 : controle numerique 
	// 2 : controle e-mail - null autorisé
				
	var args = controle.arguments;
	var erreur = 0;
	var idform = args[0];
	var premierchamperreur = "";
	
	for (i=1;i<args.length;i++)
	{		
		// extraction variable obli
		var obli = args[i].substring(0, 1);
		
		//extraction IDcontroleJS 
		var pos2emediese = args[i].indexOf("#", 2);
		var idcontrolejs = args[i].substring(2, pos2emediese);
		
		if (idcontrolejs!=-1)
		{
		
			//extraction nominput
			pos2emediese = pos2emediese + 1;
			var nominput = args[i].substring(pos2emediese, args[i].length);
			
			nom = "p" + nominput;
			// on reinitialise tout les marqueurs d'erreur	
			var t = eval("document.forms." + idform + "."+nom+".name");
			eval("document.forms." + idform + "."+nom+".src='design/pixel.gif'");
			var valeurinput = eval("document.forms[idform]." + nominput + ".value");
			var valeurcheck = 0;
			
			
			// si checkbox verification case coché
			if (idcontrolejs == 4)
			{
				
				n = 0;
				y = 0;
				temp = 0 
				temp = eval("document.forms." + idform + "." + nominput + ".length");
															
				if (!isNaN(temp))
					{
					for (y = 0; y < temp ; y++)
			 			  {
				   	 		if ( eval("document.forms." + idform + "." + nominput + "[" + y + "].checked"))
			    				{
									n = n + 1;	
			    				}
  			 	   		  }
				 	}
			 
				 if (n == 0)
				 {
					 valeurcheck = 1;
				 }
			}
			

			// si Listbox vérif si valeur 0
			if (idcontrolejs == 6)
			{
			temp = eval("document.forms." + idform + "." + nominput + ".value");
			
				if (temp == 0)
					{
						valeurcheck = 1;
					}
	
			}
				

			// test si champ obligatoire			 
			if (obli==1)
			{			
				if ((valeurinput == "") || (valeurcheck == 1)) 
				{
					eval("document.forms." + idform + "."+nom+".src='design/Erreur2.gif'");
					erreur = 1;
					if (premierchamperreur == '') premierchamperreur  = nominput;
					valeurcheck = "null"
				}
			}
		
			// controle en fonction du type du champ	
			switch (idcontrolejs) 
			{
						
			   case "1" :
			  
					if (valeurinput != '') 
					{
						wvaleurinput = Remplace(valeurinput,",",".");
						
						if (isNaN(wvaleurinput)) 
						{
							eval("document.forms." + idform + "."+nom+".src='design/Erreur2.gif'"); 
							erreur = 1;
							if (premierchamperreur == '') premierchamperreur  = nominput;							
						}		
					}
					break;						
					
			   case "2" :
					if (MailFaux(valeurinput)) 
					{
						eval("document.forms." + idform + "."+nom+".src='design/Erreur2.gif'"); 
						erreur = 1;
						if (premierchamperreur == '') premierchamperreur  = nominput;								
					}		
					break;
					
				case "3" :
				
					var nominput2 = "confirmation" + nominput
					var valeurinput2 = eval("document.forms[idform]." + nominput2 + ".value");
					if (valeurinput2 != valeurinput)
					{
						eval("document.forms." + idform + "."+nom+".src='design/Erreur2.gif'"); 					
						erreur = 1;
						if (premierchamperreur == '') premierchamperreur  = nominput2;							
					}
				

				
			}						
		} 				
		
	}
	if (erreur == 1)
		return premierchamperreur;
	else			
		return "0";

}		

		
function MailFaux(ValeurInput)
{
  if (ValeurInput!='')
  {
	  dotPos = ValeurInput.indexOf('.');
	  if (dotPos>0)
	  {
		  if (dotPos <= (ValeurInput.length - 3))
		  {
			  var Regex = new RegExp("^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$");		  
	    	  var Result = Regex.test(ValeurInput);
			  if (Result) {return false;}
			  else {return true;}
		   }	  
		   else 
		  {
		  	  return true;
		  }				
		}
		else 
		{
			return true;
		}
	}
}			

function Remplace(expr,a,b) 
{
 var i=0
    while (i!=-1) 
 {
     i=expr.indexOf(a,i);
        if (i>=0) 
  {
            expr=expr.substring(0,i)+b+expr.substring(i+a.length);
            i+=b.length;
         }
      }
      return expr
}

		
function MailFaux(ValeurInput)
{
  if (ValeurInput!='')
  {
	  dotPos = ValeurInput.indexOf('.');
	  if (dotPos>0)
	  {
		  if (dotPos <= (ValeurInput.length - 3))
		  {
			  var Regex = new RegExp("^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$");		  
	    	  var Result = Regex.test(ValeurInput);
			  if (Result) {return false;}
			  else {return true;}
		   }	  
		   else 
		  {
		  	  return true;
		  }				
		}
		else 
		{
			return true;
		}
	}
}			

function Remplace(expr,a,b) 
{
 var i=0
    while (i!=-1) 
 {
     i=expr.indexOf(a,i);
        if (i>=0) 
  {
            expr=expr.substring(0,i)+b+expr.substring(i+a.length);
            i+=b.length;
         }
      }
      return expr
}
