FMJS.ready(function()
	{
		G('#id_useremail').focus( function() 
			{ 
				G("#email_logo").hide();
				G('#help_useremail').show(); 
			}
		);
		G('#id_username').focus( function() 
			{ 
				G("#name_logo").hide();
				G('#help_username').show(); 
			} 
		);
		G('#id_fullname').focus( function() 
			{ 
				G("#fullname_logo").hide();
				G('#help_fullname').show(); 
			} 
		);
		G('#id_password').focus( function() 
			{ 
				G("#pwd_logo").hide();
				G('#help_password').show(); 
			}
		);
		G('#id_password2').focus( function() 
			{ 
				G("#pwd2_logo").hide();
				G('#help_password2').show();
			} 
		);
		G('#id_invcode').focus( function() 
			{ 
				G("#inv_logo").hide();
				G('#help_invcode').show();
			} 
		);
		G('#id_useremail').blur( function() 
			{ 
				G('#help_useremail').hide();
				var iCode = validateEmail();
				if(iCode != -1 && iCode != 0){
					G("#email_logo").show();
				}
				if(iCode == 0){
					ajaxValEmail();
				}
			} 
		);
		G('#id_username').blur( function() 
			{ 
				G('#help_username').hide();
				var iCode = validateUserName();
				if(iCode != -1 && iCode != 0){
					G("#name_logo").show();
				}
				if(iCode == 0){
					ajaxValUserName();
				}
			 } 
		 );
		G('#id_fullname').blur( function() 
			{ 
				G('#help_fullname').hide();
				var iCode = validateFullName();
				if(iCode != -1 && iCode != 0){
					G("#fullname_logo").show();
				}
			 } 
		 );
		G('#id_password').blur( function() 
			{ 
				G('#help_password').hide();
				var iCode = validatePassword();
				if(iCode != -1 && iCode != 0){
					G("#pwd_logo").show();
				}
			} 
		);
		G('#id_password2').blur( function() 
			{ 
				G('#help_password2').hide();
				var iCode = validatePassword2();
				if(iCode != -1 && iCode != 0){
					G("#pwd2_logo").show();
				}
			} 
		);
		G('#id_invcode').blur( function() 
			{ 
				G('#help_invcode').hide();
				var iCode = validateInv();
				if(iCode != -1 && iCode != 0){
					G("#inv_logo").show();
				}
				if(iCode == 0){
					ajaxValInv();
				}
			} 
		);
		G('#regFrm').submit(function()
			{
				if(onSubmitFrm()){
					return true;
				}else{
					G(document.documentElement)? G(document.documentElement).attr("scrollTop","0"):G(document.body).attr("scrollTop","0");
					G('#id_submit').attr("name","0");
					return false;
				}
			}
		);
		G('#id_changeCode').click(function()
			{
				changeVarCode();
			}
		);
		G('#id_submit').click(function()
			{
				var fg = G(this).attr("name");
				if(fg == 0){
					G(this).attr("name","1");
					G('#regFrm').submit();
				}
			}
		);
		var errorCode = G('#errorCode').val();
		if(!FM.String.isBlank(errorCode)){
			FM.MSG.showErrorMsg(errorCode);
		}
	}
);
function changeVarCode(){
	var url = "/f5/mwfm/uaccount?ctrl=vc&timeStamp=" + new Date().getTime();
	G('#id_varcode').val("");
	G('#id_varcode').focus();
	G("#img_varcode").attr("src",url);
}
//校验账号是否被注册function ajaxValUserName(){
	var strValue = G('#id_username').attr("value");
	var url   = "/f5/mwfm/uaccount?timeStamp=" + new Date().getTime();
	var param = "ctrl=ckun&username=" + encodeURIComponent(strValue);
	FMJS.postXML(url, param, function(xml){
		var iCode = G(xml).find("error_code").text();
		if(iCode != 0){
			G("#name_logo").show();
		}
	});
}
//已注册function ajaxValEmail(){
	var strValue = G('#id_useremail').attr("value");
	var url   = "/f5/mwfm/uaccount?timeStamp=" + new Date().getTime();
	var param = "ctrl=ck&useremail=" + escape(strValue);
	FMJS.postXML(url, param, function(xml){
		var iCode = G(xml).find("error_code").text();
		if(iCode != 0){
			G("#email_logo").show();
		}
	});
}
//校验Email
function validateEmail(){
	var strValue = G('#id_useremail').attr("value");
	//为空
	if(FM.String.isBlank(strValue)){
		return -1;
	}
	//不正确
	if(!FM.String.isEmail(strValue)){
		return 13103;
	}
	//过长
	if(FM.String.len(strValue) > FM.EnvParam.iEmailMax){
		return 13101;
	}
	//过短
	if(FM.String.len(FM.STRING.trim(strValue)) < FM.EnvParam.iEmailMin){
		return 13102;
	}
	
	return 0;
}
//已注册
function ajaxValInv(){
	var strValue = G('#id_invcode').attr("value");
	var url   = "/f5/mwfm/uaccount?timeStamp=" + new Date().getTime();
	var param = "ctrl=iv&invcode=" + escape(strValue);
	FMJS.postXML(url, param, function(xml){
		var iCode = G(xml).find("error_code").text();
		if(iCode != 0){
			G("#inv_logo").show();
		}
	});
}
//校验用户名function validateUserName(){
	var strValue = G('#id_username').attr("value");
	
	//为空
	if(FM.String.isBlank(strValue)){
		return -1;
	}
	//过长
	if(FM.String.len(strValue) > FM.EnvParam.iAccountNameMax){
		return 13012;
	}
	//过短
	if(FM.String.len(FM.STRING.trim(strValue)) < FM.EnvParam.iAccountNameMin){
		return 13013;
	}
	//非法字符
	if(!FM.String.isNewUserName(strValue)){
		return 13014;
	}
	return 0;
}
//校验姓名
function validateFullName(){
	var strValue = G('#id_fullname').attr("value");
	//为空
	if(FM.String.isBlank(strValue)){
		return 13385;
	}
	//过长
	if(FM.String.len(strValue) > FM.EnvParam.iFullNameMax){
		return 13382;
	}
	//过短
	if(FM.String.len(FM.STRING.trim(strValue)) < FM.EnvParam.iFullNameMin){
		return 13383;
	}
	//非法字符
	if(!FM.String.isFullName(strValue)){
		return 13014;
	}
	return 0;
}
//校验密码
function validatePassword(){
	var strValue = G('#id_password').attr("value");
	
	if(FM.String.isBlank(strValue)){
		return -1;
	}
	//过长
	if(FM.String.len(strValue) > FM.EnvParam.iPwdMax){
		return 13022;
	}
	//过短
	if(FM.String.len(strValue) < FM.EnvParam.iPwdMin){
		return 13023;
	}
	return 0;
}
//校验重复密码
function validatePassword2(){
	var strValue = G('#id_password').attr("value");
	var strValue2 = G('#id_password2').attr("value");
	
	if(strValue != strValue2){
		return 13025;
	}
	return 0;
}

