﻿/**
* GridViewBTD
* 
* @author     banhthidiem <banhthidiem@gmail.com>
* @copyright  2008 Bach Khoa Computer Inc.
* @version    1.0 2008/09/30
*/

var EventName =
{
	/******* Event Name of Update Data GridView *******/
	submit: "submit",
	submitComplete: "submitComplete",

	/******* Event Name of Paging GridView *******/
	pagingChange: "pagingChange",
	
	/******* Event Name of Sort Column *******/
	sort: "sortColumn",

	/******* Event Name of Columm GridView *******/
	click: "click",
	blur: "blur",
	focus: "focus",
	change: "change",
	dblClick: "dblclick",
	keyDown: "keydown",
	keyPress: "keypress",
	keyUp: "keyup",
	mouseDown: "mousedown",
	mouseUp: "mouseup",
	mouseOver: "mouseover",
	mouseMove: "mousemove",
	mouseOut: "mouseout",

	/******* Event Name of Row GridView *******/
	rowDataBound: "rowDataBound",
	rowClick: "rowClick",
	rowDblClick: "rowDblClick",
	rowMouseDown: "rowMouseDown",
	rowMouseUp: "rowMouseUp",
	rowMouseOver: "rowMouseOver",
	rowMouseMove: "rowMouseMove",
	rowMouseOut: "rowMouseOut",

	/******* Event Name of Function GridView *******/
	insertNewRecord: "insertNewRecord",
	editRecord: "editRecord",
	deleteRecord: "deleteRecord"
};

var BoundStatus =
{
	insert: "Insert",
	update: "Update",
	remove: "Remove"
};

var ColummType =
{
	radioBox: "radiobox",
	checkBox: "checkbox",
	textBox: "textbox",
	multiSelectBox: "multiSelectBox",
	selectBox: "selectBox",
	label: "label",
	labelDate: "labelDate",
	linkButton: "linkbutton",
	hyperLink: "hyperlink",
	image: "image",
	file: "file",
	textArea: "textArea",
	richText: "richText",
	email: "email",
	number: "number",
	date: "date",
	keyUpdate: "keyUpdate",
	none: "none"
};

var SortType = {
	none: "None", asc: "ASC", desc: "DESC", noSort: "noSort"
};

GridViewBTD = function(objContainer, listData, myName) {
	this.listData = listData;
	this.myName = myName;
	this.objContainer = objContainer;
	this.elGridView = null;
	this.elContainerGV = null;
	this.elCellContainerGV = null;
	this.elRowEdit = null;
	this.listMapHeader = [];
	this.widthOfFunctionColumn = 80;
	this.widthOfSelectionColumn = 20;

	/**************************Selection Row******************************/
	this.elSelectionAll = null;

	/*************** Add, Edit, Delete record Properties ******************/
	this.textTitleFormUpdate = "Cập nhật biểu mẩu";
	this.hasFile = false;
	this.isAddNewRecord = true;
	this.elContainerFormUpdate = null;
	this.elTableFormUpdate = null;
	this.popupFormUpdate = null;
	this.useUpdateDataSystem = false;

	/*************** Store cookie Properties ******************/
	this.cookieName = "";
	this.oCacheHeader = null;

	/*************** Move Column Properties ******************/
	this.elMoveColumn = null;
	this.elIconMoveColumn = null;
	this.elCellNeedMove = null;
	this.detalCoord = { X: 0, Y: 0 };
	this.startMoveCol = false;
	this.canMove = false;

	/*************** Resize Column Properties ******************/
	this.widthToResize = 3;
	this.gvWidth = 0;
	this.elCellResizing = null;
	this.canResize = false;
	this.startResizeCol = false;

	/*************** Main Menu Properties ******************/
	this.elMainMenu = null;
	this.elItemActiveMM = null;

	/*************** Sort Menu Properties ******************/
	this.elSortMenu = null;
	this.elSortCellTHead = null;

	/*************** Hide Column Properties ******************/
	this.isOverMenuColumn = false;
	this.elBtnShowCol = null;
	this.elMenuColumn = null;
	this.isShowBtn = false;
	this.isShowMenu = false;

	/*************** Event ******************/
	this.listEvent = new Array();

	/*************** Properties ******************/
	this.isShowAddNew = false;
	this.isShowEdit = true;
	this.isShowDelete = false;
	this.isShowPaging = false;
	this.isShowTotal = false;
	this.isAllowResizeColumn = false;
	this.isAllowMoveColumn = false;
	this.isAllowHideColumn = false;
	this.isAllowSortColumn = false;
	this.isAllowStoreCookie = false;
	this.isAllowSelectRow = false;

	/*************** Paging ******************/
	this.pagingRecord = { begin: 0, end: 0 };
	this.elPageChoose = null;
	this.currentIndexContainerPage = 1;
	this.listContainerPages = new Array();

	this.viewRecord = 0;
	this.totalPage = 0;
	this.totalRecord = 0;
	this.maxPage = 10;

	this.elContainerPagingPreview = null;
	this.elContainerPagingNext = null;

	/*************** Style ******************/
	this.cssHeaderTD = "headerTD";
	this.cssHeaderText = "headerText";
	this.cssBtnShowCol = "btnShowCol";
	this.cssContainerPaging = "containerPaging";

};

/*****************************************************************************
Private Methods Start
*****************************************************************************/

GridViewBTD.prototype.checkParentHaxFixed = function() {
	return utilObj.checkParentHaxFixed(this.elContainerGV);
};

/*======================================================================
============================Store in Cookie=============================
======================================================================*/
GridViewBTD.prototype.createCookieName = function() {
	var url = location.href.split("?")[0].split("#")[0] + this.myName;
	var strSpe = "_=(;)$.";
	for (var i = 0; i < strSpe.length; i++) {
		url = url.replace(new RegExp("\\" + strSpe.charAt(i), "gi"), "_" + i);
	}
	this.cookieName = url;
};

GridViewBTD.prototype.setCookie = function() {
	var oCacheHeader = new Object(); // { position: 1, display: "", width: 100 }
	for (var i = 0; i < this.listMapHeader.length; i++) {
		var elCell = this.listMapHeader[i].elCell;
		oCacheHeader[this.listMapHeader[i].item.name] = {
			position: elCell.cellIndex,
			display: elCell.style.display != "none" ? "" : "none",
			width: this.listMapHeader[i].item.width
		};
	}
	this.oCacheHeader = oCacheHeader;
	utilObj.setCookie(this.cookieName, JSON.stringify(oCacheHeader));
};

GridViewBTD.prototype.getCookie = function() {
	var value = utilObj.getCookie(this.cookieName);
	if (value != null) {
		value = JSON.eval(value);
		for (var i = 0; i < this.listData.head.length; i++) {
			var item = this.listData.head[i];
			if (value[item.name] == null) return null;
		}
	}
	for (var name in value) {
		var item = this.getHeadByName(name);
		if (item == null) {
			return null;
		}
	}
	return value;
};

GridViewBTD.prototype.getElContainer = function() {
	var re = null;
	if (typeof (this.objContainer) == "string")
		re = utilObj.getElById(this.objContainer);
	else
		re = this.objContainer;
	return re;
};

GridViewBTD.prototype.createGridView = function() {
	this.elContainerGV = utilObj.createEl("DIV");
	this.elContainerGV.className = "containerGV";
	this.getElContainer().appendChild(this.elContainerGV);
	var el = utilObj.createEl("TABLE");
	el.id = "GridView" + this.myName;
	el.className = "gridView";
	if (utilObj.isSafari) {
		el.style.width = "100%";
	}
	el.style.overflow = "hidden";
	el.style.tableLayout = "fixed";
	el.style.textOverflow = "ellipsis";
	this.elGridView = el;
	this.elContainerGV.appendChild(el);
};

/*======================================================================
==============================Sort Menu=================================
======================================================================*/

GridViewBTD.prototype.createEventSortColumn = function(el) {
	var self = this;
	utilObj.addEvent(el, "click", function(e) {
		if (el.head.item.sortType == SortType.noSort || self.isShowBtn || self.canResize) return;
		var sortType = el.head.item.sortType;
		sortType = sortType == SortType.asc ? SortType.desc : SortType.asc;
		self.onSortColumn(e, sortType);
	});
};

GridViewBTD.prototype.getListSortInfo = function() {
	var re = [];
	for (var i = 0; i < this.listData.head.length; i++) {
		var item = this.listData.head[i];
		if (item.sortType == SortType.none || item.sortType == SortType.noSort) continue;
		re.push({ field: item.name, typeSort: item.sortType });
	}
	return re;
};

GridViewBTD.prototype.onSortColumn = function(e, sortType) {
	for (var i = 0; i < this.listMapHeader.length; i++) {
		var item = this.listMapHeader[i].item;
		if (item.sortType == SortType.noSort) continue;
		item.sortType = SortType.none;
		this.listMapHeader[i].elCell.className = "sort " + item.sortType;
	}
	var item = this.elSortCellTHead.head.item;
	item.sortType = sortType;
	this.elSortCellTHead.elIconSort.className = "sort " + sortType;
	this.hideSortMenu(true);
	this.executeEventNormal(e, EventName.sort);
};

GridViewBTD.prototype.createSortMenu = function() {
	var elDIV = utilObj.createEl("DIV");
	elDIV.className = "mainMenuGV";
	elDIV.style.display = "none";
	utilObj.addChildToBody(elDIV);
	var self = this;
	utilObj.addEvent(elDIV, "mouseover", function(e) {
		self.isOverSortMenu = true;
	});
	utilObj.addEvent(elDIV, "mouseout", function(e) {
		self.isOverSortMenu = false;
	});
	utilObj.addEvent(window, "resize", function(e) {
		self.hideSortMenu();
	});
	utilObj.addEvent(document, "scroll", function(e) {
		self.hideSortMenu();
	});
	this.elSortMenu = elDIV;
	var self = this;
	var listItemSM = new Object();
	listItemSM["asc"] = { name: "Tăng dần", cssIcon: "asc", hasChildren: false,
		onClick: function(e, el) {
			self.onSortColumn(e, SortType.asc);
		},
		onMouseOver: function(e, el) {
		},
		onMouseOut: function() {
		}
	};
	listItemSM["desc"] = { name: "Giảm dần", cssIcon: "desc", hasChildren: false,
		onClick: function(e, el) {
			self.onSortColumn(e, SortType.desc);
		},
		onMouseOver: function(e, el) {
		},
		onMouseOut: function() {
		}
	};

	this.createItemSortMenu(listItemSM["asc"]);
	this.createItemSortMenu(listItemSM["desc"]);
};

GridViewBTD.prototype.showSortMenu = function(e, el) {

	var pos = utilObj.coordsElChildByParentIntelligent(e, this.elSortMenu, el);
	var size = utilObj.getElementSize(el);
	pos = { X: pos.X - 1, Y: pos.Y + 1 - size.height };
	this.elSortMenu.style.display = "block";
	this.elSortMenu.style.left = pos.X + "px";
	this.elSortMenu.style.top = pos.Y + "px";
};

GridViewBTD.prototype.hideSortMenu = function(force) {
	if (typeof force == "undefined") {
		if (this.isOverSortMenu) return;
	}
	if (this.elSortMenu != null) {
		this.elSortMenu.style.display = "none";
	}
};

GridViewBTD.prototype.createItemSortMenu = function(item) {
	var elA = utilObj.createEl("A");
	elA.item = item;
	elA.className = item.hasChildren ? "item hasChildren" : "item";
	var elImg = utilObj.createEl("DIV");
	elImg.className = "icon " + item.cssIcon;
	elA.appendChild(elImg);
	var elText = utilObj.createEl("LABEL");
	elText.innerHTML = item.name;
	elA.appendChild(elText);
	this.elSortMenu.appendChild(elA);
	var self = this;
	utilObj.addEvent(elA, "mouseover", function(e) {
		elA.className = item.hasChildren ? "item active hasChildren" : "item active";
		self.elItemActiveMM.className = "item active hasChildren";
		if (item.onMouseOver != null) item.onMouseOver(e, elA);
	});
	utilObj.addEvent(elA, "mouseout", function(e) {
		elA.className = item.hasChildren ? "item hasChildren" : "item";
		if (item.onMouseOut != null) item.onMouseOut();
	});
	utilObj.addEvent(elA, "click", function(e) {
		elA.className = item.hasChildren ? "item active hasChildren" : "item active";
		if (item.onClick != null) item.onClick(e, elA);
	});
};


/*======================================================================
==============================Main Menu=================================
======================================================================*/

