// JavaScript Document
function getXMLHTTPRequest() {
try {
req = new XMLHttpRequest();
} catch(err1) {
  try {
  req = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (err2) {
    try {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (err3) {
      req = false;
    }
  }
}
return req;
}

var http = getXMLHTTPRequest();
var http2 = getXMLHTTPRequest();
//#### Menu ####
function llamarMenu()
{
	var myurl = 'menu.php';
	//myRand = parseInt(Math.random()*999999999999999);
	//var modurl = myurl+"&rand="+myRand;
	http.open("GET", myurl, true);
	http.onreadystatechange = mostrarMenu;
	http.send(null);
}

function mostrarMenu()
{
	if (http.readyState == 4 || http.readyState == 0)
	{
		
		if(http.status == 200)
		{
			var respuesta = http.responseText
		   document.getElementById('menu').innerHTML = respuesta;
		   total();

		}
  	} else {
  document.getElementById('menu').innerHTML = '<img src="loading.gif"/>';
  }
}

//#### Top ####

function llamarTop(cat,sub,pag)
{

	var myurl = 'top.php?cat='+encodeURIComponent(cat)+'&sub='+encodeURIComponent(sub)+'&pagina='+pag;
	//alert(myurl);
	//myRand = parseInt(Math.random()*999999999999999);
	//var modurl = myurl+"&rand="+myRand;
	http.open("GET", myurl, true);
	http.onreadystatechange = mostrarTop;
	http.send(null);
}

function mostrarTop()
{
	if (http.readyState == 4 || http.readyState == 0)
	{
		
		if(http.status == 200)
		{
			var respuesta = http.responseText
			if(respuesta == "")
			{
				document.getElementById('top').innerHTML = "<br><span class=\"texto\">No hay resultados para esta busqueda</span>";
				document.getElementById('foto').innerHTML = '';
			}
			else
			{
				document.getElementById('top').innerHTML = respuesta;	
				document.getElementById('foto').innerHTML = '';
			}
		   
		}
  	} else {
  document.getElementById('top').innerHTML = '<img src="loading.gif"/>';
  }
}
//#### Foto ####
function llamarFoto(id)
{
	var myurl = 'foto.php?id='+id;
	//myRand = parseInt(Math.random()*999999999999999);
	//var modurl = myurl+"&rand="+myRand;
	http.open("GET", myurl, true);
	http.onreadystatechange = mostrarFoto;
	http.send(null);
}

function mostrarFoto()
{
	if (http.readyState == 4 || http.readyState == 0)
	{
		
		if(http.status == 200)
		{
			var respuesta = http.responseText
		   document.getElementById('foto').innerHTML = respuesta;
		   //document.location = '#fotoini';
		}
  	} else {
  document.getElementById('foto').innerHTML = '<img src="loading.gif"/>';
  }
}

//#### TAGS ####
function llamarTags(tag,pag)
{

	var myurl = 'top.php?acc=tags&tag='+encodeURIComponent(tag)+'&pagina='+pag;
	//alert(myurl);
	//myRand = parseInt(Math.random()*999999999999999);
	//var modurl = myurl+"&rand="+myRand;
	http.open("GET", myurl, true);
	http.onreadystatechange = mostrarTop;
	http.send(null);
}

//#### BUSCADOR ####
function llamarBuscador(texto,pag)
{
	if(texto =="")
	{
		var texto = document.form1.texto.value
	}
	var myurl = 'top.php?acc=buscar&texto='+encodeURIComponent(texto)+'&pagina='+pag;
	//alert(myurl);
	//myRand = parseInt(Math.random()*999999999999999);
	//var modurl = myurl+"&rand="+myRand;
	http.open("GET", myurl, true);
	http.onreadystatechange = mostrarTop;
	http.send(null);
}

//#### BUSCADOR ####
function llamarTodas(pag)
{
	var myurl = 'top.php?acc=todas&pagina='+pag;
	//alert(myurl);
	//myRand = parseInt(Math.random()*999999999999999);
	//var modurl = myurl+"&rand="+myRand;
	http.open("GET", myurl, true);
	http.onreadystatechange = mostrarTop;
	http.send(null);
}

//#### FLASH ####
function llamarFlash()
{
	var texto = document.form1.texto.value
	var myurl = 'flash.html';
	//alert(myurl);
	//myRand = parseInt(Math.random()*999999999999999);
	//var modurl = myurl+"&rand="+myRand;
	http.open("GET", myurl, true);
	http.onreadystatechange = mostrarTop;
	http.send(null);
}
//#### CONCEJOS ####
function llamarconcejo(conc,pag)
{

	var myurl = 'top.php?acc=concejos&conc='+encodeURIComponent(conc)+'&pagina='+pag;
	//alert(myurl);
	//myRand = parseInt(Math.random()*999999999999999);
	//var modurl = myurl+"&rand="+myRand;
	http.open("GET", myurl, true);
	http.onreadystatechange = mostrarTop;
	http.send(null);
}
//#### TOTAL ####

function total()
{
	var myurl = 'total.php';
	//alert(myurl);
	myRand = parseInt(Math.random()*999999999999999);
	var modurl = myurl+"?rand="+myRand;
	http.open("GET", modurl, true);
	http.onreadystatechange = mostrarTotal;
	http.send(null);
}

function mostrarTotal()
{
	if (http.readyState == 4 || http.readyState == 0)
	{
		
		if(http.status == 200)
		{
			var respuesta = http.responseText
			document.getElementById('total').innerHTML = respuesta;
			//document.location = '#fotoini';
		}
  	} else {
  document.getElementById('total').innerHTML = '';
  }
}