/* --- Javascripts Utils --- */


// Cache ou Montre un identifiant

function xd_cacheMontreLId(ID) {
	if (document.getElementById(ID).style.display == 'block') {
		document.getElementById(ID).style.display = 'none'
	} else {
		document.getElementById(ID).style.display = 'block'
	}
}

function xd_cacheTousLesId(Racine,Debut,Fin) {
	for(i=Debut;i<=Fin;i++) {
		if (document.getElementById(Racine+i)) {
			document.getElementById(Racine+i).style.display = 'none'
		}
	}
}



/* ------------- */
/* --- PopUp --- */
/* ------------- */

function xd_popUpImage(url,largeur,hauteur) {
	window.open(url,'popup','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1,width='+largeur+',height='+hauteur);
}

function xd_popUp(url,largeur,hauteur) {
	window.open('index.php5?acces='+url,'zoom','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1,width='+largeur+',height='+hauteur+',left=200,top=200');
}

/* --- Hide Show menu --- */


function hideShowMenu() {
	if (document.getElementById('boutons').style.display=='none') { 
		document.getElementById('boutons').style.display='block';
		document.getElementById('menu').style.width='10em';
		document.getElementById('body').style.left='12em';
	} else {
		document.getElementById('boutons').style.display='none' 
		document.getElementById('menu').style.width='10px';
		document.getElementById('body').style.left='30px';
	}
}

/* ----------------------------------------------- */
/* --- 				Fonctions AJAX 			 	  --- */
/* --- envoie d'une requete sql via javascript --- */
/* ----------------------------------------------- */

function showChoice(table,numrelation,numfiltre,valeur,iddiv,maxfiltre) {
	if (valeur.length==0) { 
		document.getElementById("txtHint").innerHTML="";
		return;
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="ajax.php";
	//url=url+"?q="+valeur;
	url=url+"?Table="+table+"&NumRelation="+numrelation+"&NumFiltre="+numfiltre+"&Valeur="+valeur
	url=url+"&sid="+Math.random();
	/* --- */
	IDDIV = iddiv
	TABLE = table
	NUMRELATION = numrelation
	NUMFILTRE = numfiltre +1
	VALEUR = valeur
	MAXFILTRE = maxfiltre
	/* --- */
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function GetXmlHttpObject() {
  var xmlHttp=null;
  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  } 
  catch (e) {
    // Internet Explorer
	 try {
		  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	 }
	 catch (e) {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}

function stateChanged() { 
	if (xmlHttp.readyState==4) {
		document.getElementById(IDDIV).innerHTML=xmlHttp.responseText;
		if (NUMFILTRE<MAXFILTRE) {
			// Pb sur le div à modifier et le num filtre
	//		showChoice(TABLE,NUMRELATION,NUMFILTRE,VALEUR,IDDIV,MAXFILTRE)
		}
	}
}
