
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 nombrep="";
var emailp="";
var cont=1;
var seccion="";
var pagina=0;
var region="";
var enviarcorreo="";
function mandarinfo(nombre,email)
{
nombrep=nombre;
emailp=email;
obtenerTextoServidor();
}

function obtenerTextoServidor() 
{
  var myurl = 'librerias/servidor.php';
  myRand = parseInt(Math.random()*999999999999999);
  var modurl = myurl+"?rand="+myRand+"&nombre="+nombrep+"&email="+emailp;
  http.open("GET", modurl, true);
  http.onreadystatechange = useHttpResponse;
  http.send(null);
}

function useHttpResponse() {
   if (http.readyState == 4) {
    if(http.status == 200) {
      var miTexto = http.responseText;
      document.getElementById('recibe').innerHTML = miTexto;
    }
  } else {
  document.getElementById('recibe').innerHTML = "<br><br><br><center><img src='imagenesplantilla/enviando.gif' width='116' height='32' /></center>";
  }
}

function vergaleria(numfin,hacer)
{
	if(hacer=="mas")
	{
		cont++;
	}
	else
	{
		cont--;
	}
	if(cont>=numfin)
	{
	
		cont=1;
	}
	if(cont<1)
	{
		cont=numfin;
	}	
obtenerImagendelServidor();
}

function obtenerImagendelServidor() 
{
  var myurl = 'librerias/galeria.php';
  myRand = parseInt(Math.random()*999999999999999);
  var modurl = myurl+"?rand="+myRand+"&numimg="+cont;
  http.open("GET", modurl, true);
  http.onreadystatechange = useHttpResponse1;
  http.send(null);
}
function useHttpResponse1() {
   if (http.readyState == 4) {
    if(http.status == 200) {
      var miTexto = http.responseText;
      document.getElementById('cambiarimagen').innerHTML = miTexto;
    }
  } else {
  document.getElementById('cambiarimagen').innerHTML = "<br><br><br><center><img src='imagenesplantilla/enviando.gif' width='116' height='32' /></center>";
  }
}

function obtenerlibros(seccionviene)
{

	seccion=seccionviene;
	obtenerLibrodelServidor();
	switch (seccion)
	{
		case "leyes":
		document.getElementById('titulo').innerHTML = "<img src='menucategorias/leyes.gif' width='125' height='20' />";
		break;
		case "codigos":
		document.getElementById('titulo').innerHTML = "<img src='menucategorias/codigos.gif' width='125' height='20' />";
		break;
		case "obras":
		document.getElementById('titulo').innerHTML = "<img src='menucategorias/obras.gif' width='125' height='20' />";
		break;
	}
}

function obtenerLibrodelServidor() 
{
  var myurl = 'librerias/libros.php';
  myRand = parseInt(Math.random()*999999999999999);
  var modurl = myurl+"?rand="+myRand+"&seccion="+seccion+"&pagina=1";
  http.open("GET", modurl, true);
  http.onreadystatechange = useHttpResponse2;
  http.send(null);
}

function useHttpResponse2() {
   if (http.readyState == 4) {
    if(http.status == 200) {
      var miTexto = http.responseText;
      document.getElementById('libros').innerHTML = miTexto;
    }
  } else {
  document.getElementById('libros').innerHTML = "<table width='600' cellspacing='0' cellpadding='0' border='0'><tr><td><center><img src='imagenesplantilla/cargadorlibros.gif' width='156' height='37' /></center></td></tr></table>";
  }
}

function cambiopagina(num_pag)
{

pagina=num_pag;
obtenerPaginadelServidor();
}

function obtenerPaginadelServidor() 
{
  var myurl = 'librerias/libros.php';
  myRand = parseInt(Math.random()*999999999999999);
  var modurl = myurl+"?rand="+myRand+"&seccion="+seccion+"&pagina="+pagina;
  http.open("GET", modurl, true);
  http.onreadystatechange = useHttpResponse3;
  http.send(null);
}

function useHttpResponse3() {
   if (http.readyState == 4) {
    if(http.status == 200) {
      var miTexto = http.responseText;
      document.getElementById('libros').innerHTML = miTexto;
    }
  } else {
  document.getElementById('libros').innerHTML = "<table width='600' cellspacing='0' cellpadding='0' border='0'><tr><td><center><img src='imagenesplantilla/cargadorlibros.gif' width='156' height='800' /></center></td></tr></table>";
  }
}

function traepuntosdeventa(region1)
{
	
	region=region1;
	obtenerInfodePunto();
}

function obtenerInfodePunto() 
{
  var myurl = 'librerias/traepuntos.php';
  myRand = parseInt(Math.random()*999999999999999);
  var modurl = myurl+"?rand="+myRand+"&provincia="+region;
  http.open("GET", modurl, true);
  http.onreadystatechange = useHttpResponse4;
  http.send(null);
}
function useHttpResponse4() {
   if (http.readyState == 4) {
    if(http.status == 200) {
      var miTexto = http.responseText;
      document.getElementById('mostrar').innerHTML = miTexto;
    }
  } else {
  document.getElementById('mostrar').innerHTML = "<center><img src='imagenesplantilla/cargador.gif' width='114' height='32' alt=''></center>";
  }
}

function revisar(nombre,telefono,ciudad,pais,email,comentario)
{
	//alert("Nombre: "+nombre+"Telefono: "+telefono+"Ciudad: "+ciudad+"Pais: "+pais+" Email:"+email+"Comentario: "+comentario);
	enviarcorreo="&nombre="+nombre+"&telefono="+telefono+"&ciudad="+ciudad+"&pais="+pais+"&email="+email+"&comentarios="+comentario;	
	obtenercontacto();
}


function obtenercontacto() 
{
  var myurl = 'librerias/enviocorreo.php';
  myRand = parseInt(Math.random()*999999999999999);
  var modurl = myurl+"?rand="+myRand+enviarcorreo;

  http.open("GET", modurl, true);
  http.onreadystatechange = useHttpResponse5;
  http.send(null);
}
function useHttpResponse5() {
   if (http.readyState == 4) {
    if(http.status == 200) {
      var miTexto = http.responseText;
      document.getElementById('contactoformulario').innerHTML = miTexto;
    }
  } else {
  document.getElementById('contactoformulario').innerHTML = '<table width="539" height="69" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td width="539" height="14"><img src="contacto/header.jpg" width="539" height="14" /></td></tr><tr><td height="40" valign="top" background="contacto/cuerpo.gif"><table width="483" height="320" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td width="518" height="320" valign="middle"></div><div align="center"><font style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-variant: normal; font-weight: bolder; color: #545454;"><img src="imagenesplantilla/cargador.gif" width="114" height="32" alt=""></font></div></td></tr></table></td></tr><tr><td height="14"><img src="contacto/footer.gif" width="539" height="14" /></td></tr></table>';
  }
}
