// Changer de Class.
function ChangeClass(objet, myClass){ 
  objet.className = myClass;
}

// Redirection.
function LmUp(path){
	location.href = path;
}

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

// Fonction de validité de mail.
function test_mail(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 test_vide(champ) {
	if (champ.value.length == 0) { 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') { return 'non';
      	}
    } return 'ok';
}

// Changement automatique apres sélection d'un champ select.
function MM_jumpMenu(selObj,restore){
  eval("location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// Raffraichissement de la page parent et fermeture de la page ouverte.
function Termine(){
	opener.location.reload();
	//self.close();
}

// Ouverture de popup
function ouvrefenetre(adresse, hauteur, largeur){
var top=(screen.height-hauteur)/2;
var left=(screen.width-largeur)/2;
toto = window.open( adresse, "param", "scrollbars=yes,toolbar=no,menubar=no,resizable=no,top=50,left=50,height="+hauteur+",width="+largeur );
toto.focus();
}

// Fonction pour cacher ou afficher un div.
function affiche_cache(idDiv, nomForm, nomChamp) {
	if (document[nomForm][nomChamp].checked == false) {
		document.getElementById(idDiv).style.visibility = 'hidden';
	}
	else if (document[nomForm][nomChamp].checked == true) {
		document.getElementById(idDiv).style.visibility = 'visible';
	}
}

// Fonction pour savoir si une checkbox est selectionné.
function AnySelected(champs){
    for (i=0; i<champs.length; i++) {
        if (champs[i].checked) return true;
    }
    return false;
}


////////////////////////////
//                        //
//         AJAX           //
//                        //
////////////////////////////

function file(fichier){
	//On teste le navigateur
	if ( window.XMLHttpRequest ){ // On teste si le navigateur est Firefox
		xhr_object = new XMLHttpRequest();
	}
	else if ( window.ActiveXObject ){ // Sinon, on teste si c'est IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else{
		return false;
	}
	xhr_object.open( "GET", fichier, false );
	xhr_object.send(null);
	if ( xhr_object.readyState == 4 ){
		return xhr_object.responseText;
	}
	else{
		return false;
	}
}