GridViewBTD.prototype.createMainMenu = function() {
	var elDIV = utilObj.createEl("DIV");
	elDIV.className = "mainMenuGV";
	elDIV.style.display = "none";
	utilObj.addChildToBody(elDIV);
	var self = this;
	utilObj.addEvent(window, "resize", function(e) {
		self.hideMainMenu();
	});
	utilObj.addEvent(document, "scroll", function(e) {
		self.hideMainMenu();
	});
	this.elMainMenu = elDIV;
	var self = this;
	var listItemMM = new Object();
	listItemMM["sortCol"] = { name: "Sắp xếp", cssIcon: "sort", hasChildren: true,
		onClick: function(e, el) {
			clearTimeout(self.toHideSM);
			clearTimeout(self.toShowMC);
			self.toShowSM = setTimeout(function() { self.showSortMenu(e, el); }, 100);
		},
		onMouseOver: function(e, el) {
			clearTimeout(self.toHideSM);
			clearTimeout(self.toShowMC);
			self.toShowSM = setTimeout(function() { self.showSortMenu(e, el); }, 100);
		},
		onMouseOut: function(e, el) {
			self.toHideSM = setTimeout(function() { self.hideSortMenu(); }, 100);
		}
	};
	listItemMM["hideCol"] = { name: "Cột", cssIcon: "columns", hasChildren: true,
		onClick: function(e, el) {
			clearTimeout(self.toHideMC);
			clearTimeout(self.toShowSM);
			self.toShowMC = setTimeout(function() { self.showMenuColumn(e, el); }, 100);
		},
		onMouseOver: function(e, el) {
			clearTimeout(self.toHideMC);
			clearTimeout(self.toShowSM);
			self.toShowMC = setTimeout(function() { self.showMenuColumn(e, el); }, 100);
		},
		onMouseOut: function(e, el) {
			self.toHideMC = setTimeout(function() { self.hideMenuColumn() }, 100);
		}
	};
	this.elMainMenu.listItem = listItemMM;

	if (this.isAllowSortColumn) {
		this.createSortMenu();
		this.createItemMainMenu(listItemMM["sortCol"]);
	}

	if (this.isAllowHideColumn) {
		this.createItemMainMenu(listItemMM["hideCol"]);
	}
};

GridViewBTD.prototype.showMainMenu = function(e, elParent) {
	var pos = utilObj.coordsElChildByParentIntelligent(e, this.elMainMenu, elParent);
	var size = utilObj.getElementSize(elParent);
	this.elMainMenu.style.display = "block";
	if (pos.posCase == "bottomRight" || pos.posCase == "topRight") {
		pos.X -= size.width;
	}
	else if (pos.posCase == "bottomLeft" || pos.posCase == "topLeft") {
		pos.X += size.width;
	}
	this.elMainMenu.style.left = pos.X + "px";
	this.elMainMenu.style.top = pos.Y + "px";
};

GridViewBTD.prototype.hideMainMenu = function() {
	if (this.isShowMenu) return;
	if (this.elMainMenu != null) {
		this.elMainMenu.style.display = "none";
	}
};

GridViewBTD.prototype.createItemMainMenu = function(item) {

	var elA = utilObj.createEl("A");
	elA.item = item;
	item.element = elA;
	elA.className = item.hasChildren ? "item hasChildren" : "item";
	var elImg = utilObj.createEl("DIV");
	elImg.className = "icon " + item.cssIcon;
	elA.appendChild(elImg);
	var elText = utilObj.createEl("LABEL");
	elText.innerHTML = item.name;
	elA.appendChild(elText);
	this.elMainMenu.appendChild(elA);
	var self = this;
	utilObj.addEvent(elA, "mouseover", function(e) {
		if (self.elItemActiveMM != null && self.elItemActiveMM != elA) {
			self.hideSortMenu();
			self.hideMenuColumn();
			self.elItemActiveMM.className = self.elItemActiveMM.item.hasChildren ? "item hasChildren" : "item";
		}
		self.elItemActiveMM = elA;
		elA.className = item.hasChildren ? "item active hasChildren" : "item active";
		if (item.onMouseOver != null) item.onMouseOver(e, elA);
	});
	utilObj.addEvent(elA, "mouseout", function(e) {
		self.elItemActiveMM = elA;
		elA.className = item.hasChildren ? "item hasChildren" : "item";
		if (item.onMouseOut != null) item.onMouseOut();
	});
	utilObj.addEvent(elA, "click", function(e) {
		self.elItemActiveMM = elA;
		elA.className = item.hasChildren ? "item active hasChildren" : "item active";
		if (item.onClick != null) item.onClick(e, elA);
	});
};

/*======================================================================
========================Show Or Hide Column=============================
======================================================================*/

//
// Dùng để ẩn 1 mãng cột
//
GridViewBTD.prototype.hideColumn = function(columnIndexs) {
	var tBody = this.elGridView.tBodies[this.elGridView.tBodies.length - 1];
	// Change css row
	for (var i = 0; i < tBody.rows.length; i++) {
		for (var j = 0; j < columnIndexs.length; j++) {
			tBody.rows[i].cells[columnIndexs[j]].style.display = "none";
		}
	}
	var total = 0;
	for (var j = 0; j < columnIndexs.length; j++) {
		var elCell = this.elGridView.tHead.rows[0].cells[columnIndexs[j]];
		total += parseInt(elCell.style.width, 10);
		elCell.head.item.isShow = false;
		elCell.style.display = "none";
	}
	this.elGridView.style.width = (this.gvWidth - total) + "px";
	this.gvWidth = parseInt(this.elGridView.style.width, 10);
};

//
// Dùng để hiện 1 mãng cột bị ẩn
//
GridViewBTD.prototype.showColumn = function(columnIndexs) {
	var tBody = this.elGridView.tBodies[this.elGridView.tBodies.length - 1];
	// Change css row
	for (var i = 0; i < tBody.rows.length; i++) {
		for (var j = 0; j < columnIndexs.length; j++) {
			tBody.rows[i].cells[columnIndexs[j]].style.display = "";
		}
	}
	for (var j = 0; j < columnIndexs.length; j++) {
		var elCell = this.elGridView.tHead.rows[0].cells[columnIndexs[j]];
		var w = (this.oCacheHeader == null) ? utilObj.getStyleEl(elCell, "width") : this.oCacheHeader[elCell.head.item.name].width;
		this.elGridView.style.width = (this.gvWidth + parseInt(w, 10)) + "px";
		elCell.style.display = "";
		elCell.head.item.isShow = true;
	}
	this.gvWidth = parseInt(this.elGridView.style.width, 10);
};

GridViewBTD.prototype.onItemMenuClick = function(e, el) {
	var elTarget = utilObj.getTargetElement();
	if (elTarget.tagName.toUpperCase() == "A") {
		el.elCheckBox.checked = !el.elCheckBox.checked;
	}
	if (el.elCheckBox.checked) {
		this.showColumn([this.listMapHeader[el.item.name].elCell.cellIndex]);
	}
	else {
		var count = 0;
		for (var i = 0; i < this.listMapHeader.length; i++) {
			if (this.listMapHeader[i].elCell.style.display != "none") {
				count++;
			}
		}
		if (count == 1) {
			el.elCheckBox.checked = true;
			return;
		}
		this.hideColumn([this.listMapHeader[el.item.name].elCell.cellIndex]);
	}
	if (this.isAllowStoreCookie) this.setCookie();
};

GridViewBTD.prototype.createItemMenuColumn = function(item) {

	var elA = utilObj.createEl("A");
	elA.item = item;
	elA.className = "item";
	var elInput = utilObj.createEl("INPUT");
	elA.elCheckBox = elInput;
	elInput.type = "CHECKBOX";
	elA.appendChild(elInput);
	elA.appendChild(utilObj.createElText(item.caption));
	this.elMenuColumn.appendChild(elA);
	elInput.checked = item.isShow;
	var self = this;
	utilObj.addEvent(elA, "mouseover", function(e) {
		self.elItemActiveMM.className = "item active hasChildren";
	});
	utilObj.addEvent(elA, "click", function(e) {
		self.onItemMenuClick(e, elA);
	});
};

GridViewBTD.prototype.createMenuColumn = function() {
	var elDIV = utilObj.createEl("DIV");
	elDIV.className = "menuColGV";
	elDIV.style.display = "none";
	utilObj.addChildToBody(elDIV);
	var self = this;
	utilObj.addEvent(elDIV, "mouseover", function(e) {
		self.isOverMenuColumn = true;
	});
	utilObj.addEvent(elDIV, "mouseout", function(e) {
		self.isOverMenuColumn = false;
	});
	utilObj.addEvent(window, "resize", function(e) {
		self.hideMenuColumn();
	});
	utilObj.addEvent(document, "scroll", function(e) {
		self.hideMenuColumn();
	});
	this.elMenuColumn = elDIV;
};

GridViewBTD.prototype.showMenuColumn = function(e, el) {
	var pos = utilObj.coordsElChildByParentIntelligent(e, this.elMenuColumn, el);
	var size = utilObj.getElementSize(el);
	pos = { X: pos.X - 1, Y: pos.Y + 1 - size.height };
	this.elMenuColumn.style.display = "block";
	this.elMenuColumn.style.left = pos.X + "px";
	this.elMenuColumn.style.top = pos.Y + "px";
};

GridViewBTD.prototype.hideMenuColumn = function() {
	if (this.isOverMenuColumn) return;
	this.isShowBtn = false;
	this.elMenuColumn.style.display = "none";
};

GridViewBTD.prototype.onBtnMenuMouseOver = function(e, el) {
	this.isShowBtn = true;
};

GridViewBTD.prototype.onBtnMenuMouseOut = function(e, el) {
	if (this.isShowMenu) return;
	this.isShowBtn = false;
	el.style.display = "none";
};

GridViewBTD.prototype.onBtnMenuClick = function(e, el) {
	this.isShowMenu = true;
	this.showMainMenu(e, el);
};

GridViewBTD.prototype.createBtnShowCol = function() {
	var elA = utilObj.createEl("A");
	elA.className = this.cssBtnShowCol;
	elA.href = "javascript:void(0)";
	elA.style.display = "none";
	this.elContainerGV.appendChild(elA);
	this.elBtnShowCol = elA;
	var self = this;
	utilObj.addEvent(elA, "mouseover", function(e) {
		self.onBtnMenuMouseOver(e, elA);
	});
	utilObj.addEvent(elA, "mouseout", function(e) {
		self.onBtnMenuMouseOut(e, elA);
	});
	var eventName = utilObj.isSafari || utilObj.isFF ? "click" : "mousedown";
	utilObj.addEvent(elA, eventName, function(e) {
		self.onBtnMenuClick(e, elA);
	});
};

GridViewBTD.prototype.onShowOrHideColMouseOver = function(e, el) {
	if (this.startResizeCol) return;
	this.elSortCellTHead = el.parentNode;

	if (this.isAllowSortColumn) {
		this.elMainMenu.listItem["sortCol"].element.style.display = this.elSortCellTHead.head.item.sortType == SortType.noSort ? "none" : "";
	}
	el.appendChild(this.elBtnShowCol);
	this.elBtnShowCol.style.display = "block";
	this.elBtnShowCol.style.right = this.widthToResize + "px";
	this.elBtnShowCol.style.top = "0px";
	if (this.isShowMenu) {
		this.onBtnMenuClick(e, this.elBtnShowCol);
		if (this.elMenuColumn.style.display == "block") {
			this.showMenuColumn(e, this.elItemActiveMM);
		}
		else if (this.elSortMenu.style.display == "block") {
			this.showSortMenu(e, this.elItemActiveMM);
		}
	}
};

GridViewBTD.prototype.onShowOrHideColMouseOut = function(e, el) {
	if (this.isShowMenu) return;
	this.elBtnShowCol.style.display = "none";
};

GridViewBTD.prototype.onShowOrHideColMouseUp = function(e) {
	var isHideMenu = true;
	var elTarget = utilObj.getTargetElement();
	while (elTarget != null && elTarget.className != null) {
		if ((elTarget.className == this.cssBtnShowCol && elTarget == this.elBtnShowCol) ||
			(elTarget.className == this.cssHeaderTD && elTarget.myName == this.myName) ||
			elTarget == this.elMenuColumn || elTarget == this.elMainMenu) {
			isHideMenu = false;
			utilObj.stopEvent();
			break;
		}
		elTarget = elTarget.parentNode;
	}
	if (isHideMenu) {
		this.isShowMenu = this.isShowBtn = false;
		if (this.elItemActiveMM != null) {
			this.elItemActiveMM.className = this.elItemActiveMM.item.hasChildren ? "item hasChildren" : "item";
		}
		this.elBtnShowCol.style.display = "none";
		this.hideMainMenu();
		this.hideMenuColumn();
		this.hideSortMenu();
	}
};

