//-------------------------------------------------------------------------------------------------------------------------

function trim (chaine) {
 return chaine.replace(/(^\s*)|(\s*$)/g, "");
}

function isEmail(adresse_email){

arobase = adresse_email.indexOf("@");
point = adresse_email.indexOf(".",arobase);
mauvais_endroit_point = arobase+1;
double_point = adresse_email.indexOf("..",arobase);
nbre_carac = adresse_email.length - point;
double_arobase = adresse_email.indexOf("@",arobase+1);
   
if ( (arobase < 1) || (point <= mauvais_endroit_point) || (adresse_email.length < 5) || (double_point >= 0) || (nbre_carac < 3) || (double_arobase >= 0) )
{return false;}

else {return true}
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}	


//Checking du formulaire contact
function Check_FormContact() {

var nom = trim(document.contact.nom.value);
var prenom = trim(document.contact.prenom.value);
var mail = trim(document.contact.mail.value);
var message = trim(document.contact.message.value);

if (nom == "" || prenom == "" || mail == "" || message == "" ) {
	
	alert("All fields are required");
	return(false);

}

if (!(isEmail(mail))) {
		alert ("Your address email is incorrect");
		return(false);	
}

return(true);

}

//Checking du formulaire Offre Club
function Check_OffreClub() {

var num = trim(document.offre.num.value);
var prenom = trim(document.offre.prenom.value);
var nom = trim(document.offre.nom.value);
var message = trim(document.offre.adresse.value);
var cp = trim(document.offre.cp.value);	
var ville = trim(document.offre.ville.value);	
var pays = trim(document.offre.pays.value);
var tel = trim(document.offre.tel.value);	
var mail = trim(document.offre.mail.value);	


if ( nom == "" || prenom == "" || mail == "" || message == "" || cp == "" || ville == "" || pays == "" || tel == "" || mail == "") {
	alert("All fields are required");
	return(false);
}

if (!(isEmail(mail))) {
		alert ("Your address email is incorrect");
		return(false);	
}

if (!( (isInteger(cp)) && (cp.length==5))) {
		alert("Your zip code is not valid");
		return(false);	
	
}
	
return(true);

}



//Checking du formulaire Document
function Check_FormDocument() {

var nom = trim(document.doc.nom.value);
var prenom = trim(document.doc.prenom.value);
var mail = trim(document.doc.mail.value);
var profil = trim(document.doc.profil.value);
var profil_autre = trim(document.doc.profil_autre.value);
var societe = trim(document.doc.societe.value);	
var cp = trim(document.doc.cp.value);	
var ville = trim(document.doc.ville.value);	
var pays = trim(document.doc.pays.value);
var bool = false;
var mysel = document.getElementById("sel");


if ( nom == "" || prenom == "" || mail == "" || cp == "" || ville == "" || pays == "") {
	alert("All fields are required");
	return(false);
}

if (!(isEmail(mail))) {
		alert ("Your adress email is incorrect");
		return(false);	
}

if ( ((profil == 0)||(profil == 6)) && ( trim(profil_autre) =="")) {
		alert ("You must select a profile");
		return(false);	
}

if (!( (isInteger(cp)) && (cp.length==5))) {
		alert("Your zip code is not valid");
		return(false);	
	
}

var compteur = 0;
for (i=0;i<2;i++) {
	
	if (mysel[i].selected){
		compteur++;	
	}
}

if (compteur > 3) {
		alert("You must select 3 documents to the maximum");
		return(false);		
}
else {
	if (compteur == 0) {
		alert("Select the documents which you wish to order");
		return(false);	
	}
	else {
	 bool = true;	
	}
}

return(true);

}



//Checking du formulaire Alertes
function Check_FormAlerte() {

var nom = trim(document.alerte.nom.value);
var prenom = trim(document.alerte.prenom.value);
var mail = trim(document.alerte.mail.value);
var profil = trim(document.alerte.profil.value);
var profil_autre = trim(document.alerte.profil_autre.value);
var societe = trim(document.alerte.societe.value);	
var cp = trim(document.alerte.cp.value);	
var ville = trim(document.alerte.ville.value);	
var pays = trim(document.alerte.pays.value);
var boolcb = (
			  document.alerte.cb1.checked 
			  ||
			  document.alerte.cb2.checked 
			   ||
			  document.alerte.cb3.checked 
			  ||
			  document.alerte.cb4.checked 
			  ||
			  document.alerte.cb5.checked 
			  );

if ( nom == "" || prenom == "" || mail == "") {
	alert("Fields marked with an asterisk (*) are compulsory.");
	return(false);
}

if (!(isEmail(mail))) {
		alert ("Your address email is incorrect");
		return(false);	
}

if ( ((profil == 0)||(profil == 6)) && ( trim(profil_autre) =="")) {
		alert ("You must select a profile");
		return(false);	
}

if (!(boolcb)) {
		alert ("You must select documents");
		return(false);	
}

if ((cp!="")
&&
(!( (isInteger(cp)) && (cp.length==5)))
)
{
		alert("Your zip code is not valid");
		return(false);	
	
}
	
	
return(true);


}

