// JavaScript Document
function sendfriend_validation() 
{
	var elementFormulaire = document.getElementById("sendfriend_form");
	var nomAmi = document.getElementById("sendfriend_nomami");
	var sendfriend_email = document.getElementById("sendfriend_email");
	var sendfriend_emailami = document.getElementById("sendfriend_emailami");
	var commentaire = document.getElementById("sendfriend_commentaire");
	var bolValide = true;
	
	if (formActuel == false) 
	{
		//Form ami
		bolValide = sendfriend_checkmail(sendfriend_emailami);
		if(bolValide)
		{
			bolValide = sendfriend_checkmail(sendfriend_email);	
		}
	}
	else 
	{
		//Form admin
		bolValide = sendfriend_checkmail(sendfriend_email);
		//Form admin
		if (commentaire.value == "" && bolValide != false) 
		{
			alert(sendfriend_msg_message);
			commentaire.focus();
			bolValide = false;
		};
	};
	if(bolValide == true) 
	{
		if (sendfriend_emailami.disabled == true && nomAmi.disabled == true) 
		{
			sendfriend_emailami.disabled = false;
			nomAmi.disabled = false;
		};
		elementFormulaire.submit();
	};
};

function sendfriend_viderchamps(){
	var nom = document.getElementById("sendfriend_nom");
	nom.value = "";
	
	var nomAmi = document.getElementById("sendfriend_nomami");	
	nomAmi.value = "";
	
	var email = document.getElementById("sendfriend_email");
	email.value = "";
	
	var email_ami = document.getElementById("sendfriend_emailami");
	email_ami.value = "";
	
	var commentaire = document.getElementById("sendfriend_commentaire");
	commentaire.value = "";
}

function sendfriend_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 (sendfriend_msg_courrielinvalide);
		   email.focus();
           return false;
         }
       } 
     }
     if (!cnt)
     {
       alert (sendfriend_msg_courrielinvalide);    
	   email.focus();
       return false;
     }
	 return true;
}

function sendfriend_closewindow(strIDBloc) {
		sendfriend_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("sendfriend_form");
	var nomAmi = document.getElementById("sendfriend_nomami");
	var courrielAmi = document.getElementById("sendfriend_emailami");
	var elementTitre = document.getElementById("sendfriend_titreform");
	
	var email_lbl = document.getElementById("sendfriend_email_lbl");
	var commentaire_lbl = document.getElementById("sendfriend_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
		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;
};
