 
function dshow(obj, sType) {
    var oDiv = document.getElementById(obj); if (sType == 'show') { oDiv.style.display = 'block'; }
    if (sType == 'hide') { oDiv.style.display = 'none'; }
}
function ChangeCode(obj, codeurl) {
    $(obj).attr("src", codeurl + "?time=" + Math.random());
}

//验证
$(document).ready(function () {
    $("#Form1").validate({
        submitHandler: function (form) {
            if ($("#agreement").attr("checked") == false) {
                alert("您必须同意[注册协议]才能继续下一步");
                return false;
            }
            $("#reg").hide();
            $("#waiting").show();
            var tsTimeStamp = new Date().getTime();
            $.post("/ajax/reg.ashx", { "username": $("#username").val(), "password": $("#password").val(), "user_type": "1", "email": $("#email").val(), "time": tsTimeStamp, "act": "do_reg" },
	 	function (data, textStatus) {

	 	    if (data == "regerr") {
	 	        $("#waiting").hide();
	 	        $("#reg").show();
	 	        $("#username").attr("value", "");
	 	        $("#email").attr("value", "");
	 	        alert("注册失败");
	 	    }
	 	    else {

	 	        $("body").append(data);
	 	    }
	 	})
            // $(form).ajaxSubmit();
        },
        success: function (label) {
            label.text(" ").addClass("success");
        },
        rules: {
            username: {
                required: true,
                IsuserName: true,
                byteRangeLength: [3, 18],
                remote: {
                    url: "/ajax/reg.ashx",
                    type: "post",
                    data: { "usname": function () { return $("#username").val() }, "act": "check_usname" }
                }
            },
            email: {
                required: true,
                email: true,
                remote: {
                    url: "/ajax/reg.ashx",
                    type: "post",
                    data: { "email": function () { return $("#email").val() }, "act": "check_email" }
                }
            },
            password: {
                required: true,
                minlength: 6,
                maxlength: 18
            },
            password2: {
                required: true,
                equalTo: "#password"
            }
            ,
            valicode: {
                required: true,
                remote: {
                    url: "/ajax/reg.ashx",
                    type: "post",
                    data: { "valicode": function () { return $("#valicode").val() }, "act": "check_valicode" }
                }

            }
        },
        messages: {
            username: {
                required: "请填写用户名",
                remote: jQuery.format("用户名已经存在或者不合法")

            },
            email: {
                required: "请填写电子邮箱",
                email: jQuery.format("电子邮箱格式错误"),
                remote: jQuery.format("email已经存在")
            },
            password: {
                required: "请填写密码",
                minlength: jQuery.format("填写不能小于{0}个字符"),
                maxlength: jQuery.format("填写不能大于{0}个字符")
            },
            password2: {
                required: "请再输入一次密码",
                equalTo: "两次输入的密码不同"
            }
            ,
            valicode: {
                required: "请输入验证码",
                remote: jQuery.format("验证码输入错误")
            }
        }, errorElement: "span", 
        errorPlacement: function (error, element) {
            if (element.is(":radio"))
                error.appendTo(element.parent().next().next());
            else if (element.is(":checkbox"))
                error.appendTo(element.next());
            else
                error.appendTo(element.parent());
        }
    });
    //中文字两个字节
    jQuery.validator.addMethod("byteRangeLength", function (value, element, param) {
        var length = value.length;
        for (var i = 0; i < value.length; i++) {
            if (value.charCodeAt(i) > 127) {
                length++;
            }
        }
        return this.optional(element) || (length >= param[0] && length <= param[1]);
    }, "确保的值在3-18个字节之间(1个中文字算2个字节)");
    //字符验证
    jQuery.validator.addMethod("IsuserName", function (value, element) {
        return this.optional(element) || /^[a-zA-Z0-9_]{4,20}$/.test(value);
    }, "用户名只能是长度（4-20)位英文字母、数字和下划线");
});

$(document).ready(function () {
    $('#email').emailtip(myemails);
    $(".but100").hover(function () { $(this).addClass("but100_hover") }, function () { $(this).removeClass("but100_hover") });
    $("input[type='text'],input[type='password']").focus(function () {
        $(this).css("border-color", "#33CCFF");
    });
    $("input[type='text'],input[type='password']").blur(function () {
        $(this).css("border-color", "");
    });
});