/* *******************************************
 * This file is created by Quan Duc Binh
 * Email: Hastilydoll219@yahoo.com
 * Mobile: +84 905 089661
 * Date Created: {1}
 * Date Modified: {2}
 * ******************************************/

//Đối tượng Container để chứa các đối tượng khác
function Container()
{
	this.Objects = new BinhBK_Objects();
	this.DOM = new BinhBK_DOM();
}
//Đối tượng BinhBK_Objects dùng để lưu trữ các Object
function BinhBK_Objects()
{
	this.Items = new Array();
	this.nextIndex = 1;
	this.Length = 0;
}
BinhBK_Objects.prototype.Add = function(obj)
{
	this.Items[this.Items.length] = ["object #"+this.nextIndex,obj];
	this.nextIndex++;
	this.Length = this.Items.length;
	return "object #"+(this.nextIndex-1)
}
BinhBK_Objects.prototype.Remove = function(obj)
{
	var tempArr = new Array();
	for (var i=0;i<this.Items.length;i++)
	{
		if (this.Items[i] != obj)
			tempArr[tempArr.length] = this.Items[i];
	}
	this.Items = tempArr;
	this.Length = this.Items.length;
}
BinhBK_Objects.prototype.GetObject = function(objName)
{
	for (var i=0;i<this.Items.length;i++)
	{
		if (this.Items[i][0] == objName)
		{
			return this.Items[i][1];
		}
	}
	return null;
}
//---- End BinhBK_Objects ----//

//---- Đối tượng phục vụ cho DOM ----//
function BinhBK_DOM()
{
	
}
//Phương thức dùng để lấy x,y của đối tượng
BinhBK_DOM.prototype.getPosition = function(el)
{
	xPos = el.offsetLeft;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    
    yPos = el.offsetTop;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return {Left:xPos,Top:yPos};
}

//Phương thức để tạo nhanh một đối tượng HTML
BinhBK_DOM.prototype.createElement = function(doc,tagName,name,id,type,value)
{
	var input = doc.createElement(tagName);
	input.setAttribute("type",type);
	input.setAttribute("name",name);
	input.setAttribute("id",id);
	input.setAttribute("value",value);
	return input;
}
//Phương thức dùng để cài đặt class cho element
BinhBK_DOM.prototype.SetClass = function(elem,className)
{
	if (navigator.appName == "Microsoft Internet Explorer")
		elem.setAttribute("className",className);
	else
		elem.setAttribute("class",className);
}
//Phương thức dùng để thêm class cho Element
BinhBK_DOM.prototype.AddClass = function(elem,className)
{
	var oldClass = "";
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		oldClass = elem.getAttribute("className");
		elem.setAttribute("className",oldClass+" "+className);
	}
	else
	{
		oldClass = elem.getAttribute("class");
		elem.setAttribute("class",oldClass+" "+className);
	}
}
//Phương thức dùng để lấy ClassName của element
BinhBK_DOM.prototype.GetClass = function(elem,className)
{
	if (navigator.appName == "Microsoft Internet Explorer")
		return elem.getAttribute("className");
	else
		return elem.getAttribute("class");
}
//Phương thức dùng để thêm listener cho đối tượng
BinhBK_DOM.prototype.AddEventListener = function(elem,eventStr,callBackMethod)
{
	if (elem.addEventListener) {
		elem.addEventListener(eventStr, callBackMethod, true);
	} else {
		elem.attachEvent("on"+eventStr, callBackMethod);
	}
}
BinhBK_DOM.prototype.RemoveEventListener = function(elem,eventStr,callBackMethod)
{
	if (elem.removeEventListener) {
		elem.removeEventListener(eventStr, callBackMethod, true);
	} else {
		elem.detachEvent("on"+eventStr, callBackMethod);
	}
}
BinhBK_DOM.prototype.IsIE = function()
{
	if (navigator.appName == "Microsoft Internet Explorer")
		return true;
	else
		return false;
}
//---- Kết thúc đối tượng phục vụ cho DOM ----//
Container = new Container();

