function isEmail(_value){
	var pattern=/^(([a-z A-Z \-_ 0-9]+[a-z A-Z \-_ 0-9 \.]+)@[a-z A-Z \-_ 0-9]+\.([a-z A-Z]+(\.)?)?[a-z A-Z]+)$/;
	if(pattern.test(_value)){
		return true;
	}else{
		return false;	
	}
}
function isTel(){
	var	tel=$('#tel').val();
	var reg=/^[\d|\-|\s|\_]+$/;
	var isOk = reg.test(tel);
	if(isOk && tel.indexOf("-")<0 && tel.length<7){
		isOk = isOk && false;
	}
	
/*	else if(isOk && tel.indexOf("-")>0){
		var firstTel = tel.substring(tel.indexOf("-"));
		if(firstTel.length>1){
			firstTel = firstTel.substring(1);
			if(firstTel.indexOf("-")<0){
				if(firstTel.length!=7 && firstTel.length!=8){
					isOk = isOk && false;
					return isOk;
					//alert("区号后电话长度不对！");
				}
			}else{
				firstTel = firstTel.substring(0,firstTel.indexOf("-"));
				if(firstTel.length!=7 && firstTel.length!=8){
					isOk = isOk && false;
					return isOk;
					//alert("区号后电话长度不对！");
				}
			}
	   }else{
			isOk = isOk && false;
			return isOk;
			//alert("区号后电话长度不对！");
	   }
	}
*/	
return isOk;
};
function validateEmail(){
	if($('#email').val().length==0){
	  $('#em').empty().append('<span class="inputErro">*此项为必填项</span>');
	}else{
		if(!isEmail($('#email').val())){
			 $('#em').empty().append('<span class="inputErro">*请输入正确的E-mail地址</span>');
		}else{
			$.ajax({
				type: "POST",
				url: "login.php",
				data: "email="+$('#email').val()+"&type=checkemail",
				success: function(msg){
					if(msg=='OK'){
						$('#em').empty().append('<span class="inputSucceed">*输入正确</span>');
					}else{
						$('#em').empty().append('<span class="inputErro">*该E-mail地址已被其他用户使用，请更换其它地址</span>');
					}
				}
			});
		}
	}
}
function validatePass(){
	if($('#pwd').val().length==0){
	  $('#ps').empty().append('<span class="inputErro">*登录密码不能为空</span>');
	}else{
		if($('#pwd').val().length<5){
			 $('#ps').empty().append('<span class="inputErro">*登录密码不能小于5位</span>');
		}else{
			$('#ps').empty().append('<span class="inputSucceed">*输入正确</span>');
		}
	}
}
function validatePass2(){
	if($('#password2').val().length==0){
	  $('#ps2').empty().append('<span class="inputErro">*确认密码不能为空</span>');
	}else{
		if($('#password2').val()!=$('#pwd').val()){
			 $('#ps2').empty().append('<span class="inputErro">*两次输入密码不一致,请重新输入</span>');
		}else{
			$('#ps2').empty().append('<span class="inputSucceed">*输入正确</span>');
		}
	}
}
function validateCompany(){
	if($('#company').val().length==0){
	  $('#cp').empty().append('<span class="inputErro">*此项为必填项</span>');
	}else{
		if($('#company').val().length<2){
			 $('#cp').empty().append('<span class="inputErro">*请填写正确的单位名称或姓名</span>');
		}else{
			$('#cp').empty().append('<span class="inputSucceed">*输入正确</span>');
		}
	}
}
function validateContact(){
	if($('#contact').val().length==0){
	  $('#co').empty().append('<span class="inputErro">*此项为必填项</span>');
	}else{
		if($('#contact').val().length<2){
			 $('#co').empty().append('<span class="inputErro">*请填写正确的姓名</span>');
		}else{
			$('#co').empty().append('<span class="inputSucceed">*输入正确</span>');
		}
	}
}
function validateTel(){
	if($('#tel').val().length==0){
	  $('#te').empty().append('<span class="inputErro">*此项为必填项</span>');
	}else{
		if(!isTel($('#tel').val())){
			 $('#te').empty().append('<span class="inputErro">*请输入正确的联系电话</span>');
		}else{
			$('#te').empty().append('<span class="inputSucceed">*输入正确</span>');
		}
	}
}


