/*******************************************************************************
*                                                                              *
* Dynamic Menu System                                                          *
*                                                                              *
********************************************************************************
* Author:         Peter F. Freeman                                             *
* Date:           16th May 2010                                                *
* Version:        1.0.0                                                        *
*                                                                              *
********************************************************************************
* This menu system is designed to display the main menu on the page. By        *
* passing the mouse cursor over an item a second menu is displayed.  Selection *
* of an item on this menu passes the user to that page.                        *
*                                                                              *
* Several facilities are available to the web page writer with options to:     *
*   - Place the menu(s) Vertically or Horizontally.                            *
*   - Change the Font, Background Colour and Border Colour individually on     *
*     both Main Menu items and Secondary Menu items.                           *
*   - Adjust the size of Main Menu items and Secondary Menu Items.             *
*   - Provide an html target of the selected page.                             * 
*                                                                              *
*******************************************************************************/

/***********************************************
* A collection of functions that act on LAYERS *
***********************************************/
function showHideLayers() 
  { 
  var i, p, v, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
    if ((obj = findObj(args[i])) != null) 
      {
      v = args[i+2];
      if (obj.style) 
        {
        obj = obj.style;
        if (v == 'show')
          v = 'visible';
        else
          if (v == 'hide')
            v = 'hidden';
        }
      obj.visibility = v; 
    }
  }

function findObj(n, d) 
  { 
  var p, i, x;

  if (!d) 
    d = document; 
  if ((p=n.indexOf("?")) > 0 && parent.frames.length) 
    {
    d = parent.frames[n.substring(p+1)].document; 
    n = n.substring(0,p);
    }
  if (!(x = d[n]) && d.all) 
    x = d.all[n]; 
  for (i=0; !x&&i<d.forms.length; i++)
    x = d.forms[i][n];
  for (i=0; !x&&d.layers&&i<d.layers.length; i++)
    x = findObj(n, d.layers[i].document);
  if (!x && document.getElementById)
    x = document.getElementById(n); 
  return x;
  }

function changeProp(objName, theProp, theValue) 
  { 
  var obj = findObj(objName);
  if (obj && (theProp.indexOf("style.") == -1 || obj.style))
    {
    if (DEBUG>0) alert ("71: objName=["+objName+"] theProp=["+theProp+"] theValue=["+theValue+"]"); 
    eval ("obj." + theProp + "='" + theValue + "'");
    }
  }

function changeProp2() 
  {
  var args = arguments,
  d = document,	i, j, id = args[0], o = getObjectByID(id), s, ao, v, x;
  d.$cpe = new Array();
  if(o) 
    for(i=2; i<args.length; i+=2)
      {
      v=args[i+1];
      s="o";
      ao=args[i].split(".");
      for(j=0; j<ao.length; j++)
        {
        s+="."+ao[j];
        if(null==eval(s))
          {
          s=null; 
          break; 
          }
        } 
      x=new Object; 
      x.o=o; 
      x.n=new Array(); 
      x.v=new Array();
      x.n[x.n.length]=s; 
      eval("x.v[x.v.length]="+s); 
      d.$cpe[d.$cpe.length]=x;
      if(s) eval(s+"=v"); 
      }
  }

function getObjectByID(id,o) 
  {
  var c, el, els, f, m, n;
  if(!o)
    o = document; 
  if(o.getElementById) 
    el = o.getElementById(id);
  else 
    if(o.layers) 
      c = o.layers; 
    else 
      if(o.all) 
        el = o.all[id]; 
  if(el) 
    return el;
  if(o.id==id || o.name==id) 
    return o; 
  if(o.childNodes) 
    c = o.childNodes; 
  if(c)
    for(n=0; n<c.length; n++) 
      { 
      el = getObjectByID(id,c[n]); 
      if(el) 
        return el; 
      }
  f = o.forms; 
  if(f) 
    for(n=0; n<f.length; n++) 
      { 
      els = f[n].elements;
      for(m=0; m<els.length; m++)
        { 
        el = getObjectByID(id,els[n]); 
        if(el) 
          return el; 
        } 
      }
  return null;
  }
	
function reloadPage(init) 
  { 
  if (init==true) with (navigator) 
    {
    if ((appName == "Netscape") && (parseInt(appVersion) == 4)) 
      {
      document.pgW = innerWidth;
      document.pgH = innerHeight;
      onresize = reloadPage; 
      }
    }
  else 
    if (innerWidth != document.pgW || innerHeight != document.pgH) 
      {
      location.reload();
      }
  }
  reloadPage(true);

/*******************************************************************************
* Load the Menu Items and form the display                                     *
*******************************************************************************/
// Initialize Variables

DEBUG = 2;              // DEBUG - 0 = None; 1 = Partial; 2 = Full

// TOP MENU ARRAY
// Menu[x][0] = ID
// Menu[x][1] = Text
// Menu[x][2] = URL
// Menu[x][3] = TARGET

