
function creeXMLHttpRequestObject()
{var objRequette =null;try {objRequette =new ActiveXObject("Microsoft.XMLHTTP");
}
catch (Error){try {objRequette =new ActiveXObject("MSXML2.XMLHTTP");
}
catch (Error){try {objRequette =new XMLHttpRequest();
}
catch(Error){try {objRequette =window.createRequest();
}
catch(Error){alert("Impossible de creer l'objet XMLHttpRequest");objRequette =false;}
}
}
}
return objRequette;}

function requete (url,fct_resultat,param,asynchrone)
{
if (!(asynchrone ===false ||asynchrone ===true))
asynchrone =true;if (fct_resultat !=''){var exist;eval('if (window.'+fct_resultat+') exist=true; else exist=false;');if (!exist){alert('la fonction "'+fct_resultat+'" n\'existe pas!');return false;}
}
var req =new creeXMLHttpRequestObject();
if (asynchrone)
{req.onreadystatechange =function(){if (req.readyState ==4){if (fct_resultat !=''){try {eval(fct_resultat+"(req"+param +");");}
catch(Error){alert('l\'erreur suivante s\'est produite:\n'+Error.name+'\n'+Error.message);return false;}
}
}
};}

req.open ("GET",url,asynchrone);req.send(null);


if (asynchrone)
return true;else
return req;}

function appel (obj)
{alert(obj.responseText);}

function RegDep(obj)
{var xml =obj.responseXML;var regxml =xml.getElementsByTagName('region');var depxml =xml.getElementsByTagName('departement');var reg =document.getElementsByName('reg_id')[0];var dep =document.getElementsByName('dep_id')[0];while (reg.options.length >1)
reg.removeChild(reg.options[1]);while (dep.options.length >1)
dep.removeChild(dep.options[1]);for (i =0;i <regxml.length;++i)
{var option =document.createElement('option');option.setAttribute('value',regxml.item(i).getAttribute('id'));var txt =document.createTextNode(regxml.item(i).firstChild.nodeValue);option.appendChild(txt);reg.appendChild(option);}

for (i =0;i <depxml.length;++i)
{var option =document.createElement('option');option.setAttribute('value',depxml.item(i).getAttribute('id'));var txt =document.createTextNode(depxml.item(i).firstChild.nodeValue);option.appendChild(txt);dep.appendChild(option);}
}

