function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else begin += 2;
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
        end = dc.length;
    return unescape(dc.substring(begin + prefix.length, end));
}

function mostrarLogin(urlPerfil,urlDesconectar,urlLogin,urlRegistrar,idMarca){

    var logado=getCookie("estantesCk");
    var nodo=document.getElementById("submenu_superior");
    var texto='';
    if (idMarca == null || idMarca == ''){
        idMarca = '1';
    }
    if (idMarca=='1'){
        if(logado==null || logado==''){
            texto='<a href="'+urlLogin+'">Acceso Usuarios</a>  <span>|</span>  <a href="'+urlRegistrar+'">Crea tu propia biblioteca</a>';
        }else{
            texto='<a href="'+urlPerfil+'">Mi Perfil</a>  <span>|</span>  <a href="'+urlDesconectar+'">Desconexi&oacute;n</a>';
        }
    }else if(idMarca=='2'){
        if(logado==null || logado==''){
            texto='<a href="'+urlLogin+'">Acceso Usuarios</a>  <span>';
        }else{
            texto='<a href="'+urlPerfil+'">Publicar un Post</a>  <span>|</span>  <a href="'+urlDesconectar+'">Desconexi&oacute;n</a>';
        }
    }else{
        if(logado==null || logado==''){
            texto='<a style="background-color:white" href="'+urlLogin+'">Acceso Usuarios</a>  <span>';
        }else{
            texto='<a style="background-color:white" href="'+urlPerfil+'">Publicar un Post</a>  <span>|</span>  <a style="background-color:white" href="'+urlDesconectar+'">Desconexi&oacute;n</a>';
        }
    }
    nodo.innerHTML=texto;
}

function XHConn(){
	var xmlhttp, bComplete = false;
	try {
		xmlhttp = new XMLHttpRequest();
	}catch (e){
		var XMLHTTP_IDS = new Array('MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP' );
		var success = false;
		for (var i=0;i < XMLHTTP_IDS.length && !success; i++) {
			try {
				xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]);
				success = true;
			} catch (e) {}
		}
		if (!success) xmlhttp = false;
	}

	if (!xmlhttp) return null;
	this.connect = function(sURL, sMethod, sVars, fnDone){
		if (!xmlhttp) return false;
		bComplete = false;
		sMethod = sMethod.toUpperCase();

		try {
			if (sMethod == "GET"){
				xmlhttp.open(sMethod, sURL+"?"+sVars, true);
				sVars = "";
			}else{
				xmlhttp.open(sMethod, sURL, true);
				xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
				xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			}
			xmlhttp.onreadystatechange = function(){
				if (xmlhttp.readyState == 4 && !bComplete){
					bComplete = true;
					fnDone(xmlhttp);
				}
			};
			xmlhttp.send(sVars);
        }catch(z) {
            return false;
        }
		return true;
	};
	return this;
}

var buscenv=false;
function comprobar(){
    var inbusc=document.form_busqueda.buscar;
    inbusc.blur();
    if(inbusc.value.length < 3 || inbusc.value=="Minimo 3 caracteres"){
        inbusc.value="Minimo 3 caracteres";
        return false;
    }else{
        if (!buscenv){
            buscenv=true;
            document.form_busqueda.botbusc.disabled=true;
            return true;
        }else{
            return false;
        }
    }
}
function iniciar(obj){
    var txtBus=obj.value;
    if (txtBus=="Minimo 3 caracteres"){
        obj.value="";
    }
}
var textOrig="Incluye tu comentario..."
var enviado=false;
function introtext(campo){
    var textIntro=Trim(campo.value);
    if (textIntro==textOrig){
        campo.value="";
    }
}
function testCambio(campo){
    var textIntro=Trim(campo.value);
    if (textIntro==""){
        campo.value=textOrig;
    }
}
function validaTextArea(campo,maxlimit){
    var error=document.getElementById("error");
    if (error!=null && typeof(error)!='undefined' && error.nodeType==1){
        error.style.display="none";
    }
	if(campo.value.length > maxlimit){
		campo.blur();
		campo.value=campo.value.substring(0,maxlimit-1);
        if (error!=null && typeof(error)!='undefined' && error.nodeType==1){
            error.style.display="block";
            error.innerHTML="Ha alcanzado el tama&ntilde;o m&aacute;ximo para el comentario";
        }
	}
}
function validaTextAreaCapa(campo,maxlimit){
    var error=document.getElementById("error");
    if (error!=null && typeof(error)!='undefined' && error.nodeType==1){
        error.style.display="none";
    }
	if(campo.value.length > maxlimit){
		campo.blur();
		campo.value=campo.value.substring(0,maxlimit-1);
        if (error!=null && typeof(error)!='undefined' && error.nodeType==1){
            error.style.display="block";
            error.innerHTML="Ha alcanzado el tama&ntilde;o m&aacute;ximo para el comentario";
        }
	}
}
function isNotEmpty(field) {
    var inputStr = Trim(field.value)
    if (inputStr == "" || inputStr == null) {
        return false
    }
    return true
}
function isEmpty (s) {
	return ((s == null) || (s.length == 0));
}
function isValorVacio(valorC) {
    var valor = Trim(valorC);
    if (valor == "" || valor == null) {
        return true
    }
    return false
}
function LTrim(str) {
    return str.replace(/^\s+/g, '');
}
function RTrim(str) {
    return str.replace(/\s+$/g, '');
}
function Trim(str) {
    return LTrim(RTrim(str));
}
function isEmail(StrObj) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(StrObj)) {
		return true;
	} else {
		return false;
	}
}
function validarComentario(){
    var form=document.comentario;
    form.enviarCom.disabled=true;
    var errorForm="";
    if (form.seudonimo!=null && typeof(form.seudonimo)!='undefined' && form.seudonimo.nodeType==1 && form.mail!=null && typeof(form.mail)!='undefined' && form.mail.nodeType==1){
        if (!isValorVacio(form.seudonimo.value) && !isValorVacio(form.mail.value)){
            if (isEmail(form.mail.value)){
                if (!enviado){
                    enviado=true;
                    return true;
                }else{
                    return false;
                }
            }else{
                errorForm+="Email no es valido.";
            }
        }else{
            if (isValorVacio(form.seudonimo.value)){
                errorForm+="Pseudonimo es obligatorio.";
            }
            if (isValorVacio(form.mail.value)){
                errorForm+=" Email es obligatorio.";
            }
        }
    }
    if (isValorVacio(form.comentario_autor.value) || form.comentario_autor.value=="Incluye tu comentario.." || form.comentario_autor.value=="Incluye tu comentario..."){
        errorForm+=" El comentario es obligatorio";
    }
    if (!isValorVacio(errorForm)){
        var error=document.getElementById("error");
        error.style.display="block";
        error.innerHTML=errorForm;
        enviado=false;
        form.enviarCom.disabled=false;
        return false;
    }
}
function comprobarOpinionLibro(){
    var errorForm="";
    var form=document.comentario;
    if (form.seudonimo!=null && typeof(form.seudonimo)!='undefined' && form.seudonimo.nodeType==1 && form.mail!=null && typeof(form.mail)!='undefined' && form.mail.nodeType==1){
        if (!isValorVacio(form.seudonimo.value) && !isValorVacio(form.mail.value)){
            if (isEmail(form.mail.value)){
                if (isValorVacio(form.comentario_libro.value) || form.comentario_libro.value=="Incluye tu comentario.." || form.comentario_libro.value=="Incluye tu comentario..."){
                    errorForm+=" El comentario es obligatorio";
                }else{
                    var mySplitResult = form.comentario_libro.value.split("href");
                    if(mySplitResult.length<=4)
                        form.submit();
                    else
                        errorForm+=" Tu comentario no es correcto. Disculpa las molestias."
                }
            }else{
                errorForm+="Email no es válido.";
            }
        }else{
            if (isValorVacio(form.seudonimo.value)){
                errorForm+="Pseudónimo es obligatorio.";
            }
            if (isValorVacio(form.mail.value)){
                errorForm+=" Email es obligatorio.";
            }
        }
    }else{
        if (isValorVacio(form.comentario_libro.value) || form.comentario_libro.value=="Incluye tu comentario.." || form.comentario_libro.value=="Incluye tu comentario..."){
            errorForm+=" El comentario es obligatorio";
        }else{
            form.submit();
        }
    }
    if (!isValorVacio(errorForm)){
        var error=document.getElementById("error");
        error.style.display="block";
        error.innerHTML=errorForm;
    }
}
function comprobarOpinionGrupo(){
    var errorForm="";
    var form=document.comentario;
    if (form.seudonimo!=null && typeof(form.seudonimo)!='undefined' && form.seudonimo.nodeType==1 && form.mail!=null && typeof(form.mail)!='undefined' && form.mail.nodeType==1){
        if (!isValorVacio(form.seudonimo.value) && !isValorVacio(form.mail.value)){
            if (isEmail(form.mail.value)){
                if (isValorVacio(form.comentario_grupo.value) || form.comentario_grupo.value=="Incluye tu comentario.." || form.comentario_grupo.value=="Incluye tu comentario..."){
                    errorForm+=" El comentario es obligatorio";
                }else{
                    form.submit();
                }
            }else{
                errorForm+="Email no es válido.";
            }
        }else{
            if (isValorVacio(form.seudonimo.value)){
                errorForm+="Pseudónimo es obligatorio.";
            }
            if (isValorVacio(form.mail.value)){
                errorForm+=" Email es obligatorio.";
            }
        }
    }else{
        if (isValorVacio(form.comentario_grupo.value) || form.comentario_grupo.value=="Incluye tu comentario.." || form.comentario_grupo.value=="Incluye tu comentario..."){
            errorForm+=" El comentario es obligatorio";
        }else{
            form.submit();
        }
    }
    if (!isValorVacio(errorForm)){
        var error=document.getElementById("error");
        error.style.display="block";
        error.innerHTML=errorForm;
    }
}
function mostrarRecomendar(id,origen,clibro,titulo,autores,editorial,imagen){
	var reco=document.getElementById(id);
	var posId=id.substring(id.length-1,id.length);

	if (isNaN(posId)){
		posId="";
	}
	if (reco.innerHTML==""){
		var myConn = new XHConn();
		if (!myConn) alert("XMLHTTP no esta disponible. Inténtalo con un navegador más actual.");
		var peticion = function (oXML) {
            reco.innerHTML=oXML.responseText;
            var capaReco=document.getElementById('capaReco');
            var formReco=document.forms['frmrecomendar'+posId];

			var recIn=document.getElementById('recInputs'+posId);
			var txReco=document.getElementById('txReco'+posId);
			if (txReco!=null && typeof(txReco)!='undefined' && txReco.nodeType==1) txReco.parentNode.removeChild(txReco);
			document.getElementById('recHecha'+posId).style.display='none';
            recIn.style.display='block';
            if (formReco) formReco.style.display='block';
			//getFirstChild(reco).style.display='block';
            capaReco.style.display='block';
			reco.style.display='block';
		}

        myConn.connect("/libro/recomendar.htm", "POST", "origen="+origen+"&codlib="+clibro+"&titulo="+titulo+"&autores="+autores+"&editorial="+editorial+"&imagen="+imagen+"&id="+posId, peticion);
	}else{
        var capaReco=document.getElementById('capaReco');
        var recIn=document.getElementById('recInputs'+posId);
        var txReco=document.getElementById('txReco'+posId);
        var alarIn=document.getElementById('alarmInp'+posId);
        var formReco=document.forms['frmrecomendar'+posId];
		if (txReco!=null && typeof(txReco)!='undefined' && txReco.nodeType==1) txReco.parentNode.removeChild(txReco);
        if (formReco){
            formReco.reset();
            document.getElementById('recHecha'+posId).style.display='none';
            recIn.style.display='block';
            formReco.style.display='block';
        }

		capaReco.style.display='block';
		reco.style.display='block';
	}
}
function cerrarReco(id){
	var reco=document.getElementById('recomendar'+id);
	var recIn=document.getElementById('recInputs'+id);
	var txReco=document.getElementById('txReco'+id);
    if (txReco!=null && typeof(txReco)!='undefined' && txReco.nodeType==1){
        txReco.parentNode.removeChild(txReco);
    }
	reco.style.display='none';
}
function mostrarRecoOtro(id){
	document.forms['frmrecomendar'+id].amignombre.value="";
	document.forms['frmrecomendar'+id].amigemail.value="";
	var reco=document.getElementById('recomendar'+id);
	var recIn=document.getElementById('recInputs'+id);
	var txReco=document.getElementById('txReco'+id);
	if (txReco!=null && typeof(txReco)!='undefined' && txReco.nodeType==1) recIn.removeChild(txReco);
	recIn.style.display='block';
	document.getElementById('recHecha'+id).style.display='none';
	reco.style.display='block';
	getFirstChild(reco).display='block';
}

