/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *   __     __    __    __         __         _______    _______   *
 *  |  |   |  |  |  |  |  |       |  |       |  _____|  |   __  |  *
 *  |   \_/   |  |  |  |  |       |  |       |   __|    |  |__| |  *
 *  |  |\_/|  |  |  |  |  |____   |  |____   |  |____   |   _   /  *
 *  |__|   |__|  |__|  |_______|  |_______|  |_______|  |__| \__\  *
 *                                                                 *
 *                                     _____   ___   ___| .  ___   *
 *                                    |  |  | | __| |   | |  __ |  *
 *                                    |  |  | |___  |___| | |___|  *
 *                                                                 *
 *                                                                 *
 *    Fisier cu functii necesare functionarii paginilor de web     *
 *         ale site-ului firmei "GUV Electronics s.r.l."           *
 *     Codul poate fii folosit fara restrictii ( open source )     *
 *                                                                 *
 *           file description:         IE & NS menus functions     *
 *            programmer info:                 Written by  McM     *
 *               company info:             Miller Media s.r.l.     *
 *                     e-mail:             millermedia@xnet.ro     *
 *                                   catalinmartazan@yahoo.com     *
 *                                                                 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


var HighlightsTrail = Array();
var MenusTrail = Array();
var ImageContainer = Array();
var Menu_timeoutID;


function LayerVisibility(LayerID, State)
{
   if (LayerID != "")
   {
      document.getElementById(LayerID).style.visibility = State;
   }   
}


function DisableItems()
{
   for (var i = 0; i <= DisableItems.arguments.length - 1; i++)
   {
      with (MenuItemObj[DisableItems.arguments[i]])
      {
         ItemEnabled = false;
         ItemState = 'over';
      }
   }
}


function MakeArray()
{
   var Temp = Array();
   var N = MakeArray.arguments.length / 2 - 1;

   for (var i = 0; i <= N; i++)
   {
      Temp[i] = Array(MakeArray.arguments[2*i], MakeArray.arguments[2*i + 1]);
   }
   return Temp;
}


function Menu(MenuID, MenuCanHide, MenuType, MenuItemsIndexes)
{
  this.MenuID = MenuID;
  this.MenuCanHide = MenuCanHide;
  this.MenuType = MenuType;
  this.MenuItemsIndexes = MenuItemsIndexes;
}


function MenuItem(ItemID,
                  ItemPath,
                  ItemExt,
                  ItemWidth, ItemHeight,
                  ItemLink,
                  ItemStatusText, ItemTitle,
                  ItemState,
                  ItemEnabled,
                  ItemLevel,
                  ItemSubMenuNr)
{
  this.ItemID = ItemID;
  this.ItemPath = ItemPath;
  this.ItemExt = ItemExt;
  this.ItemWidth = ItemWidth;
  this.ItemHeight = ItemHeight;
  this.ItemTitle = ItemTitle;
  this.ItemLink = ItemLink;
  this.ItemStatusText = ItemStatusText;
  this.ItemState = ItemState;
  this.ItemEnabled = ItemEnabled;
  this.ItemLevel = ItemLevel;
  this.ItemSubMenuNr = ItemSubMenuNr;
}


function ImageSource(Nr)
{
   var strID;
   with (MenuItemObj[Nr])
   {
      if (ItemState == "normal")
      {
         strID = '';
      }   
      else if (ItemState == "over")
      {
         strID = '-over';
      }
      else if (ItemState == "down")
      {
         strID = '-down';
      }
      else if (ItemState == "up")
      {
         strID = '-up';
      }
      return ItemPath + strID + ItemExt;    
   }   

}


function RefreshItem()
{
   for (var i = 0; i <= RefreshItem.arguments.length - 1; i++)
   {
      var Nr = RefreshItem.arguments[i];
      if ( (Nr != null) && (Nr <= (MenuItemObj.length - 1)) )
      {
         with (MenuItemObj[Nr])
         {
            if (ItemEnabled)
            {
               document.getElementById(ItemID).src = ImageSource(Nr);
            }  
         }   
      }
   }
}


