// $Id: popUp.js,v 1.3 2002/11/05 16:18:57 rl Exp $

function findPosX(obj)
{
	var curleft = 0;
	if (document.getElementById || document.all)

	{	
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
	if (document.getElementById || document.all)
	{

		while (obj.offsetParent)
		{
			//printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
		curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curtop += obj.y;
	window.status = printstring;
	return curtop;
}


function getObj(name)
{
 if (document.getElementById)
 {
	   this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
 
 }
 else if (document.all)
 {
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
 }
 else if (document.layers)
 {
	   if (document.layers[name])
	   {
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	   }
	   else
	   {
	    this.obj = document.layers.testP.layers[name];
	    this.style = document.layers.testP.layers[name];
	   }
 }
}

function popUp(obj,currElem,doThis){
	var objX = findPosX(obj);
	var objY = findPosY(obj);
	var popUpWidth = 400;
	var popUpXOffset = -5;
	var popUpX = 0;
	var popUpY = 0;


	var x = new getObj(currElem);
	if (doThis == 'show') {
		x.style.visibility = "visible";

	} else if (doThis == 'hide'){
		x.style.visibility = "hidden";
	}
	if (x.obj.offsetWidth) 	{popUpWidth = x.obj.offsetWidth;}
	
	// Netscape 4 doesn't allow units
	// to be set for .top and .left
	// Netscape 7 in Standards Compliant Mode requires them

	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}

	//alert (objX + ',' + x.obj.offsetWidth + ',' + frameWidth);
	if (objX + x.obj.offsetWidth > frameWidth) {
		popUpX = frameWidth - x.obj.offsetWidth;
	} else {
		popUpX = objX;
	}

	//if ((newX - popUpWidth) < 0)
		//{newX = 300;alert('objX - 400 > 300');}
	if (document.getElementById || document.all){
		x.style.top = (objY + 15 + 'px');
		x.style.left = (popUpX - 5 + 'px');
	}else{
		x.style.top = (objY + 15);
		x.style.left = (popUpX - 5);
		
	}
}
