// in effect this defines a data structure class (it's not really executable code)
function PagePosition(refname, reftype, refx, refy) {
	if (!refname)
		alert("PagePosition called with undefined required first argument refname");
	if (! PositionCache[refname]) {
		this.name = refname;
		if (reftype) 
			this.type = reftype;	// 0=>not initialized yet, use x,y as fallback; 1=>initialized; 2=>use x,y as override
		else
			this.type = 0;
		if (refx)
			this.x = refx;
		else
			this.x = 0;
		if (refy)
			this.y = refy;
		else
			this.y = 0;
		PositionCache[refname] = this;
	}
	var cachedposition = PositionCache[refname];
	if ((! cachedposition.type) || (cachedposition.type == 0)) {
		getPagePosition(cachedposition);
	}
	return cachedposition;
}

function findElem(id) {
	var elem;
	if (document.getElementById) {
		elem = document.getElementById(id);
	} else if (document.all) {
		elem = document[id];
	} else if (document.layers) {
		elem = document.layers[id];
	}
	//if (! elem)
	//	alert("findElem("+id+") failed to find object");
	return elem;
}
function findScrollY() {
	var scrollTop;
	if (window.pageYOffset >= 0)
		scrollTop = window.pageYOffset;
	else
		scrollTop = document.body.scrollTop;
	//alert("obtained current scrollTop " + scrollTop);
	return scrollTop;
}
function setScrollPosition() {
	//alert("setScrollPosition() invoked, scrollgoal=" + scrollgoal + ", scrollgoalprev=" + scrollgoalprev + ", scrollupdatecount=" + scrollupdatecount);
	if (scrollgoal != scrollgoalprev) {
		scrollgoalprev = scrollgoal;

		//alert("before calling findElem");
		var fixedelem=findElem("fixedpart");
		//alert("after calling findElem which returned " + fixedelem);

		//alert("setting scroll position, fixedelem=" + fixedelem + ", fixedelem.style=" + fixedelem.style);
		if (fixedelem) {
			if (fixedelem.style) {
				fixedelem.style.position = "absolute";
				fixedelem.style.visibility = "visible";
				//alert("going to try to set fixedelem.style.top to " + scrollgoal);				
				fixedelem.style.top = scrollgoal;
				fixedelem.style.left = 0; 
			} else {
				fixedelem.position = "absolute";
				fixedelem.visibility = "visible";
				//alert("going to try to set fixedelem.top to " + scrollgoal);
				fixedelem.top = scrollgoal;
				fixedelem.left = 0;
			}
		}
	}
}
function getPagePosition(refposition) {
	if ((! refposition.type) || (refposition.type == 0)) {
		var refelem=findElem(refposition.name);
		// if (! refelem) may be because a) body not loaded yet, b) argument error, or c) old browser (probably NN4)
		if (refelem) {
			refposition.x = findPagePosX(refelem);
			refposition.y = findPagePosY(refelem);
			refposition.type = 1;
		}
	}
}
function findPagePosX(obj) {
	var curleft = 0;
	if (obj) {
		if (obj.offsetParent) {
			while (obj.offsetParent) {
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		} else if (obj.x) {
			curleft += obj.x;
		}
	}
	return curleft;
}
function findPagePosY(obj) {
	var curtop = 0;
	if (obj) {
		if (obj.offsetParent) {
			while (obj.offsetParent) {
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		} else if (obj.y) {
			curtop += obj.y;
		}
	}
	return curtop;
}
function setPagePosition (switchid, refid) {
	var refposition=new PagePosition(refid);
	var switchelem=findElem(switchid);

	if (switchelem.style) {
		switchelem.style.top = refposition.y;
		switchelem.style.left = refposition.x; 
	} else {
		switchelem.top = refposition.y;
		switchelem.left = refposition.x;
	}
}
function hide (switchid, refid)
{
	var switchelem = findElem(switchid);
	if (switchelem.style)
		switchelem.style.visibility = "hidden";
	else
		switchelem.visibility = "hidden";
}
function show (switchid, refid)
{
	setPagePosition(switchid, refid);

	var switchelem = findElem(switchid);

	if (switchelem.style)
		switchelem.style.visibility = "visible";
	else
		switchelem.visibility = "visible";
}

// browser-specific bug compensations
function WM_netscapeCssFix()
{
    // This part was inspired by Matthew_Baird@wayfarer.com
    // It gets around another unfortunate bug whereby Netscape
    // fires a resize event when the scrollbars pop up. This
    // checks to make sure that the window's available size
    // has actually changed.

    if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth ||             document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight)
        {
	//alert("document reload invoked");
        document.location = document.location;
	  // location.reload();	// this alternate line is a change from distributed -- performance enhancement or not?
        }
}
function WM_netscapeCssFixCheckIn()
{
    // This function checks to make sure the version of Netscape
    // in use contains the bug; if so, it records the window's
    // width and height and sets all resize events to be handled
    // by the WM_netscapeCssFix() function.

    if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4))
        {
        if (typeof document.WM == 'undefined')
            {
            document.WM = new Object;
            }

        if (typeof document.WM.WM_scaleFont == 'undefined')
            {
            document.WM.WM_netscapeCssFix = new Object;
            document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
            document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
            }

        //alert("document reload set up");
        window.onresize = WM_netscapeCssFix;
        }
}
function addLoadEvent(func,args) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		alert("window.onload set to just func");
		window.onload = func(args);
	} else {
		window.onload = function() {
			alert("window.onload set to oldfunc and newfunc");
			oldonload();
			func(args);
		}
	}
}

// function definitions above; actually execute now things below 
//  (similar to body OnLoad= except for _all_ pages
//   ad without any presence on the <BODY tag>
WM_netscapeCssFixCheckIn();
