function ajax_traitement(valeur,nom_script_php,param_php,nom_id,nature,action)
{
    var xhr=null;
    
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() { 
	alert_ajax(xhr,nom_id,nom_script_php,param_php,nature,action); 
    };

	if (nom_script_php != '')
		xhr.open("GET", nom_script_php+'?param='+valeur+param_php, true);
    xhr.send(null);
}

function alert_ajax(xhr,nom_id,nom_script_php,param_php,nature,action)
{
    if (xhr.readyState==4) 
    {
    	var docXML= xhr.responseXML;
    	var items = docXML.getElementsByTagName("donnee")

	if (nom_script_php == 'ajax_communautes.php') {
		document.getElementById("id_service").className="nonaffiche";
		document.getElementById("id_fonction").className="nonaffiche";
		document.getElementById("id_influence").className="nonaffiche";
	}

	if (nom_script_php == 'ajax_services.php') {
		document.getElementById("id_service").className="affiche";
		document.getElementById("id_fonction").className="nonaffiche";
		document.getElementById("id_influence").className="nonaffiche";
	}

	if (nom_script_php == 'ajax_fonctions.php') {
		document.getElementById("id_fonction").className="affiche";
		document.getElementById("id_influence").className="nonaffiche";
	}

	if (nom_script_php == 'ajax_decideurs.php') {
		document.getElementById("id_influence").className="affiche";
	}
	
	if (action == 'suppr') {
		if ((nature == 'populations') || (nature == 'motscles') || (nature == 'themes') || (nature == 'rubriques') || (nature == 'sousrubriques') || (nature == 'typesdocuments'))
			document.getElementById("checkbox_"+nom_id).className="nonaffiche";
		document.getElementById("suppr_"+nom_id).className="nonaffiche";
		document.getElementById("reactive_"+nom_id).className="affiche";
	}
	else 
		if (action == 'reactive') {
			if ((nature == 'populations') || (nature == 'motscles') || (nature == 'themes') || (nature == 'rubriques') || (nature == 'sousrubriques') || (nature == 'typesdocuments'))
				document.getElementById("checkbox_"+nom_id).className="affiche";
			document.getElementById("suppr_"+nom_id).className="affiche";
			document.getElementById("reactive_"+nom_id).className="nonaffiche";
		}
		else
			if (action == 'affichage_simple') {
				document.getElementById(nom_id).className="affiche";
				document.getElementById(nom_id+"_on").className="nonaffiche";
			}

   	for (i=0;i<items.length;i++)
    	{
		if (i == 0)
			document.getElementById(nom_id).innerHTML =items.item(i).firstChild.data;
		else // seul cas où il y a plus de données renvoyées : maj de la zone de recherche ; mise à jour de la combo suivante ET de la zone de résultats de recherche
			document.getElementById("resultats_recherche").innerHTML =items.item(i).firstChild.data;
    	}
  }
}

function form_focus(nom_form,champ) {
	document.nom_form.champ.focus();
 }

function str_repeat(i, m) { for (var o = []; m > 0; o[--m] = i); return(o.join('')); }

function sprintf () {
  var i = 0, a, f = arguments[i++], o = [], m, p, c, x;
  while (f) {
    if (m = /^[^\x25]+/.exec(f)) o.push(m[0]);
    else if (m = /^\x25{2}/.exec(f)) o.push('%');
    else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
      if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) throw("Too few arguments.");
      if (/[^s]/.test(m[7]) && (typeof(a) != 'number'))
        throw("Expecting number but found " + typeof(a));
      switch (m[7]) {
        case 'b': a = a.toString(2); break;
        case 'c': a = String.fromCharCode(a); break;
        case 'd': a = parseInt(a); break;
        case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
        case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
        case 'o': a = a.toString(8); break;
        case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
        case 'u': a = Math.abs(a); break;
        case 'x': a = a.toString(16); break;
        case 'X': a = a.toString(16).toUpperCase(); break;
      }
      a = (/[def]/.test(m[7]) && m[2] && a > 0 ? '+' + a : a);
      c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
      x = m[5] - String(a).length;
      p = m[5] ? str_repeat(c, x) : '';
      o.push(m[4] ? a + p : p + a);
    }
    else throw ("Huh ?!");
    f = f.substring(m[0].length);
  }
  return o.join('');
}


function ord (string) {
    var str = string + '';
    
    var code = str.charCodeAt(0);
    if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters)
        var hi = code;
        if (str.length === 1) {
            return code; // This is just a high surrogate with no following low surrogate, so we return its value;
                                    // we could also throw an error as it is not a complete character, but someone may want to know
        }
        var low = str.charCodeAt(1);
        if (!low) {
            
        }
        return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
    }
    if (0xDC00 <= code && code <= 0xDFFF) { // Low surrogate
        return code; // This is just a low surrogate with no preceding high surrogate, so we return its value;
                                // we could also throw an error as it is not a complete character, but someone may want to know
    }
    return code;
}


function encode(chaine)
{
	uid='';
	for (i=0;i<chaine.value.length;i++)
		uid=uid+sprintf("%02x",ord(chaine.value.charAt(i)));
		
	return uid;
};

function encode_value(chaine)
{
	uid='';
	for (i=0;i<chaine.length;i++)
		uid=uid+sprintf("%02x",ord(chaine.charAt(i)));
		
	return uid;
};

var Timer=null;
var Pas=3;
function moveLayer(Sens,contenu,support) {

	if (contenu) { 
		varcontenu=contenu;
		varsupport=support;
	}

   var Objet=document.getElementById(varcontenu);
    if(parseInt(Objet.style.top) + (Pas*Sens)>0)  {
      clearTimeout(Timer);
   }
   else if(parseInt(Objet.style.top) + (Pas*Sens)<-(Objet.offsetHeight-document.getElementById(varsupport).offsetHeight)) {
      clearTimeout(Timer);
   }
    else {
        Objet.style.top = (parseInt(Objet.style.top) + (Pas*Sens)) + "px";
   }
   Timer = setTimeout("moveLayer(" + Sens + ");", 30);
}
