function FormValide(index)
{// Verifie si au moins un champ contient une valeur
	var form = document.forms[index]; // On récupere le formulaire à analyser
	var formValide = false;
	for (var index2= 0; index2 < document.forms[index].elements.length; index2++)
	{// Verifier si l'element contient quelque chose
		element = document.forms[index].elements[index2];
		if ((element.type != "hidden") && (element.type != "submit") && (element.type != "reset") && (element.type != "button") &&
		(element.value.length != 0))
		{// L'element contient une valeur. Donc le formulaire est valide
			formValide = true;
		}// L'element contient une valeur. Donc le formulaire est valide
	}// Verifier si l'element contient quelque chose
	
	return formValide;
}


function VerifierForm2(index)
{// Verifier le contenu d'un formulaire de type form2 (contribution)
	if (document.forms[index].elements['ContributorName'].value == "")
	{// Champ obligatoire absent
		alert ("Vous avez oublié d'indiquer votre nom");
		return -1;
	} 
	
	if (document.forms[index].elements['ContributorEmail'].value == "")
	{// Champ obligatoire absent
		alert ("Vous avez oublié d'indiquer votre e-mail");
		return -1;
	} 
	
	if (document.forms[index].elements['ContributionSubject'].value == "")
	{// Champ obligatoire absent
		alert ("Vous avez oublié d'indiquer un sujet");
		return -1;
	} 
	
	if (document.forms[index].elements['ContributionStoryPartCR'].value == "")
	{// Champ obligatoire absent
		alert ("Vous avez oublié de rédiger le récit");
		return -1;
	} 
	
	if (document.forms[index].elements['ContributionAnalysisPartCR'].value == "")
	{// Champ obligatoire absent
		alert ("Vous avez oublié de rédiger l'analyse");
		return -1;
	} 
	
	// Vérification des formats
	if (!document.forms[index].elements['ContributorEmail'].value.match(/.+@.+\.+/))
	{// Format mail incorrect
		alert ("Votre adresse mail est incorrecte");
		return -1;
	}// Format mail incorrect
	
	// On remplace les retour chariot par _CRLF_  dans le récit et l'analyse
	document.forms[index].elements['ContributionStoryPart'].value =
		document.forms[index].elements['ContributionStoryPartCR'].value.replace(/\n/g, "_CRLF_");
	document.forms[index].elements['ContributionAnalysisPart'].value =
		document.forms[index].elements['ContributionAnalysisPartCR'].value.replace(/\n/g, "_CRLF_");

	// Faire disparaitre les textarea
	document.forms[index].elements['ContributionStoryPartCR'].setAttribute("disabled", "disabled");
	document.forms[index].elements['ContributionAnalysisPartCR'].setAttribute("disabled", "disabled");
	
	
	return index;
}// Verifier le contenu d'un formulaire de type form2 (contribution)



function VerifierFormPubPayante(index)
{// Verifier le contenu d'un formulaire de type formPubPayante
	if (document.forms[index].elements['PubTitle'].value == "")
	{// Champ obligatoire absent
		alert ("Merci d'indiquer un titre à votre publicité");
		return -1;
	} 
	
	if (document.forms[index].elements['PubTexteCR'].value == "")
	{// Champ obligatoire absent
		alert ("Merci d'entrer un texte pour votre publicité");
		return -1;
	} 
	
	if (document.forms[index].elements['PersonEmail'].value == "")
	{// Champ obligatoire absent
		alert ("Merci d'indiquer votre mail");
		return -1;
	} 
	
	// Vérification des formats
	if (!document.forms[index].elements['PersonEmail'].value.match(/.+@.+\.+/))
	{// Format mail incorrect
		alert ("Votre adresse mail est incorrecte");
		return -1;
	}// Format mail incorrect
	
	if (document.forms[index].elements['PersonLastName'].value == "")
	{// Champ obligatoire absent
		alert ("Merci d'indiquer votre nom");
		return -1;
	} 
	
	if (document.forms[index].elements['PersonPhone'].value == "")
	{// Champ obligatoire absent
		alert ("Merci d'indiquer votre telephone");
		return -1;
	} 

	if ((document.forms[index].elements['PersonAddress'].value == "") &&
		(document.forms[index].elements['PersonAddress2'].value == ""))
	{// Champ obligatoire absent
		alert ("Merci d'indiquer votre adresse (rue, immeuble, nom de société, etc)");
		return -1;
	} 

	if (document.forms[index].elements['PersonCP'].value == "")
	{// Champ obligatoire absent
		alert ("Merci d'indiquer votre code postal");
		return -1;
	} 

	if (document.forms[index].elements['PersonTown'].value == "")
	{// Champ obligatoire absent
		alert ("Merci d'indiquer votre ville");
		return -1;
	} 

	// On remplace les retour chariot par _CRLF_  dans PubTexte
	document.forms[index].elements['PubTexte'].value =
		document.forms[index].elements['PubTexteCR'].value.replace(/\n/g, "_CRLF_");

	document.forms[index].elements['PubTexte'].value =
		document.forms[index].elements['PubTexte'].value.replace(/\r/g, "");

	return index;
}// Verifier le contenu d'un formulaire de type formPubPayante