function recomendar(origen,id,titulo,autores,editorial,imagen){
	var reco=document.getElementById('recomendar'+id);
	var recIn=document.getElementById('recInputs'+id);
	var txReco=document.getElementById('txReco'+id);
	var txErr=validarReco(id);
	if (txReco!=null && typeof(txReco)!='undefined' && txReco.nodeType==1){
		if (txErr!=null && txErr!="") txReco.innerHTML="<img src='/i/error2.gif' alt='Error datos' />"+txErr;
		else{
            txReco.innerHTML="Enviando la recomendaci\xf3n";
            var myConn = new XHConn();
            if (!myConn) alert("XMLHTTP no esta disponible. Inténtalo con un navegador más actual.");
            var peticion = function (oXML) {
                recIn.style.display='none';
                var rText=oXML.responseText;
                if (rText.indexOf("{")>=0){
                    var respuesta=eval('('+rText+')');
                    if (respuesta){
                        document.getElementById('respRecom'+id).innerHTML=respuesta.resp;
                    }
                }
                document.getElementById('recHecha'+id).style.display='block';
            }
            myConn.connect("/libro/enviarRecomendacion.htm", "POST", "tipoRecomendacion="+origen+"&codigoLibro="+document.frmrecomendar.codigoLibro.value+"&tunombre="+document.frmrecomendar.tunombre.value+"&tuemail="+document.frmrecomendar.tuemail.value+"&amignombre="+document.frmrecomendar.amignombre.value+"&amigemail="+document.frmrecomendar.amigemail.value+"&titulo="+titulo+"&autores="+autores+"&editorial="+editorial+"&imagen="+imagen, peticion);
        }
	}else{
		var txError = document.createElement("p");
		var myTexto;
		var imErr;
		if (txErr!=null && txErr!=""){
			imErr=document.createElement("img");
			imErr.src="/i/error2.gif";
			imErr.alt="Error datos";
			myTexto = document.createTextNode(txErr);
		}else{
            myTexto = document.createTextNode("Enviando la recomendación");
            var myConn = new XHConn();
            if (!myConn) alert("XMLHTTP no esta disponible. Inténtalo con un navegador más actual.");
            var peticion = function (oXML) {
                recIn.style.display='none';
                var rText=oXML.responseText;
                if (rText.indexOf("{")>=0){

                    var respuesta=eval('('+rText+')');
                    if (respuesta){
                        document.getElementById('respRecom'+id).innerHTML=respuesta.resp;
                    }
                }
                document.getElementById('recHecha'+id).style.display='block';
            }
            myConn.connect("/libro/enviarRecomendacion.htm", "POST", "tipoRecomendacion="+origen+"&codigoLibro="+document.frmrecomendar.codigoLibro.value+"&tunombre="+document.frmrecomendar.tunombre.value+"&tuemail="+document.frmrecomendar.tuemail.value+"&amignombre="+document.frmrecomendar.amignombre.value+"&amigemail="+document.frmrecomendar.amigemail.value+"&titulo="+titulo+"&autores="+autores+"&editorial="+editorial+"&imagen="+imagen, peticion);
        }
		if (imErr!=null && typeof(imErr)!='undefined' && imErr.nodeType==1) txError.appendChild(imErr);
		txError.appendChild(myTexto);
		txError.id="txReco"+id;
		txError.className="txReco";
        txError.style.fontFamily="Arial";
        txError.style.fontSize="12px"
        txError.style.color="#fe8434";
        txError.style.textDecoration="none";
        txError.style.textAlign="justify";
        //recIn.insertBefore(txError,getFirstChild(recIn));
        recIn.appendChild(txError);
	}
	return false;
}
function validarReco(id){
	var txErr="";
	if (isEmpty(document.forms['frmrecomendar'+id].tunombre.value)){
        txErr=" Tu Nombre no puede estar vac&iacute;o.";
	}
	if (isEmpty(document.forms['frmrecomendar'+id].amignombre.value)){
        txErr=txErr+" El Nombre de tu amigo no puede estar vac&iacute;o.";
	}
	if (!isEmail(document.forms['frmrecomendar'+id].tuemail.value)){
        txErr=txErr+" Tu Email no es correcto.";
	}
	if (!isEmail(document.forms['frmrecomendar'+id].amigemail.value)){
        txErr=txErr+" El Email de tu amigo no es correcto.";
	}
	return txErr;
}