GridViewBTD.prototype.showOrHideColumn = function(el) {
	var self = this;
	utilObj.addEvent(el, "mouseover", function(e) {
		self.onShowOrHideColMouseOver(e, el);
	});
	utilObj.addEvent(el, "mouseout", function(e) {
		self.onShowOrHideColMouseOut(e, el);
	});
};

/*======================================================================
===========================Resize Column================================
======================================================================*/

GridViewBTD.prototype.changeWidthColumn = function() {
	// Set All Parent display = ""
	var listParentDisplayNone = [];
	var elParent = this.getElContainer();
	while (elParent != null && elParent.tagName != null) {
		var value = utilObj.getStyleEl(elParent, "display");
		if (value.toLowerCase() == "none") {
			elParent.style.display = "";
			listParentDisplayNone.push(elParent);
		}
		elParent = elParent.parentNode;
	}

	// Init
	var cells = this.elGridView.tHead.rows[0].cells;
	var total = 0;
	var isLoadFormCookie = false;
	var widths = [];
	var hasColFunc = this.isShowAddNew || this.isShowEdit || this.isShowDelete;
	if (this.isAllowStoreCookie) {
		isLoadFormCookie = this.oCacheHeader != null;
	}
	if (isLoadFormCookie) {
		if (this.isAllowSelectRow) {
			widths[widths.length] = {
				position: 0,
				width: this.widthOfSelectionColumn
			};
			total += this.widthOfSelectionColumn;
		}
		for (var name in this.oCacheHeader) {
			if (this.oCacheHeader[name].width == null) continue;
			widths[widths.length] = {
				position: this.oCacheHeader[name].position,
				width: this.oCacheHeader[name].width
			};
			if (this.oCacheHeader[name].display != "none") {
				total += this.oCacheHeader[name].width;
			}
		}
		if (hasColFunc) {
			widths[widths.length] = {
				position: cells[cells.length - 1].cellIndex,
				width: this.widthOfFunctionColumn
			};
			total += this.widthOfFunctionColumn;
		}
	}
	else {
		for (var i = 0; i < cells.length; i++) {
			var width = 0;
			if (this.isAllowSelectRow && i == 0) {
				width = this.widthOfSelectionColumn;
				total += width;
			}
			else if (hasColFunc && i == cells.length - 1) {
				width = this.widthOfFunctionColumn;
				total += width;
			}
			else if (cells[i].head != null) {
				if (cells[i].head.item.width != null && cells[i].head.item.width > 10) {
					width = cells[i].head.item.width;
				}
				else {
					width = utilObj.getElementSize(cells[i]).width;
					cells[i].head.item.width = width;
				}
				if (cells[i].head.item.isShow) {
					total += width;
				}
			}
			widths[widths.length] = {
				position: cells[i].cellIndex,
				width: width
			};
		}
	}
	this.gvWidth = total;
	this.elGridView.style.width = this.gvWidth + "px";
	for (var i = 0; i < widths.length; i++) {
		var head = cells[widths[i].position].head;
		if (head != null) {
			head.item.width = widths[i].width;
			if (isLoadFormCookie) {
				if (this.oCacheHeader[head.item.name].display == "none") {
					cells[widths[i].position].style.display = "none";
				}
			}
			else {
				if (!head.item.isShow) {
					cells[widths[i].position].style.display = "none";
				}
			}
		}
		cells[widths[i].position].style.width = widths[i].width + "px";
	}

	// Restore parent display = "none"
	for (var i = 0; i < listParentDisplayNone.length; i++) {
		listParentDisplayNone[i].style.display = "none";
	}
};

GridViewBTD.prototype.getElCellHeader = function(e) {
	var elTarget = utilObj.getTargetElement();
	while (elTarget != null && elTarget.className != null) {
		if (elTarget.className == this.cssHeaderTD && elTarget.myName == this.myName) {
			return elTarget;
		}
		elTarget = elTarget.parentNode;
	}
	return null;
};

GridViewBTD.prototype.onResizeColMouseMove = function(e) {
	if (this.isShowMenu) return;
	if (this.startMoveCol) return;
	var elCell = this.getElCellHeader(e);

	e = utilObj.getWindowEvent();
	var mouseCoords = utilObj.mouseCoords(e);
	if (elCell != null) {
		if (!elCell.head.item.isAllowResize) return;
		var elCellPos = utilObj.getElementPosition(elCell);
		var elCellSize = utilObj.getElementSize(elCell);
		var coord = elCellPos.X + elCellSize.width;
		if (coord - this.widthToResize <= mouseCoords.X && mouseCoords.X <= coord) {
			this.canResize = true;
			elCell.parentNode.style.cursor = "w-resize";
		}
		else {
			this.canResize = false;
			if (!this.startResizeCol) {
				elCell.parentNode.style.cursor = "default";
			}
		}
	}
	if (this.startResizeCol) {
		var detal = mouseCoords.X - this.mouseDownCoords.X;
		if (this.w + detal < 10) {
			return;
		}
		this.elGridView.style.width = this.gvWidth + detal + "px";
		this.elCellResizing.style.width = (this.w + detal) + "px";
		this.elCellResizing.head.item.width = this.w + detal;
	}
};

GridViewBTD.prototype.onResizeColMouseDown = function(e) {
	e = utilObj.getWindowEvent();
	if (utilObj.isRightClick(e)) return;
	var elCell = this.getElCellHeader();
	if (elCell == null || !this.canResize || elCell.isFunctionGV != null) return;
	this.elCellResizing = elCell;
	this.startResizeCol = true;
	this.mouseDownCoords = utilObj.mouseCoords(e);
	this.w = parseInt(this.elCellResizing.style.width, 10);
	utilObj.disableSelection(document.body);
	utilObj.stopEvent();
};

GridViewBTD.prototype.onResizeColMouseUp = function(e) {
	if (!this.startResizeCol) return;
	this.elCellResizing = null;
	this.startResizeCol = false;
	this.gvWidth = parseInt(this.elGridView.style.width, 10);
	utilObj.enableSelection(document.body);
	if (this.isAllowStoreCookie) this.setCookie();
};

GridViewBTD.prototype.resizeColumn = function() {
	var self = this;
	utilObj.addEvent(document, "mousedown", function(e) {
		self.onResizeColMouseDown(e);
	});
	utilObj.addEvent(document, "mousemove", function(e) {
		self.onResizeColMouseMove(e);
	});
	utilObj.addEvent(document, "mouseup", function(e) {
		self.onResizeColMouseUp(e);
	});
};

/*======================================================================
=============================Move Column================================
======================================================================*/

GridViewBTD.prototype.createIconMoveColumn = function() {
	var elDiv = utilObj.createEl("DIV");
	elDiv.className = "iconMoveColumn";
	elDiv.style.display = "none";
	this.elContainerGV.appendChild(elDiv);
	this.elIconMoveColumn = elDiv;
};

GridViewBTD.prototype.showIconMoveColumn = function(oPos) {
	var elIconCol = this.elIconMoveColumn;
	elIconCol.style.display = "";
	elIconCol.style.left = oPos.X + "px";
	elIconCol.style.top = (oPos.Y - 9) + "px";
};

GridViewBTD.prototype.hideIconMoveColumn = function() {
	this.elIconMoveColumn.style.display = "none";
};

GridViewBTD.prototype.createMoveColumn = function() {
	var elDiv = utilObj.createEl("DIV");
	elDiv.className = "moveColumn";
	elDiv.style.display = "none";
	this.elContainerGV.appendChild(elDiv);
	this.elMoveColumn = elDiv;
};

GridViewBTD.prototype.showMoveColumn = function(isFirst) {
	var elCol = this.elMoveColumn;
	if (!isFirst) {
		elCol.style.display = "";
		return;
	}
	var oPos = utilObj.getElementPosition(this.elCellMoving);
	var oSize = utilObj.getElementSize(this.elCellMoving);
	this.detalCoord = {
		X: this.mouseDownCoords.X - oPos.X,
		Y: this.mouseDownCoords.Y - oPos.Y
	};
	elCol.innerHTML = this.elCellMoving.firstChild.innerHTML;
	elCol.style.display = "none";
	elCol.style.left = oPos.X + "px";
	elCol.style.top = oPos.Y + "px";
	elCol.style.width = (oSize.width - this.widthToResize - 8) + "px";
	elCol.style.height = (oSize.height - 8) + "px";
};

GridViewBTD.prototype.hideMoveColumn = function() {
	this.elMoveColumn.style.display = "none";
};

GridViewBTD.prototype.onMoveColMouseDown = function(e) {
	e = utilObj.getWindowEvent();
	if (utilObj.isRightClick(e)) return;
	var elCell = this.getElCellHeader();
	if (elCell == null || this.canResize || elCell.isFunctionGV != null) return;
	this.startMoveCol = true;
	this.elCellMoving = elCell;
	this.mouseDownCoords = utilObj.mouseCoords(e);
	this.showMoveColumn(true);
	utilObj.disableSelection(document.body);
	utilObj.stopEvent();
};

GridViewBTD.prototype.onMoveColMouseMove = function(e) {
	if (this.isShowMenu) return;
	if (this.startResizeCol) return;
	e = utilObj.getWindowEvent();
	var mouseCoords = utilObj.mouseCoords(e);
	if (this.startMoveCol) {
		this.showMoveColumn(false);
		this.elMoveColumn.style.left = (mouseCoords.X - this.detalCoord.X) + "px";
		this.elMoveColumn.style.top = (mouseCoords.Y - this.detalCoord.Y) + "px";
		for (var i = 0; i < this.listMapHeader.length; i++) {
			var elCell = this.listMapHeader[i].elCell;
			if (this.elCellMoving != elCell && elCell.style.display != "none") {
				var elCellPos = utilObj.getElementPosition(elCell);
				var elCellSize = utilObj.getElementSize(elCell);
				var start = { X: elCellPos.X, Y: elCellPos.Y };
				var mid = { X: elCellPos.X + (elCellSize.width / 2), Y: elCellPos.Y };
				var end = { X: elCellPos.X + elCellSize.width, Y: elCellPos.Y };
				if (start.Y <= mouseCoords.Y && mouseCoords.Y < end.Y + elCellSize.height) {
					if (start.X <= mouseCoords.X && mouseCoords.X < mid.X) {
						this.canMove = true;
						this.elCellNeedMove = elCell;
						this.showIconMoveColumn(start);
						break;
					}
					else if (mid.X <= mouseCoords.X && mouseCoords.X < end.X) {
						this.canMove = true;
						this.elCellNeedMove = elCell.nextSibling;
						this.showIconMoveColumn(end);
						break;
					}
					else {
						this.hideIconMoveColumn();
					}
				}
				else {
					this.hideIconMoveColumn();
				}
			}
			else {
				this.canMove = false;
				this.hideIconMoveColumn();
			}
		}
	}
};

GridViewBTD.prototype.onMoveColMouseUp = function(e) {
	if (!this.startMoveCol) return;
	this.startMoveCol = false;
	this.hideMoveColumn();
	if (!this.canMove) return;
	this.canMove = false;
	this.hideIconMoveColumn();
	utilObj.enableSelection(document.body);
	var tBody = this.elGridView.tBodies[this.elGridView.tBodies.length - 1]; // Opera has not THead
	// Move Column
	var isTypeRichText = this.elCellMoving.head.item.type == ColummType.richText;
	for (var i = 0; i < tBody.rows.length; i++) {
		var elCells = tBody.rows[i].cells;
		var content = "";
		var elRichText = null;
		// Use for RichText
		if (isTypeRichText) {
			elRichText = elCells[this.elCellMoving.cellIndex].element;
			content = elRichText.getContent();
		}

		tBody.rows[i].insertBefore(elCells[this.elCellMoving.cellIndex],
			elCells[this.elCellNeedMove.cellIndex]);
		// Use for RichText
		if (isTypeRichText) {
			elRichText.iframeInit(content);
		}
	}

	this.changeHeaderColumn();
	this.elCellMoving = this.elCellNeedMove = null;
	if (this.isAllowStoreCookie) this.setCookie();
};

GridViewBTD.prototype.moveColumn = function() {
	this.createMoveColumn();
	this.createIconMoveColumn();
	var self = this;
	utilObj.addEvent(document, "mousedown", function(e) {
		self.onMoveColMouseDown(e);
	});
	utilObj.addEvent(document, "mousemove", function(e) {
		self.onMoveColMouseMove(e);
	});
	utilObj.addEvent(document, "mouseup", function(e) {
		self.onMoveColMouseUp(e);
	});
};

