/* Minification failed. Returning unminified contents.
(2,11): run-time error CSS1031: Expected selector, found '='
(2,11): run-time error CSS1025: Expected comma or open brace, found '='
 */
/// <reference path ="../Scripts/typings/jqueryui/jqueryui.d.ts"/> 
var Login = /** @class */ (function () {
    function Login(authenticationLoginPath) {
        this.authenticationLoginPath = authenticationLoginPath;
    }
    Login.prototype.handleSuccess = function (data) {
        if (data.result == "successlogin") {
            location.replace(data.returnUrl);
        }
        else {
            $("#leftSlideDiv").show();
            $("#rightSlideDiv").hide();
            $('#rightSlideDiv').html(data);
            $("#leftSlideDiv").effect("slide", { "direction": "left", "mode": "hide" }, 500);
            $("#rightSlideDiv").effect("slide", { "direction": "right", "mode": "show" }, 500);
            var login = new Login(this.authenticationLoginPath);
            login.addClickEventListeners();
            setTimeout(function () { $("#FirstCharacter").focus(); }, 600);
        }
    };
    Login.prototype.disableButton = function (button, message) {
        $(button).attr("disabled", "disabled");
        $(button).html('<i class="fa fa-refresh fa-spin fa fa-fw"></i> ' + message);
    };
    Login.prototype.loadLoginSection = function (sectionName) {
        var sectionUrl = window.location.href;
        switch (sectionName) {
            case "ForgotenPassword":
                sectionUrl = sectionUrl.replace("Authentication/Login", "LostOrForgotten/RegisterLost");
                break;
            case "UserPassword":
                sectionUrl = sectionUrl.replace("Authentication/Login", "Authentication/UserPassword");
                break;
            case "RegistrationOptions":
                sectionUrl = sectionUrl.replace("Authentication/Login", "Registration/RegistrationOptions");
                break;
            case "TwoFactorSetup":
                sectionUrl = sectionUrl.replace("Authentication/Login", "Authentication/TwoFactorSetup");
                break;
            case "TwoFactorOptions":
                sectionUrl = sectionUrl.replace("Authentication/Login", "Authentication/TwoFactorOptions");
                break;
            case "TwoFactorVoiceOption":
                sectionUrl = sectionUrl.replace("Authentication/Login", "Authentication/TwoFactorAuthenticationCodeDeliveryOptions?type=Voice&");
                break;
            case "TwoFactorTextOption":
                sectionUrl = sectionUrl.replace("Authentication/Login", "Authentication/TwoFactorAuthenticationCodeDeliveryOptions?type=Text&");
                break;
            //case "TwoFactorSetupMultipleNumbers": // #ChooseFromExistingOrAddNew
            //    sectionUrl = sectionUrl.replace("Authentication/Login", "Authentication/TwoFactorSetupMultipleNumbers");
            //    break;
            //case "TwoFactorExistingNumbersOption":
            //    sectionUrl = sectionUrl.replace("Authentication/Login", "Authentication/TwoFactorExistingNumbers");
            //case "TwoFactorNewNumberOption":
            //        sectionUrl = sectionUrl.replace("Authentication/Login", "Authentication/TwoFactorAuthenticationNewTelephone");
            default:
                sectionUrl = sectionUrl.replace("Authentication/Login", "/");
        }
        var handleSuccessFunc = this.handleSuccess;
        var path = location.pathname;
        var isAuthenticationPath = path.search("Authentication/Login") > 0;
        if (isAuthenticationPath) {
            $.get(sectionUrl, function (data) {
                handleSuccessFunc(data);
            });
        }
        else {
            window.location.href = this.authenticationLoginPath;
        }
    };
    Login.prototype.submitForm = function (button, message) {
        this.disableButton(button, message);
        $(button).submit();
    };
    Login.prototype.callLoginSection = function (button, message, section) {
        this.disableButton(button, "Loading...");
        this.loadLoginSection(section);
    };
    Login.prototype.register = function (button, message) {
        var sectionUrl = window.location.href;
        var buttonText = $(button).text();
        this.disableButton(button, message);
        if (buttonText.toUpperCase() === "CORPORATE") {
            window.location.href = sectionUrl.replace("Authentication/Login", "Registration?type=corporate&");
        }
        else {
            window.location.href = sectionUrl.replace("Authentication/Login", "Registration?type=personal&");
        }
    };
    Login.prototype.addClickEventListeners = function () {
        var _this = this;
        var context = this;
        var forgotPasswordBtns = document.getElementsByName("forgot-password");
        var i;
        if (forgotPasswordBtns) {
            for (i = 0; i < forgotPasswordBtns.length; ++i) {
                forgotPasswordBtns[i].removeEventListener("click", null);
                forgotPasswordBtns[i].addEventListener("click", function (e) { return _this.callLoginSection(e.currentTarget, "Loading...", "ForgotenPassword"); });
            }
        }
        $(".login-password").each(function () {
            var self = $(this);
            self.unbind("click");
            self.click(function (e) { return context.submitForm(e.currentTarget, "LOGGING IN..."); });
        });
        $(".login-memorable").each(function () {
            var self = $(this);
            self.unbind("click");
            self.click(function (e) { return context.submitForm(e.currentTarget, "LOGGING IN..."); });
        });
        $(".js-two-factor").each(function () {
            var self = $(this);
            self.unbind("click");
            self.click(function (e) { return context.submitForm(e.currentTarget, "LOGGING IN..."); });
        });
        $(".two-factor-setup").each(function () {
            var self = $(this);
            self.unbind("click");
            self.click(function (e) { return context.submitForm(e.currentTarget, "LOGGING IN..."); });
        });
        $(".submit-change").each(function () {
            var self = $(this);
            self.unbind("click");
            self.click(function (e) { return context.submitForm(e.currentTarget, "RESETTING..."); });
        });
        $(".js-multiple-numbers-voice").each(function () {
            var self = $(this);
            self.unbind("click");
            self.click(function (e) { return context.submitForm(e.currentTarget, "LOADING..."); });
        });
        $(".js-new-telephone-voice").each(function () {
            var self = $(this);
            self.unbind("click");
            self.click(function (e) { return context.submitForm(e.currentTarget, "LOADING..."); });
        });
        $(".js-new-mobile-text").each(function () {
            var self = $(this);
            self.unbind("click");
            self.click(function (e) { return context.submitForm(e.currentTarget, "LOADING..."); });
        });
        var userPasswordBtns = document.getElementsByName("user-password");
        if (userPasswordBtns) {
            for (i = 0; i < userPasswordBtns.length; ++i) {
                userPasswordBtns[i].removeEventListener("click", null);
                userPasswordBtns[i].addEventListener("click", function (e) { return _this.callLoginSection(e.currentTarget, "Loading...", "UserPassword"); });
            }
        }
        var registrationOptionBtns = document.getElementsByName("registration-options");
        if (registrationOptionBtns) {
            for (i = 0; i < registrationOptionBtns.length; ++i) {
                registrationOptionBtns[i].removeEventListener("click", null);
                registrationOptionBtns[i].addEventListener("click", function (e) { return _this.callLoginSection(e.currentTarget, "LOADING...", "RegistrationOptions"); });
            }
        }
        var twofaVoiceOption = document.getElementById("voice-option");
        if (twofaVoiceOption) {
            twofaVoiceOption.removeEventListener("click", null);
            twofaVoiceOption.addEventListener("click", function (e) { return _this.callLoginSection(e.currentTarget, "LOADING...", "TwoFactorVoiceOption"); });
        }
        var twofaVoiceNewOption = document.getElementById("new-phone-option");
        if (twofaVoiceNewOption) {
            twofaVoiceNewOption.removeEventListener("click", null);
            twofaVoiceNewOption.addEventListener("click", function (e) { return _this.callLoginSection(e.currentTarget, "LOADING...", "TwoFactorNewNumberOption"); });
        }
        var twofaVoiceExistingOption = document.getElementById("existing-phone-option");
        if (twofaVoiceExistingOption) {
            twofaVoiceExistingOption.removeEventListener("click", null);
            twofaVoiceExistingOption.addEventListener("click", function (e) { return _this.callLoginSection(e.currentTarget, "LOADING...", "TwoFactorExistingNumbersOption"); });
        }
        var twoFaTextOption = document.getElementById("text-option");
        if (twoFaTextOption) {
            twoFaTextOption.removeEventListener("click", null);
            twoFaTextOption.addEventListener("click", function (e) { return _this.callLoginSection(e.currentTarget, "LOADING...", "TwoFactorTextOption"); });
        }
        var useExistingMobileLink = document.getElementById("use-existing-number-text");
        if (useExistingMobileLink) {
            useExistingMobileLink.removeEventListener("click", null);
            useExistingMobileLink.addEventListener("click", function (e) { return _this.callLoginSection(e.currentTarget, "LOADING...", "TwoFactorTextExistingOption"); });
        }
        var registerPersonalBtn = document.getElementById("register-personal");
        if (registerPersonalBtn) {
            registerPersonalBtn.removeEventListener("click", null);
            registerPersonalBtn.addEventListener("click", function (e) { return _this.register(e.currentTarget, "Loading..."); });
        }
        var registerCorpBtn = document.getElementById("register-corporate");
        if (registerCorpBtn) {
            registerCorpBtn.removeEventListener("click", null);
            registerCorpBtn.addEventListener("click", function (e) { return _this.register(e.currentTarget, "Loading..."); });
        }
        $('.enterClickable').each(function () {
            $(this).find('input').keypress(function (e) {
                if (e.which == 10 || e.which == 13) {
                    $(this.form).find(".enterButtonClickable").focus().click();
                }
            });
        });
        $($('.memoriable-info-char[name="FirstCharacter"]')[0]).keyup(function (e) {
            if (e.keyCode !== 8 && e.keyCode !== 46 && e.keyCode !== 16 && e.keyCode !== 9) {
                $($('.memoriable-info-char[name="SecondCharacter"]')[0]).focus();
            }
        });
        var self = this;
        $(".chk-use-existing").click(function () {
            var mobileNumberInput = $(".mobile-number-input");
            var countryCodeInput = $(".country-code-input");
            if ($(this).is(":checked")) {
                var existingMobileNumber = $(".existing-mobile-hidden").val();
                var existingCountryCodeNumber = $(".existing-country-code-hidden").val();
                mobileNumberInput.val(existingMobileNumber);
                countryCodeInput.val(existingCountryCodeNumber);
                self.DisableCountryCodeMobileNumberInputs(mobileNumberInput, countryCodeInput);
            }
            else {
                self.EnableCountryCodeMobileNumberInputs(mobileNumberInput, countryCodeInput);
            }
        });
        /*As readonly does not work with select tags
          $(".country-code-input") select tag has been disabled and
          enabled again on form submit to send the selected value over post request*/
    };
    Login.prototype.DisableCountryCodeMobileNumberInputs = function (mobileNumberInput, countryCodeInput) {
        countryCodeInput.prop("disabled", "disabled");
        mobileNumberInput.prop("readonly", "readonly");
    };
    Login.prototype.EnableCountryCodeMobileNumberInputs = function (mobileNumberInput, countryCodeInput) {
        countryCodeInput.removeAttr("disabled");
        mobileNumberInput.removeAttr("readonly");
    };
    return Login;
}());
//# sourceMappingURL=login.js.map
