﻿$(document).ready(function () {
    //登录
    $('#btnLogin').click(function () {
        var userid = $('#txtUserId')[0].value, password = $('#txtPassword')[0].value;
        if (userid == "" || password == "") {
            alert("通行证和密码不能为空！请重新填写。");
            return;
        }
        $.ajax({
            url: syspath + '/Register/ajax.aspx',
            data: "type=login&userid=" + escape(userid) + "&password=" + escape(password)
                          + "&time" + new Date().toString(),
            type: 'POST',
            timeout: 30000,
            success: function (msg) {
                if (msg.indexOf("登录成功!") != -1) {
                    if (msg.indexOf("登录成功!转向到:") != -1) {
                        location = msg.replace("登录成功!转向到:", "");
                        return;
                    }
                    location = syspath + '/UserCenter/MyDocList.aspx';
                    return;
                }
                else {
                    alert(msg);
                    return;
                }
            },
            error: function (xmlHttpRequest, error) {
                if (error == "timeout")
                    alert("发送数据超时，请重新提交！");
                else if (error == "error")
                    alert("提交数据发生错误！");
            }
        });
        return false;
    });
    //退出
    $('#btnLogout').click(function () {
        Logout();
    });
    //退出
    $('#btnLogoutStatus').click(function () {
        Logout();
    });
    $('#txtUserId').keypress(function () {
        if (event.keyCode == 13 && $('#txtUserId')[0].value == "") {
            alert("用户不能为空");
        }
        else if (event.keyCode == 13 && $('#txtUserId')[0].value != "") {
            $('#txtPassword').focus();
        }
    });
    $('#txtPassword').keypress(function () {
        if (event.keyCode == 13 && $('#txtPassword')[0].value == "") {
            alert("密码不能为空");
        }
        else if (event.keyCode == 13 && $('#txtPassword')[0].value != "") {
            $('#btnLogin').click();
        }
    });
});

//退出登录
function Logout() {
    if (!confirm("确定退出登录吗?")) {
        return;
    }
    $.ajax({
        url: syspath + '/Register/ajax.aspx',
        data: "type=logout&time" + new Date().toString(),
        type: 'POST',
        timeout: 30000,
        success: function (msg) {
            location = syspath;
            return;
        },
        error: function (xmlHttpRequest, error) {
            if (error == "timeout")
                alert("发送数据超时，请重新提交！");
            else if (error == "error")
                alert("提交数据发生错误！");
        }
    })
    return false;
}
