//==============================================================================//
//--------------------        jQuery注册表单验证/12109        --------------------//
//==============================================================================//
jquery(document).ready(function(){
	jquery.formValidator.initConfig({formid:"registerForm",onerror:function(msg){if(document.getElementsByName("manageType")[4].checked == true){jquery("#shopName").formValidator({empty:true});jquery("#address").formValidator({empty:true});jquery("#mainBusiness").formValidator({empty:true});}},onsuccess:function(){return true;}});
	jquery("#loginId").formValidator({onshow:" ",onfocus:"此项为必填项4-18位(包括字母、数字、下划线、首字母以字母开头)",oncorrect:"该会员可以注册"}).inputValidator({min:4,max:18,onerror:"请输入合法的会员账号，4-18位(包括字母、数字、下划线、首字母以字母开头)"}).regexValidator({regexp:"^[a-zA-Z]{1}([a-zA-Z0-9]|[_]){3,17}$",onerror:"请输入合法的会员账号，4-18位(包括字母、数字、下划线、首字母以字母开头)"}).ajaxValidator({
	    type : "post",
		url : "visitor/checkRegisterData.htm?t=" + new Date().getTime(),
		datatype : "json",
		
		success : function(data){
			
            if(data.loginId == "0"){
            	return true;
			}else{
				if(data.loginId == "2"){//会员已被删除
					return false;
				}else{
					if(data.loginId == "3"){//会员已被禁用
						return false;
					}else{
						return false;//会员已被注册
					}
				}
			}
		},
		buttons: jquery("#button"),
		error: function(){alert("服务器没有返回数据，可能服务器忙，请重试");},
		onerror : "该会员已经被注册，请重新输入",
		onwait : "正在对用户名进行合法性校验，请稍候..."
	});;
	jquery("#loginPassword").formValidator({onshow:" ",onfocus:"此项为必填项由6-18个字母（区分大小写）或数字组成",oncorrect:"填写正确"}).inputValidator({min:6,max:18,empty:{leftempty:false,rightempty:false,emptyerror:"密码两边不能有空符号"},onerror:"您设置的密码有误。密码由6-18个字母（区分大小写）或数字组成"}).regexValidator({regexp:"^[A-Za-z0-9]+$",onerror:"您设置的密码有误。密码由6-18个字母（区分大小写）或数字组成"});
	jquery("#conPassword").formValidator({onshow:" ",onfocus:"请再输入一遍您上面输入的密码",oncorrect:"密码输入一致"}).inputValidator({min:6,max:18,empty:{leftempty:false,rightempty:false,emptyerror:"重复密码两边不能有空符号"},onerror:"重复密码不能为空,请确认"}).compareValidator({desid:"loginPassword",operateor:"=",onerror:"两次输入的密码不一致，请再输入一遍您上面填写的密码"});
	jquery("#name").formValidator({onshow:" ",onfocus:"此项为必填项",oncorrect:"填写正确"}).inputValidator({min:4,max:20,onerror:"4-20个字符，一个汉字为两个字符"}).regexValidator({regexp:"^[\u4e00-\u9fa5\A-Z]{2,20}$",param:"g",onerror:"真实姓名格式不正确"});
	jquery(":radio[name='sex']").formValidator({tipid:"sexTip",onshow:" ",onfocus:" ",oncorrect:" "}).inputValidator({min:1,max:1,onerror:"请选择性别"});
	jquery("#email").formValidator({empty:true,onshow:" ",onfocus:" ",oncorrect:"邮箱格式正确。这是客户与您联系的首选方式，请确保填写正确"}).inputValidator({min:6,max:32,onerror:"电子邮件格式不正确，请填写正确的电子邮件地址"}).regexValidator({regexp:"^([\\w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([\\w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$",onerror:"电子邮件格式不正确，请填写正确的电子邮件地址"});
	jquery("#phone").formValidator({onshow:" ",onfocus:"多个号码，请用'/'分隔;分机号码，请用'-'分隔",oncorrect:"填写正确"}).regexValidator({regexp:"^[[0-9]{3,4}-|\[0-9]{4}-]?([0-9]{8}|[0-9]{7})?$",onerror:"号码不对，请按区号-电话号码-分机号填写"});
	jquery("#fax").formValidator({empty:true,onshow:" ",onfocus:"多个号码，请用'/'分隔;分机号码，请用'-'分隔",oncorrect:"填写正确"}).regexValidator({regexp:"^[[0-9]{3,4}-|\[0-9]{4}-]?([0-9]{8}|[0-9]{7})?$",onerror:"号码不对，请按区号-电话号码-分机号填写"});
	jquery("#mobile").formValidator({empty:true,onshow:" ",onfocus:"方便客户及时联系您！易批发不绑定任何收费服务",oncorrect:"填写正确"}).inputValidator({min:11,max:11,onerror:"请填写正确的手机号码"}).regexValidator({regexp:"^1(3|5)[0-9]{9}$|^18(6|7|8|9)[0-9]{8}$", onerror:"请填写正确的手机号码"});
	jquery("#shopName").formValidator({onshow:" ",onfocus:"此项为必填项，注册企业请填写工商局注册的全称，无商号的个体经营者请填写执照上的姓名，并标注个体经营。如张三（个体经营）",oncorrect:"填写正确"}).inputValidator({min:4,max:40,onerror:"4-40个字符，一个汉字为两个字符"});
	jquery("#address").formValidator({onshow:" ",onfocus:"此项为必填项，请详细填写贵公司/商铺经营地址。如：女装大厦11层11号",oncorrect:"填写正确"}).inputValidator({min:4,max:80,onerror:"4-80个字符，一个汉字为两个字符"});
	jquery("#mainBusiness").formValidator({empty:true,onshow:" ",onfocus:"此项为必选项,为了给您提供匹配的产品信息，请选择贵公司/商铺主营的产品关键字",oncorrect:"填写正确"}).inputValidator({min:1,onerror: "请选择主营行业"});//.defaultPassed();
	jquery("#sellGoods").formValidator({empty:true,onshow:" ",onfocus:"为了给您提供匹配的产品信息，请填写贵公司/商铺主营的产品关键字。",oncorrect:"填写正确"}).inputValidator({min:1,onerror:"为了给您提供匹配的产品信息，请填写贵公司/商铺主营的产品关键字。"});
	jquery("#pickGoods").formValidator({empty:true,onshow:" ",onfocus:"为了给您提供匹配的产品信息，请填写贵公司/商铺主营的产品关键字。",oncorrect:"填写正确"}).inputValidator({min:1,onerror:"为了给您提供匹配的产品信息，请填写贵公司/商铺主营的产品关键字。"});
	
	
});