Menu = new Array();
 
// MENU ITEM ARRAY
// MenuItem[x][0] = PARENT_ID
// MenuItem[x][1] = ID
// MenuItem[x][2] = Text
// MenuItem[x][3] = URL
// MenuItem[x][4] = TARGET

MenuItem = new Array();

var i = 0;
var ii = 0;                 //used in validation of Menu Array
var MaxMenuIndex = 0;

if (DEBUG>1) alert ("Loading menu.js....");

// Default Layer Frame for Internet Explorer and Netscape 6.X
var Layer = "\"<div id='\"+IDLABEL+\"' class='CBORDER' Style='Position:absolute; visibility:\"+VISIBILITY+\"; left:\"+(LEFT+NS6X)+\"px; top:\"+(TOP+NS6X)+\"px; width:\"+(WIDTH+NS6X)+\"px; height:\"+(HEIGHT+NS6X)+\"px; background-color:\"+MyLayerColor+\"; layer-background-image: url(\"+MyLayerBackground+\"); z-index:\"+ZINDEX+\"; URL(\"+MyURL+\")' \"";
var Layer_End = "</div>";
LAYER = new Array();         //Menu string FOR EACH ITEM
MOUSEOVEROUT = new Array();  //Hold menu's id that should have OnMouseOver && OnMouseOut
TOPLEFT = new Array();       //holds TOP and LEFT measures for each menu item
Parent_Children_ID = new Array();

// Layers Variables
var IDLABEL = "";
var VISIBILITY = "visible";  //default
var ZINDEX = 0;
var MyURL = "";

// Position function variables
var TopParent = TOP;
var LeftParent = LEFT;
var ORGWIDTH = WIDTH;
var ORGWIDTHOFFSET = WIDTH_OFFSET;

Parent_Child_Count = new Array();   //Counts the children of each Main Menu
var Main_Parent_Count = 0;          //Counts the number of the Main menu 

// Validation Variable
Error = false; 
var mytarget = "";

// Netscape Corrections
var NS_Table_Width_Corr = 0;
var NS_Table_Heigth_Corr = 0;
var NS6X = 0; 

if (!document.all && document.getElementById) 
  {
  NS6X =- 2;
  } 

/*******************************************************************************
* Add Menu item to Menu Array                                                  *
*******************************************************************************/
function AddTopMenu (ID, Text, URL, TARGET) 
  { 
  var valid = "0123456789";   // Validation
  var temp;
	 
  if (ID.length == 0) 
    {
    alert ("The Menu #"+(ii+1)+" does not have an ID assigned"); 
    Error = true;
    }
	
  // check if ID is composed 
  else 
    { 
    // Checking ID is a number
    for (var j=0; j<ID.length; j++) 
      {
      temp = ID.substring(j, j+1);
      if (valid.indexOf(temp) == -1) 
        {
        alert ("The ID of the Menu #"+(ii+1)+" should be a number value"); 
        Error = true;
        }
      }
    }
	
  if (Text.length == 0) 
    {
    alert ("The Menu #"+(ii+1)+" should have text assigned"); 
    Error = true;
    }

  ii++;
  Menu[i] = new Array();    
  if (!Error) 
    {
    for (var j=0; j<4 ;j++) 
      {         
      if (j==0) 
        { 
        Menu[i][0] = ID;  
        } 
      if (j==1) 
        { 
        Menu[i][1] = Text;       
        }
      if (j==2) 
        { 
        Menu[i][2] = URL;        
        }
      if (j==3) 
        { 
        Menu[i][3] = TARGET;     
        }
      }
    i++; 
    MaxMenuIndex = i;
    }  
	
  // Reinitialze Error Value
  Error=false;
  }

/*******************************************************************************
* Add Menu item to Menu Array                                                  *
*******************************************************************************/
function AddMenuItem (PARENT_ID, ID, Text, URL, TARGET) 
  { 
  var valid = "0123456789";      //Validation
  var temp;
	 
  /******************************************
  * Check PARENT_ID                         *
  ******************************************/
  if (PARENT_ID.length == 0) 
    {
    alert ("The MenuItem #"+(ii+1)+" does not have a PARENT_ID assigned"); 
    Error = true;
    }
	
  // check if PARENT_ID is composed 
  else 
    { 
    // Checking if number
    for (var j=0; j<PARENT_ID.length; j++) 
      {
      temp = PARENT_ID.substring(j, j+1);
      if (valid.indexOf(temp) == -1) 
        {
        alert ("The PARENT_ID of the Menu #"+(ii+1)+" should be a number value"); 
        Error = true;
        }
      }
    }
	
  /******************************************
  * Check ID                                *
  ******************************************/
  if (ID.length == 0) 
    {
    alert ("The MenuItem #"+(ii+1)+" does not have an ID assigned"); 
    Error = true;
    }
	
  // check if ID is composed 
  else 
    { 
    // Checking if number
    for (var j=0; j<ID.length; j++) 
      {
      temp = ID.substring(j, j+1);
      if (valid.indexOf(temp) == -1) 
        {
        alert ("The ID of the Menu #"+(ii+1)+" should be a number value"); 
        Error = true;
        }
      }
    }
	
  /******************************************
  * Check Text                              *
  ******************************************/
  if (Text.length == 0) 
    {
    alert ("The Menu #"+(ii+1)+" should have text assigned"); 
    Error = true;
    }
  ii++;
   
  MenuItem[i] = new Array();    
  if (!Error) 
    {
    for (var j=0; j<5 ;j++) 
      {         
      if (j==0) 
        { 
        MenuItem[i][0] = PARENT_ID;  
        } 
      if (j==1) 
        { 
        MenuItem[i][1] = ID;       
        }
      if (j==2) 
        { 
        MenuItem[i][2] = Text;        
        }
      if (j==3) 
        { 
        MenuItem[i][3] = URL;     
        }
      if (j==4) 
        { 
        MenuItem[i][4] = TARGET;     
        }
      }
    i++; 
    MaxMenuIndex = i;
    }  
	
  //Reinitialze Error Value
  Error=false;
  }

