IE4 = (document.all);
NS4 = (document.layers);
if (!IE4) {
	if (!NS4)
		NS4 = (document.getElementById);
}

var form1=false;
var form2=false;

if (NS4) document.captureEvents(Event.KEYPRESS);
document.onkeypress = doKey;

function processClicks() {
	return false;
}

function processKeys() {
	return false;
}

function Querystring(){
// get the query string, ignore the ? at the front.
	var querystring=location.search.substring(1,location.search.length);

// parse out name/value pairs separated via &
	var args = querystring.split('&');

// split out each name = value pair
	for (var i=0;i < args.length;i++) {
		var pair = args[i].split('=');

		// Fix broken unescaping
		temp = unescape(pair[0]).split('+');
		temp0 = temp.join(' ');

		temp = unescape(pair[1]).split('+');
		temp1 = temp.join(' ');

		this[temp0]=temp1;
	}
	this.get=Querystring_get;
}

function Querystring_get(strKey,strDefault) {
	var value=this[strKey];
	if (value==null){value=strDefault;}

	return value;
}
var qs = new Querystring();
var ca= qs.get("ca","null");
if (ca!='null') {
	setCookie("codigoAfiliado",ca,"","/","","");
}

var esInt=qs.get("in","null");
var esIn=false;
if (esInt!='null' && !isEmpty (esInt) && esInt=="1")
esIn=true;
else
esIn=false;

var rapidaenviada=false;
var avanzenviada=false;
function busqueda(){
	document.onclick = processClicks;
	document.onkeypress=processKeys;
	document.form_busqueda.boton_Buscar.disabled=true;
	document.form_busqueda.buscar.readOnly=true;
	document.form_busqueda.action='/busquedas/quickResults';
	if (!rapidaenviada){ rapidaenviada=true;document.form_busqueda.submit();}
	return false;
}

function doKey(e) {
  whichASC = (NS4) ? e.which : event.keyCode;
  whichKey = String.fromCharCode(whichASC).toLowerCase();

  if (whichASC == 13) {
    if (form1) {
	document.onkeypress=processKeys;
	document.form_busqueda.boton_Buscar.disabled=true;
	document.form_busqueda.buscar.readOnly=true;

	busqueda();
    }
    if (form2){
        busqAvanz();
    }
  }
}

function setFormModified(formName) {
  if (formName=='quick') {
      form1=true;
      form2=false;
  }
  if (formName=='advanced') {
      form1=false;
      form2=true;
  }
}

function busqAvanz(){
	document.fBusquedaAvanzada.action='/busquedas/resultados';
	document.fBusquedaAvanzada.onkeypress=processKeys;
	document.fBusquedaAvanzada.titbus.readOnly=true;
	document.fBusquedaAvanzada.autorbus.readOnly=true;
	document.fBusquedaAvanzada.isbnbus.readOnly=true;
	document.fBusquedaAvanzada.editbus.readOnly=true;
	document.fBusquedaAvanzada.idibus.readOnly=true;
	document.fBusquedaAvanzada.encbus.readOnly=true;
	document.fBusquedaAvanzada.sl1.readOnly=true;
	var boton=document.fBusquedaAvanzada.bot_ava;
	if (boton!=null && typeof(boton)!='undefined' && boton.nodeType==1) document.fBusquedaAvanzada.bot_ava.disabled=true;
    if (!avanzenviada){
        avanzenviada=true;
        var pathPage=location.pathname;
        var tipoBus='';
        if (pathPage.indexOf("/quickResults")!=-1){
            tipoBus='rapida';
        }else{
            if (pathPage.indexOf("/resultados")!=-1){
                tipoBus='avanzada';
            }else{
                if (pathPage.indexOf("/libro/")==0 || pathPage.indexOf("/ultimonivel")!=-1 || pathPage.indexOf("/niveltres")!=-1){
                    tipoBus='tematica';
                }
            }
        }
        trackFormAvanzada(tipoBus,document.fBusquedaAvanzada);
        document.fBusquedaAvanzada.submit();
    }
	return false;
}
var cdlvisitor= getCookie("cdlvisitor");
var uNombre= getUNombre();
var uRapida= getURapida();
var uId= getUId();

function getUNombre() {
	uNombre='';
	if (cdlvisitor!=null) {
		var i1= cdlvisitor.indexOf("-");
		if (i1>0) {
			var resto= cdlvisitor.substring(i1+1);
			var i2= resto.indexOf("-");
			if (i2>0) {
				uNombre= resto.substring(i2+1);
			}
		}
	}
	return uNombre;
}

function getURapida() {
	var uRapida='';
	if (cdlvisitor!=null) {
		var i1= cdlvisitor.indexOf("-");
		if (i1>=0) {
			var resto= cdlvisitor.substring(i1+1);
			var i2= resto.indexOf("-");
			if (i2>=0) {
				uRapida= resto.substring(0,i2);
			}
		}
	}
	return uRapida;
}

function getUId() {
	var uId='0';
		if (cdlvisitor!=null) {
		var i1= cdlvisitor.indexOf("-");
		if (i1>=0) {
			uId= cdlvisitor.substring(0,i1);
		}
	}
	return uId;
}