GridViewBTD.prototype.changeHeaderColumn = function() {

	var headMoving = this.elCellMoving.head;
	var headNeedMove = this.elCellNeedMove.head;

	// Insert 1 item head to NeedMove position
	var cellNeedMoveIndex = this.isAllowSelectRow ? this.elCellNeedMove.cellIndex - 1 : this.elCellNeedMove.cellIndex;
	this.listMapHeader.splice(cellNeedMoveIndex, 0, headMoving);
	// Remove 1 item in Moving position
	var detal = this.elCellMoving.cellIndex > this.elCellNeedMove.cellIndex ? 1 : 0;
	var cellMovingIndex = this.isAllowSelectRow ? this.elCellMoving.cellIndex - 1 : this.elCellMoving.cellIndex;
	this.listMapHeader.splice(cellMovingIndex + detal, 1);
	// ElCell
	this.elGridView.tHead.rows[0].insertBefore(this.elCellMoving, this.elCellNeedMove);

};

/*======================================================================
===========================Selection Row================================
======================================================================*/

GridViewBTD.prototype.setStyleRow = function(elCheckBox) {
	var elRow = elCheckBox.parentNode.parentNode;
	if (elCheckBox.checked) {
		elRow.className = elRow.className.replace("bgColor", "");
		elRow.className = elRow.className.replace("alternatingBgColor", "");
		if(elRow.className.indexOf("selectionBgColor", 0) == -1) {
			elRow.className += " selectionBgColor";
		}
	}
	else {
		elRow.className = elRow.className.replace("selectionBgColor", "");
		if ((elRow.rowIndex % 2 != 0) && (elRow.className.indexOf("bgColor", 0) == -1))
		{
			elRow.className += " bgColor";
		}
		else if((elRow.rowIndex % 2 == 0 )  && (elRow.className.indexOf("alternatingBgColor", 0) == -1))
		{
			elRow.className += " alternatingBgColor";
		}
	}
};

GridViewBTD.prototype.changeStatusSelectAllRow = function() {
	var tBody = this.elGridView.tBodies[this.elGridView.tBodies.length - 1];
	for (var i = 0; i < tBody.rows.length; i++) {
		tBody.rows[i].cells[0].element.checked = this.elSelectionAll.checked;
		this.setStyleRow(tBody.rows[i].cells[0].element);
	}
};

GridViewBTD.prototype.createElCellSelectAllRow = function(elRow) {
	if (!this.isAllowSelectRow) return;
	var elCell = elRow.insertCell(elRow.cells.length);
	elCell.isFunctionGV = true;
	elCell.style.width = this.widthOfSelectionColumn + "px";
	elCell.style.textAlign = "center";

	elCell.element = utilObj.createEl("INPUT");
	elCell.element.type = "CHECKBOX";
	elCell.element.title = "Tất cả";
	elCell.element.style.padding = elCell.element.style.margin = "0px";
	this.elSelectionAll = elCell.element;
	elCell.appendChild(elCell.element);
	var self = this;
	utilObj.addEvent(elCell.element, "click", function(e) {
		self.changeStatusSelectAllRow();
	});
};

GridViewBTD.prototype.setRowsSelected = function(values, fieldValue) {
	if (!this.isAllowSelectRow || this.elGridView == null) return;
	values = utilObj.convertArrayToDictionary(values);
	var tBody = this.elGridView.tBodies[this.elGridView.tBodies.length - 1];
	var count = 0;
	for (var i = 0; i < tBody.rows.length; i++) {
		if (values[tBody.rows[i].item[fieldValue]] != null) {
			count++;
			tBody.rows[i].cells[0].element.checked = true;
		}
		else {
			tBody.rows[i].cells[0].element.checked = false;
		}
		this.setStyleRow(tBody.rows[i].cells[0].element);
	}
	this.elSelectionAll.checked = count == tBody.rows.length;
};

GridViewBTD.prototype.addRowsSelected = function(values, fieldValue) {
	if (!this.isAllowSelectRow || this.elGridView == null) return;
	values = utilObj.convertArrayToDictionary(values);
	var tBody = this.elGridView.tBodies[this.elGridView.tBodies.length - 1];
	var count = 0;
	for (var i = 0; i < tBody.rows.length; i++) {
		if (values[tBody.rows[i].item[fieldValue]] != null) {
			tBody.rows[i].cells[0].element.checked = true;
			this.setStyleRow(tBody.rows[i].cells[0].element);
		}
		if (tBody.rows[i].cells[0].element.checked) {
			count++;
		}
	}
	this.elSelectionAll.checked = count == tBody.rows.length;
};


GridViewBTD.prototype.getRowsSelected = function() {
	var rows = [];
	if (!this.isAllowSelectRow || this.elGridView == null) return rows;
	var tBody = this.elGridView.tBodies[this.elGridView.tBodies.length - 1];
	for (var i = 0; i < tBody.rows.length; i++) {
		if (tBody.rows[i].cells[0].element.checked) {
			rows.push(tBody.rows[i]);
		}
	}
	return rows;
};

GridViewBTD.prototype.changeStatusSelectRow = function(el) {
	this.setStyleRow(el);
	var isAll = true;
	var tBody = this.elGridView.tBodies[this.elGridView.tBodies.length - 1];
	for (var i = 0; i < tBody.rows.length; i++) {
		if (!tBody.rows[i].cells[0].element.checked) {
			isAll = false;
			break;
		}
	}
	this.elSelectionAll.checked = isAll;
};

GridViewBTD.prototype.createElCellSelectRow = function(elRow) {
	if (!this.isAllowSelectRow) return;
	var elCell = elRow.insertCell(elRow.cells.length);
	elCell.isFunctionGV = true;
	elCell.element = utilObj.createEl("INPUT");
	elCell.style.textAlign = "center";
	elCell.element.type = "CHECKBOX";
	elCell.element.style.padding = elCell.element.style.margin = "0px";
	elCell.appendChild(elCell.element);
	var self = this;
	utilObj.addEvent(elCell.element, "click", function(e) {
		self.changeStatusSelectRow(elCell.element);
	});
};

/*======================================================================
=============================Create GV==================================
======================================================================*/

GridViewBTD.prototype.getColumnIndex = function(name) {
	return this.listMapHeader[name].elCell.cellIndex;
};

GridViewBTD.prototype.getHeadByName = function(name) {
	for (var i = 0; i < this.listData.head.length; i++) {
		var item = this.listData.head[i];
		if (item.name == name) return item;
	}
	return null;
};

GridViewBTD.prototype.createElCellOfTHead = function(elRow, item) {
	var elCell = elRow.insertCell(elRow.cells.length);
	elCell.myName = this.myName;
	elCell.className = this.cssHeaderTD;
	item.isAllowHide = item.isAllowHide != null ? item.isAllowHide : true;

	var elDiv = utilObj.createEl("DIV");
	if (this.isAllowHideColumn) {
		this.showOrHideColumn(elDiv);
		if (item.isAllowHide) {
			this.createItemMenuColumn(item);
		}
	}
	elCell.element = elDiv;
	elCell.appendChild(elDiv);
	if (typeof (item.captionNote) != "undefined") {
		elDiv.title = item.captionNote;
	}

	elDiv.className = this.cssHeaderText;
	if (item.cssHeader != null && item.cssHeader != "") {
		elDiv.className += " " + item.cssHeader;
	}
	var elLabel = utilObj.createEl("LABEL");
	elLabel.innerHTML = item.caption;
	elDiv.appendChild(elLabel);

	if (this.isAllowSortColumn) {
		// Sort
		var elIconSort = utilObj.createEl("DIV");
		elIconSort.className = "sort " + SortType.none;
		elDiv.appendChild(elIconSort);
		elCell.elIconSort = elIconSort;
		this.createEventSortColumn(elCell);
	}

	return elCell;
};

GridViewBTD.prototype.createTHead = function() {
	var el = this.elGridView.createTHead();
	el.id = "tHeadGridView" + this.myName;
	var elRow = el.insertRow(el.rows.length);
	elRow.className = "gridViewTitle";
	var elCell = null;
	var isLoadFormCookie = false;

	if (this.isAllowSortColumn || this.isAllowHideColumn) {
		this.createMainMenu();
	}

	if (this.isAllowHideColumn) {
		this.createBtnShowCol();
		this.createMenuColumn();
		var self = this;
		utilObj.addEvent(document, "mouseup", function(e) {
			self.onShowOrHideColMouseUp(e);
		});
	}
	if (this.isAllowStoreCookie) {
		this.createCookieName();
		this.oCacheHeader = this.getCookie();
		isLoadFormCookie = this.oCacheHeader != null;
	}
	this.createElCellSelectAllRow(elRow);
	if (isLoadFormCookie) {
		for (var name in this.oCacheHeader) {
			var item = this.getHeadByName(name);
			if (item == null) continue;
			item.isShow = this.oCacheHeader[name].display == "";
			item.isAllowResize = item.isAllowResize != null ? item.isAllowResize : true;
			item.sortType = item.sortType != null ? item.sortType : SortType.none;
			var elCellTHead = this.createElCellOfTHead(elRow, item);
			if (!item.isAllowResize) {
				this.oCacheHeader[name].width = item.width;
			}
			var head = {
				item: item,
				elCell: elCellTHead
			};
			elCellTHead.head = head;
			var indexList = this.isAllowSelectRow ? this.oCacheHeader[name].position - 1 : this.oCacheHeader[name].position;
			this.listMapHeader[indexList] = this.listMapHeader[name] = head;
		}
	}
	else {
		for (var i = 0; i < this.listData.head.length; i++) {
			var item = this.listData.head[i];
			item.isShow = item.isShow != null ? item.isShow : true;
			item.isAllowResize = item.isAllowResize != null ? item.isAllowResize : true;
			item.sortType = item.sortType != null ? item.sortType : SortType.none;
			
			var elCellTHead = this.createElCellOfTHead(elRow, item);
			var head = {
				item: item,
				elCell: elCellTHead
			};
			elCellTHead.head = head;
			this.listMapHeader[i] = this.listMapHeader[item.name] = head;
		}
	}

	this.createFunctionAddNew(elRow);
};

GridViewBTD.prototype.createTFoot = function() {
	if (!this.isShowPaging && !this.isShowTotal) return;
	var el = this.elGridView.createTFoot();
	el.id = "tFootGridView" + this.myName;
	var elRow = el.insertRow(el.rows.length);
	var elCell = elRow.insertCell(0);
	elCell.colSpan = this.elGridView.tHead.rows[0].cells.length;
	elCell.className = "gridViewFoot";
};

GridViewBTD.prototype.createTBody = function() {
	this.elGridView.appendChild(utilObj.createEl("TBODY"));
	for (var i = 0; i < this.listData.data.length; i++) {
		this.insertRow(this.listData.data[i]);
	}
};

GridViewBTD.prototype.insertRow = function(item) {

	var tBody = this.elGridView.tBodies[this.elGridView.tBodies.length - 1];
	item.rowID = tBody.rows.length;
	var elRow = tBody.insertRow(tBody.rows.length);
	elRow.className = tBody.rows.length % 2 != 0 ? "bgColor" : "alternatingBgColor";
	elRow.item = item;
	item.elRow = elRow;
	// Create Cell for Selection Row
	this.createElCellSelectRow(elRow);
	for (var i = 0; i < this.listMapHeader.length; i++) {
		var elCell = this.insertCell(elRow, this.listMapHeader[i].item);
		if (this.isAllowHideColumn && this.oCacheHeader != null &&
			this.oCacheHeader[this.listMapHeader[i].item.name].display == "none" ||
			!this.listMapHeader[i].item.isShow) {
			elCell.style.display = "none";
		}
	}
	this.createFunctionUpdate(elRow);
	this.mapEventForRow(elRow);

	var e = new Object();
	e.boundStatus = BoundStatus.insert;
	this.executeEventForRow(e, elRow, EventName.rowDataBound);
};

GridViewBTD.prototype.insertCell = function(elRow, oHead) {
	var elCell = elRow.insertCell(elRow.cells.length);
	if (oHead.cssItem != null && oHead.cssItem != "") {
		elCell.className = oHead.cssItem;
	}
	switch (oHead.type) {
		case ColummType.hyperLink:
			this.createHyperLink(elCell, oHead);
			break;
		case ColummType.linkButton:
			this.createLinkButton(elCell, oHead);
			break;
		case ColummType.textBox:
			this.createTextBox(elCell, oHead);
			break;
		case ColummType.checkBox:
			this.createCheckBox(elCell, oHead);
			break;
		case ColummType.radioBox:
			this.createRadioBox(elCell, oHead);
			break;
		case ColummType.multiSelectBox:
			this.createMultiSelectBox(elCell, oHead);
			break;
		case ColummType.selectBox:
			this.createSelectBox(elCell, oHead);
			break;
		case ColummType.email:
		case ColummType.number:
		case ColummType.label:
			this.createLabel(elCell, oHead);
			break;
		case ColummType.labelDate:
			this.createLabelDate(elCell, oHead);
			break;
		case ColummType.file:
			this.createLinkFile(elCell, oHead);
			break;
		case ColummType.image:
			this.createImage(elCell, oHead);
			break;
		case ColummType.richText:
			this.createRichText(elCell, oHead);
			break;
		case ColummType.textArea:
			this.createTextArea(elCell, oHead);
			break;
		case ColummType.date:
			this.createDate(elCell, oHead);
			break;
	}
	return elCell;
};