var id,loc,bool;function affDep(obj,div)
{xml =obj.responseXML;loc =xml.getElementsByTagName('root').item(0).childNodes.item(0).tagName;cont =xml.getElementsByTagName('lieu');div =document.getElementById(div);ul =document.createElement('ul');bool =true;if(loc =='Vil'){bool =false;}


for (i =0;i <cont.length;i++){
var li =document.createElement('li');var a =document.createElement('a');var croix =document.createTextNode("+");var label =document.createElement("label");var txt =document.createTextNode(" "+cont.item(i).getAttribute('nom'));var b =document.createElement('b');var cb =document.createElement('input');var divGauche =document.createElement ('div');var divBas =document.createElement ('div');var carreVert =document.createElement ('span');var divDroite =document.createElement ('div');
li.style.marginBottom ='1px';li.style.listStyleType ='none';li.style.textAlign ='right';li.style.width =div.style.width;divGauche.style.textAlign ='left';divGauche.style.width ='450px';divGauche.style.display ='inline';if (loc =='Sec'){divGauche.style.paddingLeft ='20px';}

if (loc =='Vil'){divGauche.style.paddingLeft ='40px';}

a.style.color ='black';a.style.textDecoration ='none';id =cont.item(i).getAttribute('id');a.setAttribute('href','#');a.setAttribute('id','lien' +loc +'-' +id);a.onclick =function (){var nom =this.getAttribute('id').replace('lien','');affSousRub (nom.split('-')[0],nom.split('-')[1],nom);return false;};divDroite.style.marginLeft ='5px';divDroite.style.marginRight ='60px';divDroite.style.display ='inline';label.htmlFor ='CB-'+id;cb.setAttribute('type','checkbox');cb.setAttribute('id','CB-'+id);cb.setAttribute('name','CB'+loc+'-'+id);if (loc !='Vil'){cb.onclick =function (){checkChild(this.getAttribute('name').replace('CB',''),this.getAttribute('id'),true);checkParent(this.id);};}
else {cb.onclick =function (){checkChild(this.getAttribute('name').replace('CB',''),this.getAttribute('id'),false);checkParent(this.id);};}

divBas.style.visibility ='hidden';divBas.style.display ='none';divBas.style.width =li.style.width;divBas.setAttribute('id',loc +'-' +id);carreVert.className ='carreVert';carreVert.style.visibility ='hidden';carreVert.setAttribute('id','CV-' +loc +'-' +id);carreVert.onclick =function (){var nom =this.getAttribute('id').replace('CV-','');hideCarre(this,nom.split('-')[1],nom.split('-')[0],bool);};if (div.parentNode.getElementsByTagName('input')[0].checked ==true){cb.defaultChecked =true;}
else if ((cont.item(i).getAttribute('full'))&&(div.parentNode.getElementsByTagName('span')[0].style.visibility =='visible')){if (cont.item(i).getAttribute('full')=='non'){cb.defaultChecked =false;carreVert.style.visibility ='visible';}
}
else if (div.parentNode.getElementsByTagName('span')[0].style.visibility =='hidden'){cb.defaultChecked =false;}
else if (cont.item(i).getAttribute('checked')=='oui'){cb.defaultChecked =true;}



a.appendChild(croix);label.appendChild(txt);if (loc !="Vil")
divGauche.appendChild(a);if (loc =="Dep"){b.appendChild(label);divGauche.appendChild(b);li.style.backgroundColor ='#999999';}

if (loc =="Sec"){li.style.backgroundColor ='#DDDDDD';divGauche.appendChild(label);}

if (loc =="Vil"){li.style.backgroundColor ='#FFFFFF';divGauche.appendChild(label);}

li.appendChild(divGauche);divDroite.appendChild(carreVert);divDroite.appendChild(cb);li.appendChild(divDroite);if (loc !="Vil"){li.appendChild(divBas)}

ul.appendChild(li);}
div.style.visibility ='visible';div.style.display ='block';ul.style.marginLeft ='0px';ul.style.marginBottom ='3px';ul.style.marginTop ='3px';ul.style.padding ='0px';div.appendChild(ul);}

