/*
 * LOGIN
 */
function checkFormLogin() {
  var errors = 'Attention tu dois saisir :\n'
  var areErrors = true;
  if(document.form_log.pseudo.value == '' ) {
    errors += '\n- ton pseudo.';
    areErrors = false;
  } 
  if(document.form_log.password.value == '' ) {
    errors += '\n- ton mot de passe.';
    areErrors = false;
  }
  //retour
  if(!areErrors){
    alert(errors);
  }else{
     if(document.form_log.conditions.checked==false) {
      alert("tu dois accepter le règlement pour pouvoir participer !.");
    }else{
      document.form_log.submit();
    }
  }
}
function checkFormLogin2() {
  var errors = 'Attention tu dois saisir :\n'
  var areErrors = true;
  if(document.form_log2.pseudo.value == '' ) {
    errors += '\n- ton pseudo.';
    areErrors = false;
  } 
  if(document.form_log2.password.value == '' ) {
    errors += '\n- ton mot de passe.';
    areErrors = false;
  }
  //retour
  if(!areErrors){
    alert(errors);
  }else{
    document.form_log2.submit();
  }
}
/*
 * LOGOUT
 */
function formLogOut() {
    document.form_deconnect.submit();
}

function checkParticipation() {
  var errors = 'Pour participer tu dois :\n';
  var areErrors = true;
  val_title = document.participer.data_title.value;
  val_sound = document.participer.data_sound.value;
  val_loggue = document.participer.loggue.value
  if(val_loggue != 1){
    alert("Tu dois être identifié pour participer !");
    return false;
  }
  if (val_title == '' ) {
    errors+="\n - Tu dois saisir un titre !";
    areErrors= false;    
  }  
  if (val_sound == '' || val_sound.length != 0 && val_sound.substring(val_sound.lastIndexOf("."), val_sound.length).toLowerCase() != ".mp3" ) {
    errors+="\n - Tu dois selectionner un fichier mp3 !";
    areErrors= false;    
  }  
  //retour
  if(!areErrors){
    alert(errors);
    //return false;
  }else{
        document.participer.submit();
  }
}

function checkParticipationPhoto() {
  var errors = 'Pour participer :\n'
  var areErrors = true;
  val_photo = document.participer_photo.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);
  }else{
        document.participer_photo.submit();
  }
}


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 envoieMailAmi() {
  var errors = 'Pour envoyer un email :\n'
  var areErrors = true;

  var val_email_1 = document.form_envoi_ami.email_1.value;
  var val_email_2 = document.form_envoi_ami.email_2.value;
  var val_email_3 = document.form_envoi_ami.email_3.value;
  var val_email_4 = document.form_envoi_ami.email_4.value;

  if(val_email_1=="" && val_email_2=="" && val_email_3=="" && val_email_4=="") {
     errors+="- Saisie au moins un email !!!\r";
     areErrors= false;
  }

  if((!checkMail(val_email_1) && val_email_1!="") || (!checkMail(val_email_2) && val_email_2!="") || (!checkMail(val_email_3) && val_email_3!="") || (!checkMail(val_email_4) && val_email_4!="") ) {
    errors+="- l'un des email n'est pas valide !!!\r";
    areErrors= false;
  }

  //retour
  if(!areErrors){
    alert(errors);
    //return false;
  }else{
        document.form_envoi_ami.submit();
  }
}
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;
}




/* ON GARDE CE QU'IL Y A AU DESSUS ^^^^^ */









/*
 *  PARTICIPATION PHOTO
 */
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;
    } 
    */
}
/*
 *  OUVRIR LA PARTICIPATION
 */
function openParticipation(url) {
    var url = 'participer_'+url+'.php';
    if(document.form_participer_photo.conditions.checked==true) {
      //document.form_participer_photo.submit();
      document.location.href=url;
    }else{
      alert("Tu dois cocher la case pour confirmer que tu as pris connaissance du règlement du jeu concours GARNIER PURE.");
      //return false;
    }  
}

/*
 * COMMENTAIRES
 */

function validCommentaire() {
  var errors = 'Pour valider ta participation :\n'
  var areErrors = true;
  var val_id_skynaute = document.form_commentaire.id_skynaute.value;
  var val_comm = document.form_commentaire.commentaire.value;
  
  if(val_id_skynaute.length == 0 ) {
    errors+="\n- tu dois être identifié.";
    areErrors= false;    
  }

  if(val_comm.length > 75 ) {
    errors+="\n- ton comm dépasse 75 caractères.";
    areErrors= false;
  }
  //retour
  if(!areErrors){
    alert(errors);
    return false;
  }else{
    document.form_commentaire.submit();
  }
}




/*
 * MAIL
 */



/*******************************************************************************************/

/*
 *  MODIFICATION
 */
