// Toolbar client-side scripting

function isButtonPressed()
{
	if (event.type == 'mouseup')
		return 0;
	else
		return (event.button != 0);
}

function isIE(nVersion, bIncludeMajor) 
{
	/*  -------------------------------------------------------------------------------
		this function tests the browser for the specified version "nVersion".
		version MUST BE passed in the following format	
		
			<minor><major>
			
		examples:
			50
			55
			60
			
		the parameter "bIncludeMajor" specifies if the function returns TRUE even if
		the browser version is major than the specified one.
		------------------------------------------------------------------------------- */
	
	var userAgent = navigator.userAgent;
	var MSIEIndex = userAgent.indexOf("MSIE");
	var nIEVersion = 0;
	
	if (MSIEIndex < 0)
		return false;

	nIEVersion = new Number(userAgent.substring((MSIEIndex + 5), (MSIEIndex + 6)) + 
							userAgent.substring((MSIEIndex + 7), (MSIEIndex + 8))) ;
		
	return (bIncludeMajor ? 
		(nIEVersion >= nVersion) :
		(nIEVersion == nVersion) );
}

function setBtnStyle(sID, sStyle)
{
	var oDiv = document.getElementById('ButtonDiv_' + sID);
	var oImg = document.getElementById('ButtonImg_' + sID);
	
	if (sStyle == 'auto')
	{
		return true;
		/*
		Ho remmato questo pezzo perché in errore con mozilla a causa dell'oggetto event.
		Non ho riscontrato problemi (Sergio)
		if (isButtonPressed())
		{
			if (isIE(55, true))
				oDiv.setCapture(true);
							
			sStyle='pressed';
		}
		else
		{
			if (isIE(55, true))
				oDiv.releaseCapture();	
			
			sStyle='normal';
		}
		*/
	}

	switch(sStyle) 
	{
		case 'hover':		
			oDiv.className = 'toolbarDivHover';
			oImg.className = 'toolbarImgHover';
			break;
		case 'normal':
			oDiv.className = 'toolbarDivNormal';
			oImg.className = 'toolbarImgNormal';
			break;
		case 'pressed':
			oDiv.className = 'toolbarDivPressed';
			oImg.className = 'toolbarImgPressed';
			break;
		default:
			alert('unknown style for setButtonStyle()');
	}	
}	


//Calcola se la lista ci stà sotto altrimenti la visualizza sopra
function TBCalcAbsoluteTop(obj)
{
	var nTop=obj.offsetTop;
	obj=obj.offsetParent;
	while(obj != null)
	{
		nTop=nTop + obj.offsetTop + obj.clientTop;
		obj=obj.offsetParent;
	}
	return nTop;
}				


function TB_CalculatePositionList(TDMenu,SubMenu) {
					
	if (SubMenu != null && TDMenu!=null)
	{
		var nMaxH=TBCalcAbsoluteTop(TDMenu)+SubMenu.clientHeight+50;
		if (nMaxH>document.body.clientHeight+document.body.scrollTop-5)
		{
			SubMenu.style.posTop=-1*SubMenu.clientHeight;
		}
		else
		{
			SubMenu.style.posTop=TDMenu.clientHeight;
		}
	}	
	return;
				
}
				
function TBShowList(sCode) {
					
	var TDMenu = document.getElementById('ButtonTDDiv_' + sCode);
	var SubMenu = document.getElementById('ButtonList_' + sCode);
					
	TB_CalculatePositionList(TDMenu,SubMenu);
					
	SubMenu.style.display='inline';
					
	TB_CalculatePositionList(TDMenu,SubMenu);
	return;
}

function TBHideList(sCode) {
	var SubMenu = document.getElementById('ButtonList_' + sCode);
	if (SubMenu != null)
	{
		SubMenu.style.display='none';
	}	
	return;
}
