/*
   +----------------------------------------------------------------------+
   | XMLHttpRequest javascript file
   +----------------------------------------------------------------------+
   | Este codigo esta sujeto a la licencia GPL.                           |
   | Si no tienes una copia de dicha licencia, puedes hacer:              |
   | http://www.google.com -> Buscar "GPL" -> Voy a tener suerte.         |
   | Y no pongas excusas como "No tengo Internet", se cayo Google,        | 
   | o se me rompió el teclado.                                           |
   +----------------------------------------------------------------------+
   | Publicado en: MaestrosDelWeb.com                                     |
   |        http://www.maestrosdelweb.com                                 |
   +----------------------------------------------------------------------+
   | Autor: Daniel "Pichongol" Lopez <pichongol@yahoo.com>                |
   |        http://pichongol.blogspot.com                                 |
   +----------------------------------------------------------------------+
   +----------------------------------------------------------------------+
   | Chequea http://pichongol.blogspot.com por nuevas versiones,          |
   | dudas y consultas                                                    |
   +----------------------------------------------------------------------+
*/

/**** Objeto XMLHttpRequest *****/
var xmlHttp=null;
try {
	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
	try {
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	 }
	catch(e) {}
}

/**** Forma nativa ****/
if (xmlHttp==null)
	xmlHttp=new XMLHttpRequest();


/********* Realiza la peticion y entrega el resultado como texto *************/
function ajaxPerform(sync, xmlMessage, responser, method){
	xmlHttp.open(method, responser, sync);
    xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    
    xmlHttp.send(xmlMessage);
    return xmlHttp.responseText;
}

// envia el formulario
function buildPOST(theForm) { 
    var qs = '';
    for (e=0;e<theForm.elements.length;e++) {
        if (theForm.elements[e].type=="checkbox"){
          if (theForm.elements[e].checked==true){
            var name = theForm.elements[e].name;
            qs+=(qs=='')?'':'&';
            qs+= name+'='+escape(theForm.elements[e].value);
          }
        }else{
          if (theForm.elements[e].name!='') {
              var name = theForm.elements[e].name;
              qs+=(qs=='')?'':'&';
              qs+= name+'='+escape(theForm.elements[e].value);
          }
        }
    }
    return qs;
}














/*---------------SUBIR PORTADAS --------------------------*/


var http=createRequestObject();
var uploader="";
var uploadDir="";
var dirname="";
var filename="";
var timeInterval="";
var idname="";

function createRequestObject() {
    var obj;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
    	return new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
    	return new XMLHttpRequest();
    }
}
function traceUpload() {
   http.onreadystatechange = handleResponse;
   http.open("GET", 'http://www.librofilia.com/ajax_colaboracionportada.php?uploadDir='+uploadDir+'&dirname='+dirname+'&filename='+filename+'&uploader='+uploader);
   http.send(null);
}
function handleResponse() {
	if(http.readyState == 4){
		var response=http.responseText;
		if(response.indexOf("portada se subi") != -1){
			clearInterval(timeInterval);
			//document.getElementById('loading'+idname).innerHTML="";
		}
        document.getElementById(uploaderId).innerHTML=response;
    }
    else {
    	document.getElementById(uploaderId).innerHTML='<img src="http://www.librofilia.com/imagenes/cargando.gif"> Subiendo portada';
    }
}
function uploadFile(obj, dname, fich) {
	uploadDir=obj.value;
	idname=obj.name;
	dirname=dname;
	//filename=uploadDir.substr(uploadDir.lastIndexOf('\\')+1);
	filename=fich+".jpg";
	//document.getElementById('loading'+idname).innerHTML="<img src='loading.gif' alt='loading...' />";
	uploaderId = 'uploader'+obj.name;
	uploader = obj.name;
	document.getElementById('formName'+obj.name).submit();
	timeInterval=setInterval("traceUpload()", 1500);
}

/*----------------------------------------      HASTA AQUI LO DE SUBIR         */


































