var xmlhttp;
var xmlhttp2;
var currSearch;
var ouOk = 1;
var prem=0;

function checkLocation(str)
{

	xmlhttp2=GetXmlHttpObject()
	if (xmlhttp2==null)
	  {
	  alert ("Your browser does not support XML HTTP Request");
	  return;
	  }
	var url="search.php";
	url=url+"?q="+str.value;
	url=url+"&check=true";
	url=url+"&sid="+Math.random();
	xmlhttp2.open("GET",url,true);
	xmlhttp2.send(null);
	xmlhttp2.onreadystatechange=function() {
	if ( (xmlhttp2.readyState == 4) && (xmlhttp2.status == 200) ) {
		ouOk=xmlhttp2.responseText;
		prem=444;
		}
	}

}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {
  document.getElementById(currSearch).innerHTML='';
  document.getElementById(currSearch).innerHTML+=xmlhttp.responseText;
  document.getElementById(currSearch).style.border="1px solid #A5ACB2";
  document.getElementById(currSearch).style.backgroundColor="#ffffff";
  }
}

function showResult(str,idsearch)
{

currSearch = idsearch;
if (str.length<=1)
  {
  document.getElementById(currSearch).innerHTML="";
  document.getElementById(currSearch).style.border="0px";
  document.getElementById(currSearch).style.backgroundColor="transparent";
  return;
  }
xmlhttp=GetXmlHttpObject()
if (xmlhttp==null)
  {
  alert ("Your browser does not support XML HTTP Request");
  return;
  }

var url="search.php";
url=url+"?q="+str.value;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged ;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}


function stateChanged()
{
if (xmlhttp.readyState==4)
  {
  document.getElementById(currSearch).innerHTML='';
  document.getElementById(currSearch).innerHTML+=xmlhttp.responseText;
  document.getElementById(currSearch).style.border="1px solid #A5ACB2";
  document.getElementById(currSearch).style.backgroundColor="#ffffff";
  }
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

function hidesearch()
{
 document.getElementById(currSearch).innerHTML="";
 document.getElementById(currSearch).style.border="0px";
 document.getElementById(currSearch).style.backgroundColor="transparent";
}

function assignOu(id,string)
{
	
 var tab = string.split(';');
 document.formulaire.elements['dep'].value = tab[0];

 document.formulaire.elements['ville'].value = tab[1];
 hidesearch();
 checkLocation(document.formulaire.elements['ville']);
}