/*******************************************************************************
* BUILD MENUS                                                                  *
*******************************************************************************/
function BuildTopMenu() 
  {

  /******************************************
  * Nescape 4 Correction                    *
  ******************************************/
  NS4XCorrection();
    
  /**********************************************
  * Initilize Position and Mouse Over Variables *
  **********************************************/
  for (var j=0; j<MaxMenuIndex; j++) 
    { 
    TOPLEFT[j] = new Array();
    Parent_Child_Count[j] = 0;
    MOUSEOVEROUT[j] = new Array(); 
    Parent_Children_ID[j] = new Array();  
    TOPLEFT[j][0] = 0;
    TOPLEFT[j][1] = 0;
    }   

  /**********************************************
  * Build Main Menu Items                       *
  **********************************************/

  /**********************************************
  * Build Menu Border and font roll colorI      *
  * through Style Sheet                         *
  **********************************************/
  if (LayerBorderSize!="") 
    {
    document.writeln("<Style type=\"text/css\">");
    document.writeln(".CBORDER {");
    document.writeln(" width:" + WIDTH + "px;"); 
    document.writeln(" heigth:" + HEIGHT + "px;");  
    document.writeln(" border: " + LayerBorderStyle + " " + LayerBorderColor + " " + LayerBorderSize + "px;}\n"); 

    // Link and Roll Link Color
    if (FONTLINKCOLOR != "") 
      {
      if (DEBUG>1) alert ("FONTLINKCOLOR = "+FONTLINKCOLOR);
      document.writeln(".CBORDER A:link { color: " + FONTLINKCOLOR + "; text-decoration: " + DECORATION + ";}\n");
      }
    if (FONTLINKROLLCOLOR != "") 
      {
      if (DEBUG>1) alert ("FONTLINKROLLCOLOR = "+FONTLINKROLLCOLOR);
      } 
    document.writeln("\n</style>\n");
    }

  /**********************************************
  * Build each Menu                             *
  **********************************************/
  for (i=0; i < MaxMenuIndex;i++) 
    {

    /**********************************************
    * Calculates Main Positions, visibility and   *
    * determines ID.                              *
    **********************************************/
    CalcLayerVariables(i); 

    /**********************************************
    * Global Properties.                          *
    **********************************************/
    var MyLayerColor = LayerColor;
    var MyLayerRollColor = LayerRollColor;
    var MyLayerBackground = LayerBackground
          
    // Roll Color  
    if (Main_Parent_LayerColor!="" ) 
      {
      MyLayerColor = Main_Parent_LayerColor;
      }   
 
    // Background Color
    if (Main_Parent_LayerBackground != "" ) 
      {
      MyLayerBackground = Main_Parent_LayerBackground;
      } 

    /**********************************************
    * Save Layer Code.                            *
    **********************************************/
    LAYER[i] = eval(Layer);           

    if (DEBUG>1) alert ("LAYER["+i+"] = "+LAYER[i]);
    }  // End of FOR

  /**********************************************
  * Add same level Mouse Events.                *
  **********************************************/
  SameLevelMouseEvents(); 
 
  /**********************************************
  * Each Menu Item is built and written here.   *
  **********************************************/
  if (DEBUG>1) alert ("Main_Parent_FONTCOLOR = "+Main_Parent_FONTCOLOR);

  /**********************************************
  * Menu Font Item Properties.                  *
  **********************************************/
  for (var j=0; j<MaxMenuIndex; j++) 
    {
    var MyFONT = FONT;
    var MyFONTCOLOR = FONTCOLOR;
    var MyFONTSIZE = FONTSIZE;
    var MyFONTSTYLE = FONTSTYLE;
    var MySTARTCHAR = START_CHAR;
    var MyHALIGN = HALIGN;
 
    /**********************************************
    * Menu Parent/Child Font Item Properties.     *
    **********************************************/
    if (Main_Parent_FONT != "") 
      {
      MyFONT = Main_Parent_FONT;
      }  
    if (Main_Parent_FONTCOLOR != "") 
      {
      MyFONTCOLOR = Main_Parent_FONTCOLOR;
      }              
    if (Main_Parent_FONTSIZE != "") 
      {
      MyFONTSIZE = Main_Parent_FONTSIZE;
      }    
    if (Main_Parent_FONTSTYLE != "") 
      {
      MyFONTSTYLE = Main_Parent_FONTSTYLE;
      }  
    if (Main_Parent_START_CHAR != "") 
      {
      MySTARTCHAR = Main_Parent_START_CHAR;
      }
    if (Main_Parent_HALIGN != "") 
      {
      MyHALIGN = Main_Parent_HALIGN;
      }        

    /**********************************************
    * Menu Item Mouse Over Out Functions.         *
    **********************************************/
    var MOUSEOVERCODE = "";
    var MOUSEOUTCODE = "";
    for (var jj=0; jj<MaxMenuIndex; jj++) 
      {
      if (MOUSEOVEROUT[j][jj] != null) 
        {
        MOUSEOVERCODE = MOUSEOVERCODE + "showHideLayers('" + MOUSEOVEROUT[j][jj] + "','','show');";
        MOUSEOUTCODE = MOUSEOUTCODE + "showHideLayers('" + MOUSEOVEROUT[j][jj] + "','','hide');";
        } 
      else 
        { 
        MOUSEOVERCODE = MOUSEOVERCODE + "PathRoad(" + j + ",1)";           
        MOUSEOUTCODE = MOUSEOUTCODE + "PathRoad(" + j + ",0)";          
        break;
        } 
      } 

    /**********************************************
    * Build Menu Item - Link.                     *
    **********************************************/
    mytarget = ""; 
    if (Menu[j][3] != "") 
      {
      mytarget = Menu[j][3];
      }
    document.write(LAYER[j] + " onMouseOver=\"" + MOUSEOVERCODE + "\" onMouseOut=\"" + MOUSEOUTCODE + "\">");               
    var LINK = "";      
    // display link if any
    if (Menu[j][2] != "") 
      {   
      LINK = "<A href=\"" + Menu[j][2] + "\"";
      if (mytarget != "") 
        {
        LINK = LINK + " target=\"" + mytarget + "\"";
        }
      LINK = LINK + " >"
      if (DEBUG>1) alert ("LINK = "+LINK);
      }

    /**********************************************
    * Build Menu Item - Alignment.                *
    **********************************************/
    if (MyHALIGN != "") 
      {
      document.write("<DIV ALIGN='"+MyHALIGN+"'>");
      } 

    /**********************************************
    * Build Font Properties.                      *
    **********************************************/
    var FONT_PROPERTIES = "";  
    if (MyFONT != "") 
      {
      FONT_PROPERTIES = " Face='" + MyFONT + "'";
      }
    if (MyFONTSIZE != "") 
      {
      FONT_PROPERTIES = FONT_PROPERTIES + " size='" + MyFONTSIZE + "'";
      }
    if (MyFONTCOLOR != "") 
      {
      FONT_PROPERTIES = FONT_PROPERTIES + " color='" + MyFONTCOLOR + "'";
      }
    if (FONT_PROPERTIES != "") 
      {
      FONT_PROPERTIES = "<FONT " + FONT_PROPERTIES + ">";
      }
    if (MyFONTSTYLE != "") 
      {
      FONT_PROPERTIES = "<" + MyFONTSTYLE + ">" + FONT_PROPERTIES;
      }    

    /**********************************************
    * Write Link if any.                          *
    **********************************************/
    if (LINK != "") 
      {
      document.write("</a>");
      }

    /**********************************************
    * Write Font Properties.                      *
    **********************************************/
    if (Menu[j][1] != "") 
      {
      if (FONT_PROPERTIES != "") 
        {
        document.write(FONT_PROPERTIES);
        }
      document.write(MySTARTCHAR);
      if (LINK != "") 
        {
        document.write(LINK);
        } 
      document.write(Menu[j][1]);       
      if (LINK != "") 
        {
        document.write("</a>");
        }
      if (FONT_PROPERTIES != "") 
        {
        document.write("</FONT>");
        } 
      if (MyFONTSTYLE != "") 
        {
        document.write("</" + MyFONTSTYLE + ">");
        }
      }

    /**********************************************
    * Close Align.                                *
    **********************************************/
    if  (MyHALIGN != "") 
      {
      document.write("</DIV>");
      }

    /**********************************************
    * Close layer.                                *
    **********************************************/
    document.writeln(Layer_End);
    }
  } 