/*** funciones de procesado ***/
function remote_login(form){
	xmlMessage = buildPOST(form);
	xmlMessage+="&action=login";
	var result = ajaxPerform(false, xmlMessage, 'http://www.librofilia.com/ajax_validar_usuario.php', "post");
	if(result=="0"){
		document.getElementById("login_err_msg").innerHTML = "Usuario/contrase&ntilde;a no v&aacute;lidos.";
		document.getElementById("login_err_msg").style.visibility = "visible";
	}
	else {
	  window.location = "http://www.librofilia.com"
		//document.getElementById("divbienvenido").innerHTML="<b>Bienvenido</b> "+result;
	}
}


function procesar_comentario_personal(form){
	xmlMessage = buildPOST(form);
	//xmlMessage+="&action=login";

	var result = ajaxPerform(false, xmlMessage, 'http://www.librofilia.com/ajax_comentario_personal.php', "post");
	var num_form;
  if (arguments.length==2){
    num_form=arguments[1];
  }else{
    num_form="";
  }
	if(result=="0"){
		document.getElementById("comentarioGrabado"+num_form).innerHTML = "<b>Lo sentimos, ocurri&oacute; un error al grabar su nota personal.</b>";
		document.getElementById("comentarioGrabado"+num_form).style.visibility = "visible";
	}
	else {
		document.getElementById("formularioComentarioPersonal"+num_form).style.display = "none";
		document.getElementById("comentarioGrabado"+num_form).innerHTML = "<b>Nota personal guardada</b><br>"+document.getElementById("comentario"+num_form).value+"<br><a href=\"javascript:mostrardiv('formularioComentarioPersonal"+num_form+"');javascript:ocultardiv('comentarioGrabado"+num_form+"');\">Modificar nota</a>";
		document.getElementById("comentarioGrabado"+num_form).style.visibility = "visible";
		document.getElementById("comentarioGrabado"+num_form).style.display = "block";
	}
	return false;
}


function procesar_critica(form){
	xmlMessage = buildPOST(form);
	//xmlMessage+="&action=login";


      var num_form;
      if (arguments.length==2){
        num_form=arguments[1];
      }else{
        num_form="";
      }

  if (document.getElementById("titulo"+num_form).value.length<3){
	    document.getElementById("criticasCargando"+num_form).style.display = "none";
	    if (num_form==""){
	       document.getElementById("reglasCritica").style.display = "none";
      }
		  document.getElementById("criticaGrabada"+num_form).innerHTML = "<b>Debe introducir un titulo para su critica.</b>";
      document.getElementById("criticaGrabada"+num_form).style.visibility = "visible";
      document.getElementById("criticaGrabada"+num_form).style.display = "block";
      document.getElementById("formularioCritica"+num_form).style.display = "block";
      document.getElementById("titulo"+num_form).className="campoerror";
  }else
  {
      var result = ajaxPerform(false, xmlMessage, 'http://www.librofilia.com/ajax_criticas.php', "post");
	   if(result=="0"){
	     document.getElementById("criticasCargando"+num_form).style.display = "none";
		    document.getElementById("criticaGrabada"+num_form).innerHTML = "<b>Lo sentimos, ocurri&oacute; un error al grabar su cr&iacute;tica.</b>";
		    document.getElementById("criticaGrabada"+num_form).style.visibility = "visible";
	   }
	   else {
	     document.getElementById("criticasCargando"+num_form).style.display = "none";
		    document.getElementById("formularioCritica"+num_form).style.display = "none";
		    document.getElementById("criticaGrabada"+num_form).innerHTML = "<b>Cr&iacute;tica guardada</b><br>Su crítica ha sido envíada y aparecerá en Librofilia tan pronto como sea validada por nuestro equipo de coordinaci&oacute;n de contenidos. Muchas gracias por su participaci&oacute;n<br><p align=\"justify\"><b>"+document.getElementById("titulo"+num_form).value+"</b><br>"+document.getElementById("critica"+num_form).value+"</p><p align=\"justify\"><i>"+document.getElementById("spoiler"+num_form).value+"</i></p><a href=\"javascript:mostrardiv('formularioCritica"+num_form+"');javascript:ocultardiv('criticaGrabada"+num_form+"');\">Modificar cr&iacute;tica</a>";
		    document.getElementById("criticaGrabada"+num_form).style.visibility = "visible";
		    document.getElementById("criticaGrabada"+num_form).style.display = "block";
	   }
  }
	return false;
}