function checkform(theform){
	if(theform.email.value.length==0){
		$('#em').empty().append('<span class="inputErro">*此项为必填项</span>');
		alert("E-mail地址不能为空");
		theform.email.focus();
		return false
	}
	if(!isEmail(theform.email.value)){
		$('#em').empty().append('<span class="inputErro">*请输入正确的E-mail地址</span>');
		alert("请输入正确的E-mail地址");
		theform.email.focus();
		return false
	}
	if(theform.pwd.value.length==0){
		$('#ps').empty().append('<span class="inputErro">*登录密码不能为空</span>');
		alert("登录密码不能为空");
		theform.pwd.focus();
		return false
	}
	if(theform.pwd.value.length < 5){
		$('#ps').empty().append('<span class="inputErro">*登录密码不能小于5位字符</span>');
		alert("登录密码不能小于5位");
		theform.pwd.focus();
		return false
	}
	if(theform.password2.value.length==0){
		$('#ps2').empty().append('<span class="inputErro">*确认密码不能为空</span>');
		alert("确认密码不能为空");
		theform.password2.focus();
		return false
	}
	if(theform.pwd.value!=theform.password2.value){
		$('#ps2').empty().append('<span class="inputErro">*两次输入密码不一致,请重新输入</span>');
		alert("两次输入密码不一致,请重新输入");
		theform.password2.focus();
		return false
	}
	if(theform.company.value.length==0){
		$('#cp').empty().append('<span class="inputErro">*此项为必填项</span>');
		alert("单位名称不能为空");
		theform.company.focus();
		return false
	}
	if(theform.company.value.length < 2){
		$('#cp').empty().append('<span class="inputErro">*请填写正确的单位名称或姓名</span>');
		alert("请填写正确的单位名称或姓名");
		theform.company.focus();
		return false
	}
	if(theform.contact.value.length==0){
		$('#co').empty().append('<span class="inputErro">*此项为必填项</span>');
		alert("联系人不能为空");
		theform.contact.focus();
		return false
	}
	if(theform.contact.value.length < 2){
		$('#co').empty().append('<span class="inputErro">*请填写正确的姓名</span>');
		alert("请填写正确的姓名");
		theform.contact.focus();
		return false
	}
	if(theform.tel.value.length==0){
		$('#te').empty().append('<span class="inputErro">*此项为必填项</span>');
		alert("联系电话不能为空");
		theform.tel.focus();
		return false
	}
	if(!isTel(theform.tel.value)){
		$('#te').empty().append('<span class="inputErro">*请填写正确的联系电话</span>');
		alert("请填写正确的联系电话");
		theform.tel.focus();
		return false
	}
	if(theform.agree.checked==false){
		alert("请勾选同意建站服务条款");
		return false
	}
	
}
function getpassform(theform){
	if(theform.getpass_email.value.length==0){
		alert("E-mail地址不能为空");
		theform.getpass_email.focus();
		return false
	}
	if(!isEmail(theform.getpass_email.value)){
		alert("请输入正确的E-mail地址");
		theform.getpass_email.focus();
		return false
	}

}
function setpassform(theform){
	if(theform.setpass.value.length < 5){
		alert("登录密码不能小于5位");
		theform.setpass.focus();
		return false
	}
	if(theform.setpass.value!=theform.resetpass.value){
		alert("两次输入密码不一致,请重新输入");
		theform.resetpass.focus();
		return false
	}
}
(function($){
	$.fn.lo_login = function(){
		var lo_email=$("#lo_email")[0].value,lo_pwd=$("#lo_pwd")[0].value,checkcode=$("#checkcode")[0].value;
		if(!isEmail(lo_email)){
			$("#lo_email").focus();
			alert('请输入正确的E-mail地址');
			return false;
		}
		if(lo_pwd.length==0){
			$("#lo_pwd").focus();
			alert("登录密码不能为空");
			return false
		}
		if(lo_pwd.length<5){
			$("#lo_pwd").focus();
			alert("登录密码不能小于5位字符");
			return false
		}
		if(checkcode.length<5){
			$("#checkcode").focus();
			alert("请填写正确的验证码");
			return false
		}
		$.ajax({
			type: "POST",
			url: "login.php",
			data: "email="+lo_email+"&pwd="+lo_pwd+"&checkcode="+checkcode+"&type=login",
			success: function(msg){
				if(msg=='system parameter error'){
					alert('登录失败,提交数据有误');
				}else if(msg=='emailerror'){
					alert('登录失败,E-mail地址格式有误');
				}else if(msg=='usfailure'){
					alert('登录失败,E-mail帐号不存在');
				}else if(msg=='psfailure'){
					alert('登录密码错误');
				}else if(msg=='checkcode'){
					alert('验证码错误');
				}else if(msg=='audifailure'){
					alert('帐号登录被禁用');
				}else if(msg=='OK'){
					$('#logininfo').empty().append('<div class="middle_info">欢迎您：<span style="color: #73b420;">'+lo_email+'</span></div><div class="middles"><a href="manage.php" title="管理中心"><img src="images/LoginPic1.gif" alt="" border="0" /></a></div><div class="middles"><a href="/logout.php" title="安全退出"><img src="images/LoginPic2.gif" alt="安全退出" border="0" /></a></div><div class="getps">离开管理时请务必点击安全退出。</div>');
				}else{
					alert('未知错误，请与客服人员联系');
				}
			}
		});
	};
})(jQuery);
(function($){
	$.fn.timeout_login = function(){
		var lo_email=$("#timeout_email")[0].value,lo_pwd=$("#timeout_pwd")[0].value,checkcode=$("#timeout_checkcode")[0].value;
		if(!isEmail(lo_email)){
			$("#timeout_email").focus();
			alert('请输入正确的E-mail地址');
			return false;
		}
		if(lo_pwd.length==0){
			$("#timeout_pwd").focus();
			alert("登录密码不能为空");
			return false
		}
		if(lo_pwd.length<5){
			$("#timeout_pwd").focus();
			alert("登录密码不能小于5位字符");
			return false
		}
		if(checkcode.length<5){
			$("#timeout_checkcode").focus();
			alert("请填写正确的验证码");
			return false
		}
		$.ajax({
			type: "POST",
			url: "login.php",
			data: "email="+lo_email+"&pwd="+lo_pwd+"&checkcode="+checkcode+"&type=login",
			success: function(msg){
				if(msg=='system parameter error'){
					alert('登录失败,提交数据有误');
				}else if(msg=='emailerror'){
					alert('登录失败,E-mail地址格式有误');
				}else if(msg=='usfailure'){
					alert('登录失败,E-mail帐号不存在');
				}else if(msg=='psfailure'){
					alert('登录密码错误');
				}else if(msg=='checkcode'){
					alert('验证码错误');
				}else if(msg=='OK'){
					window.location='manage.php';
				}else{
					alert('未知错误，请与客服人员联系');
				}
			}
		});
	};
})(jQuery);
function codeUrl(url){var timestamp = (new Date()).valueOf();urlurl = url.substring(0,17);if((url.indexOf("&")>=0)){urlurl = url + "&tamp=" + timestamp;}else{urlurl = url + "?timestamp=" + timestamp;}return urlurl;}
$(document).ready(function(){$(".loginCodeimg").click(function(){$(".loginCodeimg").attr("src",codeUrl("/checkcode.php"));});}); 