/*
  Funzioni di visualizzazione di finestre con parametri
*/

var windowsPtr  = new Array();
var windowsName = new Array();

//----------------------------------------------------------------------------------------------------
function openFinestraPar (URL, nome, testo, width, height, top, left, toolbarVisible, statusVisible, resize) {
  if (top=="") {   // se la distanza dal bordo superiore è nulla, centra verticalmente
    top=(screen.height/2)-(height/2);
  }
  if (left=="") {  // se la distanza dal bordo sinistro è nulla, centra orizzontalmente
    left=(screen.width - width)/2;
  }
  var prev;

  prev = window.open(URL, nome, "toolbar="+toolbarVisible+",location=0,directories=0,menuBar=0,scrollbars=1,resizable="+resize+",status="+statusVisible+",width=" + width + ",height=" + height + ",left=" + left + ",top=" + top);

  if (URL =="") {  // se non è stato specificato il nome di un file, inserisce il testo
    if (testo!="") {
      prev.document.write(testo);
    }
  }
  return prev;
}
//----------------------------------------------------------------------------------------------------
function openFinestra(URL,nome,tBar) {

  //alert("BROWSER " + navigator.family);
  if (navigator.family=='gecko' || navigator.family=='nn4') {    // Communicator 4, Mozilla e Netscape >= 6.x
    if (screen.Width > 800) {
      WIDTH = screen.availWidth-30;
    }
    else {
      WIDTH = screen.availWidth;
    }
    HEIGHT = screen.availHeight-160;
  }
  else if (navigator.family=='ie4') {  // I.E. >= 4
    if (screen.Width > 800) {
      WIDTH = screen.Width-30;
    }
    else {
      WIDTH = screen.Width;
    }
    HEIGHT = screen.Height-160;
  }
  else
  {
    if (screen.Width > 800) {
      WIDTH = screen.Width-30;
    }
    else {
      WIDTH = screen.Width;
    }
    HEIGHT = screen.Height-160;
  }	

  LEFT = "";
  TOP  = 50;
  var prev = openFinestraPar (URL,nome,"", WIDTH, HEIGHT, TOP, LEFT,tBar,1,1);
  return prev;
}
//----------------------------------------------------------------------------------------------------
function openFinDettagli (URL,nome) {
  // Visualizzazione dettagli dei congressi
  HEIGHT = screen.Height-160;
  var win = openFinestraPar (URL,nome,"", 800, HEIGHT, "", "",1,1,1);
  win.focus();
}
//----------------------------------------------------------------------------------------------------
function apriFinestraEngine(URL, nome, tBar)
{
   //
   // Se la finestra è già stata aperta rimando a quell'istanza
   //
   for ( i=0;i<windowsPtr.length;i++)
   {
     // alert(windowsPtr[i].name + "<-->" + nome);
     if ( windowsName[i].name == nome )
     {
        var win = windowsPtr[i];
        // Se è stata chiusa la riapro
        if ( win.closed )
        {
           win = openFinestra(URL,nome,tBar);
           win.focus();
           windowsPtr[i] = win;
           return;
        }
        // altrimenti ricarico la location
        else
        {
           win.location = URL;
           win.focus();
           return;
        }
     }
   }
   //
   // Se ancora non è stata aperta la inserisco nella lista
   //
   var arraySize = windowsPtr.length;
   var win;
   // Per evitare l'errore sul focus dell'iexplorer 4/5.x chiudo e riapro forzamente la nuova finestra
   if ( navigator.appVersion.substring(0,1) == "4" && navigator.appName.indexOf("Microsoft") >= 0 )
   {
      win = openFinestra("null.html",nome,tBar);
      win.close();
      win = openFinestra(URL,nome,tBar);
   }
   else
   {
     win = openFinestra(URL,nome,tBar);
   }
   win.focus();
   windowsName[arraySize] = nome;
   windowsPtr[arraySize] = win;
}
//----------------------------------------------------------------------------------------------------
// Apre una finestra per la visualizzazione della form d'invio degli email (vedi: mlm/GestioneGruppicls)
function openFinestraEmail (URL,nome) {
  var win = openFinestraPar (URL, nome, "", 700, 600, "", "", 0, 1, 0);
  win.focus();
}
//----------------------------------------------------------------------------------------------------
// Apre una nuova finestra per visualizzare i siti delle società del gruppo Enel
function goSocieta(URL){
  if (URL=="combo") {
    stSocieta = document.main.cmbSocieta.selectedIndex
    if (stSocieta != 0){
        stSocieta = document.main.cmbSocieta.options[stSocieta].value
        document.main.cmbSocieta.value=0
    }
  }
  else {
    stSocieta = URL;
  }
  var WIDTH= screen.availWidth -10;
  var HEIGHT = screen.availHeight - 100;
  var win = openFinestraPar (stSocieta, "il_gruppo", "", WIDTH, HEIGHT, 1, 1, 1, 1, 1);
  win.focus();
}
//----------------------------------------------------------------------------------------------------
// Apre una nuova finestra per visualizzare i siti delle società del gruppo Enel
function goSocietaTop(URL){
  if (URL=="combo") {
    stSocieta = document.main.cmbSocietaTop.selectedIndex
    if (stSocieta != 0){
        stSocieta = document.main.cmbSocietaTop.options[stSocieta].value
        document.main.cmbSocietaTop.value=0
        if (stSocieta == "0") {
          return;
        }
    }
  }
  else {
    stSocieta = URL;
  }
  var WIDTH= screen.availWidth -10;
  var HEIGHT = screen.availHeight - 100;
  var win = openFinestraPar (stSocieta, "il_gruppo", "", WIDTH, HEIGHT, 1, 1, 1, 1, 1);
  win.focus();
}
//----------------------------------------------------------------------------------------------------
// Apre una nuova finestra per visualizzare i siti delle società del gruppo Enel
function goSocietaBottom(URL){
  if (URL=="combo") {
    stSocieta = document.main.cmbSocietaBottom.selectedIndex
    if (stSocieta != 0){
        stSocieta = document.main.cmbSocietaBottom.options[stSocieta].value
        document.main.cmbSocietaBottom.value=0
        if (stSocieta == "0") {
          return;
        }
    }
  }
  else {
    stSocieta = URL;
  }
  var WIDTH= screen.availWidth -10;
  var HEIGHT = screen.availHeight - 100;
  var win = openFinestraPar (stSocieta, "il_gruppo", "", WIDTH, HEIGHT, 1, 1, 1, 1, 1);
  win.focus();
}
//----------------------------------------------------------------------------------------------------
