/**********************************************
* Verification du formulaire de l'inscription *
**********************************************/
function verif_attente() {
  var login=document.f_inscription.login.value;
  var nom=document.f_inscription.nom.value;
  var prenom=document.f_inscription.prenom.value;
  var pass1=document.f_inscription.pass1.value;
  var pass2=document.f_inscription.pass2.value;
  var fonction=document.f_inscription.fonction.value;
  var fct_precision=document.f_inscription.fct_precision.value;
  var adr_prof=document.f_inscription.adr_prof.value;
  var adr_prof_code=document.f_inscription.adr_prof_code.value;
  var adr_prof_ville=document.f_inscription.adr_prof_ville.value;
  var mail=document.f_inscription.mail.value;
 
  if ( login == '' ) {
    non_rempli("Nom d'utilisateur");
  } else if ( login.length<3) {
    nb_incorect("Nom d'utilisateur",3);
  } else if (!chaine(login)) {
    non_chaine("Nom d'utilisateur");
  } else if ( pass1=='') {
    non_rempli('Mot de passe');
  } else if ( pass1.length<5) {
    nb_incorect('Mot de passe',5);
  } else if (pass1!=pass2) {
    window.alert("Les mots de passes doivent être identiques");
  } else if (nom=='') {
    non_rempli('Nom');
  } else if ( !chaine(nom)) {
    non_chaine('Nom');
  } else if ( prenom == '' ) {
    non_rempli('Prénom');
  } else if ( !chaine(prenom) ) {
    non_chaine('Prénom');
  } else if ( mail == '' ) {
    non_rempli('E-mail');
  } else if ( !testEmail(mail) ) {
    window.alert("L'adresse e-mail n'est pas valide !");
  } else if ( fonction==0 ) {
    window.alert('Vous devez choisir votre fonction');
  } else if ( fonction=='Autre' && fct_precision=='' ) {
    window.alert('Vous devez préciser votre fonction.');
  } else if ( fonction=='Autre profession paramédicale' && fct_precision=='' ) {
    window.alert('Vous devez préciser votre fonction.');
  } else if ( adr_prof == '' ) {
    non_rempli("Lieu de l'adresse professionnelle");
  } else if ( adr_prof_code == '' ) {
    non_rempli("Code postal de l'adresse professionnelle");
  } else if ( isNaN(adr_prof_code) ) {
    non_nombre("Code postal de l'adresse professionnelle");
  } else if ( adr_prof_ville == '' ) {
    non_rempli("Ville de l'adresse professionnelle");
  } else {
    f_inscription.submit();
  }
}



/**************************************************
* Verification du formulaire de contact *
**************************************************/
function verif_mesaj() {
  var gonderen=document.f_mesaj.gonderen.value;
  var msg=document.f_mesaj.mesaj.value;
  var mail=document.f_mesaj.mail.value;

  if ( gonderen == '' ) {
    window.alert("Lütfen adınızı ve soyadınızı yazın !");
  } else if ( msg == '' ) {
    window.alert("Lütfen mesaj bölümünü doldurun !");
  } else if ( mail == '' ) {
    window.alert("Lütfen Email adresinizi yazın !");
  } else if (!testEmail(mail) ) {
    window.alert("Email adresi hatalı ! Lütfen Email adresinizi doğru yazın.");
  } else {
    f_mesaj.submit();
  }
}

/**************************************************
* Verification du formulaire de contact *
**************************************************/
function verif_defter() {
  var gonderen=document.f_defter.gonderen.value;
  var msg=document.f_defter.mesaj.value;
  var mail=document.f_defter.mail.value;

  if ( gonderen == '' ) {
    window.alert("Lütfen adınızı ve soyadınızı yazın !");
  } else if ( msg == '' ) {
    window.alert("Lütfen mesaj bölümünü doldurun !");
  } else if ( mail == '' ) {
    window.alert("Lütfen Email adresinizi yazın !");
  } else if (!testEmail(mail) ) {
    window.alert("Email adresi hatalı ! Lütfen Email adresinizi doğru yazın.");
  } else {
    f_defter.submit();
  }
}

/*****************************
* Differents types d'alertes *
******************************/

function nb_incorect(nom,nb) {
  window.alert("Le champ '" + nom + "' doit comporter au moins "+nb+" caractères.");
}
function non_rempli(champ) {
  window.alert("Le champ \'"+champ+"\' n\'est pas rempli !");
}
function non_nombre(champ) {
  window.alert("Le champ \'"+champ+"\' doit être un nombre !");
}
function non_positif(champ) {
  window.alert("Le champ \'"+champ+"\' doit être un nombre positif ou nul !");
}
function non_entierPositif(champ) {
  window.alert("Le champ \'"+champ+"\' doit être un entier positif ou nul !");
}
function non_chaine(champ) {
  window.alert("Le champ \'"+champ+"\' ne peut contenir que des caractères alphabétiques, numériques ou un tiret. L'espace n'est pas autorisé !");
}

/****************************************************************
* Teste si une chaine contient que des caracteres alphabetiques *
****************************************************************/
function chaine(valeur) {
  var test=true;
  if (valeur.search(/^[a-zA-Z0-9-_]*$/) == -1) test=false;
  return test;
}

/**************************************************
* Teste si un nombre est un entier positif ou nul *
**************************************************/
function entierPositif(valeur) {
  var test=true;
  if (valeur.search(/^[0-9]*$/) == -1) test=false;
  if (valeur < 0 ) test=false;
  return test;
}

/**************************************************************
* Teste si l'adreese email est valide, renvoie TRUE si valide *
**************************************************************/
function testEmail(valeur) {
  var test=false;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(valeur)) test=true;
  return test;
}  