/**********************************************
* Build Secondary Menu Items                  *
**********************************************/
function BuildMenuItems() 
  {
  /**********************************************
  * Netscape 4 Correction.                      *
  **********************************************/
  NS4XCorrection();
    
  /**********************************************
  * Initilize Position and MouseOver Variables. *
  **********************************************/
  for (var j=0; j<MaxMenuIndex; j++) 
    { 
    TOPLEFT[j] = new Array();
    Parent_Child_Count[j] = 0;
    MOUSEOVEROUT[j] = new Array(); 
    Parent_Children_ID[j] = new Array();  
    TOPLEFT[j][0] = 0;
    TOPLEFT[j][1] = 0;
    }   

  /**********************************************
  * Build Menu Items.                           *
  **********************************************/

  /**********************************************
  * Build Menu Border and font roll color       *
  * through CSS Stylesheet.                     *
  **********************************************/
  if (LayerBorderSize!="") 
    {
    document.writeln("<Style type=\"text/css\">");
    document.writeln(".CBORDER {");
    document.writeln(" width:" + WIDTH + "px;"); 
    document.writeln(" heigth:" + HEIGHT + "px;");  
    document.writeln(" border: " + LayerBorderStyle + " " + LayerBorderColor + " " + LayerBorderSize + "px;}\n"); 

    // Link and Roll Link Color
    if (FONTLINKCOLOR != "") 
      {
      if (DEBUG>1) alert ("FONTLINKCOLOR = "+FONTLINKCOLOR);
      document.writeln(".CBORDER A:link { color: " + FONTLINKCOLOR + "; text-decoration: " + DECORATION + ";}\n");
      }
    if (FONTLINKROLLCOLOR != "") 
      {
      if (DEBUG>1) alert ("FONTLINKROLLCOLOR = "+FONTLINKROLLCOLOR);
      } 
    document.writeln("\n</style>\n");
    }

  /**********************************************
  * Build each Menu.                            *
  **********************************************/
  for (i=0; i < MaxMenuIndex;i++) 
    {

    /**********************************************
    * Calculates Main Positions, visibility and   *
    * determines ID.                              *
    **********************************************/
    CalcLayerVariables(i); 

    /**********************************************
    * Global Properties.                          *
    **********************************************/
    var MyLayerColor = LayerColor;
    var MyLayerRollColor = LayerRollColor;
    var MyLayerBackground = LayerBackground
          
    // Roll Color  
    if (Main_Parent_LayerColor!="" ) 
      {
      MyLayerColor = Main_Parent_LayerColor;
      }   
 
    // Background Color
    if (Main_Parent_LayerBackground != "" ) 
      {
      MyLayerBackground = Main_Parent_LayerBackground;
      } 

    /**********************************************
    * Save Layer Code.                            *
    **********************************************/
    LAYER[i] = eval(Layer);           

    if (DEBUG>1) alert ("LAYER["+i+"] = "+LAYER[i]);
    }  // End of FOR

  /**********************************************
  * Add samelevel mouse events.                 *
  **********************************************/
  SameLevelMouseEvents(); 
 
  /**********************************************
  * Each Menu Item is built and written here.   *
  **********************************************/
  if (DEBUG>1) alert ("Main_Parent_FONTCOLOR = "+Main_Parent_FONTCOLOR);

  /**********************************************
  * Menu Item Font Properties.                  *
  **********************************************/
  for (var j=0; j<MaxMenuIndex; j++) 
    {
    var MyFONT = FONT;
    var MyFONTCOLOR = FONTCOLOR;
    var MyFONTSIZE = FONTSIZE;
    var MyFONTSTYLE = FONTSTYLE;
    var MySTARTCHAR = START_CHAR;
    var MyHALIGN = HALIGN;
 
    /**********************************************
    * Menu Parent/Children Font Properties.       *
    **********************************************/
    if (Main_Parent_FONT != "") 
      {
      MyFONT = Main_Parent_FONT;
      }  
    if (Main_Parent_FONTCOLOR != "") 
      {
      MyFONTCOLOR = Main_Parent_FONTCOLOR;
      }              
    if (Main_Parent_FONTSIZE != "") 
      {
      MyFONTSIZE = Main_Parent_FONTSIZE;
      }    
    if (Main_Parent_FONTSTYLE != "") 
      {
      MyFONTSTYLE = Main_Parent_FONTSTYLE;
      }  
    if (Main_Parent_START_CHAR != "") 
      {
      MySTARTCHAR = Main_Parent_START_CHAR;
      }
    if (Main_Parent_HALIGN != "") 
      {
      MyHALIGN = Main_Parent_HALIGN;
      }        

    /**********************************************
    * Menu Item MouseOver Out Functions.          *
    **********************************************/
    var MOUSEOVERCODE = "";
    var MOUSEOUTCODE = "";
    for (var jj=0; jj<MaxMenuIndex; jj++) 
      {
      if (MOUSEOVEROUT[j][jj] != null) 
        {
        MOUSEOVERCODE = MOUSEOVERCODE + "showHideLayers('" + MOUSEOVEROUT[j][jj] + "','','show');";
        MOUSEOUTCODE = MOUSEOUTCODE + "showHideLayers('" + MOUSEOVEROUT[j][jj] + "','','hide');";
        } 
      else 
        { 
        MOUSEOVERCODE = MOUSEOVERCODE + "PathRoad(" + j + ",1)";           
        MOUSEOUTCODE = MOUSEOUTCODE + "PathRoad(" + j + ",0)";          
        break;
        } 
      } 

    /**********************************************
    * Build Menu Item - Link.                     *
    **********************************************/
    mytarget = ""; 
    if (MenuItem[j][4] != "") 
      {
      mytarget = MenuItem[j][4];
      }
    document.write(LAYER[j] + " onMouseOver=\"" + MOUSEOVERCODE + "\" onMouseOut=\"" + MOUSEOUTCODE + "\">");               
    var LINK = "";      
    // display link if any
    if (MenuItem[j][3] != "") 
      {   
      LINK = "<A href=\"" + MenuItem[j][3] + "\"";
      if (mytarget != "") 
        {
        LINK = LINK + " target=\"" + mytarget + "\"";
        }
      LINK = LINK + " >"
      if (DEBUG>1) alert ("LINK = "+LINK);
      }

    /**********************************************
    * Build Menu Item Alignment.                  *
    **********************************************/
    if (MyHALIGN != "") 
      {
      document.write("<DIV ALIGN='"+MyHALIGN+"'>");
      } 

    /**********************************************
    * Build Fonts Properties.                     *
    **********************************************/
    var FONT_PROPERTIES = "";  
    if (MyFONT != "") 
      {
      FONT_PROPERTIES = " Face='" + MyFONT + "'";
      }
    if (MyFONTSIZE != "") 
      {
      FONT_PROPERTIES = FONT_PROPERTIES + " size='" + MyFONTSIZE + "'";
      }
    if (MyFONTCOLOR != "") 
      {
      FONT_PROPERTIES = FONT_PROPERTIES + " color='" + MyFONTCOLOR + "'";
      }
    if (FONT_PROPERTIES != "") 
      {
      FONT_PROPERTIES = "<FONT " + FONT_PROPERTIES + ">";
      }
    if (MyFONTSTYLE != "") 
      {
      FONT_PROPERTIES = "<" + MyFONTSTYLE + ">" + FONT_PROPERTIES;
      }    

    /**********************************************
    * Write Link if any.                          *
    **********************************************/
    if (LINK != "") 
      {
      document.write("</a>");
      }

    /**********************************************
    * Write Font Properties.                      *
    **********************************************/
    if (MenuItem[j][2] != "") 
      {
      if (FONT_PROPERTIES != "") 
        {
        document.write(FONT_PROPERTIES);
        }
      document.write(MySTARTCHAR);
      if (LINK != "") 
        {
        document.write(LINK);
        } 
      document.write(MenuItem[j][2]);       
      if (LINK != "") 
        {
        document.write("</a>");
        }
      if (FONT_PROPERTIES != "") 
        {
        document.write("</FONT>");
        } 
      if (MyFONTSTYLE != "") 
        {
        document.write("</" + MyFONTSTYLE + ">");
        }
      }

    /**********************************************
    * Close Align.                                *
    **********************************************/
    if  (MyHALIGN != "") 
      {
      document.write("</DIV>");
      }

    /**********************************************
    * Close layer.                                *
    **********************************************/
    document.writeln(Layer_End);
    }
  } 

