﻿var ShowRegisterForm = function() {
    var html = '';
    html += '<ul>';
    html += '<li><b>用户名：</b><input name="txtUserName" id="txtUserName" maxlength="20" type="text" class="inp-text" /><font color="#FF0000">*</font></li>';
    html += '<li><b>密&nbsp;&nbsp;码：</b><input name="txtPassword" id="txtPassword" maxlength="20" type="password" class="inp-text" /><font color="#FF0000">*</font></li>';
    html += '<li><b>确认密码：</b><input name="txtPassword1" id="txtPassword1" type="password" class="inp-text" /><font color="#FF0000">*</font></li>';
    html += '<li><b>电子邮件：</b><input name="txtEmail" id="txtEmail" maxlength="100" type="text" class="inp-text" /><font color="#FF0000">*</font></li>';
    html += '<li><b>联系电话：</b><input name="txtLinkTel" id="txtLinkTel" maxlength="50" type="text" class="inp-text" /></li>';
    html += '<li><b>联系QQ：</b><input name="txtQQ" id="txtQQ" maxlength="50" type="text" class="inp-text" /></li>';
    html += '<li style="text-align:center;"><input type="button"  class="inp-land02" value="提交" id="btnRegister" onclick="doRegister();" /></li>';
    html += '<li style="text-align:center;display:none;" id="liNotice">正在注册中，请稍候……</li>';
    html += '</ul>';

    openDialog('用户注册', html);
};

var doRegister = function() {
    var userName = $.trim($('#txtUserName').val());
    var userPass = $('#txtPassword').val();
    var email = $.trim($('#txtEmail').val());
    var linkTel = $.trim($('#txtLinkTel').val());
    var qq = $.trim($('#txtQQ').val());

    if (userName == '') {
        alert('请填写用户名！');
        $('#txtUserName').focus();
        return;
    }

    if (userPass == '') {
        alert('请填写密码！');
        $('#txtPassword').focus();
        return;
    }

    if (userPass != $('#txtPassword1').val()) {
        alert('两次输入的密码不一致！');
        $('#txtPassword1').focus();
        return;
    }

    if (email == '') {
        alert('请填写电子邮件！');
        $('#txtEmail').focus();
        return;
    }

    res = /^[0-9a-zA-Z_\-\.]+@[0-9a-zA-Z_\-]+(\.[0-9a-zA-Z_\-]+)*$/;
    var re = new RegExp(res);
    if (email.match(re) == null) {
        alert('电子邮件格式错误！');
        $('#txtEmail').focus();
        return;
    }

    var checklinkTel = linkTel.replace('-', '');
    if ((checklinkTel == '' && linkTel != '') || (checklinkTel != '' && isNaN(parseInt(checklinkTel)))) {
        alert('电话号码格式错误！');
        $('#txtLinkTel').focus();
        return;
    }

    if (qq != '' && (isNaN(parseInt(qq)) || qq.length < 5 || qq.length > 12)) {
        alert('QQ号码格式错误！');
        $('#txtQQ').focus();
        return;
    }

    $('#btnRegister').attr('disabled', 'disabled');
    $('#liNotice').show();

    $.ajax({
        type: 'post',
        url: 'ajax.ashx',
        dataType: 'json',
        data: { op: 'register', username: userName, userpass: userPass, email: email, linktel: linkTel, qq: qq },
        success: function(msg) {
            alert(msg.Msg);
            $('#btnRegister').removeAttr('disabled');
            $('#liNotice').hide();
            if (msg.Result == 1) {
                CloseDialog();
                window.location.href = '/';
            }
        },
        error: function() {
            $('#liNotice').hide();
            alert('系统异常，请稍有再试！');
        }
    });
};
