/********************************************************************
*                   Form Validation                                        *
********************************************************************/
var valid;
function onSubmit(lang) {
  //alert("A");
  submitForm(lang);

if (valid=='ok') {
        document.forms[0].submit();
	}
}


msgError = new Array();

function languageIndex(langue)
{	
	if(langue=="en") return 'anglais';
	if(langue=="es") return 'espagnol';
	return 'francais';
}

var francais = languageIndex("fr");
var anglais = languageIndex("en");

msgError[francais]=new Array();
msgError[anglais]=new Array();

function formError(langue,error)
{
	alert(msgError[langue][error]);
	//return false;
}

//msgError[francais][0] = '';
//msgError[anglais][0] = '';

/******* Messages d'erreur ********/
msgError[francais][0] = 'La saisie de votre nom est obligatoire';
msgError[anglais][0] = 'You must key in your first name';

msgError[francais][1] = 'La saisie de votre prénom est obligatoire ';
msgError[anglais][1] = 'You must key in your last name';

msgError[francais][2] = 'La saisie de votre société ou raison sociale est obligatoire ';
msgError[anglais][2] = 'You must key in your civility';

msgError[francais][3] = 'La saisie de votre adresse e-mail est obligatoire ';
msgError[anglais][3] = 'You must key in your e-mail address';

msgError[francais][4] = 'Veuillez vérifier que votre adresse e-mail est correctement saisie ';
msgError[anglais][4] = 'Please check that your e-mail address has been keyed in correctly';

msgError[francais][5] = 'La saisie d\'un numéro de téléphone est obligatoire ';
msgError[anglais][5] = 'You must key in the comment';

//msgError[francais][6] = 'La saisie de votre secteur d\'activité est obligatoire';
//msgError[anglais][6] = 'You must key in the comment';


function mailValide(mel)
{
	//alert(mel);
	reMail= /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/;
	if (mel.match(reMail)!=null) return true;
	else return false;
}

function nonVide(texte)
{	
	//alert(texte.length);
	return (texte.length>0);
	
}

function submitForm(langue)
{

	langue=languageIndex(langue);
	var objFormulaire = document.formulaire;
	
	if(!nonVide(objFormulaire.nom.value)) return formError(langue,0);
	if(!nonVide(objFormulaire.prenom.value)) return formError(langue,1);
	if(!nonVide(objFormulaire.societe.value)) return formError(langue,2);
	//if(!nonVide(objFormulaire.secteur.value)) return formError(langue,6);
	if(!nonVide(objFormulaire.tel_fixe.value)) return formError(langue,5);
	if(!nonVide(objFormulaire.mail.value)) return formError(langue,3);
	if(!mailValide(objFormulaire.mail.value)) return formError(langue,4);

	valid='ok';
	return valid;
}


