function busRapida()
{
var form = document.formBusRapida;
if (form.palabrasBusqueda.value=="")
{
alertModal(introPalBusqueda, "times-circle");
form.palabrasBusqueda.focus();
return false;
}
return true;
}
function soloEbook()
{
var form = document.formBusRapida;
if (form.tipoArticulo.checked == true) {
form.tipoBus.value = "soloEbooks";
}
else {
form.tipoBus.value = "full";
}
}
function abre_ventana(elemento, ancho, alto, scroll)
{
var ventana=window.open(elemento.href, "_blank", "width="+ancho+"px, height="+alto+"px, scrollbars="+scroll);
return ventana==undefined;
}
function validarEmail(input)
{
if (!isEmail(input.value))
{
alertModal(emailIncorrecto, input);
return false;
}
return true;
}
function modifier_moneda(precio, param_moneda)
{
precio = precio.replace(",",".");
var parametros = String(param_moneda).split("|");
var simboloMoneda = parametros[0];
var posicionMoneda = parametros[1];
var length = parametros[2];
var dec = parametros[3];
var mil = parametros[4];
switch(posicionMoneda)
{
case "I":
return simboloMoneda+" "+number_format(precio, length, dec, mil);
break;
default:
return number_format(precio, length, dec, mil)+" "+simboloMoneda;
}
}
function number_format( number, decimals, dec_point, thousands_sep )
{
var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
var d = dec_point == undefined ? "," : dec_point;
var t = thousands_sep == undefined ? "." : thousands_sep, s = n < 0 ? "-" : "";
var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}
function insMiniCar(codArticulo)
{
$.ajax({
url:rutaHtml+"/cesta/insCarrito.ajax.php?codArticulo="+codArticulo,
async:true,
contentType: "application/x-www-form-urlencoded",
dataType: "json",
error: function(e, transport, otroobj) {
alert("No se ha podido realizar correctamente la petición AJAX de insertar en carrito");
console.log(e, transport);
},
global: true,
ifModified: false,
processData:true,
success: function(result)
{
if (result["correcto"])
{
//alert(result["link_portada"]);
var htmlArt =
'
'+
'
'+
'

'+
'
'+result["descripcion"]+'';
if (result["tipo_articulo"] == 'E')
{
htmlArt += '
ebook
';
}
else if (result["tipo_articulo"] == 'I')
{
htmlArt += '
POD
';
}
htmlArt +=
'
'+
'
'+
'1'+
'
'+
'
'+
modifier_moneda(result["pvp_euros"], paramMoneda)+
'
'+
'
'+
'
';
//alert(htmlArt);
$("#miniCesta").html($("#miniCesta").html()+htmlArt);
$(".numArticulos").html(result["num_articulos"]);
$("#precioTotalMiniCesta").html(modifier_moneda(result["precio_total"], paramMoneda));
totalArticulosCesta++;
// Notificacion
//show_stack_bar_top('success', ''+artInsCestaOK+' '+verCesta+'.');
alertInsCarrito(artInsCestaOK, "check-circle", result);
}
else
{
alertModal(result["mensaje"], "info-circle");
}
},
timeout: 10000,
type: "GET"
});
}
function delArticulo(i, codArticulo)
{
$.ajax({
url:rutaHtml+"/cesta/delArticulo.ajax.php?codArticulo="+codArticulo,
async:true,
contentType: "application/x-www-form-urlencoded",
dataType: "json",
error: function(e, transport, otroobj) {
alert("No se ha podido realizar correctamente la petición AJAX de borrar del carrito");
console.log(e, transport);
},
global: true,
ifModified: false,
processData:true,
success: function(result)
{
if (result["correcto"])
{
$("#miniCesta_articulo"+i).hide();
$(".numArticulos").html(result["num_articulos"]);
$("#precioTotalMiniCesta").html(modifier_moneda(result["precio_total"], paramMoneda));
totalArticulosCesta--;
}
else
{
alertModal(result["mensaje"], null);
}
},
timeout: 10000,
type: "GET"
});
}
function cambiaCantidad(incrementar, i, codArticulo)
{
$.ajax({
url:rutaHtml+"/cesta/cantidad.ajax.php?codArticulo="+codArticulo+"&incrementar="+incrementar,
async:true,
contentType: "application/x-www-form-urlencoded",
dataType: "json",
error: function(e, transport, otroobj) {
alert("No se ha podido realizar correctamente la petición AJAX de cambiar cantidad en carrito");
console.log(e, transport);
},
global: true,
ifModified: false,
processData:true,
success: function(result)
{
if (result["correcto"])
{
$("#miniCesta_can"+i).html(result["nueva_cantidad"]);
$("#numArticulos").html(result["num_articulos"]+"x");
$("#precioTotalMiniCesta").html(modifier_moneda(result["precio_total"], paramMoneda));
}
else
{
alertModal(result["mensaje"], null);
}
},
timeout: 10000,
type: "GET"
});
}
var stack_bar_top = {"dir1": "down", "dir2": "right", "push": "top", "spacing1": 0, "spacing2": 0};
function show_stack_bar_top(type, msg) {
var opts = {
//title: "Over Here",
text: "Información.
",
addclass: "stack-bar-top",
cornerclass: "",
width: "100%",
delay: 4000,
history: false,
icon: false,
sticker: false,
closer: false,
stack: stack_bar_top
};
switch (type) {
case 'error':
//opts.title = "Oh No";
opts.text = ""+msg+"
";
opts.type = "error";
break;
case 'info':
//opts.title = "Breaking News";
opts.text = ""+msg+"
";
opts.type = "info";
break;
case 'success':
//opts.title = "Good News Everyone";
opts.text = ""+msg+"
";
opts.type = "success";
break;
}
$.pnotify(opts);
}
/** Tabs **/
$(document).ready(function() {
if (paginaActual == "detalle.php") {
//console.log("ficha Detalle: S");
$("#detnavtab").idTabs();
}
});
/** Buscador **/
$(document).ready(function() {
if(autocomplete) {
valorAutocomplete = "";
$("#autocompleta").autocomplete({
source: rutaHtml + "/busqueda/resultsAutocomplete.ajax.php",
open: function () { $('ul.ui-autocomplete').hide().fadeIn(400) },
close: function () { $('ul.ui-autocomplete').show().fadeOut(100) },
minLength: 2,
focus: function( event, ui ) {
if (ui.item[0] != "titulo" && ui.item[0] != "todos")
$( "#autocompleta" ).val( ui.item[0] );
return false;
},
select: function( event, ui ) {
$( "#autocompleta" ).val( ui.item[0] );
return false;
}
}).data("ui-autocomplete")._renderItem = function (ul, item) {
if (item[0] == 'titulo')
return $("")
.data("item.autocomplete", item)
.append("" + item[1] + "")
.appendTo(ul);
else if (item[0] == 'todos')
return $("")
.data("item.autocomplete", item)
.append("" + verTodos + "")
.appendTo(ul);
else
return $("")
.data("item.autocomplete", item)
.append("
" + item[0] + "" + item[2] + "")
.appendTo(ul);
};
$('#autocompleta').click(function () {
$("#autocompleta").val(valorAutocomplete);
});
$('#autocompleta').keyup(function () {
valorAutocomplete = $("#autocompleta").val();
});
}
});
/** Carrito compra **/
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;
function jsddm_openCesta()
{
if (totalArticulosCesta > 0) {
jsddm_canceltimer();
jsddm_close();
ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
}
}
function jsddm_open()
{
jsddm_canceltimer();
jsddm_close();
ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
}
function jsddm_close()
{
if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}
function jsddm_timer()
{
closetimer = window.setTimeout(jsddm_close, timeout);
}
function jsddm_canceltimer()
{
if(closetimer)
{ window.clearTimeout(closetimer);
closetimer = null;
}
}
$(document).ready(function() {
$('#jsddm > li').bind('mouseover', jsddm_open);
$('#jsddm > li').bind('mouseout', jsddm_timer);
$('#jsddm_menucab > li').bind('mouseover', jsddm_open);
$('#jsddm_menucab > li').bind('mouseout', jsddm_timer);
if (paginaActual != "cestaCompra.php") {
$('#cart-fixed').bind('mouseover', jsddm_openCesta);
$('#cart-fixed').bind('mouseout', jsddm_timer);
}
});
/** Enlace ver más/menos filtros facetado **/
$(document).ready(function() {
if(paginaActual == "listaLibros.php" || paginaActual == "dispatcherMateria.php" || paginaActual == "listaLibrosAutor.php" || paginaActual == "listaLibrosMateria.php") {
// Ver mas
if( $('.show-filters').length > 0 ) {
$('.show-filters').click( function() {
$(this).parent().parent().find('.sidebar-hidden-filter').css('display','block');
$(this).css('display','none');
var id = $(this).attr('id');
id = id.substring(0, id.length-1);
//alert(id);
$('#'+id+'H').show();
return false;
});
}
// Ver menos
if( $('.hide-filters').length > 0 ) {
$('.hide-filters').click( function() {
$(this).parent().parent().find('.sidebar-hidden-filter').css('display','none');
$(this).css('display','none');
var id = $(this).attr('id');
id = id.substring(0, id.length-1);
//alert(id);
$('#'+id+'S').show();
return false;
});
}
}
});
function generaSesion(parametro, valor)
{
$.ajax({
url:rutaHtml+"/generaSesion.ajax.php?pm="+parametro+"&valor="+escape(valor),
async:true,
contentType: "application/x-www-form-urlencoded",
dataType: "json",
error: function(e, transport, otroobj) {
alert("No se ha podido realizar correctamente la petición AJAX de afiliado");
console.log(e, transport);
},
global: true,
ifModified: false,
processData:true,
success: function(result)
{
if (result != "OK")
{
alertModal("No ha podido generarse la sesion para el afiliado", null);
}
},
timeout: 10000,
type: "GET"
})
;
}
$(document).ready(function() {
if (afiliado != "") {
generaSesion("AFILIADO", afiliado);
}
});
/** Cerrar ventana cookies **/
$(document).ready(function() {
$("#close-cookies-message").click(function(){
$("#cookie-compliant").css("display", "none");
});
});
$(document).ready(function() {
window.name = 'parentwindow';
});
/** Filters mobile **/
$(document).ready(function() {
$('#btn-filters').click(function() {
$(this).toggleClass('open');
$('.filters-selects').slideToggle('fast');
});
});
/** List display mode **/
$(document).ready(function(){
$("a.switcher").bind("click", function(e){
e.preventDefault();
var theid = $(this).attr("id");
var theproducts = $(".books");
var active = $(".active").attr('data-value'); //Clase del elemento activo
if($(this).hasClass("active")) {
return false;
} else {
var cols = $(this).attr('data-value'); //Clase a aplicar
if(theid == "gridview") {
$(this).addClass("active");
$("#listview").removeClass("active");
theproducts.removeClass(active);
theproducts.addClass(cols);
}
else if(theid == "listview") {
$(this).addClass("active");
$("#gridview").removeClass("active");
theproducts.removeClass(active);
theproducts.addClass(cols);
}
}
});
});
/** Modales **/
// Modal genérica que muestra mensaje
function mostrarMensaje(titulo, mensaje, ejecutar, parametro)
{
BootstrapDialog.show({
type: BootstrapDialog.TYPE_DEFAULT,
title: titulo,
message: $('').load('/includes/mensaje.php?mensaje='+escape(mensaje)),
draggable: true,
buttons: [
{
label: 'Cerrar',
cssClass: 'btn-primary',
action: function(dialogItself) {
dialogItself.close();
if (ejecutar != '' && ejecutar != null)
ejecutar(parametro);
}
}
]
});
}
function alertModal(mensaje, icono){
var $textAndIcon = $('');
$textAndIcon.append('');
$textAndIcon.append(''+mensaje+'
');
BootstrapDialog.show({
type: BootstrapDialog.TYPE_DEFAULT,
size: BootstrapDialog.SIZE_NORMAL,
cssClass: 'alertModal-dialog modal-no-header modal-no-footer '+icono,
message : $textAndIcon
});
setTimeout(function() { $('.alertModal-dialog').modal('hide'); }, 5000);
}
function alertInsCarrito(mensaje, icono, result){
var $textAndIcon = $('');
$textAndIcon.append('');
$textAndIcon.append(''+mensaje+ ' ('+totalArticulosCesta+' en total)
');
$textAndIcon.append(
''
);
BootstrapDialog.show({
type: BootstrapDialog.TYPE_DEFAULT,
size: BootstrapDialog.SIZE_NORMAL,
cssClass: 'alertCarrito-dialog modal-no-header modal-no-footer '+icono,
message : $textAndIcon,
buttons: [{
label: seguirComprando,
action: function(dialogRef) {
dialogRef.close();
}
},{
label: verCesta,
cssClass: 'btn-primary',
action: function (dialogRef) {
$(location).attr('href', rutaHtml+'/cesta/cestaCompra.php');
}
}]
});
}
function confirmModal(mensaje, icono, element){
var $textAndIcon = $('');
$textAndIcon.append('');
$textAndIcon.append(''+mensaje+'
');
BootstrapDialog.show({
type: BootstrapDialog.TYPE_DEFAULT,
cssClass: 'confirmModal-dialog modal-no-header '+icono,
message: $textAndIcon,
buttons: [{
label: cancelar,
action: function(dialogRef) {
dialogRef.close();
}
},{
label: aceptar,
cssClass: 'btn-primary',
action: function (dialogRef) {
var eId = element.attr('id');
$(location).attr('href', element.attr('href'));
}
}]
});
}
function notificacion() {
if (notifOK != "") {
alertModal(notifOK, "check-circle");
}
else if (notifERR != "") {
alertModal(notifERR, "times-circle");
}
else if (notifINFO != "") {
alertModal(notifINFO, "info-circle");
}
}
/** Labelauty **/
$(document).ready(function(){
$(".labelauty").labelauty({
// Development Mode
// This will activate console debug messages
development: false,
// Trigger Class
// This class will be used to apply styles
class: "labelauty",
// Use text label ?
// If false, then only an icon represents the input
label: true,
// Separator between labels' messages
// If you use this separator for anything, choose a new one
separator: "|",
// Default Checked Message
// This message will be visible when input is checked
checked_label: "Checked",
// Default UnChecked Message
// This message will be visible when input is unchecked
unchecked_label: "Unchecked",
// Minimum Label Width
// This value will be used to apply a minimum width to the text labels
minimum_width: false,
// Use the greatest width between two text labels ?
// If this has a true value, then label width will be the greatest between labels
same_width: true
});
notificacion();
});
$('.btn-cart').click(function () {
var numArticulos = $('.numArticulos').html();
if(numArticulos == 0) {
$(this).removeAttr("href");
alertModal(noArticulosCesta, "info-circle");
}
});
/** Sticy Header / Scrolltop **/
$(document).ready(function($) {
if(stickyHeader) {
$(window).scroll(function() {
var scroll = $(window).scrollTop();
var width = $(window).width();
var sticky_ini = 35;
if($('#header.header-2').length) {
sticky_ini = 1;
}
if (scroll >= sticky_ini && width > 767) {
$('#header').addClass('sticky');
$('#header #logotipo img').attr('src', rutaImg + '/logo-white.png');
$('.ui-autocomplete').fadeOut();
}
else {
$('#header').removeClass('sticky');
$('#header.header-1 #logotipo img').attr('src', rutaImg + '/logo.png');
$('#header.header-3 #logotipo img').attr('src', rutaImg + '/logo.png');
}
if (width <= 767) {
$('#header #logotipo img').attr('src', rutaImg + '/logo-white.png');
}
});
}
});
/** Scrollto **/
$(document).ready(function() {
$(window).scroll(function(){
if ($(this).scrollTop() > 55) {
$('.scrollToTop').fadeIn();
} else {
$('.scrollToTop').fadeOut();
}
});
$('.scrollToTop').click(function(){
$('html, body').animate({scrollTop : 0},800);
return false;
});
});
/** Checkbox links **/
$(document).ready(function() {
$('.list-group-item').click(function (e) {
e.stopPropagation();
var $this = $(this).find("[type=checkbox]");
if ($this.is(":checked")) {
$this.prop("checked", false);
$this.val(1);
}
else {
$this.prop("checked", true);
$this.val("")
}
});
});
/** Tooltips/Popover **/
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip({
trigger : 'hover',
container: 'body',
animated : 'fade',
});
$(function () {
$('[data-toggle="popover"]').popover()
})
});
/** Resize images minifichas
$(document).ready(function() {
$('.portada img').each(function() {
var height = $(this).height();
var new_height = 230; //new size
if (height > new_height) {
var width = $(this).width();
var calculo = Math.round((100*new_height)/ height); //percentage
var new_width = Math.round((width*calculo)/100);
$(this).css({
height : new_height+'px',
width : new_width+'px'
});
}
});
});
**/
/** Resize images detalle **/
$(document).ready(function() {
if (paginaActual == "detalle.php") {
$('.fichaDetalle img').each(function() {
var height = $(this).height();
var new_height = 350; //new size
if (height > new_height) {
var width = $(this).width();
var calculo = Math.round((100*new_height)/ height); //percentage
var new_width = Math.round((width*calculo)/100);
$(this).css({
height : new_height+'px',
width : new_width+'px'
});
}
});
}
});
/** Promociones **/
$(document).ready(function () {
$('.grupoCestaOfertaImpar').last().css('border-bottom', '10px solid #fdfdfd');
$('.grupoCestaOfertaPar').last().css('border-bottom', '10px solid #fdfdfd');
});
/** Disponibilidad on-line listados */
$(document).ready(function () {
let ids = [];
let pattern = /^.*\_(.+)$/;
$('[id^="dispo_"]').each(function () {
let match = this.id.match(pattern)
if (match.length > 1) {
let id = match[1]
ids.push(id)
}
})
if (ids.length > 0) disponibilidadListadoMiniFichas(ids) // ids.forEach(disponibilidadListadoMiniFicha)
});
function disponibilidadListadoMiniFichas (ids) {
//console.log("ids: " + ids);
//let listadoCodigos = ids.map(s => s.trim()).join(',')
let listadoCodigos = ids.join(',');
//console.log("listadoCodigos: " + listadoCodigos);
return $.ajax({
url: rutaHtml + '/busqueda/disponibilidad.ajax.php?codigo=' + listadoCodigos,
async: true,
contentType: 'application/x-www-form-urlencoded',
dataType: 'json',
error: function (jqXhr, textStatus, errorThrown) {
console.error(textStatus, errorThrown, jqXhr)
},
global: true,
ifModified: false,
processData: true,
success: function (resultList) {
resultList.forEach(function (result) {
let codigo = result.codigo
if (!!result.descripcion) {
let idCapa = '#' + codigo
$(idCapa).show()
$(idCapa).html(result.descripcion)
let botonComprar = $('#href_dispo_' + codigo)
if (result.vendible === 'S' && botonComprar.length) botonComprar.show()
}
})
},
timeout: 10000,
type: 'GET'
})
}
function disponibilidadMiniFicha (id) {
var idCapa = '#' + id;
var codArticulo = id.substring(id.indexOf('_') + 1);
$.ajax({
url: rutaHtml + '/busqueda/disponibilidad.ajax.php?codigo=' + codArticulo,
async: true,
contentType: 'application/x-www-form-urlencoded',
dataType: 'json',
error: function (jqXhr, textStatus, errorThrown) {
console.error(textStatus, errorThrown, jqXhr)
},
global: true,
ifModified: false,
processData: true,
success: function (result) {
if (!!result.descripcion) {
$(idCapa).show()
$(idCapa).html(result.descripcion)
let botonComprar = $('#href_dispo_' + codArticulo)
if (result.vendible === 'S' && botonComprar.length) botonComprar.show();
}
},
timeout: 10000,
type: 'GET'
})
}
/** Paneles **/
$(document).ready(function() {
$('.collapse').on('show.bs.collapse', function() {
var id = $(this).attr('id');
$('a[href="#' + id + '"] .panel-title span').html('');
});
$('.collapse').on('hide.bs.collapse', function() {
var id = $(this).attr('id');
$('a[href="#' + id + '"] .panel-title span').html('');
});
});
/** jsSocials **/
if (paginaActual == "detalle.php") {
$("#share-links").jsSocials({
shareIn: "popup",
showLabel: false,
showCount: false,
shares: ["facebook", "twitter", "linkedin", "pinterest", "email"]
});
}
/** Slick Slider **/
$(document).ready(function(){
$('.slider').slick({
autoplay: true,
slidesToShow: 1,
slidesToScroll: 1,
dots: true,
arrows: false,
prevArrow: '',
nextArrow: '',
responsive: [
{
breakpoint: 768,
settings: {
autoplay: true,
arrows: false,
dots: false
}
},
]
});
$('.carrusel').slick({
slidesToShow: 6,
slidesToScroll: 6,
dots: false,
arrows: true,
adaptiveHeight: true,
prevArrow: '',
nextArrow: '',
responsive: [
{
breakpoint: 1200,
settings: {
slidesToShow: 5,
slidesToScroll: 5,
}
},
{
breakpoint: 992,
settings: {
slidesToShow: 4,
slidesToScroll: 4
}
},
{
breakpoint: 768,
settings: {
slidesToShow: 3,
slidesToScroll: 3
}
},
{
breakpoint: 576,
settings: {
slidesToShow: 2,
slidesToScroll: 2
}
},
]
});
});
$(document).ready(function() {
// ofuscación de Añadir a Favoritos
$('.nomesigas').on('click', function () {
window.location.href = window.atob($(this).attr("data-link"));
return false;
});
//
$('#botonComprar, .botonComprar').on('click', function () {
insMiniCar($(this).attr("data-id"));
return false;
});
});