GridViewBTD.prototype.updateCell = function(oHead, cellIndex) {
	var elCell = this.elRowEdit.cells[cellIndex];
	switch (oHead.type) {
		case ColummType.file:
			elCell.element.href = oHead.path + this.elRowEdit.item[oHead.field];
			elCell.element.innerHTML = (this.elRowEdit.item[oHead.field] == null) ? "" : this.elRowEdit.item[oHead.field];
			break;
		case ColummType.hyperLink:
			elCell.element.href = this.elRowEdit.item[oHead.fieldURL];
			elCell.element.innerHTML = (this.elRowEdit.item[oHead.field] == null) ? "" : this.elRowEdit.item[oHead.field];
			break;
		case ColummType.linkButton:
			elCell.element.innerHTML = (this.elRowEdit.item[oHead.field] == null) ? "" : this.elRowEdit.item[oHead.field];
			break;
		case ColummType.textBox:
			elCell.element.value = (this.elRowEdit.item[oHead.field] == null) ? "" : this.elRowEdit.item[oHead.field];
			break;
		case ColummType.checkBox:
			elCell.element.checked = this.elRowEdit.item[oHead.field];
			break;
		case ColummType.radioBox:
			var listElement = elCell.listElement; // Get list Element of Radio Box
			for (var i = 0; i < listElement.length; i++) {
				listElement[i].checked = this.elRowEdit.item[oHead.field] == listElement[i].value;
			}
			break;
		case ColummType.multiSelectBox:
			var dicData = utilObj.convertArrayToDictionary(this.elRowEdit.item[oHead.field]);
			elCell.element.selectedValues(dicData);
			break;
		case ColummType.selectBox:
			for (var i = 0; i < oHead.listItem.length; i++) {
				elCell.element[i].selected = this.elRowEdit.item[oHead.field] == oHead.listItem[i].value;
			}
			break;
		case ColummType.email:
		case ColummType.number:
		case ColummType.label:
			elCell.element.innerHTML = (this.elRowEdit.item[oHead.field] == null) ? "" : this.elRowEdit.item[oHead.field];
			break;
		case ColummType.labelDate:
			var value = "";
			if (this.elRowEdit.item[oHead.field] != "" && this.elRowEdit.item[oHead.field] != null) {
				if (!(this.elRowEdit.item[oHead.field] instanceof Date)) {
					this.elRowEdit.item[oHead.field] = Date.parseDate(this.elRowEdit.item[oHead.field], Date.stringFormat.dateTime);
				}
				value = this.elRowEdit.item[oHead.field].toVNString();
			}
			elCell.element.innerHTML = value;
			break;
		case ColummType.image:
			elCell.element.src = oHead.path + this.elRowEdit.item[oHead.field];
			break;
		case ColummType.textArea:
			elCell.element.value = (this.elRowEdit.item[oHead.field] == null) ? "" : this.elRowEdit.item[oHead.field];
			break;
		case ColummType.richText:
			elCell.element.setContent(this.elRowEdit.item[oHead.field] == null ? "" : this.elRowEdit.item[oHead.field]);
			break;
		case ColummType.date:
			var value = "";
			if (this.elRowEdit.item[oHead.field] != "" && this.elRowEdit.item[oHead.field] != null) {
				if (!(this.elRowEdit.item[oHead.field] instanceof Date)) {
					this.elRowEdit.item[oHead.field] = Date.parseDate(this.elRowEdit.item[oHead.field], Date.stringFormat.dateTime);
				}
				value = this.elRowEdit.item[oHead.field];
			}
			elCell.element.setDate(value);
			break;
	}
};

/*============================================================================
============================Form Insert, Edit, Delete=========================
============================================================================*/

GridViewBTD.prototype.createFieldUpdateTextBox = function(elCell, w) {
	elCell.element = utilObj.createEl("INPUT");
	elCell.element.type = "text";
	elCell.element.className = "inputText";
	elCell.element.style.width = w + "px";
	elCell.appendChild(elCell.element);
};

GridViewBTD.prototype.createFieldUpdateCheckBox = function(elCell) {
	elCell.element = utilObj.createEl("INPUT");
	elCell.element.type = "checkbox";
	elCell.appendChild(elCell.element);
};

GridViewBTD.prototype.createFieldUpdateRadioBox = function(elCell, oHead) {
	var elRow = elCell.parentNode;
	elCell.listElement = [];
	for (var i = 0; i < oHead.listItem.length; i++) {
		var elRadio = utilObj.createEl("INPUT");
		elRadio.id = this.myName + "Update" + oHead.name + elRow.rowIndex + i;
		elRadio.name = this.myName + "Update" + oHead.name + elRow.rowIndex;
		elRadio.type = "radio";
		elRadio.value = oHead.listItem[i].value;
		elCell.appendChild(elRadio);
		elCell.listElement.push(elRadio);

		var elLabel = utilObj.createEl("LABEL");
		elLabel.htmlFor = elRadio.id;
		elLabel.innerHTML = oHead.listItem[i].text;
		elCell.appendChild(elLabel);
	}
};

GridViewBTD.prototype.createFieldUpdateSelectBox = function(elCell, oHead) {
	elCell.element = utilObj.createEl("SELECT");
	elCell.element.className = "inputText";
	for (var i = 0; i < oHead.listItem.length; i++) {
		var elOption = this.createOption(oHead.listItem[i]);
		try {
			elCell.element.add(elOption, null); // standards compliant
		}
		catch (ex) {
			elCell.element.add(elOption); // IE only
		}
	}
	elCell.appendChild(elCell.element);
};

GridViewBTD.prototype.createFieldUpdateMultiSelectBox = function(elCell, oHead) {
	elCell.element = new MultiSelectBoxBTD(elCell, oHead.dataMSB, this.myName + "_oMSBUpdate");
};

GridViewBTD.prototype.createFieldUpdateFile = function(elCell, rowIndex) {
	elCell.elContainerFile = utilObj.createEl("DIV");
	elCell.appendChild(elCell.elContainerFile);

	elCell.element = utilObj.createEl("INPUT");
	elCell.element.name = "imageFieldUpdateDataGV" + this.myName + rowIndex;
	elCell.element.className = "inputText";
	elCell.element.type = "file";
	elCell.appendChild(elCell.element);
};


GridViewBTD.prototype.createFieldUpdateTextArea = function(elCell, w) {
	elCell.element = utilObj.createEl("TEXTAREA");
	elCell.element.rows = 4;
	elCell.element.className = "inputText";
	elCell.element.style.width = w + "px";
	elCell.appendChild(elCell.element);
};

GridViewBTD.prototype.createFieldUpdateRichText = function(elCell) {
	elCell.element = new ObjectIframe(elCell, "elementRTE" + this.myName, "", "100%", 100, "inputText");
};

GridViewBTD.prototype.createFieldUpdateDate = function(elCell) {
	elCell.element = new CalendarBTD(elCell, "elCalendar" + this.myName, "", false);
};

GridViewBTD.prototype.createFieldUpdateKey = function(elCell) {
	elCell.element = utilObj.createEl("INPUT");
	elCell.element.type = "hidden";
	elCell.appendChild(elCell.element);
};

GridViewBTD.prototype.createFieldFormUpdate = function(oHead) {
	var elRow = this.elTableFormUpdate.insertRow(this.elTableFormUpdate.rows.length);
	var elCell = elRow.insertCell(0);
	elCell.innerHTML = oHead.caption + ":";
	elCell = elRow.insertCell(1);
	oHead.elCellFormUpdate = elCell;
	var w = oHead.widthEdit != null ? oHead.widthEdit : (oHead.width != null ? oHead.width : 200);
	w = w > 300 ? 300 : (w < 50 ? 50 : w);
	switch (oHead.typeUpdate) {
		case ColummType.email:
		case ColummType.number:
		case ColummType.textBox:
			this.createFieldUpdateTextBox(elCell, w);
			break;
		case ColummType.checkBox:
			this.createFieldUpdateCheckBox(elCell);
			break;
		case ColummType.radioBox:
			this.createFieldUpdateRadioBox(elCell, oHead);
			break;
		case ColummType.multiSelectBox:
			this.createFieldUpdateMultiSelectBox(elCell, oHead);
			break;
		case ColummType.selectBox:
			this.createFieldUpdateSelectBox(elCell, oHead);
			break;
		case ColummType.file:
		case ColummType.image:
			this.hasFile = true;
			this.createFieldUpdateFile(elCell, elRow.rowIndex);
			break;
		case ColummType.textArea:
			this.createFieldUpdateTextArea(elCell, w);
			break;
		case ColummType.richText:
			this.createFieldUpdateRichText(elCell);
			break;
		case ColummType.date:
			this.createFieldUpdateDate(elCell);
			break;
		case ColummType.keyUpdate:
			this.createFieldUpdateKey(elCell);
			elRow.style.display = "none";
			break;
	}
};

GridViewBTD.prototype.checkFieldFormUpdate = function(oHead) {
	var elCell = oHead.elCellFormUpdate;
	oHead.isAllowUpdateNull = oHead.isAllowUpdateNull != null ? oHead.isAllowUpdateNull : false;
	if (oHead.isAllowUpdateNull ||
		(!this.isAddNewRecord && (oHead.typeUpdate == ColummType.file || oHead.typeUpdate == ColummType.image))) return true;
	switch (oHead.typeUpdate) {
		case ColummType.email:
			elCell.element.value = elCell.element.value.trim();
			if (elCell.element.value.trim() == "" || !utilObj.isEmail(elCell.element.value)) {
				alert("Mời bạn nhập \"" + oHead.caption + "\" phải đúng cú pháp email!");
				elCell.element.focus();
				return false;
			}
			break;
		case ColummType.number:
			elCell.element.value = elCell.element.value.trim();
			if (elCell.element.value == "" || !utilObj.isNumber(elCell.element.value)) {
				alert("Mời bạn nhập \"" + oHead.caption + "\" phải là số!");
				elCell.element.focus();
				return false;
			}
			break;
		case ColummType.textBox:
		case ColummType.textArea:
			if (elCell.element.value.trim() == "") {
				alert("Mời bạn nhập \"" + oHead.caption + "\"!");
				elCell.element.focus();
				return false;
			}
			break;
		case ColummType.file:
		case ColummType.image:
			if (elCell.element.value == "") {
				alert("Mời bạn nhập \"" + oHead.caption + "\"!");
				return false;
			}
			break;
		case ColummType.richText:
			if (elCell.element.getContent() == "") {
				alert("Mời bạn nhập \"" + oHead.caption + "\"!");
				elCell.element.focus();
				return false;
			}
			break;
		case ColummType.date:
			if (elCell.element.getStringDate() == "") {
				alert("Mời bạn chọn \"" + oHead.caption + "\"!");
				elCell.element.focus();
				return false;
			}
			break;
		case ColummType.radioBox:
			var isOk = false;
			for (var i = 0; i < elCell.listElement.length; i++) {
				if (elCell.listElement[i].checked) {
					isOk = true;
					break;
				}
			}
			if (!isOk) {
				alert("Mời bạn chọn \"" + oHead.caption + "\"!");
				return false;
			}
			break;
		case ColummType.multiSelectBox:
			if (elCell.element.getValue() == "") {
				alert("Mời bạn chọn \"" + oHead.caption + "\"!");
				return false;
			}
			break;
	}
	return true;
};

