function parsea_res(resultado)
{
	if (resultado=='NOK')
	{
		clearInterval(id_timer_progress);
		document.getElementById('progress_bar2').style.display='none';
		document.getElementById('content').innerHTML='Error en la búsqueda (1)';
		return 0;
	}
	if (resultado=='ERRBBDD')
	{
		clearInterval(id_timer_progress);
		document.getElementById('progress_bar2').style.display='none';
		document.getElementById('content').innerHTML='Error en la búsqueda (2)';
		return 0;
	}
	if (resultado=='ERRAUTH')
	{
		clearInterval(id_timer_progress);
		document.getElementById('progress_bar2').style.display='none';
		document.getElementById('content').innerHTML='Error en la búsqueda (3)';
		return 0;
	}
	return 1;
}
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
 return xmlhttp;

}

var http;
var AJAX=0;
function inicia_XML()
{
	http=getHTTPObject();
	if (http===false)
		AJAX=0;
	else
		AJAX=1;
}

function rXML_busqueda()
{
	if (http.readyState==4)
	{
		if (http.status == 200)
		{
			//alert(http.responseText);
			var xmlDoc = http.responseXML;
			var stat= xmlDoc.getElementsByTagName('stat').item(0).firstChild.data;
			if (!parsea_res(stat))
				return;
			var cad="";
			var numres= xmlDoc.getElementsByTagName('nres').item(0).firstChild.data;
			var resultados=xmlDoc.getElementsByTagName('res');
			if (numres>0)
			{
				cad+="<table width='100%' cellpadding='2' cellspacing='0' class='tx11'><tr><td align='center'><b>"+numres+" resultado";
				if (numres>1) cad+='s';
				cad+=" encontrado";
				if (numres>1) cad+='s';
				cad+="</td></tr>";

				for (x=0;x<resultados.length;x++)
				{
					var titulo=resultados.item(x).getElementsByTagName('titu').item(0).firstChild.data;
					var fichero=resultados.item(x).getElementsByTagName('fich').item(0).firstChild.data;
					cad+="<tr><td onclick=\"document.contenido.location.href='./contenidos/"+fichero+"'\"><a class='amenu' target='contenido' href='./contenidos/"+fichero+"?resalta="+termino_busqueda+"' style='height:17px'>"+titulo+"</a></td></tr>";
				}
			}
			else
				cad="<table width='100%' cellpadding='4' cellspacing='0' class='tx11'><tr><td align='center'><b>No se han encontrado resultados</b></td></tr></table>";
			clearInterval(id_timer_progress);
		   	document.getElementById('progress_bar2').style.display='none';
			document.getElementById('content2').innerHTML=cad;
		}
        else
        {
			clearInterval(id_timer_progress);
		   	document.getElementById('progress_bar2').style.display='none';
			document.getElementById('content2').innerHTML='Error en la búsqueda';
		}
	}
}
function r_busqueda(valores)
{
	var cad="";
	var p=valores.split('#');
	var numres=p[0];

	if (numres>0)
	{
		cad+="<table width='100%' cellpadding='2' cellspacing='0' class='tx11'><tr><td align='center'><b>"+numres+" resultado";
		if (numres>1) cad+='s';
		cad+=" encontrado";
		if (numres>1) cad+='s';
		cad+="</td></tr>";
		var valores=p[1].split('@');
		for (x=0;x<valores.length;x++)
		{
			var a=valores[x].split('$');
			var titulo=a[0];
			var fichero=a[1];
			cad+="<tr><td onclick=\"document.contenido.location.href='./contenidos/"+fichero+"'\"><a class='amenu' target='contenido' href='./contenidos/"+fichero+"?resalta="+termino_busqueda+"' style='height:17px'>"+titulo+"</a></td></tr>";
		}
	}
	else
		cad="<table width='100%' cellpadding='4' cellspacing='0' class='tx11'><tr><td align='center'><b>No se han encontrado resultados</b></td></tr></table>";
	clearInterval(id_timer_progress);
	document.getElementById('progress_bar2').style.display='none';
	document.getElementById('content2').innerHTML=cad;
}
function busca_online(termino)
{
	if (AJAX)
	{
		http.open("GET", "./php/buscador.php?xml=1&termino="+termino+"&rand="+Math.random()+Math.random()+Math.random(), true);
		http.onreadystatechange = rXML_busqueda;
		http.send(null);
	}
	else
	{
		document.getElementById('ifr').src="./php/buscador.php?xml=0&termino="+termino+"&rand="+Math.random()+Math.random()+Math.random();
	}
}