// -------------------- SWAPIMAGE --------------------
function swapImage(which,img) {
	eval('document.'+which+'.src = "'+img+'"');
}
var sdap = (document.all) ? true : false;

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

// -------------------- OPENWINDOW --------------------
function openWindow(url,nom,dimx,dimy,type) {
	featur0 = "top=20,left=20,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width="+ dimx + ",height=" + dimy;
  featur1 = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width="+ dimx + ",height=" + dimy;
	featur2 = "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width="+ dimx + ",height=" + dimy;
	props = eval('featur'+type);
	window.open(url,nom,props);
}

// -------------------- FORM --------------------
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");
var espagnol =languageIndex("es");

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

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

msgError[francais][1] = 'La saisie de votre nom est obligatoire ';
msgError[anglais][1] = 'You must key in your name';
msgError[espagnol][1] = '¡Indique su nombre !';

msgError[francais][2] = 'Veuillez saisir votre adresse.';
msgError[anglais][2] = 'You must key in your address';
msgError[espagnol][2] = '¡Indique su dirección !';

msgError[francais][3] = 'Veuillez saisir votre code postal.';
msgError[anglais][3] = 'You must key in your zip code';
msgError[espagnol][3] = '¡Indique su dirección !';

msgError[francais][4] = 'Veuillez saisir votre ville.';
msgError[anglais][4] = 'You must key in your city';
msgError[espagnol][4] = '¡Indique su dirección !';

msgError[francais][5] = 'Veuillez saisir votre numéro de téléphone.';
msgError[anglais][5] = 'You must key in your phone number';
msgError[espagnol][5] = '¡Indique su número de teléfono !';

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

msgError[francais][7] = 'Veuillez saisir un message';
msgError[anglais][7] = 'You must key in a message';
msgError[espagnol][7] = '¡Indique su consulta !';


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;

	if(!nonVide(objFormulaire.nom.value)) return formError(langue,1);
	if(!nonVide(objFormulaire.adresse.value)) return formError(langue,2);
	if(!nonVide(objFormulaire.zip.value)) return formError(langue,3);
	if(!nonVide(objFormulaire.ville.value)) return formError(langue,4);
	if(!nonVide(objFormulaire.tel.value)) return formError(langue,5);
	if(!nonVide(objFormulaire.email.value)) return formError(langue,6);
	if(!mailValide(objFormulaire.email.value)) return formError(langue,6);
	if(!nonVide(objFormulaire.message.value)) return formError(langue,7);
	document.formulaire.submit(); return true;
	
}