function mostrarComentar(id,origen,opId, titulo){
    var div=id+''+opId;
    var coment=document.getElementById(div);
    var posId=id.substring(id.length-1,id.length);

	if (isNaN(posId)){
		posId="";
	}
	if (coment.innerHTML==""){
		var myConn = new XHConn();
		if (!myConn) alert("XMLHTTP no esta disponible. Inténtalo con un navegador más actual.");
		var peticion = function (oXML) {
            coment.innerHTML=oXML.responseText;
            var capaComentar=document.getElementById('capaComentar');
            capaComentar.style.display='block';
            coment.style.display='block';
		}
		myConn.connect("/libro/comentar.htm", "POST", "origen="+origen+"&titulo="+escape(titulo)+"&opId="+opId+"&id="+posId, peticion);
	}else{
        var capaComentar=document.getElementById('capaComentar');
        capaComentar.style.display='block';
        coment.style.display='block';
	}
}

function mostrarComentarAutor(id,origen,idAutor){
    var div=id;
	var coment=document.getElementById(div);
	var posId=id.substring(id.length-1,id.length);
    var urlOrigen=location.pathname;
    if (urlOrigen==null) urlOrigen="";

	if (isNaN(posId)){
		posId="";
	}
	if (coment.innerHTML==""){
		var myConn = new XHConn();
		if (!myConn) alert("XMLHTTP no esta disponible. Inténtalo con un navegador más actual.");
		var peticion = function (oXML) {
			coment.innerHTML=oXML.responseText;
            var capaComentar=document.getElementById('capaComentar');
            capaComentar.style.display='block';
			coment.style.display='block';
		}

		myConn.connect("/autor/opinar.htm", "POST", "origen="+origen+"&id="+posId+"&idAutor="+idAutor+"&urlOrigen="+urlOrigen, peticion);
	}else{
         var capaComentar=document.getElementById('capaComentar');
		capaComentar.style.display='block';
		coment.style.display='block';
	}
}
function checkOpinionAutor(){
        var texto=document.forms['opinionAutor'].opinion_autor.value;
        if (texto!=null && texto!='' && texto!='Incluye tu comentario...'){
            document.forms['opinionAutor'].urlOrigen.value=window.location.pathname+window.location.search;
            document.opinionAutor.submit();
        }else{
            document.getElementById("opinion_autor").value='Incluye tu comentario...';
        }
}
function ver(url) {
    var hWnd = window.open('http://www.casadellibro.com'+url,"","width=600,height=600,resizable=yes,status=yes,scrollbars=auto");
    if ((document.window != null) && (!hWnd.opener))
        hWnd.opener = document.window;
}
function ver2(url) {
    var hWnd = window.open('http://www.casadellibro.com'+url,"","width=400,height=500,resizable=yes,status=yes,scrollbars=auto");
    if ((document.window != null) && (!hWnd.opener))
        hWnd.opener = document.window;
}
function realizarBusqueda(){
    var texto=document.forms['buscador'].buscar.value;
    if (texto!=null && texto!='' && texto!='Busqueda' && texto!='B&uacute;squeda' && texto!='B\xfasqueda' && texto!='Búsqueda'){
        document.buscador.submit();
    }else{
        document.getElementById("buscar").value='B\xfasqueda';
    }
}
function handleEnterGrupo (numTematicas, event) {
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 13) {
        checkFormCrear(numTematicas);
        return false;
    }
    else
    return true;
}
function habilitarTem(numTematicas){
    var i=0;
    for (i=0;i<=numTematicas;i++){
        if(document.forms['formularioCreacion'].tematica[i]!=null)
            document.forms['formularioCreacion'].tematica[i].disabled = false;
    }
}
function deshabilitarTem(numTematicas){
    var i=0;
    for (i=0;i<=numTematicas;i++){
        if(document.forms['formularioCreacion'].tematica[i]!=null)
            document.forms['formularioCreacion'].tematica[i].disabled = true;
    }
}
function checkFormCrear(numTematicas){
    var alerta="";
    var hayAlerta=false;
    if(document.forms['formularioCreacion'].categoria[1]!=null && document.forms['formularioCreacion'].categoria[1].checked){
        //si es categoria tematica
        var hayTematica=false;
        var i=0;
        for (i=0;i<=numTematicas && !hayTematica;i++){
            if(document.forms['formularioCreacion'].tematica[i]!=null && document.forms['formularioCreacion'].tematica[i].checked)
                hayTematica=true;
        }
        if(!hayTematica){
            alerta = alerta + "Si el grupo es tematico, has de escoger una tematica del listado\n";
            hayAlerta=true;
        }
    }
    if(document.formularioCreacion.nombre_grupo.value == null || document.formularioCreacion.nombre_grupo.value.replace(/^(\s|\&nbsp;)*|(\s|\&nbsp;)*$/g,"")==''){
        hayAlerta=true;
        alerta = alerta + "Tienes que poner un nombre al grupo\n";
    }else{
        if(document.formularioCreacion.nombre_grupo.value.replace(/^(\s|\&nbsp;)*|(\s|\&nbsp;)*$/g,"").length<4){
            hayAlerta=true;
            alerta = alerta + "Tienes que poner un nombre con mas de 3 caracteres\n";
        }
    }
    if(hayAlerta){
        document.getElementById("alertas").innerHTML="<p style='color:red;font-weight:bold'>"+alerta+"</p>";
    }else{
        document.getElementById("enlaceBoton").style.display='none';
        document.formularioCreacion.submit();
        }
}
var denuncEnviada=false;
function checkCamposDenuncia(){
    var formu=document.formDenuncia;
    formu.denunEnv.disabled=true;
    formu.denunEnv.style.visibility="hidden";
    var divErr=document.getElementById("errorReg");
    var divOk=document.getElementById("okReg");
    if(Trim(formu.nombreDenunciante.value)=='' || Trim(formu.apellidoDenunciante.value)==''
        || Trim(formu.mailDenunciante.value)=='' || Trim(formu.textoDenuncia.value)==''){
        divErr.innerHTML="Debe rellenar todos los campos";
        divErr.style.display="block";
        formu.denunEnv.disabled=false;
        formu.denunEnv.style.visibility="visible";
    }else{
        if(isEmail(formu.mailDenunciante.value)){
            var mySplitResult = formu.textoDenuncia.value.split("href");
            if(mySplitResult.length<=4){
                divErr.innerHTML="";
                divErr.style.display="none";
                divOk.innerHTML="<img src=\"/i/cargando.gif\" alt=\"\" />Enviando la denuncia...";
                divOk.style.display="block";
                var myConn = new XHConn();
                if (!myConn) alert("XMLHTTP no esta disponible. Inténtalo con un navegador más actual.");
                var peticion = function (oXML) {
                    var rText=oXML.responseText;
                    if (rText.indexOf("{")>=0){
                        var respuesta=eval('('+rText+')');
                        if (respuesta){
                            divOk.innerHTML=respuesta.resp;
                            divOk.style.display="block";
                        }
                    }
                }
                if (!denuncEnviada){
                    denuncEnviada=true;
                    myConn.connect(formu.urlDestino.value, "POST", "nombreDenunciante="+escape(formu.nombreDenunciante.value)+"&apellidoDenunciante="+escape(formu.apellidoDenunciante.value)+"&mailDenunciante="+formu.mailDenunciante.value+"&textoDenuncia="+escape(formu.textoDenuncia.value)+"&textoOculto="+escape(formu.textoOculto.value), peticion);
                }
            }else{
                divErr.innerHTML="Contenido de la denuncia incorrecto. Disculpe las molestias";
                divErr.style.display="block";
                formu.denunEnv.style.visibility="visible";
                formu.denunEnv.disabled=false;
            }
        }else{
            divErr.innerHTML="El email es incorrecto";
            divErr.style.display="block";
            formu.denunEnv.style.visibility="visible";
            formu.denunEnv.disabled=false;
        }
    }
    return false;
}

