
    function nuovo_nome() {
      var a_nome = new Array()
      var az = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
      for (var i = 0; i < 6; i++)
        a_nome.push(az.charAt(Math.random()*26))
      return a_nome.join("")
    }


    function apri_dialogo(w, h, nome, altre_opzioni) {
      var opzioni = new Array()
      if ((typeof w != "undefined") && (w != ""))
        opzioni.push("width=" + w)
      if ((typeof h != "undefined") && (h != ""))
        opzioni.push("height=" + h)
      opzioni.push("titlebar=no, resizable=yes, scrollbars=yes")
      if ((typeof altre_opzioni != "undefined") && (altre_opzioni != ""))
        opzioni.push(altre_opzioni)
      if ((typeof nome == "undefined") || (nome == ""))
        nome = nuovo_nome()
      return window.open("", nome, opzioni.join(", "))
    }


    function apriDialogo(w, h, nome, altre_opzioni) {
      return apri_dialogo(w, h, nome, altre_opzioni)
    }


    function crea_opzioni(opzioni_default, altre_opzioni) {
      var opzioni = new Array()
      opzioni.push(opzioni_default)
      if ((typeof altre_opzioni != "undefined") && (altre_opzioni != null) && (altre_opzioni != ""))
        opzioni.push(altre_opzioni)
      return opzioni
    }


    function apri_finestra_html(html, w, h, altre_opzioni) {
      var opzioni = crea_opzioni("titlebar=no, resizable=yes, scrollbars=yes", altre_opzioni)
      if ((typeof w != "undefined") && (w != ""))
        opzioni.push("width=" + w)
      if ((typeof h != "undefined") && (h != ""))
        opzioni.push("height=" + h)
      return window.open(html, nuovo_nome(), opzioni.join(", "))
    }


    function apri_dialogo_html(html, w, h, altre_opzioni) {
      var opzioni = crea_opzioni("dependent=yes,dialog=yes,minimizable=no,modal=yes,alwaysRaised=yes", altre_opzioni)
      var win = apri_finestra_html(html, w, h, opzioni.join(", "))
      return win
    }


    function apri_finestra_schermointero(html, altre_opzioni) {
      var opzioni = crea_opzioni("fullscreen=yes, scrollbars=yes", altre_opzioni)
      opzioni.push("width=" + screen.width)
      opzioni.push("height=" + screen.height)
      return window.open(html, nuovo_nome(), opzioni.join(", "))
    }


    var aMessaggioTitolo = new Array()
    var aMessaggioTesto = new Array()
    var aMessaggioTipo = new Array()


    function alert_quasar__comune(titolo, testo, w, h, altre_opzioni, tipo) {
      if (typeof testo == "undefined") {
        testo = titolo
        titolo = "Messaggio dallo Staff di Quasar"
      }
      var nome = nuovo_nome()
      aMessaggioTitolo[nome] = titolo
      aMessaggioTesto[nome] = testo
      aMessaggioTipo[nome] = tipo

      if (typeof w == "undefined")
        w = screen.width * 0.66
      if (typeof h == "undefined")
        h = screen.height * 0.55
      var t = (screen.height - h) / 2
      var l = (screen.width - w) / 2

      var opzioni = new Array()
      opzioni.push("top=" + t)
      opzioni.push("left=" + l)
      opzioni.push("width=" + w)
      opzioni.push("height=" + h)
      opzioni.push("titlebar=no, resizable=yes, scrollbars=yes")
      if ((typeof altre_opzioni != "undefined") && (altre_opzioni != ""))
        opzioni.push(altre_opzioni)

      var w = window.open("/alert.html", nome, opzioni.join(", "))
    }


    function alert_quasar(titolo, testo, w, h, altre_opzioni) {
      alert_quasar__comune(titolo, testo, w, h, altre_opzioni, "testo")
    }


    function alert_quasar_html(titolo, testo, w, h, altre_opzioni) {
      alert_quasar__comune(titolo, testo, w, h, altre_opzioni, "html")
    }


    function alert_quasar_wiki(titolo, testo, w, h, altre_opzioni) {
      alert_quasar__comune(titolo, testo, w, h, altre_opzioni, "wiki")
    }


    function scrivi_alert(w) {
      if (aMessaggioTipo[w.name] == "testo") {
        w.imposta_testo("titolo", aMessaggioTitolo[w.name])
        w.imposta_testo("testo", aMessaggioTesto[w.name])
      }
      else if (aMessaggioTipo[w.name] == "html") {
        w.imposta_html("titolo", aMessaggioTitolo[w.name])
        w.imposta_html("testo", aMessaggioTesto[w.name])
      }
      else if (aMessaggioTipo[w.name] == "wiki") {
        w.imposta_wiki("titolo", aMessaggioTitolo[w.name])
        w.imposta_wiki("testo", aMessaggioTesto[w.name])
      }
    }


    var ie = navigator.appName.indexOf("Internet Explorer") != -1


    function window_height(w) {
      if (typeof w == "undefined")
        w = window
      if (ie)
        return w.document.body.clientHeight
      else
        return w.innerHeight
    }


    function window_width(w) {
      if (typeof w == "undefined")
        w = window
      if (ie)
        return w.document.body.clientWidth
      else
        return w.innerWidth
    }


    function window_scroll_offset_y(w) {
      if (typeof w == "undefined")
        w = window
      if (ie)
        return w.document.body.scrollTop
      else
        return w.pageYOffset
    }


    function mostra_item_se_non_visibile(w, id_item) {
      var obj_item = w.document.getElementById(id_item)
      if (obj_item == null)
        return
      var item_y = obj_item.offsetTop
      var item_h = obj_item.offsetHeight
      var win_miny = window_scroll_offset_y(w)
      var win_maxy = win_miny + window_height(w)

      var scroll_y = 0
      var scroll_offset = (item_h*2)

/*
      if (item_y + item_h > win_maxy) {
        scroll_y = item_y + item_h - scroll_offset
      }
      else if (item_y < win_miny)  {
        scroll_y = item_y - scroll_offset
      }
      else
        return
*/

      if ((item_y < win_miny) || (item_y + item_h > win_maxy)) {
        scroll_y = item_y - ((win_maxy - win_miny) / 2) + (item_h / 2)
      }
      else
        return

      if (scroll_y <= 0)
        scroll_y = 0
      w.scrollTo(0, scroll_y)
    }


/* */

var w_controllo = new Array();
var f_controllo = new Array();
var d_controllo = new Array();
var DELAY_CONTROLLO = 200;


function controlla_finestra(w, f, d) {
	if (arguments.length == 3) {
		w_controllo[w.name] = w;
		f_controllo[w.name] = f;
		d_controllo[w.name] = d;
	} 
	else if (arguments.length == 2) {
		w_controllo[w.name] = w;
		f_controllo[w.name] = f;
	} 
	else if (arguments.length == 1) {
		var nome = arguments[0];
		w = w_controllo[nome];
		f = f_controllo[nome];
		d = d_controllo[nome];
	} 
	else
		return;
	try {
		if ((w == null) || w.closed)
			f.call(d);
		else
			setTimeout("controlla_finestra('" + w.name + "')", DELAY_CONTROLLO);
	} catch (e) {
		f.call(d);
	}
}

