/**
* Fonctions de controle et de validation de chacun des formulaires
*/

function validNewsletter(form)
{
	if (EstVide(form.email.value, 'Entrez votre e-mail') || !IsMail(form.email.value)) {
		alert("Veuillez saisir une adresse correcte");
		form.email.focus();
		return false;
	}
	return true;
}

function validSouscription(form)
{
	var check1  = false;
	var check2  = false;
	var msg = "Veuillez remplir les champs correctement";
	if (form.civilite.value == 0) {
		alert(msg); 
		form.civilite.focus();
		return false;
	}
	if (EstVide(form.firstname.value, 'Votre nom')) {
		alert(msg); 
		form.firstname.focus();
		return false;
	}
	if (EstVide(form.surname.value, 'Prenom')) {
		alert(msg); 
		form.surname.focus();
		return false;
	}
	if (EstVide(form.address.value, 'votre adresse...')) {
		alert(msg); 
		form.address.focus();
		return false;
	}
	if (EstVide(form.cp.value, 'Code postal') || !IsNumeric(form.cp.value)) {
		alert(msg); 
		form.cp.focus();
		return false;
	}
	if (EstVide(form.teldom.value, 'Telephone') || !IsNumeric(form.teldom.value)) {
		alert(msg); 
		form.teldom.focus();
		return false;
	}
	// facultatif
	if (!EstVide(form.telgsm.value, 'Tel gsm') && !IsNumeric(form.telgsm.value)) {
		alert(msg); 
		form.telgsm.focus();
		return false;
	}
	// facultatif
	if (!EstVide(form.telpro.value, 'Tel pro') && !IsNumeric(form.telpro.value)) {
		alert(msg); 
		form.telpro.focus();
		return false;
	}
	if (EstVide(form.email.value, 'email') || !IsMail(form.email.value)) {
		alert(msg); 
		form.email.focus();
		return false;
	}
	if (form.pieceid.value == 0) {
		alert(msg); 
		form.pieceid.focus();
		return false;
	}
	if (EstVide(form.numpiece.value, 'Numero de la piece')) {
		alert(msg); 
		form.numpiece.focus();
		return false;
	}
	if (EstVide(form.deliv.value, 'date et lieu de delivrance')) {
		alert(msg); 
		form.deliv.focus();
		return false;
	}
	if (EstVide(form.expire.value, 'expire le')) {
		alert(msg); 
		form.expire.focus();
		return false;
	}
	// facultatif
	if (!IsEmpty(form.numenfants.value) && !IsNumeric(form.numenfants.value)) {
		alert(msg); 
		form.numenfants.focus();
		return false;
	}
	if (form.habitat.value == 0) {
		alert(msg);
		form.habitat.focus();
		return false;
	}
	// Choix du bouquet
	if (form.idbouquet.value == 0) {
		alert(msg); 
		form.idbouquet.focus();
		return false;
	}
	// Test si une option sélectionnée (Bouton radio)
	for (i=0; i<form.condition.length; i++) {
		if(form.condition[i].checked) check1 = true;
	}
	if (!check1) {
		alert(msg); 
		form.condition[0].focus();
		return false;
	}
	if (!form.cgvcheck.checked) {
		alert ("Vous devez accepter les CGV si vous souhaitez poursuivre la souscription");
		form.cgvcheck.focus();
		return false;
	}
	if (erreur){
		alert(msg);
		return false;
	}
	return true;
}

function validConseiller(form)
{
	var msg = "Veuillez remplir les champs correctement";
	var check  = false;
	if (form.probleme.value == 0) {
		alert(msg); 
		form.probleme.focus();
		return false;
	}
	if (form.probleme.value == 'AUTRES' && form.comments.value == "Autres...") {
		alert(msg); 
		form.comments.focus();
		return false;
	}
	if (EstVide(form.firstname.value, 'Nom')) {
		alert(msg); 
		form.firstname.focus();
		return false;
	}
	if (EstVide(form.surname.value, 'Prenom')) {
		alert(msg); 
		form.surname.focus();
		return false;
	}
	if (EstVide(form.telephone.value, 'Telephone') || !IsNumeric(form.telephone.value)) {
		alert(msg); 
		form.telephone.focus();
		return false;
	}
	if (EstVide(form.email.value, 'email') || !IsMail(form.email.value)) {
		alert(msg); 
		form.email.focus();
		return false;
	}
	// Test si une option sélectionnée (Bouton radio)
	for (i=0; i<form.heure.length; i++) {
		if(form.heure[i].checked) check = true;
	}
	if (!check) {
		alert(msg); 
		form.heure[0].focus();
		return false;
	}
	return true;
}

