
var userCheckStatus = false;
var aMsg = [];
aMsg[104] = "\u606d\u559c\uff0c\u8be5\u7528\u6237\u540d\u53ef\u4ee5\u4f7f\u7528";
function hballsUpdateCustomFormAjax(formName) {
	var allRight = 0;
	if (checkUserName("userName")) {
		allRight = allRight + 1;
	}
	if (checkPass("password")) {
		allRight = allRight + 1;
	}
	if (checkPass1("password1")) {
		allRight = allRight + 1;
	}
	if (checkEmail("email")) {
		allRight = allRight + 1;
	}
	if (checkQq("qq")) {
		allRight = allRight + 1;
	}
	if (userCheckStatus) {
		allRight = allRight + 1;
	}
	if (allRight == 6) {
		var pars2 = Form.serialize(formName);
	//	alert(pars2);
		var checkUser = new Ajax.Request("../supermarket/register.do", {method:"post", parameters:pars2, asynchronous:"false", onSuccess:setOk, onFailure:errMain});
	}
}


function setOk(originalRequest) {
	var sText = originalRequest.responseText;
	var aText = sText.split("\n");
	var aNewText = [];
	aText.each(function (tmp) {
		if (tmp != "" && tmp != "\r") {
			aNewText.push(tmp);
		}
	});
	aText = aNewText;
	if (parseInt(aText[0]) == 0) {
		error_info = '&nbsp;'+"\<img src='/supermarket/images/warning.gif' \/\>" +'&nbsp;'+"\u7528\u6237\u8f93\u5165\u7684\u9a8c\u8bc1\u7801\u9519\u8bef,\u8bf7\u91cd\u65b0\u8f93\u5165";
		fRefreshRandomNoClick();
		$("userCheckCode_errorInfo").innerHTML = error_info + "<br/>";
	}
	if (parseInt(aText[0]) == 5) {
		$("userCheckCode_errorInfo").innerHTML = "";
		$("customupdate").disabled = "true";
		$("refreshRandomNo").disabled = "true";
		//alert($("userName").value);
		alert("\u7528\u6237\u6ce8\u518c\u6210\u529f");
		redirect();
	}
}
function errMain(originalRequest) {
	alert("\u8bf7\u91cd\u65b0\u63d0\u4ea4");
	return false;
}
function redirect() {
//	alert($("userName").value);
	var UrlStr = "login.do?j_username=" + $("userName").value + "&j_password=" + $("password").value;
	location = UrlStr;
}


