/********************************
VERIFICATION CHAMPS DE FORMULAIRE
********************************/
function IsEmpty(sValue)
{
	if (sValue != null)
	{
		if (sValue != "")
		{
			return false;
		}
	}
	
	return true;
}
function isEmailValid(val) {
	   var accepted = true;
	   var chaine = new String(val);
	   if (((chaine.indexOf("@") < 0) || (chaine.indexOf(".") < 0))|| chaine == ""){
	    	accepted = false;
	   }
	   return(accepted);
	}

function isEntierValid(val) {
	   var accepted = true ;
	   var chaine =  new String(val);
	   if (( chaine.search(/[^0-9]/) != -1)) {
	   	accepted = false;
	   }
	   return(accepted);
	}
	
function isComplet5Valid(val) {
	   var accepted = true ;
	   var chaine =  new String(val);
	   if (chaine.length < 5) {
	   	accepted = false;
	   }
	   return(accepted);
	}

function isComplet10Valid(val) {
	   var accepted = true ;
	   var chaine =  new String(val);
	   if (chaine.length < 10) {
	   	accepted = false;
	   }
	   return(accepted);
	}

function champs_valid(){
	thisForm=document.forms[0];
	if ((!(thisForm.F01civilite[0].checked)) && (!(thisForm.F01civilite[1].checked)) && (!(thisForm.F01civilite[2].checked)))
	{
		alert("Merci de choisir une CIVILITE");
		thisForm.F01civilite[0].focus();
		return false;
	}
	if (IsEmpty(thisForm.F02Nom.value)) {
		alert("Merci de renseigner votre NOM");
		thisForm.F02Nom.focus();
		return false;
	}
	if (IsEmpty(thisForm.F03Prenom.value)) {
		alert("Merci de renseigner votre PRENOM");
		thisForm.F03Prenom.focus();
		return false;
	}
	if ( IsEmpty(thisForm.F04Telephone.value) ) {
		alert("Merci de renseigner un TELEPHONE");
		thisForm.F04Telephone.focus();
		return false;
	}
	if (!IsEmpty(thisForm.F04Telephone.value) ) {
		if (!isEntierValid(thisForm.F04Telephone.value)) {
			alert("Le champ TELEPHONE ne doit contenir que des chiffres");
			thisForm.F04Telephone.focus();
			return false;
		}else if(!isComplet10Valid(thisForm.F04Telephone.value)){
		     alert("Le champ TELEPHONE doit contenir 10 chiffres");
			thisForm.F04Telephone.focus();
			return false;
		}
	}
	if (IsEmpty(thisForm.F05Email.value)) {
		alert("Merci de renseigner le champ E-MAIL");
		thisForm.F05Email.focus();
		return false;
	} else if (!isEmailValid(thisForm.F05Email.value)) {
		alert("L'adresse EMAIL saisie est incorrecte.");
		thisForm.F05Email.focus();
		return false;
	}
	if (IsEmpty(thisForm.F06Message.value)) {
		alert("Merci de saisir votre message");
		thisForm.F06Message.focus();
		return false;
	}
	var resultat = "";
	if (!(IsEmpty(thisForm.F07Autorisation.value) ))
	 {
		resultat = "OUI le client accepte de recevoir des courriers electroniques";
		resultat += " a caractere commercial";
		resultat += " de la part de la boutique Le Chardon";
		thisForm.F07Autorisation.value = resultat;
	 }
	alert("Votre message va être envoyé");
	envoieFormulaire();
}

function envoieFormulaire() {
				thisForm=document.forms[0];
				thisForm.action="envoi_mail_contact.php";
				thisForm.submit();
}

