(function() {
    var url = "Login.aspx",
inputs = document.getElementsByTagName("input"),
account = inputs[0],
pwd = inputs[1],
    date = inputs[2],
    btnLogin = inputs[3],
    btnExit = inputs[4],
    btnUpdate = inputs[5];
    function init() {
        bindEvents();
        account.focus();
    }
    function bindEvents() {
        $(date).focus(function() {
            this.blur();
        });
        $(account).keydown(function(e) {
            if (e.keyCode == 13) {
                pwd.focus();
            }
        });
        $(pwd).keydown(function(e) {
            if (e.keyCode == 13) {
                login();
            }
        });
        $(btnLogin).click(function() {
            login();
        });
        $(btnExit).click(function() {
            if (confirm("您确定要退出本系统吗?")) {
                window.opener = null;
                window.open('', '_self');
                window.close();
            }
        });
    }
    function validate() {
        if (!account.value) {
            alert("账号不能为空");
            account.focus();
            return false;
        }
        if (!pwd.value) {
            alert("密码不能为空");
            pwd.focus();
            return false;
        }
        return true;
    }
    function login() {
        if (!validate()) return;
        $.post(url, { action: "login", account: account.value, password: pwd.value }, function(data) {
            if (data == "success") {
                window.location.href = "Index.aspx";
            } else if (data == "unAuthorize") {
                alert("此系统未经备案,请联系软件供应商!");
            } else if (data == "maxUserCount") {
                alert("当前在线人数已超过最大注册用户数!");
            }
            else {
                alert("用户名或密码错误!");
            }
        });
    }
    init();
})();