// Change la photo en passant sur l'icone

function changePhoto(img,texte,type) {
	document.getElementById('photo').src="visuels/photos_"+type+"/"+img;
	document.getElementById('photo').alt=texte;
	document.getElementById('texte_photo').innerHTML=texte;
}


/* --- MACHINE A ECRIRE --- */
var i=0
var j=0
var texteNE, affiche

var ie = (document.all);
var ne = (document.layers); 



function init_machine_a_ecrire(){
	texteNE='';
	machine_a_ecrire();
}
	
function machine_a_ecrire(){
	texteNE=texteNE+texte.charAt(i)
		affiche=texteNE
		if (texte.charAt(i)=="<") {
			j=1
		}
	if (texte.charAt(i)==">") {
		j=0
	}
	if (j==0) {
		if (document.getElementById) { // avec internet explorer
			document.getElementById("TitrePage").innerHTML = affiche;
		}
	}
	if (i<texte.length-1){
		i++
			setTimeout("machine_a_ecrire()",50)
	}
	else
		return
}


/* ------------------------- */
/* --- compatibilité OLD version formulaires à faire migrer avec XD_ValideFomulaire --- */
/* ---------------------------------------- */

// JavaScript Document
//CouleurFondMenu='#FABE10';

// Change la couleur de fond des cellules d'un tableau
function ChangeCouleur(id,couleur) {
	document.getElementById(id).style.backgroundColor=couleur;
}

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];}
}

/* Validation de formulaire */

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
	var obj = MM_findObj(objName);
	if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
		if (theValue == true || theValue == false)
			eval("obj."+theProp+"="+theValue);
		else eval("obj."+theProp+"='"+theValue+"'");
	}
}

function MM_validateForm() { //v4.0
	var i,j,p,pos,q,nom,valeur,test,num,min,max,tmp_nom,errors='',errorsOr='',errorsSelect='',estVideOr='true',args=MM_validateForm.arguments;
	for (i=0; i<(args.length-1); i+=2) {
		if (args[i].indexOf(',')==-1) {
			test=args[i+1]; val=document.getElementById(args[i]);
			nom=val.name;
			valeur=val.value;
			if (valeur!="") {
				if (test.indexOf('isEmail')!=-1) {
					p=valeur.indexOf('@');
					if (p<1 || p==(valeur.length-1)) errors+='- '+nm+' doit contenir une adresse e-mail.\n';
				} else if (test!='R') {
					num = parseFloat(valeur);
					if (isNaN(valeur)) errors+='- '+nom+' doit contenir un nombre.\n';
					if (test.indexOf('inRange') != -1) {
						p=test.indexOf(':');
						min=test.substring(8,p); max=test.substring(p+1);
						if (num<min || max<num) errors+='- '+nom+' doit contenir un nombre entre '+min+' et '+max+'.\n';
					}
				}
			} else if (test.charAt(0) == 'R') errors += '- '+nom+' est nécessaire.\n';
		} else {
			nom=args[i];
			test=args[i+1];
			if (test=='Or') {
				while (nom.indexOf(',')!=-1) {
					pos=nom.indexOf(',');
					tmp_nom=nom.substring(0,pos);
					if (document.getElementById(tmp_nom).value!='') {
						estVideOr='false';
					}
					nom=nom.substring(pos+1,nom.length);
					errorsOr+='- '+tmp_nom+'\n';
				}
				if (document.getElementById(nom).value!='') {
					estVideOr='false';
				} else {
					errorsOr+='- '+nom+'\n';
				}
			} else if (test=='S') {
				// Vérifie la valeur de tmp_nom si égale à la valeur donnée aprés la virgule
				pos=nom.indexOf(',');
				tmp_nom=nom.substring(0,pos);
				if (document.getElementById(tmp_nom).value==nom.substring(pos+1,nom.length)) {
					errorsSelect += '- '+tmp_nom+'\n';
				}
			}		
		}
	}      
	if (errorsSelect) { errors += '\nVous devez effectuer une sélection dans les champs suivants :\n'+errorsSelect };
	if (estVideOr=='true') { errors +='\nAu moins un des champs suivant est obligatoire :\n'+errorsOr };
	if (errors) alert('Les erreurs suivantes doivent être corrigées :\n'+errors);
	document.MM_returnValue = (errors == '');
}


