var fixBrowserQuirks = true;

var ObjectPositionBody = null;

function getObjectPosition(id) {
	var useWindow=false;
	var coordinates=new Object();
	coordinates.x=0; coordinates.y=0;
	coordinates.z=0; coordinates.w=0;

	if (ObjectPositionBody==null) {
		if (document.body) {
			ObjectPositionBody = document.body;
		   } else if (document.getElementsByTagName) {
			ObjectPositionBody =  document.getElementsByTagName('BODY').item(0);
		   }
	   }
	var o = null;
	if (document.getElementById && (o = document.getElementById(id))!=null) {
		coordinates.x = ObjectPosition_getPageOffsetLeft(o);
		coordinates.y = ObjectPosition_getPageOffsetTop(o);
		coordinates.z = document.getElementById(id).offsetHeight;
		coordinates.w = document.getElementById(id).offsetWidth;
	   } else if (document.anchors && document.anchors.length && document.anchors.length>0 && document.anchors[0].x) {
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==id) { 
				coordinates.x = document.anchors[i].x;
				coordinates.y = document.anchors[i].y;
				coordinates.z = document.getElementById(id).offsetHeight;
				coordinates.w = document.getElementById(id).offsetWidth;
				return coordinates;
			   }
		   }
	   } else if (document.all && (o=document.all[id])!=null) {
		coordinates.x = ObjectPosition_getPageOffsetLeft(o);
		coordinates.y = ObjectPosition_getPageOffsetTop(o);
		coordinates.z = document.getEementById(id).offsetHeight;
		coordinates.w = document.getElementById(id).offsetWidth;
		return coordinates;
	   }
	return coordinates;
   }

function ObjectPosition_getPageOffsetLeft (el) {
	return ObjectPosition_getPageOffsetTopLeft(el,"Left");
   }
   
function ObjectPosition_getPageOffsetTop (el) {
	return ObjectPosition_getPageOffsetTopLeft(el,"Top");
   }

function ObjectPosition_getPageOffsetTopLeft(el,type) {
	if (el.offsetParent && el.parentNode && el.offsetParent==ObjectPositionBody && el.parentNode!=ObjectPositionBody) {
		var considerScrolls = true;
		if (fixBrowserQuirks && window.opera) { considerScrolls = false; } // Opera doesn't need to consider the scroll setting of elements, since it already does so in it's offsetLeft and offsetTop values
		var offset=el["offset"+type];
		while((el=el.parentNode) != null) { 
			if (el==ObjectPositionBody) { 
				if (typeof(el["offset"+type])=="number") {
					offset += el["offset"+type];
				   }
				considerScrolls = false;
			   }
			if (considerScrolls && el!=ObjectPositionBody && el["scroll"+type]) {
				offset -= el["scroll"+type]; 
			   }
		   }
		return offset;
	   } else {
		var offset=el["offset"+type];
		var padding=0;
		var considerScrolls = true;
		if (fixBrowserQuirks && window.opera) { considerScrolls = false; } // Opera doesn't need to consider the scroll setting of elements, since it already does so in it's offsetLeft and offsetTop values
		while((el=el.offsetParent) != null) { 
			padding+=2;
			offset += el["offset"+type]; 
			if (considerScrolls && el!=ObjectPositionBody && el["scroll"+type]) { // Don't count the body scroll!
				offset -= el["scroll"+type]; 
			   }
		   }
		return offset;
	   }
   }
