/* Minification failed. Returning unminified contents.
(301,85-91): run-time error JS1137: 'static' is a new reserved word and should not be used as an identifier: static
 */
/* js generated file - Copied by gulp */
/* WARNING: Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. */

$(function () {
    "use strict";

    //Catch all ajax errors
    $(document).ajaxError(function (event, response, settings, exc) {
        //event - contains the event object
        //response (xhr) - contains the XMLHttpRequest object
        //settings (options) - contains the options used in the AJAX request
        //exc - contains the JavaScript exception, if one occurred
        try {
            var httpService = LP.helpers.http;
            var httpStatusCodes = LP.enums.HttpStatusCodes;

            console.error(settings.type + " " + response.statusText + " " + response.status + " " + settings.url);
            var statusMsg = httpService.formatStatusCodeString(response.status, settings.url);
            event.request = settings.data || null;

            if (typeof Logger !== "undefined") {
                try {
                    switch (response.status) {
                        case httpStatusCodes.Forbidden:
                        case httpStatusCodes.Failure:
                        case httpStatusCodes.NotFound:
                            Logger.Error(statusMsg, null, event);
                            break;
                        default:
                            if (httpService.is4xxCode(response.status) || httpService.is5xxCode(response.status) || httpService.isExceptionalCode(response.status)) {
                                Logger.Error(statusMsg, null, event);
                            } else if (httpService.is3xxCode(response.status)) {
                                Logger.Warning(statusMsg, null, event);
                            }
                            break;
                    }
                } catch (ex) {
                }
            }
        } catch (err) {
        }

    });

    if (typeof antiForgeryToken !== 'undefined') {

        $(document).ajaxSend(function (event, jqxhr, settings) {
            if (settings.url === null || settings.url.toLowerCase().indexOf("conchatserver") === -1) {
                jqxhr.setRequestHeader("AntiForgeryToken", antiForgeryToken);
            }
        });

      //  $.ajaxSetup({
       //     headers: { "AntiForgeryToken": antiForgeryToken }
        //});
    }
});
/* js generated file - Copied by gulp */
/* WARNING: Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. */

(function () {
    "use strict";

    window.addEventListener("error", function (err) {
        if (typeof Logger === "undefined") return;

        try {
            Logger.Error(err.message, false, err);
        } catch (ex) {
        }
    });
}());
/* js generated file - Copied by gulp */
/* WARNING: Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. */

$(function () {
    "use strict";
    if (typeof (WebSettings) !== "undefined" && typeof (LP) !== "undefined") {

        try {

            //Apply for logged users only
            if (WebSettings.getUser().isLoggedIn) {

                //Set badge unread count
                if (LP.services && LP.services.ui && LP.services.ui.BadgeBubbleService) {
                    var bubbleService = new LP.services.ui.BadgeBubbleService();
                    if (bubbleService) {
                        bubbleService.setUnreadCount();
                    }
                }

                //Set tier level cookie
                if (LP.services && LP.services.SupportService) {
                    var supportService = new LP.services.SupportService();
                    if (supportService) {
                        supportService.enableTierLevelUpdateInSupportLink(".footer-service-center-link, .header-service-center-link");
                    }
                }
            }

            //Save UA Details
            var uaDetailsElementId = '#hiddenUserAgentDetails';
            if ($(uaDetailsElementId).length > 0) {
                $(uaDetailsElementId).val(typeof UserAgentHelper !== "undefined" && UserAgentHelper.userAgentDetails ? JSON.stringify(UserAgentHelper.userAgentDetails()) : "{}");
            }
        } catch (ex) {
            //Log exception
            if (typeof Logger !== "undefined") {
                try {
                    var errorMessage = "Error: " + ex.toString() +
                        "\r\n  name = " + ex.name +
                        "\r\n  message = " + ex.message +
                        "\r\n  stackTrace = " + ex.stack;
                    Logger.Error(errorMessage);
                } catch (ex) {
                    //Ignored.
                }
            }
        }
    }

});

/*
 * Overrides the localstorage browser check (alters isLocalStorageNameSupported() method) 
 * to solve the following a possible error when Safari (OS X or iOS) is in private browsing mode:
 * "QuotaExceededError: DOM Exception 22: An attempt was made to add something to storage that exceeded the quota."
 */
function isLocalStorageNameSupported() {
    "use strict";

    if (typeof localStorage === "object") {
        try {
            localStorage.setItem("localStorage", 1);
            localStorage.removeItem("localStorage");
        } catch (e) {
            Storage.prototype._setItem = Storage.prototype.setItem;
            Storage.prototype.setItem = function () { };
            console.warn("Your web browser does not support storing settings locally. In Safari, the most common cause of this is using \"Private Browsing Mode\". Some settings may not save or some features may not work properly for you.");
        }
    }
};
/* js generated file - Copied by gulp */
/* WARNING: Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. */