//检查密码
function checkPass(Name) {
	var needCheck = $F(Name);
	var error_info = "";
	var regex = /^.{6,20}$/;
	if (needCheck.length === 0) {
		error_info = '&nbsp;'+"\<img src='/supermarket/images/warning.gif' \/\>" +'&nbsp;'+"\u7528\u6237\u5bc6\u7801\u4e0d\u80fd\u4e3a\u7a7a";
		$(Name + "_errorInfo").innerHTML = error_info;
		return false;
	} else {
		if (regex.test(needCheck) === false) {
			error_info = '&nbsp;'+"\<img src='/supermarket/images/warning.gif' \/\>" +'&nbsp;'+"\u5bc6\u7801\u957f\u5ea6\u4e0d\u8db3\u516d\u4f4d";
			$(Name + "_errorInfo").innerHTML = error_info;
			return false;
		} else {
			if ($F(Name + "1").length === 0 || ($F(Name + "1") == (needCheck))) {
				$(Name + "_errorInfo").innerHTML = "";
				$("password1_errorInfo").innerHTML = "";
				return true;
			} else {
				error_info = '&nbsp;'+"\<img src='/supermarket/images/warning.gif' \/\>" +'&nbsp;'+"\u5bc6\u7801\u4e0e\u786e\u8ba4\u5bc6\u7801\u5fc5\u987b\u4e00\u81f4\uff01";
				$(Name + "_errorInfo").innerHTML = error_info;
				return false;
			}
		}
	}
}
function checkPass1(Name) {
	var needCheck = $F(Name);
	var error_info = "";
	var regex = /^.{6,20}$/;
	if (needCheck.length === 0) {
		error_info ='&nbsp;'+"\<img src='/supermarket/images/warning.gif' \/\>" +'&nbsp;'+ "\u7528\u6237\u5bc6\u7801\u4e0d\u80fd\u4e3a\u7a7a";
		$(Name + "_errorInfo").innerHTML = error_info;
		return false;
	} else {
		if (regex.test(needCheck) === false) {
			error_info = '&nbsp;'+"\<img src='/supermarket/images/warning.gif' \/\>" +'&nbsp;'+"\u5bc6\u7801\u957f\u5ea6\u4e0d\u8db3\u516d\u4f4d";
			$(Name + "_errorInfo").innerHTML = error_info;
			return false;
		} else {
			if ($F("password").length === 0 || ($F("password") == (needCheck))) {
				$(Name + "_errorInfo").innerHTML = "";
				$("password_errorInfo").innerHTML = "";
				return true;
			} else {
				error_info = '&nbsp;'+"\<img src='/supermarket/images/warning.gif' \/\>" +'&nbsp;'+"\u5bc6\u7801\u4e0e\u786e\u8ba4\u5bc6\u7801\u5fc5\u987b\u4e00\u81f4\uff01";
				$(Name + "_errorInfo").innerHTML = error_info;
				return false;
			}
		}
	}
}
function checkUserName(Name) {
	var needCheck = $F(Name);
	var error_info = "";
	var regex = /^[\x00-\xff]{3,20}$/;
	if (needCheck.length === 0) {
		error_info = '&nbsp;'+"\<img src='/supermarket/images/warning.gif' \/\>" +'&nbsp;'+"\u7528\u6237\u540d\u4e0d\u80fd\u4e3a\u7a7a";
		$(Name + "_errorInfo").innerHTML = error_info;
		return false;
	} else {
		if (regex.test(needCheck) === false) {
			error_info = '&nbsp;'+"\<img src='/supermarket/images/warning.gif' \/\>" +'&nbsp;'+"用户名只能由字母和数字组成";
			$("userName_Info").innerHTML="";
			$(Name + "_errorInfo").innerHTML = error_info;
			return false;
		}
		 else {
			$(Name + "_errorInfo").innerHTML = "";
			if (!userCheckStatus) {
				userCheckStatus = false;
				var parms='username='+needCheck;
				new Ajax.Request("checkuser.do" , {method:'post',parameters:parms, onSuccess:checkUsernameReport, onFailure:errMain});
			}
			return true;
		}
	}
}
function checkUsernameReport(originalRequest) {
	var sText = originalRequest.responseText;
	var aText = sText.split("\n");
	var aNewText = [];
	aText.each(function (tmp) {
		if (tmp != "" && tmp != "\r") {
			aNewText.push(tmp);
		}
	});
	aText = aNewText;
	if (!isNaN(aText[0])) {
		if (parseInt(aText[0]) == 104) {
			$("userName_Info").innerHTML = aMsg[parseInt(aText[0])];
			userCheckStatus = true;
			return true;
		}
		if (parseInt(aText[0]) == 5) {
			$("userName_Info").innerHTML = "\u4f60\u9009\u62e9\u7684\u7528\u6237\u540d\u5df2\u7ecf\u88ab\u4f7f\u7528,\u4f60\u6216\u53ef\u4f7f\u7528" + (aText.length == 2 ? aText[1] : "");
			return false;
		} else {
			$("userName_Info").innerHTML = "";
			return false;
		}
	}
}
	



function checkEmail(email) {
	var regex = /^(([\-\w]+)\.?)+@(([\-\w]+)\.?)+\.[a-zA-Z]{2,4}$/;
	var needCheck = $F(email);
	var error_info = "";
	if (needCheck.length === 0) {
		if (email === "msn") {
			$(email + "_errorInfo").innerHTML = "";
			return true;
		} else {
			error_info = '&nbsp;'+"\<img src='/supermarket/images/warning.gif' \/\>" +'&nbsp;'+"E-Mail\u5730\u5740\u4e0d\u80fd\u4e3a\u7a7a";
			$(email + "_errorInfo").innerHTML = error_info;
			return false;
		}
	} else {
		if (regex.test(needCheck) === false) {
			error_info ='&nbsp;'+"\<img src='/supermarket/images/warning.gif' \/\>" +'&nbsp;'+ "E-Mail\u683c\u5f0f\u4e0d\u6b63\u786e";
			$(email + "_errorInfo").innerHTML = error_info;
			return false;
		} else {
			$(email + "_errorInfo").innerHTML = "";
			return true;
		}
	}
}


