function fm_ini(){
	var fm,i,j
	for(i=0;i<document.forms.length;i++){
		fm=document.forms[i]
		for(j=0;j<fm.length;j++){
			if((fm[j].alt+"").indexOf(":")==-1)
				continue			
			fm[j].onblur=function(){
				this.style.background=(tx_chk(this)==true)?'#EEEEEE':'#FF0000';
				(tx_chk(this)==true)?oo("chk_"+this.name).style.color="blue":oo("chk_"+this.name).style.color="red";
			}
			fm[j].onfocus=function(){this.style.background='#CCFF99'}
		}
	}
}
function fm_chk(fm){
	var isPass=true;
	for(var i=0;i<fm.length;i++){
		if((fm[i].alt+"").indexOf(":")==-1) {
			continue;}
		if(!tx_chk(fm[i])){
			isPass=false;
			fm[i].style.background='#FF0000';
		} else fm[i].style.background='#FFFFFF';
	}
	if(isPass){
		return true;
	}else{
		oo("Error").innerHTML = "您填写的信息有误，请根据页面红字更改！";
		return false;
	}
}

function GetO(){
    var ajax=false; 
    try { 
    	ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
    } catch (e) { 
   	 	try { 
    		ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
    	} catch (E) { 
    		ajax = false; 
    	} 
    }
    if (!ajax && typeof XMLHttpRequest!='undefined') { 
    	ajax = new XMLHttpRequest(); 
    } 
    return ajax;
}

