

function set_insee(val_ville,val_cp)
{
	document.getElementsByName("insee_bien")[0].value=val;
	document.getElementsByName("ajax_ville")[0].innerHTML=val_ville;
	document.getElementById("ajax_cp").style.visibility ='hidden';
}

function alert_ajax(xhr)
{
    if (xhr.readyState==4) 
    {
    	var tmp="";
    
    	var docXML= xhr.responseXML;
    	var items = docXML.getElementsByTagName("insee")
    	//on fait juste une boucle sur chaque element "donnee" trouvé
    	for (i=0;i<items.length;i++)
    	{
    		ina=items.item(i).firstChild.data;
    		
    		tmp=tmp+"<div onClick=\"set_insee("+items.item(i).attributes[0].nodeValue+",'"+ina+"',"+items.item(i).attributes[1].nodeValue+")\" id='"+i+"'><font color='#0000DD'>"+ina+"</font></div>";
    	}
    	document.getElementById("ajax_cp").innerHTML=tmp;

    	document.getElementById("ajax_cp").style.visibility ='visible';
    	
    }
}


function ajax(ville)
{ 
    var xhr=null;
  alert("rr");  
    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); };
    
    
    //on appelle le fichier reponse.txt
    xhr.open("GET", "search_insee.php?ville="+ville, true);
    xhr.send(null);
}

function nouvellefenetre(img) {
 mafenetre =
 window.open(img, "photo : ".img, ",width=1200,height=900,scrollbars");
 mafenetre.focus();
}


function draw_form(xhr)
{
    if (xhr.readyState==4) 
    {
    	var tmp="";
    	tmp=tmp+"<form name='form2' method='post' action='index.php'>";
		tmp=tmp+"<table  border='0' cellspacing='0' cellpadding='1'>";
		tmp=tmp+"<tr>";
		tmp=tmp+"<td>&nbsp;</td>";
		tmp=tmp+"<td align='right' class='pt-texte'>&nbsp;</td>";
		tmp=tmp+"<td>&nbsp;</td>";
		tmp=tmp+"<td class='pt-texte'>&nbsp;</td>";
		tmp=tmp+"</tr>";
                

    	var docXML= xhr.responseXML;
    	var items = docXML.getElementsByTagName("criteres")
    	//on fait juste une boucle sur chaque element "donnee" trouvé
    	for (i=0;i<items.length;i++)
    	{
    		tmp=tmp+"<tr>";
			tmp=tmp+"<td><img src='images/pixel.gif' width='45' height='1'></td>";
			tmp=tmp+"<td align='right' class='pt-texte'>"+items.item(i).attributes[2].nodeValue+"</td>";
			tmp=tmp+"<td><img src='images/pixel.gif' width='10' height='8'></td>";
			tmp=tmp+"<td class='pt-texte'>";
                
    		ina=items.item(i);
    		var selection = ina.getElementsByTagName("select")
    		tmp=tmp+"<Select name='"+items.item(i).attributes[1].nodeValue+"' class='champ' onChange='document.form2.submit()'>";
    		
    		for (is=0;is<selection.length;is++)
    		{
  				tmp=tmp+"<option ";
  				if(selection.item(is).attributes[1].nodeValue=='1')
  				tmp=tmp+" selected ";
  				tmp=tmp+ " value='"+selection.item(is).attributes[0].nodeValue+"' >"+selection.item(is).firstChild.data+"</option>";			
    		}
    		tmp=tmp+"</Select>";
    		tmp=tmp+"</td></tr>";
    		
    		
//tmp=tmp+"<div onClick=\"set_insee("+items.item(i).attributes[0].nodeValue+",'"+ina+"',"+items.item(i).attributes[1].nodeValue+")\" id='"+i+"'><font color='#0000DD'>"+ina+"</font></div>";    		
    	}
    	
    	/*
    	tmp=tmp+"<tr>";
                  tmp=tmp+"<td>&nbsp;</td>";
                  tmp=tmp+"<td align='right' class='pt-texte'>CP / Ville</td>";
                  tmp=tmp+"<td>&nbsp;</td>";
                  tmp=tmp+"<td class='pt-texte'><input name='textfield' type='text' class='champ2'></td>";
                tmp=tmp+"</tr>";
        */
                tmp=tmp+"<tr>";
                  tmp=tmp+"<td>&nbsp;</td>";
                  tmp=tmp+"<td colspan='3'><input name='menu' type='hidden' value='recherche'><a href='#' onClick='document.form2.submit()'><img src='images/btn_trouver.gif' width='233' height='21' border='0' ></a></td>";
                tmp=tmp+"</tr>";
                tmp=tmp+"<tr>";
                  tmp=tmp+"<td>&nbsp;</td>";
                  //tmp=tmp+"<td colspan='3'><a href='#' class='lien'>&gt; Recherche avanc&eacute;e</a></td>";
                  tmp=tmp+"</tr>";
              tmp=tmp+"</table>";
           tmp=tmp+"</form>";
            
            
    	document.getElementById("moteur_recherche").innerHTML=tmp;

    	//document.getElementById("moteur_recherche").style.visibility ='visible';
    	
    }
}



function ajax_search(type_bien,cle_tranche)
{ 
    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() { draw_form(xhr); };
    
    
    //on appelle le fichier reponse.txt
    xhr.open("GET", "admin/search_form.php?type_bien="+type_bien+"&cle_tranche="+cle_tranche, true); 
    //?ville="+ville
    xhr.send(null);
}