function checkQq(NumFieldInput) {
	var needCheck = $F(NumFieldInput);
	var error_info = "";

	var regex = /^\d{4,20}$/;
	if (needCheck.length === 0) {
		$(NumFieldInput + "_errorInfo").innerHTML = "";
		return true;
	} else {
		if (regex.test(needCheck) === false) {
			error_info = '&nbsp;'+"\<img src='/supermarket/images/warning.gif' \/\>" +'&nbsp;'+"QQ\u53f7\u7801\u4f4d\u6570\u4e0d\u8db3\u6216\u5b58\u5728\u975e\u6570\u5b57\u5b57\u7b26";
			$(NumFieldInput + "_errorInfo").innerHTML = error_info;
			return false;
		} else {
			$(NumFieldInput + "_errorInfo").innerHTML = "";
//checkFormOfCustomForm(Name);
			return true;
		}
	}
}


function fRefreshRandomNoClick() {
	var oImg = $("randomNoImg");
	if (!oImg) {
		oImg = document.createElement("IMG");
		oImg.setAttribute("alt", "\u5c06\u56fe\u4e2d\u7684\u6587\u5b57\u586b\u5230\u5de6\u8fb9\u8f93\u5165\u6846\u4e2d");
		oImg.setAttribute("width", "106");
		oImg.setAttribute("height", "28");
		oImg.setAttribute("id", "randomNoImg");
		var oSpan = document.createElement("SPAN");
		$("checkcode").appendChild(oImg);
		$("checkcode").appendChild(oSpan);
	}
	dt=new Date();
		$('randomNoImg').src ='getImg.do?t='+dt+Math.random();
}


function checkNameForComment(Name){
var needCheck=$F(Name);
var error_info='';
if (needCheck.length===0){
error_info='&nbsp;'+"\<img src='/supermarket/images/warning.gif' \/\>" +'&nbsp;'+'用户的呢称不能为空';
$(Name+'_errorInfo').innerHTML=error_info;
return false;
}
if (needCheck.length>10){
error_info='&nbsp;'+"\<img src='/supermarket/images/warning.gif' \/\>" +'&nbsp;'+'用户的呢称太长，不超过十个字符';
$(Name+'_errorInfo').innerHTML=error_info;
return false;
}
else{
$(Name+'_errorInfo').innerHTML='';
//checkFormOfCustomForm(Name);
return true;
}
}

function checkNameForCommentContent(Name){
var needCheck=$F(Name);
var error_info='';
if (needCheck.length===0){
error_info='&nbsp;'+"\<img src='/supermarket/images/warning.gif' \/\>" +'&nbsp;'+'留言内容不能为空';
$(Name+'_errorInfo').innerHTML=error_info;
return false;
}
if (needCheck.length>200){
error_info='&nbsp;'+"\<img src='/supermarket/images/warning.gif' \/\>" +'&nbsp;'+'留言内容太长，不超过200个字符';
$(Name+'_errorInfo').innerHTML=error_info;
return false;
}
else{
$(Name+'_errorInfo').innerHTML='';
//checkFormOfCustomForm(Name);
return true;
}
}



function hballsCommentSubmitFormAjax(formName) {
	var allRight = 0;
	if (checkNameForComment("userWhoComment")) {
		allRight = allRight + 1;
	}
	if (checkEmail("userWhoCommentEmail")) {
		allRight = allRight + 1;
	}
	if (checkNameForComment("userComment")) {
		allRight = allRight + 1;
	}
	if (allRight == 3) {
		var pars2 = Form.serialize(formName);
		//alert(pars2);
		var checkUser = new Ajax.Request("/supermarket/commentSubmit.do", {method:"post", parameters:pars2, asynchronous:"false", onSuccess:commentOk, onFailure:errMain});
	}
}

function commentOk(originalRequest) {
	var sText = originalRequest.responseText;
	var aText = sText.split("\n");
	var aNewText = [];
	aText.each(function (tmp) {
		if (tmp != "" && tmp != "\r") {
			aNewText.push(tmp);
		}
	});
	aText = aNewText;
	if (parseInt(aText[0]) == 0) {
	
	}
	if (parseInt(aText[0]) == 5) {
		
		alert("您的留言已经被记录。");
		redirect();
	}
}