// JavaScript Document
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//fonction utilisée pour l'antispam des adresses mail
function dolink(ad){
   link = 'mailto:' + ad.replace(/\.\..+t\.\./,"@"); 
   return link;
}

//vérifie la validité d'une adresse mail saisie dans les formulaires
function isEmailAddress(email){
	var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	//var re = new RegExp("^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$","g");
	var chaine = new String(email);
	var retour = re.test(chaine);
	return retour;
}

//change les combo du formulaire ContactUs en fonction du secteur choisi
function ContactChangeSelects(sector) {
	if (sector=='aeronautics') {
		//value,texte, value,texte, value,texte, ...
		var arr_activity = new Array('Manufacturer','Manufacturer','Aircraft Company','Aircraft Company','Distributor','Distributor','Other','Other');
		var arr_recipient = new Array('Commercial','Commercial','Purchase','Purchase','Study dept','Study dept','Marketing','Marketing','Direction','Direction','Other','Other');
	} else {
		//value,texte, value,texte, value,texte, ...
		var arr_activity = new Array('Coachbuilder','Coachbuilder','Manufacturer','Manufacturer','Transport Company','Transport Company','Distributor','Distributor','Other','Other');
		var arr_recipient = new Array('Commercial','Commercial','Purchase','Purchase','Study dept','Study dept','Marketing','Marketing','Direction','Direction','Other','Other');
	}
	var activity = document.getElementById('activity');
	var i=0;
	//suppression des options existantes
	for (i=activity.length-1; i>=0; i--) {
		activity.remove(i);
	}
	//création des options
	i=0;
	while (i<arr_activity.length) {
		option = document.createElement("option");
		option.appendChild(document.createTextNode(arr_activity[i+1]));
		option.setAttribute("value",arr_activity[i]);
		activity.appendChild(option);
		i += 2;
	}
	
	var recipient = document.getElementById('recipient');
	//suppression des options existantes
	for (i=recipient.length-1; i>=0; i--) {
		recipient.remove(i);
	}
	//création des options
	i=0;
	while (i<arr_recipient.length) {
		option = document.createElement("option");
		option.appendChild(document.createTextNode(arr_recipient[i+1]));
		option.setAttribute("value",arr_recipient[i]);
		recipient.appendChild(option);
		i += 2;
	}
}

//vérifie les données du formulaire ContactUs
function checkContactConstraint() {
	var el = document.form_contact;
	el.id_article.value = document.form_recup_id_article.id_article.value;
	if (el.name.value=='') { alert('The name field is required.'); el.name.focus(); return false; }
	if (el.first_name.value=='') { alert('The first name field is required.'); el.first_name.focus(); return false; }
	if (!isEmailAddress(el.email.value)) { alert('The email address field is not valid.'); el.email.focus(); return false; }
	if (el.subject.value=='') { alert('The subject field is required.'); el.subject.focus(); return false; }
	if (el.message.value=='') { alert('The message field is required.'); el.message.focus(); return false; }
	return true;
}

//vérifie les données du formulaire Training offers
function checkTrainingConstraint() {
	var el = document.form_training;
	if (el.title.value=='') { alert('The title field is required.'); el.title.focus(); return false; }
	if (el.name.value=='') { alert('The name field is required.'); el.name.focus(); return false; }
	if (el.first_name.value=='') { alert('The first name field is required.'); el.first_name.focus(); return false; }
	if (el.phone.value=='') { alert('The phone number field is required.'); el.phone.focus(); return false; }
	if (!isEmailAddress(el.email.value)) { alert('The email address field is not valid.'); el.email.focus(); return false; }
	if (el.motivation.value=='') { alert('The motivation field is required.'); el.motivation.focus(); return false; }
	if (el.motivation_file.value=='') { alert('The motivation file is required.'); el.motivation_file.focus(); return false; }
	if (el.motivation_file.value.substr(-3)!='doc' && el.motivation_file.value.substr(-3)!='pdf') { alert('The motivation file must be a Word or PDF document.'); el.motivation_file.focus(); return false; }
	if (el.cv_file.value=='') { alert('The CV file is required.'); el.cv_file.focus(); return false; }
	if (el.cv_file.value.substr(-3)!='doc' && el.cv_file.value.substr(-3)!='pdf') { alert('The CV file must be a Word or PDF document.'); el.cv_file.focus(); return false; }
	return true;
}	

//vérifie les données du formulaire job offers
function checkJobConstraint() {
	var el = document.form_job;
	if (el.title.value=='') { alert('The title field is required.'); el.title.focus(); return false; }
	if (el.name.value=='') { alert('The name field is required.'); el.name.focus(); return false; }
	if (el.first_name.value=='') { alert('The first name field is required.'); el.first_name.focus(); return false; }
	if (el.phone.value=='') { alert('The phone number field is required.'); el.phone.focus(); return false; }
	if (!isEmailAddress(el.email.value)) { alert('The email address field is not valid.'); el.email.focus(); return false; }
	if (el.motivation.value=='') { alert('The motivation field is required.'); el.motivation.focus(); return false; }
	if (el.motivation_file.value=='') { alert('The motivation file is required.'); el.motivation_file.focus(); return false; }
	if (el.motivation_file.value.substr(-3)!='doc' && el.motivation_file.value.substr(-3)!='pdf') { alert('The motivation file must be a Word or PDF document.'); el.motivation_file.focus(); return false; }
	if (el.cv_file.value=='') { alert('The CV file is required.'); el.cv_file.focus(); return false; }
	if (el.cv_file.value.substr(-3)!='doc' && el.cv_file.value.substr(-3)!='pdf') { alert('The CV file must be a Word or PDF document.'); el.cv_file.focus(); return false; }
	return true;
}

//vérifie les données du formulaire Apply
function checkApplyConstraint() {
	var el = document.form_apply;
	el.id_article.value = document.form_recup_id_article.id_article.value;
	if (el.title.value=='') { alert('The title field is required.'); el.title.focus(); return false; }
	if (el.name.value=='') { alert('The name field is required.'); el.name.focus(); return false; }
	if (el.first_name.value=='') { alert('The first name field is required.'); el.first_name.focus(); return false; }
	if (el.phone.value=='') { alert('The phone number field is required.'); el.phone.focus(); return false; }
	if (!isEmailAddress(el.email.value)) { alert('The email address field is not valid.'); el.email.focus(); return false; }
	if (el.job.value=='') { alert('The job field is required.'); el.job.focus(); return false; }
	if (el.motivation.value=='') { alert('The motivation field is required.'); el.motivation.focus(); return false; }
	if (el.motivation_file.value=='') { alert('The motivation file is required.'); el.motivation_file.focus(); return false; }
	if (el.motivation_file.value.substr(-3)!='doc' && el.motivation_file.value.substr(-3)!='pdf') { alert('The motivation file must be a Word or PDF document.'); el.motivation_file.focus(); return false; }
	if (el.cv_file.value=='') { alert('The CV file is required.'); el.cv_file.focus(); return false; }
	if (el.cv_file.value.substr(-3)!='doc' && el.cv_file.value.substr(-3)!='pdf') { alert('The CV file must be a Word or PDF document.'); el.cv_file.focus(); return false; }
	return true;
}	

//-->