/*******************************************************************************
* End of Menu Item.                                                            *
*******************************************************************************/


/*******************************************************************************
* Netscape 4 Correction Stuff.                                                 *
*******************************************************************************/
function NS4XCorrection() 
  {
  if (document.layers) 
    {
    Layer = "\"<layer class='CBORDER' id='\"+IDLABEL+\"' background='\"+MyLayerBackground+\"' position='absolute' visibility='\"+VISIBILITY+\"' left='\"+LEFT+\"' top='\"+TOP+\"' width='\"+WIDTH+\"' height='\"+HEIGHT+\"' bgcolor='\"+MyLayerColor+\"' z-index='\"+ZINDEX+\"'\" ";    
    Layer_End = "</layer>";
    }
  NS_Table_Width_Corr = 5;
  NS_Table_Heigth_Corr = 5;
  }

function NS4ImageCorrect(Index) 
  {
  var NS4FIX = "";
  if (document.layers) 
    {
    return "layers.Layer" + Menu[Index][1] + ".document.";
    }
  return ""; 
  }
  
/**********************************************
* Calculates Menu Item Position.              *
**********************************************/
function CalcLayerVariables(Index) 
  {
  var ID = Menu[Index][0];
  var MyDescription = "";

  // if Main Parent   
  if (ID == ID) 
    {   
    MyDescription = "Main Parent";
    // Menu Type  
    if (MENU_TYPE == 1) 
      {
      // Horizontal  
      TOP = TopParent; 
      LEFT = (Main_Parent_Count * (ORGWIDTH-2))+ LeftParent - (LayerBorderSize*Main_Parent_Count);  
      }
    else 
      {
      // Vertical
      TOP = (Main_Parent_Count * HEIGHT)+TopParent - (LayerBorderSize*Main_Parent_Count);
      LEFT = LeftParent;  
      }
    TOPLEFT[Index][0] = TOP;        
    TOPLEFT[Index][1] = LEFT;                   
    IDLABEL = "Layer" + Menu[i][0];        
    VISIBILITY = "visible";
    ZINDEX = 100; //on top of the first 99 layers in the page!
    WIDTH =((+ORGWIDTH)-(+LayerBorderSize));

    Main_Parent_Count++;                
    }
  else 
    {
    //Child
    MyDescription = "Child";
    //Find Parent        
    ChildofAParent = false;        
    var ParentIndex = 0; 
    for (var j=0; j<MaxMenuIndex; j++) 
      { 
      if (Menu[j][1] == Parent_ID) 
        {  
        //collecting Children of Parents 
        for (var g=0; g<MaxMenuIndex; g++) 
          {
          if (Parent_Children_ID[j][g] == null) 
            {
            Parent_Children_ID[j][g] = IDLABEL;
            break;
            }
          } 
        if (Menu[j][1] == Menu[j][0]) 
          {
          ChildofAParent = true;
          }
        ParentIndex = j; 
        break;
        }
      }
    
    //if child of a Main Parent and Menu Type is Horizental                        
    if (ChildofAParent && MENU_TYPE == 1) 
      {
      Parent_Child_Count[ParentIndex] = Parent_Child_Count[ParentIndex] + 1;                                   
      TOP = TopParent +(Parent_Child_Count[ParentIndex] * HEIGHT) - ((Parent_Child_Count[ParentIndex])*LayerBorderSize);
      LEFT = TOPLEFT[ParentIndex][1];                  
      WIDTH = ((+ORGWIDTH)-(+LayerBorderSize)) + WIDTH_OFFSET;
      ZINDEX = 101; //on top of the first 100 layers in the page!                  
      MyDescription = "Child of Parent";
      } 
    else 
      { 
      //if a child of a child  
      Parent_Child_Count[ParentIndex] = Parent_Child_Count[ParentIndex] + 1; 
      TOP = (TOPLEFT[ParentIndex][0]) + ((Parent_Child_Count[ParentIndex]-1) * HEIGHT) - ((Parent_Child_Count[ParentIndex]-1)*LayerBorderSize) + TOP_OFFSET;
      LEFT = (WIDTH + TOPLEFT[ParentIndex][1]) - LEFT_OFFSET - LayerBorderSize;               
      WIDTH = ((+ORGWIDTH) - (+LayerBorderSize)) + ORGWIDTHOFFSET;
      if (ChildofAParent) 
        {
        ZINDEX = 101;
        }
      else 
        {
        ZINDEX=102;
        } 
      //on top of the first 100 layers in the page,100 is Main Parent and 101 is Parent
      MyDescription = "Child of a Child";
      }        
    VISIBILITY = "hidden";  
    IDLABEL = "Layer" + Menu[Index][1];          
    TOPLEFT[Index][0] = TOP;                                              
    TOPLEFT[Index][1] = LEFT;
    }    
  }