function validModification() {
  var errors = 'Pour valider ta participation :\n'
  var areErrors = true;
  val_titre = document.form_modification.titre.value;
  val_texte_1 = document.form_modification.texte_1.value;
  val_texte_2 = document.form_modification.texte_2.value;
  val_texte_3= document.form_modification.texte_3.value;
  val_photo_1 = document.form_modification.photo_1.value;
  val_photo_2 = document.form_modification.photo_2.value;
  val_photo_3 = document.form_modification.photo_3.value;
  val_presentation = document.form_modification.presentation.value;
  /*val_action = document.form_participation.action_form.value;*/
  // traitement titre_1 et texte_1
  if(val_titre.length == 0 ) {
    errors+="\n- tu dois saisir un titre.";
    areErrors= false;
  }
  if(val_titre.length > 100 ) {
    errors+="\n- ton titre dépasse 100 caractères.";
    areErrors= false;
  }
  if(val_texte_1.length == 0 ) {
    errors += '\n- tu dois saisir une histoire.';
    areErrors = false;
  }
  if(val_texte_1.length > 500 ) {
    errors += '\n- ton histoire dépasse les 500 caractères.';
    areErrors = false;
  }
  //traitement texte_2
  if(val_texte_2.length > 500 ) {
    errors += '\n- ton histoire 2 dépasse les 500 caractères.';
    areErrors = false;
  }
  //traitement texte_3
  if(val_texte_3.length > 500 ) {
    errors += '\n- ton histoire 3 dépasse les 500 caractères.';
    areErrors = false;
  }
  //traitement photo_2  
  if (val_photo_2.length != 0 && val_photo_2.substring(val_photo_2.lastIndexOf("."), val_photo_2.length).toLowerCase() != ".jpg") {
    errors+="\n- ta photo (2) doit etre au format JPEG.";
    areErrors= false;
  }  
  //traitement photo_3  
  if (val_photo_3.length != 0 && val_photo_3.substring(val_photo_3.lastIndexOf("."), val_photo_3.length).toLowerCase() != ".jpg") {
    errors+="\n- ta photo (3) doit etre au format JPEG.";
    areErrors= false;
  }  
  //traitement presentation
  if(val_presentation.length > 150 ) {
    errors += '\n- ta présentation dépasse les 150 caractères.';
    areErrors = false;
  }
  //retour
  if(!areErrors){
    alert(errors);
  }else{
    if(document.form_modification.conditions.checked==false) {
      alert("Pour valider tes modifications, tu dois accepter le règlement.");
    }else{
      question = "Attention : Chaque nouvelle modification entraîne la remise à zéro du nombre de votes en ta faveur et ton défi doit repasser en modération !!!\rEs-tu sûre de vouloir modifier ton défi ?";
      if(confirm(question)){
        document.form_modification.submit();
      }
    }
  }
}


/*
 *  SUUPRIME
 */


function supprimePhoto3() {
  val1 = document.form_modification.supp_photo_3.checked;
  if (val1 == 1) {
    /*alert(val);*/
    Hide("photo3");
  } else {
    /*alert('nonon');*/
    Show("photo3");
  }
}
function supprimePhoto2() {
  val2 = document.form_modification.supp_photo_2.checked;
  if (val2 == 1) {
    /*alert(val);*/
    Hide("photo2");
  } else {
    /*alert('nonon');*/
    Show("photo2");
  }
}


var id;
function Show(id){
	if (document.all){
		var pathlay = document.all[id];
		//window.alert(111);
	} else if (document.getElementById){
		var pathlay = document.getElementById(id);
		//window.alert(id);
	}
	pathlay.style.display="block";
}
function Hide(id){
	if (document.all){
		var pathlay = document.all[id];
		//window.alert(111);
	} else if (document.getElementById){
		var pathlay = document.getElementById(id);
		//window.alert(222);
	}
	pathlay.style.display="none";
}
/* ******************************
/* FONCTION PREVENIR/POSTER UN COMMENTAIRE */
/* ******************************
*/
var id;

function ShowMsg(id){
	if (document.all){
		var pathlay = document.all[id];
		//window.alert(111);
	} else if (document.getElementById){
		var pathlay = document.getElementById(id);
		//window.alert(id);
	}
	pathlay.style.display="block";
}



function HideMsg(id){
	if (document.all){
		var pathlay = document.all[id];
		//window.alert(111);
	} else if (document.getElementById){
		var pathlay = document.getElementById(id);
		//window.alert(222);
	}
	pathlay.style.display="none";
}


var TabStorys = new Array();
TabStorys[0] = "1";
TabStorys[1] = "2";
var ActualNbStorys = 0;

function AddStorys(){
  if(ActualNbStorys<TabStorys.length){
    ShowMsg("addStory"+TabStorys[ActualNbStorys]);		
  }
	
  ActualNbStorys++;
  if(ActualNbStorys==TabStorys.length){
    HideMsg("btnaddstorys");
  }
}

var cnt = new Array();
cnt[0] = "1";
cnt[1] = "2";
var ActualCnt = 0;

function DisplayBlock1(){	
  ShowMsg("compteur1");
}

function DisplayNone1(){	
  HideMsg("compteur1");
}
function DisplayBlock2(){	
  ShowMsg("compteur2");
}

function DisplayNone2(){	
  HideMsg("compteur2");
}

function Vider (){
  if(document.text1.value!="") {
    alert("ALERTEEEEEE");
    //document.text1.value='';		
  }	
}