function checkCamposContacto (){
    var formu=document.formcontacto;
    formu.denunEnv.disabled=true;
    formu.denunEnv.style.visibility="hidden";
    var divErr=document.getElementById("errorReg");
    var divOk=document.getElementById("okReg");
    if(Trim(formu.tunombre.value)=='' || Trim(formu.tuemail.value)=='' || Trim(formu.tumensaje.value)==''){
        divErr.innerHTML="Debe rellenar todos los campos";
        divErr.style.display="block";
        formu.denunEnv.disabled=false;
        formu.denunEnv.style.visibility="visible";
    }else{
        if(isEmail(formu.tuemail.value)){
            var mySplitResult = formu.tumensaje.value.split("href");
            if(mySplitResult.length<=4){
                divErr.innerHTML="";
                divErr.style.display="none";
                divOk.innerHTML="<img src=\"/i/cargando.gif\" alt=\"\" />Enviando el mensaje...";
                divOk.style.display="block";
                var myConn = new XHConn();
                if (!myConn) alert("XMLHTTP no esta disponible. Inténtalo con un navegador más actual.");
                var peticion = function (oXML) {
                    var rText=oXML.responseText;
                    if (rText.indexOf("{")>=0){
                        var respuesta=eval('('+rText+')');
                        if (respuesta){
                            divOk.innerHTML=respuesta.resp;
                            divOk.style.display="block";
                        }
                    }
                }
                if (!denuncEnviada){
                    denuncEnviada=true;
                    myConn.connect(formu.urlDestino.value, "POST", "tunombre="+escape(formu.tunombre.value)+"&tuemail="+formu.tuemail.value+"&tumensaje="+escape(formu.tumensaje.value), peticion);
                }
            }else{
                divErr.innerHTML="Tu peticion no es correcta. Disculpe las molestias.";
                divErr.style.display="block";
                formu.denunEnv.style.visibility="visible";
                formu.denunEnv.disabled=false;
            }
        }else{
            divErr.innerHTML="El email es incorrecto";
            divErr.style.display="block";
            formu.denunEnv.style.visibility="visible";
            formu.denunEnv.disabled=false;
        }
    }
    return false;
}

function cerrarCapaComentar(){
    document.getElementById('capaComentar').style.display='none';
}
function mostrarOpinar(id,origen,idGrupo){
        var div=id;
        var coment=document.getElementById(div);
        var posId=id.substring(id.length-1,id.length);
        var urlOrigen=location.pathname;
        if (urlOrigen==null) urlOrigen="";

        if (isNaN(posId)){
            posId="";
        }
        if (coment.innerHTML==""){
            var myConn = new XHConn();
            if (!myConn) alert("XMLHTTP no esta disponible. Inténtalo con un navegador más actual.");
            var peticion = function (oXML) {
                coment.innerHTML=oXML.responseText;
                var capaComentar=document.getElementById('capaComentar');
                capaComentar.style.display='block';
                coment.style.display='block';
            }

            myConn.connect("/grupo/opinar.htm", "POST", "origen="+origen+"&id="+posId+"&idGrupo="+idGrupo, peticion);
        }else{
             var capaComentar=document.getElementById('capaComentar');
            capaComentar.style.display='block';
            coment.style.display='block';
        }
}

function cerrarCapaOpinar(){
    /*document.getElementById('capaOpinar').style.display='none';*/
     document.getElementById('capaComentar').style.display='none';
}

function mostrarInvitarEOR(){
    document.getElementById('capaRecoEOR').style.display='block';
    }
function cerrarRecoEOR(){
    document.getElementById('capaRecoEOR').style.display='none';
    }

function mostrarInvitar(id,origen,cgrupo,nombreGrupo){
    var reco=document.getElementById(id);
    var posId=id.substring(id.length-1,id.length);

    if (isNaN(posId)){
        posId="";
    }
    if (reco.innerHTML==""){
        var myConn = new XHConn();
        if (!myConn) alert("XMLHTTP no esta disponible. Inténtalo con un navegador más actual.");
        var peticion = function (oXML) {
            reco.innerHTML=oXML.responseText;
            var capaReco=document.getElementById('capaReco');
            var formReco=document.forms['frmrecomendar'+posId];

            var recIn=document.getElementById('recInputs'+posId);
            var txReco=document.getElementById('txReco'+posId);
            if (txReco!=null && typeof(txReco)!='undefined' && txReco.nodeType==1) txReco.parentNode.removeChild(txReco);
            document.getElementById('recHecha'+posId).style.display='none';
            recIn.style.display='block';
            if (formReco) formReco.style.display='block';
            //getFirstChild(reco).style.display='block';
            capaReco.style.display='block';
            reco.style.display='block';
        }
        myConn.connect("/grupo/invitar.htm", "POST", "origen="+origen+"&codgrupo="+cgrupo+"&id="+posId+"&nombreGrupo="+nombreGrupo, peticion);
    }else{
        var capaReco=document.getElementById('capaReco');
        var recIn=document.getElementById('recInputs'+posId);
        var txReco=document.getElementById('txReco'+posId);
        var alarIn=document.getElementById('alarmInp'+posId);
        var formReco=document.forms['frmrecomendar'+posId];
        if (txReco!=null && typeof(txReco)!='undefined' && txReco.nodeType==1) txReco.parentNode.removeChild(txReco);

        if (formReco){
            formReco.reset();
            document.getElementById('recHecha'+posId).style.display='none';
            recIn.style.display='block';
            formReco.style.display='block';
        }

        capaReco.style.display='block';
        reco.style.display='block';
    }
}
function cerrarRecoGrupo(id){
    var reco=document.getElementById('capaReco');
    var recIn=document.getElementById('recInputs'+id);
    var txReco=document.getElementById('txReco'+id);
    if (txReco!=null && typeof(txReco)!='undefined' && txReco.nodeType==1){ 
        txReco.parentNode.removeChild(txReco);
    }
    reco.style.display='none';
}
function mostrarRecoOtro(id){
    document.forms['frmrecomendar'+id].amignombre.value="";
    document.forms['frmrecomendar'+id].amigemail.value="";
    var reco=document.getElementById('recomendar'+id);
    var recIn=document.getElementById('recInputs'+id);
    var txReco=document.getElementById('txReco'+id);
    if (txReco!=null && typeof(txReco)!='undefined' && txReco.nodeType==1) recIn.removeChild(txReco);
    recIn.style.display='block';
    document.getElementById('recHecha'+id).style.display='none';
    reco.style.display='block';
    getFirstChild(reco).display='block';
}

function recomendarGrupo(origen,id){
    //var reco=document.getElementById('recomendar'+id);
    var recIn=document.getElementById('recInputs'+id);
    var txReco=document.getElementById('txReco'+id);
    var txErr=validarRecoGrupo(id);
    if (txReco!=null && typeof(txReco)!='undefined' && txReco.nodeType==1){
        if (txErr!=null && txErr!="") txReco.innerHTML="<img src='/i/error2.gif' alt='Error datos' />"+txErr;
        else{
            txReco.innerHTML="Enviando la recomendación";
            var myConn = new XHConn();
            if (!myConn) alert("XMLHTTP no esta disponible. Inténtalo con un navegador más actual.");
            var peticion = function (oXML) {
                recIn.style.display='none';
                var rText=oXML.responseText;
                if (rText.indexOf("{")>=0){
                    var respuesta=eval('('+rText+')');
                    if (respuesta){
                        document.getElementById('respRecom'+id).innerHTML=respuesta.resp;
                    }
                }
                document.getElementById('recHecha'+id).style.display='block';
            }
            myConn.connect("/grupo/enviarInvitacion.htm", "POST", "tipoRecomendacion="+origen+"&nombreGrupo="+document.frmrecomendar.nombreGrupo.value+"&codigoGrupo="+document.frmrecomendar.codigoGrupo.value+"&amignombre="+document.frmrecomendar.amignombre.value+"&amigemail="+document.frmrecomendar.amigemail.value, peticion);
        }
    }else{
    var txError = document.createElement("p");
    var myTexto;
    var imErr;
    if (txErr!=null && txErr!=""){
        imErr=document.createElement("img");
        imErr.src="/i/error2.gif";
        imErr.alt="Error datos";
        myTexto = document.createTextNode(txErr);
    }else{
    myTexto = document.createTextNode("Enviando la recomendación");
    var myConn = new XHConn();
    if (!myConn) alert("XMLHTTP no esta disponible. Inténtalo con un navegador más actual.");
    var peticion = function (oXML) {
        recIn.style.display='none';
        var rText=oXML.responseText;
        if (rText.indexOf("{")>=0){
            var respuesta=eval('('+rText+')');
            if (respuesta){
                document.getElementById('respRecom'+id).innerHTML=respuesta.resp;
            }
        }
        document.getElementById('recHecha'+id).style.display='block';
    }
    myConn.connect("/grupo/enviarInvitacion.htm", "POST", "tipoRecomendacion="+origen+"&nombreGrupo="+document.frmrecomendar.nombreGrupo.value+"&codigoGrupo="+document.frmrecomendar.codigoGrupo.value+"&amignombre="+document.frmrecomendar.amignombre.value+"&amigemail="+document.frmrecomendar.amigemail.value, peticion);
}
if (imErr!=null && typeof(imErr)!='undefined' && imErr.nodeType==1) txError.appendChild(imErr);
txError.appendChild(myTexto);
txError.id="txReco"+id;
txError.className="txReco";
txError.style.fontFamily="Arial";
txError.style.fontSize="12px"
txError.style.color="#fe8434";
txError.style.textDecoration="none";
txError.style.textAlign="justify";
//recIn.insertBefore(txError,getFirstChild(recIn));
recIn.appendChild(txError);
}
return false;
}

