
function CVisualObject(sName, nLeft, nTop, nWidth, nHeight)
{
	CVisualObject_Constructor(this, sName, nLeft, nTop, nWidth, nHeight);
}

function CVisualObject_Constructor(_this, sName, nLeft, nTop, nWidth, nHeight)
{
	CObject_Constructor(_this);
	_this.SetClassName("CVisualObject");

	_this.m_sObjName = sName;
	_this.m_nId = GetNewId();
	_this.m_nZIndex = -1;
	_this.GetElement = CVisualObject_GetElement;
	_this.GetStyle = CVisualObject_GetStyle;

	_this.m_bEnabled = true;
	_this.m_bVisible = true;
	_this.m_bFocused = false;

	_this.m_owner = null;
	_this.m_parent = null;

	_this.m_arItems = null;

	_this.m_sBgColor = null;
	_this.m_nBorder = 1;

	_this.m_nLeft = SafeNumber(nLeft);
	_this.m_nTop = SafeNumber(nTop);
	_this.m_nWidth = SafeNumber(nWidth);
	_this.m_nHeight = SafeNumber(nHeight);

	_this.GetObjectName = CVisualObject_GetObjectName;
	_this.GetId = CVisualObject_GetId;

	_this.GetZIndex = CVisualObject_GetZIndex;
	_this.SetZIndex = CVisualObject_SetZIndex;

	_this.virtual("SetBgColor");

	_this.m_sCSS = "";
	_this.m_sDisabledCSS = "";
	_this.GetCSS = CVisualObject_GetCSS;

	_this.m_sExtStyle = "";
	_this.m_sExtTag = "";

	_this.IsEnabled = CVisualObject_IsEnabled;
	_this.IsVisible = CVisualObject_IsVisible;
	_this.IsFocused = CVisualObject_IsFocused;

	_this.virtual("InsertItem");
	_this.GetItem = CVisualObject_GetItem;

	_this.virtual("SetLeft");
	_this.virtual("SetTop");
	_this.virtual("SetHeight");
	_this.virtual("SetWidth");
	_this.virtual("GetAbsLeft");
	_this.virtual("GetAbsTop");
	_this.virtual("MoveTo");
	_this.virtual("AbsMoveTo");

	_this.virtual("SetOwner");
	_this.virtual("SetParent");

	_this.virtual("Draw");
	_this.virtual("OnDraw");

	_this.virtual("Enable");
	_this.virtual("Visible");

	_this.virtual("SetFocus");
	_this.virtual("KillFocus");

	_this.virtual("OnMouseOver");
	_this.virtual("OnMouseOut");
	_this.virtual("IsMouseOver");
	_this.$GetMouseFuncTags = CVisualObject_$GetMouseFuncTags;

	AddVisualObject(_this);
}

function CVisualObject_GetElement()
{
	var obj = null;
	var sObjName = this.GetObjectName();

	if (IsIE())
		obj = document.all(sObjName);
	else
	if (IsNN())
		if (this.m_owner)
			obj = (this.m_owner.GetElement() ? 
				this.m_owner.GetElement().document.layers[sObjName] :
				null);	
		else
			obj = document.layers[sObjName];
	
	return obj;
}

function CVisualObject_GetStyle()
{
	var style = null;
	var thisEl = this.GetElement();

	if (thisEl)	
	{
		if (IsIE())
			style = thisEl.style;
		else
		if (IsNN())
			style = thisEl;
	}	
	return style;
}

function CVisualObject_SetLeft(nLeft)
{
	this.m_nLeft = nLeft;

	var obj = this.GetElement();
	if (obj)
		this.GetStyle().left = this.m_nLeft;
}

function CVisualObject_SetTop(nTop)
{
	this.m_nTop = nTop;

	var obj = this.GetElement();
	if (obj)
		this.GetStyle().top = this.m_nTop;
}

function CVisualObject_GetAbsLeft(nLeft)
{
	return this.m_nLeft + (this.m_owner ? this.m_owner.GetAbsLeft() : 0);
}

function CVisualObject_GetAbsTop(nTop)
{
	return this.m_nTop + (this.m_owner ? this.m_owner.GetAbsTop() : 0);
}

function CVisualObject_SetHeight(nHeight)
{
	this.m_nHeight = nHeight;
}

function CVisualObject_SetWidth(nWidth)
{
	this.m_nWidth = nWidth;
}

function CVisualObject_MoveTo(nLeft, nTop)
{
	this.SetLeft(nLeft);
	this.SetTop(nTop);
}

function CVisualObject_AbsMoveTo(nLeft, nTop)
{
	if (this.m_owner)
	{
		nLeft -= this.m_owner.GetAbsLeft();
		nTop -= this.m_owner.GetAbsTop();
	}

	this.MoveTo(nLeft, nTop);
}

function CVisualObject_GetId()
{
	return this.m_nId;
}

function CVisualObject_SetBgColor(nBgColor)
{
	this.m_sBgColor = nBgColor;
}

function CVisualObject_SetZIndex(nInd)
{
	this.m_nZIndex = nInd;
	var style = this.GetStyle();
	if (style)
		style.zIndex = nInd;
}

