// JScript File

function getElement(psID) {
   if(document.all) {
      return document.all[psID];
   } else {
      return document.getElementById(psID);
   }
} 

var _openWin =null;
var _hiItem =null;

var _timeId=null

function stopTimeOut(timeId)
{
   clearTimeout(_timeId);
   _timeId = null;
}

function MenuBar_ShowMainWindow(button,window,cssPrefix, topHeight)
{  	
	stopTimeOut(_timeId)	
	_timeId = setTimeout("autoCloseWindow('"+cssPrefix+"')",10000);

	// event.cancelBubble = true;
	
	var w = getElement(window);
     
    CloseAllSubWIndow(0);	
   
    if ( _hiItem != null )
          _hiItem.className  = cssPrefix+'_Cell'; 
    
    if ( _openWin != null )
			_openWin.style.visibility = 'hidden';	      
     
    if ( w != null )
        button.className = cssPrefix + '_Cell_O';
     else 
        button.className = cssPrefix + '_Cell_O_No_Window';
               
    
     _hiItem = button;
	
	if ( w != null && ( w.style.visibility == 'hidden' || w.style.visibility == '' )  )
	{	
			w.style.top = topHeight;
			w.style.visibility = 'visible';
		    _openWin = w;
		
	}
   
    //document.forms[0].onclick = CloseWin; 
	
}

var _subItems = new Array(10);
var _subWindows = new Array(10);

function MenuBar_ShowSubWindow(button,window,cssPrefix, itemCssPrefix)
{

	stopTimeOut(_timeId)	
	_timeId = setTimeout("autoCloseWindow('"+itemCssPrefix+"')",10000);

	var w = getElement(window);
	var _data = window.split('_');
	var _level = parseInt(_data[_data.length-2]);
	
 
    // Il Bottone

//    if ( _subItems[_level] != null ) // Ripristino stile normale ....
 //   {
			ResetStyleItem(_level,cssPrefix);
           //_subItems[_level].className  = cssPrefix; 
           
//	}



    button.className = cssPrefix+'_O';
               
    _subItems[_level] = button;
   
   // La finestra

    // if ( _subWindows[_level] != null )
	//	_subWindows[_level].style.visibility = 'hidden'; 
	
	
	
	CloseAllSubWIndow(_level);
	
	if ( w != null && ( w.style.visibility == 'hidden' || w.style.visibility == '' )  )
	{	
		w.style.visibility = 'visible';
		  _subWindows[_level] = w;		
	}

}

function ResetStyleItem(level,cssPrefix)
{
   		for( i = level;  i < 10 ; i++)
		{			
			if ( _subItems[i] != null )
					_subItems[i].className  = cssPrefix; 
		}
	
}

function CloseAllSubWIndow(level)
{
   		for( i = level;  i < 10 ; i++)
		{			
			if ( _subWindows[i] != null )
				_subWindows[i].style.visibility = 'hidden';	
		}
	
}

function autoCloseWindow(cssPrefix)
{	

     if ( _hiItem != null )
     {
         _hiItem.className  = cssPrefix+'_Cell'; 
     }
    
    if ( _openWin != null )
			_openWin.style.visibility = 'hidden';	 

    	for( i = 0;  i < 10 ; i++)
		{			
			if ( _subWindows[i] != null )
				_subWindows[i].style.visibility = 'hidden';	
		}		
		
		for( i = 0;  i < 10 ; i++)
		{			
			if ( _subItems[i] != null )
				_subItems[i].className  = cssPrefix + '_Item'; 
		}
		
		_hiItem = null;
		_openWin = null;
		
        _subItems = new Array(10);
        _subWindows = new Array(10);

}