$(function(){ $('.link_lightbox').magnificPopup({ type: 'inline', midClick: true }); $(".boto_compra").click(function(event){ event.preventDefault(); var id_art=$(this).attr('id_subarticle'); var carro = $("#carro_petit_detallat"); var foto = $("#foto_"+id_art); var marginTop = carro.offset().top - foto.offset().top; var marginLeft = carro.offset().left - foto.offset().left; $(".foto_animada").stop(true,true).removeAttr("style"); foto.animate({marginTop:marginTop,marginLeft:marginLeft, opacity:0.2},1000,function(){ foto.removeAttr("style"); }); cart_afegir_article(id_art) }); $(".checkbox_comparar").click(function(event){ var checkbox_marcats = $(".checkbox_comparar:checked").length; if(checkbox_marcats > 3) { alert("Sólo se pueden comparar 3 artículos máximo"); event.preventDefault(); } }); $('.galeria_generica').magnificPopup({ delegate: 'a', type: 'image', gallery: { enabled: true } }); $(window).resize(function(){ if($(window).width() > 979) { $("#categoriestopmenu_ul").removeAttr("style"); $(".node_parent ul").removeAttr("style"); } }); $(".node_parent > a").click(function(event){ if($(window).width() < 979) { // Si tinc més ul's desplego if($(this).parent().children('ul').length > 0) { event.preventDefault(); $(this).parent().find("ul").slideToggle(); } } }); }); function comprova_form_newsletter() { error = ""; var frm = document.frm_newsletter; if(frm.xmal.value.length < 3 || frm.xmal.value=='E-mail') error += 'Rellene el campo: E-mail\n'; else if(!(/\S+@\S+\.\S+/.test(frm.xmal.value))) error += 'E-mail incorrecto\n'; if(error) alert(error); else frm.submit(); } function filtra_llistat() { var frm = document.frm_limits; try { afegirCookie("limit",frm.limit.value,365); afegirCookie("order",frm.order.value,365); } catch(err){} frm.submit(); } function filtra_caracs() { var frm = document.frm_caracs; var num_caracs = 0; $(".filtre_carac").each(function(){ if($(this).val() != "") num_caracs = num_caracs+1; }); if(num_caracs > 0) frm.submit(); else document.location = apps_url+"?id="+frm.id.value; } function canvia_vista(vista) { $("#boto_blocs,#boto_llista").css("opacity",0.5); if(vista == 'B') { $(".bloc_article").removeClass('vista_llista'); $("#boto_blocs").css("opacity","1"); } else { $(".bloc_article").addClass('vista_llista'); $("#boto_llista").css("opacity","1"); } try { afegirCookie("vista",vista,365); } catch(err){} } function comparar_articles() { var checkbox_marcats = $(".checkbox_comparar:checked").length; var cad_articles =""; if(checkbox_marcats > 1) { $(".checkbox_comparar:checked").each(function(index, element) { cad_articles = cad_articles+"&productes["+index+"]="+$(this).attr("id_subarticle"); }); document.location = apps_url+"?action=pc&p=PUBLIC/PLANTILLES/comparar.php"+cad_articles; } else alert("Debe haber más de un artículo para hacer la comparación"); } function cart_afegir_article(id) { q=$("#article_"+id).val()*1; q=parseInt(q); if(q<1 || isNaN(q)){q=1;} ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart_small.php&unitats="+q+"&id_subarticle="+id,"carro_petit"); } function cart_recalcular() { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart.php&action_cart=recalcular&"+$("#form_cart").serialize(),"content"); } function cart_elimina_linea(id) { $("#cart_line_"+id).val(0); cart_recalcular() } function cart_canvia_regio(id) { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart.php&action_cart=canvia_regio&id_regio="+id,"content"); } function cart_canvia_transportista(id) { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart.php&action_cart=canvia_transportista&id_transportista="+id,"content"); } function cart_eliminar() { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart.php&action_cart=elimina_cart","content"); } function cart_promo() { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart.php&action_cart=promo&promo="+$("#promo").val(),"content"); } function dades_client() { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/client.php","content"); } //-------------------------------------------------------------------------------------------------------------------------------------------------------- function ajaxpage(url, containerid, post_params) { try { obj=$("#"+containerid); if(obj.outerHeight()>50) { t=obj.offset().top; l=obj.offset().left; obj.prepend('


'); } //host=window.location.host; //href=window.location.href.toString(); //protocol=href.split(host)[0]; url=url.replace(url.split("/")[2],window.location.host); $.post( url, post_params,function(data){obj.html(data);$("#capa_trans").remove();} ).always(function( data ) {$("#capa_trans").remove();}); } catch(e) { alert(e.message); } } var error_mostrat = false; function display_error(text,tipus) { switch(tipus) { case 'E':case 'e': clase="error"; break; case 'P':case 'p': clase="positiu"; break; default: clase="neutre"; break; } if(text) { if(!error_mostrat) { $('body').prepend(''); error_mostrat = true; } $('#displayedError').stop(true,true); $('#displayedError').removeClass("error"); $('#displayedError').removeClass("positiu"); $('#displayedError').removeClass("neutre"); $('#displayedError').addClass(clase); $('#displayedError').html(text); $('#displayedError').css({'position':'fixed', 'bottom' : '10px', 'right' : '20px', 'left' : '20px', 'z-index':'500'}); $('#displayedError').fadeIn(300, function(){ $('#displayedError').delay(3000).fadeOut(300); }); } }