

function addUserSubForm() {
	validateEmail(true);
	
}

function validateEmail(validateAll) {
	var eValue = '';
	eValue = $('email').value;
	var pattern = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;

	if (eValue != null
			&& (eValue == "" || eValue.replace(/^\s+|\s+$/g, "").length == 0)) {
		DWRUtil.setValue("spanhello", "请输入您常用的邮箱，方便日后找回密码。");
		showHintMsg("spanhello", false);
		return false;
	} else if (pattern.test(eValue) == false) {
		DWRUtil.setValue("spanhello", "邮箱格式不正确！");
		showHintMsg("spanhello", false);
		return false;
	} else {
		if (eValue != '') {
			callBack.prototype.validateAll=validateAll;
			UserDao.emailIsExist(eValue, callBack);
		}
	}
}
var callBack = function(data) {
	if (data) {
		DWRUtil.setValue("spanhello", "该邮箱已经被注册!");
		showHintMsg("spanhello", false);
		return false;
	} else {
		DWRUtil.setValue("spanhello", "");
		hideHintMsg("spanhello", false);
		if (callBack.prototype.validateAll) {
			if (validateAll()) {
				if (confirm("您确定提交吗？")) {
					document.forms.addUser.action = "/addUser.do";
					document.forms.addUser.submit();
				}
			}
		}
		return true;
	}
};

function validatePassword() {
	var pValue = '';
	pValue = $('upassword').value;
	if (pValue != null
			&& (pValue == "" || pValue.replace(/^\s+|\s+$/g, "").length == 0)) {
		DWRUtil.setValue("spanPass", "用户密码 为必填项。");
		showHintMsg("spanPass", false);
		return false;
	} else if (pValue.length < 6) {
		DWRUtil.setValue("spanPass", "用户密码不能少于6个字符");
		showHintMsg("spanPass", false);
		return false;
	} else {
		DWRUtil.setValue("spanPass", "");
		hideHintMsg("spanPass", false);
		return true;
	}
}

function validateRepass() {
	var pValue = $('upassword').value;
	var rpValue = $('cpassword').value;
	if (rpValue != pValue) {
		DWRUtil.setValue("spanRepass", "两次密码不一致");
		showHintMsg("spanRepass", false);
		return false;
	} else {
		DWRUtil.setValue("spanRepass", "");
		hideHintMsg("spanRepass", false);
		return true;
	}
}
function validateCompanyName() {
	var coValue = '';
	coValue = $('companyName').value;
	if (coValue != null
			&& (coValue == "" || coValue.replace(/^\s+|\s+$/g, "").length == 0)) {
		DWRUtil.setValue("spanComp", "公司全称 为必填项。");
		showHintMsg("spanComp", false);
		return false;
	} else {
		DWRUtil.setValue("spanComp", "");
		hideHintMsg("spanComp", false);
		return true;
	}
}

function validateCompanyaddr() {
	var caddrValue = '';
	caddrValue = $('companyaddr').value;
	if (caddrValue != null
			&& (caddrValue == "" || caddrValue.replace(/^\s+|\s+$/g, "").length == 0)) {
		DWRUtil.setValue("spanCaddr", "公司地址 为必填项。");
		showHintMsg("spanCaddr", false);
		return false;
	} else {
		DWRUtil.setValue("spanCaddr", "");
		hideHintMsg("spanCaddr", false);
		return true;
	}
}

function validateZipcode() {
	var zipcodeValue = '';
	zipcodeValue = $('zipcode').value;
	if (zipcodeValue != null
			&& (zipcodeValue == "" || zipcodeValue.replace(/^\s+|\s+$/g, "").length == 0)) {
		DWRUtil.setValue("spanZipcode", "邮政编码 为必填项。");
		showHintMsg("spanZipcode", false);
		return false;
	} else {
		DWRUtil.setValue("spanZipcode", "");
		hideHintMsg("spanZipcode", false);
		return true;
	}
}

function validatePn() {
	var pnValue = '';
	pnValue = $('principalname').value;
	if (pnValue != null
			&& (pnValue == "" || pnValue.replace(/^\s+|\s+$/g, "").length == 0)) {
		DWRUtil.setValue("spanPn", "姓名 为必填项。");
		showHintMsg("spanPn", false);
		return false;
	} else {
		DWRUtil.setValue("spanPn", "");
		hideHintMsg("spanPn", false);
		return true;
	}
}

function validateLinktel() {
	var ltValue = "";
	ltValue = $('linktel').value;
	var pattern = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{1,8}))?$/;
	if (ltValue != null
			&& (ltValue == "" || ltValue.replace(/^\s+|\s+$/g, "").length == 0)) {
		DWRUtil.setValue("spanLinktel", "联系电话 为必填项。");
		showHintMsg("spanLinktel", true);
		return false;
	} else if (pattern.test(ltValue) == false) {
		DWRUtil.setValue("spanLinktel", "联系电话格式不正确！（格式:010-62167788-1234）");
		showHintMsg("spanLinktel", true);
		return false
	} else {
		DWRUtil.setValue("spanLinktel", "");
		hideHintMsg("spanLinktel", true);
		return true;
	}
}