function validSearch(form)
{
	var msg = "Vous devez saisir au moins un critere pour effectuer une recherche";
	var check  = false;
	
	if (EstVide(form.titre.value, 'chercher selon titre') && form.channel.value == -1 && form.subtype.value == -1) {
		alert(msg); 
		form.titre.focus();
		return false;
	}
	return true;
}

function validPrevenir(form)
{
	var msg = "Veuillez remplir les champs correctement";
	var check  = false;
	
	if (EstVide(form.email.value, 'Entrez votre email') || !IsMail(form.email.value)) {
		alert(msg); 
		form.email.focus();
		return false;
	}
	if (EstVide(form.mailami.value, 'Email destinataire') || !IsMail(form.mailami.value)) {
		alert(msg); 
		form.mailami.focus();
		return false;
	}
	return true;
}

function validAlerter(form)
{
	var msg = "Veuillez remplir les champs correctement";
	var check  = false;

	// Test si une option sélectionnée (Bouton radio)
	for (i=0; i<form.heure.length; i++) {
		if(form.heure[i].checked) check = true;
	}
	if (!check) {
		alert(msg); 
		form.heure[0].focus();
		return false;
	}
	
	if (EstVide(form.email.value, 'Entrez votre email') || !IsMail(form.email.value)) {
		alert(msg); 
		form.email.focus();
		return false;
	}
	return true;
}

function validSavoirplus(form)
{
	var msg = "Veuillez remplir les champs correctement";
	var check  = false;
	
	if (EstVide(form.firstname.value, 'Votre nom')) {
		alert(msg); 
		form.firstname.focus();
		return false;
	}
	/*if (EstVide(form.surname.value, 'Prenom')) {
		alert(msg); 
		form.email.focus();
		return false;
	}*/
	if (EstVide(form.telephone.value, 'Telephone') || !IsNumeric(form.telephone.value)) {
		alert(msg); 
		form.telephone.focus();
		return false;
	}
	// Test si une option sélectionnée (Bouton radio)
	/*for (i=0; i<form.heure.length; i++) {
		if(form.heure[i].checked) check = true;
	}
	if (!check) {
		alert(msg); 
		form.heure[0].focus();
		return false;
	}*/
	return true;
}

function validRenseignement(form)
{
	var msg = "Veuillez remplir les champs correctement";
	var check  = false;
	if (form.probleme.value == 0) {
		alert(msg); 
		form.probleme.focus();
		return false;
	}
	if (form.probleme.value == 'AUTRES' && form.comments.value == "Autres...") {
		alert(msg); 
		form.comments.focus();
		return false;
	}
	if (EstVide(form.firstname.value, 'Nom')) {
		alert(msg); 
		form.firstname.focus();
		return false;
	}
	if (EstVide(form.surname.value, 'Prenom')) {
		alert(msg); 
		form.surname.focus();
		return false;
	}
	if (EstVide(form.telephone.value, 'telephone') || !IsNumeric(form.telephone.value)) {
		alert(msg); 
		form.telephone.focus();
		return false;
	}
	if (EstVide(form.email.value, 'email') || !IsMail(form.email.value)) {
		alert(msg); 
		form.email.focus();
		return false;
	}
	// Test si une option sélectionnée (Bouton radio)
	/*for (i=0; i<form.heure.length; i++) {
		if(form.heure[i].checked) check = true;
	}
	if (!check) {
		alert(msg); 
		form.email.focus();
		return false;
	}*/
	return true;
}

function validFaq(form)
{
	var msg = "Veuillez remplir les champs correctement";
	if (IsEmpty(form.comments.value)) {
		alert(msg); 
		form.comments.focus();
		return false;
	}
	if (EstVide(form.email.value, 'Votre e-mail') || !IsMail(form.email.value)) {
		alert(msg); 
		form.email.focus();
		return false;
	}
	return true;
}

function validNewsavantage(form)
{
	var msg = "Veuillez remplir les champs correctement";
	var check  = false;
	
	if (EstVide(form.firstname.value, 'Votre nom')) {
		alert(msg); 
		form.firstname.focus();
		return false;
	}
	if (EstVide(form.surname.value, 'Votre prenom')) {
		alert(msg); 
		form.surname.focus();
		return false;
	}
	if (EstVide(form.telephone.value, 'Telephone') || !IsNumeric(form.telephone.value)) {
		alert(msg); 
		form.telephone.focus();
		return false;
	}
	if (EstVide(form.ville.value, 'Ville')) {
		alert(msg); 
		form.ville.focus();
		return false;
	}
	if (EstVide(form.email.value, 'E-mail') || !IsMail(form.email.value)) {
		alert(msg); 
		form.email.focus();
		return false;
	}
	// Test si une option sélectionnée (Bouton radio)
	for (i=0; i<form.abonne.length; i++) {
		if(form.abonne[i].checked) check = true;
	}
	if (!check) {
		alert(msg); 
		form.abonne[0].focus();
		return false;
	}
	return true;
}

