var KEY_CODE_ENTER = 13;
var KEY_CODE_TAB = 9;
var KEY_CODE_UP = 38;
var KEY_CODE_DOWN = 40;
var KEY_CODE_LEFT = 37;
var KEY_CODE_RIGHT = 39;
var KEY_CODE_BS = 8;
var KEY_CODE_DEL = 46;
var KEY_CODE_ESC = 27;
var KEY_CODE_SPACE = 32;

var _TYPE_OF_FUNCTION = "function";

var __clientRect = {width: 0, height: 0};

function $(tagId)
{
	var tagObj = document.getElementById(tagId);
	
	if (tagObj)
	{
		tagObj.setText = function (str)
		{
			if (tagObj.textContent)
			{
				// for Firefox
				if ((tagObj.hasChildNodes()) && (tagObj.firstChild.textContent))
				{
					tagObj.firstChild.textContent = str;
				}
				else
				{
					tagObj.textContent = str;
				}
			}
			else
			{
				tagObj.innerText = str;
			}
		}
		
		tagObj.setHTML = function (str)
		{
			tagObj.innerHTML = str;
		}
		
		tagObj.getNodeValue = function ()
		{
			if ((tagObj.firstChild) && (tagObj.firstChild.nodeValue))
			{
				return tagObj.firstChild.nodeValue;
			}
			return null;
		}
		
		tagObj.setNodeValue = function (str)
		{
			if ((tagObj.firstChild) && (tagObj.firstChild.nodeValue))
			{
				tagObj.firstChild.nodeValue = str;
			}
		}
		
		tagObj.hide = function ()
		{
			tagObj.style.visibility = "hidden";
		}
		
		tagObj.remove = function ()
		{
			tagObj.style.display = "none";
		}
		
		tagObj.show = function ()
		{
			tagObj.style.visibility = "visible";
			tagObj.style.display = "block";
		}
		
		tagObj.showLine = function ()
		{
			tagObj.style.visibility = "visible";
			tagObj.style.display = "inline";
		}
		
		tagObj.isShowed = function ()
		{
			if ((tagObj.style.visibility != "hidden") && (tagObj.style.display != "none"))
			{
				return true;
			}
			return false;
		}
		
		return tagObj;
	}
	return null;
}

function trim(str)
{
	return str.replace(/^[ ]*/gim, "").replace(/[ ]*$/gim, "");
}

function getSelectedIndex(obj)
{
	for (var n = 0; n < obj.options.length; n++)
	{
		if (obj.options[n].selected) return n;
	}
	return null;
}

function getKeyCode(event)
{
	return ((window.event) ? window.event.keyCode : event.which);
}

function getMouseBtnCode(event)
{
	return ((window.event) ? window.event.button : event.button);
}

function getMousePosition(event)
{
	var pos = {x: 0, y: 0};
	if (window.event)
	{
		pos.x = window.event.clientX;
		pos.y = window.event.clientY;
	}
	else
	{
		pos.x = event.pageX;
		pos.y = event.pageY;
	}
	return pos;
}

function getClientSize()
{
	__clientRect.height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	__clientRect.width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
	return __clientRect;
}

function setTransparency(obj, val)
{
	if (obj)
	{
		obj.style.filter = "alpha(opacity=" + val + ")";
		obj.style.opacity = (val / 100);
	}
}

function getObjectRect(obj)
{
	var objRect = {x: 0, y: 0, width: 0, height: 0};
	var scX = document.body.scrollLeft || document.documentElement.scrollLeft;
	var scY = document.body.scrollTop  || document.documentElement.scrollTop;
	if (obj.getBoundingClientRect)
	{
		var rect = obj.getBoundingClientRect();
		objRect.x = rect.left + scX - 2;
		objRect.y = rect.top + scY - 2;
		objRect.width = rect.right - rect.left;
		objRect.height = rect.bottom - rect.top;
	}
	else if (document.getBoxObjectFor)
	{
		var pos = document.getBoxObjectFor(obj);
		objRect.x = pos.x;
		objRect.y = pos.y;
		objRect.width = pos.width;
		objRect.height = pos.height;
	}
	else
	{
		return null;
	}
	return objRect;
}

function setCancelBubble(event)
{
	if (window.event)
	{
		window.event.cancelBubble = true;
	}
	else
	{
		event.cancelBubble = true;
	}
}

function isIE()
{
	return (navigator.appVersion.indexOf("MSIE") != -1);
}

function isIE_version(version)
{
	return (navigator.appVersion.indexOf("MSIE " + version) != -1);
}

function reportError(errObj)
{
	return;
}

function dummy()
{
	return;
}