function RemoveHighlight()
{
   var intStart, intFinish, boolStop;
   
   intStart = ( ((RemoveHighlight.arguments.length == 1) || (RemoveHighlight.arguments.length == 2)) ? RemoveHighlight.arguments[0] : 0);
   if ( (intStart < 0) || (intStart > (HighlightsTrail.length - 1)) )
   {
      boolStop = true;
   }
   else
   {
      boolStop = false;
      if (RemoveHighlight.arguments.length == 1)
      {
         intFinish = intStart;
      }
      else
      {
         intFinish = (RemoveHighlight.arguments.length == 2 ? Math.min(RemoveHighlight.arguments[1], HighlightsTrail.length - 1) : HighlightsTrail.length - 1);
      }
   }
   
   if (!boolStop)
   {
      for (i = intFinish; i >= intStart; i--)
      {
         if (HighlightsTrail[i] != null)
         {
            with (MenuItemObj[HighlightsTrail[i]])
            {
               if (ItemEnabled)
               {
                  ItemState = 'normal';
                  RefreshItem(HighlightsTrail[i]);
                  HighlightsTrail[i] = void HighlightsTrail[i]
               }
            }
         }
      }
   }       
}


function SetHighlight(intPosition, inputValue)
{
   with (MenuItemObj[inputValue])
   {
      if (ItemEnabled)
      {
         ItemState = 'over';
         RefreshItem(inputValue);
         HighlightsTrail[intPosition] = inputValue;
      }   
   }   
}


function SetMenuVisibility(strVisibility, intPosition, inputValue)
{
   if ( (inputValue != null) &&
        ( (inputValue >= 0) && (inputValue <= (MenuObj.length - 1)) ) )
   {
      if (MenuObj[inputValue].MenuCanHide)
      {
         LayerVisibility(MenuObj[inputValue].MenuID, strVisibility);

         if (strVisibility == "hidden")
         {
            MenusTrail[intPosition] = void inputValue;
         }
         else if (strVisibility == "visible")
         {
            MenusTrail[intPosition] = inputValue;
         }
      }   
   }
}


function doAfterDelay()
{
   RemoveHighlight();
   for (i = (MenusTrail.length - 1); i >= 1; i--)
   {
      SetMenuVisibility("hidden", i, MenusTrail[i]);
   }
}


function DoOnItemEnter(Nr)
{
   // cancel execution of exit function
   if (Menu_timeoutID)
   {
      clearTimeout(Menu_timeoutID);
   }
   // end
   
      // remove and/or set highlights
   with (MenuItemObj[Nr])
   {
      RemoveHighlight(ItemLevel + 1, ItemLevel + 2); // removes highlights on submenus, if any exist
      if (Nr != HighlightsTrail[ItemLevel])
      {
         RemoveHighlight(ItemLevel);
         SetHighlight(ItemLevel, Nr);
      }
      // end

      // hide/show submenus
      SetMenuVisibility("hidden", ItemLevel + 2, MenusTrail[ItemLevel + 2]);
      if ( (MenusTrail[ItemLevel + 1] != null) && (MenusTrail[ItemLevel + 1] != ItemSubMenuNr) )
      {
         SetMenuVisibility("hidden", ItemLevel + 1, MenusTrail[ItemLevel + 1]);
      }
      if ( (ItemSubMenuNr != null) && (ItemSubMenuNr != MenusTrail[ItemLevel + 1]) )
      {
         SetMenuVisibility("visible", ItemLevel + 1, ItemSubMenuNr);
      }
      // end
   }
}


function InsertStrValue(strInsert, arrayValue, strTarget)
{
   var strTemp= "";
   var pos = strTarget.indexOf(";");

   if (strInsert == "")
   {
      if (pos != -1)
      {
         strInsert = strTarget.slice(0, pos);
      }
      else
      {
         strInsert = strTarget;
      }
   }

   if (arrayValue.length > 0)
   {
      for(var i = 0; i < arrayValue.length; i++)
      {
         strTemp += ";" + arrayValue[i];
      }
   }
   

   if ((strInsert + strTemp) != strTarget)
   {
      strTarget = strInsert + strTemp;
   }

   return strTarget;
}


function DoOnItemClick(Nr)
{
   with (MenuItemObj[Nr])
   {
      if ( ItemEnabled && (ItemLink != null) && (ItemSubMenuNr == null) )
      {
         window.location = ItemLink;
      }
   }
}


function DoOnMenuExit()
{
   Menu_timeoutID = setTimeout("doAfterDelay()", 100);
}