function getUrl(codigo,nombre) {
	if (codigo!='') {
		if (codigo=='1') {
			return "/comprar-libros";
		} else {
			return "/libros-"+nombre+"/"+codigo;
		}
	} else {
		return "/comprar-libros";
	}
}
function esNodo(nodo){
	return (nodo!=null && typeof(nodo)!='undefined' && nodo.nodeType==1);
}
function writePesta() {
        url=window.location.pathname;
        var pest;
        try{
	if (url=='' || url=='/' || url.indexOf("comprar-libros")>-1){
		pest=document.getElementById("ps1");
		if (esNodo(pest))
			pest.className="pestaAct";
	}else{
    		if (url.indexOf("libros-recomendados")>-1){
			pest=document.getElementById("ps2");
			if (esNodo(pest))
				pest.className="pestaAct";
    		}else{
    			if (url.indexOf("libros-destacados")>-1){
				pest=document.getElementById("ps3");
				if (esNodo(pest))
					pest.className="pestaAct";
    			}else{
                                if (url=="/ebooks" || url.indexOf("libros-novedades-ebook")>-1){
					pest=document.getElementById("ps9");
					if (esNodo(pest))
						pest.className="pestaAct";
    				}else{
                                    if (url.indexOf("libros-novedades")>-1){
                                            pest=document.getElementById("ps4");
                                            if (esNodo(pest))
                                                    pest.className="pestaAct";
                                    }else{
                                            if (url.indexOf("libros-mas-vendidos")>-1){
                                                    pest=document.getElementById("ps5");
                                                    if (esNodo(pest))
                                                            pest.className="pestaAct";
                                            }else{
                                                    if (url.indexOf("libros-bolsillo")>-1){
                                                            pest=document.getElementById("ps6");
                                                            if (esNodo(pest))
                                                                    pest.className="pestaAct";
                                                    }else{
                                                            if (url.indexOf("libros-ofertas")>-1){
                                                                    pest=document.getElementById("ps7");
                                                                    if (esNodo(pest))
                                                                            pest.className="pestaAct";
                                                            }else{
                                                                    if (url.indexOf("libros-preventa")>-1){
                                                                            pest=document.getElementById("ps8");
                                                                            if (esNodo(pest))
                                                                                    pest.className="pestaAct";
                                                                    }
                                                            }
                                                    }
                                            }
                                    }
                                }
    			}
		}
	}
	}catch(e){};
}

function replaceChars(entry, replace_this, with_this) {
	temp = "" + entry; // temporary holder

	while (temp.indexOf(replace_this)>-1) {
		pos= temp.indexOf(replace_this);
		temp = "" + (temp.substring(0, pos) + with_this + temp.substring((pos + replace_this.length), temp.length));
	}
	return temp;
}

function isEmptyWord(str) {
		str= Trim(str).toLowerCase();

		//Preposicion: a, de, con, en, del, al, por, para, segun
		esPreposicion= (str=="a") || (str=="de") || (str=="con") || (str=="en") || (str=="del") || (str=="al") || (str=="por") || (str=="para") || (str=="segun");
		//Articulo determinado: el, la , lo, los, las
		esDeterminado= (str=="el") || (str=="la") || (str=="lo") || (str=="los") || (str=="las");
		//Articulo Indeterminado: un, una, uno, unos, unas
		esIndeterminado= (str=="un") || (str=="una") || (str=="uno") || (str=="unos") || (str=="unas");
		//Conjunciones: y, o, e, que
		esConjuncion= (str=="y") || (str=="o") || (str=="e") || (str=="que");
		//Catalan: i, unes, les, els
		esCatalan= (str=="i") || (str=="unes") || (str=="les") || (str=="els");
		//Ingles: of, in, on, the, this, that, those, these, a
		esIngles= (str=="of") || (str=="in") || (str=="on") || (str=="the") || (str=="this") || (str=="that") || (str=="those") || (str=="these") || (str=="a");
		//Pronombre personales: yo, tu , ella, nosotros, vosotros, nosotras, vosotras, ellos, ellas
		esPronombre= (str=="yo") || (str=="tu") || (str=="ella") || (str=="nosotros") || (str=="vosotros") || (str=="nosotras") || (str=="vosotras") || (str=="ellos") || (str=="ellas");
		//Demostrativos: esto, esta, eso, esa, ese
		esDemostrativo= (str=="esto") || (str=="esta") || (str=="eso") || (str=="esa") || (str=="ese");
		//Posesivos: mio, mia, tuyo, tuya, suyo, suya, mi
		esPosesivo= (str=="mio") || (str=="mia") || (str=="tuyo") || (str=="tuya") || (str=="suyo") || (str=="suya") || (str=="mi");

		isEmpty= esPreposicion || esDeterminado || esIndeterminado || esConjuncion || esCatalan || esIngles || esPronombre || esDemostrativo | esPosesivo;
		return isEmpty;
}

function getMeaningWords(s) {
	var token="";
	var cadenaFinal= "";
	var cadena= new String(s);

	for (var i=0; i< cadena.length; i++) {
		if (cadena.charAt(i)!=' ') token=token+cadena.charAt(i);
		else {
			if (isEmptyWord(Trim(token))) token="";
			else {
				cadenaFinal=cadenaFinal+" "+Trim(token);
				token="";
			}
		}
	}

	if (isEmptyWord(Trim(token))) token="";
	else cadenaFinal=cadenaFinal+" "+Trim(token);

	cadenaFinal= replaceChars(cadenaFinal, ".", " ");

	return cadenaFinal.toLowerCase();
}

function writeFavo(categ){
	var favorit = getCookie("tematicas");
	var tempor = favorit;
	var catTemp ="";
	if (favorit!=null && favorit.length!=0){
		if (favorit.indexOf("-")!=-1){
			do {
			    catTemp=tempor.substring(0,tempor.indexOf("-"));
			    tempor=tempor.substring(tempor.indexOf("-")+1,tempor.length);
			    if (catTemp==categ){
			    	document.write('<img src="/i/prefer.gif" alt="Preferencia" />');
			    }
			}while(tempor.indexOf("-")!=-1)
			if (tempor==categ){
				document.write('<img src="/i/prefer.gif" alt="Preferencia" />');
			}
		}else{
			if (categ==favorit) document.write('<img src="/i/prefer.gif" alt="Preferencia" />');
		}
	}
}

function isFloat (s){
	var i;
	var seenDecimalPoint = false;
	if (isEmpty(s))
		if (isFloat.arguments.length == 1) return defaultEmptyOK;
	else return (isFloat.arguments[1] == true);

	if (s == decimalPointDelimiter) return false;

	for (i = 0; i < s.length; i++){
		// Check that current character is number.bu
		var c = s.charAt(i);
		if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
		else if (!isDigit(c)) return false;
	}

	// All characters are numbers.
	return true;
}

function isWhitespace (s){
	var i;
	if (isEmpty(s)) return true;
	for (i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}
	// All characters are whitespace.
	return true;
}

function isEmpty (s) {
	return ((s == null) || (s.length == 0));
}

function LTrim(str) {
	for (var i=0; str.charAt(i)==" "; i++);
	return str.substring(i,str.length);
	}
function RTrim(str) {
	for (var i=str.length-1; str.charAt(i)==" "; i--);
	return str.substring(0,i+1);
	}
function Trim(str) {
	return LTrim(RTrim(str));
	}

function isNotEmpty(field) {
    var inputStr = Trim(field.value)
    if (inputStr == "" || inputStr == null) {
        return false
    }
    return true
}

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") +
		      ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
		  document.cookie = curCookie;
}

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 deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") +"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function fixDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)
		date.setTime(date.getTime() - skew);
}

var pathSeccion="/secciones/seccion2";
var pathBiblio="/fichas/fichabiblio2";

function openDefaultNewWindow( url, windowName, width, height ) {
	options = "menubar=no,toolbar=no,height=" + height + ",width=" + width;
	return window.open( url, windowName, options );
}

function imprimir() {
	window.print();
}

function volver() {
	window.history.back();
}

function isValorVacio(valorC) {
    var valor = Trim(valorC);
    if (valor == "" || valor == null) {
        return true
    }
    return false
}

function isNum(q) {
    for ( i = 0; i < q.length; i++ ) {
        valor = parseInt(q.charAt(i));
        if (isNaN(valor)) {
            return true
        }
    }
    return false
}

function isNumFloat(q) {
    var array = null;
    var parte1 = null;
    var parte2 = null;
    if (q.indexOf(",") != -1){
         array = q.split(",");
         parte1 = array[0];
         parte2 = array[1];
         for ( i = 0; i < parte1.length; i++ ) {
                valor = parseInt(parte1.charAt(i));
                if (isNaN(valor)) {
                    return true
                }
            }
            for ( i = 0; i < parte2.length; i++ ) {
                valor = parseInt(parte2.charAt(i));
                if (isNaN(valor)) {
                    return true
                }
            }
         return false
    }else if (q.indexOf(".") != -1){
        array = q.split(".");
        parte1 = array[0];
        parte2 = array[1];
        for ( i = 0; i < parte1.length; i++ ) {
            valor = parseInt(parte1.charAt(i));
            if (isNaN(valor)) {
                return true
            }
        }
        for ( i = 0; i < parte2.length; i++ ) {
            valor = parseInt(parte2.charAt(i));
            if (isNaN(valor)) {
                return true
            }
        }
        return false
    }else{
        for ( i = 0; i < q.length; i++ ) {
            valor = parseInt(q.charAt(i));
            if (isNaN(valor)) {
                return true
            }
        }
        return false
    }

}

function confirmarSegundaMano(){
            document.form_confirmacion.action='/areausuario/misdatos?ver=4&ver2=3&verAux=6';
            document.form_confirmacion.submit();
}

function volverBusqueda(){
            document.form_confirmacion.action='/busquedasSM/busquedaSegundaMano';
            document.form_confirmacion.submit();
}

function masUds(tcantidad){
    if(document.getElementById(tcantidad)!=null){
        var uds=document.getElementById(tcantidad).value;
        if(uds!=null && uds!='undefined'){
            var unidades=eval(uds);
            unidades=unidades+1;
            document.getElementById(tcantidad).value=unidades;
        }
    }
}
function menosUds(tcantidad){
    var uds=document.getElementById(tcantidad).value;
    if(uds!=null && uds!='undefined'){
        var unidades=eval(uds);
        if(unidades>1){
            unidades=unidades-1;
            document.getElementById(tcantidad).value=unidades;
        }
    }
}

function guardarSegundaMano(){
        var errorForm="";
        if (document.form_datosSM.loginVendedor.value == "" || document.form_datosSM.loginVendedor.value == 0 && (!isValorVacio(document.form_datosSM.testado.value) && !isValorVacio(document.form_datosSM.tprecio.value) && !isValorVacio(document.form_datosSM.tcantidad.value) && document.form_datosSM.tcantidad.value != 0 && isNumFloat(document.form_datosSM.tprecio.value)== false)){
            document.form_datosSM.action=document.form_datosSM.hostRedirect.value+'/areausuario/registropreferenciasNuevo';
            document.form_datosSM.submit();
        }else if (!isValorVacio(document.form_datosSM.testado.value) && !isValorVacio(document.form_datosSM.tprecio.value) && !isValorVacio(document.form_datosSM.tcantidad.value) && document.form_datosSM.tcantidad.value != 0 && isNumFloat(document.form_datosSM.tprecio.value)== false){
            document.form_datosSM.action='/vendedor/segundaManoTrans';
            document.form_datosSM.submit();
        }else{            
             if (isValorVacio(document.form_datosSM.testado.value)){
                 errorForm+=" El estado del libro es obligatorio.";
            }else if(isValorVacio(document.form_datosSM.tprecio.value) || document.form_datosSM.tprecio.value<=0){
                errorForm+=" El precio del libro es obligatorio o es un precio no v&aacute;lido.";
            }else if(isNumFloat(document.form_datosSM.tprecio.value)== true){
                errorForm+=" El precio debe ser num&eacute;rico."
            }else{
                errorForm+=" La cantidad de libros es obligatoria.";
            }
        }
        if (!isValorVacio(errorForm)){
            var error=document.getElementById("error");
            error.style.display="block";
            error.innerHTML=errorForm;
            document.form_datosSM.guardar.disabled=false;
    }
}

function changeAction(form, newUrl) {
	form.action=newUrl;
}

function submitToUrl(form, newUrl) {
	changeAction(form, newUrl);
	form.submit();
}

function checkWindowOpen( windowHandle, url, windowName, width, height ) {
	if( windowHandle == null || windowHandle.closed ) {
		windowHandle = openDefaultNewWindow( url, windowName, width , height );
	} else {
		windowHandle.location = url;
		windowHandle.focus();
	}
	return windowHandle;
}

function ReplaceChar(String, OldChar, NewChar){
	for(var n=0; n<String.length; n++){
		if (String.charAt(n) == OldChar) {
			String = String.substring(0,n) + NewChar + String.substring(n+1,String.length);
		}
	}
	return String;
}


var windowTitleGlobal;
var titleTextGlobal;
var errorTextGlobal;
var windowRedirectUrl;

function open_error_window(errorText, titleText, urlRedirect, windowTitle, width, height, left, top){
	var putItThere = null;
	var chasm = screen.availWidth;
	var mount = screen.availHeight;

	if ((urlRedirect== null) || (urlRedirect=='undefined')) {
		windowRedirectUrl='';
	} else {
		windowRedirectUrl=urlRedirect;
	}

	if ((windowTitle == null) || (windowTitle=='undefined')) {
		windowTitleGlobal ='::Casa Del Libro:: - Error';
	} else {
		windowTitleGlobal=windowTitle;
	}

	if ((titleText == null)||(titleText=='undefined')) {
		titleTextGlobal='por favor,<br>compruebe los siguientes campos';
	} else {
		titleTextGlobal=titleText;
	}

	if ((errorText == null)||(errorText=='undefined')) {
		errorText='';
	} else {
		errorTextGlobal=errorText;
	}

	if ((width == null) || (width=='undefined'))
		width ='300';
	if ((height == null) || (height=='undefined'))
		height ='300';
	if ((left == null) || (left=='undefined'))
		left =((chasm - width - 10) * .5);
	if ((top == null) || (top=='undefined'))
		top =((mount - height - 30) * .5);
	new_window = open("/common/windowPopUp","displayWindow","width="+width+",height="+height+",left="+ left +",top="+ top);
}

function checkTextLength(textControl, textName, length) {
	if (textControl.value.length > length) {
		open_error_window('',textName+' no puede contener m&aacute;s de '+length+' caracteres.');
		textControl.value=textControl.value.substring(0,length-1);
		//textControl.focus();
		return false;
	}
	return true;
}
function validaTextArea(field,maxlimit){
	if(field.value.length > maxlimit){
		field.blur();
		open_error_window('El &aacute;rea de texto no puede contener m&aacute;s de '+maxlimit+' caracteres.');
		field.value=field.value.substring(0,maxlimit-1);
	}
}

function isEmail(StrObj) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(StrObj)) {
		return true;
	} else {
		return false;
	}
}
function validaBoletin() {
	var tipo = "";
	if ((!document.myFormBoletin.tipogeneral.checked) && (!document.myFormBoletin.tiponoticia.checked)) {
		open_error_window('Tipo de bolet&iacute;n.');
	} else {
		if (document.myFormBoletin.tipogeneral.checked) {
			tipo = document.myFormBoletin.tipogeneral.value + "|";
		}
		if (document.myFormBoletin.tiponoticia.checked) {
			tipo = tipo + document.myFormBoletin.tiponoticia.value;
		}
		document.myFormBoletin.tipoboletin.value = tipo;

		if (!isEmail(document.myFormBoletin.email.value)) {
			open_error_window('Email incorrecto.');
		} else {
			document.onclick = processClicks;
			document.myFormBoletin.submit();
		}
	}
}

function ReplaceChar(String, OldChar, NewChar){
	for(n=0; n< String.length; n++){
		if (String.charAt(n) == OldChar) String = String.substring(0,n) + NewChar + String.substring(n+1,String.length);
	}
	return String;
}

function filterChars(cadena) {
	var str= cadena;
	str=ReplaceChar(str,'�','&Ntilde;');
	str=ReplaceChar(str,'�','&ntilde;');
	str=ReplaceChar(str,'�','&Aacute;');
	str=ReplaceChar(str,'�','&Eacute;');
	str=ReplaceChar(str,'�','&Iacute;');
	str=ReplaceChar(str,'�','&Oacute;');
	str=ReplaceChar(str,'�','&Uacute;');
	str=ReplaceChar(str,'�','&aacute;');
	str=ReplaceChar(str,'�','&eacute;');
	str=ReplaceChar(str,'�','&iacute;');
	str=ReplaceChar(str,'�','&oacute;');
	str=ReplaceChar(str,'�','&uacute;');
	str=ReplaceChar(str,'�','&iquest;');
	str=ReplaceChar(str,'�','&iexcl;');
	str=ReplaceChar(str,'-','&macr;');
	str=ReplaceChar(str,'�','&Ccedil;');
	str=ReplaceChar(str,'�','&ccedil;');
	str=ReplaceChar(str,'�','&Uuml;');
	str=ReplaceChar(str,'�','&uuml;');
	str=ReplaceChar(str,'�','&Agrave;');
	str=ReplaceChar(str,'�','&agrave;');
	return str;
}

function filterCharsToHex(cadena) {
	var str= cadena;
	str=replaceChars(str,'�','%D1');
	str=replaceChars(str,'�','%F1');
	str=replaceChars(str,'�','%C1');
	str=replaceChars(str,'�','%C9');
	str=replaceChars(str,'�','%CD');
	str=replaceChars(str,'�','%D3');
	str=replaceChars(str,'�','%DA');
	str=replaceChars(str,'�','%E1');
	str=replaceChars(str,'�','%E9');
	str=replaceChars(str,'�','%ED');
	str=replaceChars(str,'�','%F3');
	str=replaceChars(str,'�','%FA');
	str=replaceChars(str,'�','%BF');
	str=replaceChars(str,'�','%A1');
	str=replaceChars(str,'-','%AF');
	str=replaceChars(str,'�','%C7');
	str=replaceChars(str,'�','%E7');
	str=replaceChars(str,'�','%FC');
	str=replaceChars(str,'�','%DC');
	str=replaceChars(str,'�','%C0');
	str=replaceChars(str,'�','%E0');
	return str;
}
function esES() {
	var idioma='';
	var isIE= (window.navigator.appName.indexOf('Explorer')>0);
	if (isIE) idioma= navigator.userLanguage.toLowerCase();
	else idioma= navigator.language;
	if ((idioma!='es') && (idioma!='es-es')) return false;
	else return true;
}

function formatFloat (s) {
	var maxFraction= 2;
	var dotSeen= false;
	var k=0;
	var result="";
	var str=new String(s);

	for (var i = 0; (i < str.length) && (k <= maxFraction); i++){
		var c = str.charAt(i);
		if ((c == '.') || (dotSeen)) {
			dotSeen=true;
			k=k+1;
		}
		result=result+c;
	}
	return result;
}

function actualiza() {
	document.location.reload();
}
function mostrarBolsa(){
	var cuantos=1;
	var cuantosVan=0;
	var ruta=window.location.href;
	if (ruta.indexOf('fichabiblio')>-1 || ruta.indexOf('/libro-')>-1) cuantos=3;
	var carro=getCookie("cart");
	var numLib=0;
	var valorLib=0;var lib="";
	var libros=document.getElementById("librosBolsa");
	var valLib=document.getElementById("valLib");
	var totLib=document.getElementById("totLib");
	if (carro!=null && carro!=''){
		var cartView=getCookie("vercart");
		var lineasV;
		var prodInc;
		if (cartView!=null && cartView!='') {
			lineasV= cartView.split('|');
			prodInc=lineasV.length;
		}
		var lineas= carro.split('|');
		var buscarTit=true;
		for (var i=0;i < lineas.length;i++) {
			var linea = lineas[i].split('_');
			var codigo=linea[0];
			var titulo="";
			var precio;
			var autor;
			var img;
			var cantidad=linea[5];
            if (linea.length==7){
	            titulo=linea[1];
                precio=linea[2];
                autor=linea[3];
                img=linea[4];
                cantidad=linea[5];
                buscarTit=false;
            }else{
                precio=linea[1];
                cantidad=linea[2];
                buscarTit=true;
            }
			numLib=eval(numLib)+eval(cantidad);
			valorLib=eval(valorLib)+(cantidad*precio);
			if (cuantosVan<cuantos){
				if (prodInc>0){
					for (var j=0;j < prodInc;j++){
						var lineaV = lineasV[j].split('_');
						if (lineaV[0]==codigo){
							titulo=unescape(lineaV[1]);
							autor=unescape(lineaV[2]);
							img=lineaV[3];
							cuantosVan++;
							lib=lib+"<div class='lIz'><div class='ocultar_izda'><img src='"+img+"' /></div><div class='ocultar_dcha'><span class='tx2'>"+titulo+"</span><br /><span class='tx3'>"+autor+"</span><br /><span class='tx2'>"+precio+" &euro;</span></div>";
						}
					}
				}else{
					if (!buscarTit){
						cuantosVan++;
						titulo=unescape(titulo);
						if (titulo.length>38) titulo=titulo.substring(0,35)+"...";
						autor=unescape(autor);
						if (autor.length>30) autor=autor.substring(0,30)+"...";
						lib=lib+"<div class='lIz'><div class='ocultar_izda'><img src='"+img+"' /></div><div class='ocultar_dcha'><span class='tx2'>"+titulo+"</span><br /><span class='tx3'>"+autor+"</span><br /><span class='tx2'>"+precio+" &euro;</span></div>";
					}
				}
			}
		}
	}else{
		lib="<p>"+laBolsaVacia+"</p>";
	}
	libros.innerHTML=lib;
	valLib.innerHTML=formatFloat(valorLib)+" &euro;";
	totLib.innerHTML=numLib;
}
var capas = ["capa_ocultar2", "capa_ocultar3"];
function cambiar(capa) {
	soy = document.getElementById(capa);
	soy.style.display = (soy.style.display == "block") ? "none" : "block";
}
function irFavoritos (url) {
	document.onclick = processClicks;
	window.location=url;
}

function mueTextOferta(textoOf){
	var conten=document.getElementById("discontinuoDoble");
	var textoOferta=document.getElementById("teOferDesc");
	if (textoOferta==null || typeof(textoOferta)=='undefined'){
		textoOferta=document.createElement("DIV");
		textoOferta.id="teOferDesc";
		textoOferta.innerHTML=textoOf+"<br /><a href='#' class=\"fl_right\" onclick='this.parentNode.style.visibility=\"hidden\"'>["+cerrarDetalle+"]</a>";
		conten.appendChild(textoOferta);
                textoOferta.style.visibility="visible";
	}else{
		textoOferta.style.visibility="visible";
	}
}
function mueTextPreventa(textoOf){
	var conten=document.getElementById("iconoPreventa");
	var textoOferta=document.getElementById("tePrevDesc");
	if (textoOferta==null || typeof(textoOferta)=='undefined'){
		textoOferta=document.createElement("DIV");
		textoOferta.id="tePrevDesc";
		textoOferta.innerHTML=textoOf+"<br /><a href='#' class=\"fl_right\" onclick='this.parentNode.style.visibility=\"hidden\"'>["+cerrarDetalle+"]</a>";
		conten.appendChild(textoOferta);
		textoOferta.style.visibility="visible";
	}else{
		textoOferta.style.visibility="visible";
	}
}
function muestraPreventa(){
	var textoPrev=document.getElementById("tePrevDesc");
	if (textoPrev!=null && typeof(textoPrev)!='undefined'){
		textoPrev.style.visibility="visible";
	}
}
function muestraDispo(){
	var textoPrev=document.getElementById("teDispo");
	if (textoPrev!=null && typeof(textoPrev)!='undefined'){
		textoPrev.style.visibility="visible";
	}
}
function mueDisponib(opc){
        var ruta=window.location.href;
	if (opc!=null && opc!='undefined' && opc==0){
		textoOf=txtLibStock;
	}
	if (opc!=null && opc!='undefined' && opc==1){
		textoOf=txtEdicAgotada;
	}
	if (opc!=null && opc!='undefined' && opc==2){
		textoOf=txtLibDisponible;
	}
        if (opc!=null && opc!='undefined' && opc==3){
		textoOf=txtProdStock;
	}
	var conten=document.getElementById("iconoPreventa");
         if (ruta.indexOf('nolibro')>-1){
	    var textoOferta=document.getElementById("teDispo2");
         }
         else{
            var textoOferta=document.getElementById("teDispo");
         }
	if (textoOferta==null || typeof(textoOferta)=='undefined'){
		textoOferta=document.createElement("DIV");
                if (ruta.indexOf('nolibro')>-1){
		   textoOferta.id="teDispo2";
                }else{
                   textoOferta.id="teDispo";
                }
		textoOferta.innerHTML=textoOf+"<br /><a href='#' class=\"fl_right\" onclick='this.parentNode.style.visibility=\"hidden\"'>["+cerrarDetalle+"]</a>";
		conten.appendChild(textoOferta);
		textoOferta.style.visibility="visible";
	}else{
		textoOferta.style.visibility="visible";
	}
}
function mostrarRecomendar(id,origen,clibro,cnov,txnoved,opcion,tipo,idiom){
    	if (idiom==null || typeof(idiom)=='undefined'){idiom="";}
	if (tipo==null || typeof(tipo)=='undefined'){tipo="";}
	var reco=document.getElementById(id);
	var posId=id.substring(id.length-1,id.length);
	if (isNaN(posId)){
		posId="";
	}
        var opcionActual=document.getElementById("opcion");
        var opcionValor="";
        if(opcionActual!=null) opcionValor=opcionActual.value;
        else opcionValor="";
        if (opcionValor!="" && opcionValor!=opcion){
            reco.innerHTML="";
        }
	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 formReco=document.forms['frmrecomendar'+posId];
	var formAlarm=document.forms['frmalarma'+posId];
			//formReco.reset();
			var recIn=document.getElementById('recInputs'+posId);
			var txReco=document.getElementById('txReco'+posId);
			var alarIn=document.getElementById('alarmInp'+posId);
			if (txReco!=null && typeof(txReco)!='undefined' && txReco.nodeType==1) txReco.parentNode.removeChild(txReco);
			document.getElementById('recHecha'+posId).style.display='none';
			if (opcion=="reco"){
				if (formAlarm){
					formReco.reset();
					formAlarm.style.display='none';
					document.getElementById('alarmHecha'+posId).style.display='none';
					alarIn.style.display='none';
				}
				recIn.style.display='block';
				if (formReco) formReco.style.display='block';
			}else{
				if (opcion=="alarma"){
					if (formReco) formReco.style.display='none';
					if (formAlarm) formAlarm.style.display='block';
				}
			}
			getFirstChild(reco).style.display='block';
			reco.style.display='block';
		}
		myConn.connect("/servicios/recomendar", "POST", "origen="+origen+"&codlib="+clibro+"&codNoved="+cnov+"&txtNoved="+txnoved+"&tipo="+tipo+"&opcion="+opcion+"&id="+posId+"&lang="+idiom, peticion);
	}else{
		var recIn=document.getElementById('recInputs'+posId);
		var txReco=document.getElementById('txReco'+posId);
		var alarIn=document.getElementById('alarmInp'+posId);
	var formReco=document.forms['frmrecomendar'+posId];
	var formAlarm=document.forms['frmalarma'+posId];
		if (txReco!=null && typeof(txReco)!='undefined' && txReco.nodeType==1) txReco.parentNode.removeChild(txReco);
		if (opcion=="reco"){
			if (formAlarm){
				formAlarm.reset();
				formAlarm.style.display='none';
				document.getElementById('alarmHecha'+posId).style.display='none';
				alarIn.style.display='none';
			}
			if (formReco){
				formReco.reset();
				document.getElementById('recHecha'+posId).style.display='none';
				recIn.style.display='block';
				formReco.style.display='block';
			}
		}else{
			if (opcion=="alarma"){
				if (formReco) formReco.style.display='none';
				if (formAlarm){
					formAlarm.reset();
					document.getElementById('alarmHecha'+posId).style.display='none';
					alarIn.style.display='block';
					formAlarm.style.display='block';
				}
			}
		}
		getFirstChild(reco).style.display='block';
		reco.style.display='block';
	}
}
function validarReco(id){
	var txErr="";
	if (isEmpty(document.forms['frmrecomendar'+id].tunombre.value)){
    		txErr=noRecoNombre;
	}
	if (isEmpty(document.forms['frmrecomendar'+id].amignombre.value)){
    		txErr=txErr+noRecoNombreAmi;
	}
	if (!isEmail(document.forms['frmrecomendar'+id].tuemail.value)){
    		txErr=txErr+noRecoEmail;
	}
	if (!isEmail(document.forms['frmrecomendar'+id].amigemail.value)){
		txErr=txErr+noRecoEmailAmi;
	}
	return txErr;
}
function recomendar(origen,id,idiom){
        if (idiom==null || typeof(idiom)=='undefined'){idiom="";}
	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='"+altErrorReco+"' />"+txErr;
		else{
                    txReco.innerHTML=enviandoReco;
                    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;
                                trackEvento("recomendacion",origen+"-recomendar",id);
                            }
                        }
                        document.getElementById('recHecha'+id).style.display='block';
                    }
                    myConn.connect("/apadrina/apadrina", "POST", "tipoRecomendacion="+origen+"&codigoLibro="+document.frmrecomendar.codigoLibro.value+"&tunombre="+escape(document.frmrecomendar.tunombre.value)+"&tuemail="+document.frmrecomendar.tuemail.value+"&amignombre="+escape(document.frmrecomendar.amignombre.value)+"&amigemail="+document.frmrecomendar.amigemail.value+"&lang="+idiom, 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=altErrorReco;
			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;
                                trackEvento("recomendacion",origen+"-recomendar",id);
                            }
                        }
                        document.getElementById('recHecha'+id).style.display='block';
                    }
                    myConn.connect("/apadrina/apadrina", "POST", "tipoRecomendacion="+origen+"&codigoLibro="+document.frmrecomendar.codigoLibro.value+"&tunombre="+escape(document.frmrecomendar.tunombre.value)+"&tuemail="+document.frmrecomendar.tuemail.value+"&amignombre="+escape(document.frmrecomendar.amignombre.value)+"&amigemail="+document.frmrecomendar.amigemail.value+"&lang="+idiom, peticion);
                }
		if (imErr!=null && typeof(imErr)!='undefined' && imErr.nodeType==1) txError.appendChild(imErr);
		txError.appendChild(myTexto);
		txError.id="txReco"+id;
		txError.className="txReco";
		recIn.insertBefore(txError,getFirstChild(recIn));
	}
	return false;
}
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 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 validarAlerta(formu){
	var txErr="";
	if (!isEmail(formu.alemail.value)){
    		txErr=noRecoEmail;
	}
	return txErr;
}
function alertas(id,idiom){
	if (idiom==null || typeof(idiom)=='undefined'){idiom="";}
	var formul=eval('document.frmalarma'+id);
	var alarIn=document.getElementById('alarmInp'+id);
	var txReco=document.getElementById('txReco'+id);
	var txErr=validarAlerta(formul);
	var frecu;
	if (txReco!=null && typeof(txReco)!='undefined' && txReco.nodeType==1){
		if (txErr!=null && txErr!="") txReco.innerHTML="<img src='/i/error2.gif' alt='"+altErrorReco+"' />"+txErr;
		else{
                    txReco.innerHTML=tramitandoSolic;
                    for (var i=0; i< formul.alfrec.length;i++) {
	                    if (formul.alfrec[i].checked){
        		            frecu=formul.alfrec[i].value;
	                    }
                    }
                    var myConn = new XHConn();
                    if (!myConn) alert("XMLHTTP no esta disponible. Int�ntalo con un navegador m�s actual.");
                    var peticion = function (oXML) {
                        alarIn.style.display='none';
                        var rText=oXML.responseText;
                        if (rText.indexOf("{")>=0){
                            var respuesta=eval('('+rText+')');
                            if (respuesta){
                                document.getElementById("respAlarm"+id).innerHTML=respuesta.resp;
                            }
                        }
                        document.getElementById('alarmHecha'+id).style.display='block';
                    }
                    myConn.connect("/otros/graciasAlarma", "POST", "tipo="+formul.tipo.value+"&codigoNoved="+formul.codigoNoved.value+"&alemail="+formul.alemail.value+"&alfrec="+frecu+"&lang="+idiom, 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=altErrorReco;
			myTexto = document.createTextNode(txErr);
		}else{
                    myTexto = document.createTextNode(tramitandoSolic);
                    for (var i=0; i< formul.alfrec.length;i++) {
	                    if (formul.alfrec[i].checked){
        		            frecu=formul.alfrec[i].value;
	                    }
                    }
                    var myConn = new XHConn();
                    if (!myConn) alert("XMLHTTP no esta disponible. Int�ntalo con un navegador m�s actual.");
                    var peticion = function (oXML) {
                        alarIn.style.display='none';
                        var rText=oXML.responseText;
                        if (rText.indexOf("{")>=0){
                            var respuesta=eval('('+rText+')');
                            if (respuesta){
                                document.getElementById("respAlarm"+id).innerHTML=respuesta.resp;
                            }
                        }
                        document.getElementById('alarmHecha'+id).style.display='block';
                    }
                    myConn.connect("/otros/graciasAlarma", "POST", "tipo="+formul.tipo.value+"&codigoNoved="+formul.codigoNoved.value+"&alemail="+formul.alemail.value+"&alfrec="+frecu+"&lang="+idiom, peticion);
                }
		if (imErr!=null && typeof(imErr)!='undefined' && imErr.nodeType==1) txError.appendChild(imErr);
		txError.appendChild(myTexto);
		txError.id="txReco"+id;
		txError.className="txReco";
		alarIn.insertBefore(txError,getFirstChild(alarIn));
	}
	return false;
}
function getNextSibling(startBrother){
	endBrother=startBrother.nextSibling;
	while(endBrother!=null && endBrother.nodeType!=1){
		endBrother = endBrother.nextSibling;
	}
	return endBrother;
}
function getFirstChild(startNode){
var m=0;
var hijo;
if (startNode.hasChildNodes()){
	hijo=startNode.childNodes[0];
	while(m<(startNode.childNodes.length-1) && startNode.childNodes[m].nodeType!=1){
		m++;
		hijo=startNode.childNodes[m];
	}
}
return hijo;
}
function busqAvanzSegundaMano(nombrediv, form){
        var capaPrincipal = document.getElementById(nombrediv);
        var titulo =  escape(form.titbus.value);
        var isbn = form.isbnbus.value;
        capaPrincipal.innerHTML = "Cargando ...";
        var myConn = new XHConn();
        if (!myConn) alert("XMLHTTP no esta disponible. Intentalo con un navegador m?s actual.");
        var peticion = function (oXML) {
            capaPrincipal.innerHTML=oXML.responseText;
        };
        myConn.connect("/busquedasSM/resultadosSegundaMano", "POST", "titbus="+titulo+"&isbnbus="+isbn, peticion);
}
function busqAvanzSegundaManoLDA(nombrediv, form, inParam, lang){
    
        var capaPrincipal = document.getElementById(nombrediv);
        var titulo = form.titbus.value;
        var isbn = form.isbnbus.value;
        if((titulo!=null && titulo!='' && titulo.length>2) || (isbn!=null && isbn!='' && isbn.length>2)){
            var smsError = document.getElementById('smsError');
            if(smsError!=null && smsError!='' && smsError!='null'){
                smsError.style.visibility='hidden';
                smsError.style.display='none';
            }
            capaPrincipal.innerHTML = "Cargando ...";
            var myConn = new XHConn();
            if (!myConn) alert("XMLHTTP no esta disponible. Intentalo con un navegador m?s actual.");
            var peticion = function (oXML) {
                capaPrincipal.innerHTML=oXML.responseText;
            };
            myConn.connect("/busquedas/resultadosLibros", "POST", inParam+lang+"&titbus="+titulo+"&isbnbus="+isbn, peticion);
        }else{
            var smsError2 = document.getElementById('smsError');
            if(smsError2!=null && smsError2!='' && smsError2!='null'){
                smsError2.style.visibility='visible';
                smsError2.style.display='block';
            }
        }
}

