/* 
AnchorPosition.js
Author: Matt Kruse
Modified: Wayne Buckelew
Last modified: 8/8/01
*/
function getAnchorPosition(anchorname) {
	var useWindow = false;
	var coords = new Object();
	var x=0,y=0;

	var use_gebi = false, use_css = false, use_layers = false;
	if (document.getElementById) use_gebi = true;
	else if (document.all) use_css = true;
	else if (document.layers) use_layers = true;

 	if (use_gebi&&document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]); }
	else if (use_gebi) {
		var o = document.getElementById(anchorname);
		if (!o) {
			for (var i=0; i<document.images.length; i++) {
				if (document.images[i].name == anchorname) {
					coords.x = document.images[i].x;
					coords.y = document.images[i].y;
					return coords; }
			}
		}
		x = AnchorPosition_getPageOffsetLeft(o);
		y = AnchorPosition_getPageOffsetTop(o); }
 	else if (use_css) {
		x = AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y = AnchorPosition_getPageOffsetTop(document.all[anchorname]); }
	else if (use_layers) {
		var found=0;
		for (var i=0;i<document.anchors.length;i++) {
			if (document.anchors[i].name==anchorname) {
				coords.x=document.anchors[i].x;
				coords.y=document.anchors[i].y;
				return coords; }
		}
		for (var i=0;i<document.images.length;i++) {
			if (document.images[i].name==anchorname) {
				coords.x=document.images[i].x;
				coords.y=document.images[i].y;
				return coords; }
		}
		if (found==0) {
			coords.x=0; coords.y=0; return coords;
		}
		//x = document.anchors[i].x;
		//y = document.anchors[i].y;
	} else {
		coords.x=0;coords.y=0;return coords;
	}
	coords.x=x;
	coords.y=y;
	return coords;
}

function getAnchorWindowPosition(anchorname) {
	var coords=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coords.x-document.body.scrollLeft+window.screenLeft;
			y=coords.y-document.body.scrollTop+window.screenTop;
		} else {
			x=coords.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coords.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	}
	else if (document.all) {
		x=coords.x-document.body.scrollLeft+window.screenLeft;
		y=coords.y-document.body.scrollTop+window.screenTop; }
	else if (document.layers) {
		x=coords.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coords.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
	}
	coords.x=x;
	coords.y=y;
	return coords;
}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent)!=null)
		ol+=el.offsetLeft;
	return ol;
}

function AnchorPosition_getWindowOffsetLeft (el) {
	var scrollamount=document.body.scrollLeft;
	return AnchorPosition_getPageOffsetLeft(el)-scrollamount;
}	

function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent)!=null)
		ot+=el.offsetTop; 
	return ot;
}

function AnchorPosition_getWindowOffsetTop (el) {
	var scrollamount=document.body.scrollTop;
	return AnchorPosition_getPageOffsetTop(el)-scrollamount;
}
