﻿// JScript 文件
$__Pager__ = ({
    'ShowMessage' : function ($msg, $textForm) {
        alert('系统错误：' + $msg);
        if ($textForm)
        {
            $textForm.focus();
        }
        return;
        var $prompt_layer = document.getElementById('__Pager_Prompt__');
        if (!$prompt_layer)
        {
            $prompt_layer = document.createElement('div');
            with ($prompt_layer)
            {
                id = '__Pager_Prompt__';
                style.position = 'absolute';
                style.left = '30%';
                style.top = '20%';
                style.width = '350px';
                style.height = '150px';
                style.border = '1px solid #999';
                style.backgroundColor = '#719929';
                style.lineHeight = '18px';
            }
            $prompt_layer.innerHTML = '<div class="__Pager_Prompt_Title__" style="line-height:30px;height:30px;padding:0px 3px 0px 3px;color:white;cursor:move;" onmousedown="RegisterDragObjectOnMouseDown(event, this, document.getElementById(\'__Pager_Prompt__\'));"><div style="float:left;">操作失败</div><div style="float:right;"><a id="__Pager_Prompt_CloseButton__" href="javascript:void(document.getElementById(\'__Pager_Prompt__\').style.display=\'none\');" style="color:#000;font-weight:bold;">关闭</a></div></div><div class="__Pager_Prompt_Content__"><div style="background:#FFF;width:100%;height:90%;padding:0px;margin:0px;overflow:auto;"><div style="padding:5px;"><div align="center" id="__Pager_Prompt_Content__" style="margin:20px auto auto auto;"></div></div></div><div style="clear:both;"></div></div>';
            document.body.appendChild($prompt_layer);
        }
        if ($prompt_layer)
        {
            $prompt_layer.style.display = 'block';
            document.getElementById('__Pager_Prompt_Content__').innerHTML = $msg;
        }
        //alert($msg);
    }
    ,'OnFocus' : function ($textForm) {
        //with (document.getElementById('__' + $textForm.name + '__').style)
        with ($textForm.style)
        {
            border = '1px solid #9ECC00';
        }
    }
    ,'OnBlur' : function ($textForm) {
        //with (document.getElementById('__' + $textForm.name + '__').style)
        with ($textForm.style)
        {
            //border = '0px';
            border = '1px solid #84A1BD';
        }
    }
    ,'DoLogin' : function ($form) {
        try
        {
            var $user_name = $form['UserName'].value.trim();
            if ('' === $user_name)
            {
                this.ShowMessage('请输入您的用户名？', $form['UserName']);
                $form['UserName'].focus();
                return false;
            }
            var $user_pwd = $form['UserPassword'].value.trim();
            if ('' === $user_pwd)
            {
                this.ShowMessage('请输入您的密码？', $form['UserPassword']);
                $form['UserPassword'].focus();
                return false;
            }
            var $valid_code = $form['txtValidCode'].value.trim();
            if ('' === $valid_code)
            {
                this.ShowMessage('请输入验证码？', $form['txtValidCode']);
                $form['txtValidCode'].focus();
                return false;
            }
            if (null === $valid_code.match(/^[0-9]{4}$/ig))
            {
                this.ShowMessage('验证码必须是4位数字！', $form['txtValidCode']);
                $form['txtValidCode'].focus();
                return false;
            }
            
            var $self = this;
            server_Page_Default.DoLogin(
                $user_name
                ,$user_pwd
                ,$valid_code
                ,function ($result) {
                    /*
                    $result 成员
                    error对象
                    value属性
                    request对象
                    context对象
                    duration
                    json对象
                    //*/
                    if ($result.error)
                    {
                        $self.ShowMessage($result.error.Message);
                        return false;
                    }
                    $self.LoginSuccess($form);
                }
            );
        }
        catch ($ex)
        {
            alert($ex.message);
        }
        finally
        {
            return false;
        }
    }
    ,'LoginSuccess' : function ($form) {
        document.getElementById('WelcomeUser').innerHTML = $form['UserName'].value.trim();
        document.getElementById('LoginArea').style.display = 'none';
        document.getElementById('LoginedArea').style.display = '';
        window.location.href='default.html';
    }
});
