/**
 * Common DIV functions
 * Work in IE(4\5\6), NN4, NN6, Mozilla, Opera
 * Kirill Kudryavtsev kck@mail.ru
 **/
var isOPERA = (navigator.userAgent.indexOf('Opera') >= 0) ? true : false;
var isIE    = (document.all) ? true : false;
var isW3C   = (document.getElementById && !isIE) ? true : false;
var isNN4   = (document.layers) ? true : false;
var isNN6   = (navigator.userAgent.indexOf('Netscape6') >= 0) ? true : false;

// isDHTML capable browser for degradability
var isDHTML = (isIE || isW3C || isNN4) ? true : false;

// Get element by name
function getObjByName(objName)
{
	if (!isDHTML) return null;
	return (isIE || isW3C) ?
		((isIE) ? document.all[objName] : document.getElementById(objName) ) :
		document.layers[objName];
}

// Hide named object
function hideObj(objName)
{
	if (!isDHTML) return null;
	obj = getObjByName(objName);
	if(!obj) return;
	if (isIE || isW3C)
	{
		obj.style.visibility = 'hidden';
	}
	else
	{
		obj.visibility = 'hide';
	}
}

// Show named object
function showObj(objName)
{
	if (!isDHTML) return null;
	obj = getObjByName(objName);
	if(!obj) return;
	if (isIE || isW3C)
	{
		obj.style.visibility = 'visible';
	}
	else
	{
		obj.visibility = 'show';
	}
}

function moveObjTo(objName, x, y)
{
	if (isDHTML)
	{
		if (isIE || isW3C || isOPERA)
		{
			obj = getObjByName(objName);
			obj.style.left = x + "px";
			obj.style.top  = y + "px";
		}
		else
		{
			document.layers[objName].left = x;
			document.layers[objName].top = y;
		}
	}
}


function findObjTop(objName)
{
	var tmp    = 0;
	var parent = getObjByName(objName);
	while (parent)
	{
		tmp   += parent.offsetTop;
		parent = parent.offsetParent;
	}
	return tmp;
}

// Get named object's computed left
function findObjLeft(objName)
{
	var tmp    = 0;
	var parent = getObjByName(objName);
	while (parent)
	{
		tmp   += parent.offsetLeft;
		parent = parent.offsetParent;
	}
	return tmp;
}
// Get named object's computed width
function findObjWidth(objName) {
	if (isDHTML) {
		if (isIE) {
			return eval(objName + '.offsetWidth');
		}
		if (isW3C) {
			obj = document.getElementById(objName);
			return parseInt(document.defaultView.getComputedStyle(obj, '').getPropertyValue('width'));
		}
		if (isOPERA) {
			obj = document.getElementById(objName);
			return obj.style.pixelWidth;
		}
		// else isNN4
		return document.layers[objName].clip.width;
	}
	return null;
}

// Get named object's computed height
function findObjHeight(objName) {
	if (isDHTML) {
		if (isIE) {
			return eval(objName + '.offsetHeight');
		}
		if (isW3C) {
			obj = document.getElementById(objName);
			return parseInt(document.defaultView.getComputedStyle(obj, '').getPropertyValue('height'));
		}
		if (isOPERA) {
			obj = document.getElementById(objName);
			return obj.style.pixelHeight;
		}
		// else is NN4
		return document.layers[objName].clip.height;
	}
	return null;
}

// Get browser width
function findClientWidth() {
	if (isDHTML) {
		if (isIE) {
			return document.body.clientWidth;
		} // else is NN4 && W3C
		else {
			return innerWidth;
		}
	}
	else {
		return null;
	}
}

// Get browser height
function findClientHeight() {
	if (isDHTML) {
		if (isIE) {
			return document.body.clientHeight;
		}
		else { // else isNN4 && W3C
			return innerHeight;
		}
	}
	else {
		return null;
	}
}
function setBgColor(objName, bgcolor) {
	if (isDHTML) {
		obj = getObjByName(objName);
		if (obj != null) {
			if (isIE || isW3C) {
				obj.style.backgroundColor = bgcolor;
			}
			else if ( isOPERA ) {
				obj.style.background = bgcolor;
			}
			else {
				obj.document.bgColor = bgcolor;
			}
		}
	}
}
