

// ------------------------------------------------------------
//  Gestion des listes d'activités arborescentes
// ------------------------------------------------------------

function Developper(Id) {
	document.getElementById("ImgDev"+Id).style.display="None";
	document.getElementById("ImgCol"+Id).style.display="Inline";
	document.getElementById("Div"+Id).style.display="Block";
}
function Collapser(Id) {
	document.getElementById("ImgDev"+Id).style.display="Inline";
	document.getElementById("ImgCol"+Id).style.display="None";
	document.getElementById("Div"+Id).style.display="None";
}
function Inverser(Id) {
	if(document.getElementById("Div"+Id).style.display.toUpperCase() == "NONE")
		{Developper(Id);}
	else
		{Collapser(Id);}
}

function Executer(Id) {
	if(document.Frm.Dept.value=="")
		{window.location="entreprises.php?OrdRub="+Id;}
	else
		{window.location="entreprises.php?OrdRub="+Id+"&DeptEnt="+document.Frm.Dept.value;}
}

function ValiderNomEnt(Saisie, NonVide) {
	if(NonVide && Saisie == "") {
		throw new Error("Le nom de l'entreprise est obligatoire.");}
	if(Saisie == "")
		{return Saisie;}
	Saisie = Saisie.replace(/-/g, " ");
	Saisie = Saisie.replace(/\./g, "");
	Saisie = Saisie.replace(/é|è|ê|ë/g, "e");
	Saisie = Saisie.replace(/à|â/g, "a");	
	Saisie = Saisie.replace(/ç/g, "c");
	Saisie = Saisie.toUpperCase();
	return Saisie;
} 

function ValiderFrm() {
	try {
		with(document.Frm) {
		if(!NomEnt.value) {return false ;}
			NomEnt.value = ValiderNomEnt(NomEnt.value, true);
		}
	return true;
	}
	catch(Error) {
		alert(Error.message);
		return false;
	}
}

var Ld1Id='';
var Ld2Id='';
var id_liste='';

function ValideRubNiv2(val) {
	Ld1Id=val; //id_département
	id_liste='2';//Utilisé dans la fonction ChargeLd() pour identifier la liste déroulante
	var LD_URL = 'ValideRubNiv2.php?Ld1='+Ld1Id;
	ObjetXHR(LD_URL)
	// Réinitialisation de Ld3 si modification de LD1 après passage en Ld2
	//if (Ld2Id!='') {ValideLd3('');	}
}

function ValideRubNiv3(val) {
	Ld2Id=val; //id_commune
	id_liste='3'; //Utilisé dans la fonction ChargeLd() pour identifier la liste déroulante
	var LD_URL = 'ValideRubNiv3.php?Ld1='+Ld1Id+'&Ld2='+Ld2Id;
	if (Ld2Id=='') {var LD_URL = 'ValideRubNiv3.php';}	
	ObjetXHR(LD_URL)
}

function compteClic (val) {
	LD_URL='pub/compteur.php?pubid='+val;
	//alert ('compteur');
	ObjetXHR(LD_URL);
}

function ObjetXHR(LD_URL) {
	//creation de l'objet XMLHttpRequest
	if (window.XMLHttpRequest) { // Mozilla,...
		xmlhttp=new XMLHttpRequest();
		if (xmlhttp.overrideMimeType) {
			xmlhttp.overrideMimeType('text/xml');
		}	
		xmlhttp.onreadystatechange=ChargeLd;
		xmlhttp.open("GET", LD_URL, true);
		xmlhttp.send(null);
	} else if (window.ActiveXObject) { //IE 
		xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); 
		if (xmlhttp) {
			xmlhttp.onreadystatechange=ChargeLd;
			xmlhttp.open('GET', LD_URL, false);
			xmlhttp.send();
		}
	}
	// Bouton non apparent car modification de LD1 ou Ld2
	document.getElementById('buttons').style.display='none';
}

// fonction pour manipuler l'appel asynchrone
function ChargeLd() {
	if (xmlhttp.readyState==4) { 
		if (xmlhttp.status==200) { 
			//span id="niv2" ou "niv3"
			document.getElementById('niv'+id_liste).innerHTML=xmlhttp.responseText; 
			if (xmlhttp.responseText.indexOf('disabled')<=0) {
				//focus sur liste déroulante 2 ou 3
				document.getElementById('Liste'+id_liste).focus(); 
			}	
		}
	}
}

function Affiche_Btn() {
	document.getElementById('buttons').style.display='inline';
}