function agregar_etiqueta(form){
	xmlMessage = buildPOST(form);
	//xmlMessage+="&action=login";

	var result = ajaxPerform(false, xmlMessage, 'http://www.librofilia.com/ajax_agregar_etiqueta.php', "post");
	if(result=="OK"){
		document.getElementById("etiquetasCargando").style.display = "none";
		document.getElementById("etiquetaGrabada").innerHTML = "<b>Etiqueta(s) grabada(s)</b>. La ficha de este libro se actualizar&aacute; pronto con la nueva informaci&oacute;n<br>";
		document.getElementById("etiquetaGrabada").style.visibility = "visible";
		document.getElementById("etiquetaGrabada").style.display = "block";
  }else{
    document.getElementById("etiquetasCargando").style.display = "none";
		document.getElementById("etiquetaGrabada").innerHTML = "<b>Lo sentimos, ocurri&oacute; un error al grabar la(s) etiqueta(s).</b>";
		document.getElementById("etiquetaGrabada").style.visibility = "visible";
    document.getElementById("etiquetaGrabada").style.display = "block";
	}
	return false;
}


function enviar_sinopsis(form){
	xmlMessage = buildPOST(form);
	//xmlMessage+="&action=login";

	var result = ajaxPerform(false, xmlMessage, 'http://www.librofilia.com/ajax_agregar_sinopsis.php', "post");
	if(result=="OK"){
		document.getElementById("sinopsisCargando").style.display = "none";
		document.getElementById("sinopsisGrabada").innerHTML = "<b>Sinopsis grabada</b>.<br>Nuestro equipo de coordinaci&oacute;n de contenidos comparar&aacute; la versi&oacute;n anterior de esta ficha con la propuesta que ha env&iacute;ado, y de ser interesante el cambio se proceder&aacute; a su actualizaci&oacute;n con su texto, y se le asignar&aacute;n 3 puntos de Karma por su contribuci&oacute;n a mejorar la comunidad. Gracias por su colaboraci&oacute;n.<br><p align='justify'><i>"+document.getElementById("sinopsis").value+"</i></p>";
		document.getElementById("sinopsisGrabada").style.visibility = "visible";
		document.getElementById("sinopsisGrabada").style.display = "block";
  }else{
    document.getElementById("sinopsisCargando").style.display = "none";
		document.getElementById("sinopsisGrabada").innerHTML = "<b>Lo sentimos, ocurri&oacute; un error al grabar la sinopsis.</b>";
		document.getElementById("sinopsisGrabada").style.visibility = "visible";
    document.getElementById("sinopsisGrabada").style.display = "block";
	}
	return false;
}

function enviar_titulo(form){
	xmlMessage = buildPOST(form);
	//xmlMessage+="&action=login";

	var result = ajaxPerform(false, xmlMessage, 'http://www.librofilia.com/ajax_agregar_titulo.php', "post");
	if(result=="OK"){
		document.getElementById("tituloCargando").style.display = "none";
    document.getElementById("tituloGrabado").innerHTML = "<b>Titulo grabado</b>.<br>Nuestro equipo de coordinaci&oacute;n de contenidos comparar&aacute; la versi&oacute;n anterior de esta ficha con la propuesta que ha env&iacute;ado, y de ser interesante el cambio se proceder&aacute; a su actualizaci&oacute;n con su t&iacute;tulo, y se le asignar&aacute;n 2 puntos de Karma por su contribuci&oacute;n a mejorar la comunidad. Gracias por su colaboraci&oacute;n.<br><p align='justify'><i>"+document.getElementById("titulo").value+"</i></p>";
		document.getElementById("tituloGrabado").style.visibility = "visible";
		document.getElementById("tituloGrabado").style.display = "block";
  }else{
    document.getElementById("tituloCargando").style.display = "none";
		document.getElementById("tituloGrabado").innerHTML = "<b>Lo sentimos, ocurri&oacute; un error al grabar su propuesta de titulo.</b>";
		document.getElementById("tituloGrabado").style.visibility = "visible";
    document.getElementById("tituloGrabado").style.display = "block";
	}
	return false;
}

