//************************************************************
//  文件：Ajax处理函数集合
//************************************************************

//显示信息
function ajaxdisplay(o) {
	$(o).style.display = "block";
}

//隐藏信息
function ajaxhidden(o) {
	$(o).style.display = "none";
}

//创建XMLHttpRequest对象
function createajax() {
	var xmlhttp;
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			try {
				xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {}
		}
	}
	return xmlhttp;
}

//检测验证码输入的信息
function codecheck(i, o) {
	var code = $(i).value;
	var xmlhttp = createajax();
	xmlhttp.onreadystatechange = function() {
		if (4 == xmlhttp.readyState) {
			if (200 == xmlhttp.status) {
				$(o).innerHTML = xmlhttp.responseText;
			} else {
				alert("异步提交数据时发生一个错误。");
			}
		}
	}
	xmlhttp.open("post","ajax_check.asp",true);
	xmlhttp.setRequestHeader('content-type','application/x-www-form-urlencoded');
	xmlhttp.send("act=code&usercode=" + escape(code) + "&n=" + Math.random());
}

//检测注册输入的信息
function regcheck(i, o) {
	ajaxhidden(o);
	var username = document.register_form["username"].value;
	var userpass = document.register_form["userpass"].value;
	var userconfirm = document.register_form["userconfirm"].value;
	var useremail = document.register_form["useremail"].value;
	var userweb = document.register_form["userweb"].value;
	var userurl = document.register_form["userurl"].value;
	var userqq = document.register_form["userqq"].value;
	var xmlhttp = createajax();
	xmlhttp.onreadystatechange = function() {
		if (4 == xmlhttp.readyState) {
			if (200 == xmlhttp.status) {
				$("de_" + o).innerHTML = xmlhttp.responseText;
			} else {
				alert("异步提交数据时发生一个错误。");
			}
		}
	}
	xmlhttp.open("post","ajax_check.asp",true);
	xmlhttp.setRequestHeader('content-type','application/x-www-form-urlencoded');
	xmlhttp.send("act=" + escape(i) + "&username=" + escape(username) + "&userpass=" + escape(userpass) + "&userconfirm=" + escape(userconfirm) + "&useremail=" + escape(useremail) + "&userweb=" + escape(userweb) + "&userurl=" + escape(userurl) + "&userqq=" + escape(userqq) + "&n=" + Math.random());
}

//检测找回密码输入的信息
function recovercheck(i, o) {
	ajaxhidden(o);
	var userpass = document.recover_form["userpass"].value;
	var userconfirm = document.recover_form["userconfirm"].value;
	var xmlhttp = createajax();
	xmlhttp.onreadystatechange = function() {
		if (4 == xmlhttp.readyState) {
			if (200 == xmlhttp.status) {
				$("de_" + o).innerHTML = xmlhttp.responseText;
			} else {
				alert("异步提交数据时发生一个错误。");
			}
		}
	}
	xmlhttp.open("post","ajax_check.asp",true);
	xmlhttp.setRequestHeader('content-type','application/x-www-form-urlencoded');
	xmlhttp.send("act=" + escape(i) + "&userpass=" + escape(userpass) + "&userconfirm=" + escape(userconfirm) + "&n=" + Math.random());
}

//检测个人资料输入的信息
function modifyinfocheck(i, o) {
	ajaxhidden(o);
	var userweb = document.modifyinfo_form["userweb"].value;
	var userurl = document.modifyinfo_form["userurl"].value;
	var userqq = document.modifyinfo_form["userqq"].value;
	var xmlhttp = createajax();
	xmlhttp.onreadystatechange = function() {
		if (4 == xmlhttp.readyState) {
			if (200 == xmlhttp.status) {
				$("de_" + o).innerHTML = xmlhttp.responseText;
			} else {
				alert("异步提交数据时发生一个错误。");
			}
		}
	}
	xmlhttp.open("post","ajax_check.asp",true);
	xmlhttp.setRequestHeader('content-type','application/x-www-form-urlencoded');
	xmlhttp.send("act=" + escape(i) + "&userweb=" + escape(userweb) + "&userurl=" + escape(userurl) + "&userqq=" + escape(userqq) + "&n=" + Math.random());
}

//检测修改密码输入的信息
function modifypasscheck(i, o) {
	ajaxhidden(o);
	var userold = document.modifyinfo_form["userold"].value;
	var userpass = document.modifyinfo_form["userpass"].value;
	var userconfirm = document.modifyinfo_form["userconfirm"].value;
	var xmlhttp = createajax();
	xmlhttp.onreadystatechange = function() {
		if (4 == xmlhttp.readyState) {
			if (200 == xmlhttp.status) {
				$("de_" + o).innerHTML = xmlhttp.responseText;
			} else {
				alert("异步提交数据时发生一个错误。");
			}
		}
	}
	xmlhttp.open("post","ajax_check.asp",true);
	xmlhttp.setRequestHeader('content-type','application/x-www-form-urlencoded');
	xmlhttp.send("act=" + escape(i) + "&userold=" + escape(userold) + "&userpass=" + escape(userpass) + "&userconfirm=" + escape(userconfirm) + "&n=" + Math.random());
}

//处理提交的建议反馈
function ajax_advice() {
	var adviceid = $("adviceid").value;
	var advicestr = $("advicestr").value;
	var advicecode = $("advicecode").value;
	if (adviceid.length < 1) {
		alert("错误：\n请选择反馈问题类型。");
		return false;
	}
	if (advicestr.length < 1) {
		alert("错误：\n请填写要反馈的信息内容。");
		return false;
	}
	if (advicecode.length < 4) {
		alert("错误：\n请填写验证码。");
		return false;
	}
	var xmlhttp = createajax();
	xmlhttp.onreadystatechange = function() {
		if (4 == xmlhttp.readyState) {
			if (200 == xmlhttp.status) {
				if (xmlhttp.responseText == "err1") {
					alert("错误：\n请选择反馈问题类型。");
				}
				if (xmlhttp.responseText == "err2") {
					alert("错误：\n请填写要反馈的信息内容。");
				}
				if (xmlhttp.responseText == "err3") {
					alert("错误：\n请填写正确的验证码。");
				}
				if (xmlhttp.responseText == "err4") {
					alert("您提交的内容我们正在处理，请不要重复提交。");
					advice("none");
				}
				if (xmlhttp.responseText == "err5") {
					alert("您提交的内容请限制在 200 个汉字以内。");
				}
				if (xmlhttp.responseText == "ok") {
					alert("您提交的信息已经反馈给客服人员，感谢您的建议。");
					advice("none");
				}
			} else {
				alert("异步提交数据时发生一个错误。");
			}
		}
	}
	xmlhttp.open("post","ajax_check.asp",true);
	xmlhttp.setRequestHeader('content-type','application/x-www-form-urlencoded');
	xmlhttp.send("act=advice&adviceid=" + escape(adviceid) + "&advicestr=" + escape(advicestr) + "&advicecode=" + escape(advicecode) + "&n=" + Math.random());
	}