function onClickCB(obj){
	if(G(obj).attr("checked")){
		G("#id_submit").attr("disabled","");
	}else{
		G("#id_submit").attr("disabled","false");
	}
}
//表单提交验证
function onSubmitFrm(){
	//用户为空
	var strUserName = G('#id_username').attr("value");
	if(FM.String.isBlank(strUserName)){
		FM.MSG.showErrorMsg(13011);
		G("#name_logo").show();
		return false;
	}
	var iNameCode = validateUserName();
	if(iNameCode != -1 && iNameCode != 0){
		FM.MSG.showErrorMsg(iNameCode);
		G("#name_logo").show();
		return false;
	}
	//姓名为空
	var strFullName = G('#id_fullname').attr("value");
	if(FM.String.isBlank(strFullName)){
		FM.MSG.showErrorMsg(13383);
		G("#fullname_logo").show();
		return false;
	}
	var iFullNameCode = validateFullName();
	if(iFullNameCode != -1 && iFullNameCode != 0){
		FM.MSG.showErrorMsg(iFullNameCode);
		G("#fullname_logo").show();
		return false;
	}
	//密码为空
	var strPassword = G('#id_password').attr("value");
	if(FM.String.isBlank(strPassword)){
		FM.MSG.showErrorMsg(13021);
		G("#pwd_logo").show();
		return false;
	}
	var iPwdCode = validatePassword();
	if(iPwdCode != -1 && iPwdCode != 0){
		FM.MSG.showErrorMsg(iPwdCode);
		G("#pwd_logo").show();
		return false;
	}
	var iPwdCode2 = validatePassword2();
	if(iPwdCode2 != -1 && iPwdCode2 != 0){
		FM.MSG.showErrorMsg(iPwdCode2);
		G("#pwd2_logo").show();
		return false;
	}
	//Email为空
	var strEmail   = G('#id_useremail').attr("value");
	if(FM.String.isBlank(strEmail)){
		FM.MSG.showErrorMsg(13100);
		G("#email_logo").show();
		return false;
	}
	var iEmailCode = validateEmail();
	if(iEmailCode != -1 && iEmailCode != 0){
		FM.MSG.showErrorMsg(iEmailCode);
		G("#email_logo").show();
		return false;
	}
	//验证码	var strVarCode = G('#id_varcode').attr("value");
	if(FM.String.isBlank(strVarCode)){
		FM.MSG.showErrorMsg(13223);
		return false;
	}
	if(FM.String.len(strVarCode) != FM.EnvParam.iVarCodeLen){
		FM.MSG.showErrorMsg(13224);
		return false;
	}
	
	G('#id_submit').attr("disabled","false");
	return true;
}
