var isInvitation = 0;

function kk(path) {
	if (window.confirm("\u786e\u5b9a\u9000\u51fa\u7cfb\u7edf\uff1f")) {
		window.location.href = path + "/user/Logout.action";
	}
}
function edit_tg() {
	var left_n = document.getElementById("edit_diqu");
	if (left_n.style.display == "none") {
		left_n.style.display = "block";
	} else {
		left_n.style.display = "none";
	}
}
/**
 * 检查新增域名表单
 * @return {Boolean}
 */
function checkAddDomainForm(){
	if(!checkDomainOrigin("origin")){
		return false;
	}
	return true;
}


//updateUseInfo
function formSubmit() {
	var userName = $("#userNameCn").val();
	var mobile = $("#userMobile").val();
	if (isBlank(userName)) {
		alert("公司名不能为空");
		return false;
	}
	if (!isCellPhone(mobile)) {
		alert("手机为空或格式非法");
		return false;
	}
	return true;
}
/*  updateUserPwd  */
function updatePwdFormSubmit() {

	var newPwd = $("#newPwd").val();
	var old = $("#oldPwd").val();
	var confirm = $("#passWord").val();
	if (!isPwd(old)) {
		alert("旧密码为空或格式非法");
		return false;
	}
	if (!isPwd(newPwd)) {
		alert("新密码为空或格式非法");
		return false;
	}
	if (!isPwd(confirm)) {
		alert("确认密码为空或格式非法");
		return false;
	}
	if (newPwd != confirm) {
		alert("确认密码与新密码不相同");
		return false;
	}
	return true;
}
/**
 * 注册表单
 * @return {Boolean}
 */
function regFormSubmit() {
	var email = document.getElementById("email").value;
	if (!isEmail(email)) {
		alert("邮箱地址非法或者为空");
		return false;
	}
	var userName = document.getElementById("cnname").value;
	if(isBlank(userName)){
		alert("公司名不能为空");
		return false;
	}
	var name2 = document.getElementById("contact").value;
	if(isBlank(name2)){
		alert("联系人姓名不能为空");
		return false;
	}
	var tel = document.getElementById("tel").value;
	if(!isCellPhone(tel)){
		alert("手机格式非法或者为空");
		return false;
	}
	var passWord = document.getElementById("pwd").value;
	if(!isPwd(passWord)){
		alert("密码非法或者为空");
		return false;
	}
	var passWordConfirm = document.getElementById("pwdag").value;
	if(!isPwd(passWordConfirm)){
		alert("确认密码非法或者为空");
		return false;
	}
	var reginfo = document.getElementById("xieyi");
	if(!reginfo.checked){
		alert('请接受注册协议！');
		return false;
	}
	if($("#imageCode").val().length==0)
	{
		alert('请输入验证码！');
		return false;
	}
	$.ajax({url:"checkImageCode.action?code="+$("#imageCode").val()+"&data="+Math.random(),async:true,success:function(msg){
		if(msg=="Y")
		{
			document.Register.submit();
		}
		else
		{
			$("#imageCode").val('');
			return false;
		}
	},dataType:"text"});
}
/**
 * 验证码
 * @param {} path
 */
function refreshImageCode(path) {
		document.getElementById("img").src = path + "/image.jsp?" + Math.random();
}
/**
 * 检查登录表单
 * @return {Boolean}
 */
function checkLogin() {
	var uname = document.getElementById("email").value;
	var pwd = document.getElementById("password").value;
	var imageCode = document.getElementById("imageCode").value;
	//alert(uname+"  "+ pwd + "  "+ imageCode);
  //	alert(uname + pwd + imageCode);
	if (uname == null || pwd == null || uname == "" || pwd == "" || imageCode == "" || imageCode == null) {
		alert("\u90ae\u7bb1\u3001\u5bc6\u7801\u3001\u9a8c\u8bc1\u7801\u4e0d\u80fd\u4e3a\u7a7a\uff01");
		return false;
	}else if(isInvitation == 1 && $.trim(document.getElementById("invitationCode").value)=="")
	{
		alert("邀请码不能为空");
		return false;
	}else{
		document.loginForm.submit();
	}
}

$(function(){
	$("#email").blur(function(){
		if($.trim($(this).val())=="")
		{
			return;
		}
		$.ajax({url:"/checkUserEmail.action?userEmail="+$(this).val()+"&data="+Math.random(),
				async:true,
				success:function(msg){
					checkEmailResult(msg);
				},dataType:"text"});
	});
	
	$("#sendBtn").click(function(){
				var email = document.getElementById("userEmail").value;
				if (!isEmail(email)) {
					alert("邮箱地址非法或者为空");
					return;
				}
				var userName = document.getElementById("cnname").value;
				if(isBlank(userName)){
					alert("公司名不能为空");
					return;
				}
				
				$.ajax({
				type:'POST',
				url:"/checkUserEmail.action",
				async:true,
				data:"userEmail="+$.trim(email)+"&data="+Math.random(),
				success:function(msg){
				
					checkEmailResult(msg);
				},dataType:"text"});
				
				
	});
	
	$("#devolveBtn").click(function(){
				var email = document.getElementById("userEmail").value;
				if (!isEmail(email)) {
					alert("邮箱地址非法或者为空");
					return;
				}
				
				$.ajax({
				type:'POST',
				url:"/checkUserEmail.action",
				async:true,
				data:"userEmail="+$.trim(email)+"&data="+Math.random(),
				success:function(msg){
					isExist(msg);
				},dataType:"text"});
	});			
});

$(document).ready(function(){ 
	$("#invitationLi").hide();
})
