var sustituir = true;
var oXMLhttp;

function buscarTiendas()
{
//	sustituir = true;
	var ciudad = "caracas";

 	oXMLhttp = zXmlHttp.createRequest();
 	
 	var ciuF=document.getElementById("ciudad");
 	if (ciuF) {
 		ciudad=ciuF.value;
 	}
 	
	oXMLhttp.open("get","http://www.farmatodo.com/xml/tiendas.asp?ciudad="+ciudad+"&servicios=KODAK,FR-1HORA&servor=1",true);

	oXMLhttp.onreadystatechange = function() {

		if (oXMLhttp.readyState == 4) {
			actualizarListado();
	    }
	};

	oXMLhttp.send(null);
	
}	

function actualizarListado() {

	
	var doc= oXMLhttp.responseXML;
	var raiz = doc.documentElement;
	var resumido = false;
	var txtHR = "";
	
	if (raiz.childNodes.length > 5 ) {
	    resumido = true;
	    txtHr = "";
	} else {
	    resumido = false;
	}

    document.getElementById("listado").innerHTML = "";
	
	for (var i = 0; i < raiz.childNodes.length; i++)
	{
		var tienda = raiz.childNodes[i];
		
		if (tienda.attributes != null)
	    {
		    var codigo = tienda.getAttribute("codigo");
    		
		    var currentChild = tienda.firstChild;
    		
		    do
		    {
		        switch (currentChild.tagName)
		        {
				    case "nombre":
					    sNombre = currentChild.text;
					    break;
				    case "horario":
					    sHorario = currentChild.text;
					    break;
				    case "telefonos":
					    sTelefonos = currentChild.text;
					    break;
				    case "direccion":
					    sDireccion = currentChild.text;
					    break;
				    case "gerente":
					    sGerente = currentChild.text;
					    break;
				    case "regente":
					    sRegente = currentChild.text;
					    break;
				    default:
					    break;
			    }
		    }
		    while (currentChild = currentChild.nextSibling);
    		
/*		    if (sustituir)
		    {
			    document.getElementById("listado").innerHTML = "";
			    sustituir=false;
		    }*/
    		
		    var separador;
		    if (i==(raiz.childNodes.length - 1))
		    {
			    separador="";
		    }
		    else
		    {
			    separador=txtHR;
		    }
    		
		    if (resumido)
		    {
			    document.getElementById("listado").innerHTML +=	"<h2>"+
			    "<a href=\"/farmacias/mapa.asp?tienda="+codigo+"\"> "+sNombre+"</a></h2>";
            }
            else
            { 
        	    document.getElementById("listado").innerHTML +=	"<h2 style=\"margin-bottom: 5px;\"> "+
        	    "<a href=\"/farmacias/mapa.asp?tienda="+codigo+"\">"+sNombre+"</a>"+
			    "</h2><table class=\"listado\" >"+
			    "<tr><th>Horario:   </th><td>"+sHorario+"</td></tr>"+
			    "<tr><th>Teléfonos: </th><td>"+sTelefonos+"</td></tr>"+
			    "<tr><th>Dirección: </th><td>"+sDireccion+"</td></tr>"+
	 		    "</table>"+
	 		    "<a href=\"/farmacias/mapa.asp?tienda="+codigo+"\"><img src=\"../img/botones/foto-y-mapa.gif\" class=\"right\" width=\"85\" height=\"23\" style=\"margin-right: 20px;\" alt=\"Ver Tiendas\" /></a>"+
	            separador;
            }
        }
	}
}
