var personalizationManager = null; window.sfCorrelationId = Date.now().toString(36) + Math.random().toString(36).substring(2), function () { "use strict"; var PersonalizationManager = function () { this.personalizedContainers = [], this.personalizedContent = [], this._personalizedContentLoadedHandlers = [] }; if (PersonalizationManager.prototype = { initialize: function () { var e = this; e.IEVersion = this.detectIE(), this.loadPersonalizableContainers(), this.personalizedContainers.length > 0 && this.loadPersonalizedContent() }, loadPersonalizableContainers: function () { this.personalizedContainers = this.getScriptElementsWithAttribute("data-sf-pers-id") }, loadPersonalizedContent: function () { for (var firstPersonalizedContainer = this.personalizedContainers[0], pageNodeId = firstPersonalizedContainer.getAttribute("data-sf-pers-page-node-id"), pageDataId = firstPersonalizedContainer.getAttribute("data-sf-pers-page-data-id"), pageNodeKey = firstPersonalizedContainer.getAttribute("data-sf-pers-page-node-key"), appPath = firstPersonalizedContainer.getAttribute("data-sf-app-path"), sfCulture = firstPersonalizedContainer.getAttribute("data-sf-culture"), loadedScripts = firstPersonalizedContainer.getAttribute("data-sf-loaded-scripts"), pageUrl = window.location.toString(), controls = [], i = 0; i < this.personalizedContainers.length; i++) { var raiseEventsFlag = 0; "True" === this.personalizedContainers[i].getAttribute("data-sf-pers-raise-events") && (raiseEventsFlag = 1), controls.push(this.personalizedContainers[i].getAttribute("data-sf-pers-id") + "_" + raiseEventsFlag) } var that = this, referrer = document.referrer, url = this.getServiceUrl(appPath, pageNodeId, pageDataId, pageNodeKey, pageUrl, controls); that.sf_loaded_scripts = loadedScripts ? eval(loadedScripts) : []; var xmlHttp = new XMLHttpRequest; xmlHttp.open("GET", url, !0), xmlHttp.setRequestHeader("Content-type", "application/json; charset=utf-8"), xmlHttp.setRequestHeader("Accept", "application/json"), referrer && referrer.length > 0 ? xmlHttp.setRequestHeader("SF_URL_REFERER", referrer) : xmlHttp.setRequestHeader("SF_NO_URL_REFERER", "true"), sfCulture && xmlHttp.setRequestHeader("SF_UI_CULTURE", sfCulture), xmlHttp.onreadystatechange = function () { 4 === xmlHttp.readyState && 200 === xmlHttp.status && that.evalContentToPageContext(xmlHttp.responseText) }, xmlHttp.send(null) }, evalContentToPageContext: function (response) { var container, that = this, responseItems = eval(response), initialResponseItems = eval(response); this.initializeContainer(0, responseItems, function () { for (var e = [], t = 0; t < that.personalizedContainers.length; t++) { container = that.personalizedContainers[t]; for (var n = 0; n < container.bottomScripts.length; n++)e.push(container.bottomScripts[n]) } that.appendBottomScripts(0, e, function () { that.onPersonalizedContentLoaded({ response: initialResponseItems }) }) }) }, appendBottomScripts: function (e, t, n) { var i = this; if (t.length > e) { var a = t[e]; a.onload = function () { i.appendBottomScripts(e + 1, t, n) }, document.body.appendChild(a) } else n() }, initializeContainer: function (e, t, n) { var i = this; if (this.personalizedContainers.length > e) for (var a, r, o = this.personalizedContainers[e], s = o.getAttribute("data-sf-pers-id"), d = 0; d < t.length; d++)s === (r = t[d]).ControlId && ((a = document.createElement("div")).innerHTML = r.Content, o.bottomScripts = [], this.copyNode(a, null, o, function () { o.parentNode.removeChild(o), t.splice(d, 1), i.initializeContainer(e + 1, t, n) })); else n() }, copyNode: function (e, t, n, i) { if (e) { var a, r, o = this; e.tagName ? (!1 !== o.IEVersion && (10 == o.IEVersion || 11 == o.IEVersion) && "TEXTAREA" == e.tagName && e.attributes.placeholder && e.attributes.placeholder.value === e.innerHTML && (e.innerHTML = ""), a = this.isDescendantOfSvg(e) ? document.createElementNS("http://www.w3.org/2000/svg", e.tagName) : document.createElement(e.tagName), this.copyAttributes(e, a), r = this.determineNextNodes(e, t, a), "SCRIPT" === a.tagName && a.attributes.src ? o.contains(o.sf_loaded_scripts, a.attributes.src.value) ? this.copyNode(r.source, r.parent, n, i) : a.attributes["data-sf-section"] && a.attributes["data-sf-section"].value && "bottom" === a.attributes["data-sf-section"].value.toLowerCase() ? (a.removeAttribute("data-sf-section"), n.bottomScripts.push(a), o.copyNode(r.source, r.parent, n, i)) : (a.removeAttribute("data-sf-section"), a.onload = function () { o.copyNode(r.source, r.parent, n, i) }, this.addNode(a, t, n)) : (this.addNode(a, t, n), this.copyNode(r.source, r.parent, n, i))) : (r = this.determineNextNodes(e, t), this.addNode(e, t, n, !0), this.copyNode(r.source, r.parent, n, i)) } else i() }, addNode: function (e, t, n, i) { e = i ? e.cloneNode(!0) : e, t ? t.appendChild(e) : n.parentNode.insertBefore(e, n) }, copyAttributes: function (e, t) { for (var n, i = 0; i < e.attributes.length; i++)n = e.attributes[i], t.setAttribute(n.name, n.value) }, contains: function (e, t) { for (var n = 0; n < e.length; n++)if (e[n] === t) return !0; return !1 }, determineNextNodes: function (e, t, n) { var i, a = t; if (e.firstChild) i = e.firstChild, a = n; else if (e.nextSibling) i = e.nextSibling; else for (t = e.parentNode, a = null !== a ? a.parentNode : null; t;) { if (t.nextSibling) { i = t.nextSibling; break } t = t.parentNode, a = null !== a ? a.parentNode : null } return { source: i, parent: a } }, getServiceUrl: function (e, t, n, i, a, r) { e = e || "/"; var o = window.location.protocol + "//" + window.location.hostname + ":" + window.location.port + e + "RestApi/personalizations/render"; return o + ("?pageNodeId=" + t + "&pageDataId=" + n + "&pageNodeKey=" + i + "&url=" + encodeURIComponent(a) + "&controls=" + r.join(",") + "&correlationId=" + window.sfCorrelationId) }, getScriptElementsWithAttribute: function (e) { var t = [], n = document.scripts; n || (n = document.getElementsByTagName("script")); for (var i = 0, a = n.length; i < a; i++)null !== n[i].getAttribute(e) && t.push(n[i]); return t }, addPersonalizedContentLoaded: function (e) { this._personalizedContentLoadedHandlers.push(e) }, onPersonalizedContentLoaded: function (e) { for (var t = 0; t < this._personalizedContentLoadedHandlers.length; t++)this._personalizedContentLoadedHandlers[t](e) }, detectIE: function () { var e = window.navigator.userAgent, t = e.indexOf("MSIE "); if (t > 0) return parseInt(e.substring(t + 5, e.indexOf(".", t)), 10); if (e.indexOf("Trident/") > 0) { var n = e.indexOf("rv:"); return parseInt(e.substring(n + 3, e.indexOf(".", n)), 10) } var i = e.indexOf("Edge/"); return i > 0 && parseInt(e.substring(i + 5, e.indexOf(".", i)), 10) }, isDescendantOfSvg: function (e) { for (; e;) { if ("svg" === e.tagName) return !0; e = e.parentNode } return !1 } }, personalizationManager = new PersonalizationManager, window.jQuery) jQuery(document).ready(function () { personalizationManager.initialize() }); else { var initialized = !1; document.addEventListener && document.addEventListener("DOMContentLoaded", function (e) { initialized || (initialized = !0, personalizationManager.initialize()) }), window.onload = function () { initialized || (initialized = !0, personalizationManager.initialize()) } } }();