/**
 * 用户注册
 *
 */

function saveReg(){
  	var obj;
  	try{
  		var name=getValue_public("username");
  		if(name=='')
  		{
  			alert('请输入用户名！');
  			return;
  		}
  		var word1=getValue_public("password");
  		if(word1=='')
  		{
  			alert('请输入密码！');
  			return;
  		}
  		var word2=getValue_public("password2");
  		if(word2=='')
  		{
  			alert('请输入确认密码！');
  			return;
  		}
  		if(word1!=word2)
  		{
  			alert('两次输入的密码不一致！');
  			return;
  		}
  		var tel=getValue_public("telphone");
  		if(tel=='')
  		{
  			alert('电话号码不能为空！');
  			return;
  		}
  		if(!isphonenumber(tel))
  		{
  			return;
  		}
  		var email=getValue_public("email")
  		if(!mail(email))
  		{
  			return;
  		}
  		var check=getValue_public("hidcheck")
  		//alert(check);
  		if(check=='1')
  		{
  			document.getElementById("spuser").focus();
  			return;
  		}
  		
  	obj = {
			username:getValue_public("username"),
			password:getValue_public("password"),
			telphone:getValue_public("telphone"),
			email:getValue_public("email"),
			code:getValue_public("code")		
		};
		saveRegest.save(obj,callback);
  	}catch(ex){
		alert(ex.message);
  	}
}

function check_email(Email) 
{ 
var emailRE=/^[a-zA-Z0-9\-\_]+\@+[a-zA-Z0-9\-\_]+\.+[a-zA-Z0-9\-\_]{2,4}$/
var resualt= emailRE.test(Email); 
return resualt; 
} 
function mail(email){
if(email==""){ 
alert("请留下您的电子信箱地址，以方便我们回复"); 
return false; 
}else if(!check_email(email)){ 
alert("请输入正确的电子信箱地址"); 
return false; 
} 
else
 return true;
}

function isphonenumber(obj)
{ 
	var pattern=/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}1[0-9]{10}$)/; 
	if(pattern.test(obj)) 
	{ 
	return true; 
	} 
	else 
	{ 
		alert('电话号码错误!');
	return false; 
	} 
}

function callback(data){
		if(data=='0'){
			alert("验证码不正确!");
			return;
		}
		if(data=='1')
		{
			alert("注册成功,等待审核!");
		}
		if(data=='2'){
			alert("注册失败!");
		}
	window.location.href="../../index.jsp";
	  }
function CheckName()
{
	var name=getValue_public("username");
	if(name=='')
	{
		//alert('用户名不能为空！');
		document.getElementById("spuser").innerHTML="请输入用户名";
		document.getElementById("hidcheck").value="1";
		return;
	}
	saveRegest.Checkuser(name,checkout);
	}
function checkout(data){
	if(data=='0'){
		document.getElementById("spuser").innerHTML="用户名可用";
		document.getElementById("hidcheck").value="0";
		//alert("用户名可用!");
		return;
	}
	if(data=='1')
	{
		document.getElementById("spuser").innerHTML="用户名被占用了";
		document.getElementById("hidcheck").value="1";
		document.getElementById("spuser").focus();
		//alert("用户名被用了!");
	}
  }
function Loginuser()
{
	var name=getValue_public("username");
	if(name=='')
	{
		document.getElementById("username").focus();
		return;
	}
	var pwd=getValue_public("password");
	if(pwd=='')
	{
		document.getElementById("password").focus();
		return;
	}
	var cod=getValue_public("code");
	if(cod=='')
	{
		document.getElementById("code").focus();
		return;
	}
	var obj = {
			username:getValue_public("username"),
			password:getValue_public("password"),
			code:getValue_public("code")		
		};
		saveRegest.LoginUser(obj,logincode);
}
function logincode(data)
{
	if(data=='0'){
		alert("验证码错误!");
		document.getElementById("code").focus();
		return;
	}
	
	else if(data=='2')
	{
		alert("密码错误或者未通过审核!");
		return;
	}
	else
	{
		//alert("登录成功!");
		window.location.href="jsp/login/mebregist.jsp?user_id="+data;
	}
	}
