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="livesearch.php";
	url=url+"?q="+str.value;
	url=url+"&t="+str.name;
	url=url+"&check=true";
	url=url+"&live="+document.formulaireRecherche.live.value;
	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='<a href="javascript:;" onclick="hideLivesearch();" class="closelivesearch">&nbsp;</a>';
  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="livesearch.php";
url=url+"?q="+str.value;
url=url+"&t="+str.name;
if(document.formulaireRecherche.live.value == "FDC")
{
	url=url+"&live=FDC";
}
else if(document.formulaireRecherche.live.value == "TER")
{
	url=url+"&live=TER";
}
else if(document.formulaireRecherche.live.value == "CLC")
{
	url=url+"&live=CLC";
}
if((document.formulaireRecherche.live.value == "IMO" || document.formulaireRecherche.live.value == "BPR") && document.formulaireRecherche.action.value=='affichage')
{
	url=url+"&dep_ref=".document.formulaireRecherche.departement_ref.value;
}
	
	
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged ;
//alert(url);
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}


function stateChanged()
{
if (xmlhttp.readyState==4)
  {
  //document.getElementById(currSearch).innerHTML='<a href="javascript:;" onclick="hideLivesearch();" class="closelivesearch">&nbsp;</a>';
  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 hideLivesearch()
{
 document.getElementById(currSearch).innerHTML="";
 document.getElementById(currSearch).style.border="0px";
 document.getElementById(currSearch).style.backgroundColor="transparent";
}

function assignOu(id,string)
{
 document.formulaireRecherche.elements['ou'].value = string;
 //document.formulaireRecherche.elements['ou2'].value = id;
 hideLivesearch();
 checkLocation(document.formulaireRecherche.elements['ou']);
}

function assignBien_ville(id,string)
{
 document.formulaireRecherche.elements['bien_ville'].value = string;
 hideLivesearch();
 checkLocation(document.formulaireRecherche.elements['bien_ville']);
}

function assignProprietaire_ville(id,string)
{
 document.formulaireRecherche.elements['proprietaire_ville'].value = string;
 hideLivesearch();
 checkLocation(document.formulaireRecherche.elements['proprietaire_ville']);
}

function assignMotcle(id,string)
{
 document.formulaireRecherche.elements['motcle'].value = string;
 hideLivesearch();
}
function assignVillebien2(codepostal,insee,string)
{
 document.formulaire.elements['offre_villebien'].value = string;
 document.formulaire.elements['offre_geoloc_codes_postaux'].value = codepostal;
 document.formulaire.elements['offre_geoloc_codes_insee'].value = insee;
 document.formulaire.elements['offre_geoloc_villes'].value = string;
 hideLivesearch();
}
function assignVillebien(codepostal,insee,string)
{
 document.formulaireRecherche.elements['offre_villebien'].value = string;
 document.formulaireRecherche.elements['offre_geoloc_codes_postaux'].value = codepostal;
 document.formulaireRecherche.elements['offre_geoloc_codes_insee'].value = insee;
 document.formulaireRecherche.elements['offre_geoloc_villes'].value = string;
 hideLivesearch();
}
