/* Minification failed. Returning unminified contents.
(1,1): run-time error CSS1019: Unexpected token, found '('
(1,11): run-time error CSS1031: Expected selector, found '('
(1,11): run-time error CSS1025: Expected comma or open brace, found '('
(331,2): run-time error CSS1019: Unexpected token, found '('
(331,9): run-time error CSS1031: Expected selector, found ')'
(331,9): run-time error CSS1025: Expected comma or open brace, found ')'
 */
(function ($) {
    function Login() {
        var $this = this, formLogin;
        function initializeForm() {
            formLogin = new Global.FormValidationReset('form');
            $('#btnsubmit').click(function () {
                if ($('form').valid()) {
                    if (!$("#chk1").is(':checked')) {
                        $('.clsterm').show();
                        return false;
                    }
                    $("#loadingElement").show();
                }
                else { return true; }
            });

            $(".login-btn").click(function () {
                $(".register-btn").removeClass("active");
                $(".login-btn").addClass("active");
                $("#divSignUp").hide();
                $("#divSignIn").show();
                //$("#divLoginState2").hide();
            });
            $(".register-btn").click(function () {
                $(".login-btn").removeClass("active");
                $(".register-btn").addClass("active");
                $("#divSignUp").show();
                $("#divSignIn").hide();
                //$("#divLoginState2").hide();
            });

            $("#btnregisterNow").click(function () {
                $(".login-btn").removeClass("active");
                $(".register-btn").addClass("active");
                $("#divSignUp").show();
                $("#divSignIn").hide();
                $("#divLoginState2").hide();
            });

            //$(document).on("change", "#txtUserEmailId", function () {
            //    alert('');
            //});
            //$("#txtUserEmailId").change(function () {
            //    $('#btnSignIn').click();
            //});

            $('#txtUserEmailId').keypress(function (e) {
                if (e.keyCode == 13) {
                    e.preventDefault();
                    $('#btnSignIn').click();

                }
            });

            $('#btnSignInBack').click(function (e) {
                $(".signin").show();
                $(".signin2").hide();
                $(".signin2factorresendemail").hide();
                $(".signinemail").removeAttr('disabled');
            });

            $('#btnSignInBackn2factorBack').click(function (e) {
                $("#divLoginState2").show();
                $("#divLogin2factor").hide();
                $(".signin").show();
                $(".signin2").hide();
                $(".signin2factorresendemail").hide();
                $(".signinemail").removeAttr('disabled');
            });



            $('#btnSignIn').click(function (e) {
                // e.preventDefault();

                $("#divloginMsg").hide();
                if ($('#frm-signin-second').valid()) {
                    if ($("#txtUserEmailId").val() != "") {
                        $("#loadingElement").show();
                        $.post(domain + 'CompanySignUp/Login?Id=' + $("#txtUserEmailId").val(), function (result) {
                            $("#loadingElement").hide();
                            if (result.code == "notexist") {
                                $("#divMsg").show();
                                $("#divMsg").html("Invalid email");
                                $(".clsVerification").hide();
                            } else if (result.code == "locked") {
                                $("#divMsg").show();
                                $("#divMsg").html("Your account is currently locked, please contact your administrator or try again later");
                                $(".clsVerification").hide();
                            }
                            else if (result.code == "notverified") {
                                $("#divMsg").show();
                                $("#divMsg").html("Your account is not verified. Please use below link to resend account verification email.");
                                $(".clsVerification").show();
                                $("#vlink").attr('href', domain + 'CompanySignUp/ResendVerificationEmail?EmailId=' + $("#txtUserEmailId").val());
                            }
                            else if (result.code == "notactive") {
                                $("#divMsg").show();
                                $("#divMsg").html("Your account has been deactivated, please contact to admin.");
                            }
                            else {
                                $("#divMsg").hide();
                                $(".signin").hide();
                                $(".signin2").show();
                                $("#txtEmailId").val($("#txtUserEmailId").val());
                                $(".signinemail").attr('disabled', 'disabled');

                                $("#UserId").val(result.userid);
                                $("#CompanyId").val(result.companyid);
                                $("#TotalCompany").val(result.companycount);
                                if (result.companyref > 0) {
                                    $("#divcompanyref").hide();
                                    $("#CompanyRef").val(result.companyref);
                                }


                            }
                        });
                    }
                    else {
                        $("#divMsg").show();
                        $("#divMsg").html("Please enter email-id");
                    }

                }

            });

            var pageType = $("#PageType").val();
            if (pageType == 2) {
                $(".login-btn").removeClass("active");
                $(".register-btn").addClass("active");
                $("#divSignUp").show();
                $("#divSignIn").hide();
                $("#divLoginState2").hide();
            }


            $('#btnLogin').click(function () {
                // alert('');
                if ($('#frm-signin-second').valid()) {
                    //alert('cal')

                    if ($("#CompanyRef").val() == "") {
                        $("#divloginMsg").show();
                        $("#divloginMsg").html("Please enter company reference No.");
                    }
                    if ($("#txtloginpassword").val() == "") {
                        $("#txtloginpassword").val('');
                        $("#divloginMsg").show();
                        $("#divloginMsg").html("Please enter password");
                    }
                    else {
                        $("#loadingElement").show();
                        $.post(domain + 'CompanySignUp/UserLogin', { companyRef: $("#CompanyRef").val(), userId: $("#UserId").val(), password: $("#txtloginpassword").val() }, function (result) {
                            $("#loadingElement").hide();

                            if (result.result == 10 && result.errorCode == "invalidpassword") {
                                $("#txtloginpassword").val('');
                                $("#divloginMsg").show();
                                $("#divloginMsg").html("Invalid password");
                            } else if (result.result == 10 && result.errorCode == "locked") {
                                $("#txtloginpassword").val('');
                                $("#divloginMsg").show();
                                $("#divloginMsg").html("Your account is currently locked, please contact your administrator or try again later");
                            }
                            else if (result.result == 0 && result.errorCode == "planexpire") {
                                $("#txtloginpassword").val('');
                                $("#divloginMsg").hide();
                                $("#divloginMsg").show();
                                $("#divloginMsg").html("Your subscription plan has been expire.");
                                // $(".clsVerification").hide();
                            } else if (result.result == 0 && result.errorCode == "2factor") {
                                $("#twofactorUserId").val(result.userid);
                                $("#twofactorCompanyId").val(result.companyid);
                                $("#twofactorprovider").val(result.provider);

                                if (parseInt(result.provider) == 1) {
                                    $("#authprovidertitle").html("Please verify google auth TOTP");
                                } else if (parseInt(result.provider) == 2) {
                                    $("#authprovidertitle").html("Please verify Email OTP");
                                    $(".signin2factorresendemail").show();
                                } else {
                                    $("#authprovidertitle").html("Please verify SMS OTP");
                                }
                                $("#divLoginState2").hide();
                                $("#divloginMsg2factor").hide();
                                $("#divLogin2factor").show();
                            }

                            else if (result.result == 0) {
                                $("#txtloginpassword").val('');
                                $("#divloginMsg").show();
                                $("#divloginMsg").html("Invalid password");
                                // $(".clsVerification").hide();
                            }

                            else {
                                window.location.href = domain + "Company/Dashboard";
                            }
                        });
                    }
                }

            });

            $('#btnLogin2factor').click(function () {
                if ($('#frm-signin-2factor').valid()) {

                    if ($("#txtlogintotp").val() == "") {
                        $("#txtlogintotp").val('');
                        $("#divloginMsg2factor").show();
                        $("#divloginMsg2factor").html("Please enter TOTP");
                    }
                    else {
                        $("#loadingElement").show();
                        $("#divloginMsg2factor").hide();
                        $("#div2factorMsgsucess").hide();
                        $.post(domain + 'CompanySignUp/TwofactorLogin', { provider: $("#twofactorprovider").val(), companyId: $("#twofactorCompanyId").val(), userId: $("#twofactorUserId").val(), totp: $("#txtlogintotp").val() }, function (result) {
                            $("#loadingElement").hide();

                            if (result.result == 0 && result.errorCode == "invalidtotp") {
                                $("#txtlogintotp").val('');
                                $("#divloginMsg2factor").show();
                                $("#divloginMsg2factor").html(result.message);
                            } else if (result.result == 0 && result.errorCode == "googleAuthNotEnable") {
                                $("#txtlogintotp").val('');
                                $("#divloginMsg2factor").show();
                                $("#divloginMsg2factor").html("Google Auth not Enable");
                            }
                            else if (result.result == 0) {
                                $("#txtlogintotp").val('');
                                $("#divloginMsg2factor").show();
                                $("#divloginMsg2factor").html("Invalid TOTP");
                            }
                            else {
                                window.location.href = domain + "Company/Dashboard";
                            }
                        });
                    }
                }

            });

            $('#btnresendemail').click(function () {
                
                        $("#loadingElement").show();
                $("#divloginMsg2factor").hide();
                $("#div2factorMsgsucess").hide();
                        $.post(domain + 'CompanySignUp/ResendEmailOTP', { provider: $("#twofactorprovider").val(), companyId: $("#twofactorCompanyId").val(), userId: $("#twofactorUserId").val(), totp: $("#txtlogintotp").val() }, function (result) {
                            $("#loadingElement").hide();

                            if (result.result == 0 && result.errorCode == "notsend") {
                                $("#txtlogintotp").val('');
                                $("#divloginMsg2factor").show();
                                $("#divloginMsg2factor").html("Please try again !");
                            } else if (result.result == 0) {
                                $("#txtlogintotp").val('');
                                $("#div2factorMsgsucess").show();
                                $("#div2factorMsgsucess").html("OTP sent to email!");
                            }
                        });
                    
                

            });

            //$('#btnLogin2factor').click(function () {
            //    if ($('#frm-signin-2factor').valid()) {

            //        if ($("#txtlogintotp").val() == "") {
            //            $("#txtlogintotp").val('');
            //            $("#divloginMsg2factor").show();
            //            $("#divloginMsg2factor").html("Please enter TOTP");
            //        }
            //        else {
            //            $("#loadingElement").show();
            //            $("#divloginMsg2factor").hide();
            //            $.post(domain + 'CompanySignUp/TwofactorLogin', { provider: $("#twofactorprovider").val(), companyId: $("#twofactorCompanyId").val(), userId: $("#twofactorUserId").val(), totp: $("#txtlogintotp").val() }, function (result) {
            //                $("#loadingElement").hide();

            //                if (result.result == 0 && result.errorCode == "invalidtotp") {
            //                    $("#txtlogintotp").val('');
            //                    $("#divloginMsg2factor").show();
            //                    $("#divloginMsg2factor").html(result.message);
            //                } else if (result.result == 0 && result.errorCode == "googleAuthNotEnable") {
            //                    $("#txtlogintotp").val('');
            //                    $("#divloginMsg2factor").show();
            //                    $("#divloginMsg2factor").html("Google Auth not Enable");
            //                }
            //                else if (result.result == 0) {
            //                    $("#txtlogintotp").val('');
            //                    $("#divloginMsg2factor").show();
            //                    $("#divloginMsg2factor").html("Invalid TOTP");
            //                }

            //                else {
            //                    window.location.href = domain + "Company/Dashboard";
            //                }
            //            });
            //        }
            //    }

            //});

            $('#frm-signin-second').keypress(function (e) {
                if (e.keyCode == 13) {
                    $('#btnLogin').click();
                }
            });

            //$('#txtUserEmailId').keypress(function (e) {
            //    alert('');
            //    if (e.keyCode == 13) {
            //        $('#btnSignIn').click();
            //    }
            //});

        }

        $this.init = function () {
            initializeForm();

        };
    }

    $(function () {
        var self = new Login();
        self.init();
    });
}(jQuery));
