$(document).ready(function(){
	$("#username1").blur(function() { 
		if(0 < $(this).val().length){
			Chk("#username1",'username','required'); 
		}else{
			$(this).next('span').html('');
		}
	}); 
	$("#mobile").blur(function() { 
		if(0 < $(this).val().length){
			ChkMobile("#mobile",'mobile','required'); 
		}else{
			$(this).next('span').html('');
		}
	}); 
	$("#submit_user_Form").click(function() {
		if(FormCheck()){
			$('#user_Form').submit();
		
		}
	});
			
})

function Chk(obj,type,action){
	if ($(obj).val().search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1) 
	{
		$("#checkM").html("<img src=\"imgs/wrong.gif\" alt=\"wrong\" /> 请输入正确的邮箱地址！");
		return false; 
	}
	$.post("ajax/ajax.regist.php",
		   { type:type,val: $(obj).val(),action:action},
		   function(data){
				var re = eval ("("+data+")");
				if(re.right == true){
					var img = "<img src=\"imgs/right.gif\" align=\"absmiddle\" alt=\"corrent\" />";
				}else{
					var img = "<img src=\"imgs/wrong.gif\" align=\"absmiddle\" alt=\"wrong\" />";					
				}
				$("#checkM").html(img+re.reason);
		   }
	);
}

function ChkMobile(obj,type,action){
	if($(obj).val().search(/^13\d{9}$|^18\d{9}$|^14\d{9}$|15\d{9}$/) == -1) 
	{
		//alert("请输入正确的手机号！");
		$("#checkMobile").html("请输入正确的手机号！");
		return false; 
	}
	$.post("ajax/ajax.regist.php",
		   { type:type,val: $(obj).val(),action:action},
		   function(data){
				var re = eval ("("+data+")");
				if(re.right == true){
					var img = "<img src=\"imgs/right.gif\" alt=\"corrent\" />";
				}else{
					var img = "<img src=\"imgs/wrong.gif\" alt=\"wrong\" />";					
				}
				$("#checkMobile").html(img+re.reason);
		   }
	);
}


	
function FormCheck(){
	    if(Required('#username1','请输入您的邮箱') == false) return false;
		var emailStr=document.user_Form.username1.value;
		if (emailStr.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)  
		{
			alert("请输入正确的邮箱地址！"); 
			return false; 
		}
		
		
		var mobileStr=document.user_Form.mobile.value;
		if (mobileStr.search(/^13\d{9}$|^18\d{9}$|^14\d{9}$|15\d{9}$/) == -1) 
		{
			alert("请输入正确的手机号！"); 
			return false; 
		}
		
		
		if(Required('#password','请输入密码') == false) return false;
			if($('#password').val()!=$('#confirm').val())
			{
				alert('输入密码不一致');	 
				return false;
			 }
		if(Required('#nick','请输入昵称') == false) return false;
	
	if($('#terms').attr('checked') != true){
		alert('您是否同意服务条约？');
		$('#terms').focus();
		return false;
	}


	return true;
}


