$(function(){

	onloadurl();

	$("#submitBtn").click(function(){
		var postId = $("#postId").val();
		var name = $("#name").val();
		var width = $("#width").val();
		var height = $("#height").val();
		var demo = $("#demo").val();

		if(postId=='' || postId=='0'){
			if(name==''){
				layer.msg('添加广告位，名称不能为空！',{icon: 5});
				return;
			}
		}
		var params = {
				postId:postId,
				name:name,
				width:width,
				height:height,
				demo:demo
		};

		var _httpURL = "";
		if(postId=='' || postId=='0'){
			_httpURL = HttpRest+"advertpost/create.shtml";
		}else{
			_httpURL = HttpRest+"advertpost/save.shtml";
		}
		$.ajax({
			url: _httpURL, 
			type: "post", 
			dataType: "json",
			data:$.toJSON(params),   
			contentType:"application/json",
			success: function(data) { 
				if(data.code=='01'){
					layer.confirm('保存成功！是否关闭窗口?', function(index) {
						parent.grid.loadData();
						parent.layer.close(parent.pageii);
						return false;
					});
				}else{
					layer.msg('保存失败！',{icon: 5});
				}
			}
		});
	});

});