// JavaScript Document
/*
	reg
	mover
	mout
	error
	correct
*/
function regCheckfrm(){};
regCheckfrm.prototype=
{	
	/*
	*id
	*match true 不可以为空，且填写正确 false 可以为空。但如果填写需正确
	*reg 规则
	*
	*/
	error:[],//true 是通过验证,false 不能通过验证	
	chkfrm:function(option)
	{
		//alert(option['mout']['success']);
		if($("#"+option.id).attr("id"))
		{
			var e_id=$("#"+option.id).attr("id");
			var e_val=$("#"+option.id).val();
			if(option.match)
			{				
				this.error[e_id]=false;		//开了match的话。默认就为false
				if(e_val==""){this.error[e_id]=false;}
				else
				{	
					if(option.reg && option.reg!="scode")
					{
						var reg=option.reg;this.error[e_id]=reg.test(e_val);
					}else
					{
						if(option.reg=="scode")
						{
							var c=$.cookie("CheckCode");
							if(c==e_val)
							{
								this.error[e_id]=true;
							}else
							{
								this.error[e_id]=false;
							}
						}else
						{
							this.error[e_id]=true;
						}
					}
				}
			}else
			{
				if(e_val==""){this.error[e_id]=true;}
				else
				{
					if(option.reg){var reg=option.reg;this.error[e_id]=reg.test(e_val);}else{this.error[e_id]=true;}
				}
			}
		}
		if(this.error[e_id])
		{
			$("#"+option.id+"_hit").empty();
			$("#"+option.id+"_hit").append("<img src='img/ly/reg4.gif'/>");
			$("#"+option.id+"_hit").append(option["mout"]["success"]);
			if(typeof(option["toggle"])!="undefined")
			{
				if($("#"+option["toggle"]["destination"]).val()!=""&&$("#"+option["toggle"]["source"]).val()!="")
				{
						if($("#"+option["toggle"]["destination"]).val()==$("#"+option["toggle"]["source"]).val())
						{
							this.error[e_id]=true;
							$("#"+option["toggle"]["source"]+"_hit").empty();
							$("#"+option["toggle"]["source"]+"_hit").append("<img src='img/ly/reg4.gif'/>");
							$("#"+option["toggle"]["source"]+"_hit").append(option["toggle"]["success"]);
							$("#"+option["toggle"]["destination"]+"_hit").empty();
							$("#"+option["toggle"]["destination"]+"_hit").append("<img src='img/ly/reg4.gif'/>");
							$("#"+option["toggle"]["destination"]+"_hit").append(option["toggle"]["success"]);
						}else
						{
							this.error[e_id]=false;
							$("#"+option["toggle"]["source"]+"_hit").empty();
							$("#"+option["toggle"]["source"]+"_hit").append("<img src='img/ly/reg3.gif'/>");
							$("#"+option["toggle"]["source"]+"_hit").append(option["toggle"]["error"]);
							$("#"+option["toggle"]["destination"]+"_hit").empty();
							$("#"+option["toggle"]["destination"]+"_hit").append("<img src='img/ly/reg3.gif'/>");
							$("#"+option["toggle"]["destination"]+"_hit").append(option["toggle"]["error"]);
						}
				}				
			}
		}
		else
		{
			$("#"+option.id+"_hit").empty();
			$("#"+option.id+"_hit").append("<img src='img/ly/reg3.gif'/>");
			$("#"+option.id+"_hit").append(option["mout"]["error"]);
		}
	},
	chkinit:function(option)
	{
		//alert(option['mover']);
		var obj=$("#"+option.id+"_hit");
		obj.empty();
		obj.append("<img src='img/ly/reg2.gif'/>");
		obj.append(option.mover);
	},
	/*
	*id
	*match
	*reg
	*mover
	*mout{success error}
	*maxl
	*/
	chkElement:function(option)
	{
		var _this=this;			//复制对象。防止下面this冲突
		var timer=null;
		if($("#"+option.id).attr("id"))
		{
			var obj=$("#"+option.id);
			if(option.match)
			{				
				this.error[option.id]=false;		//开了match的话。默认就为false
			}
			obj.keyup(function()
							   {
								   if(typeof(timer)){clearTimeout(timer);}
								   timer=setTimeout(function(){_this.chkfrm(option)},500);
								   
								});
			obj.blur(function(){_this.chkfrm(option);});
			obj.focus(function(){_this.chkinit(option);});
		}
		/*if(option.maxl)
		{
			obj.change(function(){$("#"+option.id+"_hit").append(option.maxl);});
		}*/
	},
	isValidate:function()
	{
		for(p in this.error)
		{			
			if(!this.error[p]){return false; break;}
		}
		return true;
	}
}