GridViewBTD.prototype.setValueFieldFormUpdate = function(oHead, itemData) {
	var elCell = oHead.elCellFormUpdate;
	var data = itemData != null ? itemData[oHead.field] : oHead.defaultValue;
	switch (oHead.typeUpdate) {
		case ColummType.image:
			elCell.elContainerFile.innerHTML =
				data == null ? "" : "<img src='" + oHead.path + data + "' border='0' />";
			break;
		case ColummType.file:
			elCell.elContainerFile.innerHTML =
				data == null ? "" : "<a href='" + oHead.path + data + "'>" + data + "</a>";
			break;
		case ColummType.email:
		case ColummType.number:
		case ColummType.textBox:
		case ColummType.textArea:
		case ColummType.keyUpdate:
			elCell.element.value = data == null ? "" : data;
			break;
		case ColummType.radioBox:
			var listElement = elCell.listElement; // Get list Element of Radio Box
			for (var i = 0; i < listElement.length; i++) {
				if (data == null) {
					listElement[i].checked = false;
				}
				else {
					listElement[i].checked = data == listElement[i].value;
				}
			}
			break;
		case ColummType.multiSelectBox:
			var dicData = utilObj.convertArrayToDictionary(data == null ? new Object() : data);
			elCell.element.selectedValues(dicData);
			break;
		case ColummType.selectBox:
			if (data == null) break;
			for (var i = 0; i < oHead.listItem.length; i++) {
				if (data == oHead.listItem[i].value) {
					elCell.element[i].selected = true;
					break;
				}
			}
			break;
		case ColummType.checkBox:
			elCell.element.checked = data == null ? false : data;
			break;
		case ColummType.richText:
			elCell.element.setContent(data == null ? "" : data);
			break;
		case ColummType.date:
			elCell.element.setDate(data == null ? "" : data);
			break;
	}
	return "";
};

GridViewBTD.prototype.getValueFieldFormUpdate = function(oHead) {
	var elCell = oHead.elCellFormUpdate;
	switch (oHead.typeUpdate) {
		case ColummType.email:
		case ColummType.number:
		case ColummType.textBox:
		case ColummType.textArea:
		case ColummType.selectBox:
		case ColummType.keyUpdate:
			return elCell.element.value.trim();
		case ColummType.radioBox:
			for (var i = 0; i < elCell.listElement.length; i++) {
				if (elCell.listElement[i].checked) {
					return elCell.listElement[i].value;
				}
			}
		case ColummType.multiSelectBox:
			return elCell.element.getValueArray();
		case ColummType.checkBox:
			return elCell.element.checked;
		case ColummType.richText:
			return elCell.element.getContent();
		case ColummType.date:
			return elCell.element.getDate();
		case ColummType.file:
		case ColummType.image:
			return elCell.element.name;
	}
	return "";
};

GridViewBTD.prototype.initDataFormUpdate = function() {
	this.elContainerFormUpdate.reset();
	for (var i = 0; i < this.listData.head.length; i++) {
		var itemHeader = this.listData.head[i];
		if (itemHeader.typeUpdate != ColummType.none) {
			this.setValueFieldFormUpdate(itemHeader, this.isAddNewRecord ? null : this.elRowEdit.item);
		}
	}
};

GridViewBTD.prototype.responseComplete = function(e) {
	var newE = new Object();
	newE["isAddNew"] = this.isAddNewRecord;
	try {
		if (this.hasFile) {
			var i = e.elIframe;
			if (i.contentDocument) {
				var d = i.contentDocument;
			}
			else if (i.contentWindow) {
				var d = i.contentWindow.document;
			}
			// Create new Iframe d.location.href = "about:blank"
			if (d.location.href == "about:blank") {
				return;
			}
			newE["responseData"] = JSON.eval(Encoder.htmlDecode(d.body.innerHTML));
		}
		else {
			newE["responseData"] = e.result;
		}
		this.popupFormUpdate.hide(); // Hide Modal Popup
	}
	catch (err) { alert("Error 'responseComplete': " + err.message); }
	try {
		this.executeEventNormal(newE, EventName.submitComplete);
	}
	catch (err) {
		alert("Error 'responseComplete.executeEventNormal': " + err.message);
	}
};

GridViewBTD.prototype.submit = function(itemData, action) {
	if (action == null) return;
	if (this.hasFile) {
		this.elContainerFormUpdate.elObjectJson.value = JSON.stringify(itemData);
		this.elContainerFormUpdate.action = action;
		this.elContainerFormUpdate.submit();
	}
	else {
		if (action instanceof Function) {
			var self = this;
			action(itemData, function(e) { self.responseComplete(e); });
		}
	}
};

GridViewBTD.prototype.checkFormUpdate = function(e) {
	var itemData = new Object();
	for (var i = 0; i < this.listData.head.length; i++) {
		var itemHeader = this.listData.head[i];
		if (itemHeader.typeUpdate != ColummType.none) {
			if (this.checkFieldFormUpdate(itemHeader)) {
				itemData[itemHeader.field] = this.getValueFieldFormUpdate(itemHeader);
			}
			else {
				return null;
			}
		}
	}
	if (e == null) {
		e = utilObj.getWindowEvent();
		if (e == null) {
			e = new Object();
		}
	}
	e["isAddNew"] = this.isAddNewRecord;
	e["itemData"] = itemData;
	this.executeEventNormal(e, EventName.submit);
};

GridViewBTD.prototype.createBtnFormUpdate = function() {
	var self = this;
	var elDiv = utilObj.createEl("DIV");
	elDiv.style.textAlign = "center";
	elDiv.style.padding = "5px";
	this.elContainerFormUpdate.appendChild(elDiv);

	elDiv.elBtnOk = utilObj.createEl("INPUT");
	elDiv.elBtnOk.type = "button";
	elDiv.elBtnOk.value = "Ok";
	utilObj.addEvent(elDiv.elBtnOk, "click", function(e) {
		self.checkFormUpdate(e);
	});
	elDiv.appendChild(elDiv.elBtnOk);

	elDiv.elBtnCancel = utilObj.createEl("INPUT");
	elDiv.elBtnCancel.type = "button";
	elDiv.elBtnCancel.value = "Cancel";
	utilObj.addEvent(elDiv.elBtnCancel, "click", function(e) {
		self.popupFormUpdate.hide(); // Hide Modal Popup
	});
	elDiv.appendChild(elDiv.elBtnCancel);

	this.elContainerFormUpdate.elObjectJson = utilObj.createEl("INPUT");
	this.elContainerFormUpdate.elObjectJson.name = "DataJsonObject";
	this.elContainerFormUpdate.elObjectJson.type = "hidden";
	this.elContainerFormUpdate.elObjectJson.value = "";
	this.elContainerFormUpdate.appendChild(this.elContainerFormUpdate.elObjectJson);
};

GridViewBTD.prototype.setTitleFormUpdate = function(textTitle) {
	this.textTitleFormUpdate = textTitle;
	if (this.popupFormUpdate) {
		this.popupFormUpdate.setTitle(this.textTitleFormUpdate);
	}
};

GridViewBTD.prototype.createFormUpdate = function() {
	var self = this;
	this.elContainerFormUpdate = utilObj.createEl("FORM");
	this.elContainerFormUpdate.className = "popupFormUpdateGV";
	utilObj.addChildToBody(this.elContainerFormUpdate);
	// Create Modal Popup
	this.popupFormUpdate = new ModalPopup(this.elContainerFormUpdate, this.textTitleFormUpdate);

	var elDivStyle = utilObj.createEl("DIV");
	elDivStyle.className = "body";
	this.elContainerFormUpdate.appendChild(elDivStyle);
	var elTable = utilObj.createEl("TABLE");
	elTable.id = "formUpdateGV" + this.myName;
	elTable.className = "table";
	elTable.border = elTable.cellPadding = elTable.cellSpacing = 0;
	this.elTableFormUpdate = elTable;
	elDivStyle.appendChild(elTable);

	for (var i = 0; i < this.listData.head.length; i++) {
		var itemHeader = this.listData.head[i];
		if (itemHeader.typeUpdate != ColummType.none) {
			this.createFieldFormUpdate(itemHeader);
		}
	}
	this.createBtnFormUpdate();
	if (this.hasFile) {
		// Create Iframe submit
		var elIframe = utilObj.createEl("IFRAME");
		elIframe.name = elIframe.id = "iframeUpdateDataGV" + this.myName;
		elIframe.style.position = "absolute";
		elIframe.style.top = elIframe.style.left = "-1000px";
		elIframe.style.width = elIframe.style.height = "0px";
		this.elContainerFormUpdate.appendChild(elIframe);
		utilObj.addEvent(elIframe, "load", function(e) {
			e["elIframe"] = elIframe;
			self.responseComplete(e);
		});

		// Attribute of FormUpdate
		this.elContainerFormUpdate.method = "post";
		this.elContainerFormUpdate.encoding = "multipart/form-data";
		this.elContainerFormUpdate.target = elIframe.id;
	}
	utilObj.addEvent(this.elContainerFormUpdate, "keydown", function(e) {
		if (e.keyCode == 13 && (self.popupFormUpdate != null && self.popupFormUpdate.isShow)) {
			self.checkFormUpdate(e);
			utilObj.stopEvent();
		}
	});
};

GridViewBTD.prototype.showFormUpdate = function(isAddNewRecord) {
	this.isAddNewRecord = isAddNewRecord;
	if (this.elContainerFormUpdate == null) {
		this.createFormUpdate();
	}
	this.initDataFormUpdate();
	this.popupFormUpdate.display(); // Call Modal Popup
};

/*============================================================================
====================Create Element Insert, Edit, Delete=======================
============================================================================*/

GridViewBTD.prototype.createFunctionAddNew = function(elRow) {
	if (!this.isShowAddNew && !this.isShowEdit && !this.isShowDelete) return;

	var self = this;
	var elCell = elRow.insertCell(elRow.cells.length);
	elCell.style.textAlign = "center";
	elCell.style.width = this.widthOfFunctionColumn + "px";
	elCell.isFunctionGV = true;
	utilObj.addEvent(elCell, "mouseover", function(e) {
		if (!self.startResizeCol) elRow.style.cursor = "default";
	});

	if (!this.isShowAddNew) {
		var elDiv = utilObj.createEl("DIV");
		elDiv.className = this.cssHeaderText;
		elDiv.innerHTML = " ";
		elCell.appendChild(elDiv);
		return;
	}

	// Tag A Add New Record
	elCell.element = utilObj.createEl("A");
	elCell.element.style.padding = "4px";
	elCell.element.innerHTML = "Thêm mới";
	elCell.element.href = "javascript:void(0);";
	elCell.appendChild(elCell.element);
	// Add Event
	utilObj.addEvent(elCell.element, "click", function(e) {
		if (self.useUpdateDataSystem) {
			self.showFormUpdate(true);
		}
		else {
			self.executeEvent(e, elCell.element, EventName.insertNewRecord);
		}
	});
};

GridViewBTD.prototype.createFunctionUpdate = function(elRow) {
	if (!this.isShowAddNew && !this.isShowEdit && !this.isShowDelete) return;
	var elCell = elRow.insertCell(elRow.cells.length);
	elCell.style.textAlign = "center";
	elCell.isFunctionUpdate = true;
	var self = this;

	if (this.isShowEdit) {
		// Tag A Edit
		elCell.elEdit = utilObj.createEl("A");
		elCell.elEdit.innerHTML = "Sửa";
		elCell.elEdit.href = "javascript:void(0);";
		elCell.appendChild(elCell.elEdit);

		// Add Event
		utilObj.addEvent(elCell.elEdit, "click", function(e) {
			self.elRowEdit = elRow;
			if (self.useUpdateDataSystem) {
				self.showFormUpdate(false);
			}
			else {
				self.executeEvent(e, elCell.elEdit, EventName.editRecord);
			}
		});
	}

	if (this.isShowEdit && this.isShowDelete) {
		// Sep
		elCell.appendChild(utilObj.createElText(" - "));
	}

	if (this.isShowDelete) {
		// Tag A Delete
		elCell.elDelete = utilObj.createEl("A");
		elCell.elDelete.innerHTML = "Xóa";
		elCell.elDelete.href = "javascript:void(0);";
		elCell.appendChild(elCell.elDelete);
		// Add Event
		utilObj.addEvent(elCell.elDelete, "click", function(e) {
			self.executeEvent(e, elCell.elDelete, EventName.deleteRecord);
		});
	}
};

/*============================================================================
=========================Create Element for GridView==========================
============================================================================*/

GridViewBTD.prototype.createHyperLink = function(elCell, oHead) {
	var elRow = elCell.parentNode;
	elCell.element = utilObj.createEl("A");
	if (oHead.fieldURL != null && elRow.item[oHead.fieldURL]) {
		elCell.element.href = elRow.item[oHead.fieldURL];
	}
	else {
		elCell.element.href = "javascript:void(0)";
	}
	elCell.element.innerHTML = (elRow.item[oHead.field] == null) ? "" : elRow.item[oHead.field];
	elCell.appendChild(elCell.element);
	// Map event
	this.mapEvent(elCell.element, oHead.name);
};

GridViewBTD.prototype.createLinkFile = function(elCell, oHead) {
	var elRow = elCell.parentNode;
	elCell.element = utilObj.createEl("A");
	elCell.element.href = oHead.path + elRow.item[oHead.field];
	elCell.element.innerHTML = (elRow.item[oHead.field] == null) ? "" : elRow.item[oHead.field];
	elCell.appendChild(elCell.element);
	// Map event
	this.mapEvent(elCell.element, oHead.name);
};