function mostrarBotonInvitar(idGrupo, nombre){
    var logado=getCookie("estantesCk");
    var nodo=document.getElementById("botonInvitar");
    var texto='';
    if(logado==null || logado==''){
        texto='<a href=\'#\' onclick="mostrarInvitarEOR();return false"><img src="/i/btn_invitarGrupo.jpg" /></a>';
    }else{
        texto='<a href=\'#\' onclick="mostrarInvitar(\'recomendar\',\'fg\',\''+idGrupo+'\',\''+nombre+'\');return false"><img src="/i/btn_invitarGrupo.jpg" /></a>';
    }
    nodo.innerHTML=texto;
}

function recomendarEOR(){
    var reco=document.getElementById('recomendar');
    var recIn=document.getElementById('recInputs');
    var txReco=document.getElementById('txReco');
    var txErr=validarRecoEOR();
    if (txReco!=null && typeof(txReco)!='undefined' && txReco.nodeType==1){
        if (txErr!=null && txErr!="") txReco.innerHTML="<img src='/i/error2.gif' alt='Error datos' />"+txErr;
        else{
            document.forms['frmrecomendarEOR'].location.value=window.location.pathname+window.location.search;
            document.forms['frmrecomendarEOR'].submit();
        }
    }else{
        var txError = document.createElement("p");
        var myTexto;
        var imErr;
        if (txErr!=null && txErr!=""){
            imErr=document.createElement("img");
            imErr.src="/i/error2.gif";
            imErr.alt="Error datos";
            myTexto = document.createTextNode(txErr);
        }else{
            document.forms['frmrecomendarEOR'].location.value=window.location.pathname+window.location.search;
            document.forms['frmrecomendarEOR'].submit();
        }
        if (imErr!=null && typeof(imErr)!='undefined' && imErr.nodeType==1) txError.appendChild(imErr);
            txError.appendChild(myTexto);
            txError.id="txReco";
            txError.className="txReco";
            txError.style.fontFamily="Arial";
            txError.style.fontSize="12px"
            txError.style.color="#fe8434";
            txError.style.textDecoration="none";
            txError.style.textAlign="justify";
            recIn.appendChild(txError);
    }
}
function validarRecoGrupo(id){
    var txErr="";
    if (isEmpty(document.forms['frmrecomendar'+id].amignombre.value)){
        txErr=txErr+" El Nombre de tu amigo no puede estar vac\xfedo.";
    }
    if (!isEmail(document.forms['frmrecomendar'+id].amigemail.value)){
        txErr=txErr+" El Email de tu amigo no es correcto.";
    }
    return txErr;
}
function validarRecoEOR(){
    var txErr="";
    if (isEmpty(document.forms['frmrecomendarEOR'].amignombre.value)){
        txErr=txErr+" El Nombre de tu amigo no puede estar vac\xfedo.";
    }
    if (!isEmail(document.forms['frmrecomendarEOR'].amigemail.value)){
        txErr=txErr+" El Email de tu amigo no es correcto.";
    }
    return txErr;
}
function unir(){
            document.forms['frmunir'].location.value=window.location.pathname+window.location.search;
            document.forms['frmunir'].submit();
}

function mostrarEditar(campo, link, linkGuardar, input){
        if(campo!=''){
            document.getElementById(campo).onfocus = null;
            document.getElementById(campo).disabled = false;
            document.getElementById(campo).className = "enabled_presentacion";
            document.getElementById(campo).style.visibility = "visible";
            document.getElementById(campo).style.display="block";
        }else{
            document.getElementById('aviso').style.visibility = "visible";
        }
        document.getElementById(link).style.visibility = "hidden";
        document.getElementById(linkGuardar).style.visibility = "visible";
        if(input!=''){
            document.getElementById(input).style.visibility = "visible";
        }
    }
    function checkGuardar(campo){
        var alerta="";
        var hayAlerta=false;
        if(campo=='nombre_grupo'){
            if(document.getElementById(campo) == null || document.getElementById(campo).value.replace(/^(\s|\&nbsp;)*|(\s|\&nbsp;)*$/g,"")==''){
                        hayAlerta=true;
                        alerta = alerta + "Tienes que poner un nombre al grupo\n";
            }else{
                if(document.getElementById(campo).value.replace(/^(\s|\&nbsp;)*|(\s|\&nbsp;)*$/g,"").length<4){
                    hayAlerta=true;
                    alerta = alerta + "Tienes que poner un nombre con m\xfe1s de 3 caracteres\n";
                }
            }
            if(hayAlerta){
                document.getElementById("alerta_nombre").innerHTML="<p style='color:red;font-weight:bold'>"+alerta+"</p>";
            }else{
                document.forms['cambiarNombre'].location.value=window.location.pathname+window.location.search;
                document.forms['cambiarNombre'].submit();
            }
        }else if(campo=='file_guardar_foto'){
                if(document.getElementById(campo) == null || document.getElementById(campo).value.replace(/^(\s|\&nbsp;)*|(\s|\&nbsp;)*$/g,"")==''){
                    hayAlerta=true;
                    alerta = alerta + "Tienes que seleccionar una imagen\n";
                }
                if(hayAlerta){
                    document.getElementById("alerta_foto").innerHTML="<p style='color:red;font-weight:bold'>"+alerta+"</p>";
                }else{
                    document.getElementById('link_guardar_foto').style.display='none';
                    document.forms['cambiarFoto'].location.value=window.location.pathname+window.location.search;
                    submitImagenGrupo(document.forms['cambiarFoto']);
                }
        }else{
            document.forms['cambiarPresentacion'].location.value=window.location.pathname+window.location.search;
            document.forms['cambiarPresentacion'].submit();
        }
    }

    AIM = {

    frame : function(c) {

        var n = 'f' + Math.floor(Math.random() * 99999);
        var d = document.createElement('DIV');
        d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
        document.body.appendChild(d);

        var i = document.getElementById(n);
        if (c && typeof(c.onComplete) == 'function') {
            i.onComplete = c.onComplete;
        }

        return n;
    },

    form : function(f, name) {
        f.setAttribute('target', name);
    },

    submit : function(f, c) {
        AIM.form(f, AIM.frame(c));
        if (c && typeof(c.onStart) == 'function') {
            return c.onStart();
        } else {
            return true;
        }
    },

    loaded : function(id) {
        var i = document.getElementById(id);
        if (i.contentDocument) {
            var d = i.contentDocument;
        } else if (i.contentWindow) {
            var d = i.contentWindow.document;
        } else {
            var d = window.frames[id].document;
        }
        if (d.location.href == "about:blank") {
            return;
        }

        if (typeof(i.onComplete) == 'function') {
            i.onComplete(d.body.innerHTML);
        }
    }

}
function getTopPos(objet){
    var returnValue=objet.offsetTop;
    while ((objet=objet.offsetParent)!=null){
        if (objet.tagName!='HTML') returnValue+=objet.offsetTop;
    }
    return returnValue;
}
function getLeftPos(objet){
    var returnValue=objet.offsetLeft;
    while ((objet=objet.offsetParent)!=null){
        if (objet.tagName!='HTML') returnValue+=objet.offsetLeft;
    }
    return returnValue;
}
function startCallback() {
        var capa=document.getElementById('sube');
        capa.innerHTML ="<img width=\"109px\" height=\"116px\" src=\"/i/cargando.gif\" alt=\"Subiendo imagen\" />";
        capa.style.top=(getTopPos(document.cambiarFoto.imagenGrupo)-8)+'px';
        capa.style.left=(getLeftPos(document.cambiarFoto.imagenGrupo)-10)+'px';
        document.getElementById('imagenGrupo').style.visibility='hidden';
        document.getElementById('file_guardar_foto').style.visibility='hidden';
        document.getElementById('aviso').style.visibility='hidden';
        document.getElementById('alerta_foto').style.visibility='hidden';
        capa.style.visibility='visible';
        return true;
}

