/*
 * ERREUR LOGIN
 */

function errorNoLogin() {
  document.getElementById('erreur').style.display='block';
  document.getElementById('message').innerHTML = 'Tu dois d\'identifier!';
}

function errorAlreadyPlay() {
  document.getElementById('erreur').style.display='block';
  document.getElementById('message').innerHTML = 'Tu as d&eacute;j&agrave; particip&eacute;!';
}

function formLogOut() {
    document.form_deconnect.submit();
}
/*
 * MAIL
 */

function validEmailAmi() {
  if(document.formEnvoiAmi.email_1.value!="") {
    if(!checkMail(document.formEnvoiAmi.email_1.value)) {
      alert("Tu n'as pas saisi un email correct.");
      return false;
    }else{
      /*document.formEnvoiAmi.submit();*/
      return true;
    }
  }else{
    alert("Tu dois sasir l'email d'un(e) ami(e).");
    return false;
  }
}

function checkMail(str) {
	var verif = /^[a-zA-Z0-9\-\_]{1,}[a-zA-Z0-9\.\-\_]*[a-zA-Z0-9\-\_]{1,}@[a-zA-Z0-9]{1,}[a-zA-Z0-9\.\-\_]*[a-zA-Z0-9]{1,}[.][a-zA-Z]{2,4}$/;
	if(verif.test(str)) return true;
	else return false;
}

function envoieMailAmi() {
  var errors = 'Pour envoyer un email :\n'
  var areErrors = true;

  var val_mail1 = document.form_invite.mail1.value;
  var val_mail2 = document.form_invite.mail2.value;
  var val_mail3 = document.form_invite.mail3.value;
  var val_mail4 = document.form_invite.mail4.value;
  var val_mail5 = document.form_invite.mail5.value;
  var val_mail6 = document.form_invite.mail6.value;


  if(val_mail1=="" && val_mail2=="" && val_mail3=="" && val_mail4=="" && val_mail5=="" && val_mail6=="" ) {
     errors+="- Saisie au moins un email !!!\r";
     areErrors= false;
  }

  if((!checkMail(val_mail1) && val_mail1!="") || (!checkMail(val_mail2) && val_mail2!="") || (!checkMail(val_mail3) && val_mail3!="") || (!checkMail(val_mail4) && val_mail4!="") || (!checkMail(val_mail5) && val_mail5!="") || (!checkMail(val_mail6) && val_mail6!="") ) {
    errors+="- l'un des email n'est pas valide !!!\r";
    areErrors= false;
  }

  //retour
  if(!areErrors){
    alert(errors);
    return false;
  }else{
        document.form_invite.submit();
  }

}



/*
 * PARTICIPATION
 */
/*
function checkParticipation() {
  var errors = 'Pour participer :\n'
  var areErrors = true;
  val_photo = document.participer_prevalid.data_photo.value;
  //traitement photo
  if (val_photo.length != 0 && val_photo.substring(val_photo.lastIndexOf("."), val_photo.length).toLowerCase() != ".jpg" && val_photo.substring(val_photo.lastIndexOf("."), val_photo.length).toLowerCase() != ".png" ) {
    errors+="\n- ta photo doit etre au format JPEG ou PNG.";
    areErrors= false;
  }  
  //retour
  if(!areErrors){
    alert(errors);
    return false;
  }else{
        document.participer.submit();
  }
}
*/
function preParticipation($message) {
    if(document.participer_prevalid.conditions.checked==true) {
      document.participer_prevalid.submit();
    }else{
      alert($message);
      return false;
    }     
}

function validParticipation() {
    /*if(document.form_participer_photo.conditions.checked==true) {*/
      document.form_participer_photo.submit();
    /*}else{
      alert("Tu dois cocher la case pour confirmer que tu as prit connaissance du règlement du jeu concours GARNIER PURE.");
      return false;
    } 
    */
}


//ERREUR IMG
function errorFormatImg() {
  document.getElementById('erreur').style.display='block';
  document.getElementById('message').innerHTML = 'Format image KO !';
}



