/// <reference path="../../Scripts/jquery-1.8.2.min.js" />

$(function () {
    $("#loginyq").find("input").keydown(function (e) {
        if (e.keyCode == 13) {
            var index = $(this).attr("tabindex");
            var el = $("#loginyq").find("input[tabindex='" + (parseInt(index) + 1) + "']");
            if (el.length == 0) {
                login();
            }
            else {
                el.focus();
            }
        }
    });
})

function login() {
    var username = $("#username").val();
    var pwd = $("#pwd").val();

    $.ajax({
        url: "/Account/Login",
        type: "post",
        data: "username=" + username + "&pwd=" + pwd,
        success: function (ret) {
            if (ret.state == -1) {
                alert(ret.mess);
            } else {
                window.location.href = "/Admin/Index";
            }
        }
    });
}
