var livelloRiservato = 0;
var riservata = false;

//*********** mappa del sito *********************
//*** viene stampato un elenco completo        ***
//*** ad albero delle voci del sito            ***
//************************************************

function mappaSito()
{ 
     var inizioLivello2 = false;
     var inizioLivello3 = false;
     var inizioLivello4 = false;
     var interlinea_sx = "<img src=\"http://www.abi.it/images/sitemap_interlinea_sx.gif\" width=\"22\" height=\"17\" border=\"0\">";
     var interlinea_center = "<img src=\"http://www.abi.it/images/sitemap_interlinea_center.gif\" width=\"82\" height=\"17\" border=\"0\">";
     var interlinea_dx = "<img src=\"http://www.abi.it/images/sitemap_interlinea_dx.gif\" width=\"496\" height=\"17\" border=\"0\">";
     var sitemapColonnaFreccia = "<img src=\"http://www.abi.it/images/sitemap_colonna_freccia.gif\" width=\"25\" height=\"12\" border=\"0\">";   // determina la altezza della cella + freccia
     var sitemapColonnaFine = "<img src=\"http://www.abi.it/images/sitemap_colonna_fine.gif\" width=\"25\" height=\"6\" border=\"0\">";          // angolo finale della linea verticale
     var InterlineaFinePar = "<img src=\"http://www.abi.it/images/ghost.gif\" width=\"1\" height=\"16\" border=\"0\">";                          // interlinea della fine dei paragrafi
     if (screen.colorDepth<=8){
     var bkgCelle = "http://www.abi.it/images/sitemap_colonna_256.jpg";
     var sitemapColonnaInterlinea = "<img src=\"http://www.abi.it/images/sitemap_colonna_256.jpg\" width=\"25\" height=\"12\" border=\"0\">"
     }
     else{
     var bkgCelle = "http://www.abi.it/images/sitemap_colonna.jpg";
     var sitemapColonnaInterlinea = "<img src=\"http://www.abi.it/images/sitemap_colonna.jpg\" width=\"25\" height=\"12\" border=\"0\">";}        // determina la altezza della cella
     var fineColonna = "<td>"+sitemapColonnaFine+"</td><td width=\"131\">"+InterlineaFinePar+"</td>";
     var inizioCampoLabel = "<td background=\""+bkgCelle+"\">"+sitemapColonnaFreccia+"</td><td width=\"131\">";
     var inizioCampoLabel2 = "<td background=\""+bkgCelle+"\">"+sitemapColonnaInterlinea+"</td><td width=\"131\">";
     var fineCampoLabels = "</td>";

     for (k=0; k<theSiteMap.length; k++)
     {
          if ((theSiteMap[k][1] > 0) && ((theSiteMap[k][0].charAt(0) == "0")||(theSiteMap[k][0].charAt(0)+theSiteMap[k][0].charAt(1)+theSiteMap[k][0].charAt(2) == "200")||(theSiteMap[k][0].charAt(0)+theSiteMap[k][0].charAt(1)+theSiteMap[k][0].charAt(2) == "100")))
          {
               //*** primo livello ***//

               if (theSiteMap[k][1] == "1")
               {
                   
                    document.write(InterlineaFinePar+
                    "<table width=\"600\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"inist\">"+
                    "<tr valign=\"top\">"+
                    "<td>"+interlinea_sx+"</td>"+
                    "<td>"+interlinea_center+"</td>"+
                    "<td>"+interlinea_dx+"</td>"+
                    "</tr>"+
                    "<tr valign=\"top\">"+
                    "<td></td>"+
                    "<td>");
                    stampaLabel(k);
                    document.write("  </td>");
                    document.write("  <td>");

                    //*** secondo livello ***//

                    if (theSiteMap[k+1][1] == "2")
                    {
                         document.write(" <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"inist\">");
                         inizioLivello2 = true;
                         for (h=k+1; h<theSiteMap.length; h++)
                         {
                              if (theSiteMap[h][1] <= livelloRiservato)
                              {
                                   riservata = false;
                              }
                              document.write("<tr valign=\"top\">");
                              if (inizioLivello2)
                              {
                                   document.write(inizioCampoLabel);
                                   stampaLabel(h);
                                   document.write(fineCampoLabels);
                                   inizioLivello2 = false;
                              }
                              else if ((theSiteMap[h][1] < 2) || (theSiteMap[h][1] > 2))
                              {
                                   document.write(fineColonna);
                                   k = h-1;
                                   h = theSiteMap.length;
                              }
                              else //if (!(theSiteMap[h][1] > 2))
                              {
                                   document.write(inizioCampoLabel2);
                                   stampaLabel(h);
                                   document.write(fineCampoLabels);
                              }
                              document.write(" <td>");

                              //*** terzo livello ***//

                              if (h < theSiteMap.length)
                              {
                                   if (theSiteMap[h+1][1] == "3")
                                   {
                                        //**condizione per commissioni**

                                        idComm = theSiteMap[h+1][0].charAt(0)+theSiteMap[h+1][0].charAt(1)+theSiteMap[h+1][0].charAt(2);
                                        if ((idComm == "0_7") && (theSiteMap[h+1][1] > 2))
                                        {
                                             for (y=h+1; y<theSiteMap.length; y++)
                                             {
                                                  if (theSiteMap[y][1] == 2)
                                                  {
                                                       h = y-1;
                                                       y = theSiteMap.length;
                                                  }
                                             }
                                        }

                                        //**fine condizione per commissioni**

                                        else
                                        {
                                             document.write(" <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"inist\">");
                                             inizioLivello3 = true;
                                             for (y=h+1; y<theSiteMap.length; y++)
                                             {
                                                  if (theSiteMap[y][1] <= livelloRiservato)
                                                  {
                                                       riservata = false;
                                                  }
                                                  document.write("<tr valign=\"top\">");
                                                  if (inizioLivello3)
                                                  {
                                                       document.write(inizioCampoLabel);
                                                       stampaLabel(y);
                                                       document.write(fineCampoLabels);
                                                       inizioLivello3 = false;
                                                  }
                                                  else if (theSiteMap[y][1] < 3)
                                                  {
                                                       document.write(fineColonna);
                                                       h = y-1;
                                                       y = theSiteMap.length;
                                                  }
                                                  else
                                                  {
                                                       document.write(inizioCampoLabel2);
                                                       stampaLabel(y);
                                                       document.write(fineCampoLabels);
                                                  }
                                                  document.write(" <td>");

                                                  //*** quarto livello ***//

                                                  if (y < theSiteMap.length)
                                                  {
                                                       if (theSiteMap[y+1][1] == "4")
                                                       {
                                                            document.write(" <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"inist\">");
                                                            inizioLivello4 = true;
                                                            for (x=y+1; x<theSiteMap.length; x++)
                                                            {
                                                                 if ((x < theSiteMap.length) && (theSiteMap[x][1] <= 4))
                                                                 {
                                                                           if (theSiteMap[x][1] <= livelloRiservato)
                                                                           {
                                                                                riservata = false;
                                                                           }
                                                                           document.write("<tr valign=\"top\">");
                                                                           if (inizioLivello4)
                                                                           {
                                                                                document.write(inizioCampoLabel);
                                                                                stampaLabel(x);
                                                                                document.write(fineCampoLabels);
                                                                                inizioLivello4 = false;
                                                                           }
                                                                           else if (theSiteMap[x][1] < 4)
                                                                           {
                                                                                document.write(fineColonna);
                                                                                y = x-1;
                                                                                x = theSiteMap.length;
                                                                           }
                                                                           else
                                                                           {
                                                                                document.write(inizioCampoLabel2);
                                                                                stampaLabel(x);
                                                                                document.write(fineCampoLabels);
                                                                           }
                                                                           //document.write(" <td>");
                                                                 }
                                                                 //document.write(" </td>");
                                                                 document.write("</tr>");
                                                            }
                                                            document.write(" </table>");
                                                       }
                                                  }
                                                  //*** fine quarto livello ***//

                                                  document.write(" </td>");
                                                  document.write("</tr>");
                                             }
                                             document.write(" </table>");
                                        }
                                   }
                              }
                              //*** fine terzo livello ***//
                              document.write(" </td>");
                              document.write("</tr>");
                         }
                         document.write(" </table>");
                    }
                    //*** fine secondo livello ***//
                    document.write("  </td>");
                    document.write(" </tr>");
                    document.write("</table>");
               }
               //*** fine primo livello ***//
          }
     }
}

//*********** stampa label ************************
//*** viene stampata la voce della mappa        ***
//************************************************

function stampaLabel(idLabel)
{
     var lock = "<img src=\"http://www.abi.it/images/sitemap_lucchetto.gif\" width=\"12\" height=\"12\" border=\"0\" alt=\"\">";  // lucchetto

     if (theSiteMap[idLabel][3] == "*")
     {
          document.write("<span class=\"istitutionalight\">"+theSiteMap[idLabel][2] + lock + "</span>");
          livelloRiservato = theSiteMap[idLabel][1];
          riservata = true;
     }
     else if (riservata)
     {
          document.write("<span class=\"istitutionalight\">"+theSiteMap[idLabel][2] + lock + "</span>");
     }
     else
     {
          document.write("<a href=\"" + theSiteMap[idLabel][3] + "\" target=\"" + theSiteMap[idLabel][4] + "\" class=\"istitutional\" ");
          document.write(">");
          document.write(theSiteMap[idLabel][2] + "</a>");
     }
}