GridViewBTD.prototype.createLinkButton = function(elCell, oHead) {
	var elRow = elCell.parentNode;
	elCell.element = utilObj.createEl("A");
	elCell.element.href = "javascript:void(0);";
	elCell.element.innerHTML = (elRow.item[oHead.field] == null) ? "" : elRow.item[oHead.field];
	elCell.appendChild(elCell.element);
	// Map event
	this.mapEvent(elCell.element, oHead.name);
	// Add Event
	if (oHead.action != null) {
		var self = this;
		var element = elCell.element;
		utilObj.addEvent(elCell.element, "click", function(e) {
			self.executeEventLinkButton(e, element, oHead.action, elRow);
		});
	}
};

GridViewBTD.prototype.executeEventLinkButton = function(e, element, func, elRow) {
	if (typeof (func) == "string") {
		eval(func)(element, elRow);
	}
	else if (func instanceof Function) {
		func(element, elRow);
	}
};

GridViewBTD.prototype.createTextBox = function(elCell, oHead) {
	var elRow = elCell.parentNode;
	elCell.element = utilObj.createEl("INPUT");
	elCell.element.type = "text";
	elCell.element.style.width = "100%";
	elCell.element.className = "inputText";
	elCell.element.value = (elRow.item[oHead.field] == null) ? "" : elRow.item[oHead.field];
	elCell.appendChild(elCell.element);
	// Map event
	this.mapEvent(elCell.element, oHead.name);
};

GridViewBTD.prototype.createCheckBox = function(elCell, oHead) {
	var elRow = elCell.parentNode;
	elCell.element = utilObj.createEl("INPUT");
	elCell.element.type = "checkbox";
	elCell.appendChild(elCell.element);
	if (elRow.item[oHead.field] != null && typeof elRow.item[oHead.field] == "boolean") {
		elCell.element.checked = elRow.item[oHead.field];
	}
	// Map event
	this.mapEvent(elCell.element, oHead.name);
};

GridViewBTD.prototype.createRadioBox = function(elCell, oHead) {
	var elRow = elCell.parentNode;
	elCell.listElement = [];
	for (var i = 0; i < oHead.listItem.length; i++) {
		var elRadio = utilObj.createEl("INPUT");
		elRadio.id = this.myName + oHead.name + elRow.rowIndex + i;
		elRadio.name = this.myName + oHead.name + elRow.rowIndex;
		elRadio.type = "radio";
		elRadio.checked = elRow.item[oHead.field] == oHead.listItem[i].value;
		elRadio.value = oHead.listItem[i].value;
		elCell.appendChild(elRadio);
		elCell.listElement.push(elRadio);

		var elLabel = utilObj.createEl("LABEL");
		elLabel.htmlFor = elRadio.id;
		elLabel.innerHTML = oHead.listItem[i].text;
		elCell.appendChild(elLabel);
		// Map event
		this.mapEvent(elRadio, oHead.name);
	}
};

GridViewBTD.prototype.createOption = function(item) {
	var elOption = utilObj.createEl("OPTION");
	elOption.text = item.text;
	elOption.value = item.value;
	return elOption;
};

GridViewBTD.prototype.createSelectBox = function(elCell, oHead) {
	var elRow = elCell.parentNode;
	elCell.element = utilObj.createEl("SELECT");
	elCell.element.style.width = "100%";
	elCell.element.className = "inputText";
	for (var i = 0; i < oHead.listItem.length; i++) {
		var elOption = this.createOption(oHead.listItem[i]);
		try {
			elCell.element.add(elOption, null); // standards compliant
		}
		catch (ex) {
			elCell.element.add(elOption); // IE only
		}
		elOption.selected = elRow.item[oHead.field] == oHead.listItem[i].value;
	}
	elCell.appendChild(elCell.element);
	// Map event
	this.mapEvent(elCell.element, oHead.name);
};

GridViewBTD.prototype.createMultiSelectBox = function(elCell, oHead) {
	var elRow = elCell.parentNode;
	var dicData = utilObj.convertArrayToDictionary(elRow.item[oHead.field]);
	elCell.element = new MultiSelectBoxBTD(elCell, oHead.dataMSB, this.myName + "_oMSB" + elRow.rowIndex);
	elCell.element.setWidth("100%");
	elCell.element.selectedValues(dicData);
	// Map event
	this.mapEventMultiSelectBox(elCell.element, oHead.name);
};

GridViewBTD.prototype.createLabel = function(elCell, oHead) {
	var elRow = elCell.parentNode;
	elCell.element = utilObj.createEl("LABEL");
	elCell.element.innerHTML = (elRow.item[oHead.field] == null) ? "" : elRow.item[oHead.field];
	elCell.appendChild(elCell.element);
	// Map event
	this.mapEvent(elCell.element, oHead.name);
};

GridViewBTD.prototype.createLabelDate = function(elCell, oHead) {
	var elRow = elCell.parentNode;
	var value = "";
	if (elRow.item[oHead.field] != "" && elRow.item[oHead.field] != null) {
		if (!(elRow.item[oHead.field] instanceof Date)) {
			elRow.item[oHead.field] = Date.parseDate(elRow.item[oHead.field], Date.stringFormat.dateTime);
		}
		value = elRow.item[oHead.field].toVNString();
	}
	elCell.element = utilObj.createEl("LABEL");
	elCell.element.innerHTML = value;
	elCell.appendChild(elCell.element);
	// Map event
	this.mapEvent(elCell.element, oHead.name);
};

GridViewBTD.prototype.createImage = function(elCell, oHead) {
	var elRow = elCell.parentNode;
	elCell.element = utilObj.createEl("IMG");
	elCell.element.src = oHead.path + elRow.item[oHead.field];
	elCell.appendChild(elCell.element);
	// Map event
	this.mapEvent(elCell.element, oHead.name);
};

GridViewBTD.prototype.createTextArea = function(elCell, oHead) {
	var elRow = elCell.parentNode;
	elCell.element = utilObj.createEl("TEXTAREA");
	elCell.element.style.width = "100%";
	elCell.element.rows = 4;
	elCell.element.className = "inputText";
	elCell.element.value = (elRow.item[oHead.field] == null) ? "" : elRow.item[oHead.field];
	elCell.appendChild(elCell.element);
	// Map event
	this.mapEvent(elCell.element, oHead.name);
};

GridViewBTD.prototype.createDate = function(elCell, oHead) {
	var elRow = elCell.parentNode;
	elCell.element = new CalendarBTD(elCell, "elCalendar" + this.myName + elRow.rowIndex, "", false);
	elCell.element.setWidth("100%");
	var value = elRow.item[oHead.field];
	if (value != null) {
		if (!(value instanceof Date)) {
			value = Date.parseDate(value, Date.stringFormat.dateTime);
		}
		elCell.element.setDate(value);
	}
	// Map event
	this.mapEventCalendar(elCell.element, oHead.name);
};

GridViewBTD.prototype.createRichText = function(elCell, oHead) {
	var elRow = elCell.parentNode;
	elCell.element = new ObjectIframe(elCell, "elementRTE" + this.myName + elRow.rowIndex,
		(elRow.item[oHead.field] == null) ? "" : elRow.item[oHead.field], "100%", 60, "inputText");
	// Map event
	this.mapEventRichText(elCell.element, oHead.name);
};


/*****************************************************************************
Private Methods End
*****************************************************************************/

/*****************************************************************************
Public Methods Start
*****************************************************************************/

GridViewBTD.prototype.dataBind = function() {
	this.createGridView();
	this.createTHead();
	this.createTBody();
	this.createTFoot();

	if (this.isAllowResizeColumn) {
		this.resizeColumn();
	}
	if (this.isAllowResizeColumn || this.isAllowHideColumn) {
		this.changeWidthColumn();
	}
	if (this.isAllowMoveColumn) {
		this.moveColumn();
	}
};

GridViewBTD.prototype.reloadData = function() {
	this.elGridView.removeChild(this.elGridView.tBodies[this.elGridView.tBodies.length - 1]);
	this.createTBody();
};

GridViewBTD.prototype.insertNewRow = function(item) {
	this.listData.data.push(item);
	this.insertRow(item);
};

GridViewBTD.prototype.updateRow = function(item) {
	item.rowID = this.elRowEdit.item.rowID;
	//item.recordID = this.elRowEdit.item.recordID;
	this.elRowEdit.item = item;
	item.elRow = this.elRowEdit;
	for (var i = 0; i < this.listMapHeader.length; i++) {
		this.updateCell(this.listMapHeader[i].item, i);
	}
	var e = new Object();
	e.boundStatus = BoundStatus.update;
	this.executeEventForRow(e, this.elRowEdit, EventName.rowDataBound);
};

GridViewBTD.prototype.removeRow = function(elRow) {
	// Delete data array
	for (var i = 0; i < this.listData.data.length; i++) {
		if (elRow.item.rowID == this.listData.data[i].rowID) {
			this.listData.data.splice(i, 1);
			break;
		}
	}

	var tBody = this.elGridView.tBodies[this.elGridView.tBodies.length - 1];
	// Change css row
	var start = elRow.rowIndex;
	start = utilObj.isOpera ? start - this.elGridView.tFoot.rows.length : start;
	for (var i = start; i < tBody.rows.length; i++) {
		tBody.rows[i].className = i % 2 != 0 ? "bgColor" : "alternatingBgColor";
		var e = new Object();
		e.boundStatus = BoundStatus.remove;
		this.executeEventForRow(e, tBody.rows[i], EventName.rowDataBound);
	}

	// Delete row
	tBody.removeChild(elRow);
};

/*****************************************************************************
Public Methods End
*****************************************************************************/

/*****************************************************************************
Event Start
*****************************************************************************/

GridViewBTD.prototype.mapEventForRow = function(elRow) {
	var self = this;
	// Add Event
	elRow["onclick"] = function(e) {
		self.executeEventForRow(e, elRow, EventName.rowClick);
	};

	elRow["ondblclick"] = function(e) {
		self.executeEventForRow(e, elRow, EventName.rowDblClick);
	};

	elRow["onmousedown"] = function(e) {
		self.executeEventForRow(e, elRow, EventName.rowMouseDown);
	};

	elRow["onmousemove"] = function(e) {
		self.executeEventForRow(e, elRow, EventName.rowMouseMove);
	};
	elRow["onmouseout"] = function(e) {
		self.executeEventForRow(e, elRow, EventName.rowMouseOut);
	};

	elRow["onmouseover"] = function(e) {
		self.executeEventForRow(e, elRow, EventName.rowMouseOver);
	};

	elRow["onmouseup"] = function(e) {
		self.executeEventForRow(e, elRow, EventName.rowMouseUp);
	};
};

GridViewBTD.prototype.mapEvent = function(element, name) {
	var self = this;
	// Add Event
	element["onclick"] = function(e) {
		self.executeEvent(e, element, name + EventName.click);
	};

	element["onblur"] = function(e) {
		self.executeEvent(e, element, name + EventName.blur);
	};

	element["onfocus"] = function(e) {
		self.executeEvent(e, element, name + EventName.focus);
	};

	element["onchange"] = function(e) {
		self.executeEvent(e, element, name + EventName.change);
	};

	element["ondblclick"] = function(e) {
		self.executeEvent(e, element, name + EventName.dblClick);
	};

	element["onkeydown"] = function(e) {
		self.executeEvent(e, element, name + EventName.keyDown);
	};

	element["onkeypress"] = function(e) {
		self.executeEvent(e, element, name + EventName.keyPress);
	};

	element["onkeyup"] = function(e) {
		self.executeEvent(e, element, name + EventName.keyUp);
	};

	element["onmousedown"] = function(e) {
		self.executeEvent(e, element, name + EventName.mouseDown);
	};

	element["onmousemove"] = function(e) {
		self.executeEvent(e, element, name + EventName.mouseMove);
	};
	element["onmouseout"] = function(e) {
		self.executeEvent(e, element, name + EventName.mouseOut);
	};

	element["onmouseover"] = function(e) {
		self.executeEvent(e, element, name + EventName.mouseOver);
	};

	element["onmouseup"] = function(e) {
		self.executeEvent(e, element, name + EventName.mouseUp);
	};
};

GridViewBTD.prototype.mapEventRichText = function(element, name) {
	var self = this;
	var elChild = element.elIframe;
	element.addEvent(EventNameRTE.change, function(e) {
		self.executeEvent(e, elChild, name + EventName.change);
	});
};