function completeCallback(response) {
        var capa=document.getElementById('sube');
        capa.innerHTML=response;
        capa.style.visibility='visible';
}
function submitImagenGrupo(form){
    if (!AIM.submit(form, {
        'onStart' : startCallback,
        'onComplete' : completeCallback
    })){
        }
        form.submit();
}

    function crearComentarioGrupo(){
        var texto=document.forms['comentario'].opinion_grupo.value;
        if (texto!=null && texto!='' && texto!='Incluye tu comentario...'){
            document.forms['comentario'].location.value=window.location.pathname+window.location.search;
            document.comentario.submit();
        }else{
            document.getElementById("opinion_grupo").value='Incluye un comentario..';
        }
    }
function mostrarBuscadorAvanzado(idBiblioteca, existeLista, formUrl, urlBiblioteca){
    var nodo=document.getElementById("busquedaAvanzada");
    var texto='';
    if((idBiblioteca!=null && idBiblioteca!='') || existeLista){
        texto='<div class="buscar">';
        texto+='<form name="buscador" action="'+formUrl+'" method="get">';
        texto+='<div class="izquierda"><br /><p class="texto_gris">Puedes seguir a\xf1adiendo libros a continuaci\xf3n</p><div class="interUsr">';
        texto+='<select name="buscarPor"><option value="">Seleccione</option><option value="t">T\xedtulo</option><option value="a">Autor</option><option value="i">ISBN</option></select>';
        texto+='<input id="buscar" name="buscar" type="text" value="B\xfasqueda" onfocus="if(this.value==\'B\xfasqueda\')this.value=\'\';" onblur="if(this.value.replace(/^(\\s|\\&nbsp;)*|(\\s|\\&nbsp;)*$/g,\'\') ==\'\')this.value=\'B\xfasqueda\';"/>';
        texto+='<input type="hidden" name="idBiblioteca" id="idBiblioteca" value="'+idBiblioteca+'"/>';
        texto+='<input type="hidden" name="tbusq" id="tbusq" value="l"/></div></div><div class="derecha"><div class="btn_verlibro"><a href="#" onClick="javascript:realizarBusqueda();"><img src="/i/btn_verLibro.jpg" /></a></div>';
        if(idBiblioteca!=null && idBiblioteca!=''){
            texto+='<div class="foto"><a href="'+urlBiblioteca+'"><img src="/i/btn_irBiblioteca.jpg" /></a></div>';
        }
        texto+='</div></form></div>';
    }
    nodo.innerHTML=texto;
}
function pseudonimoValido(campo){
    var expres=/^[a-z\-\_0-9]{3,}$/;
    return expres.test(campo);
}
function comprobarRegEntrar(){
    var formu=document.registrar;
    var errorReg=document.getElementById("errorReg");
    var txtError="";
    var txtMal="";
    if (isValorVacio(formu.nombre_miembro.value)){
        txtError+="Nombre.&nbsp;&nbsp;";
    }
    if (isValorVacio(formu.apellidos_miembro.value)){
        txtError+="Apellidos.&nbsp;&nbsp;";
    }
    if (isValorVacio(formu.nick_miembro.value)){
        txtError+="Pseud&oacute;nimo.&nbsp;&nbsp;";
    }else{
        if (!pseudonimoValido(Trim(formu.nick_miembro.value))){
            txtMal+="Pseud&oacute;nimo no v&aacute;lido.&nbsp;&nbsp;";
        }
    }
    if (isValorVacio(formu.mail_miembro.value)){
        txtError+="Correo electr&oacute;nico.&nbsp;&nbsp;";
    }else{
        if (!isEmail(formu.mail_miembro.value)){
            txtMal+="Correo electr&oacute;nico incorrecto.&nbsp;&nbsp;";
        }
    }
    if (isValorVacio(formu.password_miembro.value)){
        txtError+="Contrase&ntilde;a.&nbsp;&nbsp;";
    }
    if (isValorVacio(formu.password2_miembro.value)){
        txtError+="Repetir Contrase&ntilde;a.&nbsp;&nbsp;";
    }
    if (!isValorVacio(formu.password_miembro.value) && formu.password_miembro.value!=formu.password2_miembro.value){
        txtMal+="Contrase&ntilde;as no coinciden.&nbsp;&nbsp;";
    }
    if (formu.comboSexo.selectedIndex==0){
        txtError+="Sexo.&nbsp;&nbsp;";
    }
    if (formu.comboDiaCumple.selectedIndex==0 || formu.comboMesCumple.selectedIndex==0 || formu.comboAnioCumple.selectedIndex==0){
        txtError+="Fecha de nacimiento.&nbsp;&nbsp;";
    }
    if (formu.comboPais.selectedIndex==0){
        txtError+="Pa&iacute;s.&nbsp;&nbsp;";
    }
    if(!formu.terminos.checked){
        txtError+="Debes aceptar los t&eacute;rminos";
    }
    if (!isValorVacio(txtError) || !isValorVacio(txtMal)){
        if (!isValorVacio(txtError)) txtError="Campos obligatorios:&nbsp;&nbsp;"+txtError;
        if (!isValorVacio(txtMal)) txtMal="Campos err&oacute;neos:&nbsp;&nbsp;"+txtMal;
        if (errorReg!=null && typeof(errorReg)!='undefined' && errorReg.nodeType==1){
            errorReg.innerHTML=txtError+"<br />"+txtMal;
            errorReg.style.display="block";
        }
        return false;
    }else{
        return true;
    }
}
function loginEntrar(){
    var formu=document.login;
    var errorReg=document.getElementById("errorLogin");
    var txtError="";
    if (!isValorVacio(formu.mail_miembro.value) && !isValorVacio(formu.password_miembro.value)){
        if (!isEmail(formu.mail_miembro.value)){
            txtError="Correo electr&oacute;nico incorrecto.";
        }
    }else{
        txtError="Rellena correo electr&oacute;nico y contrase&ntilde;a.";
    }
    if (!isValorVacio(txtError)){
        if (errorReg!=null && typeof(errorReg)!='undefined' && errorReg.nodeType==1){
            errorReg.innerHTML=txtError;
            errorReg.style.display="block";
        }
        return false;
    }else{
        return true;
    }
}
function comprobarRegistro(){
    var formu=document.formulario;
    var errorReg=document.getElementById("errorReg");
    var txtError="";
    var txtMal="";
    if (isValorVacio(formu.nombre_miembro.value)){
        txtError+="Nombre.&nbsp;&nbsp;";
    }
    if (isValorVacio(formu.apellidos_miembro.value)){
        txtError+="Apellidos.&nbsp;&nbsp;";
    }
    if (isValorVacio(formu.nickname_miembro.value)){
        txtError+="Pseud&oacute;nimo.&nbsp;&nbsp;";
    }else{
        if (!pseudonimoValido(Trim(formu.nickname_miembro.value))){
            txtMal+="Pseud&oacute;nimo no v&aacute;lido.&nbsp;&nbsp;";
        }
    }
    if (isValorVacio(formu.mail_miembro.value)){
        txtError+="Correo electr&oacute;nico.&nbsp;&nbsp;";
    }else{
        if (!isEmail(formu.mail_miembro.value)){
            txtMal+="Correo electr&oacute;nico incorrecto.&nbsp;&nbsp;";
        }
    }
    if (isValorVacio(formu.password_miembro.value)){
        txtError+="Contrase&ntilde;a.&nbsp;&nbsp;";
    }
    if (isValorVacio(formu.password2_miembro.value)){
        txtError+="Repetir Contrase&ntilde;a.&nbsp;&nbsp;";
    }
    if (!isValorVacio(formu.password_miembro.value) && formu.password_miembro.value!=formu.password2_miembro.value){
        txtMal+="Contrase&ntilde;as no coinciden.&nbsp;&nbsp;";
    }
    if (formu.comboSexo.selectedIndex==0){
        txtError+="Sexo.&nbsp;&nbsp;";
    }
    if (formu.comboDiaCumple.selectedIndex==0 || formu.comboMesCumple.selectedIndex==0 || formu.comboAnioCumple.selectedIndex==0){
        txtError+="Fecha de nacimiento.&nbsp;&nbsp;";
    }
    if (formu.comboPais.selectedIndex==0){
        txtError+="Pa&iacute;s.&nbsp;&nbsp;";
    }
    if (formu.comboLibros.selectedIndex==0){
        txtError+="N&uacute;mero libros que lee.&nbsp;&nbsp;";
    }
    if(!formu.terminos.checked){
        txtError+="Debes aceptar los t&eacute;rminos";
    }
    if (!isValorVacio(txtError) || !isValorVacio(txtMal)){
        if (!isValorVacio(txtError)) txtError="Campos obligatorios:&nbsp;&nbsp;"+txtError;
        if (!isValorVacio(txtMal)) txtMal="Campos err&oacute;neos:&nbsp;&nbsp;"+txtMal;
        if (errorReg!=null && typeof(errorReg)!='undefined' && errorReg.nodeType==1){
            errorReg.innerHTML=txtError+"<br />"+txtMal;
            errorReg.style.display="block";
        }
        return false;
    }else{
        return true;
    }
}
function comprobarPerfil(){
    var formu=document.formulario;
    var errorReg=document.getElementById("errorReg");
    var txtError="";
    var txtMal="";
    if (isValorVacio(formu.nombre_miembro.value)){
        txtError+="Nombre.&nbsp;&nbsp;";
    }
    if (isValorVacio(formu.apellidos_miembro.value)){
        txtError+="Apellidos.&nbsp;&nbsp;";
    }
    if (!formu.passant_miembro.disabled){
        if (!isValorVacio(formu.passant_miembro.value) && !isValorVacio(formu.pass1_miembro.value) && !isValorVacio(formu.pass2_miembro.value)){
            if (isValorVacio(formu.passant_miembro.value)){
                txtError+="Contrase&ntilde;a antigua.&nbsp;&nbsp;";
            }
            if (isValorVacio(formu.pass1_miembro.value)){
                txtError+="Contrase&ntilde;a nueva.&nbsp;&nbsp;";
            }
            if (isValorVacio(formu.pass2_miembro.value)){
                txtError+="Repetir Contrase&ntilde;a nueva.&nbsp;&nbsp;";
            }
            if (!isValorVacio(formu.pass1_miembro.value) && formu.pass1_miembro.value!=formu.pass2_miembro.value){
                txtMal+="Contrase&ntilde;as nuevas no coinciden.&nbsp;&nbsp;";
            }
        }
    }
    if (formu.comboSexo.selectedIndex==0){
        txtError+="Sexo.&nbsp;&nbsp;";
    }
    if (formu.comboDiaCumple.selectedIndex==0 || formu.comboMesCumple.selectedIndex==0 || formu.comboAnioCumple.selectedIndex==0){
        txtError+="Fecha de nacimiento.&nbsp;&nbsp;";
    }
    if (formu.comboPais.selectedIndex==0){
        txtError+="Pa&iacute;s.&nbsp;&nbsp;";
    }
    if (formu.comboLibros.selectedIndex==0){
        txtError+="N&uacute;mero libros que lee.&nbsp;&nbsp;";
    }
    if (!isValorVacio(txtError) || !isValorVacio(txtMal)){
        if (!isValorVacio(txtError)) txtError="Campos obligatorios:&nbsp;&nbsp;"+txtError;
        if (!isValorVacio(txtMal)) txtMal="Campos err&oacute;neos:&nbsp;&nbsp;"+txtMal;
        if (errorReg!=null && typeof(errorReg)!='undefined' && errorReg.nodeType==1){
            errorReg.innerHTML=txtError+"<br />"+txtMal;
            errorReg.style.display="block";
        }
        return false;
    }else{
        return true;
    }
}
function habilCampo(campo){
    var nomClase=campo.className;
    nomClase=nomClase.replace("deshabil","habil");
    campo.className=nomClase;
}
function editarCampo(formu,campo, link){
    if (campo=="password"){
        var divPass=document.getElementById("password");
        if (divPass!=null && typeof(divPass)!='undefined'){
            divPass.style.display="block";
            var campoF=eval('document.forms["'+formu+'"].passant_miembro');
            if (campoF!=null && typeof(campoF)!='undefined'){
                campoF.disabled=false;
                habilCampo(campoF);
                campoF.focus();
            }
            campoF=eval('document.forms["'+formu+'"].pass1_miembro');
            if (campoF!=null && typeof(campoF)!='undefined'){
                campoF.disabled=false;
                habilCampo(campoF);
            }
            campoF=eval('document.forms["'+formu+'"].pass2_miembro');
            if (campoF!=null && typeof(campoF)!='undefined'){
                campoF.disabled=false;
                habilCampo(campoF);
            }
        }
    }else{
        var campoF=eval('document.forms["'+formu+'"].'+campo);
        if (campoF!=null && typeof(campoF)!='undefined'){
            campoF.disabled=false;
            habilCampo(campoF);
            campoF.focus();
            if (campo=="comboDiaCumple"){
                editarCampo(formu,"comboMesCumple", link);
                editarCampo(formu,"comboAnioCumple", link);
            }else{
                if (campo=="mail_miembro"){
                    var divPass=document.getElementById("passemail");
                    if (divPass!=null && typeof(divPass)!='undefined'){
                        divPass.style.display="block";
                        var campoF=eval('document.forms["'+formu+'"].passemail_miembro');
                        if (campoF!=null && typeof(campoF)!='undefined'){
                            campoF.disabled=false;
                            habilCampo(campoF);
                        }
                    }
                }
            }
        }
    }
}