function validParrainage(form)
{
	var msg = "Veuillez remplir les champs correctement";
	var check  = false;
	
	if (EstVide(form.firstname.value, 'Votre nom')) {
		alert(msg); 
		form.firstname.focus();
		return false;
	}
	if (EstVide(form.surname.value, 'Votre prenom')) {
		alert(msg); 
		form.surname.focus();
		return false;
	}
	if (EstVide(form.adresse.value, 'Adresse')) {
		alert(msg); 
		form.adresse.focus();
		return false;
	}
	if (EstVide(form.codepostal.value, 'Code postal') || !IsNumeric(form.codepostal.value)) {
		alert(msg); 
		form.codepostal.focus();
		return false;
	}
	if (EstVide(form.telephone.value, 'Telephone') || !IsNumeric(form.telephone.value)) {
		alert(msg); 
		form.telephone.focus();
		return false;
	}
	if (EstVide(form.gsm.value, 'Gsm') || !IsNumeric(form.gsm.value)) {
		alert(msg); 
		form.gsm.focus();
		return false;
	}
	if (EstVide(form.email.value, 'E-mail') || !IsMail(form.email.value)) {
		alert(msg); 
		form.email.focus();
		return false;
	}
	if (EstVide(form.decodeur.value, 'No Carte decodeur')) {
		alert('Veuillez saisir votre No de carte decodeur'); 
		form.decodeur.focus();
		return false;
	}

	if (EstVide(form.firstnamef.value, 'Nom')) {
		alert(msg); 
		form.firstnamef.focus();
		return false;
	}
	if (EstVide(form.surnamef.value, 'Prenom')) {
		alert(msg); 
		form.surnamef.focus();
		return false;
	}
	if (EstVide(form.adressef.value, 'Adresse')) {
		alert(msg); 
		form.adressef.focus();
		return false;
	}
	if (EstVide(form.codepostalf.value, 'Code postal') || !IsNumeric(form.codepostalf.value)) {
		alert(msg); 
		form.codepostalf.focus();
		return false;
	}
	if (EstVide(form.telephonef.value, 'Telephone') || !IsNumeric(form.telephonef.value)) {
		alert(msg); 
		form.telephonef.focus();
		return false;
	}
	if (EstVide(form.gsmf.value, 'Gsm') || !IsNumeric(form.gsmf.value)) {
		alert(msg); 
		form.gsmf.focus();
		return false;
	}
	if (EstVide(form.emailf.value, 'E-mail') || !IsMail(form.emailf.value)) {
		alert(msg); 
		form.emailf.focus();
		return false;
	}
	return true;
}
function validNewwebsite(form)
{
	var msg = "Veuillez remplir les champs correctement";
	var check  = false;
	
	if (EstVide(form.firstname.value, 'Votre nom')) {
		alert(msg); 
		form.firstname.focus();
		return false;
	}
	if (EstVide(form.surname.value, 'Votre prenom')) {
		alert(msg); 
		form.surname.focus();
		return false;
	}
	if (EstVide(form.adresse.value, 'Adresse')) {
		alert(msg); 
		form.adresse.focus();
		return false;
	}
	if (EstVide(form.gsm.value, 'GSM') || !IsNumeric(form.gsm.value)) {
		alert('Entrez uniquement des chiffres, sans espaces. Ex : 0262000000'); 
		form.gsm.focus();
		return false;
	}
	if (EstVide(form.email.value, 'E-mail') || !IsMail(form.email.value)) {
		alert('L\'adresse e-mail que vous avez saisi est incorrecte'); 
		form.email.focus();
		return false;
	}
	if (IsEmpty(form.reponse1.value)) {
		alert('Vous devez r&eacute;pondre &agrave; toutes les questions pour participer au jeu'); 
		form.reponse1.focus();
		return false;
	}
	if (IsEmpty(form.reponse2.value)) {
		alert('Vous devez r&eacute;pondre &agrave; toutes les questions pour participer au jeu'); 
		form.reponse2.focus();
		return false;
	}
	return true;
}
