function formVal(){
		this.check = function(elem,type,txt){
		    this.elem=elem;
			this.type=type;
			this.txt=txt;
			$(this.elem).siblings(".reg_tips").show();
			switch (this.type) {
				case "focus"://聚焦
					$(this.elem).siblings(".reg_tips").html("<img src='http://img.zhui.cn/i/onFocus.gif' alt='' /> " + txt).css("background", "#E9F0FF");
					break;
				case "success"://成功
					$(this.elem).siblings(".reg_tips").html("<img src='http://img.zhui.cn/i/onSuccess.gif' alt='' /> " + txt).css("background", "#E9FFEB");
					break;
				case "error"://失败
					$(this.elem).siblings(".reg_tips").html("<span class='onError'><img src='http://img.zhui.cn/i/onError.gif' alt='' /> " + txt+"</span>").css("background", "#FFF2E9");
					break;
				case "load"://载入
					$(this.elem).siblings(".reg_tips").html("<img src='http://img.zhui.cn/i/onLoad.gif' alt='' /> " + txt).css("background", "#E9F0FF");
					break;
			    default:
				   $(this.elem).siblings(".reg_tips").hide();
				   break;
			}
		}
	}

$(document).ready(function() {
       var FV=new formVal();
  $(".usernameInput").bind("change", function() {//用户名
            if ($(".usernameInput").val().length >= 4) {
                $.ajax({
                    type: "POST",
                    url: "UserCheck.ashx", //传入API来处理
                    async: false,
                    dataType: "xml",
                    data: "showmode=1&encode=gb2312&k=" + encodeURIComponent($(".usernameInput").val()) + "&c=0", //查看有无重复的用户
					beforeSend:function(){
						FV.check(".usernameInput","load","处理中");
					},
                    success: function(xml) {
                        $(xml).find("Zhui").find("StatusInfo").each(function() {//解析xml
                            if ($(this).find("Status").text() == "1") {
								FV.check(".usernameInput","success","可以注册");
                            }
                            else {
								FV.check(".usernameInput","error","已经被占用,如果您是百邮用户可以直接<a href='Login.aspx'>登录</a>");
								return false;
                            }
                        });
                    },
					error:function(){
						FV.check(".usernameInput","error","连接服务器失败!");
							return false;
					}
                });
            }else{
				FV.check(".usernameInput","error","用户名不能小于4个字符!");
				return false;
			    }
        }).bind("focus",function(){
		FV.check(".usernameInput","focus","不少于4位英文或数字(必须以英文字母开头)");

		}).bind("blur",function(){
			$(this).triggerHandler("change");
});

$(".passwordInput").bind("focus",function(){//密码
        FV.check(".passwordInput","focus","密码由3-20个英文字母、数字或特殊符号组成");
		}).bind("change",function(){
			var len=$(this).val().length;
			if(len<3){
				FV.check(".passwordInput","error","密码太短,请重新输入");
			return false;
			}else{
				FV.check(".passwordInput","success","输入正确");
			}
		}).bind("blur",function(){
			$(this).triggerHandler("change");
});

$(".repassInput").bind("focus",function(){//确认密码
    FV.check(".repassInput","focus","请再次输入密码");
  }).bind("change",function(){
  	   var p1=$(".passwordInput").val();
	   var p2=$(this).val();
	   if(p2==""||p2.length<3){
	   	FV.check(".repassInput","","");
	   }else
	   if(p1!=p2){
	   	FV.check(".repassInput","error","两次密码不一致,请检查");
	   }else{
	   	FV.check(".repassInput","success","输入一致");
			}
  }).bind("blur",function(){
	$(this).triggerHandler("change");
  });

$(".useremailInput").bind("focus",function(){//Email
       FV.check(".useremailInput","focus","欢迎留下Email");
}).bind("change",function(){
	var email=$(this).val();
	if(email!=""){
	if(isEmail(email)){//如果正确
	FV.check(".useremailInput","success","输入正确");
	}else{
		FV.check(".useremailInput","error","Email地址不合法,请检查");
	}
 }else{
 	$(this).siblings(".reg_tips").html("").hide();
 }
}).bind("blur",function(){
	$(this).triggerHandler("change");
})

$(".userphoneInput").bind("focus",function(){//手机号码
     FV.check(".userphoneInput","focus","请输入11位手机号码(仅支持中国大陆手机)");
}).bind("change", function() {
	     var phoneNum=$(".userphoneInput").val()
            if (phoneNum.length == 11) {
				if (isMobilePhone(phoneNum)) {
					$.ajax({
						type: "POST",
						url: "UserCheck.ashx", //传入API来处理
						dataType: "xml",
						data: "showmode=1&encode=gb2312&k=" + encodeURIComponent($(".userphoneInput").val()) + "&c=2", //查看有无重复的手机号码
						beforeSend: function(){
							FV.check(".userphoneInput","load","处理中...");
						},
						success: function(xml){
							$(xml).find("Zhui").find("StatusInfo").each(function(){//解析xml
								if ($(this).find("Status").text() == "1") {
									FV.check(".userphoneInput","success","手机号码正确");
								}
								else {
									FV.check(".userphoneInput","error","已经被占用.");
								}
							});
						},
						error: function(){
							FV.check(".userphoneInput","error","连接服务器失败!");
						}
					});
				}else{
					FV.check(".userphoneInput","error","手机号码不规范哦.");
				}
            }
            else{
                $(".userphoneInput").siblings(".reg_tips").html("").hide();
            }
        }).bind("blur",function(){
			$(this).triggerHandler("change");
});

$(".yz").bind("focus",function(){//验证码
	FV.check(".yz","focus","请输入验证码");
}).bind("blur",function(){
	if ($(this).val() == "") {
		FV.check(".yz","error","验证码不能为空");
	}else{//Ajax处理:
		$(this).siblings(".reg_tips").hide();
	}
})

$("#aspnetForm").bind("submit",function(){//表单提交
   var bloo=$("#agreement").attr("checked");
	if(!bloo){
		alert("请先同意服务条款");
		return false;
	}
	$(".required:input").each(function(){
		if($(this).siblings(".reg_tips").html()==""){
			$(this).triggerHandler("blur");
		}
	})
var numError=$(".onError").length;
if(numError){
	return false;
}
 })

})
function isMobilePhone(num){//验证手机号码
   //if(/^13d{9}$/g.test(num)||(/^15[8,9]d{8}$/g.test(num))){
   	if(/^1d{10}$/g.test(num)){
         return true;
    }else{
        return false;
   }
}

function isEmail(mail) { //验证Email
if (mail.search(/^w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]+$/) != -1){
     return true;
     }else
     return false;
 }