function validateMobiletel() {
	var mtValue = "";
	mtValue = $('mobiletel').value;
	var pattern = /^(?:13\d|15[0123456789]|18[0123456789])-?\d{5}(\d{3}|\*{3})$/;

	if (mtValue != null
			&& (mtValue == "" || mtValue.replace(/^\s+|\s+$/g, "").length == 0)) {
		DWRUtil.setValue("spanMobiletel", "移动电话 为必填项。");
		showHintMsg("spanMobiletel", true);
		return false;
	} else if (pattern.test(mtValue) == false) {
		DWRUtil.setValue("spanMobiletel", "移动电话格式不正确！（格式:13981818181）");
		showHintMsg("spanMobiletel", true);
		return false;
	} else {
		DWRUtil.setValue("spanMobiletel", "");
		hideHintMsg("spanMobiletel", true);
		return true;
	}
}

function validateProvince() {
	var mtProvince = "";
	mtProvince = $('province').value;
	if (mtProvince != null
			&& (mtProvince == "" || mtProvince.replace(/^\s+|\s+$/g, "").length == 0)) {
		DWRUtil.setValue("spanProvince", "请选择公司所在省份。");
		showHintMsg("spanProvince", false);
		return false;
	} else {

		DWRUtil.setValue("spanProvince", "");
		hideHintMsg("spanProvince", false);
		return true;
	}
}

function validateCity() {
	var mtCity = "";
	mtCity = $('city').value;
	if (mtCity != null
			&& (mtCity == "" || mtCity.replace(/^\s+|\s+$/g, "").length == 0)) {
		DWRUtil.setValue("spanCity", "请选择公司所在城市。");
		showHintMsg("spanCity", false);
		return false;
	} else {
		DWRUtil.setValue("spanCity", "");
		hideHintMsg("spanCity", false);
		return true;
	}
}

function validateIndustry() {
	var mtProvince = "";
	mtProvince = $('industrys').value;
	if (mtProvince != null
			&& (mtProvince == "" || mtProvince.replace(/^\s+|\s+$/g, "").length == 0)) {
		DWRUtil.setValue("spanIndustrys", "请选择公司的行业。");
		showHintMsg("spanIndustrys", false);
		return false;
	} else {

		DWRUtil.setValue("spanIndustrys", "");
		hideHintMsg("spanIndustrys", false);
		return true;
	}
}

function validateSubIndustry() {
	var mtCity = "";
	mtCity = $('subindustrys').value;
	if (mtCity != null
			&& (mtCity == "" || mtCity.replace(/^\s+|\s+$/g, "").length == 0)) {
		DWRUtil.setValue("spanSubindustrys", "请选择公司的子行业。");
		showHintMsg("spanSubindustrys", false);
		return false;
	} else {

		DWRUtil.setValue("spanSubindustrys", "");
		hideHintMsg("spanSubindustrys", false);
		return true;
	}
}
function validatePosition() {

	var positions = document.getElementsByName("user.positions.dictionaryCode");
	var bool = false;
	for (var i = 0; i < positions.length; i++) {
		if (positions[i].checked) {
			DWRUtil.setValue("spanPosition", "1");
			hideHintMsg("spanPosition", false);
			return true;
		}
	}

	DWRUtil.setValue("spanPosition", "请选择您的职务。")
	showHintMsg("spanPosition", false);
	return false;

}
function validateNickName(){
	var caddrValue = '';
	caddrValue = $('nickName').value;
	if (caddrValue != null
			&& (caddrValue == "" || caddrValue.replace(/^\s+|\s+$/g, "").length == 0)) {
		DWRUtil.setValue("spanNickName", "昵称 为必填项。");
		showHintMsg("spanNickName", false);
		return false;
	} else {
		DWRUtil.setValue("spanNickName", "");
		hideHintMsg("spanNickName", false);
		return true;
	}
}
function validateAll() {
	if (validatePassword() 
			&& validateRepass() 
			&& validateNickName()
			&& validatePn()
			&& validateLinktel() 
			&& validateMobiletel()
			&& validateCompanyName() 
			&& validateCompanyaddr()
			&& validateZipcode() 
			&& validateProvince() 
			&& validateCity()
			&& validatePosition() 
			&& validateIndustry()
			&& validateSubIndustry()) {
		return true;
	} else {
		return false;
	}
}
function showHintMsg(id, hindDefMsg) {
	if (hindDefMsg) {
		getNextSibling($(id).parentNode).style.display = "none";
	}
	$(id).parentNode.style.display = "inline";

}
function hideHintMsg(id, showDefMsg) {
	if (showDefMsg) {
		getNextSibling($(id).parentNode).style.display = "inline";
	}
	$(id).parentNode.style.display = "none";

}
function getNextSibling(obj){
	if(obj.nextSibling.nodeType==3) {
		sibling=obj.nextSibling.nextSibling; // Moz. Opera
	}
	else {
		sibling=obj.nextSibling; // IE
	}
	return sibling;
}
