// JavaScript Document var lastscrollTop = 0; var margin = 0; var diferencia = 0; var carro_desplegat = false; var ajaxTimer = false; var ajaxCall = false; var timeOut = false; var slide_act = 0; var num_slides = 0; var timeOutSlideHome = 0; var mida_mobile = 1000; var last_elem = ""; $(function(){ var height = $(window).height(); var width = $(window).width(); var w_scroll = 0; /*$.magnificPopup.instance._onFocusIn = function(e) { // Do nothing if target element is select2 input if( $(e.target).hasClass('allow_input') ) { return true; } // Else call parent method $.magnificPopup.proto._onFocusIn.call(this,e); };*/ $('.cycle-home').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(); } }); $('.gallery-item').magnificPopup({ type: 'image', gallery:{ enabled:true } }); $('.galeria_generica').magnificPopup({ delegate: 'a', type: 'image', gallery: { enabled: true } }); $('.filter-popup').magnificPopup({ type: 'inline', fixedContentPos: false, fixedBgPos: true, overflowY: 'auto', closeBtnInside: true, preloader: false, midClick: true, removalDelay: 100, mainClass: 'my-mfp-slide-bottom' }); // SLIDE PRINCIPAL HOME if($("#sliderHome").length > 0) { num_slides = $("#sliderHome img").length; timeOutSlideHome = setTimeout("canviar_slide_home()",5000); } // SLIDE CATÀLEGS HOME if($("#slide_catalegs").length > 0) { var owl= $("#slide_catalegs"); owl.owlCarousel({ loop:false, navigation:true, navigationText: ['',''], margin:35, itemsDesktop : [3000,5], //5 items between 1000px and 901px itemsDesktopSmall : [900,3], // betweem 900px and 601px itemsTablet: [600,2], //2 items between 600 and 0 responsive: true, responsiveRefreshRate : 200, responsiveBaseWidth: window, autoPlay : false, center: true }); } var auth_mostrat = false; $("#auth>span").bind("click",function(e) { auth_mostrat = true; if(!$(this).hasClass('active')) { $('.barra_desplegat').click(); $(this).addClass('active barra_desplegat'); $("#menu_client").stop(true,true).slideDown(100); $("#auth_user").select(); } else { $(this).removeClass('active barra_desplegat'); $("#menu_client").stop(true,true).slideUp(100); } }) $("#idiomes > li").click(function(event){ //event.preventDefault(); $(this).find("ul:first").stop(true,true).slideToggle(100); if(!$(this).find(".label_barra").hasClass('active')) $('.barra_desplegat').click(); $(this).find(".bg_linear").toggleClass("active"); $(this).find(".label_barra").toggleClass("barra_desplegat"); }); $("#boto_desplega_recerca").click(function(event) { event.preventDefault(); var elem = $(this); if(!elem.hasClass('active')) $('.barra_desplegat').click(); if($("#div-results").is(':visible')) { tancar_recerca(); } elem.toggleClass('active barra_desplegat'); $('#recerca').toggleClass("active"); $("#camp-recerca").focus(); }); $('.see_pwd').mousedown(function(event) { if(event.which==1) $(this).prev().attr("type","text"); }); $('html').mouseup(function() { $('.see_pwd').prev().attr("type","password"); }); $('.desplega_families .fa').click(function() { if($('#cont_height').attr('style')) $('#cont_height').removeAttr('style'); else $('#cont_height').css('max-height',$('.column').height()+'px'); $(this).toggleClass('active'); $('.desplega_families .deg').toggleClass('toggled'); }) $(window).on('load resize',function(){ w_scroll = window.innerWidth-$(window).width(); if($(window).width() <= mida_mobile && last_elem != '#contenidor_arees') { $("#header").insertAfter('#contenidor_arees'); last_elem = "#contenidor_arees"; $("#columna_esq").removeAttr("style"); if($('#fixed_menu .botiga_menu').length == 0) { clone = $('.botiga_menu').clone(); $('#botiga_menu').html(clone); clone = $('#barra_top .desplegador_menu').clone(); $('#botiga_menu').append(clone); clone = $('#menu').clone(); $('#botiga_menu').append(clone); } $('#menu .botiga_menu').removeClass('active'); $('#menu .botiga_menu').next().stop(true,true).slideUp("fast"); } else if($(window).width() > mida_mobile && last_elem != '#barra_top') { $("#header").insertAfter('#barra_top'); last_elem = "#barra_top"; } if($(window).width() <= (mida_mobile - w_scroll)) { $('#fixed_menu').addClass('fixed'); } else { if($(document).scrollTop() <= 300) { $('#fixed_menu').removeClass('fixed'); } } if($("#recerca.active").height()) { //if($(window).height()!=height ||) { height = $(window).height(); width_search = $('.contenidor_centrat').width(); if($(window).width() > 1000) $("#recerca").css({'height':(height-70)+'px','width':(width_search)+'px'}); else $("#recerca").css('height',(height-150)+'px'); //} } }); $(window).scroll(function(){ /*if($(document).scrollTop() > 300) { if($('#fixed_menu .botiga_menu').length == 0) { clone = $('.botiga_menu').clone(); $('#botiga_menu').html(clone); } } else { $("#botiga_menu > a").removeClass('active'); $("#botiga_menu > div").slideUp('fast'); }*/ if($(window).width() > mida_mobile) { if($('#columna_esq').length) controla_scroll(); if($(document).scrollTop() > 300 && $('#content').height()> 800) { //if(!$("#fixed_menu").hasClass('fixed')) $("#fixed_menu").addClass('fixed'); $("#scroll_top").fadeIn(250); if($('#fixed_menu .botiga_menu').length == 0) { clone = $('.botiga_menu').clone(); $('#botiga_menu').html(clone); } } else { $("#fixed_menu").removeClass('fixed'); $("#scroll_top").fadeOut(250); $("#botiga_menu > a").removeClass('active'); $("#botiga_menu > div").slideUp('fast'); } } else { if($('#columna_esq').length) $("#columna_esq").removeAttr("style"); } }); $('input[name="destacats"]').click(function() { //event.preventDefault(); $('input[name="destacats"]').prop("checked",false); $('input[name="destacats"]').not(this).removeClass("chkd"); if($(this).hasClass('chkd')) $(this).prop("checked",false); else $(this).prop("checked",true); $(this).toggleClass('chkd'); }); $("#scroll_top").click(function() { $('html,body').animate({ scrollTop: 0 }, 'fast'); }); $('#desplegador_botiga').click(function() { $('#menu_sup, #form_families').toggle() }); $(".boto_compra").click(function(event){ event.preventDefault(); var id_grup=$(this).attr('id_grup'); var id_art=$(this).attr('id_subarticle'); cart_afegir_article(id_art); anima_imatge(id_grup); if($(window).width() > mida_mobile && !$('#desplega_cart_small').hasClass('active')) desplegar_cart(100); }); $(".open_modal").click(function(event) { event.preventDefault(); p = $(this).parent(); $(p).find('.trigger_popup').click(); event.stopPropagation(); }) ; inicia_vistes_rapides(); }); function mark_all(el) { trigger = $(el).attr("name"); mark = false; $('input[data-id="'+trigger+'"]').each(function(index, element) { mark = !$(element).is(":checked"); if(mark == true) { return false; } }); $('input[data-id="'+trigger+'"]').prop("checked",mark); $(el).prop("checked",mark); } function inicia_vistes_rapides() { if($('.gallery_popup').length) $('.gallery_popup').cycle(); $('.ajax-popup-link').magnificPopup({ type: 'ajax', closeOnContentClick:false, callbacks:{ ajaxContentAdded:function(){ height = $(window).height(); if($(window).width() <= mida_mobile) $(".white-popup-ajax > div > div:first-child").css('height',(height-70)+'px'); $(".white-popup-ajax .boto_compra").click(function(event){ event.preventDefault(); var id_grup=$(this).attr('id_grup'); var id_art=$(this).attr('id_subarticle'); anima_imatge(id_grup); cart_afegir_article(id_art); }); inicia_vistes_rapides(); } } }); $.magnificPopup.instance._onFocusIn = function(e) { // Do nothing if target element if( $(e.target).parents().hasClass('fixed') ) { return true; } // Else call parent method $.magnificPopup.proto._onFocusIn.call(this,e); }; } function anima_imatge(id_art) { //si no hi ha imatge per animar no fem res if ($(".foto_"+id_art).length) { var carro = $("#carro_petit"); var foto_original = $(".foto_"+id_art).get(0); foto_original = $(foto_original); foto_top=foto_original.offset().top+"px"; foto_left=foto_original.offset().left+"px"; foto_width=foto_original.width()+"px"; foto_height=foto_original.height()+"px"; var foto = foto_original .clone() .attr('id','img_clonada') .css({ top:foto_top, left:foto_left, width:foto_width, height:foto_height, position:"absolute", "z-index":"9999" }) .appendTo("body"); var marginTop = carro.offset().top - foto.offset().top; var marginLeft = carro.offset().left - foto.offset().left; var amplada = carro.offset().width; foto.animate({marginTop:marginTop,marginLeft:marginLeft, opacity:0.2, width:120+"px", height:120+"px"},1000,function(){ foto.remove(); }); } } function controla_scroll() { var limitSuperat = $(document).scrollTop() > $("#content").offset().top; if($("#columna_esq").outerHeight() < $("#columna_dre").outerHeight()) { var limitSuperat2 = $(document).scrollTop() > $("#content").offset().top+50; var window_bottom = $(document).scrollTop()+$(window).height(); var columna_esq_bottom = $("#columna_esq").offset().top+$("#columna_esq").outerHeight(); var condicio1; var condicio2; if(limitSuperat2) { diferencia = lastscrollTop-$(document).scrollTop(); //Estic baixant i la part inferior de la pantalla encara no ha arribat al final de la columna condicio1=diferencia < 0 && window_bottom <= columna_esq_bottom+10; //Estic pujant i encara no he arribat al principi de la columna condicio2=diferencia > 0; //Estic baixant i la columna està apunt de sobreposar-se al peu de pàgina condicio3=diferencia < 0 && window_bottom >= $("#prefooter").offset().top; if(condicio1 || condicio2 || condicio3) { margin = margin+diferencia;} if(margin > 0) margin = 0; $("#columna_esq").css({'position':'fixed','top':60,'margin-top':margin,'overflow':'hidden'}); } else { $("#columna_esq").removeAttr("style"); margin=0; diferencia=0; } lastscrollTop = $(document).scrollTop(); } } function desplega_menu(elem) { if(!elem) var elem = "#menu"; $(elem).slideToggle("fast"); /*if($(".nav_areas .botiga_menu").hasClass('active')) { //desplega_botiga(event,$(".nav_areas .botiga_menu")) }*/ } function comprova_formulari_client() { var frm = document.form_client; error = ""; 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($("#g-recaptcha-response").val() == "") { error +=escriu_el_codi+'\n'; } if(error) alert(error); else frm.submit(); } function canviar_slide_home(n_slide) { if(n_slide >= 0) { slide_act = n_slide; clearTimeout(timeOutSlideHome); } else slide_act = (slide_act+1)%num_slides; var label_act_top = $("#label_"+slide_act).position().top; var label_act_height = $("#label_"+slide_act).outerHeight(); var contenidor_labels_height = $("#labels_home > div").outerHeight(); if(label_act_top >= contenidor_labels_height || label_act_top+label_act_height <= 0) { var newpos = $("#label_"+slide_act).outerHeight(true)*slide_act; $("#labels_home > div").animate({scrollTop:(newpos)}); } $("#sliderHome a.active,#labels_home span.active").removeClass("active"); $("#foto_"+slide_act+",#label_"+slide_act).addClass("active"); timeOutSlideHome = setTimeout("canviar_slide_home()",5000); } function next_slide_home() { canviar_slide_home((slide_act+1)%num_slides); } function prev_slide_home() { var nou_label = slide_act-1; if(nou_label < 0) nou_label = num_slides-1; canviar_slide_home(nou_label); } function carregar_recerca(){ //$("#div-results").css('display','none').html(''); $("#div-results").html('
'); term = $("#camp-recerca").val(); if(!$("#bg_sec").is(":visible") && term.length > 0) { //$("html,body").scrollTop(0).css('overflow','hidden'); $("html,body").css('overflow','hidden'); if($(window).width() > mida_mobile) r_height = 70 else r_height = 150 $("#bg_sec").fadeIn(300,function(){ $("#recerca").css('background-color','#FFFFFF').animate({width:$('.contenidor_centrat').width(),height:(($(window).height())-r_height)},500,function(){ $("#recerca .titol_recerca").fadeIn(); aplicar_recerca(term); }); }); } else aplicar_recerca(term); } function aplicar_recerca(term) { if(ajaxCall) ajaxCall.abort(); if(term.length < 3) { $("#div-results").html('
La búsqueda no tiene suficientes caracteres
'); } else { ajaxCall = $.ajax({ url: 'https://www.muropapel.com/index.php', data: { action : 'p', p : 'PUBLIC/php/search_res.php', desc : term }, dataType: 'html', success: function(data){ $("#div-results").html(data); ajaxCall=null; } }); } } function tancar_recerca() { $("#recerca .titol_recerca").css("display","none"); $("#bg_sec").fadeOut(300); $("#recerca").animate({width:206,height:36},500,function(){ $("body,#recerca").removeAttr("style"); if(!$('.mfp-bg').length) $("html").removeAttr("style"); if($("#recerca").hasClass('active')) { $("#boto_desplega_recerca,#recerca").removeClass('active'); $("#boto_desplega_recerca").removeClass('barra_desplegat'); } }); $("#div-results").html(''); } // FUNCIONS ÁREA CLIENT ------------------------------------------------------------------------------------------------------------------------------------------ function pressupost_print(id,id_c) { var add_query = ""; if(id_c) var add_query="&id_c="+id_c; window.open(apps_url+"?action=p&p=PUBLIC/SHOP/pressupostos_client.php&action_client=imprimir&id_pressupost="+id+add_query); } function v_press(id,c) { $('#detalls_pres_'+id).html('
'); $.post(apps_url+'?action=p&p=PUBLIC/SHOP/pressupostos_detalls_client.php&id_pressupost='+id+'&id_c='+c+'&no_index=true',function(data){ $('#detalls_pres_'+id).html(data); }); } function modifica_quantitat_pres(id,id_detall,valor,c) { $('#detalls_pres_'+id).html('
'); $.post(apps_url+'?action=p&p=PUBLIC/SHOP/pressupostos_detalls_client.php&action_client=pressupost_update&id_pressupost='+id+'&id_detall='+id_detall+'&quantitat='+valor+'&id_c='+c+'&no_index=true',function(data){ $('#detalls_pres_'+id).html(data); }); } function albara_print(id,id_c) { var add_query = ""; if(id_c) var add_query="&id_c="+id_c; window.open(apps_url+"?action=p&p=PUBLIC/SHOP/comandes_client.php&action_client=imprimir&id_albara="+id+add_query); } function v_albara(id,c) { $('#detalls_alb_'+id).html('
'); $.post(apps_url+'?action=p&p=PUBLIC/SHOP/comandes_detalls_client.php&id_albara='+id+'&id_c='+c+'&no_index=true',function(data){ $('#detalls_alb_'+id).html(data); }); } function v_carro_pendent(sid) { $('#detalls_carro_'+sid).html('
'); $.post(apps_url+'?action=p&p=PUBLIC/SHOP/carros_pendents_detalls.php&sid_carro='+sid+'&no_index=true',function(data){ $('#detalls_carro_'+sid).html(data); }); } function v_carro_recuperar(sid) { $('#detalls_carro_'+sid).html('
'); ajaxpage(apps_url+'?action=p&p=PUBLIC/SHOP/carros_pendents_recuperar.php&sid_carro='+sid+'&no_index=true','detalls_carro_'+sid,"",cartSmall_recalcular_total); /*$.post(apps_url+'?action=p&p=PUBLIC/SHOP/carros_pendents_recuperar.php&sid_carro='+sid+'&no_index=true',function(data){ $('#detalls_carro_'+sid).html(data); }); cartSmall_actualitzar_vista()*/ } function desplega_menu_area_client() { algun_visible=true; $("#desplegador_menu_area_client").toggleClass("mnu_selected"); $("#desplegador_menu_meva_comanda").removeClass("mnu_selected"); $("#desplegador_menu_compra_rapida").removeClass("mnu_selected"); if ($("#area_client_lat").css("display")=="none") { $("#area_client_lat,#area_client_lat2").stop(true,true).slideToggle(200); $("#carro_resum").stop(true,true).slideUp(200); $("#seccio").stop(true,true).slideUp(200); } else { $("#area_client_lat,#area_client_lat2").stop(true,true).slideToggle(200); } } // FUNCIONS CARRO ------------------------------------------------------------------------------------------------------------------------------------------------ function desplegar_cart(durada) { if(!durada) durada = 0; if(!$('#desplega_cart_small').hasClass('active')) $('.barra_desplegat').click(); $('#desplega_cart_small').toggleClass('active barra_desplegat'); $('#cont_cart_small').stop(true,true).slideToggle(durada); $('#carro_petit #qty-rapida').focus(); } function cart_afegir_article(id,qty) { var carro = "cart_small_detail"; if(qty) q=qty; else q=$("#article_"+id).val()*1; q=parseInt(q); if(q<1 || isNaN(q)){q=1;} if($("#carro_petit").length > 0) ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart_small_detail.php&action_cart=add&unitats="+q+"&id_subarticle="+id,"arts_cart_small","",cart_actualitzar_vista); else document.location = apps_url+"?action=pc&p=PUBLIC/SHOP/cart.php&action_cart=add&unitats="+q+"&id_subarticle="+id; } function cartSmall_actualitzar_vista() { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart_small_detail.php","arts_cart_small"); } function cart_actualitzar_vista() { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart.php","carro_gran"); } function cart_petit_elimina_linia(id) { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart_small_detail.php&action_cart=del&id_subarticle="+id,"arts_cart_small","",cart_actualitzar_vista); } function cart_recalcular() { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart.php&action_cart=recalcular&"+$("#form_cart").serialize(),"carro_gran","",cartSmall_actualitzar_vista); } function cart_small_recalcular(id,n) { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart_small_detail.php&action_cart=recalcular&id_subarticle="+id+"&unitats="+n,"arts_cart_small","",cart_actualitzar_vista); } function cartSmall_recalcular_total() { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart_small_detail.php&action_cart=recalcular_total","arts_cart_small","",cart_actualitzar_vista); } function cart_elimina_linea(id) { $("#cart_page_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,"carro_gran"); } function cart_canvia_transportista(id) { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart.php&action_cart=canvia_transportista&id_transportista="+id,"carro_gran"); } function cart_eliminar() { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart.php&action_cart=elimina_cart","carro_gran","",cartSmall_actualitzar_vista); } function cart_promo() { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/cart.php&action_cart=promo&promo="+$("#promo").val(),"carro_gran"); } function dades_client() { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/client.php","content"); } function cart_result() { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/result.php&que=albara&"+$("#form_cart").serialize(),"content","",cartSmall_recalcular_total); } function cart_result_pres() { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/result.php&que=pressupost&"+$("#form_cart").serialize(),"content","",cartSmall_recalcular_total); } function cart_result_lic() { ajaxpage(apps_url+"?action=p&p=PUBLIC/SHOP/result.php&que=licitacio&"+$("#form_cart").serialize(),"content","",cartSmall_recalcular_total); } function result_families(next) { ajaxpage(apps_url+"?action=p&p=PUBLIC/PLANTILLAS/families.php&que=filtre&next="+next+"&"+$("#form_families").serialize(),"result_families"); } function filtra_llistat_ajax(next) { el = $('#destacats').find('input:checked') el.prop('checked',false); ajaxpage(apps_url+"?action=p&p=PUBLIC/PLANTILLAS/families.php&que=filtre&next="+next+"&"+$("#form_families").serialize()+"&"+$("#form_filtres_caracs").serialize(),"result_families"); $.magnificPopup.close(); } function load_more(next) { ajaxpage(apps_url+"?action=p&p=PUBLIC/PLANTILLAS/families.php&que=filtre&next="+next+"&"+$("#form_families").serialize(),"res_load_more_"+next); } function put_cart_to_presu(id,id_client) { ajaxpage(apps_url+'?action=p&p=PUBLIC/SHOP/pressupostos_detalls_client.php&que=pres_add_cart&id_pressupost='+id+'&id_c='+id_client,"detalls_pres_"+id,"",cartSmall_actualitzar_vista); } //-------------------------------------------------------------------------------------------------------------------------------------------------------- function ajaxpage(url, containerid, post_params, callback) { 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();} ) .done(function() { if(callback) { callback(); var selector = "#arts_cart_small tbody" if(callback == cartSmall_actualitzar_vista) selector = "#cart tbody"; var count = $(selector).children().length; $('.linees').remove(); if(count>0) $('#desplega_cart_small').append('
'+count+'
'); } }) .always(function( data ) { $("#capa_trans").remove(); }); } catch(e) { alert(e.message); } } var error_mostrat = false; var timeoutMissatge = null; 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({'width':'300px','position':'fixed', 'top' : '46%', 'left' : '50%','margin-left':'-160px', 'z-index':'500'}); clearTimeout(timeoutMissatge); $('#displayedError').stop(true,true).css('display','none').fadeIn(300, function(){ timeoutMissatge = setTimeout(function(){$('#displayedError').fadeOut(300);},3000); }); } } function acceptar_rgpd() { ajaxpage(apps_url+"?action=p&p=PUBLIC/php/methods.php&m=accept_rgpd&"+$('#frm_acceptar_rgpd').serialize(),""); $.magnificPopup.instance.close(); } function change_pwd() { ajaxpage(apps_url+"?action=p&p=PUBLIC/php/methods.php&m=change_pwd&"+$('#frm_new_pwd').serialize(),"change_pwd_result"); }