// JavaScript Document


function submitForm(langue){
	if ( verifform(langue)) document.forms['formcontact'].submit();
}

function verifform(langue){
	
	 nom = trim(document.forms['formcontact'].nom.value);
	 societe = trim(document.forms['formcontact'].societe.value);
	 email = trim(document.forms['formcontact'].email.value);
	 tel = trim(document.forms['formcontact'].tel.value);
	 message = trim(document.forms['formcontact'].message.value);
	 bool = true;	
	 msgfr = "Merci de renseigner les champs suivants : ";
	 msgen = "Thank you to fill the following fields : ";
	
	if (langue == "fr") {
		msg = msgfr;
		if (nom == "") {
	  		msg = msg + "\n - votre nom";
	  		document.forms['formcontact'].nom.focus();
			bool = false;
	 	}

	    if (societe == "") {
			msg = msg + "\n - votre societe";
	  		document.forms['formcontact'].societe.focus();
	  		bool = false;
	   } 

	   if (!isValidEmail(email)) {
	 	 msg = msg + " \n - votre adresse mail";
	  	 document.forms['formcontact'].email.focus();
		 bool = false;
		}
		
	   if (tel == "") {
	  		msg = msg + "\n - votre t\351l\351phone ";
	  		document.forms['formcontact'].tel.focus();
	  		bool = false;
	 	}

	 	if(message == "") {
	  		msg = msg + "\n - votre message ";
	  		document.forms['formcontact'].message.focus();
	  		bool = false;
	 	}
		
	} else {
		msg = msgen;
		if (nom == "") {
	  		msg = msg + "\n - your name";
	  		document.forms['formcontact'].nom.focus();
			bool = false;
	 	}

	    if (societe == "") {
			msg = msg + "\n - your company";
	  		document.forms['formcontact'].societe.focus();
	  		bool = false;
	   } 

	   if (!isValidEmail(email)) {
	 	 msg = msg + " \n - your email address";
	  	 document.forms['formcontact'].email.focus();
		 bool = false;
		}
		
	  if (tel == "") {
	  		msg = msg + "\n - your phone number ";
	  		document.forms['formcontact'].tel.focus();
	  		bool = false;
	 	}

	 	if(message == "") {
	  		msg = msg + "\n - your message ";
	  		document.forms['formcontact'].message.focus();
	  		bool = false;
	 	}
	}
		
  if (bool == false) alert(msg);	
 return bool;
}


function trim(str) {
   return str.replace(/^\s*|\s*$/,"");
}

function isValidEmail(emailAddress) {

   var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(emailAddress);
}