function DoOnItemImageLoad(Nr)
{
   with (MenuItemObj[Nr])
   {
      if (ItemState == "normal")
      {
         ImageContainer[Nr] = new Image();
         ImageContainer[Nr].src = ItemPath + '-over' + ItemExt;
      }
   }
}


function Write_IMG_Tag(Nr)
{
   with (MenuItemObj[Nr])
   {
      document.write('<IMG ID=\"'+ ItemID + '\" SRC=\"'+ ImageSource(Nr) + '\" WIDTH=\"' + ItemWidth +'\" HEIGHT=\"' + ItemHeight + '\" BORDER=\"0\" TITLE=\"' + ItemTitle + '\"');
      document.write('ONLOAD=\"DoOnItemImageLoad(' + Nr + ')\">');
  }
}


function Write_A_Tag(Nr)
{  
  
   document.write('<A ');       

   with (MenuItemObj[Nr])
   {
      document.write(' ONMOUSEOVER=\"window.status=\'' + ItemStatusText + '\';');
      document.write(' DoOnItemEnter(' + Nr + '); return true;\"');  
      document.write(' ONMOUSEOUT=\"window.status=\'\'; return true;\"');
      document.write(' ONCLICK=\"DoOnItemClick(' + Nr + '); return true;\">');
   }   

   Write_IMG_Tag(Nr);

   document.write('</A>');
}


function Write_TABLE_Tag(Nr)
{
  var i,j;
  
  document.writeln('<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>');

  with (MenuObj[Nr])
  {
     if (MenuType == "h")
     {
        document.write('<TR>');
        
        for(i = 0; i < MenuItemsIndexes.length; i++)
        {
           for(j = MenuItemsIndexes[i][0]; j <= MenuItemsIndexes[i][1]; j++)
           {
              document.write('<TD>');
              Write_A_Tag(j);
              document.writeln('</TD>');
           }
        }
        
        document.write('</TR>');
     }  
     
     else if (MenuType == "v")
     {
        for(i = 0; i < MenuItemsIndexes.length; i++)
        {
           for(j = MenuItemsIndexes[i][0]; j <= MenuItemsIndexes[i][1]; j++)
           {
              document.write('<TR><TD>');
              Write_A_Tag(j);
              document.writeln('</TD></TR>');
           }
        }
     }
  }

  document.write('</TABLE>');
}


function MenuDimensions(ArrayObj, strType)
{
   var i, j;
   var Temp = Array();
   Temp[0] = Temp[1] = 0;

   if (strType == "h")
   {
      for(i = 0; i < ArrayObj.length; i++)
      {
         for(j = ArrayObj[i][0]; j <= ArrayObj[i][1]; j++)
         {
            Temp[0] += MenuItemObj[j].ItemWidth;
         }
         Temp[1] = MenuItemObj[ArrayObj[0][0]].ItemHeight;
      }
   }
   else if (strType == "v")
   {
      for(i = 0; i < ArrayObj.length; i++)
      {
         Temp[0] = MenuItemObj[ArrayObj[0][0]].ItemWidth;
         for(j = ArrayObj[i][0]; j <= ArrayObj[i][1]; j++)
         {
            Temp[1] += MenuItemObj[j].ItemHeight;
         }
      }
   }
   return Temp;
}


function MakeMenu(MenuNr,
                  LeftPos, TopPos,
                  VisibilityState)
{
   with (MenuObj[MenuNr])
   {
      document.write('<DIV ID=\''+ MenuID + '\'');
      document.write('STYLE="position:absolute; left:' + LeftPos + 'px; top:' + TopPos + 'px; '+
                     'z-index:' + (MenuItemObj[MenuItemsIndexes[0][0]].ItemLevel + 1) + '; visibility: ' + VisibilityState + 
                     '; width: ' + MenuDimensions(MenuItemsIndexes, MenuType)[0] + 'px; height: '+ MenuDimensions(MenuItemsIndexes, MenuType)[1] +'px;"');
      document.write('ONMOUSEOUT=\"DoOnMenuExit(); return true;\">');               
      
      Write_TABLE_Tag(MenuNr);
      
      document.write('</DIV>');
   }
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *                                                               *
 *                          END of FILE                          *
 *                                                               *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */