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;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.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 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 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 lineas= carro.split('|');
		for (var i=0;i < lineas.length;i++) {
			var linea = lineas[i].split('_');
			var codigo=linea[0];
			var titulo=linea[1];
			var precio=linea[2];
			var autor=linea[3];
			var img=linea[4];
			var cantidad=linea[5];
			titulo=unescape(titulo);
			if (titulo.length>38) titulo=titulo.substring(0,35)+"...";
			autor=unescape(autor);
			if (autor.length>30) autor=autor.substring(0,30)+"...";
			numLib=eval(numLib)+eval(cantidad);
			valorLib=eval(valorLib)+(cantidad*precio);
			if (i<cuantos) 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>La bolsa está vacía</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\"'>[Cerrar]</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\"'>[Cerrar]</a>";
		conten.appendChild(textoOferta);
	}else{
		textoOferta.style.visibility="visible";
	}
}
function mueDisponib(opc){
        var ruta=window.location.href; 
	if (opc!=null && opc!='undefined' && opc==0){
		textoOf='<font color=red><strong>Libro en stock</strong></font>, <strong>salida de almac&eacute;n en menos de 48 horas</strong> (laborables). Este tiempo no incluye el tiempo de transporte, que depender&aacute; de la forma de env&iacute;o y del pa&iacute;s de destino seleccionado.';
	}
	if (opc!=null && opc!='undefined' && opc==1){
		textoOf='<font color=red><strong>Edición agotada</strong></font>, por lo que no podemos servirlo actualmente. No obstante, si lo deseas <strong>podemos avisarte</strong> mediante correo electr&oacute;nico';
		textoOf=textoOf+' <strong>cuando se reedite</strong>. Para esto, por favor pulsa sobre el bot&oacute;n <strong>"Avisar reedici&oacute;n"</strong> y rellena el formulario que se te mostrar&aacute; a continuaci&oacute;n.';
	}
	if (opc!=null && opc!='undefined' && opc==2){
		textoOf='<font color=red><strong>Libro disponible</strong></font>, <strong>salida de almac&eacute;n entre 2 y 7 d&iacute;as</strong> (laborables), excepto si fuera necesario pedirlo a editorial. En todo <strong>momento te mantendremos informado por email</strong>, y';
		textoOf=textoOf+' podr&aacute;s modificar/anular el pedido si el plazo excede lo esperado. Este tiempo no incluye el tiempo de transporte, que depender&aacute; de la forma de env&iacute;o y del pa&iacute;s de destino seleccionado.';
	}
        if (opc!=null && opc!='undefined' && opc==3){
		textoOf='<font color=red><strong>Producto en stock</strong></font>, <strong>salida de almac&eacute;n en menos de 48 horas</strong> (laborables). Este tiempo no incluye el tiempo de transporte, que depender&aacute; de la forma de env&iacute;o y del pa&iacute;s de destino seleccionado.';
	}
	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\"'>[Cerrar]</a>";
		conten.appendChild(textoOferta);
	}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="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 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='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("/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="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("/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="Tu Email no es correcto";
	}
	return txErr;
}
function alertas(id){
	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='Error datos' />"+txErr;
		else{
                    txReco.innerHTML="Tramitando la solicitud";
                    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, 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("Tramitando la solicitud");
                    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, 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;
}