function agregar_estante(form){
	xmlMessage = buildPOST(form);
	//xmlMessage+="&action=login";

	var result = ajaxPerform(false, xmlMessage, 'http://www.librofilia.com/ajax_estanterias_quitar.php', "post");
	if(result=="OK"){
		document.getElementById("agregarEstanteCargando").style.display = "none";
		document.getElementById("nohayestanteria").style.display = "none";
    document.getElementById("agregarEstanteGrabado").innerHTML = "<b>Libro agregado a la estanter&iacute;a</b> Ya puede verlo en su <a href='http://www.librofilia.com/biblioteca.php'>biblioteca</a>.<br></p>";
		document.getElementById("agregarEstanteGrabado").style.visibility = "visible";
		document.getElementById("agregarEstanteGrabado").style.display = "block";
  }else{
    document.getElementById("agregarEstanteCargando").style.display = "none";
		document.getElementById("agregarEstanteGrabado").innerHTML = "<b>Lo sentimos, ocurri&oacute; un error al agregar el libro a la estanter&iacute;a de su biblioteca.</b>";
		document.getElementById("agregarEstanteGrabado").style.visibility = "visible";
    document.getElementById("agregarEstanteGrabado").style.display = "block";
	}
	return false;
}


function quitar_de_estanteria(form,num_estanteria){
	xmlMessage = buildPOST(form);
	//xmlMessage+="&action=login";
	var result = ajaxPerform(false, xmlMessage, 'http://www.librofilia.com/ajax_estanterias_quitar.php', "post");
	if(result=="OK"){
		document.getElementById("estanteria"+num_estanteria).style.display = "none";
	}
}


function marcar_leyendo(form){
	xmlMessage = buildPOST(form);
	//xmlMessage+="&action=login";
		document.getElementById("leyendoExplicacion").style.display = "none";
		document.getElementById("leyendoCargando").style.display = "block";
	var result = ajaxPerform(false, xmlMessage, 'http://www.librofilia.com/ajax_leyendo.php', "post");
	if(result=="OK"){
	document.getElementById("leyendoCargando").style.display = "none";
    document.getElementById("leyendoGrabado").innerHTML = "<b>Libro marcado</b>.<br>Este libro ha sido marcado como tu lectura actual. Podr&aacute; ser vista en tu perfil, o si utilizas nuestros <b>widgets</b> en cualquier p&aacute;gina web donde los hayas insertado.</p>";
		document.getElementById("leyendoGrabado").style.visibility = "visible";
		document.getElementById("leyendoGrabado").style.display = "block";
  }else{
    document.getElementById("leyendoCargando").style.display = "none";
		document.getElementById("leyendoGrabado").innerHTML = "<b>Lo sentimos, ocurri&oacute; un error al grabar su lectura actual.</b>";
		document.getElementById("leyendoGrabado").style.visibility = "visible";
    document.getElementById("leyendoGrabado").style.display = "block";
	}
}

