// getElementPosition(elementname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named element, relative to the page.
function getElementPosition(elementname) {
	// This function will return an Object with x and y properties
	var coordinates=new Object();
	var x=0,y=0;

	// Browser capability sniffing
	var use_dom=false, use_css=false;
	// is DOM Complaint
	if (document.getElementById) { use_dom=true; }
	// isIE
	else if (document.all) { use_css=true; }
	
	// Logic to find position
	if (use_css) {
		x=getPageOffsetLeft(document.all[elementname]);
		y=getPageOffsetTop(document.all[elementname]);
	}
	else if (use_dom) {
		var o=document.getElementById(elementname);
		x=getPageOffsetLeft(o);
		y=getPageOffsetTop(o);
	}
	else {
		coordinates.x=0; 
		coordinates.y=0; 
		return coordinates;
	}
	
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
}

function getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
}

function getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
}





