//---------------------------------------------------------------
// dbgtData.js
// Copyright (C) 2002 David Bollinger (davebollinger@hotmail.com)
//
// Support code for the "dbGroupToc" modification - A grouped
// table of contents for ArcIMS 3.1 HTML viewer sites.
//
// Notice:   This code may be freely distributed, used and
//           modified provided that this comment remains intact.
//---------------------------------------------------------------


//
// create the global resource object
//
tocResource = new RESOURCE("");
tocResource.stringTitle = "LAYER";                     // text to display as title of toc
tocResource.imageWidth = 23;                            // width in pixels of icons/swatches
tocResource.imageHeight = 18;                           // height in pixels of icons/swatches
tocResource.groupSpacing = 10;                           // height in pixels of blank space between groups

tocResource.iconPath = "images/";                   // path to icon images

tocResource.iconPixel = "icon_pixel.gif";               // single transparent pixel
tocResource.iconBlank = "icon_blank.gif";               // all transparent placeholder
tocResource.iconClosed = "icon_closed.gif";             // closed group folder
tocResource.iconOpened = "icon_opened.gif";             // opened group folder
tocResource.iconChild = "icon_child.gif";               // connecting line to child layer
tocResource.iconChildLast = "icon_childlast.gif";        // connecting line to child layer for the last layer of group
//tocResource.iconOrphan = "icon_orphan.gif";             // non-connecting line to an orphan ("only child") layer
tocResource.iconHidden = "icon_hidden.gif";             // layer not visible, unselected checkbox
tocResource.iconVisible = "icon_visible.gif";           // layer visible, selected checkbox
tocResource.iconVisscale = "icon_visscale.gif";         // layer visible, but not at this scale
tocResource.iconTristate = "icon_tristate.gif";         // tri-state checkbox, some layers visible
tocResource.iconActive = "icon_active.gif";             // selected radio
tocResource.iconInactive = "icon_inactive.gif";         // unselected radio
//tocResource.iconInfo = "icon_info.gif";                 // for displayLayerInfoButton
//tocResource.iconHelp = "icon_help.gif";                 // not currently used

//INIZIO Profilazione TOC - PTO
//Funzione che permette la visibilità di un determinato gruppo all'interno della TOC
//Viene gestita anche la visibilità dei layer presenti all'interno dell'AXL e settati
//per default a false (e cioè non visibili)
function getCommandGroupParams(cmdString,groupName,verifica)
    {
     var bTrovato = false;
     if (verifica)
      {

       var startpos = 0;
       var endpos = 0;

       var cmdString2 = unescape(cmdString.toUpperCase());
        pos = cmdString2.indexOf("GROUP=");
       if (pos!=-1)
          {
          startpos = pos + 6;
          endpos = cmdString.indexOf("&",startpos);
          if (endpos==-1) endpos = cmdString.length;

          var escGroup = unescape(cmdString.substring(startpos,endpos));
          var separator="|";
          var arrayOfStrings = escGroup.split(separator);

          var indice = 0;

          while (indice<arrayOfStrings.length && bTrovato==false)
                {
//alert("arrayOfStrings[indice]= " + arrayOfStrings[indice] + "\ngroupName.slice(9)= " + groupName.slice(9));
                    if ( arrayOfStrings[indice] == groupName.slice(9) )
                    {
                        bTrovato=true;
                    }
                    indice++;
                }

          return bTrovato    //Il Gruppo deve essere visualizzato nella TOC
          }
      }
      else
        {
        bTrovato = true;
        return bTrovato;
        }
    }
//FINE Profilazione TOC - PTO

//=======================================================================================

//Inizio NewToc : NTO
// Gestione array di toc
//var toc = new TOC("Toc_modificata");
var toc = new Array()
toc[0] = new TOC("Toc_modificata");
toc[1] = new TOC("Toc Secondaria");
var toc_csi_tocIndex=0;
//Fine NewToc : NTO


