var ajaxTimer = false; var ajaxCall = false; var timeOut = false; $(function(){ if($(window).width() < 984) { append_menu(); } $(".cycle").cycle(); $("#camp-recerca").keydown(function(){ if(ajaxTimer) window.clearTimeout(ajaxTimer); if(ajaxCall) ajaxCall.abort(); }); $("#camp-recerca").keyup(function(e){ if(e.keyCode != 13) { ajaxTimer = setTimeout(function(){carregar_recerca()},1000); window.ajaxTimer; } else { carregar_recerca(); } }); $("#camp-recerca2").keydown(function(){ if(ajaxTimer) window.clearTimeout(ajaxTimer); if(ajaxCall) ajaxCall.abort(); }); $("#camp-recerca2").keyup(function(e){ if(e.keyCode != 13) { ajaxTimer = setTimeout(function(){carregar_recerca2()},1000); window.ajaxTimer; } else { carregar_recerca2(); } }); $('.foto').magnificPopup({ delegate: 'a', type: 'image', tLoading: 'Loading image #%curr%...', mainClass: 'mfp-img-mobile', gallery: { enabled: true, navigateByImgClick: true, preload: [0,1] // Will preload 0 - before current, and 1 after the current image }, image: { tError: 'The image #%curr% could not be loaded.', titleSrc: function(item) { return item.el.attr('title'); } } }); $('.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"); 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(""); event.preventDefault(); } }); $('.galeria_generica').magnificPopup({ delegate: 'a', type: 'image', gallery: { enabled: true } }); $(window).resize(function(){ if($(window).width() > 984) { $("#categoriestopmenu_ul").removeAttr("style"); $(".node_parent ul").removeAttr("style"); append_head(); } else append_menu(); }); $(".node_parent > a").click(function(event){ if($(window).width() < 984) { // Si tinc més ul's desplego if($(this).parent().children('div').length > 0) { event.preventDefault(); $(this).parent().find("div:first").slideToggle(); } } }); controla_submenus(); $(window).resize(function(){ controla_submenus(); }); $('.see_pwd').mousedown(function(event) { if(event.which==1) $(this).prev().attr("type","text"); }); $('html').mouseup(function() { $('.see_pwd').prev().attr("type","password"); }); }); function controla_submenus() { var w_width = $(window).width(); $("#categoriestopmenu_ul > li").each(function(){ if($(this).offset().left > (w_width/2)) $(this).addClass("submenu_right"); else $(this).removeClass("submenu_right"); }); } function comprova_form_newsletter() { error = ""; var frm = document.frm_newsletter; if(frm.xmal.value.length < 3 || frm.xmal.value=='El teu correu electrònic') error += 'Ompli el camp: El teu correu electrònic\n'; else if(!(/\S+@\S+\.\S+/.test(frm.xmal.value))) error += 'Email incorrecte\n'; if(error) alert(error); else frm.submit(); } var data_ok = false; function comprova_dades_comentari() { var error=""; frm = document.frm_opinio; if(frm.nom_comentari.value.length < 3) error += 'Ompli el camp: Nom\n'; if(frm.text_comentari.value.length < 3) error += 'Ompli el camp: \n'; if(frm.email_comentari.value.length < 3) error += 'Ompli el camp: El teu correu electrònic\n'; else if(!(/\S+@\S+\.\S+/.test(frm.email_comentari.value))) error += 'Email incorrecte\n'; if(error) alert(error); else { data_ok = true; grecaptcha.execute(recaptcha1); } } function submit_comentari() { if(data_ok) document.frm_opinio.submit(); } function comprova_form_contacte() { error = ""; frm = document.frm_contacte; if(frm.nom.value.length < 3) error += ompli_el_camp+': '+nom+'\n'; if(frm.telefon.value.length < 3) error += ompli_el_camp+': '+telefon+'\n'; if(frm.client_mail.value.length < 3) error += ompli_el_camp+': '+email+'\n'; else if(!(/\S+@\S+\.\S+/.test(frm.client_mail.value))) error += email_incorrecto+'\n'; if(!frm.check_condicions.checked) error += cal_acceptar_condicions+'\n'; /*if(frm.captcha_client.value.length < 4) error += escriu_el_codi+'\n';*/ if(error) alert(error); else { data_ok = true; grecaptcha.execute(recaptcha1); } } function submit_contacte() { if(data_ok) document.frm_contacte.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(""); } function refresca_cart_petit() { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart_small.php","carro_petit"); } function cart_afegir_article(id, nom, quantitat) { display_error(article_afegit_al_carro, "P"); q=$("#article_"+id).val()*1; //actualitzar_unitats_restants(q); 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"); if($("#OSC_main").length > 0) { OSC_cart_recalcular(); } } function cart_afegir_linea_carro(id, titol, preu, marca, family) { dataLayer.push({ 'event': 'addToCart', 'ecommerce': { 'currencyCode': 'EUR', 'add': { // 'add' actionFieldObject measures. 'products': [{ // adding a product to a shopping cart. 'name': titol, 'id': id, 'price': preu, 'brand': marca, 'id_familia': family, 'variant': '', 'quantity': 1 }] } } }); } 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, titol, id2, units, marca) { dataLayer.push({ 'event': 'removeFromCart', 'ecommerce': { 'remove': { // 'remove' actionFieldObject measures. 'products': [{ // removing a product to a shopping cart. 'id': id2, 'name': titol, 'price': '', 'brand': marca, 'category': '', 'variant': '', 'quantity': units }] } } }); $("#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 cart_canvia_nota_regalo() { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart.php&action_cart=canvia_nota&"+$("#form_obs").serialize(),"content"); } function dades_client() { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/client.php&"+$("#form_obs").serialize(),"content"); } //-------------------------------------------------------------------------------------------------------------------------------------------------------- function ajaxpage(url, containerid, post_params) { try { obj=$("#"+containerid); if(obj.outerHeight()>50) { t=obj.offset().top; l=obj.offset().left; obj.prepend('

');
$("#div-results").html('
');
term = $("#camp-recerca2").val();
aplicar_recerca2(term);
}
function aplicar_recerca2(term)
{
if(ajaxCall) ajaxCall.abort();
if(term.length < 3) {
$("#div-results-movil").html('');
$("#content").css("display","block");
}
else
{
$("#div-results-movil").html('