/**********************************************
* Generates onMouseOver Event for same.       *
**********************************************/
function SameLevelMouseEvents() 
  {
	
  /**********************************************
  * 1 showHide Main Parent children.            *
  **********************************************/
  for (var u=0; u<MaxMenuIndex; u++)                           // FOR 1
    {
    for (var y=0; y<MaxMenuIndex; y++)                         // FOR 2 
      {
      // if not the one being tested and has the same parent
      if (y != u && (Menu[y][0] == Menu[u][1]))                // IF 1
        { 
        for (var z=0; z<MaxMenuIndex; z++)                     // FOR 3 
          {
          if (MOUSEOVEROUT[u][z] == null)                      // IF 2
            {
            MOUSEOVEROUT[u][z] = "Layer" + Menu[y][1];
            break;
            }                                                  // End of IF 2
          }                                                    // End of FOR 3
        }                                                      // End of IF 1
      }                                                        // End of FOR 2
    }                                                          // End of FOR 1

  /**********************************************
  * 2 show hide same Parent menu items.         *
  **********************************************/
  for (var u=0; u<MaxMenuIndex; u++)                           // FOR 1 
    {
    for (var z=0; z<MaxMenuIndex; z++)                         // FOR 2
      {
      if (MOUSEOVEROUT[u][z] == null)                          // IF 1
        {
        MOUSEOVEROUT[u][z] = "Layer" + Menu[u][1];
        break;
        }                                                      // End of IF 1
      }                                                        // End of FOR 2
    for (var y=0; y<MaxMenuIndex; y++)                         // FOR 3
      {
      // if not the one being tested and 
      // has the same parent and not the parent menu
      if (y!=u && (Menu[y][0] == Menu[u][0]) 
               && (Menu[y][1] != Menu[y][0]))                  // IF 2 
			  { 
        for (var z=0; z<MaxMenuIndex; z++)                     // FOR 4 
          {
          if (MOUSEOVEROUT[u][z] == null)                      // IF 3 
            {
            MOUSEOVEROUT[u][z] = "Layer" + Menu[y][1];
            break;
            }                                                  // End of IF 3
          }                                                    // End of FOR 4
        }                                                      // End of IF 2
      }                                                        // End of FOR 3
    }                                                          // End of FOR 1                                

  /**********************************************
  * 3 show hide children of non Main Parent.    *
  **********************************************/
  var same = "";
  for (var u=0; u<MaxMenuIndex; u++)                          // FOR 1
    {
    for (var y=0; y<MaxMenuIndex; y++)                        // FOR 2 
      {
      if ((Menu[u][1] == Menu[y][0]) && (Menu[y][1] 
                      != Menu[y][0]) && y!=u)                 // IF 1
        {
        for (var z=0; z<MaxMenuIndex; z++)                    // FOR 3 
          {
          if (MOUSEOVEROUT[u][z] == null)                     // IF 2 
            {
            MOUSEOVEROUT[u][z] = "Layer" + Menu[y][1];
            same = z;
            break;
            }                                                 // End IF 2
          }                 
          
        // Pass Parent's show hide to the children
        for (var z=0; z<MaxMenuIndex; z++)                    // FOR 4
          {
          if (MOUSEOVEROUT[u][z] != null)                     // IF 3
            {
            for (var x=0; x<MaxMenuIndex; x++)                // FOR 5 
              {
              if (MOUSEOVEROUT[y][x] == null)                 // IF 4 
                {
                MOUSEOVEROUT[y][x] = MOUSEOVEROUT[u][z];
                break;
                }                                             // End IF 4
              }                                               // End FOR 5
            }                                                 // End IF 3
          else 
            {
            break;
            }
          }                                                   // End FOR 4  
        }                                                     // End IF 1
      }                                                       // End of FOR 2
    }                                                         // End of FOR 1   
  }

