
function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent; 
		}
	}
	return curleft;
}
function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent; 
		}
	}
	return curtop;
}

function hide(name,parent) {
	div(name).style.display = 'none';
}

function show(name,parent) {
   var d=div(name);
   var p=document.images[parent];
   	d.style.display = '';
	xPos = findPosX(p)+ p.offsetWidth + 2;
	yPos = findPosY(p) + p.offsetHeight + 2;
	if (xPos - document.body.scrollLeft + d.offsetWidth > document.body.clientWidth) //+ document.body.scrollLeft 
	  {xPos = findPosX(p) - d.offsetWidth - 2;}
	if (yPos - document.body.scrollTop + d.offsetHeight > document.body.clientHeight) //+ 
	  {yPos = findPosY(p) - d.offsetHeight - 2;}
	d.style.left = xPos + 'px';
	d.style.top  = yPos + 'px';
        //alert(d+"\n"+p+"\n"+d.offsetWidth+"\n"+document.body.clientWidth+"\n"+findPosX(p)+"\n"+xPos+"\n");
}

function toggle(name,parent) {
   var d=div(name);
   if (!d.style.display)
   {hide(name,parent);}
   else
   {show(name,parent);}
}


function div(name) {
   var d = document;
   if(d.getElementById && !(d.all))
      return d.getElementById(name);
   else if(d.all)
      return d.all[name];
};