//Checking du formulaire Commande de documents
function Check_FormAdhesion() {

if (!((document.adherer.a1[0].checked) || (document.adherer.a1[1].checked))) {
	
	alert("You specify your profile of shareholder");
	return(false);
	
}

var societe = trim(document.adherer.societe.value);

if ( (document.adherer.a1[1].checked) && (societe == "")) {
	
	alert("Please specify the name of the company of which you are shareholder");
	return(false);
	
}


var nom = trim(document.adherer.nom.value);
var prenom = trim(document.adherer.prenom.value);
var tel = trim(document.adherer.tel.value);	
var mail = trim(document.adherer.mail.value);
var cp = trim(document.adherer.cp.value);	
var adresse = trim(document.adherer.adresse.value);
var ville = trim(document.adherer.ville.value);	
var pays = trim(document.adherer.pays.value);
var boolcb = (document.adherer.cbdeclaration.checked);



if ( nom == "" || prenom == "" || mail == "" || cp == "" || ville == "" || pays == "" || adresse == "") {
	alert("Fields marked with an asterisk (*) are compulsory.");
	return(false);
}

if (!(isEmail(mail))) {
	alert ("Your address email is incorrect");
	return(false);	
}

if (!( (isInteger(cp)) && (cp.length==5))) {
		alert("Your zip code is not valid");
		return(false);	
	
}

if (!(boolcb)) {
	alert ("Please notch the box indicating your acceptance of the conditions of the payment of the Shareholder's Club");
	return(false);	
}



return(true);

}


//Checking du formulaire suggestion
function Check_FormSuggestion() {

var nom = trim(document.suggestion.nom.value);
var prenom = trim(document.suggestion.prenom.value);
var mail = trim(document.suggestion.mail.value);
var message = trim(document.suggestion.message.value);

if (nom == "" || prenom == "" || mail == "" || message == "" ) {
	
	alert("All fields are required");
	return(false);

}

if (!(isEmail(mail))) {
		alert ("Your address email is incorrect");
		return(false);	
}

return(true);

}

//Checking du formulaire envoi à un ami
function Check_FormEnvoiAmi(formulaire){
		  	
	var email1 = trim(formulaire.email1.value);
	var message = trim(formulaire.message.value);
	var nom = trim(formulaire.nom.value);
	var emailfrom = trim(formulaire.emailfrom.value);
	var code = trim(formulaire.code.value);
	
	 
  if (email1 == "") {
		alert ("Please indicate address email");
		return(false);
		}
		
 if (!(isEmail(email1))) {
 		alert ("This address email is incorrect");
 		return(false);
 		}
		        
 if (message == "") {
		alert ("Please indicate your message");
		return(false);
		}
		
	if (nom == "") {
		alert ("Please indicate your name");
		return(false);
		}
	
	 if (emailfrom == "") {
		alert ("Please indicate your address email");
		return(false);
		}
		
 if (!(isEmail(emailfrom))) {
 		alert ("Your address email is incorrect");
 		return(false);
 		}
 	
 	if (trim(code) == "") {
		alert ("Please indicate the code");
		return(false);
	}
 			
	return(true);
}	

//Checking du formulaire Donner son avis
function Check_FormAvis(formulaire){
		  	
var message = trim(formulaire.message.value);
var emailfrom = trim(formulaire.emailfrom.value);
	var nom = trim(formulaire.nom.value);
	var prenom = trim(formulaire.prenom.value);
	
if (nom == "" || prenom == "" || emailfrom == "" || message == "" ) {
	
	alert("All fields are required");
	return(false);

}

if (!(isEmail(emailfrom))) {
 		alert ("Your address email is incorrect");
 		return(false);
 	}
 	 			
	return(true);
}