function getMyHTML(serverPage) { 
var ajax = GetO();
var rr='';

    ajax.open("GET", serverPage, false); 
    ajax.onreadystatechange = function() { 
        if (ajax.readyState == 4 && ajax.status == 200) { 
			rr=ajax.responseText;
        }
    } 
	
    ajax.send(null);
	return rr;
}
function checkuser(val){
	return getMyHTML("checkuserdata.php?mathrandid="+Math.random()*1000000+"&act=checkuser&regname="+val);
}
function checkemal(val){
	return getMyHTML("checkuserdata.php?mathrandid="+Math.random()*1000000+"&act=checkemail&email="+val);
}
function chkuser(val) {alert(val);
	if(checkuser(val)=='sorry'){
		document.getElementById('chk_username').innerHTML="Username exists!";
		document.getElementById('chk_username').style.display="";
	} else {
		document.getElementById('chk_username').style.display="none";
		document.getElementById('username_true').innerHTML="<font color='#00FF00'>√</font>";
		document.getElementById('username_true').style.display="";
}
}
function chkemail(val) {
	if(checkuser(val)=='sorry'){
		document.getElementById('chk_email').innerHTML="Email exists!";
		document.getElementById('chk_email').style.display="";
	} else {
		document.getElementById('chk_email').style.display="none";
		document.getElementById('email_true').innerHTML="<font color='#00FF00'>√</font>";
		document.getElementById('email_true').style.display="";
}
}
function tx_chk(obj){
	var name,key,val=obj.value,oShow=oo("chk_"+obj.name),trueshow=oo(obj.name+"_true")
	name=obj.alt.slice(0,obj.alt.indexOf(":"))
	key="/"+obj.alt.slice(obj.alt.indexOf(":")+1)+"/"
	//oo("chk_"+obj.name).style.display="none"
	if(key.indexOf("/null/")>-1&&val==""){
		name = (name=="password")?"密码":name;
		oShow.innerHTML="请输入"+name
		oShow.style.display=""
		return false
	}
	if(key.indexOf("/limitone/")>-1){
		if(document.getElementById("name").value == '' && document.getElementById("ename").value == '') {
			oShow.innerHTML="中文名称和英文名称至少输入一个。"
			oShow.style.display=""
			return false
		}
	}
	if(key.indexOf("/checkemal/")>-1&&(checkemal(val)=='sorry')){
		oShow.innerHTML="Email:"+val+"已注册"
		oShow.style.display=""
		return false
	}
	if(key.indexOf("/checkuser/")>-1&&(checkuser(val)=='sorry')){
		oShow.innerHTML="昵称已存在"
		oShow.style.display=""
		return false
	}
	if(key.indexOf("/checkpwd/")>-1&&(checkpwd(val)=='sorry')){
		oShow.innerHTML="您输入的密码不正确，请重试！"
		oShow.style.display=""
		return false
	}
	if(key.indexOf("/4-20/")>-1&&(strLen(val)<4||strLen(val)>20)){
		oShow.innerHTML="长度必须4-20位"
		oShow.style.display=""
		return false
	}
	if(key.indexOf("/illegal/")>-1&&(/>|<|,|\[|\]|\{|\}|\?|\/|\+|=|\||\'|\\|\"|:|;|\~|\!|\@|\#|\*|\$|\%|\^|\&|\(|\)|`/i).test(val)){
		oShow.innerHTML="请勿使用特殊字符"
		oShow.style.display=""
		return false
	}
	if(key.indexOf("/space/")>-1&&val.indexOf(" ")>-1){
		oShow.innerHTML="不能包含空格符"
		oShow.style.display=""
		return false
	}
	if(key.indexOf("/allnum/")>-1&&val!=""&&!isNaN(val)){
		oShow.innerHTML="不可以全是数字"
		oShow.style.display=""
		return false
	}
	if(key.indexOf("/capitalization/")>-1&&/[A-Z]/.test(val)){
		oShow.innerHTML="不能有大写字母"
		oShow.style.display=""
		return false
	}
	if(key.indexOf("/letter&num/")>-1&&!/^[a-zA-Z0-9_]*$/.test(val)){
		oShow.innerHTML="只能为英文和数字及_"
		oShow.style.display=""
		return false
	}
	if(key.indexOf("/checkphone/")>-1&&!/^[0-9_\(\)+\-]*$/.test(val)){
		oShow.innerHTML="电话号码格式不正确"
		oShow.style.display=""
		return false
	}
	if(key.indexOf("/SBC/")>-1&&/[ａ-ｚ０-９]/.test(val)){
		oShow.innerHTML="不能有全角字符"
		oShow.style.display=""
		return false
	}
	if(key.indexOf("/密码查询问题/")>-1&&val==''){
		oShow.innerHTML="不能有全角字符"
		oShow.style.display=""
		return false
	}
	if(key.indexOf("/chinese/")>-1&&escape(val).indexOf("%u")>-1){
		oShow.innerHTML="不能有汉字"
		oShow.style.display=""
		return false
	}
	if(key.indexOf("/end_/")>-1&&val.slice(val.length-1)=="_"){
		oShow.innerHTML="下划线不能在最后"
		oShow.style.display=""
		return false
	}
	if(key.indexOf("/repwd/")>-1){
		if(obj.form['password'].value!=val){
			oShow.innerHTML="两次密码不一致"
			oShow.style.display=""
			return false
		}
	}
	if(key.indexOf("/truemail/")>-1&&!(/^[a-z0-9_@\.-]+@([a-z0-9_-]+\.)+[a-z0-9_-]{2,3}$/.test(val))){
		oShow.innerHTML="Email格式不正确"
		oShow.style.display=""
		return false
	}
	if(key.indexOf("/need/")>-1 && obj.form[obj.name].checked!=true){
			oShow.innerHTML=name+"必须选择"
			oShow.style.display=""
			return false
	}
	if(key.indexOf("/select/")>-1&&val=="0"){
		oShow.innerHTML="请选择"+name
		oShow.style.display=""
		return false
	}
	if(key.indexOf("/updatepwd/")>-1){
		if((obj.form['oldpassword'].value && !obj.form['password'].value) || (!obj.form['oldpassword'].value && obj.form['password'].value)){
			oShow.innerHTML="<font color='#FF0000'>"+name+"</font>"
			oShow.style.display=""
			return false
		}
		if(obj.form['password'].value!=obj.form['repassword'].value){
			oShow.innerHTML="<font color='#FF0000'>新密码和确认密码不一致</font>"
			oShow.style.display=""
			return false
		}
	}
	trueshow.innerHTML="<font color='#00FF00'>√</font>";
	oShow.innerHTML="";
	return true
}
function strLen(key){
	var l=escape(key),len
	len=l.length-(l.length-l.replace(/\%u/g,"u").length)*4
	l=l.replace(/\%u/g,"uu")
	len=len-(l.length-l.replace(/\%/g,"").length)*2
	return len
}
function oo(obj){
	return document.getElementById(obj);
}
