/*
 *	Author: 	Dieter Tabor
 *	Date:		03/04/2008
 *	Revision: 	1.0.0.1
*/

function CDHTMLAPI()
{
	this.m_bIsNN4 = false;
	this.m_bIsIE4 = false;
	this.m_bIsIE6 = false;
	this.m_bIsW3C = false;
	this.m_bIsCSS = false;
	this.m_oObj;
	this.m_oElem;
	this.m_oStyle;
	this.m_cssDecl;
	this.m_nX = 0;
	this.m_nY = 0;	
	this.m_nWidth = 0;
	this.m_nHeight = 0;
	this.m_nClientWndWidth = 0;
	this.m_nClientWndHeight = 0;
	
	this.InitDHTMLAPI();
	this.GetClientWindowWidth();
	this.GetClientWindowHeight();
}

CDHTMLAPI.prototype.InitDHTMLAPI = function()
{
	if(document.images) {
		this.m_bIsCSS = (document.body && document.body.style) ? true : false;
		this.m_bIsW3C = (this.m_bIsCSS && document.getElementById) ? true : false;
		this.m_bIsIE4 = (this.m_bIsCSS && document.all) ? true : false;
		this.m_bIsNN4 = (document.layers) ? true : false;
		this.m_nIsIE6 = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
	}
}

CDHTMLAPI.prototype.SeekLayer = function(thisDoc, thisObj)
{
	for(var i = 0; i < thisDoc.layers.length; ++i) {
		if(thisDoc.layers[i].name == thisObj) {
			this.m_oObj = thisDoc.layers[i];
			break;
		}
		if(thisDoc.layers[i].document.layers.length > 0) {
			this.m_oObj = this.SeekLayer(thisDoc.layers[i].document, thisObj);
		}
	}
}

CDHTMLAPI.prototype.GetRawObject = function(thisObj)
{
	if(typeof(thisObj) == "string") {
		if(this.m_bIsW3C) {			
			this.m_oObj = document.getElementById(thisObj);
		}
		else if(this.m_bIsIE4) {			
			this.m_oObj = document.all(thisObj);
		}
		else if(this.m_bIsNN4) {			
			this.m_oObj = SeekLayer(document, thisObj);
		}
	}
	else {
		this.m_oObj = thisObj;
	}
}

CDHTMLAPI.prototype.GetObject = function(thisObj)
{
	this.GetRawObject(thisObj);
	if(this.m_oObj && this.m_bIsCSS) {
		this.m_oObj = this.m_oObj.style;
	}
}

CDHTMLAPI.prototype.MoveTo = function(thisObj, x, y)
{
	this.m_oObj = this.GetObject(thisObj);
	if(this.m_oObj) {
		if(this.m_bIsCSS) {
			var units = (typeof(this.m_oObj.left == "string")) ? "px" : 0;
			this.m_oObj.left = x + units;
			this.m_oObj.top = y + units;
		}
		else if(this.m_bIsNN4) {
			this.m_oObj.moveTo(x, y);
		}
	}
}

CDHTMLAPI.prototype.MoveBy = function(thisObj, dX, dY)
{
	this.m_oObj = this.GetObject(thisObj);
	if(this.m_oObj) {
		if(this.m_bIsCSS) {
			var units = (typeof(this.m_oObj.left = "string")) ? "px" : 0;
			this.m_oObj.left = this.GetObjectX(thisObj) + dX + units;
			this.m_oObj.top = this.GetObjectY(thisObj) + dY + units;
		}
		else if(this.m_bIsNN4) {
			this.m_oObj.moveBy(dX, dY);
		}
	}
}

CDHTMLAPI.prototype.SetZIndex = function(thisObj, zOrder)
{
	this.m_oObj = this.GetObject(thisObj);
	if(this.m_oObj) {
		this.m_oObj.zIndex = zOrder;
	}
}
			
CDHTMLAPI.prototype.SetBGColor = function(thisObj, newColor)
{
	this.m_oObj = this.GetObject(thisObj);
	if(this.m_oObj) {
		if(this.m_bIsNN4) {
			this.m_oObj.bgColor = newColor;
		}
		else if(this.m_bIsCSS) {
			this.m_oObj.backgroundColor = newColor;
		}
	}	
}

CDHTMLAPI.prototype.ShowObj = function(thisObj)
{
	this.m_oObj = this.GetObject(thisObj);
	if(this.m_oObj) {
		this.m_oObj.visibility = "visible";
	}
}

CDHTMLAPI.prototype.HideObj = function(thisObj)
{
	this.m_oObj = this.GetObject(thisObj);
	if(this.m_oObj) {
		this.m_oObj.visibility = "hidden";
	}
}

