function Position(obj) 
{
	var curleft = curtop = 0;

	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	
	return new Point(curleft, curtop);
}			

function getElementPosition(elem)
{
	//determine top, left, width and height properties
	var pos = new Position(elem);
	var width = getWidth(elem);
	var height = getHeight(elem);
	
	//create rectangle structure
	var r = new Rectangle(pos.y, pos.x, width, height);
		
	return r;
}

function Rectangle(top, left, width, height)
{
	//rectangle boundaries
	this.top = top;
	this.left = left;
	this.width = width;
	this.height = height;

	//absolute values
	this.x1 = left;
	this.x2 = left + width;
	this.y1 = top;
	this.y2 = top + height;

	//position coordinates
	this.p1 = new Point(this.x1, this.y1);
	this.p2 = new Point(this.x2, this.y1);
	this.p3 = new Point(this.x1, this.y2);
	this.p4 = new Point(this.x2, this.y2);
}

function Point(x, y)
{
	this.x = x;
	this.y = y;
}


function getWidth(el)
{
	if (isInternetExplorer)
		return getMsieWidth(el);
	else
		return parseInt(getStyle(el, "width"));
}

function getHeight(el)
{
	if (isInternetExplorer)
		return getMsieHeight(el);
	else
		return parseInt(getStyle(el, "height"));
}

function getStyle(el, style) 
{
   if(!document.getElementById) return;
   if (isInternetExplorer) return;
    var value = el.style[style];

    if(!value)
        if(document.defaultView)
            value = document.defaultView.getComputedStyle(el, "").getPropertyValue(style);
        else if(el.currentStyle)
            value = el.currentStyle[toCamelCase(style)];

     return value;
}


function setStyle(objId, style, value) 
{
	if (document.getElementById(objId) && document.getElementById(objId).style)
		document.getElementById(objId).style[style] = value;
}			


function getMsieWidth(el)
{
	return parseInt(el.currentStyle.width);
}

function getMsieHeight(el)
{
	var tmp = el.currentStyle.height;
	if (tmp.toUpperCase() == 'AUTO')
		if (el.tagName.toUpperCase() == "SELECT")
			return 40;
		else
			return 200;
	else
		return parseInt(tmp);
}

