function autoCompleteTag(sType,sInput,sDestination, iLimit, sAction ) {

	var oInput = document.getElementById(sInput);
	var iLastPos = oInput.value.lastIndexOf(",");
	var sSearch = oInput.value.substring(iLastPos);
	
	if (sAction==undefined || sAction == "") {
		sAction = "replacevalueToInput";
	}
	
	if (sSearch.length >3) {
		Updater( "../ajax/ajax_autocomplete.ajax.php", sDestination,"type="+sType+"&search="+sSearch+"&limit="+iLimit+"&destination="+sInput+"&action="+sAction);
	}
	
}

function addvalueToInput(sValue, sDestination) {
	var oInput = document.getElementById(sDestination);
	oInput.value += sValue;
}
function replacevalueToInput(sValue, sDestination) {
	var oInput = document.getElementById(sDestination);
	oInput.value = sValue;
}
function setInnerHtml(sValue,sDestination) {
	var oElement = document.getElementById(sDestination);
	if (oElement != undefined) {
		oElement.innerHTML = sValue;
	}
	else {
		alert("Erreur id rechercher non trouvé :"+sDestination);
	}
}

/* ------------------------------   AJAX --------------------------------------- */

function GetXmlHttpObject()
{ 
	var objXMLHttp=null;
	if (window.XMLHttpRequest)
		objXMLHttp=new XMLHttpRequest();
	else if (window.ActiveXObject)
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	return objXMLHttp;
} 


function Updater( sUrl, sDiv, sParam)
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert("Votre navigateur ne supporte pas le javascript.");
		return false;
	} 
	var url=sUrl;

	xmlHttp.onreadystatechange = function (){
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
		{
			setInnerHtml(xmlHttp.responseText,sDiv)
		}
	}
	
	var params = sParam;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
	xmlHttp.send(params);
	//xmlHttp = "";
	
	return true;
	
} 

function getDataFromForm(sForm) {
	
	var data="";
	var key=0;
	oForm = document.getElementById(sForm);
	
	if (oForm != undefined && oForm !=null) {
		for (key=0;key<oForm.elements.length;key++) {
			data+=escape(oForm.elements[key].name)+"="+escape(oForm.elements[key].value)+"&";
		}
		data = data.substr(0, data.length-1);
		return data ;
	}else {
		alert(sForm + " "+ oForm);
		return false;
	}
}

function SendAjaxForm ( sUrl, sDivReturn, sForm)
{
	
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert("Votre navigateur ne supporte pas le javascript.");
		return false;
	} 
	
	var url=sUrl;
	
	xmlHttp.onreadystatechange = function (){
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
		{		
					
				setInnerHtml(xmlHttp.responseText,"divmessage")
				DisplayAndHide("divhide","inline");
		}
	}
	
	var params = getDataFromForm(sForm) ;
	
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
	xmlHttp.send(params);
	
	return true;
} 

function GetEvalData ( sUrl, sParam)
{
	
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert("Votre navigateur ne supporte pas le javascript.");
		return false;
	} 
	
	var url=sUrl;
	var params = sParam ;
		
	xmlHttp.onreadystatechange = function (){
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
		{		
				eval (xmlHttp.responseText);
		}
	}
	
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
	xmlHttp.send(params);
	
	return true;
} 