function obtener_codigo(form){
	//xmlMessage+="&action=login";
	    for (i=0;i<form.color.length;i++){
       if (form.color[i].checked){
          var coloridad = form.color[i].value
          break;
       }
      }
    document.getElementById("resultadoswidget").innerHTML = "<a href='http://www.librofilia.com/verwidget/"+document.getElementById("usuario").value+"/0/'><img src='http://www.librofilia.com/widget/"+document.getElementById("usuario").value+"/0/"+coloridad+"/"+document.getElementById("ct").value.substring(1,7)+"/"+document.getElementById("ca").value.substring(1,7)+"/' style='border:0px;'></a>";
    document.getElementById("codigo").innerHTML = "<b>HTML:</b><br><textarea rows='3' cols='60'>&lt;a href=\'http://www.librofilia.com/verwidget/"+document.getElementById("usuario").value+"/0/\'&gt;&lt;img src=\'http://www.librofilia.com/widget/"+document.getElementById("usuario").value+"/0/"+coloridad+"/"+document.getElementById("ct").value.substring(1,7)+"/"+document.getElementById("ca").value.substring(1,7)+"/\' style=\'border:0px;\'&gt;&lt;/a&gt;</textarea><br><br><b>BBcode:</b><br><textarea rows='3' cols='60'>[url=http://www.librofilia.com/verwidget/"+document.getElementById("usuario").value+"/0/][img]http://www.librofilia.com/widget/"+document.getElementById("usuario").value+"/0/"+coloridad+"/"+document.getElementById("ct").value.substring(1,7)+"/"+document.getElementById("ca").value.substring(1,7)+"/[/img][/url]</textarea>";
}


function remostrar_formulario_edicion(){
	    document.getElementById("colaboracionedicionCargando").style.display = "none";
      document.getElementById("reglasEdicion").style.display = "none";
      document.getElementById("colaboracionedicionGrabado").style.visibility = "visible";
      document.getElementById("colaboracionedicionGrabado").style.display = "block";
      document.getElementById("formularioColaboracionEdicion").style.display = "block";
}

function es_numero(numero){
  if (/^([0-9])*$/.test(numero)){
    return true;
  }else{
    return false
  }
}

function enviar_edicion(form){
	//xmlMessage+="&action=login";

  if (document.getElementById("isbn").value.length<9){
    remostrar_formulario_edicion();
    document.getElementById("colaboracionedicionGrabado").innerHTML = "<b>Debe introducir un ISBN valido.</b>";
    document.getElementById("isbn").className="campoerror";
  }else
  {

    if (!es_numero(document.getElementById("ano").value)){
        remostrar_formulario_edicion();
		    document.getElementById("colaboracionedicionGrabado").innerHTML = "<b>El año no es valido (ha de ser un número).</b>";
        document.getElementById("ano").className="campoerror";
    }else
    {
      if (!es_numero(document.getElementById("pags").value)){
          remostrar_formulario_edicion();
		      document.getElementById("colaboracionedicionGrabado").innerHTML = "<b>El numero de páginas no es valido (ha de ser un número).</b>";
          document.getElementById("pags").className="campoerror";
      }else
      {
  	    xmlMessage = buildPOST(form);
        var result = ajaxPerform(false, xmlMessage, 'http://www.librofilia.com/ajax_agregar_edicion.php', "post");
        if(result=="OK"){
		      document.getElementById("colaboracionedicionCargando").style.display = "none";
          document.getElementById("colaboracionedicionGrabado").innerHTML = "<b>La edicion ha sido almacenada</b>.<br>Aparecer&aacute; en la ficha de este libro en unos minutos. Gracias por su colaboraci&oacute;n.";
		      document.getElementById("colaboracionedicionGrabado").style.visibility = "visible";
		      document.getElementById("colaboracionedicionGrabado").style.display = "block";
        }else{
          document.getElementById("colaboracionedicionCargando").style.display = "none";
		      document.getElementById("colaboracionedicionGrabado").innerHTML = "<b>Lo sentimos, ocurri&oacute; un error al grabar la edicion.</b>";
		      document.getElementById("colaboracionedicionGrabado").style.visibility = "visible";
          document.getElementById("colaboracionedicionGrabado").style.display = "block";
        }
      }
    }
  }
	return false;
}


