// Global index variable.

var treeMenuIndex = 0;

// Constructor.
  this.expanded    = false;

function TreeMenuItem(text, url, target, icon, url2,  plus) {

  this.text = text;
  this.url = url ? url : "";
  this.target =  target ? target : "";
  this.icon = icon ? icon : "";
  this.url2 = url2 ? url2 : "";
  this.plus = plus ? plus : "";

  this.expanded    = false;

  this.submenu = null;
  this.index = treeMenuIndex++;
  this.makeSubmenu = TreeMenuMakeSubmenu;
}
 

// Methods.

function TreeMenuMakeSubmenu(menu) {

  this.submenu = menu;
}


function TreeMenu() {

  this.items = new Array();
  this.addItem = treeMenuAddItem;
}

// Methods.

function treeMenuAddItem(item) {

  this.items[this.items.length] = item;
}


var treeMenuDocument;       // Handle to the menu frame document.
var treeMenuWidth;          // Menu width in pixels.
var treeMenuExpand;         // Array created from first cookie.
var treeMenuSelected;       // Index of selected menu item from other cookie.
var treeMenuSelectedFound;  // Indicates if we've displayed the selected item.
var treeMenuScrollX;        // Amount to scroll the window right, if needed.
var treeMenuScrollY;        // Amount to scroll the window down, if needed.
var treeMenuLastItem;       // Flag indicating if we are on a menu's last item.
var treeMenuDepth;          // Keeps track the current menu level.
var treeMenuBars;           // Keeps track of image placement from row to row.




//x le udienze
var treeMenucodice;

treeMenucodice="'"
//fine

//----------------------------------------------------------------------------
// This function rewrites the menu document to display the menu.
//----------------------------------------------------------------------------

