jQuery.fn.extend({          
	       Int:/^[1-9]\d*$/,
		   Intmsg:'请输入整数！',
		   Phone:/((\d{3,4})|\d{3,4}-)?\d{7,8}(-\d{3})*/,
		   Phonemsg:'请使用格式021-87888822 或者 021-44055520-555 或者 (0511)4405222！',
	       Youbian:/^\d{6}$/,
	       Youbianmsg:'请使用六位数字！',
	       tel:/^\d{11}$/,
	       telmsg:'请使用11位手机号码！',
	       Date:/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/,
		   Datemsg:'请输入2011-02-03日期格式！',
		   Num:/^((\d+\.\d*[1-9]\d*)|(\d*[1-9]\d*\.\d+)|(\d*[0-9]\d*))$/,
		   Nummsg:'请输入数字！',
		     Email:/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/,
		   Emailmsg:'请输入邮箱.',		   
		   validE:function(){	   	  
				var flag=true;
				this.addError=function(msg){
				        flag=false;
				        if(!$(this).attr("error")){				        	
				            var w=$(this).width();
						    var h=$(this).height();
							var of=$(this).offset();
							var left=(Number(of.left)+w+7);
							var top=of.top;						
							
							$(this).css("border",'solid 1px red').css("background","url(/public/images/ui/error.gif) bottom repeat-x");						
							var id="_"+ parseInt(Math.random()*100000);
							var ss="<div id="+id+" style='display:none;border:solid 1px red;padding:0 0 0 10px;line-height:"+h+"px;color:white;position:absolute;background:tomato;top:"+top+"px;left:"+left+"px'>"+msg+"</div>";
							$("body").append(ss);						
							$(this).attr('error',id);
							$(this).mouseover(function(){						 
							  $("#"+$(this).attr('error')).show();
							}).mouseout(function(){
							  $("#"+$(this).attr('error')).hide();
							});
				        }else{				        
				        	 $("#"+$(this).attr('error')).show();
				        	 //$("#"+$(this).attr('error')).offset($(this).offset());
				        }
				};
				this.removeError=function(){
					    flag=true;					 
						var eid=$(this).attr('error');
						$(this).css("border",'solid 1px #cdcdcd').css("background","url()").removeAttr("error");	
					    $("#"+eid).remove();
						$(this).unbind("mouseover");
						$(this).unbind("mouseout");
				};
			
				var reg=$(this).attr("reg").replace(/ +/g," ");
				//alert(reg + "---" + reg.split(" ").length);
				if((reg.split(" ").length==1)){ //可以不写				   
				   if($.trim($(this).val())==''){				        				       
				        this.removeError();	
				        return true;
				   }			     
				}else{//必须填写						
					if($(this).val()=='') 
					  this.addError("必须填写！");
					else{
					  this.removeError();
				    }
				    reg=reg.split(" ")[0];
				     
				}
				if(reg.indexOf("len")!=-1){ //判断如len（1,100）
						  reg=reg.replace(/len\(/,"").replace(/\)/,"").split(",");				
						  var  regEx=eval("(" + "/^.{"+reg[0]+","+reg[1]+"}$/"+")");				  
						  if(!regEx.test($(this).val())){					  	
						     this.addError("字符长度应在"+reg[0]+"和"+reg[1]+"之间！");
						  }else{
						  	 this.removeError();
						  }
					  }else{
							if(!($(this)[reg].test($(this).val()))){					
							    this.addError($(this)[reg+'msg']);
							}else{					
								this.removeError();
							}
				}	
				return flag;
		    },
		    valid:function(){
		    	var flag=true;
		    	var th=this;
				$(this).each(function(){				
					 if(!$(this).validE()){
					   flag=false;
					 }					
				});
				return flag;
		    },
		    valid_init:function(){
		   	   var th=$(this);
			   th.each(function(){
					$(this).keyup(function(){
					   $(this).validE();
					});
					$(this)[0].onchange=function(){th.valid(this);};
			   });
		   }
});


var mzj={valid:function(){
         return $("*[reg]").valid();
        }};


//全选
mzj.bindAllSelect=function(selector){
	 $(selector).click(function(){
		  var v=$(this)[0].checked;
		  var ck=$(this).parent().parent().siblings().find("input[type='checkbox']");
		  ck.each(function(){
			  $(this)[0].checked=v;  
		  });
		  
	  });
};

$(document).ready(function(){
  $("*[reg]").valid_init();
  $(".Wdate").each(function(){
     $(this).focus(function(){
     	WdatePicker({skin:'whyGreen'});
     });
  }); 
    $(".tab,.tab2").each(function(){
	   var tab=$(this);
	   tab.find("dt span").click(function(){
		   $(this).siblings().removeClass('cur');
	    	$(this).attr('class','cur');
	    	var ind=tab.find("dt span").index($(this));
	    	tab.find("dd").css('display','none');
	    	tab.find("dd").eq(ind).css('display','block');	   
       });
   });
 
});