(function (currentPage) {
    "use strict";

    var module = {};

    //****************
    //Event 8
    //****************
    //'CompleteRegistration' event is executed when a registration is completed.
    /* A user can register in these flows:
        1. through registration page
        2. creating post a request
        3. sending a message to an expert
        4. before entering chat / voice */
    module.registrationCompleted = function (props) {
        props = props || {};

        var sharedProps = window.TagManagerHelper.importProperties([
            window.TagManagerHelper.PropertyGroups.category,
            window.TagManagerHelper.PropertyGroups.expert,
            window.TagManagerHelper.PropertyGroups.session
        ]);

        var request = {
            'event': 'CompleteRegistration'
        }

        /*
        Offline - RegistrationMethod: Email, SessionType: Offline
        Regular Registration - RegistrationMethod: Email\FB, SessionType: None
        Voice - RegistrationMethod: Email/FB, SessionType: Voice
        Chat - RegistrationMethod: Email/FB, SessionType: Chat
        Post Request - RegistrationMethod: Email, SessionType: PostRequest
        */

        window.TagManagerHelper.submitEvent(request, [props, sharedProps], { submitOnlyOnce: true });
    }

    window._currentPageView = (window._currentPageView ? $.extend(window._currentPageView, module) : module);
})(window._currentPageView);
/* js generated file - Copied by gulp */
/* WARNING: Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. */

$(window).load(function () {
    var imgDefer = document.getElementsByTagName('img');
    for (var i = 0; i < imgDefer.length; i++) {
        if (imgDefer[i].getAttribute('data-src')) {
            imgDefer[i].setAttribute('src', imgDefer[i].getAttribute('data-src'));
        }
    }
});;
/* js generated file - Copied by gulp */
/* WARNING: Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. */

$(function () {
    "use strict";

    var isSessionSelectorPage = $(".session-selector-loader").length > 0;
    if (!isSessionSelectorPage || window.sessionSelectorPageLoaded) {
        return;
    }
    window.sessionSelectorPageLoaded = true;

    var controls = {
        progressBar: $(".progress-bar"),
        progressText: $(".progress-text"),
        tip: $(".tip"),
        video: $(".loading-animation video"),
        staticImage: $(".loading-animation img"),
    }

    var progressBar = {
        progress: 0,
        step: 0.05,
        fasterStep: 0.1,
    };

    var progressStates = [
        "Preparing your page",
        "Collecting data",
        "Connecting with your advisor",
        "Almost done",
    ];

    var tips = [
        'Established in 1999, Kasamba is home to over 7 million people',
        'The first documented tarot deck was created in 15th - century in Italy',
        'The word "psychic" is derived from a Greek word that means "of the mind" and "soul"',
        'Our psychics have received more than 4 million 5 - star client reviews',
        'An extensive process is guaranteed to ensure that our psychics are the best fit for our clients',
        'The oldest psychic on Kasamba is still guiding hundreds of people every month',
        'Some of the most famous and influencing people in the world meet Kasamba psychics every day',
    ];
    var tipsBuffer = [];

    function selectNextTip() {
        if (tipsBuffer.length == 0) {
            cloneAndShuffleTips();
        }

        controls.tip.text(tipsBuffer.shift());
    }

    function cloneAndShuffleTips() {
        tipsBuffer = [].concat(tips);

        var currentIndex = tipsBuffer.length, temporaryValue, randomIndex;
        while (0 !== currentIndex) {
            randomIndex = Math.floor(Math.random() * currentIndex);
            currentIndex -= 1;
            temporaryValue = tipsBuffer[currentIndex];
            tipsBuffer[currentIndex] = tipsBuffer[randomIndex];
            tipsBuffer[randomIndex] = temporaryValue;
        }
    }

    function updateProgressBar() {
        progressBar.progress += progressBar.step;
        var progressPercent = Math.round(Math.atan(progressBar.progress) / (Math.PI / 2) * 100 * 1000) / 1000;

        if (progressPercent >= 80) {
            controls.progressText.text(progressStates[3]);
        } else if (progressPercent >= 60) {
            controls.progressText.text(progressStates[2]);
        } else if (progressPercent >= 40) {
            controls.progressText.text(progressStates[1]);
            progressBar.step = progressBar.fasterStep;
        } else {
            controls.progressText.text(progressStates[0]);
        }

        controls.progressBar.css("width", progressPercent + "%");
    }

    controls.progressBar.css("width", "0%");
    selectNextTip();

    var userAgent = navigator.userAgent.toLowerCase();
    var staticMode = {
        isEnabled: userAgent.indexOf('iphone') > -1 || userAgent.indexOf('ipad') > -1,
        progressPercent: 80,
        progressStateIndex: {
            initial: 2,
            static: 3,
        },
        redirectIntervalMs: 750,
    }

    if (staticMode.isEnabled) {
        controls.staticImage.show();
        controls.progressBar.animate({ "width": staticMode.progressPercent + "%" }, staticMode.redirectIntervalMs);
        controls.progressText.text(progressStates[staticMode.progressStateIndex.initial]);

        setTimeout(function () {
            controls.progressText.text(progressStates[staticMode.progressStateIndex.static]);
            window.executeSessionSelector();
        }, staticMode.redirectIntervalMs);

    } else {
        controls.video.show();
        setInterval(updateProgressBar, 100);
        setInterval(selectNextTip, 5000);

        setTimeout(window.executeSessionSelector, 0);
    }
});;
