//Variáveis globais

flg = false;

lista_sub = new Array();

Intervalo = 0;

mOver = false;

function abre_link(caminho, id)
  {

    if (id != undefined)
      {

        document.frm1.action = 'index.php?id=' + id;

      }
    else
      {

        document.frm1.action = 'index.php?id=0';

      }

    document.frm1.hp.value = caminho;

    document.frm1.submit();

  }


function fecha_sub(obj)
  {
    if ((flg) && (!mOver))
      {

        clearInterval(Intervalo);

        obj.style.visibility = 'hidden';

        flg = false;

      }
    else
      {

        flg = true;

      }

  }

function fecha_todos()
  {

    clearInterval(Intervalo);

    cont = lista_sub.length;

    for (i = 0; i < cont; i++)
      {

        obj = document.getElementById(lista_sub[i]);

        obj.style.visibility = 'hidden';

      }

  }

function abre_fecha(flag, layer, args, menu)
  {

    //flag = 0; MouseOver
    //flag = 1; MouseOut

    tempo = args[18];

    tempo = tempo * 1000;

    tempo = (tempo / 2);

    lyr = document.getElementById(layer);

    if (flag == 0)
      {

        fecha_todos();

        if (navigator.appName != "Microsoft Internet Explorer")
          {

            lyr.style.marginLeft = menu.offsetLeft;

            lyr.style.marginTop = menu.offsetTop;

          }

        lyr.style.visibility = 'visible';

      }
    else
      {

        Intervalo = setInterval("fecha_sub(lyr)", tempo);

      }

  }

function muda_propriedades(flag, objeto, args)
  {

    //flag = 0; MouseOver
    //flag = 1; MouseOut

    if (flag == 0)
      {

        objeto.style.background = args[8];
        objeto.style.color = args[6];

      }
    else
      {

        objeto.style.background = args[7];
        objeto.style.color = args[5];

      }

  }

function muda_prop_sub(flag, obj, args)
  {

    //flag = 0; MouseOver
    //flag = 1; MouseOut

    objeto = document.getElementById(obj);

    if (flag == 0)
      {

        objeto.style.background = args[8];
        objeto.style.color = args[6];

      }
    else
      {

        objeto.style.background = args[7];
        objeto.style.color = args[5];

      }

  }


