$(function () {
	//实例化编辑器
	//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
	UE.delEditor('customer_memo');
	var customer_memo_editor = UE.getEditor('customer_memo'); //客户备注编辑框
	$("#customer_customerName").validatebox({
		required : true, 
		missingMessage : '请输入客户名称',
	});

	$("#customer_customerType").validatebox({
		required : true, 
		missingMessage : '请输入客户类型',
	});

	$("#customer_telephone").validatebox({
		required : true, 
		missingMessage : '请输入客户电话',
	});

	$("#customer_customerAddress").validatebox({
		required : true, 
		missingMessage : '请输入客户地址',
	});

	//单击添加按钮
	$("#customerAddButton").click(function () {
		//验证表单 
		if(!$("#customerAddForm").form("validate")) {
			$.messager.alert("错误提示","你输入的信息还有错误！","warning");
			$(".messager-window").css("z-index",10000);
		} else {
			$("#customerAddForm").form({
			    url:"Customer/add",
			    onSubmit: function(){
					if($("#customerAddForm").form("validate"))  { 
	                	$.messager.progress({
							text : "正在提交数据中...",
						}); 
	                	return true;
	                } else {
	                    return false;
	                }
			    },
			    success:function(data){
			    	$.messager.progress("close");
                    //此处data={"Success":true}是字符串
                	var obj = jQuery.parseJSON(data); 
                    if(obj.success){ 
                        $.messager.alert("消息","保存成功！");
                        $(".messager-window").css("z-index",10000);
                        $("#customerAddForm").form("clear");
                        customer_memo_editor.setContent("");
                    }else{
                        $.messager.alert("消息",obj.message);
                        $(".messager-window").css("z-index",10000);
                    }
			    }
			});
			//提交表单
			$("#customerAddForm").submit();
		}
	});

	//单击清空按钮
	$("#customerClearButton").click(function () { 
		$("#customerAddForm").form("clear"); 
	});
});
