$(function() {
	$("#O_LogBtn").click(function() {
		var O_Account = $("#log-account");
		var O_Password = $("#log-password");
		
		var v_account = $.trim(O_Account.val()).replace(/ /g, '').replace(/'/g, '');
		var v_password = $.trim(O_Password.val()).replace(/ /g, '').replace(/'/g, '');
		
		if(v_account == "") {
			alert("用户名不能为空！");
			O_Account.val("");
			O_Account.focus();
		} else if(v_password == "") {
			alert("密码不能为空！");
			O_Password.val("");
			O_Password.focus();
		} else {
			$.post(basePath + "?m=login.check", { account:v_account, password:v_password }, function(data) {//alert(data);
				if(data[0] == "success") {
					window.location.href = basePath;
				} else {
					alert(data[1]);
					if(data[2] == "account is null") {
						O_Account.val("");
						O_Account.focus();
					} else if(data[2] == "password is null") {
						O_Password.val("");
						O_Password.focus();
					} else if(data[2] == "member is not exists") {
						O_Account.focus();
					} else if(data[2] == "member is stopped") {
						O_Account.focus();
					} else if(data[2] == "password error") {
						O_Password.val("");
						O_Password.focus();
					}
				}
			}, "json");
		}
	});
	$("#O_RegBtn").click(function() {
		var O_Account = $("#reg-account");
		var O_Password = $("#reg-password");
		var O_RePwd = $("#reg-repwd");
		var O_Name = $("#reg-name");
		var O_Mobile = $("#reg-mobile");
		
		var v_account = $.trim(O_Account.val()).replace(/ /g, '').replace(/'/g, '');
		var v_password = $.trim(O_Password.val()).replace(/ /g, '').replace(/'/g, '');
		var v_repwd = $.trim(O_RePwd.val()).replace(/ /g, '').replace(/'/g, '');
		var v_name = $.trim(O_Name.val()).replace(/ /g, '').replace(/'/g, '');
		var v_mobile = $.trim(O_Mobile.val()).replace(/ /g, '').replace(/'/g, '');
		
		if(v_account == "") {
			alert("用户名不能为空！");
			O_Account.val("");
			O_Account.focus();
		} else if(v_password == "") {
			alert("密码不能为空！");
			O_Password.val("");
			O_Password.focus();
		} else if(v_repwd != v_password) {
			alert("两次密码不一样！");
			O_RePwd.focus();
		} else if(v_name == "") {
			alert("姓名不能为空！");
			O_Name.val("");
			O_Name.focus();
		} else if(v_mobile == "") {
			alert("手机号码不能为空！");
			O_Mobile.val("");
			O_Mobile.focus();
		} else if(v_mobile != "" && !/^(13|15|18)\d{9}$/.test(v_mobile)){
			alert("请输入正确的手机号码！");
			O_Mobile.focus();
		} else {
			$.post(basePath + "?m=login.register", { account:v_account, password:v_password, name:v_name, mobile:v_mobile }, function(data) {//alert(data);
				if(data[0] == "success") {
					window.location.href = basePath;
				} else {
					alert(data[1]);
					if(data[2] == "account is null") {
						O_Account.val("");
						O_Account.focus();
					} else if(data[2] == "password is null") {
						O_Password.val("");
						O_Password.focus();
					} else if(data[2] == "member is exists") {
						O_Account.focus();
					} else if(data[2] == "name is null") {
						O_Name.val("");
						O_Name.focus();
					} else if(data[2] == "mobile is null") {
						O_Mobile.val("");
						O_Mobile.focus();
					}
				}
			}, "json");
		}
	});
});