function treeMenuDisplay() {
  tgt=-1;

  var i, cookie;

  // Check for cookies with the menu state data. If not found, or if the menu
  // state has not been set, initialize it.

  cookie = getCookie(treeMenuName);
  if (!cookie) {
    if (!treeMenuExpand) {
      treeMenuExpand = new Array();
      for (i = 0; i < treeMenuIndex; i++)
        treeMenuExpand[i] = 0;
      treeMenuSelected = -1;
    }
  }
  else {
    treeMenuExpand = cookie.split(",");
    cookie = getCookie(treeMenuName + "-selected");
    if (!cookie)
      treeMenuSelected = -1;
    else
      treeMenuSelected = cookie;
  }

  // Set up reference to the menu document.

  treeMenuDocument = window.frames[treeMenuFrame].document;

  // Set global variables used to draw the menu.

  treeMenuDepth = 0;
  treeMenuBars = new Array();

  // Intialize scrolling data.

  treeMenuSelectedFound = false;
  treeMenuScrollX = 36;
  treeMenuScrollY = 18;

  // Draw the menu.

  if (document.images)
    treeMenuDocument.open("text/html", "replace");
  else
    treeMenuDocument.open("text/html");
  treeMenuDocument.writeln('<head>');

  treeMenuDocument.writeln('<title>' + treeMenuRoot + '</title>');
//x le udienze

 // treeMenuDocument.writeln('<script> function esempio(str) {    searchWin = window.open(str,'esempio','fullscreen=no,scrollbars=no,resizable=no,width=240,height=185,leftmargin=0, topmargin=0 ,marginwidth=0, marginheight=0,status=no,location=no,toolbar=no,fullscreen=0 } </script>');
treeMenuDocument.writeln('<script language="JavaScript">');
treeMenuDocument.writeln('function esempio(str) {');
treeMenuDocument.writeln('newwindow=window.open(str,"","width=400,height=350,alwaysLowered=0,alwaysRaised=1,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=0,location=0,menubar=0,resizable=0,status=0,titlebar=0,toolbar=0,z-lock=0")');
treeMenuDocument.writeln('newwindow.focus();');
treeMenuDocument.writeln('newwindow.creator=self');

treeMenuDocument.writeln('}');
treeMenuDocument.writeln('</script>');

//fine

  treeMenuDocument.writeln('<style type="text/css">a {text-decoration:none;}</style>');
  treeMenuDocument.writeln('</head>');
  treeMenuDocument.writeln('<body background="images/palazzospada1sfondo.jpg" bgcolor="' + treeMenuBgColor + '" text="' + treeMenuFgColor + '" link="' + treeMenuFgColor + '" alink="' + treeMenuFgColor + '" vlink="' + treeMenuFgColor + '" onLoad="parent.treeMenuScroll();">');
  treeMenuDocument.writeln('<table border=0 cellpadding=0 cellspacing=0>');
  
  treeMenuListItems(treeMenu);
  treeMenuDocument.writeln('</table>');

treeMenuDocument.writeln('<A HREF="mailto:webmaster@giustizia-amministrativa.it"><IMG src="images/mailto.gif" alt="Esclusivamente per problemi di carattere tecnico" border=0></A>');  


/////////////////////////////////////////////////////////////////////////////////////////////////////////////
treeMenuDocument.writeln('<br><A HREF="link.htm" target="mainFrame"><IMG src="images/altrisiti.gif" alt="Link" border=0></A>');  

treeMenuDocument.writeln('<br><A HREF="orgright.htm" target="mainFrame"><IMG src="images/homeini.gif" alt="Home" border=0></A>');  


////////////////////////////////////////////////////////////////////////////////////////////////////////7////////
  
 ///
 treeMenuDocument.writeln('<br>');
 treeMenuDocument.writeln('<br>');
 treeMenuDocument.writeln('<A target="_blank" HREF="https://secure.dcssoftwareeservizisrl.it/consigliodistato/login.jsp"><IMG src="images/lucchetto2.gif" width="16" height="22" alt="Area Riservata Avvocati" border=0><font face="Comic Sans MS" color="#663300" size="2" ><b> Area Riservata Avvocati  </font></b> </A>');
 /// 
  
  
  
//pezzo da inserire dovrebbe essere cosė
  treeMenuDocument.writeln('<br>');
  treeMenuDocument.writeln('<br>');
//  treeMenuDocument.writeln('<br>');
//  treeMenuDocument.writeln('<br>');
//  treeMenuDocument.writeln('<TABLE style="WIDTH: 70px; HEIGHT: 20px" width=220 border=0>');
//  treeMenuDocument.writeln('<tr>');
//  treeMenuDocument.writeln('<td>');

//x le udienze
//da rimettere x discussione
/* 28/11/2008 Commentato da Presidio  CED per  rimuovere link non  utilizzati su richiesta di CdS
treeMenuDocument.writeln('<IMG src ="images/discuss.gif" border=0><br>');

treeMenuDocument.writeln('<a href="javascript:esempio(' + treeMenucodice + 'discussione/html.asp?sigla=CDS' + treeMenucodice + ');" onmouseover="window.status=' + treeMenucodice + 'Giustizia Amministrativa Home Page' + treeMenucodice + '; return true"><b><IMG src ="images/cdssigla.gif" border=0></b></A><br>')
treeMenuDocument.writeln('<a href="javascript:esempio(' + treeMenucodice + 'discussione/html.asp?sigla=RM&tar=Roma&regione=Lazio' + treeMenucodice + ');" onmouseover="window.status=' + treeMenucodice + 'Giustizia Amministrativa Home Page' + treeMenucodice + '; return true"><b><IMG src ="images/rmsigla.gif" border=0></b></A><br>')
treeMenuDocument.writeln('<a href="javascript:esempio(' + treeMenucodice + 'discussione/html.asp?sigla=MI&tar=Milano&regione=Lombardia' + treeMenucodice + ');" onmouseover="window.status=' + treeMenucodice + 'Giustizia Amministrativa Home Page' + treeMenucodice + '; return true"><b><IMG src ="images/misigla.gif" border=0></b></A><br>')
*/
//fine discussione


// treeMenuDocument.writeln('</td>');
// treeMenuDocument.writeln('</tr>');


 //treeMenuDocument.writeln('<tr>');
 //treeMenuDocument.writeln('<td>');

//fine

//  treeMenuDocument.writeln('</td>');
//  treeMenuDocument.writeln('</tr>');
//  treeMenuDocument.writeln('</table>');

//  treeMenuDocument.writeln('<br>');
  //treeMenuDocument.writeln('<br>');
  //treeMenuDocument.writeln('<TABLE style="WIDTH: 190px; HEIGHT: 50px" cellSpacing=1 cellPadding=1 width=220 border=0>');
  //treeMenuDocument.writeln('<tr>');
  //treeMenuDocument.writeln('<td>');
  
   
  //treeMenuDocument.writeln('<IMG src="images/motore1_ric.gif" border=0>');
  //treeMenuDocument.writeln('</table>');

  //treeMenuDocument.writeln('<IMG src ="images/esclusiv.gif" border=0>');
//  treeMenuDocument.writeln('<tr>');
//  treeMenuDocument.writeln('<td>');
  //treeMenuDocument.writeln('<A HREF="mailto:webmaster@giustizia-amministrativa.it"><IMG src="images/mailto.gif" border=0></A>');
//  treeMenuDocument.writeln('<br>');
  treeMenuDocument.writeln('<A HREF="avviso.htm" target="new"><IMG src="images/avviso.gif" border=0></A>');
  //fine
  
  
  treeMenuDocument.writeln('</body>');
  treeMenuDocument.close();
}

