var Alerts=function(){function e(){var n=this;this.cycleTimeForAllAlerts=0,this.$alertsBox=$("#alertsBox"),this.$alertsBoxBody=this.$alertsBox.find("ul"),this.forceAlertRefresh=function(){n.getAlerts(n.updateAlerts,n.updateGlobalEmergencyPopup)},this.alertsCheckedOnPageLoad=!1,this.getAlerts=function(r,o){var e=Cookies.get("_culture")?Cookies.get("_culture"):"";$.ajax({url:"/Alert/GetUpdatedAlerts?lang="+e,dataType:"json"}).done(function(e){e.alerts&&r(e.alerts);var t=!1;0!==e.emergencyAlertHash?($(".emergencyPopupNotification").show(),$("footer").addClass("pad45"),Cookies.get("emergencyPopup")!=e.emergencyAlertHash&&(Cookies.set("emergencyPopup",e.emergencyAlertHash,{expires:365,path:"/"}),o(),t=!0)):($("footer").removeClass("pad45"),$(".emergencyPopupNotification").hide(),Cookies.remove("emergencyPopup",{path:"/"})),n.alertsCheckedOnPageLoad||t&&"none"!=$(".emergencyPopupNotification").css("display")||"True"!=resources.FeatureSlideModal||$(document).trigger("displayFeatureModal"),n.alertsCheckedOnPageLoad=!0})},this.updateAlerts=function(e){var t,r,o,l,s,a=n.$alertsBox.data("easyTicker"),i=(a&&a.stop(),n);n.$alertsBoxBody.empty(),0<e.length?"true"!=resources.UseAlertBellIcon?(t=0,r=Cookies.get("_culture"),o=Cookies.get("_region")?Cookies.get("_region"):"ALL",l=-1==(l=null!=r?r.toLowerCase():"en").indexOf("-")?l:l.split("-")[0],s='""',$.each(e,function(){var e;(!this.filterRegions||"ALL"==o||0<=this.regions.indexOf(o))&&("fr"===l?e=this.messages.messageLang2:"es"===l&&(e=this.messages.messageLang3),(e=(e=null!=e&&""!=e.message?e:this.messages.messageLang1).message)&&(s=this.highImportance?"highImportanceAlert":"","true"===resources.FloodgateAlertBarAsLink?i.$alertsBoxBody.append('<li id="alertsLi'+t+'" data-type="'+s+'"><a href="/List/Alerts">'+e+"</a></li>"):i.$alertsBoxBody.append('<li id="alertsLi'+t+'" data-type="'+s+'">'+e+"</li>")),t++)}),n.splitLongAlerts(),n.cycleTimeForAllAlerts=i.$alertsBoxBody[0].childElementCount*globalVars.tickerInterval,n.cycleTimeForAllAlerts>n.currentFetchAlertsFreqTime&&(clearInterval(n.fetchAlertsInterval),n.currentFetchAlertsFreqTime=n.cycleTimeForAllAlerts+1e3,n.fetchAlertsInterval=setInterval(function(){n.forceAlertRefresh()},n.currentFetchAlertsFreqTime)),$("#emptyAlertLi").remove(),i.toggleAlertColor(),1<i.$alertsBoxBody.children().length&&a?a.start():i.$alertsBoxBody.append('<li id="emptyAlertLi">&nbsp;</li>')):($(".alertIcon").attr("title",resources.Alerts),$(".alertIcon .dot").show()):"true"!=resources.UseAlertBellIcon?(i.$alertsBoxBody.append('<li id="emptyAlertLi">&nbsp;</li>'),i.toggleAlertColor()):($(".alertIcon").attr("title",resources.NoAlert),$(".alertIcon .dot").hide())},this.updateGlobalEmergencyPopup=function(){var e=Cookies.get("_culture")?Cookies.get("_culture"):"";$.ajax({url:"/Alert/GetEmergencyAlert?lang="+e,dataType:"json"}).done(function(e){$(".emergencyPopupNotification").attr("data-alert",e.content),0<e.content.length&&0==$(".modal.in").length?n.showPopup(e.content):"True"==resources.FeatureSlideModal&&$(document).trigger("displayFeatureModal")})},this.showPopup=function(e){bootbox.dialog({title:'<i style="padding-right: 5px;" class="far fa-exclamation-triangle"></i> '+resources.EmergencyAlertPopUp.toUpperCase(),onEscape:!0,className:"emergencyAlertModal",message:e})},this.toggleAlertColor=function(){"highImportanceAlert"==n.$alertsBoxBody.children().first().data("type")?$(".scrollRow").addClass("highImportanceAlert"):$(".scrollRow").removeClass("highImportanceAlert")},this.startEasyTicker()}return e.prototype.splitLongAlerts=function(){var n=this;this.$alertsBoxBody.children().each(function(t){var r=n.$alertsBox.get(0).clientHeight,o=$(this).attr("data-type"),e=$(this).text(),l="",e=e.split(" "),s=[],a="",i=0;e.forEach(function(e){a+=a?" "+e:e,$(".tempAlert").html(a),$(".tempAlert").height()>r&&(a=a.substring(0,a.lastIndexOf(" ")),s.push({key:i,value:a}),a=e,i++)}),s.push({key:i,value:a}),s.forEach(function(e){0<e.value.length&&(l+='<li id="alertsLi'+t+"_"+e.key+'" data-type="'+o+'">'+e.value+"</li>")}),$(this).replaceWith(replaceUrlsWithLinks(l))})},e.prototype.hashCode=function(e){for(var t=0,r=0;r<e.length;r++)t=~~((t<<5)-t+e.charCodeAt(r));return t},e.prototype.startEasyTicker=function(){$(".siteWideAlerts").easyTicker({direction:"up",easing:"swing",speed:"slow",interval:globalVars.tickerInterval,height:"auto",visible:1,mousePause:1,controls:{up:"",down:"",toggle:"",playText:"Play",stopText:"Stop"}}),$(".siteWideAlerts").on("contentChanged",this.toggleAlertColor)},e}();$(document).ready(function(){var r=new Alerts;r.forceAlertRefresh(),r.currentFetchAlertsFreqTime=resources.AlertRefreshInterval?parseInt(resources.AlertRefreshInterval):6e4,r.fetchAlertsInterval=setInterval(function(){r.forceAlertRefresh()},r.currentFetchAlertsFreqTime),$(".emergencyPopupNotification").on("click",function(e){$(".emergencyPopupNotification").attr("data-alert")?r.showPopup($(".emergencyPopupNotification").attr("data-alert")):r.updateGlobalEmergencyPopup()}),$(window).on("regionChanged orientationchange",function(e,t){r.forceAlertRefresh()}),Array.from(document.querySelectorAll("[data-single-submit-form]")).forEach(function(e){var t=e.querySelector("[data-single-submit-btn]");t&&e.addEventListener("submit",function(){$(e).validate().form()?(t.disabled=!0,t.classList.add("disabled")):$("html, body").animate({scrollTop:0},"slow")})})});
