function isNum(t){
	var str=/^[-\+]?[\d]+\.?\d*$/;
	return str.test(t);
}
function isStr(t){//中文数字
	var str=/^[0-9\x7f-\xff]*$/;
	return str.test(t);
}
function isLetter(t){//英文数字
	var str=/^[a-zA-Z0-9]*$/;
	return str.test(t);
}
function isInt(t){ 
	var str=/^[-\+]?\d+$/;
	return str.test(t);
}
function isFloat(t){ 
	var str=/^[-\+]?\d+(\.\d+)?$/;
	return str.test(t);
}
function isMail(mstr){
	var str=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	return str.test(mstr);
}
function isIP(t){
	var str=/^((\d{1,2}|1\d{1,2}|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d{1,2}|2[0-4]\d|25[0-5])$/;
	return str.test(t);
}
function safe(t){
	var str=/^[a-zA-Z0-9\@\.\/\\\|\#\_\-\u4e00-\u9fa5]*$/;
	return str.test(t);
}
function ensafe(t){
	var str=/^[a-zA-Z0-9\@\_]*$/;
	return str.test(t);
}
chkfm=Object();
chkfm={
	arg:null,
	submited:true,
	ajaxurl:"",
	ajaxaction:"",
	func:function(){return true;},
	msg:{empty:string_t1,
		min:string_t2,
		max:string_t3,
		nosafe:string_t4,
		equ:string_t5,
		msg:string_t6,
		once:string_t7,
		unonce:string_t8},
	strlen:function(obj){
		var len=0,str=obj.value; 
		for (var i=0;i<str.length;i++) { 
			if (str.charCodeAt(i)>255)len+=2;   
			else len++; 
		} 
		$($(obj).id+'_cc').innerHTML=string_t9+str.length+string_t10+len+string_t11; 
	},
	show_css:function(obj,k){
		$(obj).style.backgroundImage="url(/inc_js/img/reg"+k+".gif)";
		$(obj).style.height="24px";
		$(obj).style.lineHeight="24px";
		$(obj).style.backgroundRepeat="no-repeat";
		$(obj).style.paddingLeft="20px";
		$(obj).style.paddingTop="4px";
	},
	show_err:function(obj,errs){//错误
		chkfm.submited=false;
		chkfm.show_css(obj+'_cc',3);
		$(obj+'_cc').innerHTML=errs;
		try{$(obj).style.border="1px #F30 solid";
		}catch(e){}
		return false;
	},
	pass:function(obj,k,txt){//正确
		chkfm.show_css(obj+'_cc',4,0);
		if(!empty(txt))$(obj+'_cc').innerHTML=txt;
		else $(obj+'_cc').innerHTML="";
		try{$(obj).style.cssText=chkfm.arg[k].css
		}catch(e){};
	},
	enter:function(obj,k){//进入
		chkfm.show_css(obj+'_cc',2);
		if(chkfm.arg[k])$(obj+'_cc').innerHTML=chkfm.arg[k].info;
		$(obj).style.border="1px #FC3 solid";
	},
	keyin:function(obj){//输入
		$(obj).style.border="1px #158545 solid";
	},
	ini:function(fm,fid){
		var pobj="";
		for(var k in chkfm.arg){
			if(fid!=undefined&&chkfm.arg[k]['obj']!=fid)continue;
			if($(chkfm.arg[k]['obj'])==null)continue;
			if($(chkfm.arg[k]['obj']).getAttribute("type")=='hidden')continue;
			if(chkfm.arg[k]['readonly']){
				$(chkfm.arg[k]['obj']).disabled=true;
				continue;
			}
			$(chkfm.arg[k]['obj']).setAttribute("pno",k);
			if(chkfm.arg[k]['min']>0){
				if(!empty(chkfm.arg[k]['error']['min']))chkfm.arg[k]['error']['min']=chkfm.arg[k]['error']['min'].replace('\d',chkfm.arg[k]['min']);
				else chkfm.arg[k]['error']['min']=chkfm['msg']['min'].replace('\d',chkfm.arg[k]['min']);
			}
			if(chkfm.arg[k]['max']>0){
				if(!empty(chkfm.arg[k]['error']['max']))chkfm.arg[k]['error']['max']=chkfm.arg[k]['error']['max'].replace('\d',chkfm.arg[k]['max']);
				else chkfm.arg[k]['error']['max']=chkfm['msg']['max'].replace('\d',chkfm.arg[k]['max']);
				$(chkfm.arg[k]['obj']).maxLength=chkfm.arg[k]['max'];
				if($(chkfm.arg[k]['sobj'])!=null)$(chkfm.arg[k]['sobj']).maxLength=chkfm.arg[k]['max'];
			}
			chkfm.arg[k]['error']['empty']=!empty(chkfm.arg[k]['error']['empty'])?chkfm.arg[k]['error']['empty']:chkfm.msg.empty;
			chkfm.arg[k]['error']['nosafe']=!empty(chkfm.arg[k]['error']['nosafe'])?chkfm.arg[k]['error']['nosafe']:chkfm.msg.nosafe
			chkfm.arg[k]['error']['equ']=!empty(chkfm.arg[k]['error']['equ'])?chkfm.arg[k]['error']['equ']:chkfm.msg.equ;
			chkfm.arg[k]['error']['once']=!empty(chkfm.arg[k]['error']['once'])?chkfm.arg[k]['error']['once']:chkfm.msg.once;
			chkfm.arg[k]['error']['unonce']=!empty(chkfm.arg[k]['error']['unonce'])?chkfm.arg[k]['error']['unonce']:chkfm.msg.unonce;
			chkfm.arg[k]['error']['msg']=!empty(chkfm.arg[k]['error']['msg'])?chkfm.arg[k]['error']['msg']:chkfm.msg.msg;
			
			if($(chkfm.arg[k]['obj']+'_cc')==null){
				tmp=$C("span");
				tmp.id=chkfm.arg[k]['obj']+'_cc';
				tmp.innerHTML=chkfm.arg[k]['info'];
				insertAfter(tmp,$(chkfm.arg[k]['obj']));
				chkfm.show_css(tmp.id,1);
			}else{
				chkfm.show_css(chkfm.arg[k]['obj']+'_cc',1);
				$(chkfm.arg[k]['obj']+'_cc').innerHTML=chkfm.arg[k]['info'];
			}
			chkfm.arg[k].css=$(chkfm.arg[k]['obj']).style.cssText;
			$(chkfm.arg[k]['obj']).onfocus=function(){
				var no=this.getAttribute('pno');
				chkfm.enter(this.id,no);
			}
			$(chkfm.arg[k]['obj']).onkeypress=function(){
				var no=this.getAttribute('pno');
				if(this.value.length<=0)chkfm.keyin(this.id,no);
			}
			if(!empty(chkfm.arg[k]['strlen'])){
				$(chkfm.arg[k]['obj']).onkeydown=function(){
					chkfm.strlen(this);
				}
				$(chkfm.arg[k]['obj']).onkeyup=function(){
					chkfm.strlen(this);
				}
			}
			$(chkfm.arg[k]['obj']).onblur=function(){
				var no=this.getAttribute('pno');
				chkfm[chkfm.arg[no]['chktype']](chkfm['arg'][no]);
				if(chkfm.submited)chkfm.pass(this.id,no);
				no=null;
			}
			if(!empty(chkfm.arg[k]['sobj'])){
				$(chkfm.arg[k]['sobj']).setAttribute("pno",k);
				if($(chkfm.arg[k]['sobj']+'_cc')==null){
					tmp=$C("span");
					tmp.id=chkfm.arg[k]['sobj']+'_cc';
					tmp.innerHTML="";
					insertAfter(tmp,$(chkfm.arg[k]['sobj']));
				}
				$(chkfm.arg[k]['sobj']).onfocus=function(){
					if(this.value.length<=0)chkfm.enter(this.id);
				}
				$(chkfm.arg[k]['sobj']).onkeypress=function(){
					if(this.value.length<=0)chkfm.keyin(this.id);
				}
				$(chkfm.arg[k]['sobj']).onblur=function(){
					var no=this.getAttribute('pno');
					chkfm[chkfm.arg[no]['chktype']](chkfm['arg'][no]);
					if(chkfm.submited)chkfm.pass(this.id,no);
					no=null;
				}
			}
		}
		$(fm).onsubmit=function(){
			if(!chkfm.submited)return false;
			chkfm.submited=chkfm.func();
			for(var k in chkfm.arg){
				if($(chkfm.arg[k]['obj'])==null)continue;
				if(!chkfm[chkfm.arg[k]['chktype']](chkfm['arg'][k]))break;//alert(chkfm.arg[k]['obj']+"||"+chkfm.arg[k]['chktype']);
			}
			if(!chkfm.submited)return false;
			else return true;
		}
	},
	str:function(arg){
		chkfm.submited=true;
		$(arg.obj).value=trim($(arg.obj).value);
		if(arg.mastchk||(!arg.mastchk&&!empty($(arg.obj).value))){
			if(arg.mastchk&&empty($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['empty']);//非空
			if(arg.issafe&&!safe($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['nosafe']);//非安全
			if(arg.min>0&&$(arg.obj).value.toString().length<arg.min)return chkfm.show_err(arg.obj,arg['error']['min']);//字数不得小于
			if(arg.max>0&&$(arg.obj).value.toString().length>arg.max)return chkfm.show_err(arg.obj,arg['error']['max']);//字数不得大于
			if(!arg.disabled&&arg.chkonce)chkfm.chkonce(arg.obj,$(arg.obj).value,arg);//验证唯一
		}//if
		return true;
	},
	enstr:function(arg){
		chkfm.submited=true;
		$(arg.obj).value=trim($(arg.obj).value);
		if(arg.mastchk||(!arg.mastchk&&!empty($(arg.obj).value))){
			if(arg.mastchk&&empty($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['empty']);//非空
			if(arg.issafe&&!ensafe($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['nosafe']);//非安全
			if(arg.min>0&&$(arg.obj).value.toString().length<arg.min)return chkfm.show_err(arg.obj,arg['error']['min']);//字数不得小于
			if(arg.max>0&&$(arg.obj).value.toString().length>arg.max)return chkfm.show_err(arg.obj,arg['error']['max']);//字数不得大于
			if(!arg.disabled&&arg.chkonce)chkfm.chkonce(arg.obj,$(arg.obj).value,arg);//验证唯一
		}//if
		return true;
	},
	pwd:function(arg){
		chkfm.submited=true;
		$(arg.obj).value=trim($(arg.obj).value);
		if(arg.mastchk||(!arg.mastchk&&!empty($(arg.obj).value))){
			if(arg.mastchk&&empty($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['empty']);//非空
			if(arg.issafe&&!safe($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['nosafe']);//非安全
			if(arg.min>0&&$(arg.obj).value.toString().length<arg.min)return chkfm.show_err(arg.obj,arg['error']['min']);//字数不得小于
			if(arg.max>0&&$(arg.obj).value.toString().length>arg.max)return chkfm.show_err(arg.obj,arg['error']['max']);//字数不得大于
		}
		chkfm.pass(arg.obj,$(arg.obj).getAttribute('pno'));
		$(arg.sobj).value=trim($(arg.sobj).value);
		if(arg.mastchk||(!arg.mastchk&&!empty($(arg.sobj).value))){
			if(arg.mastchk&&empty($(arg.sobj).value))return chkfm.show_err(arg.sobj,arg['error']['empty']);//非空
			if(arg.issafe&&!safe($(arg.sobj).value))return chkfm.show_err(arg.sobj,arg['error']['nosafe']);//非安全
			if(arg.min>0&&$(arg.sobj).value.toString().length<arg.min)return chkfm.show_err(arg.sobj,arg['error']['min']);//字数不得小于
			if(arg.max>0&&$(arg.sobj).value.toString().length>arg.max)return chkfm.show_err(arg.sobj,arg['error']['max']);//字数不得大于
			if($(arg.obj).value!==$(arg.sobj).value)return chkfm.show_err(arg.sobj,arg['error']['equ']);//非等于
		}
		chkfm.pass(arg.sobj,$(arg.sobj).getAttribute('pno'));
		return true;
	},
	mail:function(arg){
		chkfm.submited=true;
		$(arg.obj).value=trim($(arg.obj).value);
		if(arg.mastchk||(!arg.mastchk&&!empty($(arg.obj).value))){
			if(arg.mastchk&&empty($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['empty']);//非空
			if(arg.issafe&&!safe($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['nosafe']);//非安全
			if(!isMail($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['msg']);//非邮件
			if(!arg.disabled&&arg.chkonce)chkfm.chkonce(arg.obj,$(arg.obj).value,arg);//验证唯一
		}
		return true;
	},
	int:function(arg){
		chkfm.submited=true;
		$(arg.obj).value=trim($(arg.obj).value);
		if(arg.mastchk||(!arg.mastchk&&!empty($(arg.obj).value))){
			if(arg.mastchk&&empty($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['empty']);//非空
			if(arg.issafe&&!safe($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['nosafe']);//非安全
			if(!isInt($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['msg']);//非整数
			if(arg.min>0&&parseInt($(arg.obj).value)<arg.min)return chkfm.show_err(arg.obj,arg['error']['min']);//字数不得小于
			if(arg.max>0&&parseInt($(arg.obj).value)>arg.max)return chkfm.show_err(arg.obj,arg['error']['max']);//字数不得大于
		}
		return true;
	},
	float:function(arg){
		chkfm.submited=true;
		$(arg.obj).value=trim($(arg.obj).value);
		if(arg.mastchk||(!arg.mastchk&&!empty($(arg.obj).value))){
			if(arg.mastchk&&empty($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['empty']);//非空
			if(arg.issafe&&!safe($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['nosafe']);//非安全
			if(!isFloat($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['msg']);//非小数
			if(arg.min>0&&parseFloat($(arg.obj).value)<arg.min)return chkfm.show_err(arg.obj,arg['error']['min']);//字数不得小于
			if(arg.max>0&&parseFloat($(arg.obj).value)>arg.max)return chkfm.show_err(arg.obj,arg['error']['max']);//字数不得大于
		}
		return true;
	},
	mun:function(arg){
		chkfm.submited=true;
		$(arg.obj).value=trim($(arg.obj).value);
		if(arg.mastchk||(!arg.mastchk&&!empty($(arg.obj).value))){
			if(arg.mastchk&&empty($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['empty']);//非空
			if(arg.issafe&&!safe($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['nosafe']);//非安全
			if(arg.min>0&&parseFloat($(arg.obj).value)<arg.min)return chkfm.show_err(arg.obj,arg['error']['min']);//字数不得小于
			if(arg.max>0&&parseFloat($(arg.obj).value)>arg.max)return chkfm.show_err(arg.obj,arg['error']['max']);//字数不得大于
			if(!isNum($(arg.obj).value))return chkfm.show_err(arg.obj,arg['error']['msg']);//非数字
		}
		return true;
	},
	chkonce:function(filed,srt,arg){
		var regchk={value:'action='+(!empty(arg.action)?arg.action:'')+'&fileds='+filed+'&values='+srt,
		callBack:function(t){
			if(parseInt(t)==1){
				chkfm.pass(arg.obj,$(arg.obj).getAttribute('pno'),arg['error']['once']);
				chkfm.submited=true;
			}else{
				chkfm.show_err(arg.obj,arg['error']['unonce']);
				chkfm.submited=false;
			}
		}}
		if(!empty(arg.ajaxurl)) mAjax(arg.ajaxurl,filed,regchk);
		else mAjax(chkfm.ajaxurl,filed,regchk);
	}
}
