$(function() {
	$("#log-btn").click(function() {
		var $account = $("#log-account");
		var $password = $("#log-password");
		
		var account = $account.val().replace(/ /g, '').replace(/'/g, '');
		var password = $password.val().replace(/ /g, '').replace(/'/g, '');
		
		if(account == "") {
			alert("用户名不能为空！");
			$account.val("").focus();
		} else if(password == "") {
			alert("密码不能为空！");
			$password.val("").focus();
		} else {
			
			$.post(root + "api/run.php", { account:account, password:password }, function(data) {
					if(data == 1)																		  
					{
						alert('登陆成功');
						window.location.href = root + "?m=member";
						
						return true;
					}
			});
			
			$.post(root + "?m=login.check", { account:account, password:password }, function(data) {
				if(data[0] == "success") {
					window.location.href = root + "?m=member";
				} else {
					alert(data[1]);
					if(data[2] == "account is null") {
						$account.val("").focus();
					} else if(data[2] == "password is null") {
						$password.val("").focus();
					} else if(data[2] == "member is not exists") {
						$account.focus();
					} else if(data[2] == "member is stopped") {
						$account.focus();
					} else if(data[2] == "password error") {
						$password.val("").focus();
					}
				}
			}, "json");
		}
	});
	$("#reg-btn").click(function() {
		var $account = $("#reg-account");
		var $password = $("#reg-password");
		var $repwd = $("#reg-repwd");
		var $name = $("#reg-name");
		var $mobile = $("#reg-mobile");
		
		var account = $account.val().replace(/ /g, '').replace(/'/g, '');
		var password = $password.val().replace(/ /g, '').replace(/'/g, '');
		var repwd = $repwd.val().replace(/ /g, '').replace(/'/g, '');
		var name = $name.val().replace(/ /g, '').replace(/'/g, '');
		var mobile = $mobile.val().replace(/ /g, '').replace(/'/g, '');
		
		if(account == "") {
			alert("用户名不能为空！");
			$account.val("").focus();
		} else if(password == "") {
			alert("密码不能为空！");
			$password.val("").focus();
		} else if(repwd != password) {
			alert("两次密码不一样！");
			$repwd.focus();
		} else if(name == "") {
			alert("姓名不能为空！");
			$name.val("").focus();
		} else if(mobile == "") {
			alert("手机号码不能为空！");
			$mobile.val("").focus();
		} else if(mobile != "" && !/^(13|15|18)\d{9}$/.test(mobile)){
			alert("请输入正确的手机号码！");
			$mobile.focus();
		} else {
			$.post(root + "?m=login.register", { account:account, password:password, name:name, mobile:mobile }, function(data) {//alert(data);
				if(data[0] == "success") {
					window.location.href = root + "?m=member";
				} else {
					alert(data[1]);
					if(data[2] == "account is null") {
						$account.val("").focus();
					} else if(data[2] == "password is null") {
						$password.val("").focus();
					} else if(data[2] == "member is exists") {
						$account.focus();
					} else if(data[2] == "name is null") {
						$name.val("").focus();
					} else if(data[2] == "mobile is null") {
						$mobile.val("").focus();
					}
				}
			}, "json");
		}
	});
});