function nodeCleaner(n) {

  if(!n.data.replace(/\s/g,'')) n.parentNode.removeChild(n);

}



function cleanXML(docElement) {
  var node = docElement.getElementsByTagName('*');

  for(i = 0; i < node.length; i++) {

    a = node[i].previousSibling;

    if(a && a.nodeType == 3) nodeCleaner(a);

    b = node[i].nextSibling;

    if(b && b.nodeType == 3) nodeCleaner(b);

  }

  return docElement;

}



function afficheajaxpub(lang,selection,liste)
{
	var seltag='';
	var idtag='';
	seltag = document.getElementById(selection);
	idtag = seltag.options[seltag.selectedIndex].value;	
	
	var xhr=null;
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        try {
            xhr = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() 
	{
		if(xhr.readyState==4 && xhr.status==200){
			payspub(xhr,lang,idtag); 
		}
	};
    
    //on appelle le fichier 
   var envoi="lang="+lang+"&id="+idtag+"&liste="+liste;
	//alert(envoi);
	/*xhr.open("GET", "../inc/affreponse.php"+envoi, true);
	xhr.send(null);
	*/
	xhr.open("POST", urlitdistri+"inc/affreponsepub.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(envoi);
	
	
	

}

function payspub(xhr,lang,idtag)
{	
	
	
	document.getElementById('actu').innerHTML = '';
	
	var docXML= xhr.responseXML;
	response     = docXML.documentElement;
	var items = response.getElementsByTagName("pasactu");
	count = items.length;
	if (count>0){
		for(j = 0; j < count; j++)
		{
			vhtmlnews = items[j].getElementsByTagName("libelle")[0].firstChild.nodeValue;
		}
		
	} else {
		var docXML= xhr.responseXML;
		response = cleanXML(docXML.documentElement);
		var items = response.getElementsByTagName("actualite");
		count = items.length;
		var vhtmlnews='';		
		for(i = 0; i < count; i++)
		{
			vhtmlnews += '<a href='+items[i].getElementsByTagName("lien")[0].firstChild.nodeValue+'>'+items[i].getElementsByTagName("titre")[0].firstChild.nodeValue+'</a><br />';
			vhtmlnews += ''+ items[i].getElementsByTagName("date")[0].firstChild.nodeValue + '<br />';
		}
	}
		var docXML= xhr.responseXML;
		response     = docXML.documentElement;
		var items = response.getElementsByTagName("titreactu");
		count = items.length;
		for(j = 0; j < count; j++)
		{
			lblactu = items[j].getElementsByTagName("libelle")[0].firstChild.nodeValue;
		}
		
		vhtmlactu='';
		vhtmlactu += "<div id='actu' style='margin-top:55px; margin-bottom:50px;'>";
		vhtmlactu += "<h1 style='width: 95%; text-align:left; font-size: 16px; margin-left: 10px;'><a></a>"+lblactu+"</h1>"
		vhtmlactu += "<hr style='margin-top:-2px; margin-left:10px; width: 95%; color: #7AB2B5; background-color: #7AB2B5; height: 1px; border: 0;' />"
		vhtmlactu += "<p style='font-size: 11px; margin-left:10px; margin-bottom: 60px;text-align:left;'>"
		document.getElementById('actu').innerHTML += vhtmlactu+vhtmlnews+'<br /></p></div>';
	
	
}


