(document).ready(function() 
{
	$("#username").blur(function()
	{
		if($("#username").val() == "")
		{
			$("#usernameInput").html("<div><font color=red>鐢ㄦ埛鍚嶄笉鑳戒负绌?/font></div>");
			$("#username").focus();
			return false;
		}
		if($("#username").val().length < 3 || $("#username").val().length > 20)
		{
			$("#usernameInput").html("<div><font color=red>鐢ㄦ埛鍚嶇殑闀垮害涓?鍒?0涓瓧绗?/font></div>");
			$("#username").focus();
			return false;
		}
		username();
	});
	
	$("#password").blur(function()
	{
		if($("#password").val() == "")
		{
			$("#regPassWordInfo").html("<div><font color=red>瀵嗙爜涓嶈兘涓虹┖</font></div>");
		}
		else if($("#password").val().length < 6 || $("#password").val().length > 12)
		{
			$("#regPassWordInfo").html("<div><font color=red>瀵嗙爜鐨勯暱搴﹁寖鍥村湪6鍒?2瀛楃涔嬪唴</font></div>");
		}
		else if($("#password").val().length >= 6 && $("#password").val().length <= 12)
		{
			$("#regPassWordInfo").html("<div><font color=blue>鍙互娉ㄥ唽</font></div>");
		}
		
	});
	$("#repassword").blur(function()
	{
		if($("#repassword").val() == "")
		{
			$("#regCPassWordInfo").html("<div><font color=red>瀵嗙爜涓嶈兘涓虹┖</font></div>");
		}
		else if($("#password").val() != $("#repassword").val())
		{
			$("#regCPassWordInfo").html("<div><font color=red>涓ゆ杈撳叆鐨勫瘑鐮佷笉鍚?/font></div>");
		}
		else
		{
			$("#regCPassWordInfo").html("<div><font color=blue>鍙互娉ㄥ唽</font></div>");
		}
	
	});

	$("#email").blur(function()
	{
		if($("#email").val() == "")
		{
			$("#regEmailInfo").html("<div><font color=red>閭涓嶈兘涓虹┖</font></div>");
			$("#email").focus();
			return false;
		}
		if(!$("#email").val().match("^([a-zA-Z0-9]+[_|\-|\.]?)*@([a-zA-Z0-9]+[_|\-|\.]?)*\.[a-zA-Z]{2,3}$"))
		{
			$("#regEmailInfo").html("<div><font color=red>閭濉啓鏂瑰紡閿欒</font></div>");
			$("#email").focus();
			return false;
		}
		email();
	});

	$("#checkcode").blur(function()
	{
		if($("#checkcode").val() == "")
		{
			$("#checkcodeInfo").html("<div><font color=red>楠岃瘉鐮佷笉鑳戒负绌?/font></div>");
			$("#checkcode").focus;
			return false;
		}
		checkcode();

	})
})

function username()
{
	var username = $("#username").val();
	$.ajax
	({ 
	   type:"post",
	   url :"member.php?act=ajax&type=username",
	   dataType:"json",
	   data:"username="+username, 
	   success: function(json)
	   {
		   //eval('json='+json+';');
		   if(json.is_false == 1)
		   {
				$("#usernameInput").html("<div><font color=red>"+json.info+"</font></div>");
				
				$("#username").focus;
				$("#username").val("");
		   }
		   else
		   {
				$("#usernameInput").html("<div><font color=blue>"+json.info+"</font></div>");
				
		   }
	   }   
   }); 
}

function email()
{
	var email = $("#email").val();
	$.ajax
	({ 
	   type:"post",
	   url :"member.php?act=ajax&type=email",
	   dataType:"json",
	   data:"email="+email, 
	   success: function(json)
	   {
		  if(json.is_false == 1)
		   {
				$("#regEmailInfo").html("<div><font color=red>"+json.info+"</font></div>");
				$("#email").focus;
				$("#email").val("");
		   }
		   else
		   {
				$("#regEmailInfo").html("<div><font color=blue>"+json.info+"</font></div>");
				
		   }
	   }   
   }); 
}

function checkcode()
{
	var checkcode = $("#checkcode").val();
	$.ajax
	({ 
	   type:"post",
	   url :"member.php?act=ajax&type=checkcode",
	   dataType:"json",
	   data:"checkcode="+checkcode, 
	   success: function(json)
	   {
		  if(json.is_false == 1)
		  {
				$("#checkcodeInfo").html("<div><font color=red>"+json.info+"</font></div>");
				$("#checkcode").focus;
				$("#checkcode").val("");
				return false;
		  }
		  else
		  {
				$("#checkcodeInfo").html("<div><font color=blue>"+json.info+"</font></div>");
		  }
	   }   
   }); 
}


function check_form()
{
	var username = document.getElementById("username");
	var password = document.getElementById("password");
	var repassword = document.getElementById("repassword");
	var email = document.getElementById("email");
	var checkcode = document.getElementById("checkcode");

	if(username.value == "")
	{	
		$("#usernameInput").html("<div><font color=red>鐢ㄦ埛鍚嶄笉鑳戒负绌?/font></div>");
		username.focus();
		return false;
	}
	if(username.value.length < 3 || username.value.length > 20)
	{
		document.getElementById("usernameInput").innerHTML="<font color=red>鐢ㄦ埛鍚嶇殑闀垮害涓?鍒?0涓瓧绗?/font>";
		document.getElementById("username").focus();
		return false;
	}
	if(password.value == "")
	{
		password.focus();
		return false;
	}
	if(repassword.value == "")
	{
		repassword.focus();
		return false;
	}
	if(password.value != repassword.value)
	{
		repassword.focus();
		return false;
	}
	if(email.value == "")
	{
		email.focus();
		return false;
	}
	if(!email.value.match("^([a-zA-Z0-9]+[_|\-|\.]?)*@([a-zA-Z0-9]+[_|\-|\.]?)*\.[a-zA-Z]{2,3}$"))
	{
		document.getElementById("regEmailInfo").innerHTML="<font color=red>閭濉啓鏂瑰紡閿欒</font>";
		document.getElementById("email").focus();
		return false;
	}
	if(checkcode.value == "")
	{
		document.getElementById("checkcodeInfo").innerHTML="<font color=red>楠岃瘉鐮佸～鍐欓敊璇?/font>";
		checkcode.focus();
		return false;
	}
	checkcode();
}
