$(document).ready(function() {
	var options = {
		url:			"/join/submit",	
		dataType:		"json",
		beforeSubmit:	joinRequest,
		success:		joinResponse,
		timeout:		3000
	};
	$('#joinForm').ajaxForm(options);
	checkSubmit();
});

function joinRequest(formData,jqForm,options) {
	var join = jqForm[0];
	if(join.flag.checked != true){
		alert('请参看用户注册协议'); 
		return false;
	}
	if(!jQuery.formValidator.PageIsValid('1')){
		return false;
	}
	return true;
}

function joinResponse(responseText, statusText){
	if(responseText.code == 0){
		alert(responseText.msg);
		$('#joinForm').clearForm();
		location.href = '/';
	}else{
		alert(responseText.msg);
	}
}

function checkSubmit(){
	$.formValidator.initConfig({onError:function(){alert("校验没有通过，具体错误请看错误提示")}});

	$("#user").formValidator({onshow:"由字母、数字、下划线组成，长度为4-19个字符",onfocus:"由字母、数字、下划线组成，长度为4-19个字符",oncorrect:"用户名合法"}).InputValidator({min:4,max:19,onerror:"你输入的用户名非法,请确认"}).RegexValidator({regexp:"^[a-zA-Z0-9_]{3,19}$",onerror:"你输入的用户名格式不正确!"});

	$("#passwd").formValidator({onshow:"密码长度6-16位，字母区分大小写",onfocus:"密码长度6-16位，字母区分大小写",oncorrect:""}).InputValidator({min:6,max:16,onerror:"密码长度不正确"}).CompareValidator({desID:"confirm",operateor:"=",onerror:"2次密码不一致,请确认"}).RegexValidator({regexp:"^[a-zA-Z0-9]{5,16}$",onerror:"密码格式不正确!"});

	$("#name").formValidator({onshow:"请填写真实信息",onfocus:"请填写真实信息",oncorrect:""}).InputValidator({min:1,onerror:"企业名称不能为空"});
	$("#tel").formValidator({onshow:"请填写真实信息",onfocus:"请填写真实信息",oncorrect:""}).InputValidator({min:1,onerror:"联系电话不能为空"});
	$("#contact").formValidator({onshow:"请填写相关负责人姓名",onfocus:"请填写相关负责人姓名",oncorrect:""}).InputValidator({min:1,onerror:"相关负责人不能为空"});
}