function VerifierFormPubGratuite(index)
{// Verifier le contenu d'un formulaire de type PubGratuite
	if (document.forms[index].elements['PubTitle'].value == "")
	{// Champ obligatoire absent
		alert ("Merci d'indiquer un titre à votre publicité");
		return -1;
	} 
	
	if (document.forms[index].elements['PubTexteCR'].value == "")
	{// Champ obligatoire absent
		alert ("Merci d'entrer un texte pour votre publicité");
		return -1;
	} 
	
	if (document.forms[index].elements['PersonEmail'].value == "")
	{// Champ obligatoire absent
		alert ("Merci d'indiquer votre mail");
		return -1;
	} 
	
	// Vérification des formats
	if (!document.forms[index].elements['PersonEmail'].value.match(/.+@.+\.+/))
	{// Format mail incorrect
		alert ("Votre adresse mail est incorrecte");
		return -1;
	}// Format mail incorrect
	
	if (document.forms[index].elements['PersonLastName'].value == "")
	{// Champ obligatoire absent
		alert ("Merci d'indiquer votre nom");
		return -1;
	} 
	
	if (document.forms[index].elements['PersonPhone'].value == "")
	{// Champ obligatoire absent
		alert ("Merci d'indiquer votre telephone");
		return -1;
	} 

	// On remplace les retour chariot par _CRLF_  dans PubTexte
	document.forms[index].elements['PubTexte'].value =
		document.forms[index].elements['PubTexteCR'].value.replace(/\n/g, "_CRLF_");

	return index;
}// Verifier le contenu d'un formulaire de type PubGratuite


function VerifierFormLivreDOr(index)
{// Verifier le contenu d'un formulaire de type Livre d'or

	if (document.forms[index].elements['PersonName'].value == "")
	{// Champ obligatoire absent
		alert ("Merci d'indiquer votre prénom");
		return -1;
	} 

	if (document.forms[index].elements['PersonLastName'].value == "")
	{// Champ obligatoire absent
		alert ("Merci d'indiquer votre nom");
		return -1;
	} 

	if (document.forms[index].elements['PersonFonction'].value == "")
	{// Champ obligatoire absent
		alert ("Merci d'indiquer votre fonction");
		return -1;
	} 
	
	if (document.forms[index].elements['TemoignageCR'].value == "")
	{// Champ obligatoire absent
		alert ("Merci de saisir votre recommandation, témoignage, commentaire ou question");
		return -1;
	} 
	
	// Vérification des formats
	if ((document.forms[index].elements['PersonEmail'].value != "") && 
	(!document.forms[index].elements['PersonEmail'].value.match(/.+@.+\.+/)))
	{// Format mail incorrect
		alert ("Votre adresse mail est incorrecte");
		return -1;
	}// Format mail incorrect
	

	// On remplace les retours chariot par _CRLF_  dans PubTexte
	document.forms[index].elements['Temoignage'].value =
		document.forms[index].elements['TemoignageCR'].value.replace(/\n/g, "_CRLF_");

	return index;
}// Verifier le contenu d'un formulaire de type type Livre d'or





function ActiveTextAreas(index)
{
	// Faire disparaitre les textarea
	document.forms[index].elements['ContributionStoryPartCR'].removeAttribute("disabled");
	document.forms[index].elements['ContributionAnalysisPartCR'].removeAttribute("disabled");
}

function VerifierForm1(index)
{// Verifier le contenu d'un formulaire de type form1 (abonnement));
	if (document.forms[index].elements['Nom'].value == "")
	{// Champ obligatoire absent
		alert ("Vous avez oublié d'indiquer votre nom");
		return -1;
	} 
	
	if (document.forms[index].elements['Email'].value == "")
	{// Champ obligatoire absent
		alert ("Vous avez oublié d'indiquer votre e-mail");
		return -1;
	} 

	// Vérification des formats
	if (!document.forms[index].elements['Email'].value.match(/.+@.+\.+/))
	{// Format mail incorrect
		alert ("Votre adresse mail est incorrecte");
		return -1;
	}// Format mail incorrect	

	return index;
}// Verifier le contenu d'un formulaire de type form1 (abonnement)

function CtrlForm(idForm)
{
	var soumettre = -1;
	for (var index = 0; index < document.forms.length; index++)
	{// rechercher les formulaires valides
		if (FormValide(index))
		{// Le formulaire est valide. On verifie son contenu
			if ((document.forms[index].name == 'form1') && (idForm == 'form1'))
				soumettre = VerifierForm1(index);
			else if ((document.forms[index].name == 'form2') && (idForm == 'form2'))
				soumettre = VerifierForm2(index);
			else if ((document.forms[index].name == 'formPubPayante') && (idForm == 'formPubPayante'))
				soumettre = VerifierFormPubPayante(index);
			else if ((document.forms[index].name == 'PubGratuite') && (idForm == 'PubGratuite'))
				soumettre = VerifierFormPubGratuite(index);
			else if ((document.forms[index].name == 'fLivredor') && (idForm == 'fLivredor'))
				soumettre = VerifierFormLivreDOr(index);				
				

		}// Le formulaire est valide. On vérifie son contenu

        // alert(soumettre);  Pour DEBUGAGE only
		
		if (soumettre >= 0)
		{// On soumet le formulaire trouvé
			document.forms[soumettre].submit();
			ActiveTextAreas(soumettre);
		}// On soumet le formulaire trouvé
		
	}// rechercher les formulaires valides
	
}
