/* */
var sdap = (document.all) ? true : false;

function getelem(idm){
	return elem = sdap ? document.all[idm] : document.getElementById(idm);
}



/*
Famille du fichier : Validation formulaires.
Version actuelle : 1.0
jchautbois
*/
msgError = new Array();

function languageIndex(langue)
{
	if(langue=="en") return 'anglais';
	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 civilité.';
msgError[anglais][0] = 'Please select your civil state.';

msgError[francais][1] = 'Veuillez saisir votre nom.';
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][5] = 'Veuillez saisir un n° de téléphone.';
msgError[anglais][5] = 'You must key in a message';

msgError[francais][6] = 'Veuillez saisir un n° de fax.';
msgError[anglais][6] = 'You must key in a message';

msgError[francais][7] = 'Veuillez saisir une adresse.';
msgError[anglais][7] = 'You must key in a message';

msgError[francais][8] = 'Veuillez saisir un nom de société.';
msgError[anglais][8] = 'You must key in a message';


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

function mailValide(emailAdress)
{
	var ind;
	var indbis;
	var len;
	var sub;
	var check;
	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;
	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(!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;

}


/////***** Recherche *****//////
function searche(){
	document.searcher.submit();
}

/////***** Swap Accès Intranet *****//////
function swapintra(){
	intranet = getelem('head-form-intra-champ');
	if(intranet.style.display==''){
		intranet.style.display='none';
	} else {intranet.style.display='';}
}