// JavaScript Document

function verif_nous_contacter(theForm){

	theForm.f_Nom.value = theForm.f_Nom.value.trim();
	theForm.f_Prenom.value = theForm.f_Prenom.value.trim();
	theForm.f_Num_Adherent.value = theForm.f_Num_Adherent.value.trim();
	theForm.f_Message.value = theForm.f_Message.value.trim();

	// on test la valider des checkbox
	var validCheckbox = false ;
	for (var i = 0 ; i < theForm.Adherent.length ; i++){
		if(theForm.Adherent[i].checked && !validCheckbox){
			validCheckbox = true ;
			theForm.f_Adherent.value = theForm.Adherent[i].value ;
		}
	}

   if (theForm.f_Nom.value.length == 0){
		alert("Veuillez renseigner votre nom.");
		theForm.f_Nom.focus();
		return false ;	
	} else if (theForm.f_Prenom.value.length == 0){
		alert("Veuillez renseigner votre prénom.");
		theForm.f_Prenom.focus();
		return false ;	
	} else if ( theForm.f_email.value.length == 0 || !is_email(theForm.f_email.value)  ){
		alert("Veuillez renseigner correctement votre adresse e-mail.");
		theForm.f_email.focus();
		return false ;	
	} else if (!chiffre(theForm.f_Telephone.value,'Tel')){
		alert("Veuillez renseigner correctement le numéro de téléphone.");
		theForm.f_Telephone.focus();
		return false ;	
	} else if (!validCheckbox) {
		alert("Veuillez préciser si vous êtes adhérent à Okigo.");
		theForm.Adherent[0].focus();
		return false ;	
	}  else {
		return true ;
	}
}


function chiffre(valeur,type)
  {
		var checkOK = "0123456789";
		if (type=="Tel"){checkOK = "(+) 0123456789";}
		if (type=="Date"){checkOK = "/. 0123456789";}
		if (type=="Num"){checkOK = "/. 0123456789";}
		var checkStr = valeur;
  		var allValid = true;
   
  		for (i = 0;  i < checkStr.length;  i++)
  		{
  		  ch = checkStr.charAt(i);
  		  for (j = 0;  j < checkOK.length;  j++)
   		   if (ch == checkOK.charAt(j))
        break;
  		  if (j == checkOK.length)
   		 {
    		  allValid = false;
    		  return(false);
			  break;
    	 }
        }
		if (allValid){return(true);}
}

function is_email(email){
     var reg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]{2,}[.][a-zA-Z0-9]{2,4}$/
     var reg2 = /[.@]{2,}/
     return ((reg.exec(email)!=null) && (reg2.exec(email)==null))
}
String.prototype.trim = function()
{ return this.replace(/(^\s*)|(\s*$)/g, ""); }

function GetParameter(Nom){
	var param= unescape(document.location.search.substring(1));
	if (!param.length) return('');
	var P = param.split("&");
	var PName= new Array();
	var PValue= new Array();
	for(i=0;i<P.length;i++){
	PName[i]=P[i].substring(0,P[i].indexOf("="));
	PValue[i]=P[i].substring(P[i].indexOf("=")+1);
	}
	var resultat=false;
	for(i=0;i<PName.length;i++){
		if(PName[i].toLowerCase()==Nom.toLowerCase())return (unescape(PValue[i]));                   
		}
	return('');
}