function treeMenuListItems(menu) {

  var i;

  for (i = 0; i < menu.items.length; i++) {
    if (i == menu.items.length - 1)
      treeMenuLastItem = true;
    else
      treeMenuLastItem = false;
    treeMenuDisplayItem(menu.items[i]);
  }
}

//----------------------------------------------------------------------------
// This displays a single menu or submenu item.
//----------------------------------------------------------------------------

function treeMenuDisplayItem(item) {

  var bars, cmd, expanded, i, img, alt, link, more, link2, submenu ;

  // Update vertical scrolling amount until we find the selected item.

  if (item.index == treeMenuSelected)
    treeMenuSelectedFound = true;
  if (!treeMenuSelectedFound)
    treeMenuScrollY += 18;

  
  
  if (treeMenuExpand[item.index] == 1)
    expanded = true;
  else
    expanded = false;

  if (item.submenu)
    submenu = true;
  else
    submenu = false;
  if (item.url != "")
    link = true;
  else
    link = false;
    if (item.plus == "1")
    link2 = true;
  else
    link2 = false;
    
  cmd = "return parent.treeMenuClick(" + item.index + ", " + link + ", " + submenu + ", " + link2 + ", " + expanded + ");";

  // Start the table row.

  treeMenuDocument.write('<tr valign=top><td nowrap>');

 
  bars = new Array();
  for (i = 0; i < treeMenuDepth; i++) {
   if (treeMenuBars[i]) {
      treeMenuDocument.write('<img src="' + treeMenuImgDir + 'orgline.gif" align=left border=0 vspace=0 hspace=5>');
      bars[i] = true;
   }
    else {
      treeMenuDocument.write('<img src="' + treeMenuImgDir + 'orgline.gif" align=left border=0 vspace=0 hspace=5>');
      bars[i] = false;
    }
    if (item.index == treeMenuSelected)
      treeMenuScrollX += 18;
  }

  // Determine if this is a submenu item that contains other submenus.

  more = false;
  if (item.submenu && treeMenuFolders >= 0)
    for (i = 0; i < item.submenu.items.length; i++)
      if (item.submenu.items[i].submenu != null || treeMenuFolders == 1)
        more = true;

  // Draw tee bar or corner if this item is not a submenu or if it is a
  // submenu but doesn't contain other submenus.

  if (!more) {
  if (item.target!="1") {
    if (treeMenuLastItem) {
      img = "orgline.gif";
      bars[bars.length] = false;
    }
    else {
     img = "orgline.gif";
      bars[bars.length] = true;
    }
    //treeMenuDocument.write('<img src="' + treeMenuImgDir + img + '" align=left border=0 vspace=0 hspace=0>');
 
  }
 }


 if (item.submenu) {
    if (expanded)
      img = "orgminus.gif";
      
      
    else 
      img = "orgplus.gif";
      
       treeMenuDocument.write('<a href="#"><img src="' + treeMenuImgDir + img + '"' + alt + ' align=left border=0 vspace=0 hspace=0 onClick="' + cmd + '">');

  }


  // Write the start of the link tag so all of the following images and text
  // will be clickable.
 tgt =tgt+1 ;    
  if (item.url2 == "1"){
    treeMenuDocument.write('<IMG alt="' + item.text + '" border=0 id=pippo' + tgt + ' lowsrc=' + MTMenuImageDirectory + item.icon + '_on.gif name=pippo' + tgt + ' src=" ' + MTMenuImageDirectory + item.icon + '.gif"  dynamicanimation="pippo' + tgt + '" onClick="' + cmd + '"></a>');
 } else {
    if (item.target == "1"){
    treeMenuDocument.write('<a href="' + item.url2 + '" base target="_top"  " onmouseout="document[\'pippo' + tgt + '\'].src =document[\'pippo' + tgt + '\'].imgRolln" onmouseover="document[\'pippo' + tgt + '\'].imgRolln=document[\'pippo' + tgt + '\'].src; document[\'pippo' + tgt + '\'].src=document[\'pippo' + tgt + '\'].lowsrc;"><IMG alt="' + item.text + '" border=0 id=pippo' + tgt + ' lowsrc=' + MTMenuImageDirectory + item.icon + '_on.gif name=pippo' + tgt + ' src=" ' + MTMenuImageDirectory + item.icon + '.gif"  dynamicanimation="pippo' + tgt + '">');
  }else{
   if (item.target == "2"){
    treeMenuDocument.write('<a href="' + item.url2 + '"  target="main"  " onmouseout="document[\'pippo' + tgt + '\'].src =document[\'pippo' + tgt + '\'].imgRolln" onmouseover="document[\'pippo' + tgt + '\'].imgRolln=document[\'pippo' + tgt + '\'].src; document[\'pippo' + tgt + '\'].src=document[\'pippo' + tgt + '\'].lowsrc;"><IMG alt="' + item.text + '" border=0 id=pippo' + tgt + ' lowsrc=' + MTMenuImageDirectory + item.icon + '_on.gif name=pippo' + tgt + ' src=" ' + MTMenuImageDirectory + item.icon + '.gif"  dynamicanimation="pippo' + tgt + '">');
  }else{
    treeMenuDocument.write('<a href="' + item.url2 + '"  target= "mainFrame" " onmouseout="document[\'pippo' + tgt + '\'].src =document[\'pippo' + tgt + '\'].imgRolln" onmouseover="document[\'pippo' + tgt + '\'].imgRolln=document[\'pippo' + tgt + '\'].src; document[\'pippo' + tgt + '\'].src=document[\'pippo' + tgt + '\'].lowsrc;"><IMG alt="' + item.text + '" border=0 id=pippo' + tgt + ' lowsrc=' + MTMenuImageDirectory + item.icon + '_on.gif name=pippo' + tgt + ' src=" ' + MTMenuImageDirectory + item.icon + '.gif"  dynamicanimation="pippo' + tgt + '">');
}
 }
 }
 
  if (item.url != "")
 treeMenuDocument.write('<a href="#" onClick="' + cmd + '">');

  // For a submenu item that contains other submenus, draw a tee bar or corner
  // with a plus or minus sign.

  if (more) {
    if (expanded) {
      if (treeMenuLastItem) {
        img = "menu_corner_minus.gif";
        bars[bars.length] = false;
      }
      else {
        img = "menu_tee_minus.gif";
        bars[bars.length] = true;
      }
    }
    else {
      if (treeMenuLastItem) {
        img = "menu_corner_plus.gif";
        bars[bars.length] = false;
      }
      else {
        img = "menu_tee_plus.gif";
        bars[bars.length] = true;
      }
    }
  }

  treeMenuDocument.write('</a>');
  treeMenuDocument.writeln('</td></tr>');

  // Set the placement of vertical bars needed for the next row.

  treeMenuBars = bars;

  // If the item is a submenu and it is expanded, make a recursive call to
  // draw its item list.

  if (item.submenu && expanded) {
    treeMenuDepth++;
    treeMenuListItems(item.submenu);
    treeMenuDepth--;
  }
}

