function GetMsg(champs)
{
	var txt="";
	switch (champs)
	{
		case "NomRS" : txt = "Name"
		break;
		case "TitreXS" : txt = "Title"
		break;
		case "SocieteRS" : txt = "Company"
		break;
		case "AdresseXS" : txt = "Adress"
		break;
		case "VilleXS" : txt = "City"
		break;
		case "Province_EtatRS" : txt = "State / Province"
		break;
		case "CodePostalXS" : txt = "Post code"
		break;
		case "PaysXS" : txt = "Country"
		break;
		case "TelephoneRS" : txt = "Phone"
		break;
		case "TelecopieurRS" : txt = "Fax"
		break;
		case "CourrielXM" : txt = "E-mail"
		break;
		case "Description_CommentairesRS" : txt = "Description / Comments"
		break;
	}
	return txt;
}

// vérifier la validité du format de l'adresse e-mail (un @ + un point dans l'adresse)
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;
}

// vérifier si on a entré que des blancs
function testspaces(val)
{
  	var nb = val.length;

	for(var i=0; i<nb; i++) {
  		if (val.charAt(i) != ' ') return true;
  	}
  	return false;
}

// vérifier d'après le nom du champ si ce champ est requis obligatoirement
// le repère est la lettre R à l'avant dernière position dans le nom du champ 
function testrequis(nom)
{
  if (nom.lastIndexOf("R")==nom.length-2) return true;
  return false;
}

// fonction qui teste la validité de chaque champ
function testForm(nomForm)
{
  champ=nomForm.elements;
  nbr = champ.length;  // nombre de champs à vérifier
  i=0;
  while (i<nbr)
  {
        if (testrequis(champ[i].name)) 
        {
          if (champ[i].value=="" || !testspaces(champ[i].value)) 
          {
            window.alert ("The field " + GetMsg(champ[i].name) + " must be indicated");
            champ[i].focus();
            return false;
          }
        }
        // la dernière lettre du nom du champ indique le type de donnée
	switch (champ[i].name.substr(champ[i].name.length-1))  // dernière lettre du champ champ[i].name
        {
          case "N" : // N = numérique
            if (!testNumerique(champ[i].value))
            {
              window.alert ("The field "+ GetMsg(champ[i].name) +" must be a number");
              champ[i].focus();
              return false;
            }
			break;
          case "E" : // E = entier
            if (!testEntier(champ[i].value))
            {
              window.alert ("The field "+GetMsg(champ[i].name)+" must be an integer");
              champ[i].focus();
              return false;
            }
			break;
          case "M" : // M = mail
            if (champ[i].value != "" && !testMail(champ[i].value))
            {
              window.alert ("The field "+GetMsg(champ[i].name)+" seems not to have the format name@domain.com");
              champ[i].focus();
              return false;
            }
			break;
          case "D" : // D = date
            if (!isDate(champ[i].value))   
            {
              window.alert ("The field "+GetMsg(champ[i].name)+" seems not to have the format mm/dd//yyyy");
              champ[i].focus();
              return false;
            }
			break;
          default :
           
        }
    i++;
  }
  return true;
}