function comprobarComentarioPost(){
    var errorForm="";
    var form=document.comentario;
    if (form.seudonimo!=null && typeof(form.seudonimo)!='undefined' && form.seudonimo.nodeType==1 && form.mail!=null && typeof(form.mail)!='undefined' && form.mail.nodeType==1){
        if (!isValorVacio(form.seudonimo.value) && !isValorVacio(form.mail.value)){
            var mySplitResult = form.comentario_post.value.split("href");
            var str=sustituirEmoticonos(form.comentario_post.value);
            form.comentario_post.value=str;
            if (isEmail(form.mail.value)){
                if (isValorVacio(form.comentario_post.value) || form.comentario_post.value=="Incluye tu comentario.." || form.comentario_post.value=="Incluye tu comentario..."){
                    errorForm+=" El comentario es obligatorio";
                }else{
                        if(form.crc!=null)
                            form.crc.value="librodearena";
                        form.submit();
                }
            }else{
                errorForm+="Email no es v&aacute;lido.";
            }
        }else{
            if (isValorVacio(form.seudonimo.value)){
                errorForm+="Nombre es obligatorio.";
            }
            if (isValorVacio(form.mail.value)){
                errorForm+=" Email es obligatorio.";
            }
        }
    }else{
        if (isValorVacio(form.comentario_post.value) || form.comentario_post.value=="Incluye tu comentario.."|| form.comentario_post.value=="Incluye tu comentario..."){
            errorForm+=" El comentario es obligatorio";
        }else{
            form.submit();
        }
    }
    if (!isValorVacio(errorForm)){
        var error=document.getElementById("error");
        error.style.display="block";
        error.innerHTML=errorForm;
    }
}

function comprobarBusquedaBlogs(texto, origen){
  var t = String(texto);


    if(t.length<3){
        //alert("es menor de 3!");
        document.getElementById("mensaje"+origen).style.visibility='visible';

    }else{
        document.getElementById("texto").value=t;
    document.getElementById("searchform").submit();
    }

}

