
// Début du script sur la vérification des champs saisis par le participant -->
function verifier_inscription() {
  // Entreprise -->
  if (document.inscription.nom.value == "") {
     alert("Vous n'avez pas inscrit un nom d'entreprise.");
     document.inscription.nom.focus();
     return false;
  }		
  // Representant -->
  if (document.inscription.rep.value == "") {
     alert("Vous n'avez pas inscrit un représentant.");
     document.inscription.rep.focus();
     return false;
  }
  // Stand -->
  if (document.inscription.s1.value == "") {
     alert("Vous n'avez pas inscrit le nom d'au moin une personne présente à l'intérieur du Stand.");
     document.inscription.s1.focus();
     return false;
  }
  // Kiosques Vin -->
  if (document.inscription.kiosquesv.value == "") {
     alert("Vous n'avez pas inscrit le nombre de kiosques.");
     document.inscription.kiosquesv.focus();
     return false;
  }
  // Kiosques -->
  if (document.inscription.kiosques.value == "") {
     alert("Vous n'avez pas inscrit le nombre de kiosques.");
     document.inscription.kiosques.focus();
     return false;
  }
  // Courriel -->
  if (document.inscription.email.value != "") {
     if (!valider_courriel(document.inscription.email.value)) {
        alert("Le courriel est invalide.");
        document.inscription.email.focus();
        return false;
     }
  }
  else {
        alert("Vous n'avez pas inscrit votre courriel.");
        document.inscription.email.focus();
        return false;
  }
  // Téléphone -->
  if (document.inscription.phone.value == "") {
     alert("Vous n'avez pas inscrit votre numéro de téléphone.");
	 document.inscription.phone.focus();
     return false;
  }
  // Adresse #1 -->
  if (document.inscription.addr.value == "") { 
	 alert("Vous n'avez pas inscrit votre adresse.");
	 document.inscription.addr.focus();
     return false;
  }
  // Ville -->
  if (document.inscription.ville.value == "") { 
	 alert("Vous n'avez pas inscrit votre ville.");
	 document.inscription.ville.focus();
     return false;
  }
  // Code postal -->
  if (document.inscription.cp.value == "") { 
	 alert("Vous n'avez pas inscrit votre code postal.");
	 document.inscription.cp.focus();
     return false;
  }
  else {
        if (!valider_code_postal(document.inscription.cp.value)) {
	       alert("Votre code postal est invalide. Le format du code postal doit être composé de six caractères : J9P2B5.");
	       document.inscription.cp.focus();
           return false;
        }
  }
  // Région -->
  if (document.inscription.province.value == "") {
     alert("Vous n'avez pas inscrit votre province.");
     document.inscription.province.focus();
     return false;
  } 
}

// Validation du courriel -->
function valider_courriel(courriel) {
  if (courriel.indexOf("@") == -1 ||
     courriel.indexOf("@",courriel.indexOf("@") + 1) != -1 ||
     courriel.indexOf(".") == -1 ||
     courriel.indexOf(" ") != -1 ||
     courriel.indexOf("\\") != -1 ||
     courriel.indexOf("(") != -1 ||
     courriel.indexOf(")") != -1 ||
     courriel.indexOf("<") != -1 ||
     courriel.indexOf(">") != -1 ||
     courriel.indexOf("[") != -1 ||
     courriel.indexOf("]") != -1 ||
     courriel.indexOf(":") != -1 ||
     courriel.indexOf(";") != -1 ||
     courriel.indexOf("é") != -1 ||
     courriel.indexOf("ç") != -1 ||
     courriel.indexOf("è") != -1 ||
     courriel.indexOf("à") != -1 ||
     courriel.indexOf("ê") != -1 ||
     courriel.indexOf("*") != -1 ||
     courriel.indexOf("?") != -1 ||
     courriel.indexOf("%") != -1 ||
     courriel.indexOf("&") != -1 ||
     courriel.indexOf("$") != -1 ||
     courriel.indexOf("!") != -1 ||
     courriel.length < 6) {
     return false;}
  else {
     var str = new String(courriel.substring(courriel.indexOf(".") + 1,courriel.length));
     if (str.length < 2) 
        return false;
     else 
        return true;
  }
}

// Validation du code postal -->
function valider_code_postal(code_postal) {
  if (code_postal.length > 7)
     return false;
  if (code_postal.length <= 6) {
    if ((valider_numero(code_postal.charAt(0))) ||
       (!valider_numero(code_postal.charAt(1))) ||
       (valider_numero( code_postal.charAt(2))) ||
       (!valider_numero(code_postal.charAt(3))) ||
       (valider_numero( code_postal.charAt(4))) ||
       (!valider_numero(code_postal.charAt(5))) ) 
	   return false;
    else return true;
    }
  else {
    if ((valider_numero(code_postal.charAt(0))) ||
       (!valider_numero(code_postal.charAt(1))) ||
       (valider_numero( code_postal.charAt(2))) ||
       (code_postal.charAt(2) == " ") ||
       (!valider_numero(code_postal.charAt(4))) ||
       (valider_numero( code_postal.charAt(5))) ||
       (!valider_numero(code_postal.charAt(6))) )
	   return false;
    else return true;
  }
}

// Validation des numéros -->
function valider_numero(theItem) {
  for (i = 0;i <= theItem.length; i++) {
      retour = theItem.substring(i - 1,theItem.length);
      caractere = retour.substring(0,1);
      floatValue = parseFloat(caractere);
      if (isNaN(floatValue)){
         return false;
      }
  }
  return true;
} 
