//异步验证验证码

//初始化异步基本信息
var xmlHttp;

function createXMLHttpRequest() { 
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
}
//异步验证用户名是否可用
function checkAuthCode(authCodeId){
	var authCode = document.getElementById(authCodeId).value;
	//authCode = authCode.trim();
	//验证昵称格式是否正确
	if(authCode == ''){
		showIdMsg(authCodeId,'验证码不能为空！',false);
		return false;
	}else if(authCode.length!=4){
		showIdMsg(authCodeId,'验证码长度错误！',false);
		return false;
	}
	//清空消息
	document.getElementById(authCodeId+'Info').innerHTML = '';
	
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChangeAuthCode;
	var url = "/include/members/validateMembersAuthCode.htm?authCode=" + authCode;
	xmlHttp.open("POST", url, true);
	xmlHttp.send('');
}

//结果处理程序
function handleStateChangeAuthCode() {
	//进度logo
	if(xmlHttp.readyState == 1){
		document.getElementById('authCodeState').style.display = '';
	}
	if(xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200){
			document.getElementById('authCodeState').style.display = 'none';
			//得到数据
			var xmlData = xmlHttp.responseXML; 
			//alert('xmlData = ' + xmlData);
			// 取得XML文档的根
            var root = xmlData.documentElement;      
            //alert('root = ' + root);
            // 取得<isSuccess>结果
			var authSuccess = root.getElementsByTagName("authSuccess")[0].firstChild.nodeValue;
			// 取得<msg>结果
			var msg = root.getElementsByTagName("authmsg")[0].firstChild.nodeValue;
			//显示消息
			if(authSuccess == 'true'){
				msg = "<img src='/images/main/true.gif' alt='输入正确' /> "+msg;
			}else{
				msg = "<img src='/images/main/false.gif' alt='输入错误' /> "+msg;
			}
			document.getElementById('authCodeInfo').innerHTML =  msg ;
		}
	}
}