//misc objects
//a simple encapsulation object
//used to query widths and heights
function cDomObject( sId )
{
	this.hElement = document.getElementById( sId )
	this.hStyle = this.hElement.style
}

cDomObject.prototype.getWidth = function( )
{
	return  cDomObject.getWidth( this.hElement )
}

cDomObject.getWidth = function( hElement )
{
	hElement = cDomObject.$( hElement )
	if( hElement.currentStyle )
	{
		var nWidth = parseInt( hElement.currentStyle[ 'width' ] )
		if( !isNaN( nWidth ) )
		{
			return nWidth
		}
	}
	else if( hElement.contentDocument && hElement.contentDocument.defaultView && hElement.contentDocument.defaultView.getComputedStyle )
	{
		var hStyle = hElement.contentDocument.defaultView.getComputedStyle( hElement, null )
		if( hStyle )
		{
			nWidth = hStyle.getPropertyValue( 'width' )
			return nWidth
		}
	}
	return parseInt( hElement.offsetWidth )
}

cDomObject.prototype.getHeight = function( )
{
	return  cDomObject.getHeight( this.hElement )
}

cDomObject.getHeight = function( hElement )
{
	hElement = cDomObject.$( hElement )
	if( hElement.currentStyle )
	{
		var nHeight = parseInt( hElement.currentStyle[ 'height' ] )
		if( !isNaN( nHeight ) )
		{
			return nHeight
		}
	}
	else if( hElement.contentDocument && hElement.contentDocument.defaultView && hElement.contentDocument.defaultView.getComputedStyle )
	{
		var hStyle = hElement.contentDocument.defaultView.getComputedStyle( hElement, null )
		if( hStyle )
		{
			nHeight = hStyle.getPropertyValue( 'height' )
			return nHeight
		}
	}
	return parseInt( hElement.offsetHeight )
}

cDomObject.prototype.getLeft = function()
{
	return cDomObject.getLeft( this.hElement )
}

cDomObject.getLeft = function( hElement )
{
	hElement = cDomObject.$( hElement )
	return parseInt( hElement.offsetLeft )
}

cDomObject.prototype.getTop = function( )
{
	return cDomObject.getTop( this.hElement )
}

cDomObject.getTop = function( hElement )
{
	hElement = cDomObject.$( hElement )
	return parseInt( hElement.offsetTop )
}

cDomObject.getBorderTopWidth = function( hElement )
{
	hElement = cDomObject.$( hElement )
	return hElement.clientTop ? hElement.clientTop : null
}

cDomObject.getBorderLeftWidth = function( hElement )
{
	hElement = cDomObject.$( hElement )
	return hElement.clientLeft ? hElement.clientLeft : null
}


// used to get the absolute position of an relativeli position element
// by accumulating the offset parameters
// example
// cDomObject.getOffsetParam( hElement,'offsetLeft' )
cDomObject.getOffsetParam = function( hElement, sParam, hLimitParent )
{
	hElement = cDomObject.$( hElement )
	var nRes = 0
	if( typeof hLimitParent == 'undefined' || hLimitParent == null )
	{
		hLimitParent = document.body.parentElement
	}
	while( hElement != hLimitParent )
	{
		nRes += hElement[ sParam ] ? hElement[ sParam ] : 0
		if( !hElement.offsetParent ) { break }
		hElement = hElement.offsetParent
	}
	return nRes
}


// used to get the absolute position of an relativeli position element
// by accumulating the scroll offset parameters
// example
// cDomObject.getScrollOffset( hElement,'Left' )

cDomObject.getScrollOffset = function( hElement, sParam, hLimitParent  )
{
	hElement = cDomObject.$( hElement )
	nRes = 0
	if( hLimitParent == null )
	{
		hLimitParent = document.body.parentElement
	}
	while( hElement != hLimitParent )
	{
		nRes += eval( 'hElement.scroll' + sParam )
		if( !hElement.offsetParent ) { break }
		hElement = hElement.parentNode
	}
	return nRes
}

//
cDomObject.getStyle = function( hElement, sStyleSelector )
{
	hElement = cDomObject.$( hElement )
	if( typeof( hElement.style[ sStyleSelector ] ) != 'undefined' && hElement.style[ sStyleSelector ] != '' )
	{
		return hElement.style[ sStyleSelector ]
	}
	else if( hElement.currentStyle )
	{
		if( typeof( hElement.currentStyle[ sStyleSelector ] ) != 'undefined' )
		{
			return hElement.currentStyle[ sStyleSelector ]
		}
	}
	else if( hElement.ownerDocument && hElement.ownerDocument.defaultView && hElement.ownerDocument.defaultView.getComputedStyle )
	{
		var hStyle = hElement.ownerDocument.defaultView.getComputedStyle( hElement, null )
		if( hStyle )
		{
			if( typeof( hStyle[ sStyleSelector ] ) != 'undefined' )
			{
				return hStyle[ sStyleSelector ] 
			}
		}
	}
	return null
}

cDomObject.getStyleValue = function( hElement, sStyleSelector )
{
	var sValue = cDomObject.getStyle( hElement, sStyleSelector )
	var nValue = parseInt( sValue )
	if( !isNaN( nValue ) )
	{
		return nValue
	}
	else
	{
		return null
	}
}


//
cDomObject.$ = function( hElement )
{
	if( typeof( hElement ) == 'string' )
	{
		return document.getElementById( hElement )
	}
	else
	{
		return hElement
	}
}