/**********************************************
* Menu PathColor.                             *
**********************************************/
function PathRoad(Parent, flag) 
  {
  if (DEBUG>0) alert ("PathRoad("+Parent+", "+flag+")");
  AtStart = false;
  while (!AtStart) 
    {  
    // change layer color     
    if (flag == 1) 
      {    
      //Roll
      // Layer's Image: Browser Check 
      if (Main_Parent_LayerRollColor != "") 
        {
        MyLayerRollColor = Main_Parent_LayerRollColor;
        } 
      else 
        {
        MyLayerRollColor = LayerRollColor;
        }        
      
      // Layer Color: Browser Check 
      if (document.layers) 
        {
        if (DEBUG>0) alert ("752: eval comes out to ["+"changeProp('Layer" + Menu[Parent][0] + "','document.bgColor','" + MyLayerRollColor + "','LAYER')]");
        eval ("changeProp('Layer" + Menu[Parent][1] + "','document.bgColor','" + MyLayerRollColor + "','LAYER')");
        }
      else
        {
        if (document.getElementById || document.all) 
          {
          if (DEBUG>0) alert ("758: eval comes out to ["+"changeProp('Layer" + Menu[Parent][0] + "','document.bgColor','" + MyLayerRollColor + "','LAYER')]");
          eval ("changeProp('Layer" + Menu[Parent][0] + "','style.backgroundColor','" + MyLayerRollColor + "','DIV')");
          }
        }
      }
    else 
      {  
      // Origin Image and Color
      // Layer's Image: Browser Check 
      if (Main_Parent_LayerColor != "") 
        {
        MyLayerColor = Main_Parent_LayerColor;
        }
      else 
        {
        MyLayerColor = LayerColor;
        } 

      // Layer Color: Browser Check  
      if (document.layers) 
        {
        eval ("changeProp('Layer" + Menu[Parent][0] + "','document.bgColor','" + MyLayerColor + "','LAYER')");
        }
      else 
        {
        if (document.getElementById || document.all) 
          {
          eval ("changeProp('Layer" + Menu[Parent][0] + "','style.backgroundColor','" + MyLayerColor + "','DIV')");
          }
        }      
      }
    AtStart = true;
    Parent = INDEXof(Menu[Parent][0]);  
    }
  }

/*******************************************************************************
* Find the index of the Menu Array with the Parent: Parent.                    *
*******************************************************************************/
function INDEXof(Parent) 
  {
  for (var j=0; j<MaxMenuIndex; j++) 
    {
    if (Menu[j][1] == Parent) 
      {
      return (j);
      }  
    } 
  }

/******************************************************************************/
