	 var regExp = {
	        url: /(https?):\/\/([^/: ]+)(:\d*)?(\S*)/i,
	        url2: /https?:\/\/[\w-]+?\.\w\S*/i,
	        img: /<img.+?src=(['"]?)([^>\s]+)\1.*?>/i,
	        email: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
	        html: /<(?:(?:\/?[A-Za-z][^>=\s]*(?:[=\s](?:(?!['"])[\s\S]*?|'[^']*'|"[^"]*"))*)|(?:!--[\s\S]*?--))>/g,
	        ignoreAccount: /['"\s@\/\.\\;&]/,
	        excludeWebsites: /rensea\.com|^\//i
	};
	function chgImg(){
        $('#vfcode').attr("src",'/ajax/get_catpcha.html?vt=' + Math.random()).css({"height": 30, width: 80})
    }
    function blurCheckScreenName(ele, sm){
        var oTips = $(ele).parent().next().find(".tipsBox");
        oTips.html("").hide().removeClass("tipsBoxErr");
        $(ele).removeClass("regInputFocus");
        if(!$("#screenName").val().trim()){
   	       return false;
        }
        if(/[\u4e00-\u9fa5]/.test($("#screenName").val())){
        	oTips.html("用户名字不能包含中文字符").addClass("tipsBoxErr").show();
        	$(ele).addClass("regInputFocus");
           return false;
        }
        if(/^\d+$/.test($("#screenName").val())){
        	oTips.html("用户名不能全部为数字").addClass("tipsBoxErr").show();
        	$(ele).addClass("regInputFocus");
           return false;
        } 
        if(!/^\w+$/.test($("#screenName").val())){
        	oTips.html("请输入16位以内英文字母、数字和下划线").addClass("tipsBoxErr").show();
        	$(ele).addClass("regInputFocus");
           return false;
        }   
        if(regExp.ignoreAccount.test($("#screenName").val())){
        	oTips.html("用户名不合法").addClass("tipsBoxErr").show();
        	$(ele).addClass("regInputFocus");
            return false;
         }          
        if($("#screenName").val().replace(/[^\x00-\xff]/g,"11").length < 4){
        	oTips.html("最短只允许4个英文字母、数字和下划线").addClass("tipsBoxErr").show();
        	$(ele).addClass("regInputFocus");
           return false;        
        }          
        if($("#screenName").val().replace(/[^\x00-\xff]/g,"11").length > 16){
        	oTips.html("请输入16位以内英文字母、数字和下划线").addClass("tipsBoxErr").show();
        	$(ele).addClass("regInputFocus");
           return false;        
        }     
       var ret = true;
       if($("#screenName").val())
       $.ajax({
       		 url:"/account/check.json",
       		 async: false,
       		 dataType: "json",
       		 data: {username: $("#screenName").val()}, 
       		 success:function(reply){
       		    reply = reply || {};
       		    if(!reply.avalible){
       		    	oTips.html("此用户名已经存在").addClass("tipsBoxErr").show();
       		    	$(ele).addClass("regInputFocus");
       		        ret = false;
       		    }else{
       		    	oTips.html("<img src='/images/ico_valid.gif' align='absmiddle' />").show();
       		    	$(ele).addClass("regInputFocus");
       		        ret = true;
       		    }
             }
        }); 
        return ret;
    }
   function changeDomain(v){
      var v = v||"";
      $("#userDomain").html(v);
   }
   function showTips(ele){
	   var o = $(ele).parent().next().find(".tipsBox").removeClass("tipsBoxErr");
       switch(ele.id){
          case "screenName":
              o.html("16位以内英文字母、数字和下划线").show();
              $(ele).addClass("regInputFocus");
          break;
          case "nickName":
              o.html("24位以内英文字母或12位以内中文字符").show();
              $(ele).addClass("regInputFocus");
          break;
          case "password":
              o.html("6-16个字符以内的任意字符").show();
              $(ele).addClass("regInputFocus");
          break;
          case "recheck_password":
              o.html("再次输入上面的密码").show();
              $(ele).addClass("regInputFocus");
          break;   
          case "email":
              o.html("填写正确地址，用作活动奖品通知和找回密码").show();
              $(ele).addClass("regInputFocus");
          break;  
          case "validate_code":
              o.html("输入图像中的文字,不区分大小写").show();
              $(ele).addClass("regInputFocus");
          break;                                                           
       }
   }
   var validCode = false, validCode2 = false;
   function validateBlur(ele){
       var s = $(ele).val().trim()||"";
       var oTips = $(ele).parent().next().find(".tipsBox");
       oTips.hide().removeClass("tipsBoxErr");
       $(ele).removeClass("regInputFocus");
       switch(ele.id){
          case "password":
              if(s){
	              if(s.length <6 ){
	            	  oTips.html("密码长度太短").addClass("tipsBoxErr").show();
	            	  $(ele).addClass("regInputFocus");
	              }
	              else if(s.length > 16 ){
	            	  oTips.html("密码长度太长").addClass("tipsBoxErr").show();
	            	  $(ele).addClass("regInputFocus");
	              }else{
	            	  oTips.html("<img src='/images/ico_valid.gif' align='absmiddle' />").show();
	            	  $(ele).addClass("regInputFocus");
	              }
              }else{
              }     
          break;
          case "recheck_password":
              if($("#password").val().trim() && $("#password").val().trim() != s){
            	  oTips.html("两次输入的密码不一致").addClass("tipsBoxErr").show();
            	  $(ele).addClass("regInputFocus");
              }
              if($("#password").val().trim() && s && $("#password").val().trim() == s){
            	  oTips.html("<img src='/images/ico_valid.gif' align='absmiddle' />").show();
            	  $(ele).addClass("regInputFocus");
              }
          break; 
          case "email":
             if(s){
	              if(!regExp.email.test(s)){
	            	oTips.html("邮箱格式错误").addClass("tipsBoxErr").show();
	            	$(ele).addClass("regInputFocus");
	              }else{
	            	oTips.html("<img src='/images/ico_valid.gif' align='absmiddle' />").show();
	            	$(ele).addClass("regInputFocus");
	              }  
             }
          break;  
          case "validate_code":
             if(s && (!validCode2||validCode2 == "fail"))
                $.ajax({
                   dataType: "json",
                   async: false,
                   cache: false,
                   url: "/ajax/validate_catpcha.html",
                   data: {'catpcha_code': s},
                   success: function(resp){
                        if(!resp.isCorrect){
                            oTips.html("验证码输入不正确").addClass("tipsBoxErr").show();
                            $(ele).addClass("regInputFocus");
                            chgImg();
                            validCode = "fail";
                        }else{
                        	 oTips.html("<img src='/images/ico_valid.gif' align='absmiddle' />").show();
                        	 $(ele).addClass("regInputFocus");
                             validCode = true;
                        }
                   }
                });          
          break;                                                           
       }   
   }
   $(document).ready(function(){
	   chgImg();
	   $("#regForm").submit(function(){
	            if(!blurCheckScreenName($("#screenName")[0], true)) return false;
		        if(!$('#password').val()){
		        	$("#password").parent().next().find(".tipsBox").html("密码还未输入").addClass("tipsBoxErr").show();
		        	$("#password").addClass("regInputFocus");
		        	return false;	            
		        }else{
		              var ele = $('#password')[0], s = $('#password').val();
		               if(s.length <6 ){
		                 $(ele).parent().next().find(".tipsBox").html("密码长度太短").addClass("tipsBoxErr").show();
		                 $(ele).addClass("regInputFocus");
		                 return false;
		              }
		              else if(s.length > 16 ){
		            	  $(ele).parent().next().find(".tipsBox").html("密码长度太长").addClass("tipsBoxErr").show();
		                 $(ele).addClass("regInputFocus");
		                 return false;
		              }
		        }	        
		        if(!$('#recheck_password').val()){
		        	$("#recheck_password").parent().next().find(".tipsBox").html("确认密码还未输入").addClass("tipsBoxErr").show();
		        	$("#recheck_password").addClass("regInputFocus");
		        	return false;	            
		        }	        
		        if($('#recheck_password').val()!=$('#password').val()){
		        	$("#recheck_password").parent().next().find(".tipsBox").html("两次输入的密码不一致").addClass("tipsBoxErr").show();
		        	$("#recheck_password").addClass("regInputFocus");
		        	return false;
		        }
		        if(!regExp.email.test($("#email").val())){
		          $("#email").parent().next().find(".tipsBox").html("邮箱地址格式错误").addClass("tipsBoxErr").show();
		          $("#email").addClass("regInputFocus");
		          return false;
		        }
	            var s = $("#validate_code").val();
	            var ret = true;
	            if(validCode=="fail") return false;
	            if(!validCode){
		            $.ajax({
		               dataType: "json",
		               async: false,
		               cache: false,
		               url: "/ajax/validate_catpcha.html",
		               data: {'catpcha_code': s},
		               success: function(resp){
		            	    var oTip = $("#validate_code").parent().next().find(".tipsBox");
		                    if(!resp.isCorrect){
		                    	oTip.html("验证码输入不正确").addClass("tipsBoxErr").show();
		                    	$("#validate_code").addClass("regInputFocus");
		                        ret = false;
		                        validCode2 = "fail";
		                        chgImg();
		                    }else{
		                    	 oTip.html("<img src='/images/ico_valid.gif' align='absmiddle' />").show();
		                         $("#validate_code").addClass("regInputFocus");
		                         ret = true;
		                         validCode2 = true;
		                    }
		               }
		            }); 
	            }
	            if(!$("#agree")[0].checked){
	               alert("请勾选同意人间网使用条款和隐私权政策");
	               return false;
	            }
	            return ret;
	   });
	});   
   function ckboxClick(){
	   if(this.checked){
		   $(this).parent().css("background", "#eeeeee");
	   }else{
		   $(this).parent().css("background", "#ffffff"); 
	   }
   }