/* #################################################
##                                                ##
##  INSERIMENTO DELLA TOC                         ##
##                                                ##
##  L'ORDINE DI INSERIMENTO NELL'ARRAY            ##
##    E' LO STESSO DI QUELLO                      ##
##    DI VISUALIZZAZIONE                          ##
##                                                ##
##################################################*/
// NOTA: il nome delle variabili GRPx non é importante;
// é importante che non siano definite 2 volte,
// ma possono essere inserite nell'array in qualsiasi ordine


// ----------------------------------------------------------
// add a group to the toc
// usage reminder:  GROUP( name_of_group, startup_opened )
// ----------------------------------------------------------
if ( getCommandGroupParams(webParams,"Dati di base",false) ){
var grp0 = toc[0].addGroup(new GROUP("Dati di base",true) );
//
// add layers to the group
// usage reminder:  LAYER( name_of_layer)
//
if ( getCommandGroupParams(webParams,"Regione",false) )
        grp0.addLayer( new LAYER("Regione") );

if ( getCommandGroupParams(webParams,"Province",false) )
        grp0.addLayer( new LAYER("Province") );

if ( getCommandGroupParams(webParams,"Comuni",false) )
        grp0.addLayer( new LAYER("Comuni") );

if ( getCommandGroupParams(webParams,"Idrografia lineare",false) )
	grp0.addLayer( new LAYER("Idrografia lineare") );

if ( getCommandGroupParams(webParams,"Idrografia poligonale",false) )
        grp0.addLayer( new LAYER("Idrografia poligonale") );
        
if ( getCommandGroupParams(webParams,"Aree urbanizzate",false) )
        grp0.addLayer( new LAYER("Aree urbanizzate") );
        
if ( getCommandGroupParams(webParams,"CTR Raster",false) )
        grp0.addLayer( new LAYER("CTR Raster") );

        
        
        }



// ----------------------------------------------------------
// add a group to the toc
// usage reminder:  GROUP( name_of_group, startup_opened )
// ----------------------------------------------------------
if ( getCommandGroupParams(webParams,"Dati tematici",false) ){
var grp1 = toc[0].addGroup(new GROUP("Dati tematici",true) );
//
// add layers to the group
// usage reminder:  LAYER( name_of_layer)
//
	
if ( getCommandGroupParams(webParams,"Grafo Viabilita'",false) )
	grp1.addLayer( new LAYER("Grafo Viabilita'") );
	
if ( getCommandGroupParams(webParams,"Grafo Ferroviario",false) )
	grp1.addLayer( new LAYER("Grafo Ferroviario") );
	
if ( getCommandGroupParams(webParams,"Nuovi interventi della viabilita'",false) )
	grp1.addLayer( new LAYER("Nuovi interventi della viabilita'") );
			
if ( getCommandGroupParams(webParams,"Svincoli",false) )
	grp1.addLayer( new LAYER("Svincoli") );

if ( getCommandGroupParams(webParams,"Nodi OMNIBUS Viabilita'",false) )
	grp1.addLayer( new LAYER("Nodi OMNIBUS Viabilita'") );

if ( getCommandGroupParams(webParams,"Nodi Stradali",false) )
	grp1.addLayer( new LAYER("Nodi Stradali") );
		
if ( getCommandGroupParams(webParams,"Nodi Ferroviari",false) )
	grp1.addLayer( new LAYER("Nodi Ferroviari") );	
	
if ( getCommandGroupParams(webParams,"Localizzazione incidenti 2000",false) )
	grp1.addLayer( new LAYER("Localizzazione incidenti 2000") );
	
if ( getCommandGroupParams(webParams,"Attrazione di spostamenti 1991",false) )
	grp1.addLayer( new LAYER("Attrazione di spostamenti 1991") );
	
if ( getCommandGroupParams(webParams,"Generazione di spostamenti 1991",false) )
	grp1.addLayer( new LAYER("Generazione di spostamenti 1991") );
	
if ( getCommandGroupParams(webParams,"Spostamenti intra-comunali 1991",false) )
	grp1.addLayer( new LAYER("Spostamenti intra-comunali 1991") );

}


// ----------------------------------------------------------

/////////////////////////////////////////////////////MAD; + [AP]