function sustituirEmoticonos(x)
{
    var cadena = "";
    var cadena1 = "";
    var cadena2 = "";
    var texto = x;
    var ima = "";
    for(var i = 0;i<texto.length ;i++)
    {
        cadena = texto.substring(i,i+2);
        cadena1 = texto.substring(i,i+3);
        cadena2 = texto.substring(i,i+4);

        if(cadena == ":)" && cadena1 != ":))" && cadena2!= ":)>-"){
            ima ="<img src=/i/emoticonos/1.gif> ";
            texto = texto.replace(cadena,ima);
        }
        if(cadena1 == ":-)"){
            ima ="<img src=/i/emoticonos/1.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena == ":(" && cadena1 != ":((" && cadena2 != ":(|)"){
            ima ="<img src=/i/emoticonos/2.gif> ";
            texto = texto.replace(cadena,ima);
        }
        if(cadena1 == ":-("){
            ima ="<img src=/i/emoticonos/2.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena == ";)" && cadena1 != ";))"){
            ima ="<img src=/i/emoticonos/3.gif> ";
            texto = texto.replace(cadena,ima);
        }
        if(cadena1 == ";-)"){
            ima ="<img src=/i/emoticonos/3.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena == ":D"){
            ima ="<img src=/i/emoticonos/4.gif> ";
            texto = texto.replace(cadena,ima);
        }
        if(cadena1 == ":-D"){
            ima ="<img src=/i/emoticonos/4.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ";;)"){
            ima ="<img src=/i/emoticonos/5.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ":-/"){
            ima ="<img src=/i/emoticonos/6.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena == ":x" || cadena == ":X"){
            ima ="<img src=/i/emoticonos/7.gif> ";
            texto = texto.replace(cadena,ima);
        }
        if(cadena1 == ":-x" || cadena1 == ":-X"){
            ima ="<img src=/i/emoticonos/7.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ":\">"){
            ima ="<img src=/i/emoticonos/8.gif> ";
            texto = texto.replace(cadena2,ima);
        }
        if(cadena == ":p"){
            ima ="<img src=/i/emoticonos/9.gif> ";
            texto = texto.replace(cadena,ima);
        }
        if(cadena1 == ":-p"){
            ima ="<img src=/i/emoticonos/9.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena == ":*"){
            ima ="<img src=/i/emoticonos/10.gif> ";
            texto = texto.replace(cadena,ima);
        }
        if(cadena1 == ":-*"){
            ima ="<img src=/i/emoticonos/10.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if((cadena == ":o" && cadena1 != ":o)") || cadena == ":O"){
            ima ="<img src=/i/emoticonos/11.gif> ";
            texto = texto.replace(cadena,ima);
        }
        if(cadena1 == ":-o" || cadena1 == ":-O"){
            ima ="<img src=/i/emoticonos/11.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == "X-("){
            ima ="<img src=/i/emoticonos/12.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena == ":>"){
            ima ="<img src=/i/emoticonos/13.gif> ";
            texto = texto.replace(cadena,ima);
        }
        if(cadena1 == ":->"){
            ima ="<img src=/i/emoticonos/13.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena == "B)"){
            ima ="<img src=/i/emoticonos/14.gif> ";
            texto = texto.replace(cadena,ima);
        }
        if(cadena1 == "B-)"){
            ima ="<img src=/i/emoticonos/14.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena == ":s" || cadena == ":S"){
            ima ="<img src=/i/emoticonos/15.gif> ";
            texto = texto.replace(cadena,ima);
        }
        if((cadena1 == ":-s" && cadena2!=":-ss") || (cadena1 == ":-S" && cadena2 != ":-SS")){
            ima ="<img src=/i/emoticonos/15.gif> ";
            texto = texto.replace(cadena1,ima);
        }

        if(cadena1 == ">:)"){
            ima ="<img src=/i/emoticonos/16.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ":(("){
            ima ="<img src=/i/emoticonos/17.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ":))"){
            ima ="<img src=/i/emoticonos/18.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena == ":|"){
            ima ="<img src=/i/emoticonos/19.gif> ";
            texto = texto.replace(cadena,ima);
        }
        if(cadena1 == ":-|"){
            ima ="<img src=/i/emoticonos/19.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == "/:)"){
            ima ="<img src=/i/emoticonos/20.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == "o:)" || cadena1 == "O:)"){
            ima ="<img src=/i/emoticonos/21.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ":-B"){
            ima ="<img src=/i/emoticonos/22.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena == "=;"){
            ima ="<img src=/i/emoticonos/23.gif> ";
            texto = texto.replace(cadena,ima);
        }
        if(cadena1 == "I-)" || cadena1 == "|-)"){
            ima ="<img src=/i/emoticonos/24.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == "8-|"){
            ima ="<img src=/i/emoticonos/25.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ":-&"){
            ima ="<img src=/i/emoticonos/26.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ":-$"){
            ima ="<img src=/i/emoticonos/27.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == "[-("){
            ima ="<img src=/i/emoticonos/28.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ":o)"){
            ima ="<img src=/i/emoticonos/29.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == "8-}"){
            ima ="<img src=/i/emoticonos/30.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == "(:|"){
            ima ="<img src=/i/emoticonos/31.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == "=P~"){
            ima ="<img src=/i/emoticonos/32.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ":-?"){
            ima ="<img src=/i/emoticonos/33.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == "#-o" || cadena1 == "#-O"){
            ima ="<img src=/i/emoticonos/34.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == "=D>"){
            ima ="<img src=/i/emoticonos/35.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ":@)"){
            ima ="<img src=/i/emoticonos/36.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena2 == "3:-O"){
            ima ="<img src=/i/emoticonos/37.gif> ";
            texto = texto.replace(cadena2,ima);
        }
        if(cadena2 == ":(|)"){
            ima ="<img src=/i/emoticonos/38.gif> ";
            texto = texto.replace(cadena2,ima);
        }
        if(cadena1 == "~:>"){
            ima ="<img src=/i/emoticonos/39.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena2 == "@};-"){
            ima ="<img src=/i/emoticonos/40.gif> ";
            texto = texto.replace(cadena2,ima);
        }
        if(cadena1 == "%%-"){
            ima ="<img src=/i/emoticonos/41.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena2 == "**=="){
            ima ="<img src=/i/emoticonos/42.gif> ";
            texto = texto.replace(cadena2,ima);
        }
        if(cadena2 == "(~~)"){
            ima ="<img src=/i/emoticonos/43.gif> ";
            texto = texto.replace(cadena2,ima);
        }
        if(cadena1 == "~o)"){
            ima ="<img src=/i/emoticonos/44.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena2 == "*-:)"){
            ima ="<img src=/i/emoticonos/45.gif> ";
            texto = texto.replace(cadena2,ima);
        }
        if(cadena1 == "8-X"){
            ima ="<img src=/i/emoticonos/46.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == "=:)"){
            ima ="<img src=/i/emoticonos/47.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ">-)"){
            ima ="<img src=/i/emoticonos/48.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ":-L"){
            ima ="<img src=/i/emoticonos/49.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena2 == "<):)"){
            ima ="<img src=/i/emoticonos/50.gif> ";
            texto = texto.replace(cadena2,ima);
        }
        if(cadena1 == "[-o"){
            ima ="<img src=/i/emoticonos/51.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena2 == "<@-)"){
            ima ="<img src=/i/emoticonos/52.gif> ";
            texto = texto.replace(cadena2,ima);
        }
        if(cadena1 == "$-)"){
            ima ="<img src=/i/emoticonos/53.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ":-\\"){
            ima ="<img src=/i/emoticonos/54.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ":^o"){
            ima ="<img src=/i/emoticonos/55.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == "b-("){
            ima ="<img src=/i/emoticonos/56.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena2 == ":)>-"){
            ima ="<img src=/i/emoticonos/57.gif> ";
            texto = texto.replace(cadena2,ima);
        }
        if(cadena1 == "[-X"){
            ima ="<img src=/i/emoticonos/58.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena2 == "\\:D/"){
            ima ="<img src=/i/emoticonos/59.gif> ";
            texto = texto.replace(cadena2,ima);
        }
        if(cadena2 == ">:D<"){
            ima ="<img src=/i/emoticonos/60.gif> ";
            texto = texto.replace(cadena2,ima);
        }
        if(cadena2 == "#:-S" || cadena2 == "#:-s"){
            ima ="<img src=/i/emoticonos/61.gif> ";
            texto = texto.replace(cadena2,ima);
        }
        if(cadena1 == "=(("){
            ima ="<img src=/i/emoticonos/62.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == "=))"){
            ima ="<img src=/i/emoticonos/63.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == "L-)"){
            ima ="<img src=/i/emoticonos/64.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena2 == "<:-P"){
            ima ="<img src=/i/emoticonos/65.gif> ";
            texto = texto.replace(cadena2,ima);
        }
        if(cadena2 == ":-SS" || cadena2 == ":-ss"){
            ima ="<img src=/i/emoticonos/66.gif> ";
            texto = texto.replace(cadena2,ima);
        }
        if(cadena1 == ":-w" || cadena1 == ":-W"){
            ima ="<img src=/i/emoticonos/67.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ":-<"){
            ima ="<img src=/i/emoticonos/68.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ">:P"){
            ima ="<img src=/i/emoticonos/69.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ">:/"){
            ima ="<img src=/i/emoticonos/70.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ";))"){
            ima ="<img src=/i/emoticonos/71.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == ":-@"){
            ima ="<img src=/i/emoticonos/72.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena2 == "^:)^"){
            ima ="<img src=/i/emoticonos/73.gif> ";
            texto = texto.replace(cadena2,ima);
        }
        if(cadena1 == ":-j"){
            ima ="<img src=/i/emoticonos/74.gif> ";
            texto = texto.replace(cadena1,ima);
        }
        if(cadena1 == "(*)"){
            ima ="<img src=/i/emoticonos/75.gif> ";
            texto = texto.replace(cadena1,ima);
        }
    }
    return texto;

}
