function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

var timerID = 0;
function ViewToolTip(element, tT, visible)
{
	x = findPosX(element);
	y = findPosY(element);
	
	if (! visible)
	{
		if(timerID) 
		{
			clearTimeout(timerID);
			timerID  = 0;
		}
		divtip = document.getElementById(tT);
		if (visible)
			divtip.style.visibility="visible";
		else	
			divtip.style.visibility="hidden";
	}
	else
	{
		timerID = setTimeout("ToolTip('" + x + "','" + y + "','" + tT + "')", 1000);
	}
}

function ToolTip(x, y, tT)
{
	divtip = document.getElementById(tT);
	divtip.style.visibility="visible";
	divtip.Left= x;
	divtip.Top = y -100 ;
}

function CopiaDati(source, target)
{
	var dest = document.getElementById(target);
	if (trim(dest.value) == "")
		dest.value=source.value;
}

function CentraControllo(controllo, controlWidth, controlHeight)
{
	var winW = 800;
	var winH = 600;
	if (parseInt(navigator.appVersion) > 3) 
	{
		if (navigator.appName == "Netscape") 
		{
			winW = window.innerWidth;
			winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) 
		{
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
		}
	}

	var control = document.getElementById(controllo);
	control.style.top = (winH - controlHeight) / 2;
	control.style.left = (winW - controlWidth) / 2 - 5;
}

function VisualizzaDiv(div)
{
	hideElementUnderDiv("SELECT", document.getElementById(div));
}

function NascondiDiv()
{
	showElementUnderDiv("SELECT");
}

function showElementUnderDiv(elmID)
{
	// Display any element that was hidden
	for (i = 0; i < document.all.tags(elmID).length; i++)
	{
		obj = document.all.tags(elmID)[i];
		if (! obj || ! obj.offsetParent)
			continue;
		obj.style.visibility = "visible";
	}
}
function hideElementUnderDiv(elmID, eMenu)
{
	var obj;
	// Hide any element that overlaps with the dropdown menu
	for (i = 0; i < document.all.tags(elmID).length; i++)
	{
		var ParentOffset=0;
		
		obj = document.all.tags(elmID)[i];
		if (elementTopDiv(obj) >  eMenu.offsetHeight + eMenu.offsetTop)
		{
			//if element is below bottom of menu then do nothing
		}
		else if (elementLeftDiv(obj) > parseInt(eMenu.offsetLeft) + eMenu.offsetWidth)
		{
			//if element is to the right of menu then do nothing
		}
		else if (elementLeftDiv(obj) + obj.offsetWidth < parseInt(eMenu.offsetLeft))
		{
			//if element is to the left of menu then do nothing
		}
		else if (elementTopDiv(obj) + obj.offsetHeight - 1 < parseInt(eMenu.offsetTop))
		{
			//if element is to the top of menu then do nothing
		}
		else
		{
			obj.style.visibility = "hidden";
		}
	}
}
function elementTopDiv(eSrc)
{
	var iTop = 0;
	var eParent;
		
	eParent = eSrc;
	
	while (eParent.tagName.toUpperCase() != "BODY")
	{
		iTop += eParent.offsetTop;
		eParent = eParent.offsetParent;
	}
	return iTop;

}

function elementLeftDiv(eSrc)
{	
	var iLeft = 0;
	var eParent;
		
	eParent = eSrc;
	
	while (eParent.tagName.toUpperCase() != "BODY")
	{
		iLeft += eParent.offsetLeft;
		eParent = eParent.offsetParent;
	}
	return iLeft;

}

