
 function isUndefined(a) {
    return typeof a == 'undefined';
 } 
 
 function isNull(a) {
    return typeof a == 'object' && !a;
}

function isFunction(a) {
    return typeof a == 'function';
} 
 
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isNull(a) {
    return typeof a == 'object' && !a;
}

 
   function InitMenu()
   {
	var menuBar = document.getElementById("menuBar");
    var bar = menuBar.childNodes 

     for(var i=0;i < bar.length;i++) 
        {
			
		  bar[i].onmouseover = new Function("ShowMenu('"+bar[i].id+"')");	
		  
		  
		  if (!isNull(document.getElementById(bar[i].getAttribute("menu")))) { 
			var menu=document.getElementById(bar[i].getAttribute("menu"))
			if (!isUndefined(menu)) {
				menu.style.display = "none"
				var Items = menu.childNodes
				for(var j=0; j<Items.length; j++)
					{
						var menuItem = document.getElementById(Items[j].id)
						if(menuItem.getAttribute("menu") != null)
						{ 
							FindSubMenu(menuItem.getAttribute("menu"))
						}
						if(menuItem.getAttribute("cmd") != null) 
						{
						menuItem.onclick = new Function("Do("+menuItem.id+")") 
						}
						menuItem.onmouseover = new Function("highlight('"+Items[j].id+"')")
					}    
			  }
			}
        }  
   }
   
   function FindSubMenu(subMenu)
   {
    
		if (!isNull(document.getElementById(subMenu))) {
		var menu = document.getElementById(subMenu);
         
         var Items = menu.childNodes
          for(var j=0; j<Items.length; j++)
            {
              menu.style.display = "none"
              var menuItem = document.getElementById(Items[j].id);
              
              if(menuItem.getAttribute("menu")!= null)
                 {
                    FindSubMenu(menuItem.getAttribute("menu"))
                 }

              if(menuItem.getAttribute("cmd") != null) 
                {
				    menuItem.onclick = new Function("Do("+menuItem.id+")") 
                } 
              menuItem.onmouseover = new Function("highlight('"+Items[j].id+"')")
            }  
        }
   } 
   
   function ShowMenu(vId)
   {
	var menuBar = document.getElementById("menuBar");
    var obj = document.getElementById(vId); 
    HideMenu(menuBar);

    
     if (isObject(obj)) {
		
		if (!isNull(document.getElementById(obj.getAttribute("menu")))) { 
			var menu = document.getElementById(obj.getAttribute("menu"));
			
			var bar = document.getElementById(obj.id)
			bar.className="barOver"
			
			menu.style.display = "block";
			
		    var objDiv = document.getElementById("SottoMenu");
		    objDiv.style.display = "block";
		    
			if (document.documentElement && document.documentElement.scrollTop)
				theTop = document.documentElement.scrollTop;
			else if (document.body)
				theTop = document.body.scrollTop
			else
				theTop = 0		    
		    
			if (isUndefined(document.getBoxObjectFor)) {
				
				objDiv.style.top = obj.getBoundingClientRect().top + theTop + 29;// + document.body.scrollTop
				objDiv.style.left = obj.getBoundingClientRect().left + 5; // + document.body.scrollLeft	    	    
				
			} else {
				objDiv.style.top = document.getBoxObjectFor(obj).y+ theTop +31 + "px"; // + document.body.scrollTop
				objDiv.style.left = document.getBoxObjectFor(obj).x+ theTop +7 + "px"; // + document.body.scrollLeft	    
			}
		}
     }
     
	hideElement( 'SELECT', document.getElementById("SottoMenu") );

   }
   
   function highlight(vId)
   {
	var obj = document.getElementById(vId);
   
     var PElement = document.getElementById(obj.parentNode.id)
     if(PElement.hasChildNodes() == true)
     {  var Elements = PElement.childNodes
       for(var i=0;i<Elements.length;i++)
       {
          TE = document.getElementById(Elements[i].id)
          TE.className = "menuItem"
       }
      }
      
     obj.className="ItemMouseOver"

     ShowSubMenu(obj)
   }
   
   function Do(obj)
   {
    var cmd = document.getElementById(obj).getAttribute("cmd")	
    window.navigate(cmd)
     
   }
   
   function HideMenu(obj)
   {
		
          if(obj.hasChildNodes()==true)
              {  
                 var child = obj.childNodes     
                 
                 for(var j =0;j<child.length;j++)
                  {
					
                     if (child[j].className=="barOver")
                     {
						var bar = document.getElementById(child[j].id)
						bar.className="Bar"
					 }
                     
                     if (!isNull(document.getElementById(child[j].getAttribute("menu")))) { 
						
						if(child[j].getAttribute("menu") != null)
                       {
                          var childMenu = document.getElementById(child[j].getAttribute("menu"))
                          if(childMenu.hasChildNodes()==true) 
                               HideMenu(childMenu)
                          
                           childMenu.style.display = "none" 
                         }
                     }
                  }
              
              }
              
           showElement( 'SELECT' );   
   }
   

   
   
  function ShowSubMenu(obj)
  {
     PMenu = document.getElementById(obj.parentNode.id)
     HideMenu(PMenu)
	 hideElement( 'SELECT', document.getElementById("SottoMenu") );     
     
	 
     if(obj.getAttribute("menu") != null)
     {
		if (!isNull(document.getElementById(obj.getAttribute("menu")))) { 
			var menu = document.getElementById(obj.getAttribute("menu"))
			menu.style.display = "block"
			menu.style.position ="absolute";
			menu.style.zIndex = "200";
			
			if (isUndefined(document.getBoxObjectFor)) {
				menu.style.top = 0;// + document.body.scrollTop
				menu.style.left = 176; // + document.body.scrollLeft	    	    
				
				if((obj.getBoundingClientRect().left+150) > window.screen.availWidth) {
					menu.style.left = -176;
				}				
			} else {
				menu.style.top = 0 + "px"; // + document.body.scrollTop
				menu.style.left = 176 + "px"; // + document.body.scrollLeft	    
				vWidth = document.getBoxObjectFor(obj).x+150;
				
				if(parseFloat(vWidth) > parseFloat(window.screen.availWidth) ) {
					menu.style.left = -176 +"px";
				}

			}	

			alert(menu.style.left);
			
	
	  }
	  
	  
    }
    
    
  } 


    /*
    * unhides <select> and <applet> objects (for IE only)
    */
    function showElement( elmID )
    {
      if( document.all )
      {
      
        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";
        }
      }
    }
    
    /* hides <select> and <applet> objects (for IE only) */
    function hideElement( elmID, overDiv )
    {
      if( document.all )
      {
        for( i = 0; i < document.all.tags( elmID ).length; i++ )
        {
          obj = document.all.tags( elmID )[i];
          if( !obj || !obj.offsetParent )
          {
            continue;
          }
      
          // Find the element's offsetTop and offsetLeft relative to the BODY tag.
          objLeft   = obj.offsetLeft;
          objTop    = obj.offsetTop;
          objParent = obj.offsetParent;
          
          while( objParent.tagName.toUpperCase() != "BODY" )
          {
            objLeft  += objParent.offsetLeft;
            objTop   += objParent.offsetTop;
            objParent = objParent.offsetParent;
          }
      
          objHeight = obj.offsetHeight;
          objWidth = obj.offsetWidth;
      
          if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft )
          {	
          }
          else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop )
          {
          }
          else if( overDiv.offsetTop >= ( objTop + objHeight ))
          {
          }
          else if( overDiv.offsetLeft >= ( objLeft + objWidth ))
          {
          }
          else
          {
            obj.style.visibility = "hidden";
          }
          
        }
      }
    }    


