﻿function changeKS() {
    if ($("#OldKSH").attr("checked")) {
        $("#password").remove();
        $("<input type='text' id='password' name='password' maxlength='6' tabindex='3' />").insertAfter("#labelPass");

        $("#labelPass").html("姓　　名：");
        $("#userName").formValidator({ onshow: "请输入9位的准考证号。", onfocus: "请输入9位的准考证号。", oncorrect: "准考证号格式正确。" }).regexValidator({ regexp: "OldZKZH", datatype: "enum", onerror: "准考证号格式错误！" });
        $("#password").formValidator({ onshow: "请输入原9位准考证上的姓名。", onfocus: "请输入原9位准考证上的姓名。", oncorrect: "　" }).inputValidator({ type: "size", min: 1, onerror: "姓名不能为空。" }); ;

        $("#userName").attr("maxlength", 9);
    } else {
        $("#password").remove();
        $("<input type='password' id='password' name='password' maxlength='20' tabindex='3' />").insertAfter("#labelPass");

        $("#labelPass").html("密　　码：");
        $("#userName").formValidator({ onshow: "请输入12位的准考证号。", onfocus: "请输入12位的准考证号。", oncorrect: "准考证号格式正确。" }).regexValidator({ regexp: "ZKZH", datatype: "enum", onerror: "准考证号格式错误！" });
        $("#password").formValidator({ onshow: "请输入6-20位包含字母和数字的密码。", onfocus: "请输入6-20位包含字母和数字的密码。", oncorrect: "密码格式正确。" }).regexValidator({ regexp: "Password", datatype: "enum", onerror: "密码格式非法！" });

        $("#userName").attr("maxlength", 12);
    }
    $("#password").enter2tab();
}

// 显示数据的方法
function showMsg(msg) {
    if (msg == null) {
        ShowError(true);
    }
    else {
        // 处理模板
        $("#Container").setTemplateElement("Template");
        $("#Container").processTemplate(msg);
    }
}

// 出错处理
function ShowError(v) {
    if (v) {
        $("#Container").html("");
        $("#error").html("没有内容可显示！");
    }
}

$(document).ready(function() {
    // 初始设置校验
    $.formValidator.initConfig({ formid: "aspnetForm", wideword: false, onerror: function() { alert("部分信息填写有错，请仔细查看页面上的具体提示！"); } });
    $("#InputCheck").formValidator({ onshow: "请输入下方图片中的6位数字。", onfocus: "请输入下方图片中的6位数字。", oncorrect: "验证码格式正确。" }).regexValidator({ regexp: "CheckCode", datatype: "enum", onerror: "验证码格式非法！" });
    $("#loginbtn").click(function() { $("#aspnetForm").submit(); });
    $("#notice img").click(function() { window.location.href = "PageNormal/Register.aspx"; });
    $("#CheckPic").click(GetNewPic);

    $("#OldKSH").click(changeKS);
    $("#reset").click(resetPASS);

    // 处理Input/Select的Enter
    $("input").enter2tab();
    FocusFirst();

    changeKS();
});

// 重置密码
function resetPASS() {
    GB_show('密码重置', 'PageNormal/ResetPass.aspx', '430', '580');
}

// 获取新验证码
function GetNewPic() {
    postajax("PageNormal/CheckImg.aspx/GetTag", "{}", ShowVImg);
}

// 显示新的验证码
function ShowVImg(msg) {
    if (msg == null) return;

    $("#HiddenCheckNum").val(msg.d);
    $("#CheckPic").attr("src", '/ZKService/PageNormal/CheckImg.aspx?id=' + msg.d + '&p=' + Math.random());
}