function affNiveau(obj,div)
{xml =obj.responseXML;div =document.getElementById(div);var tabCoche =new Array();tabCoche['niveau']=new Array();tabCoche['id']=new Array();tabCoche['nom']=new Array();
if (obj.responseText.indexOf('<root')>-1)
{loc =xml.getElementsByTagName('root').item(0).childNodes.item(0).tagName;cont =xml.getElementsByTagName('detail');ul =document.createElement('ul');bool =true;if(loc =='Niv3'){bool =false;}


for (i =0;i <cont.length;i++){
var li =document.createElement('li');var a =document.createElement('a');var croix =document.createTextNode("+");var label =document.createElement("label");var txt =document.createTextNode(" "+cont.item(i).getAttribute('nom'));var b =document.createElement('b');var cb =document.createElement('input');var divGauche =document.createElement ('div');var divBas =document.createElement ('div');var carreVert =document.createElement ('span');var divDroite =document.createElement ('div');
li.style.marginBottom ='1px';li.style.listStyleType ='none';li.style.textAlign ='left';
li.style.width =div.style.width;divGauche.style.textAlign ='left';divGauche.style.width ='450px';divGauche.style.display ='inline';if (loc =='Niv1'){divGauche.style.paddingLeft ='20px';}

if (loc =='Niv2'){divGauche.style.paddingLeft ='40px';}

if (loc =='Niv3'){divGauche.style.paddingLeft ='80px';}



a.className ='explorer';id =cont.item(i).getAttribute('id');if (id.substring(id.indexOf('.')).length ==2)
id +='0';a.setAttribute('href','#');a.setAttribute('id','lien' +loc +'-' +id);a.onclick =function (){var nom =this.getAttribute('id').replace('lien','');affSousNiv (nom.split('-')[0],nom.split('-')[1],nom);return false;};
if (cont.item(i).getAttribute('nbSousNiv')&&(cont.item(i).getAttribute('nbSousNiv')<=1 ||loc =="Niv3")){label.htmlFor ='CB-'+id;a.style.visibility ='hidden';}
else {label.onclick =function (){var nom =this.parentNode.parentNode.getElementsByTagName('a')[0].getAttribute('id').replace('lien','');affSousNiv (nom.split('-')[0],nom.split('-')[1],nom);return false;};}


divDroite.style.marginLeft ='5px';divDroite.style.marginRight ='60px';divDroite.style.display ='inline';cb.setAttribute('type','checkbox');cb.setAttribute('id','CB-'+id);cb.setAttribute('name','CB'+loc+'-'+id);if (loc !='Niv3'){if (cont.item(i).getAttribute('nbSousNiv')>1 &&loc !="Niv3"){
cb.onclick =function (){checkChild(this.getAttribute('name').replace('CB',''),this.getAttribute('id'),true);checkParent(this.id);var nom =this.getAttribute('name').replace('CB','');if (document.getElementById(nom).style.display !='block' &&this.checked){affSousNiv (nom.split('-')[0],nom.split('-')[1],nom);}
};
}
else {cb.onclick =function (){checkChild(this.getAttribute('name').replace('CB',''),this.getAttribute('id'),true);checkParent(this.id);};
}
}
else {cb.onclick =function (){checkChild(this.getAttribute('name').replace('CB',''),this.getAttribute('id'),false);checkParent(this.id);};}

divBas.style.visibility ='hidden';divBas.style.display ='none';divBas.style.width =li.style.width;divBas.setAttribute('id',loc +'-' +id);carreVert.className ='carreVert';
carreVert.style.visibility ='hidden';carreVert.setAttribute('id','CV-' +loc +'-' +id);carreVert.onclick =function (){var nom =this.getAttribute('id').replace('CV-','');hideCarre(this,nom.split('-')[1],nom.split('-')[0],document.getElementById('CB-'+nom.split('-')[1]).checked);
if (document.getElementById(nom).style.display !='block' &&document.getElementById('CB-'+nom.split('-')[1]).checked){affSousNiv (nom.split('-')[0],nom.split('-')[1],nom);}
};if (div.parentNode.getElementsByTagName('input')[0].checked ==true){cb.defaultChecked =true;}
else if ((cont.item(i).getAttribute('full'))&&!(div.parentNode.getElementsByTagName('span')[0].getAttribute('name'))){if (cont.item(i).getAttribute('full')=='non'){cb.defaultChecked =false;carreVert.style.visibility ='visible';tabCoche['niveau'].push(loc);tabCoche['id'].push(id);tabCoche['nom'].push(loc +'-' +id);}
else {cb.defaultChecked =true;carreVert.style.visibility ='hidden';tabCoche['niveau'].push(loc);tabCoche['id'].push(id);tabCoche['nom'].push(loc +'-' +id);}
}
else if (div.parentNode.getElementsByTagName('span')[0].style.visibility =='hidden'){cb.defaultChecked =false;}
else if (cont.item(i).getAttribute('checked')=='oui'){cb.defaultChecked =true;tabCoche['niveau'].push(loc);tabCoche['id'].push(id);tabCoche['nom'].push(loc +'-' +id);}

if (div.parentNode.getElementsByTagName('span')[0].getAttribute('name')=='hidden')
div.parentNode.getElementsByTagName('span')[0].setAttribute('name','cache');
a.appendChild(croix);label.appendChild(txt);
if (loc !="Niv3")
divGauche.appendChild(a);
divGauche.appendChild(carreVert);divGauche.appendChild(cb);if (loc =="Niv1"){

divGauche.appendChild(label);li.style.backgroundColor ='#999999';}

if (loc =="Niv2"){li.style.backgroundColor ='#DDDDDD';divGauche.appendChild(label);}

if (loc =="Niv3"){li.style.backgroundColor ='#FFFFFF';divGauche.appendChild(label);}

li.appendChild(divGauche);




if (loc !="Niv3"){li.appendChild(divBas)}

ul.appendChild(li);}

ul.style.marginLeft ='0px';ul.style.marginBottom ='3px';ul.style.marginTop ='1px';ul.style.padding ='0px';div.appendChild(ul);}
div.style.visibility ='visible';div.style.display ='block';

if (window.opener.document.URL.indexOf('haut')==-1){
for (i =0;i <tabCoche['id'].length;++i)
{if (tabCoche['niveau'][i]!='Niv3')
affSousNiv (tabCoche['niveau'][i],tabCoche['id'][i],tabCoche['nom'][i]);}
}

delete tabCoche;delete xml;delete div;delete cont;delete ul;}
