
function testMail(email)
{
  var posArobase;
  posArobase = email.indexOf("@");
  if (posArobase == -1) return false;
  var posPoint;
  posPoint = email.lastIndexOf(".");
  if ((posPoint == -1) || (posPoint < posArobase)) return false;
  return true;
}

function testrequis(nom)
{
  if (nom.lastIndexOf("R")==nom.length-2) return true;
  return false;
}

function ControlForm(nomForm)
{
	
  champ = nomForm.elements;
  nbr = champ.length;
  i=0;

  while (i<nbr)
  {
     testtemp=champ[i].type.substring(0,3);
	 if (testtemp=="tex")
     {
        if (testrequis(champ[i].name))
		{
		  	if (champ[i].value=="") 
          	{
            	window.alert ("Le champ "+champ[i].name.slice(0,-2)+" doit être renseigné");
            	champ[i].focus();
            	return false;
          	}
			
        	switch (champ[i].name.substr(champ[i].name.length-1))  
        	{
          		case "E" : 
					if (isNaN(champ[i].value))
				{
				  window.alert ("Le champ "+champ[i].name.slice(0,-2)+" doit être un nombre");
				  champ[i].value="";
				  champ[i].focus();
				  return false;
				}
				break;
          		case "M" : 
					if (!testMail(champ[i].value))
				{
				  window.alert ("Le champ "+champ[i].name.slice(0,-2)+" semble ne pas avoir le format nom@domaine.com");
				  champ[i].value="";
				  champ[i].focus();
				  return false;
				}
				break;
          		default :
        	}
		}
     }
	
    i++;
  }
	nomForm.submit();
	return nomForm;
}