function hideAndShow(hideDiv, showDiv) {
	if (hideDiv != null) {
		for (var index = 0; index < hideDiv.length; ++index) {
			var hide = hideDiv[index];
			$(hide).hide();
		}
	}
	if (showDiv != null) {
		for (var index = 0; index < showDiv.length; ++index) {
			var show = showDiv[index];
			$(show).show();
		}
	}
	
}

function showValue() {
	document.getElementById("shopName").value = "";
	document.getElementById("address").value = "";
}

function hideShopinfo() {
	hideAndShow(["ul1", "ul2", "ul3", "ul4"], null);
}

function showShopinfo() {
	showValue();
	hideAndShow(null, ["ul1", "ul2", "ul3", "ul4"]);
}

function hideBusinessinfo(value){
 if(value=="0"){
    document.getElementById("pickGoods").value="";
    hideAndShow(["pick"], ["sell"]);
  }
  if(value=="1"){
    document.getElementById("sellGoods").value="";
    hideAndShow(["sell"], ["pick"]);
  }
  if(value=="2"){
    hideAndShow(null, ["pick","sell"]);
  }
}

function loadShopinfo() {
	if (document.getElementsByName("manageType")[4].checked) {
		hideAndShow(["ul1", "ul2", "ul3", "ul4"], null);
	}
	loadBusinessinfo();
}

function loadBusinessinfo(){
  if(document.getElementsByName("businessDirection")[0].checked == true){
     hideAndShow(["pick"], ["sell"]);
  }
  if(document.getElementsByName("businessDirection")[1].checked == true){
     hideAndShow(["sell"], ["pick"]);
  }
}
