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();

/******* Messages d'erreur ********/

msgError[francais][0] = "Veuillez indiquer votre état civil.";
msgError[anglais][0] = "Please select your civil state.";

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

msgError[francais][2] = 'Veuillez saisir votre prénom.';
msgError[anglais][2] = 'You must key in your first name';

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

msgError[francais][4] = 'Veuillez saisir un message';
msgError[anglais][4] = 'You must key in a message';

msgError[francais][4] = 'Veuillez saisir un message';
msgError[anglais][4] = 'You must key in a message';

msgError[francais][5] = 'Veuillez vérifier que l\'adresse e-mail du destinataire est correctement saisie';
msgError[anglais][5] = 'Please check that the recipient e-mail address has been keyed in correctly';

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

function mailValide(emailAdress)
{
	var ind;
	var indbis;
	var len;
	var sub;
	var check;
	//emailAdress = Trim(emailAdress);
	len = emailAdress.length;
	ind = emailAdress.indexOf("@");
	if(ind==-1) return false;
	sub = emailAdress.substring(++ind,len-ind);
	if(ind!=-1)
	{
		indbis = emailAdress.substring(ind+1,emailAdress.length).indexOf(".");
	}
	if (indbis<1) return false;
	//if (ind == sub.length-1) return false;
	sub = " \"~&#'{([`\\^)]}=+$%!§:;,?*/<>éèàçùâêîôûäïüöë";
	for (i = 0; i<len;i++)
	{	
		check = emailAdress.charAt(i);
		if (sub.indexOf(check) != -1) return false;
	}
	return true;
	
}

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

function checkContact(langue)
{

	langue=languageIndex(langue);
	var objFormulaire = document.formulaire;

	/*var civiliteOK = false;
	for(var i=0;i<objFormulaire.civilite.length;i++)
	{
		if(objFormulaire.civilite[i].checked)
		{
			civiliteOK = true;
		}
	}

	if(objFormulaire.civilite.checked=="") return formError(langue,0);
	//if(!nonVide(objFormulaire.civilite.checked)) return formError(langue,0);
	if(!civiliteOK) return formError(langue,0);
	*/
	if(!nonVide(objFormulaire.nom.value)) return formError(langue,1);
	if(!nonVide(objFormulaire.prenom.value)) return formError(langue,2);	
	if(!nonVide(objFormulaire.email.value)) return formError(langue,3);
	if(!mailValide(objFormulaire.email.value)) return formError(langue,3);
	if(!nonVide(objFormulaire.message.value)) return formError(langue,4);
	document.formulaire.submit(); return true;
	
}

function checkMail(langue)
{

	langue=languageIndex(langue);
	var objFormulaire = document.formulaire;

	if(!nonVide(objFormulaire.nom.value)) return formError(langue,1);
	if(!nonVide(objFormulaire.prenom.value)) return formError(langue,2);	
	if(!nonVide(objFormulaire.email.value)) return formError(langue,3);
	if(!mailValide(objFormulaire.email.value)) return formError(langue,3);
	if(!nonVide(objFormulaire.emailr.value)) return formError(langue,5);
	if(!mailValide(objFormulaire.emailr.value)) return formError(langue,5);
	if(!nonVide(objFormulaire.message.value)) return formError(langue,4);
	document.formulaire.submit(); return true;
	
}
