
function ajax() {
        var ajax = null;
        if (window.XMLHttpRequest) {
                try {
                        ajax = new XMLHttpRequest();
                }
                catch(e) {}
        }
        else if (window.ActiveXObject) {
                try {
                        ajax = new ActiveXObject("Msxm12.XMLHTTP");
                }
                catch (e){
                        try{
                                ajax = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (e) {}
                }
        }
        return ajax;
}

function request(str,req,Idsource, Idcible) {
	if(!window['myAjax'+Idsource+Idcible]){
	//	alert ('existe pas');
  		window['myAjax'+Idsource+Idcible] = ajax();
	}
	//N'oubliez pas de modifier le chemi du fichier au besoin.
        window['myAjax'+Idsource+Idcible].open("POST", "http://"+document.domain+"/librairies/autocomplete/"+req, true);
        window['myAjax'+Idsource+Idcible].onreadystatechange = function() { 
	   if(window['myAjax'+Idsource+Idcible].readyState == 4) {
			//alert(window['myAjax'+Idsource+Idcible].responseText); // DEBUG MODE
			//document.write(window['myAjax'+Idsource+Idcible].responseText);
			//eval(window['myAjax'+Idsource+Idcible].responseText);
			document.getElementById(Idcible).innerHTML = window['myAjax'+Idsource+Idcible].responseText;
            document.getElementById(Idcible).style.display = "block";
   			var moo = '';
		 }
		
		//alert(window['myAjax'+Idsource+Idcible].readyState);
		return window['myAjax'+Idsource+Idcible].readyState;
	} ;
        window['myAjax'+Idsource+Idcible].setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        window['myAjax'+Idsource+Idcible].send("search="+str+"&source="+Idsource+"&cible="+Idcible);
}

function selected(choice, source, cible){
        document.getElementById(source).value = choice;
        document.getElementById(cible).style.display = "none";
}