// Pour savoir dans quelle sous nav on se trouve.
function selectSsNav(id){
	if (document.getElementById('ssnav_'+id)){
		document.getElementById('ssnav_'+id).className = 'on';
	}
}

// Fonctions de preload et de swap image.
function MM_preloadImages() {
  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_swapImgRestore() {
  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_findObj(n, d) {
  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() {
  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];}
}


////////////////////////////
//                        //
//      FORMULAIRES       //
//                        //
////////////////////////////

// fonction pour afficher les option si c'est une entreprise ou une association.
function checkSelect(value){
	if (value == 'entreprise / association'){
		document.getElementById('option').style.display = 'block';
	}
	else {
		document.getElementById('option').style.display = 'none';
	}
}

// Fonction de validité de mail.
function testMail(champ) {
	var car = 'non';
	for (var i = 0; i < champ.value.length; i++) {
		var ch = champ.value.substring(i, i + 1);
		if (ch == '@') {
			for (var j = i+1; j < champ.value.length; j++) {
				var ch2 = champ.value.substring(j, j + 1);
				if (ch2 == '.') {car='oui';}
				}
			}
		}
	if (car!='oui') {
		alert("votre email semble être erroné."); champ.focus(); return 'non';
	} return 'ok';
}

// Fonction test de champ vide.
function testVide(champ){
	if (champ.value.length == 0){
		champ.focus();
		return 'non';
    }
    if (champ.value.length > 0){
        var tout_espaces='oui';
    	for (var i = 0; i < champ.value.length; i++){
        	if (champ.value.substring(i, i + 1) != ' '){ tout_espaces='non'; }
      	}
      	if (tout_espaces=='oui'){
			champ.focus();
			return 'non';
      	}
    } return 'ok';
}

// Fonction pour verifier le numero de telephone.
function verifTel(telephone){
	if (telephone.value != ''){
		var reg_tel = /^[0-9]{2}(\s[0-9]{2}){4}$/
		if (!(reg_tel.exec(telephone.value)!=null)){
			alert("votre numéro n'est pas au bon format.");
			telephone.focus(); // on selectionne le champ concerné.
			return 'non';
		}
		else {
			return 'ok';
		}
	}
	else {
		alert("vous n'avez pas indiqué votre numéro.");
		telephone.focus(); // on selectionne le champ concerné.
		return 'non';
	}
}

// Fonction pour verifier les boutons radio.
function verifRadio(champ){
	var one = 'non';
	for (var i=0; i<champ.length; i++){
		if (champ[i].checked){
			var one = 'oui';
		}
	}
	if (one != 'oui'){
		return 'non';
	} return 'ok';
}

// Verification contact.
function verifCont(form){
	if (testVide(form.Nom) != 'ok') {alert("les champs marqués d'une * sont obligatoires.");return 'non'}
	if (testVide(form.Prenom) != 'ok') {alert("les champs marqués d'une * sont obligatoires.");return 'non'}
	if (verifRadio(form.Genre) != 'ok') {alert("les champs marqués d'une * sont obligatoires.");return 'non'}
	if (testVide(form.Fax) == 'ok'){ if (verifTel(form.Fax) != 'ok') {return 'non'} }
	if (verifTel(form.Tel1) != 'ok') {return 'non'}
	if (testVide(form.Tel2) == 'ok'){ if (verifTel(form.Tel2) != 'ok') {return 'non'} }
	if (testVide(form.Email) != 'ok') {alert("les champs marqués d'une * sont obligatoires..");return 'non'}
	if (testMail(form.Email) != 'ok') {return 'non'}
	if (testVide(form.Service) != 'ok') {alert("les champs marqués d'une * sont obligatoires..");return 'non'}
	return 'ok';
} 
function valCont(){
	if (verifCont(document.contact)=='ok') {
		document.contact.but.disabled = true;
		document.contact.but.value = 'patientez...';
		document.contact.submit();
	}
}
