
function TableCreateManager() {
	this.tbTitle = ["第一栏", "第二栏", "第三栏", "第四栏"];
	this.rowType = ["String", "String", "String", "String", "String"];
	this.nodeName = ["R_1", "R_2", "R_3", "R_4"];
	this.celalign = ["center", "center", "center", "center"];
	this.divId = "data";
	this.tbId  = "datatable";
	this.tbBorder = "0";
	this.tbWidth  = "100%";
	this.tb = null;
	this.result = null;
	this.init = function () {
		var len = this.tbTitle.length;
		if (this.rowType.length != len || this.nodeName.length != len || this.nodeName.length != len || this.celalign.length != len) {
			return false;
		}
	};
	this.createTable = function () {
		// 表格属性
		var tb = document.createElement("TABLE");
		tb.id = this.tbId;
		tb.border = this.tbBorder;
		tb.width = this.tbWidth;
		
		// 表头
		var th = tb.createTHead();
		var row = th.insertRow();
		for (var i = 0, n = this.tbTitle.length; i < n; i++) {
			var cell = row.insertCell();
			cell.type = this.rowType[i] == null ? "String" : this.rowType[i];
			cell.align = "center";
			cell.innerHTML = this.tbTitle[i];
		}

		// 表身
		this.tb = tb;
	};
	this.append = function () {
		// 加到 dataDiv 里
		var obj = document.getElementById(this.divId);
		if (obj != null) {
			obj.innerHTML = "";
			if (document.getElementById(this.tbId) != null) {
				this.removeTb(this.tbId);
			}
			obj.appendChild(this.tb);
		}
	};

	// 清除表格
	this.removeTb = function (tbid) {
		var tb = document.getElementById(this.divId);
		if (tb) {
			tb.parentNode.removeChild(tb);
		}
	};
}
function TablePagesSet() {
	this.result = null;
	this.setTotalCountLabel = function (labid) {
		var obj = document.getElementById(labid);
		if (obj != null) {
			obj.innerHTML = this.result.totalCount;
		}
	};
	
	this.setTotalPageLabel = function (labid) {
		var obj = document.getElementById(labid);
		if (obj != null) {
			obj.innerHTML = this.result.pageCount;
		}
	};
	
	this.setCurPageLable = function (labid) {
		var obj = document.getElementById(labid);
		if (obj != null) {
			obj.innerHTML = this.result.page + 1;
		}
	};
	this.setPageLable = function (pageid, callback) {
		var obj1 = document.getElementById(pageid[0]);
		var obj2 = document.getElementById(pageid[1]);
		var obj3 = document.getElementById(pageid[2]);
		var obj4 = document.getElementById(pageid[3]);
		if (obj1 != null && obj2 != null && obj3 != null && obj4 != null) {
			if (!this.result.firstPage) {//不是第一页
				obj1.innerHTML = "<a href=\"javascript:loadData(0,'" + callback + "');\">首页</a>";
				obj2.innerHTML = "<a href=\"javascript:loadData(" + this.result.previousPage + ",'" + callback + "');\">上一页</a>";
			} 
			else {
				obj1.innerHTML = "首页";
				obj2.innerHTML = "上一页";
			}

			if (!this.result.lastPage) {//不是最后一页
				obj3.innerHTML = "<a href=\"javascript:loadData(" + this.result.nextPage + ",'" + callback + "');\">下一页</a>";
				obj4.innerHTML = "<a href=\"javascript:loadData(" + this.result.pageCount + ",'" + callback + "');\">尾页</a>";
			} 
			else {
				obj3.innerHTML = "下一页";
				obj4.innerHTML = "尾页";
			}
		}
	};
}

function createDiv(id, parent, innerValue, className, width, height) {
	var div = document.createElement("DIV");
	var parent = document.getElementById(parent);
	div.id = id;
	div.className = className;
	div.innerHTML = innerValue;
	if (width != null && width != "") {
		div.style.width = width;
	}
	if (width != null && height != "") {
		div.style.height = height;
	}
	parent.appendChild(div);
}

function removeDiv(id) {
	var div = document.getElementById(id);
	if (div) {
		div.parentNode.removeChild(div);
	}
}

