!function(e,t){var n=function(e){var n=this;n.$elm=e,n.$map=e.find(".serviceCenter__map .map"),n.gmInstance=null,n.userLat=null,n.userLong=null,t(window).width()<768&&t(".serviceCenter").length>0&&t(".serviceCenterMap__mobile").prepend(t(".serviceCenter")),navigator.geolocation&&navigator.geolocation.getCurrentPosition(function(e){n.$map.addClass("showBtnRoute"),n.userLat=e.coords.latitude,n.userLong=e.coords.longitude}),t.ajax({url:"https://maps.googleapis.com/maps/api/js?client=gme-belroninternational&channel=belron_bel&v=3.23",dataType:"script",cache:!0}).done(function(){n.initMap()})};n.prototype.initMap=function(){var e=t(document).width()>480,n=this,a=new google.maps.LatLngBounds,r={mapTypeId:"roadmap",draggable:e};n.gmInstance=new google.maps.Map(n.$map[0],r);var s=n.$map.data("ids").split(",").join("&serviceCenterIds=");t.ajax({type:"GET",dataType:"json",url:n.$map.data("service")+"?serviceCenterIds="+s+"&type="+n.$map.data("servicecentertype"),success:function(e){var r=[],s=[];for(c=0;c<e.ServiceCenters.length;c++){var i=e.ServiceCenters[c];t(".adress__icon").addClass(i.TypeCode),r.push([i.Name,i.Latitude,i.Longitude,i.TypeCode]),s.push(['<div class="gm-popup" style="min-width: 200px;"><h4><a href="'+i.Url+'">'+i.Name+"</a></h4><p>"+i.Address+'</p><div class="searchCenters__openinghours">'+i.OpeningHours+'</div><p><a class="btnRoute" onclick="serviceCenterMap.openRouteUrl(event,'+i.Latitude+","+i.Longitude+')" href="#">'+e.Labels.DirectionsLinkLabel+'</a><a class="btn btn-primary btn-sm" href="'+i.Url+'">'+e.Labels.DetailsLinkLabel+"</a></p></div>"])}var o=!1;0==r.length&&(o=!0,r.push(["dummy",51.262073,3.205185]));var l,c,p=new google.maps.InfoWindow;for(c=0;c<r.length;c++){var m=new google.maps.LatLng(r[c][1],r[c][2]),d="/assets/corporate/img/map/ico_"+r[c][3]+".png";a.extend(m),0==o&&(l=new google.maps.Marker({position:m,map:n.gmInstance,title:r[c][0],icon:d})),0==o&&google.maps.event.addListener(l,"click",function(e,t){return function(){p.setContent(s[t][0]),p.open(n.gmInstance,e)}}(l,c)),n.gmInstance.fitBounds(a),1==r.length&&setTimeout(function(){o?n.gmInstance.setZoom(10):n.gmInstance.setZoom(15)},200)}},error:function(){console.log("Something went wrong. Please refresh the page.")}})},n.prototype.openRouteUrl=function(e,t,n){e.preventDefault(),window.open("https://www.google.com/maps?daddr="+t+","+n+"&saddr="+this.userLat+","+this.userLong)},t(document).ready(function(){t(".serviceCenter").length>0&&(e.serviceCenterMap=new n(t(".serviceCenter")))})}(window,window.jQuery),function(e,t,n){var a=function(e){console.log("search service center");var a=this;a.$elm=e,a.$map=e.find(".searchCenters__map .map"),a.$list=e.find(".searchCenters__list"),a.$form=e.find(".searchCenters__form"),a.gmInstance=null,a.centers={},a.gmMarkers=[],a.ajaxRequest=null,a.$searchLoader=a.$form.find(".loader-icon"),a.$noResults=e.find(".searchCenters__noResults"),a.template=t("#list-template").html(),n.parse(a.template),a.$elm.data("region")||a.$elm.data("region","BE"),a.savePrefilledData(),t.ajax({url:"https://maps.googleapis.com/maps/api/js?client=gme-belroninternational&channel=belron_bel&v=3.23",dataType:"script",cache:!0}).done(function(){a.initMap();var e=decodeURIComponent(r("search"));null!=e&&"null"!=e?(a.$form.find("#searchString").val(e),a.search(e)):a.$form.find("#searchString").val()?a.search(a.$form.find("#searchString").val()):a.getAllCenters()}),a.$form.on("submit",function(e){e.preventDefault(),a.search(t(this).find("#searchString").val(),!0)})},r=function(e){var t={};return window.location.href.replace(location.hash,"").replace(/[?&]+([^=&]+)=?([^&]*)?/gi,function(e,n,a){t[n]=void 0!==a?a:""}),e?t[e]?t[e]:null:t};a.prototype.getAllCenters=function(){var e=this;e.ajaxRequest&&4!=e.ajaxRequest.readyState&&e.ajaxRequest.abort(),e.ajaxRequest=t.ajax({type:"GET",dataType:"json",url:e.$elm.data("serviceall")+"?type="+e.$elm.data("servicecentertype")+"&siteName="+e.$elm.data("servicesitename"),success:function(n){e.centers=n,e.removeMarkers(),e.setMarkers(),"cc,ccx"==e.$elm.data("servicecentertype")&&t(".map__legend").show()},error:function(){console.warn("Something went wrong. Please refresh the page.")}})},a.prototype.search=function(e,n){e=encodeURIComponent(e);var a=this;a.clearResult(),a.$searchLoader.removeClass("hidden");var r="https://maps.googleapis.com/maps/api/geocode/json?client=gme-belroninternational&address="+e.trim()+"&components=country:"+a.$elm.data("region")+"&region="+a.$elm.data("region");t.ajax({type:"GET",dataType:"json",data:{url:r},url:a.$elm.data("servicesignature"),success:function(e){a.ajaxRequest&&4!=a.ajaxRequest.readyState&&a.ajaxRequest.abort(),a.ajaxRequest=t.ajax({type:"GET",dataType:"json",url:r+"&signature="+e,success:function(e){a.$searchLoader.addClass("hidden"),e.results=t.grep(e.results,function(e,t){return!0!==e.partial_match}),e.results.length>0?a.getCenters(e.results[0].geometry.location.lat,e.results[0].geometry.location.lng,n):(a.render({ServiceCenters:[]}),a.$noResults.removeClass("hidden"))},error:function(){console.warn("GM error"),a.render({ServiceCenters:[]})}})},error:function(){console.warn("Signature error"),a.render({ServiceCenters:[]})}})},a.prototype.getCenters=function(e,n,a){var s=this,i=1==s.$elm.data("requirebranchid")?"&requireBranchId=true":"&requireBranchId=false",o=1==s.$elm.data("deprioritize-popup")?"&deprioritizePopup=true":"&deprioritizePopup=false",l="";a||(l=(l=decodeURIComponent(r("branchid"))||null)?"&branchIdToListFirst="+l:""),s.ajaxRequest&&4!=s.ajaxRequest.readyState&&s.ajaxRequest.abort(),s.ajaxRequest=t.ajax({type:"GET",dataType:"json",url:s.$elm.data("service")+"?latitude="+e+"&longitude="+n+i+l+o+"&type="+s.$elm.data("servicecentertype")+"&siteName="+s.$elm.data("servicesitename"),success:function(e){s.centers=e,s.callback(e),s.render(e),s.removeMarkers(),s.setMarkers()},error:function(){console.warn("Get centers error"),s.render({ServiceCenters:[]})}})},a.prototype.initMap=function(){var e={mapTypeId:"roadmap",mapTypeControl:!1,draggable:t(document).width()>480};this.gmInstance=new google.maps.Map(this.$map[0],e)},a.prototype.removeMarkers=function(){for(var e=0;e<this.gmMarkers.length;e++)this.gmMarkers[e].setMap(null);this.gmMarkers=[]},a.prototype.setMarkers=function(){var e=this,a=new google.maps.LatLngBounds;e.gmMarkers=[];var r=[],s=[];if(void 0!==e.centers.ServiceCenters){var i=e.$elm.data("limit")||e.centers.ServiceCenters.length,o=i>e.centers.ServiceCenters.length?e.centers.ServiceCenters.length:i;for(h=0;h<o;h++){var l=e.centers.ServiceCenters[h];r.push([l.Name,l.Latitude,l.Longitude,l.TypeCode]);var c="";if(t("#infoWindow-template").length){var p={Name:l.Name,Address:l.Address,OpeningHours:l.OpeningHours,Link:l.Url,LinkLabel:e.centers.Labels.DetailsLinkLabel,DirectionsLink:"https://www.google.be/maps/search/Carglass+"+l.Address,DirectionsLinkLabel:e.centers.Labels.DirectionsLinkLabel,AppointmentLink:l.AppointmentLink,AppointmentLinkLabel:e.centers.Labels.AppointmentLinkLabel};c=[n.render(t("#infoWindow-template").html(),p)]}else c=['<div class="gm-popup" style="min-width: 300px;"><h4><a href="'+l.Url+'">'+l.Name+"</a></h4><p>"+l.Address+'</div><div class="searchCenters__openinghours">'+l.OpeningHours+'</div><p><a class="btn btn-info btn-sm" href="'+l.Url+'">'+e.centers.Labels.DetailsLinkLabel+'</a><a class="btn btn-primary btn-sm" href="'+l.BookingsLink+'">'+e.centers.Labels.AppointmentLinkLabel+"</a></p></div>"];s.push(c)}}var m=!1;0==r.length&&(m=!0,r.push(["dummy",51.262073,3.205185]));var d,h,u=new google.maps.InfoWindow;for(h=0;h<r.length;h++){var g=new google.maps.LatLng(r[h][1],r[h][2]),v="/assets/corporate/img/map/ico_"+r[h][3]+".png";a.extend(g),0==m&&(d=new google.maps.Marker({position:g,map:e.gmInstance,title:r[h][0],icon:v}),e.gmMarkers.push(d)),0==m&&google.maps.event.addListener(d,"click",function(t,n){return function(){u.setContent(s[n][0]),u.open(e.gmInstance,t)}}(d,h)),e.gmInstance.fitBounds(a),1==r.length&&setTimeout(function(){m?e.gmInstance.setZoom(10):e.gmInstance.setZoom(15)},200)}1==i&&google.maps.event.trigger(e.gmMarkers[0],"click")},a.prototype.render=function(e){if(this.$list.length){var a=n.render(this.template,e);t(".searchCenters__results").html(a),jQuery("[data-sitecontext*='glass'] .searchCenters__results .searchCenters__item").length&&window._gtmStoreLocatorGlass(),jQuery("[data-sitecontext*='carrosserie'] .searchCenters__results .searchCenters__item").length&&window._gtmStoreLocatorBody()}},a.prototype.getServiceCenterAvailability=function(n,a){var r=new Date;t.ajax({type:"GET",dataType:"json",url:this.$elm.data("availability")+"?startDate="+r.getFullYear()+","+(r.getMonth()+1)+","+r.getDate()+"&jobType="+this.$elm.data("jobtype")+"&branchCode="+n+"&damageAmount="+this.$elm.data("damage-amount")+"&type="+this.$elm.data("servicecentertype"),success:function(r){var s;(s=t(a?".bookingsflow__mapResult .moreCenters__availableSlots#branch-"+n:".bookingsflow__mapResult .serviceCenter__availableSlots")).html("");for(var i=a?1:2,o=0;o<(r.AvailableTimeSlots.length>i?i:r.AvailableTimeSlots.length);o++){var l=String(r.AvailableTimeSlots[o].DateTime).split("T")[0]+"T"+r.AvailableTimeSlots[o].StartTime,c='<span style="text-transform:capitalize">'+e.tools.getMoment(r.AvailableTimeSlots[o].DateTime,"dddd")+"</span>",p=e.tools.getMoment(l,"H:mm"),m=e.tools.getMoment(l,"D MMMM"),d=e.tools.getMoment(r.AvailableTimeSlots[o].DateTime,"YYYY-MM-DD");if(moment().format("YYYY-MM-DD")==d)var h=moment().calendar(r.AvailableTimeSlots[o].DateTime,"sameDay"),u=t('<span class="appointment__dayActive" '+(a?'data-more-centers="true" ':"")+'data-datetime="'+l+'" data-branchcode="'+n+'"><a href="#">'+h+" "+p+"</a></span>");else u=t('<span class="appointment__dayActive" '+(a?'data-more-centers="true" ':"")+'data-datetime="'+l+'" data-branchcode="'+n+'"><a href="#">'+c+" "+m+" "+p+"</a></span>");s.append(u)}e.chooseTimeSlot.initLocationSelectors()},error:function(){console.warn("Get appointment data error")}})},a.prototype.clearResult=function(){this.$noResults.addClass("hidden"),e.ajaxAbort(),"bookingsflow"==this.$elm.data("type")&&t("input#appointment_branchcode").val()&&(t(".bookingsflow__mapResult").addClass("hidden"),t(".bookingsflow__timetable").addClass("hidden"),t(".bookingsflow__appointmentForm").addClass("hidden"),e.timeTable.resetTimeTable(),t("input#appointment_branchcode").val(""),t("input#appointment_time").val(""),t(".bookingsflow__timetable").data("branchcode",""),t("#appointment_free_coffee").hide(),t("#appointment_free_papers").hide(),t("#appointment_free_wifi").hide(),t("#appointment_charging_station").hide(),t("#appointment_bicycle").hide(),t(".bookingsflow__choice .timetable__day").removeClass("timetable__dayActive").html(""),e.promoBanner.clearBanner())},a.prototype.callback=function(){if("bookingsflow"==this.$elm.data("type")){t("input#appointment_branchcode").length&&t("input#appointment_branchcode").val()&&t("input#appointment_time").val()&&e.chooseTimeSlot.selectTimeSlot(t("input#appointment_branchcode").val(),t("input#appointment_time").val()),t(".bookingsflow__mapResult.hidden").removeClass("hidden"),this.initMap(),t(".bookingsflow__mapResult .bookingsflow__serviceCenter .adress__txt h3").html(this.centers.ServiceCenters[0].Name);var n=this.centers.ServiceCenters[0].BranchNumber;t("input#appointment_branchcode").val(n),e.timeTable.$instance.data("branchcode",n);var a=decodeURIComponent(r("search")),s=decodeURIComponent(r("appointment"));null!=a&&null!=s&&(t("input#appointment_time").val(s),e.chooseTimeSlot.selectTimeSlot(t("input#appointment_branchcode").val(),t("input#appointment_time").val())),e.timeTable.getTimeTable(),e.timetableCarousel.reloadSlider(),e.promoBanner.getBanner(this.centers.ServiceCenters[0].BranchNumber),this.centers.ServiceCenters[0].Coffee?t("#appointment_free_coffee").show():t("#appointment_free_coffee").hide(),this.centers.ServiceCenters[0].Newspaper?t("#appointment_free_papers").show():t("#appointment_free_papers").hide(),this.centers.ServiceCenters[0].Wifi?t("#appointment_free_wifi").show():t("#appointment_free_wifi").hide(),this.centers.ServiceCenters[0].Bicycle?t("#appointment_bicycle").show():t("#appointment_bicycle").hide(),this.centers.ServiceCenters[0].HasChargingStation?t("#appointment_charging_station").show():t("#appointment_charging_station").hide(),console.log("with charge station"),this.centers.ServiceCenters[0].Coffee||this.centers.ServiceCenters[0].Newspaper||this.centers.ServiceCenters[0].Wifi||this.centers.ServiceCenters[0].Bicycle?t(".serviceCenter__facilities").show():t(".serviceCenter__facilities").hide(),t(".bookingsflow__appointmentForm.hidden").removeClass("hidden").show()}},a.prototype.savePrefilledData=function(){"bookingsflow"==this.$elm.data("type")&&(this.$elm.data("prefilled-branchcode",t("input#appointment_branchcode").val()),this.$elm.data("prefilled-appointment",t("input#appointment_time").val()),this.$elm.data("prefilled-searchterm",t("input#searchString").val()))},t(document).ready(function(){t(".searchCenters").length>0&&(e.searchCenters=new a(t(".searchCenters")))})}(window,window.jQuery,window.Mustache);;
