// JavaScript Document

function validation2(){
	if(document.pasuser.nom.value==""){
		//alert("Inscrivez votre nom")
		//document.pasuser.nom.focus()
		//return;
		}
	if (document.pasuser.email.value==""){
		//alert("Entrez votre adresse de courriel")
		//document.pasuser.email.focus()
		//return;
	}else {
		var bon
		var email  = document.pasuser.email.value
		bon = checkmail(email.length,email)
		if (bon==false){
		document.pasuser.email.focus()
		return;
		}
	}
	if (document.pasuser.nomami.value=="") {
		//alert("Entrez le nom de la personne à qui vous voulez envoyer cette page")
		//document.pasuser.nomami.focus()
		//return;
		}
	if (document.pasuser.emailami.value =="" ){
		alert("Entrez l'adresse de courriel de la personne à qui vous voulez envoyer cette page")
		document.pasuser.emailami.focus()
		return;
	}else {
		var bon
		var email  = document.pasuser.emailami.value
		bon = checkmail(email.length,email)
		if (bon==false){
		document.pasuser.emailami.focus()	
		return;
		}
		}
	document.pasuser.submit()
}

function valider3() {
	var elementFormulaire = document.getElementById("pasuser");
	var nomAmi = document.getElementById("nomami");
	var email = document.getElementById("email");
	var emailami = document.getElementById("emailami");
	var commentaire = document.getElementById("commentaire");
	var bolValide = true;
	
	if (formActuel == false) {
		//Form ami
		bolValide = checkmail(emailami);
		if(bolValide)
		{
			bolValide = checkmail(email);	
		}
	}
	else {
		//Form admin
		bolValide = checkmail(email);
	
		//Form admin
		if (commentaire.value == "" && bolValide != false) {
			alert("Veuiller entrer un message");
			commentaire.focus();
			bolValide = false;
		};
	};
	if(bolValide == true) {
		if (emailami.disabled == true && nomAmi.disabled == true) {
			emailami.disabled = false;
			nomAmi.disabled = false;
		};
		elementFormulaire.submit();
	};
};

function viderchamps(){
	var nom = document.getElementById("nom");
	nom.value = "";
	
	var nomAmi = document.getElementById("nomami");	
	nomAmi.value = "";
	
	var email = document.getElementById("email");
	email.value = "";
	
	var email_ami = document.getElementById("emailami");
	email_ami.value = "";
	
	var commentaire = document.getElementById("commentaire");
	commentaire.value = "";
}

function checkmail(email){
var cnt = 0;
for (var i=0; i<email.value.length; i++)
     {
       var oneChar = email.value.charAt(i);
       if (oneChar == '@')
       {
         if (cnt == 0)
         {
           cnt++;
         }
         else
         {
           alert ("Courriel invalide");
		   email.focus();
           return false;
         }
       } 
     }
     if (!cnt)
     {
       alert ("Courriel invalide");    
	   email.focus();
       return false;
     }
	 return true;
	 }
function closewindow(strIDBloc) {
		viderchamps();
		var elementBloc = document.getElementById(strIDBloc);
		elementBloc.style.display = "none";

	}
	
function showcomplementaires(showhide){
		var hidecomplementaire = document.getElementById("hidecomplementaire");
		var showhide = document.getElementById("showhide");
		
		if (showhide.value == "false"){
			hidecomplementaire.style.display ="inline";	
			showhide.value = "true";			
		}
		else{
			hidecomplementaire.style.display ="none";	
			showhide.value = "false";			
		};
};
	
function displayorhideblock(strIDBloc, bolChampPreRempli) {
	var elementBloc = document.getElementById(strIDBloc);
	var elementFormulaire = document.getElementById("pasuser");
	var nomAmi = document.getElementById("nomami");
	var courrielAmi = document.getElementById("emailami");
	var elementTitre = document.getElementById("titreform");
	
	var email_lbl = document.getElementById("email_lbl");
	var commentaire_lbl = document.getElementById("commentaire_lbl");
	
	var nodeTexte;
	
	if (formActuel == "init" || elementBloc.style.display == "none") {
		elementBloc.style.display = "block";
	}
	else {
		if (formActuel == bolChampPreRempli) {
			if (elementBloc.style.display == "block") {
				elementBloc.style.display = "none";
			}
			else {
				elementBloc.style.display = "block";
			};
		};
	};
	
	//elementTitre.childNodes[0].removeChild(elementTitre.childNodes[0].firstChild);
	if (bolChampPreRempli) {
		//Formulaire admin
		elementTitre.childNodes[0].appendChild(document.createTextNode(strTitre2));
		
		courrielAmi.parentNode.style.display = "none";
		nomAmi.parentNode.style.display = "none";
		
		courrielAmi.value = "[Administrateur]";
		nomAmi.value = "[Administrateur]";
		
		courrielAmi.disabled = true;
		nomAmi.disabled = true;
		
		if (email_lbl.firstChild.nodeValue.indexOf("*") == -1) {
			nodeTexte = document.createTextNode("* " + email_lbl.firstChild.nodeValue);
			email_lbl.removeChild(email_lbl.childNodes[0]);
			email_lbl.appendChild(nodeTexte);
			
			nodeTexte = document.createTextNode("* " + commentaire_lbl.firstChild.nodeValue);
			commentaire_lbl.removeChild(commentaire_lbl.childNodes[0]);
			commentaire_lbl.appendChild(nodeTexte);
		};
	}
	else {
		//Formulaire ami
		//elementTitre.childNodes[0].appendChild(document.createTextNode(strTitre1));
		
		courrielAmi.value = "";
		nomAmi.value = "";
		
		courrielAmi.parentNode.style.display = "block";
		nomAmi.parentNode.style.display = "block";
		
		courrielAmi.disabled = false;
		nomAmi.disabled = false;
		
		if (email_lbl.firstChild.nodeValue.indexOf("*") != -1) {
			nodeTexte = document.createTextNode(email_lbl.firstChild.nodeValue.substring(2,email_lbl.firstChild.nodeValue.length));
			email_lbl.removeChild(email_lbl.childNodes[0]);
			email_lbl.appendChild(nodeTexte);
			
			nodeTexte = document.createTextNode(commentaire_lbl.firstChild.nodeValue.substring(2,commentaire_lbl.firstChild.nodeValue.length));
			commentaire_lbl.removeChild(commentaire_lbl.childNodes[0]);
			commentaire_lbl.appendChild(nodeTexte);
		};
	};
	formActuel = bolChampPreRempli;
};
