﻿function doLogin(oForm) {
    if(!isUsername(oForm.elements['Username'].value)) {
        Tenruan.UI.MessageBox.alert('系统提示', '用户名不正确。', function() {
            oForm.elements['Username'].focus();
        }, Tenruan.UI.MessageBoxIcon.Warning);
        return;
    }
    if(Tenruan.DataValidator.isEmpty(oForm.elements['Password'].value)) {
        Tenruan.UI.MessageBox.alert('系统提示', '密码为必填项，请填写。', function() {
            oForm.elements['Password'].focus();
        }, Tenruan.UI.MessageBoxIcon.Warning);
        return;
    }
    if(Tenruan.DataValidator.isEmpty(oForm.elements['ValidateCode'].value)) {
        Tenruan.UI.MessageBox.alert('系统提示', '验证码为必填项，请填写。', function() {
            oForm.elements['Password'].focus();
        }, Tenruan.UI.MessageBoxIcon.Warning);
        return;
    }
    var oParams = Tenruan.DomForm.serialize(oForm);
    PageMask.showMask('正在登陆，请稍后...');
    var oProxy = Tenruan.Net.RemoteInvoker.createProxy('Tenruan.Web.MBCS', 'Tenruan.Web.MBCS.Services.UserService');
    oProxy.invoke('Login', function() {
        PageMask.showMask('登陆成功，正在进入后台...');
        oForm.disabled = true;
        window.location.href = 'System/';
    },
    function(sResult) {
        PageMask.closeMask();
        Tenruan.UI.MessageBox.alert('系统提示', sResult.message, null, Tenruan.UI.MessageBoxIcon.Infomation);
    },
    oParams);
}