//----------------------------------------------------------------------------
// This function handles a click on a menu item.
//----------------------------------------------------------------------------

function treeMenuClick(n, link, submenu,link2,expanded) {

  var date, cookie;
//appena si apre una cartella si chiudono le altre


// per non espandere tutto il menu'
if (link2 && !expanded)
treeMenuClickRoot();
 
  if (!treeMenuExpand)
    treeMenuDisplay();

  // If this is a submenu, toggle the expansion flag.

  if (submenu)
    treeMenuExpand[n] = 1 - treeMenuExpand[n];

  // Save the selected item index and update the cookies.

  treeMenuSelected = n;
  var date = new Date ();
  date.setTime (date.getTime() + (86400 * 1000 * treeMenuDays));
  cookie = treeMenuExpand.toString();
  setCookie(treeMenuName, cookie, date);
  setCookie(treeMenuName + "-selected", treeMenuSelected, date);

  // Set up redraw the menu frame.

  setTimeout("treeMenuDisplay()", 10);

  // Return the link flag.

  return link;
}

//----------------------------------------------------------------------------
// This function handles a click on the menu root.
//----------------------------------------------------------------------------

function treeMenuClickRoot() {

  // Clear the menu state.

  treeMenuExpand = null;
  treeMenuSelected = null;

  // Delete cookies.

  deleteCookie(treeMenuName);
  deleteCookie(treeMenuName + "-selected");

  // Set up redraw the menu frame.

  setTimeout("treeMenuDisplay()", 10);

  return false;
  
  parent.treeMenuDisplay();
}