function enviar_colaboraciontexto(form){
	xmlMessage = buildPOST(form);
	//xmlMessage+="&action=login";

	var result = ajaxPerform(false, xmlMessage, 'http://www.librofilia.com/ajax_colaboraciontexto.php', "post");
	if(result=="OK"){
		document.getElementById("colaboraciontextoCargando").style.display = "none";
    document.getElementById("colaboraciontextoGrabado").innerHTML = "<b>Propuesta de mejora de ficha almacenada</b>.<br>Nuestro equipo de coordinaci&oacute;n estudiar&aacute; su comentario y realizar&aacute; los cambios sugeridos. Gracias por su colaboraci&oacute;n.<br><p align='justify'><i>"+document.getElementById("colaboraciontexto").value+"</i></p>";
		document.getElementById("colaboraciontextoGrabado").style.visibility = "visible";
		document.getElementById("colaboraciontextoGrabado").style.display = "block";
  }else{
    document.getElementById("colaboraciontextoCargando").style.display = "none";
		document.getElementById("colaboraciontextoGrabado").innerHTML = "<b>Lo sentimos, ocurri&oacute; un error al grabar su propuesta de mejora de esta ficha.</b>";
		document.getElementById("colaboraciontextoGrabado").style.visibility = "visible";
    document.getElementById("colaboraciontextoGrabado").style.display = "block";
	}
	return false;
}

function subir_portada(form){
	xmlMessage = buildPOST(form);
	//xmlMessage+="&action=login";

	var result = ajaxPerform(false, xmlMessage, 'http://www.librofilia.com/ajax_colaboracionportada.php', "post");
	if(result=="OK"){
		document.getElementById("colaboracionportadaCargando").style.display = "none";
    document.getElementById("colaboracionportadaGrabado").innerHTML = "<b>La portada se subio correctamente</b>.<br>Nuestro equipo de coordinaci&oacute;n la revisar&aacute; y la incluira en la ficha de este libro. Gracias por su colaboraci&oacute;n.</p>";
		document.getElementById("colaboracionportadaGrabado").style.visibility = "visible";
		document.getElementById("colaboracionportadaGrabado").style.display = "block";
  }else{
    document.getElementById("colaboracionportadaCargando").style.display = "none";
		document.getElementById("colaboracionportadaGrabado").innerHTML = "<b>Lo sentimos, ocurri&oacute; un error al subir su portada:</b>"+result;
		document.getElementById("colaboracionportadaGrabado").style.visibility = "visible";
    document.getElementById("colaboracionportadaGrabado").style.display = "block";
	}
	return false;
}

function valorarLibro(libro_id,voto)
{
	//var select_id = "rate" + producto_id;
	var img_id = "imgvoto" + libro_id;

	//var value = document.getElementById(select_id).value;

	var img = document.getElementById(img_id);

	window.focus();

	//img.alt = "";


	img.src = "http://www.librofilia.com/imagenes/votos/grabando.gif";

	//var date = new Date();



	imgsrc = "http://www.librofilia.com/imgvotarlibro.php?id=" + libro_id + "&nota=" + voto;

	//if(SID != "")
//		imgsrc += '&' + SID;

	img.src = imgsrc;
}


