/*
______________________________________________________

	domfuncs.js - DOM Browser Standard Functions
		 Code by Chriztian Steinmeier

	$Id: domfuncs.js,v 1.2 2002-06-11 22:48:53+02 chriz Exp $
	
	The Class/Object CDOMfuncs contains standard
	functions for manipulating DOM elements etc.
	
	Usage
		Include the file with a script-include,
		and call the various functions via the
		DOMfuncs object's methods.
	
	Examples
		var DOMfuncs = new CDOMfuncs();
		
		DOMfuncs.placeLayer('myLayerID', '45px', 88);
		DOMfuncs.hideLayer('myLayerID');
		
______________________________________________________
													*/
var csComponent_DOMfuncs = false;

function CDOMfuncs() {
// Methods
	this.hideLayer		= m_impl_hideLayer;
	this.showLayer		= m_impl_showLayer;
	this.placeLayer		= m_impl_placeLayer;
	this.getDOMelement	= m_impl_getDOMelement;
	this.registerEvent	= m_impl_registerEvent;
	this.getXpos		= m_impl_getXpos;
	this.getYpos		= m_impl_getYpos;
	this.getLeft		= m_impl_getLeft;
	this.getTop			= m_impl_getTop;
	this.getWidth		= m_impl_getWidth;
	this.getHeight		= m_impl_getHeight;
	
// --- Implementation ---
	function m_impl_hideLayer(strDivName) {
		var objDiv = m_impl_getDOMelement(strDivName);
		if (objDiv)
			objDiv.style.visibility = "hidden";
	}
	
	function m_impl_showLayer(strDivName) {
		var objDiv = m_impl_getDOMelement(strDivName);
		if (objDiv)
			objDiv.style.visibility = "visible";
	}
	
	function m_impl_placeLayer(strDivName, strX, strY /* Optional: */, intZ) {
    	var objDiv = m_impl_getDOMelement(strDivName);
		if (objDiv) {
			objDiv.style.left = (typeof(strX) == "string" ? strX : strX + "px");
			objDiv.style.top = (typeof(strY) == "string" ? strY : strY + "px");
			if (typeof(intZ) != "undefined")
				objDiv.style.zIndex = intZ;
		}
    }
	
	// Get a reference to an element in the DOM by its ID.
	// If strElementID is not a string, it's presumed to be the object
	function m_impl_getDOMelement(strElementID) {
    	if (typeof(strElementID) == "string") {
			if (document.getElementById)
				return document.getElementById(strElementID);
			else if (document.all)
				return document.all[strElementID];
			else
				return null;
		} else {
			return strElementID;
		}
    }
	
	function m_impl_registerEvent(strElementID, strEvent, strFunction) {
		var objDiv = m_impl_getDOMelement(strElementID);
		eval("objDiv." + strEvent + " = " + strFunction + ";");
    }
	
	function m_impl_getXpos(strElementID) {
        var objDiv = m_impl_getDOMelement(strElementID);
		if (typeof(objDiv.offsetLeft) != "undefined")	// offsetLeft could be zero 
			return getRecursiveX(objDiv);
		else
			return getStyleProperty(strElementID, "left");
    }
	
	function m_impl_getYpos(strElementID) {
        var objDiv = m_impl_getDOMelement(strElementID);
		if (typeof(objDiv.offsetTop) != "undefined")	// offsetTop could be zero 
			return getRecursiveY(objDiv);
		else
			return getStyleProperty(strElementID, "top");
    }
	
	function m_impl_getLeft(strElementID) {
		objDiv = m_impl_getDOMelement(strElementID);
		if (typeof(objDiv.offsetLeft) != "undefined")
			return objDiv.offsetLeft;
		else
			return getStyleProperty(strElementID, "left");
    }
	
	function m_impl_getTop(strElementID) {
		objDiv = m_impl_getDOMelement(strElementID);
		if (typeof(objDiv.offsetTop) != "undefined")
			return objDiv.offsetTop;
		else
			return getStyleProperty(strElementID, "top");
    }
	
	function m_impl_getWidth(strElementID) {
		objDiv = m_impl_getDOMelement(strElementID);
		if (typeof(objDiv.offsetWidth) != "undefined")
			return objDiv.offsetWidth;
		else
			return getStyleProperty(strElementID, "width");
    }
	
	function m_impl_getHeight(strElementID) {
		objDiv = m_impl_getDOMelement(strElementID);
		if (typeof(objDiv.offsetHeight) != "undefined")
			return objDiv.offsetHeight;
		else
			return getStyleProperty(strElementID, "height");
    }
	
	function getRecursiveX(obj) {
		return obj.tagName == "BODY" ? obj.offsetLeft : obj.offsetLeft + getRecursiveX(obj.parentNode);
    }
	
	function getRecursiveY(obj) {
		return obj.tagName == "BODY" ? obj.offsetTop : obj.offsetTop + getRecursiveY(obj.parentNode);
    }
	
	function getStyleProperty(elmID, prop) {
        var objDiv = m_impl_getDOMelement(elmID);
		if (document.defaultView)
			return document.defaultView.getComputedStyle(objDiv, "").getPropertyValue(prop);
		else if (objDiv.currentStyle)
			return eval("objDiv.currentStyle." + prop + ";");
		else if (objDiv.style)
			return eval("objDiv.style." + prop + ";");
		else
			return "";
	}
	
	// For debugging purposes:
	this.styleDump = m_impl_styleProps;
	function m_impl_styleProps(strID) { alert(m_impl_dump(m_impl_getDOMelement(strID).style)); }
	function m_impl_dump(obj) { var s = ""; for (var f in obj) if ( typeof(obj[f]) != "function" ) s += ("    " + f + ": " + obj[f]); return s; }
}

csComponent_DOMfuncs = true;
