function isemail( str ){ 
    var myReg = /^[-_A-Za-z0-9]+@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$/; 
    if(myReg.test(str)){
	    return true; 
	} 
    return false; 
} 

function checkname(key){
    key=key.replace(/(^\s*)|(\s*$)/g,"");
	if(key==''){
	    alert('用户名不能为空');
		document.getElementById('test1').innerHTML='<font color="red">不能为空</font>';
		return;
	}
	if(key.length<4){
	    alert('用户名不能短于4个字符');
		document.getElementById('test1').innerHTML='<font color="red">不合要求</font>';
		return;
	}
	if(key.length>32){
	    alert('用户名不能长于32个字符');
		document.getElementById('test1').innerHTML='<font color="red">不合要求</font>';
		return;
	}
	if(key.charAt(0)=='0' || key.charAt(0)-0==key.charAt(0)){
	    alert('用户名不能以数字开头');
		document.getElementById('test1').innerHTML='<font color="red">不合要求</font>';
		return;
	}
	var url = 'checkkey.php?type=name';
    xmlHttp.open('POST', url, true);
    xmlHttp.onreadystatechange = function(){
	    if (xmlHttp.readyState == 4) {
            if (xmlHttp.status == 200) {
				if(xmlHttp.responseText){
					document.getElementById('test1').innerHTML='<font color="red">不合要求</font>';
				}else{
					document.getElementById('test1').innerHTML='<font color="green">可以使用</font>';
				}
	   	    }
	    }
	};
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
    xmlHttp.send('id='+key);
}

function checkpwd(key){
	if(key==''){
	    alert('密码不能为空');
		return;
	}
	if(key.length<6){
	    alert('密码不能短于6个字符');
		return;
	}
	var url = 'checkkey.php?type=pwd';
    xmlHttp.open('POST', url, true);
    xmlHttp.onreadystatechange = function(){
	    if (xmlHttp.readyState == 4) {
            if (xmlHttp.status == 200) {
				document.getElementById('test3').innerHTML=xmlHttp.responseText;
	   	    }
	    }
	};
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
    xmlHttp.send('id='+encodeURIComponent(key));
}

function checkpwd2(key){
    if(key==document.registerform.elements['password'].value){
		document.getElementById('fg').innerHTML='<font color="green">通过检验</font>';
	}else{
	    alert('验证密码应与之前所设密码保持一致！');
		document.registerform.elements['password2'].value='';
		document.getElementById('fg').innerHTML='<font color="red">不符合</font>';
	}
}

function checkmail(key){
    key=key.replace(/(^\s*)|(\s*$)/g,"");
	if(key==''){
	    alert('邮箱不能为空！');
		document.getElementById('test2').innerHTML='<font color="red">不符合</font>';
		return;
	}
	if(!isemail(key)){
	    alert('非法邮件格式！');
		document.getElementById('test2').innerHTML='<font color="red">不符合</font>';
		return;
	}
	var url = 'checkkey.php?type=mail';
    xmlHttp.open('POST', url, true);
    xmlHttp.onreadystatechange = function(){
	    if (xmlHttp.readyState == 4) {
            if (xmlHttp.status == 200) {
			    document.getElementById('test2').innerHTML=xmlHttp.responseText;
	   	    }
	    }
	};
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
    xmlHttp.send('id='+key);
}

function checkform(){
    return true;
}