GridViewBTD.prototype.mapEventMultiSelectBox = function(element, name) {
	var self = this;
	var elChild = element.oContainer;
	element.addEvent(EventNameMSB.change, function(e) {
		self.executeEvent(e, elChild, name + EventName.change);
	});
	element.addEvent(EventNameMSB.click, function(e) {
		self.executeEvent(e, elChild, name + EventName.click);
	});
};

GridViewBTD.prototype.mapEventCalendar = function(element, name) {
	var self = this;
	var elChild = element.oContainer;
	element.addEvent(EventNameCalendar.change, function(e) {
		self.executeEvent(e, elChild, name + EventName.change);
	});
	element.addEvent(EventNameCalendar.click, function(e) {
		self.executeEvent(e, elChild, name + EventName.click);
	});
};

GridViewBTD.prototype.executeEvent = function(e, element, eventName) {
	e = utilObj.getWindowEvent();
	e.elementCell = element.parentNode;
	this.executeEventForRow(e, e.elementCell.parentNode, eventName);
};

GridViewBTD.prototype.executeEventForRow = function(e, elRow, eventName) {
	if (e == null) {
		e = utilObj.getWindowEvent();
	}
	e.elementRow = elRow;
	var elFunctionUpdate = utilObj.getTargetElement();
	var isFunctionUpdate = true;
	if (elFunctionUpdate != null && elFunctionUpdate.isFunctionUpdate == null) {
		if (elFunctionUpdate.parentNode != null) {
			isFunctionUpdate = elFunctionUpdate.parentNode.isFunctionUpdate != null;
		}
		else {
			isFunctionUpdate = false;
		}
	}

	if (this.listEvent[eventName] != null) {
		for (var i = 0; i < this.listEvent[eventName].length; i++) {
			if (!isFunctionUpdate ||
				(isFunctionUpdate && (EventName.editRecord == eventName ||
					EventName.deleteRecord == eventName ||
					EventName.rowDataBound == eventName))) {
				this.listEvent[eventName][i](e);
			}
		}
	}
};

GridViewBTD.prototype.executeEventNormal = function(e, eventName) {
	if (this.listEvent[eventName] != null) {
		for (var i = 0; i < this.listEvent[eventName].length; i++) {
			this.listEvent[eventName][i](e);
		}
	}
};

GridViewBTD.prototype.addEventForFunction = function(eventName, func) {
	this.addEvent("", eventName, func);
};

GridViewBTD.prototype.removeEventForFunction = function(eventName, func) {
	this.removeEvent("", eventName, func);
};

GridViewBTD.prototype.addEvent = function(colName, eventName, func) {
	if (this.listEvent[colName + eventName] == null) {
		this.listEvent[colName + eventName] = [];
	}
	this.listEvent[colName + eventName].push(func);
};

GridViewBTD.prototype.removeEvent = function(colName, eventName, func) {
	if (this.listEvent[colName + eventName] == null) {
		return;
	}
	for (var i = 0; i < this.listEvent[colName + eventName].length; i++) {
		if (func == this.listEvent[colName + eventName][i]) {
			this.listEvent[colName + eventName].splice(i, 1);
			break;
		}
	}
};

/*****************************************************************************
Event End
*****************************************************************************/

/*****************************************************************************
Calc total of Columm function
*****************************************************************************/

GridViewBTD.prototype.calcTotal = function(colName, charSep, totalName, fractionDigits) {
	if (!this.isShowTotal) return;
	try {
		var row = this.elGridView.tFoot.rows[1];
		var cell = null;

		if (this.isShowPaging && row == null) {
			row = this.elGridView.tFoot.insertRow(1);
			cell = row.insertCell(0);
			cell.className = "gridViewFoot";
			cell.colSpan = this.elGridView.tHead.rows[0].cells.length;
		}
		else {
			cell = this.elGridView.tFoot.rows[0].cells[0];
		}
		var total = 0;
		for (var i = 0; i < this.listData.data.length; i++) {
			total += this.listData.data[i][colName];
		}
		totalName = totalName == null ? "Tổng" : totalName;
		total = total.toFixed(fractionDigits);
		total = utilObj.formatNumber(total, charSep);
		cell.innerHTML = totalName + ": <span class='calcTotal'>" + total + "</span>";
		return total;
	}
	catch (e) { }
};

/*****************************************************************************
Calc total of Columm function
*****************************************************************************/

/*****************************************************************************
Paging function
*****************************************************************************/
GridViewBTD.prototype.showOrHidePreviewOrNext = function() {
	this.elContainerPagingNext.style.display =
		(this.totalPage <= this.currentIndexContainerPage * this.maxPage) ? "none" : "";
	this.elContainerPagingPreview.style.display = (this.currentIndexContainerPage == 1) ? "none" : "";
}

GridViewBTD.prototype.gotoPage = function(elPageChoose, isStopEventPaging) {
	if (this.elPageChoose == elPageChoose) return;
	var e = new Object();
	e.end = elPageChoose["indexPage"] * this.viewRecord;
	e.begin = e.end - this.viewRecord + 1;
	this.pagingRecord = { begin: e.begin, end: e.end };
	if (this.elPageChoose != null) {
		this.elPageChoose.className = "pageNoChoose";
	}
	this.elPageChoose = elPageChoose;
	this.elPageChoose.className = "pageChoose";
	isStopEventPaging = typeof isStopEventPaging == "undefined" ? false : isStopEventPaging;
	if (!isStopEventPaging) {
		this.executeEventNormal(e, EventName.pagingChange);
	}
};

GridViewBTD.prototype.gotoPreviewOrNext = function(isNext) {
	this.listContainerPages["page" + this.currentIndexContainerPage].className = "containerNoShowPage";
	if (isNext) this.currentIndexContainerPage++;
	else this.currentIndexContainerPage--;
	this.showOrHidePreviewOrNext();

	var elNow = this.listContainerPages["page" + this.currentIndexContainerPage];
	if (elNow != null) {
		elNow.className = "containerShowPage";
		var elPage = elNow.firstChild;
		if (elPage.tagName.toLowerCase() != "span") {
			elPage = elPage.nextSibling;
		}
		this.gotoPage(elPage);
	}
};

GridViewBTD.prototype.gotoPreview = function() {
	this.gotoPreviewOrNext(false);
};

GridViewBTD.prototype.gotoNext = function() {
	this.gotoPreviewOrNext(true);
};

GridViewBTD.prototype.setPaging = function(viewRecord, totalRecord, maxPage) {
	if (!this.isShowPaging) return;
	this.viewRecord = viewRecord;
	this.totalRecord = totalRecord;
	this.totalPage = parseInt(totalRecord / this.viewRecord, 10);
	this.totalPage += (totalRecord % this.viewRecord == 0) ? 0 : 1;
	this.pagingRecord = { begin: 1, end: this.viewRecord };
	this.maxPage = (typeof (maxPage) == "undefined") ? this.maxPage : maxPage;
	this.listContainerPages = new Array();
	this.elPageChoose = null;
	this.currentIndexContainerPage = 1;

	this.elContainerPagingPreview = null;
	this.elContainerPagingNext = null;
	this.elGridView.tFoot.rows[0].cells[0].innerHTML = "";
	this.elGridView.tFoot.rows[0].cells[0].appendChild(this.getPaging());
	this.showOrHidePreviewOrNext();
};

GridViewBTD.prototype.createElPage = function(elContainerPaging, indexPage, indexContainerPaging) {
	var self = this;
	var elPage = utilObj.createEl("SPAN");
	elPage["indexPage"] = indexPage;
	elPage.innerHTML = indexPage;
	elContainerPaging.appendChild(elPage);

	if (indexPage == 1) {
		elPage.className = "pageChoose";
		this.elPageChoose = elPage;
		this.currentIndexContainerPage = indexContainerPaging;
		elContainerPaging.className = "containerShowPage";
	}
	else {
		elPage.className = "pageNoChoose";
	}
	utilObj.addEvent(elPage, EventName.click, function(e) {
		self.gotoPage(elPage);
	});
};

GridViewBTD.prototype.changePageByIndex = function(indexPage, isStopEventPaging) {
	if ((indexPage > this.totalPage) || (indexPage <= 0)) {
		return;
	}
	this.listContainerPages["page" + this.currentIndexContainerPage].className = "containerNoShowPage";
	var currentIndex = parseInt(indexPage / this.maxPage, 10);
	currentIndex += (indexPage % this.maxPage == 0) ? 0 : 1;

	this.currentIndexContainerPage = currentIndex;
	this.showOrHidePreviewOrNext();

	var elNow = this.listContainerPages["page" + this.currentIndexContainerPage];
	if (elNow != null) {
		elNow.className = "containerShowPage";
		var elPage = null;
		for (var i = 0; i < elNow.childNodes.length; i++) {
			elPage = elNow.childNodes[i];
			if (elPage.tagName.toLowerCase() == "span" && elPage["indexPage"] == indexPage) {
				break;
			}
		}
		if (elPage != null) this.gotoPage(elPage, isStopEventPaging);
	}
};

GridViewBTD.prototype.textBoxGotoPage_change = function(elTextBox) {
	elTextBox.value = elTextBox.value.trim();
	var indexPage = parseInt(elTextBox.value, 10);
	if (elTextBox.value == "" || isNaN(elTextBox.value)) {
		return;
	}

	this.changePageByIndex(indexPage, false);
};

GridViewBTD.prototype.createTextBoxGotoPage = function(elContainer) {
	var self = this;
	// Create text paping
	var elSpan = utilObj.createEl("SPAN");
	elSpan.className = "pagingText";
	elSpan.innerHTML = "Tới trang: ";
	elContainer.appendChild(elSpan);
	var elTextBox = utilObj.createEl("INPUT");
	elTextBox.type = "text";
	elTextBox.className = "inputText w30px";
	utilObj.addEvent(elTextBox, EventName.change, function(e) {
		self.textBoxGotoPage_change(elTextBox);
	});
	utilObj.addEvent(elTextBox, EventName.focus, function(e) {
		elTextBox.select();
	});
	elContainer.appendChild(elTextBox);
};

GridViewBTD.prototype.getPaging = function() {
	var totalPage = this.totalPage;
	var self = this;

	var elContainerTable = utilObj.createEl("TABLE");
	elContainerTable.className = "containerTablePaging";
	elContainerTable.style.width = "100%";
	elContainerTable.cellPadding = elContainerTable.cellSpacing = elContainerTable.border = "0";
	var elRow = elContainerTable.insertRow(0);
	var elCell = elRow.insertCell(0);
	elCell.style.width = "20%";
	elCell.style.textAlign = "left";
	elCell.innerHTML = "Tổng: " + utilObj.formatNumber(this.totalRecord, ".");
	elCell = elRow.insertCell(1);
	elCell.style.width = "80%";
	elCell.style.textAlign = "right";

	// Create Element container
	var elContainer = utilObj.createEl("SPAN");
	elCell.appendChild(elContainer);
	this.createTextBoxGotoPage(elContainer);

	var timeNext = parseInt(totalPage / this.maxPage, 10);
	timeNext += (totalPage % this.maxPage == 0) ? 0 : 1;

	var elContainerPagingPreview = utilObj.createEl("SPAN");
	elContainerPagingPreview.className = "pageNoChoose";
	elContainerPagingPreview.innerHTML = "|&lt;";
	utilObj.addEvent(elContainerPagingPreview, EventName.click, function(e) {
		self.gotoPreview();
	});
	elContainer.appendChild(elContainerPagingPreview);
	this.elContainerPagingPreview = elContainerPagingPreview;

	for (var j = 1; j <= timeNext; j++) {
		var elContainerPaging = utilObj.createEl("SPAN");
		elContainerPaging.className = "containerNoShowPage";
		elContainer.appendChild(elContainerPaging);
		this.listContainerPages["page" + j] = elContainerPaging;
		var max = j * this.maxPage;
		var min = max - this.maxPage + 1;
		max = totalPage <= max ? totalPage : max;
		for (var i = min; i <= max; i++) {
			this.createElPage(elContainerPaging, i, j);
		}
	}

	var elContainerPagingNext = utilObj.createEl("SPAN");
	elContainerPagingNext.className = "pageNoChoose";
	elContainerPagingNext.innerHTML = "&gt;|";
	utilObj.addEvent(elContainerPagingNext, EventName.click, function(e) {
		self.gotoNext();
	});
	elContainer.appendChild(elContainerPagingNext);
	this.elContainerPagingNext = elContainerPagingNext;
	return elContainerTable;
};

GridViewBTD.prototype.getBeginAndEndRecord = function() {
	return this.pagingRecord;
};

GridViewBTD.prototype.getCurrentIndexPage = function() {
	return this.elPageChoose == null ? 1 : this.elPageChoose["indexPage"];
};
/*****************************************************************************
Paging function
*****************************************************************************/