function CVisualObject_GetZIndex()
{
	var style = this.GetStyle();
	if (style)
		return style.zIndex = nInd;
	return this.m_nZIndex;
}

function CVisualObject_GetObjectName()
{
	return this.m_sObjName;
}

function CVisualObject_GetCSS(sCSS)
{
	return this.IsEnabled() ? this.m_sCSS : this.m_sDisabledCSS;
}

function CVisualObject_Enable(bState)
{
	this.m_bEnabled = bState;
}

function CVisualObject_IsEnabled()
{
	return this.m_bEnabled;
}

function CVisualObject_Visible(bState)
{
	this.m_bVisible = bState;

	var obj = this.GetElement();

	if (obj && this.GetStyle())
	{
		if (IsIE())
			this.GetStyle().visibility = 
				this.m_bVisible ? "visible" : "hidden";
		else
		if (IsNN())
			this.GetStyle().visibility = 
				this.m_bVisible ? "show" : "hide";
	}
	
	for (i in this.m_arItems)
		this.m_arItems[i].Visible(bState);
}

function CVisualObject_IsVisible()
{
	return this.m_bVisible;
}

function CVisualObject_$GetMouseFuncTags()
{
	return  " onMouseOver=\"GetVisualObject('"+ this.GetObjectName() +"').OnMouseOver();\"" +
		" onMouseOut=\"GetVisualObject('"+ this.GetObjectName() +"').OnMouseOut();\" ";
}

function CVisualObject_InsertItem(item)
{
	if (!this.m_arItems)
		this.m_arItems = new Array();
	this.m_arItems[item.GetObjectName()] = item;

	item.SetParent(this);
	item.SetOwner(this);
}

function CVisualObject_GetItem(sObjName)
{
	return this.m_arItems[sObjName];
}

function CVisualObject_SetOwner(owner)
{
	this.m_owner = owner;	
}

function CVisualObject_SetParent(parent)
{
	this.m_parent = parent;
}

function CVisualObject_SetFocus()
{
	if (GetFocusedItem())
		GetFocusedItem().KillFocus(this);

	this.m_bFocused = true;

	SetFocusedItem(this);
}

function CVisualObject_KillFocus(selectedItem)
{
	this.m_bFocused = false;

	if (selectedItem == this)
		return false;

	if (selectedItem == null && this.m_parent != null)
		this.m_parent.KillFocus(selectedItem);

	SetFocusedItem(null);

	return true;
}

function CVisualObject_IsFocused()
{
	return this.m_bFocused;
}

function CVisualObject_OnMouseOver()
{
}

function CVisualObject_OnMouseOut()
{
}

function CVisualObject_IsMouseOver(nMouseX, nMouseY)
{
	var nAbsLeft = this.GetAbsLeft();
	var nAbsTop = this.GetAbsTop();
	return  this.IsVisible() &&
		nAbsLeft <= nMouseX &&
		nMouseX <= (nAbsLeft + this.m_nWidth) &&
		nAbsTop <= nMouseY &&
		nMouseY <= (nAbsTop + this.m_nHeight);
}

function CVisualObject_OnDraw()
{
}

function CVisualObject_Draw()
{
	var sName = this.GetObjectName();

	if (IsIE())
	{
		var sBkColor = 
			(this.m_sBgColor != null && this.m_sBgColor != "") ? 		
			(" background-color: " + this.m_sBgColor + ";") : "";

		document.writeln(
		"<div name=\""+ sName +"\" id=\"" + sName + "\" " +
		" style=\"" + sBkColor +
		" position: absolute; " +
		" visibility: "+ (this.IsVisible() ? "visible;" : "hidden;") +
		" top: " + this.m_nTop + "px;" +
		" left: " + this.m_nLeft + "px;" +
		" width: " + this.m_nWidth + "px;" +
		" height: " + this.m_nHeight + "px;"+
		(this.GetZIndex() != -1 ? (" z-index:"+this.GetZIndex() + ";"):"") +
		(this.m_nBorder ? " border-width: 1px; border-style: groove;" :"") +
//		" clip: rect("+this.m_nTop+" "+nRight+" "+nBottom+" "+this.m_nLeft+");" +
//		" overflow: scroll; " +
                this.m_sExtStyle +
		"\"" + 
                this.m_sExtTag +
		">\n");

		this.OnDraw();
		document.write("</div>\n\n");
	}
	else
	if (IsNN())
	{
		var sBgColor = 
			(this.m_sBgColor != null && this.m_sBgColor != "") ? 		
			(" bgColor=" + this.m_sBgColor) : "";

		document.write(
		"<layer name=\""+ sName +"\" id=\"" + sName + "\" " +
		sBgColor +
		" left=" + this.m_nLeft +
		" top=" + this.m_nTop +
		" width=" + this.m_nWidth + 
		" height=" + this.m_nHeight + 
		" visibility=" + (this.IsVisible() ? "show" : "hide") +
//		" overflow=clip" +
		(this.GetZIndex() != -1 ? (" z-index="+this.GetZIndex()):"") +
                this.m_sExtTag +
		">\n");

		this.OnDraw();
		document.write("</layer>\n\n");
	}
}