function submenu(elemento,logged){


	for (i=1;i<5;i++){
	   var link_id = "menu" + i;
	   var link = document.getElementById(link_id);
     v_attribute_list=link.attributes;
     v_class=v_attribute_list.getNamedItem("class");
     if (i==elemento){
      v_class.value="active";
     }else{
      v_class.value="";
     }
  }

switch (elemento){

  case 1:
    if (logged){
      document.getElementById("middlebar").innerHTML=''
    +'<div id="middlebarenlaces">'
    +'<a href="http://www.librofilia.com/perfil_usuario.php"><span>Mis votaciones</span></a>'
    +'<a href="http://www.librofilia.com/comentariopersonal_seccion.php"><span>Mis comentarios</span></a>'
    +'<a href="http://www.librofilia.com/criticas_seccion.php"><span>Mis cr&iacute;ticas</span></a>'
    +'<a href="http://www.librofilia.com/biblioteca.php"><span>Mi biblioteca</span></a>'
    +'<a href="http://www.librofilia.com/creador_widgets.php"><span>Widgets</span></a>'
    +'<a href="http://www.librofilia.com/usuarios.php?accion=modificarperfil"><span>Modificar mis datos</span></a>'
    +'<a href="http://www.librofilia.com/usuarios.php?accion=logout"><span>Salir</span></a>'
    +'</div>';
    }else{
      //document.getElementById("middlebar").innerHTML="<b>Hola</b> ";

      document.getElementById("middlebar").innerHTML=''
    +'<div id="middlebarenlaces">'
    +'<a href="http://www.librofilia.com/usuarios.php?accion=registrar"><span>Reg&iacute;strese</span></a>'
    +'<a href="http://www.librofilia.com/usuarios.php?accion=olvidar"><span>¿Olvidó su contrase&ntilde;a?</span></a>'
    +'<a href="javascript:mostrardiv(\'formlogin\');"><span>Acceda a su cuenta</span></a>'
    +'</div>'
    +'<div id="formlogin" style="text-align:right;display:none;">'
+'          <form action="" name="login" id="login">'
+'             Usuario:&nbsp;&nbsp;&nbsp;&nbsp;<input name="nombre_usuario" type="text" id="nombre_usuario" onFocus="document.getElementById(\'login_err_msg\').innerHTML=\'\'" size="14"  onKeyPress="return loginEnter(this,event)">'
+'             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Contrase&ntilde;a:&nbsp;&nbsp;&nbsp;&nbsp;<input name="contrasena" type="password" id="contrasena" onFocus="document.getElementById(\'login_err_msg\').innerHTML=\'\'" size="14"  onKeyPress="return loginEnter(this,event)">'
+'             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="recordarme" style="width:20px;" value="si">&nbsp;Recordarme'
+'             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:remote_login(document.login);"><img src="http://www.librofilia.com/imagenes/enviar.gif" style="margin:0px;vertical-align:middle;" border=0></a>'
+'           </form>'
+'    </div>';

    }

  break;

  case 2:
    if (logged){
      document.getElementById("middlebar").innerHTML=''
    +'<div id="middlebarenlaces">'
    +'<a href="http://www.librofilia.com/amigos.php"><span>Amigos</span></a>'
    +'<a href="http://www.librofilia.com/almas_gemelas.php"><span>Almas gemelas</span></a>'
    +'<a href="http://www.librofilia.com/recomendaciones.php"><span>Recomendaciones</span></a>'
    +'<a href="http://www.librofilia.com/foros/"><span>Foros</span></a>'
    +'</div>';
    }else{
      //document.getElementById("middlebar").innerHTML="<b>Hola</b> ";

      document.getElementById("middlebar").innerHTML=''
    +'<div id="middlebarenlaces">'
    +'<a href="http://www.librofilia.com/foros/"><span>Foros</span></a>'
    +'</div>';

    }

  break;


  case 3:
      document.getElementById("middlebar").innerHTML=''
+'    <div id="middlebarenlaces">'
+'    <a href="http://www.librofilia.com/listado.php?criterio=alfabeto&letra=A"><span>Orden alfab&eacute;tico</span></a>'
+'    <a href="http://www.librofilia.com/categorias.php"><span>Categor&iacute;as</span></a>'
+'    <a href="http://www.librofilia.com/listas.php"><span>Listas de votaci&oacute;n</span></a>'
+'    </div>';

  break;


  case 4:
      document.getElementById("middlebar").innerHTML=''
+'    <form action="http://www.librofilia.com/listado.php" method="GET" name="buscador" id="buscador">'
+'T&iacute;tulo <input type="text" name="titulo_buscar" style="width:93px;"onKeyPress="return enviarEnter(this,event)"><input type="hidden" name="criterio" value="buscar">'
+'             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nombre del autor:&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="nombre_autor_buscar" style="width:93px;" onKeyPress="return enviarEnter(this,event)">'
+'             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Apellido del autor:&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="apellido_autor_buscar" style="width:93px;" onKeyPress="return enviarEnter(this,event)">'
+'             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:document.buscador.submit();"><img src="http://www.librofilia.com/imagenes/buscar.gif" style="margin:0px;vertical-align:middle;padding:0px;" border=0></a>'
+'      </form>';

  break;


}

//	document.getElementById("middlebar").innerHTML="<b>Hola</b> ";

	//return true;
}



function loginEnter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   remote_login(document.login);
   return false;
}else{
return true;
}
}


function enviarEnter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}