CDHTMLAPI.prototype.GetObjectX = function(thisObj)
{
	this.GetRawObject(thisObj);
	this.m_oElem = this.m_oObj;
	if(document.defaultView) {
		this.m_oStyle = document.defaultView;
		this.m_cssDecl = this.m_oStyle.getComputedStyle(this.m_oElem, "");
		this.m_nX = parseInt(this.m_cssDecl.getPropertyValue("left"));
	}
	else if(this.m_oElem.currentStyle) {
		this.m_nX = parseInt(this.m_oElem.currentStyle.left);
	}
	else if(this.m_oElem.style) {
		this.m_nX = parseInt(this.m_oElem.style);
	}
	else if(this.m_bIsNN4) {
		this.m_nX = parseInt(this.m_oElem.left);
	}
}

CDHTMLAPI.prototype.GetObjectY = function(thisObj)
{
	this.GetRawObject(thisObj);
	this.m_oElem = this.m_oObj;
	if(document.defaultView) {
		this.m_oStyle = document.defaultView;
		this.m_cssDecl = this.m_oStyle.getComputedStyle(this.m_oElem, "");
		this.m_nY = parseInt(this.m_cssDecl.getPropertyValue("top"));
	}
	else if(this.m_oElem.currentStyle) {
		this.m_nY = parseInt(this.m_oElem.currentStyle.top);
	}
	else if(this.m_oElem.style) {
		this.m_nY = parseInt(this.m_oElem.style.top);
	}
	else if(this.m_bIsNN4) {
		this.m_nY = parseInt(this.m_oElem.top);
	}
}

CDHTMLAPI.prototype.GetObjectWidth = function(thisObj)
{
	this.m_oElem = this.GetRawObject(thisObj);
	if(this.m_oElem.offsetWidth) {
		this.m_nWidth = parseInt(this.oElem.offsetWidth);
	}
	else if(this.m_oElem.clip && this.m_oElem.clip.width) {
		this.m_nWidth = parseInt(this.m_oElem.clip.width);
	}
	else if(this.m_oElem.style && this.m_oElem.style.pixelWidth) {
		this.m_nWidth = parseInt(this.m_oElem.style.pixelWidth);
	}
}

CDHTMLAPI.prototype.GetObjectHeight = function(thisObj)
{
	this.oElem = this.GetRawObject(thisObj);
	if(this.m_oElem.offsetHeight) {
		this.m_nHeight = parseInt(this.m_oElem.offsetHeight);
	}
	else if(this.m_oElem.clip && this.m_oElem.clip.height) {
		this.m_nHeight = parseInt(this.m_oElem.clip.height);
	}
	else if(this.m_oElem.style && this.m_oElem.style.pixelHeight) {
		this.m_nHeight = parseInt(this.m_oElem.style.pixelHeight);
	}
}

CDHTMLAPI.prototype.GetClientWindowWidth = function()
{
	if(window.innerWidth) {
		this.m_nClientWndWidth = window.innerWidth;
	}
	else if(this.m_bIsIE6) {
		this.m_nClientWndWidth = document.body.parentElement.clientWidth;
	}
	else if(document.body && document.body.clientWidth) {
		this.m_nClientWndWidth = document.body.clientWidth;
	}
	else {
		this.m_nClientWndWidth = 0;
	}
}

CDHTMLAPI.prototype.GetClientWindowHeight = function()
{
	if(window.innerHeight) {
		this.m_nClientWndHeight = window.innerHeight;
	}
	else if(this.m_bIsIE6) {
		this.m_nClientWndHeight = document.body.parentElement.clientHeight;
	}
	else if(document.body && document.body.clientHeight) {
		this.m_nClientWndHeight = document.body.clientHeight;
	}
	else {
		this.m_nClientWndHeight = 0;
	}
}
	
CDHTMLAPI.prototype.GetWindowWidth = function()
{
	return this.m_nClientWndWidth;
}

CDHTMLAPI.prototype.GetWindowHeight = function()
{
	return this.m_nCleintWndHeight;
}


CDHTMLAPI.prototype.ShowControl = function(thisObj)
{
	var objVal = thisObj.toString();
	this.GetObject(objVal);
	if(this.m_oObj) {
		this.m_oObj.display = "block";
	}
}

CDHTMLAPI.prototype.HideControl = function(thisObj)
{
	var objVal = thisObj.toString();
	this.GetObject(objVal);
	if(this.m_oObj) {
		this.m_oObj.display = "none";
	}
}

