$(function() {
	var O_Submit = $("#O_Submit");
	$("#O_Account").focus();
	$("body").bind('keyup', function(event) {
		if(event.keyCode == "13"){
			O_Submit.focus();
			checkAdd();
		}
	});
	O_Submit.click(function() {
		checkAdd();
	});
});
function checkAdd() {
	var O_Account = $("#O_Account");
	var O_Psd = $("#O_Psd");
	var O_Psd_Re = $("#O_Psd_Re");
	var O_Company = $("#O_Company");
	var O_Name = $("#O_Name");
	var O_Mobile = $("#O_Mobile");
	var O_Phone = $("#O_Phone");
	var O_QQ = $("#O_QQ");
	var O_Email = $("#O_Email");
	var O_Address = $("#O_Address");
	var O_Postcode = $("#O_Postcode");
	
	var v_account = O_Account.val().replace(/ /g, '').replace(/'/g, '');
	var v_psd = O_Psd.val().replace(/ /g, '').replace(/'/g, '');
	var v_psd_re = O_Psd_Re.val();
	var v_company = O_Company.val().replace(/ /g, '').replace(/'/g, '');
	var v_name = O_Name.val().replace(/ /g, '').replace(/'/g, '');
	var v_sex = $("[name='O_Sex']:checked").val(); 
	var v_mobile = O_Mobile.val().replace(/ /g, '').replace(/'/g, '');
	var v_phone = O_Phone.val().replace(/ /g, '').replace(/'/g, '');
	var v_qq = O_QQ.val().replace(/ /g, '').replace(/'/g, '');
	var v_email = O_Email.val().replace(/ /g, '').replace(/'/g, '');
	var v_address = O_Address.val().replace(/ /g, '').replace(/'/g, '');
	var v_postcode = O_Postcode.val().replace(/ /g, '').replace(/'/g, '');
	var v_status = $("[name='O_Status']:checked").val();

	if(v_account == "") {
		alert("帐号不能为空！");
		O_Account.val("");
		O_Account.focus();
	} else if(v_name == "") {
		alert("姓名不能为空！");
		O_Name.val("");
		O_Name.focus();
	} else if(v_psd == "") {
		alert("登录密码不能为空！");
		O_Psd.val("");
		O_Psd.focus();
	} else if(v_psd != v_psd_re) {
		alert("两次输入密码不一致！");
		O_Psd_Re.val("");
		O_Psd_Re.focus();
	} else if(v_mobile == "") {
		alert("手机号码不能为空！");
		O_Mobile.val("");
		O_Mobile.focus();
	} else if(!/^(13|15|18)\d{9}$/.test(v_mobile)) {
		alert("请输入正确的手机号码！");
		O_Mobile.focus();
	} else if(v_phone != "" && !/(^\d{3,4}\-\d{7,8}$)|(^\d{7,8}$)/.test(v_phone)) {
		alert("联系电话有误！");
		O_Phone.focus();
	} else if(v_qq != "" && !/\d{5,}$/.test(v_qq)) {
		alert("联系QQ有误！");
		O_QQ.focus();
	} else if(v_email != "" && !/.+@.+\.[a-zA-Z]{2,4}$/.test(v_email)) {
		alert("Email有误！");
		O_Email.focus();
	} else if(v_postcode != "" && !/\d{6,}$/.test(v_postcode)) {
		alert("邮编有误！");
		O_Postcode.focus();
	} else {
		var O_Submit = $("#O_Submit");
		O_Submit.attr("disabled", true);
		$.post("?m=admin/member.addHandle", { account:v_account, password:v_psd, company:v_company, name:v_name, sex:v_sex, mobile:v_mobile, phone:v_phone, qq:v_qq, email:v_email, address:v_address, postcode:v_postcode, status:v_status }, function(data) {//alert(data);
			alert(data[1]);
			if(data[0] == "success") {
				O_Account.val("");
				O_Psd.val("");
				O_Psd_Re.val("");
				O_Company.val("");
				O_Name.val("");
				O_Mobile.val("");
				O_Phone.val("");
				O_QQ.val("");
				O_Email.val("");
				O_Address.val("");
				O_Postcode.val("");
			} else {
				if(data[2] == "account is exists") {
					O_Account.focus();
				} else if(data[2] == "account is null") {
					O_Account.focus();
				} else if(data[2] == "password is null") {
					O_Psd.focus();
				} else if(data[2] == "name is null") {
					O_Name.focus();
				} else if(data[2] == "mobile is null") {
					O_Mobile.focus();
				}
			}
			O_Submit.attr("disabled", false);
		}, "json");
	}
}