//----------------------------------------------------------------------------
// This function scrolls the window to ensure the selected item is in view.
// It should only be called after the page has loaded.
//
// Note: This code is browser-dependent. Scrolling may be ignored for older
// browsers.
//----------------------------------------------------------------------------

function treeMenuScroll() {

  var win, height, width;

  // Get a handle to the menu frame.

  win = window.frames[treeMenuFrame];

  // Find the dimensions of the frame.

  if (document.layers) {
    height = win.innerHeight;
    width = win.innerWidth;
  }
  else if (document.all) {
    height = win.document.body.clientHeight;
    width = win.document.body.clientWidth;
  }
  else if (document.images) {
    win.scroll(0, treeMenuScrollY);
    return;
  }
  else
    return;

  // Scroll the frame if necessary.

  if (treeMenuScrollY > height)
    win.scrollBy(0, treeMenuScrollY);
  if (treeMenuScrollX > width)
    win.scrollBy(treeMenuScrollX, 0);
}

//----------------------------------------------------------------------------
// Set a cookie given a name, value and expiration date.
//----------------------------------------------------------------------------


function setCookie (name, value, expires) {

  document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() +  "; path=/";
}

//----------------------------------------------------------------------------
// Returns the value of the named cookie.
//----------------------------------------------------------------------------

function getCookie(name) {

  var search;

  search = name + "=";
  offset = document.cookie.indexOf(search) ;
  if (offset != -1) {
    offset += search.length;
    end = document.cookie.indexOf(";", offset);
    if (end == -1)
      end = document.cookie.length;
    return unescape(document.cookie.substring(offset, end));
  }
  else
    return "";
}

//----------------------------------------------------------------------------
// Delete the named cookie.
//----------------------------------------------------------------------------

function deleteCookie(name) {

  var expdate = new Date();
  expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
  setCookie(name, "", expdate);
}
