﻿$(document).ready(function () {
    $("#UserId").keypress(function (e) {
        var key = e.which;
        if (key === 13) {
            $("#Password").focus();
        }
    });
    $("#Password").keypress(function (e) {
        var key = e.which;
        if (key === 13) {
            $("#btnLogin").click();
        }
    });
    $("#btnLogin").off("click");
    $('#btnLogin').on("click", function (e) {
        e.preventDefault();
        if ($("#UserId").val().isBlank()) {
            malert(title, "아이디를 입력하세요", function () {
                $("#UserId").focus();
            });
            return;
        }
        if ($("#Password").val().isBlank()) {
            malert(title, "패스워드를 입력하세요", function () {
                $("#Password").focus();
            });
            return;
        }
        var formData = $("#LoginForm").serialize();
        $("body").mLoading({
            text: "로그인 시도중......",
        });
        $.ajax({
            url: $("#LoginForm").attr("action"),
            type: "POST",
            cache: false,
            data: formData,
            dataType: "json",
            success: function (data) {
                $("body").mLoading("hide");
                if (data.Result === 1) {
                    document.location.href = data.Url;
                } else {
                    $("body").mLoading("hide");
                    alert(data.Message);
                    document.location.reload();
                }
            }
        });
    })
});