function Escreve_Menu(menu, args, celula)
  {

    tamanho = args[2];

    l = args[1];

    t = args[0];

    cont = menu.length;

    k = 0;

    tabela = '';

    tam = l;

    celu = document.getElementById(celula);

      if (menu[0][2] == 1)
        {

          mn = " <label onMouseOut='muda_propriedades(1, this, args); abre_fecha(1, \"sub_layer" + i + "\", args, this)' onMouseOver='muda_propriedades(0, this, args); abre_fecha(0, \"sub_layer" + i + "\", args, this)' Style='Font-Weight: " + args[10] + "; Background: " + args[7] + "; Color: " + args[5] + "; Font-Size: " + args[4] + "; Font-Family: " + args[3] + "; Text-Align: " + args[9] + "; Cursor: Pointer;' id='menu" + 0 + "' name='menu" + 0 + "'>" + menu[0][0] + "</label>";

          lista_sub[k] = "sub_layer0";

          k++;

          tabela = '<div onMouseOver="mOver = true" onMouseOut="mOver = false" Style="Position: absolute; Visibility: hidden; Width: ' + args[19] + 'px; margin-left: ' + (tam - 10) + 'px; margin-top: ' + (t + 25) + 'px; Width: ' + args[19] + 'px;" id="sub_layer0">';

          tabela += '  <div Class="Content" width="100%" onMouseOver="muda_prop_sub(0, \"sub_layer0\", args)" onMouseOut="muda_prop_sub(1, \"sub_layer0\", args)">';

          tabela += '      <table width="100%" height="100%" border="' + args[11] + '" cellspacing="0" cellpadding="0">';

          tabela += '        <tr><td Style="Border-Bottom-Color: #D4D4D4; Border-Bottom-Width: 1px; Border-Bottom-Style: dotted;" id="sub_item00" align="' + args[9] + '">';

          tabela += '          <label Style="Cursor: Pointer" onMouseOver="muda_prop_sub(0, \'sub_item00\', args)" onMouseOut="muda_prop_sub(1, \'sub_item00\', args)">' + sub_item[0][0] + '</label>';

          tabela += '        </tr></td>';

          tabela += '      </table>';

          tabela += '    </div>';

          tabela += '</div>';

        }
      else
        {

           mn = " <label onMouseOut='muda_propriedades(1, this, args);' onMouseOver='muda_propriedades(0, this, args); fecha_todos();' Style='Font-Weight: " + args[10] + "; Background: " + args[7] + "; Color: " + args[5] + "; Font-Size: " + args[4] + "; Font-Family: " + args[3] + "; Text-Align: " + args[9] + "; Cursor: Pointer;' id='menu" + 0 + "' name='menu" + 0 + "' onClick='abre_link(\"" + menu[0][1] + "\")'>" + menu[0][0] + "</label>";

        }

    celu.innerHTML += mn + '&nbsp;&nbsp;';

    if ((tabela != undefined) || (tabela != "") || (tabela != " "))
      {

        celu.innerHTML += tabela;

      }


    for (i = 1; i < cont; i++)
      {


        c = i - 1;

        obj = document.getElementById('menu' + (c));

        tam += (obj.offsetWidth + tamanho);

        if (menu[i][2] == 1)
          {

            mn = " <label onMouseOut='muda_propriedades(1, this, args); abre_fecha(1, \"sub_layer" + i + "\", args, this)' onMouseOver='muda_propriedades(0, this, args); abre_fecha(0, \"sub_layer" + i + "\", args, this)' Style='Font-Weight: " + args[10] + "; Background: " + args[7] + "; Color: " + args[5] + "; Font-Size: " + args[4] + "; Font-Family: " + args[3] + "; Text-Align: " + args[9] + "; Cursor: Pointer;' id='menu" + i + "' name='menu" + i + "'>" + menu[i][0] + "</label>";

            lista_sub[k] = "sub_layer" + i;

            k++;

            sub_item = new Array();

            sub_item = menu[i][1];

            tabela = '<div onMouseOver="mOver = true;" onMouseOut="mOver = false;" Style="Position: absolute; Visibility: hidden; margin-left: 0px; margin-top: ' + (t - 50) + 'px; Width: ' + args[19] + 'px;" id="sub_layer' + i + '">';

            cnt = sub_item.length;

            tabela += '    <div width="100%" class="content">';

            tabela += '      <table width="100%" height="100%" border="' + args[11] + '" cellspacing="0" cellpadding="2">';

            for (j = 0; j < cnt; j++)
              {

                if (j == (cnt - 1))
                  {
                    w = 0;
                  }
                else
                  {
                    w = 1;
                  }

                lnk = new Array();

                lnk = menu[i][1];

                tabela += '      <tr><td Style="Border-Bottom-Color: #D4D4D4; Border-Bottom-Width: ' + w + 'px; Border-Bottom-Style: none; Color: ' + args[13] + '; Font-Family: ' + args[14] + '; Font-Size: ' + args[15] + 'px;" align="' + args[9] + '" id="sub_item' + i + j + '">';

                tabela += '        &nbsp;<label id="sub_label' + i + j + '" onClick="abre_link(\'' + lnk[j][1] + '\')" Style="Cursor: Pointer" onMouseOver="muda_prop_sub(0, \'sub_item' + i + j + '\', args)" onMouseOut="muda_prop_sub(1, \'sub_item' + i + j + '\', args)">' + sub_item[j][0] + '</label>&nbsp;';

                tabela += '      </td></tr>';


              }

            tabela += '      </table>';

            tabela += '  </div>';

            tabela += '</div>';

            celu.innerHTML += tabela;

            antigo = 0;

            for (j = 0; j < cnt; j++)
              {

                obj2 = document.getElementById('sub_label' + i + j);

                novo = obj2.offsetWidth;

                if (novo > antigo)
                  {

                    antigo = novo;

                  }

              }

            incremento = 30;

            obj2 = document.getElementById('sub_layer' + i);

            obj2.style.width = antigo + incremento;

          }
        else
          {

             mn = " <label onMouseOut='muda_propriedades(1, this, args);' onMouseOver='muda_propriedades(0, this, args); fecha_todos();' Style='Font-Weight: " + args[10] + "; Background: " + args[7] + "; Color: " + args[5] + "; Font-Size: " + args[4] + "; Font-Family: " + args[3] + "; Text-Align: " + args[9] + "; Cursor: Pointer;' id='menu" + i + "' name='menu" + i + "' onClick='abre_link(\"" + menu[i][1] + "\")'>" + menu[i][0] + "</label>";

          }


        celu.innerHTML += mn + '&nbsp;&nbsp;';

      }

  }