voci = new Array (
new Array ("index.htm", "Pagina iniziale", 1, ""),
new Array ("preventivo.php", "Preventivo", 64, "new.gif"),
new Array ("descrizione.htm", "Descrizione", 1, ""),
new Array ("contatti.htm", "Contatti", 1, ""),
new Array ("appuntamenti.htm", "Appuntamenti", 1, ""),

new Array ("laboratorioalice.pdf", "Brochure PDF", 2, ""),
new Array ("manuale/index.htm", "Consulta il manuale", 2, ""),
new Array ("download/alicedoc.exe", "Scarica il manuale HTML", 2, ""),
new Array ("manuale/manuale.pdf", "Scarica il manuale PDF", 2, ""),

new Array ("miur2003.htm", "Accordo MIUR", 1, ""),
new Array ("indire.htm", "Certificazione INDIRE", 1, ""),
new Array ("s_visione.php", "Prova GRATUITA", 1, ""),
new Array ("listino.php", "Listino prezzi", 1, ""),
new Array ("aggiorna.htm", "Aggiornamenti", 1, ""),
// new Array ("montevideo.htm", "Forum Montevideo", 1, "new.gif"),
new Array ("english/index.htm", "English", 1, "flag_uk.gif"),
new Array ("espanol/index.htm", "Espaņol", 1, "flag_es.gif"),

new Array ("index.htm", "Home page", 4, ""),
new Array ("description.htm", "Description", 4, ""),
new Array ("laboratorioalice_en.pdf", "PDF Brochure", 8, ""),
new Array ("demo.htm", "FREE Trial", 4, ""),
new Array ("price.php", "Price list", 4, ""),
new Array ("update.htm", "Update", 4, ""),
new Array ("montevideo_en.htm", "Montevideo forum", 4, "../new.gif"),

new Array ("../index.htm", "Italiano", 4, "../flag_it.gif"),
new Array ("../espanol/index.htm", "Espaņol", 4, "../flag_es.gif"),

new Array ("index.htm", "Pagina inicial", 16, ""),
new Array ("descripcion.htm", "Descripcion", 16, ""),
new Array ("miur2003.htm", "Acuerdo MIUR", 16, ""),
new Array ("indire.htm", "Certificacion INDIRE", 16, ""),
new Array ("laboratorioalice_es.pdf", "Brochure PDF", 32, ""),
new Array ("demo.htm", "Prueba GRATUITA", 16, ""),
new Array ("precios.php", "Lista de precios", 16, ""),
new Array ("actualiza.htm", "Actualizaciones", 16, ""),
new Array ("montevideo_es.htm", "Foro Montevideo", 16, "../new.gif"),

new Array ("../index.htm", "Italiano", 16, "../flag_it.gif"),
new Array ("../english/index.htm", "English", 16, "../flag_uk.gif"),

new Array ("forum/index.php", "Sala Insegnanti - forum", 1, ""),
new Array ("istitutoalice/index.htm", "Istituto Alice", 1, ""),

new Array ("../index.htm", "Home Laboratorio Alice", 128, ""),
new Array ("index.htm", "Atrio", 256, ""),
new Array ("portineria.php", "Portineria", 128, ""),
new Array ("biblioteca.htm", "Biblioteca", 128, ""),
new Array ("indexlab.htm", "Laboratorio", 128, ""),
new Array ("../forum/index.php", "Sala Insegnanti - forum", 128, ""),
new Array ("bagni.htm", "Bagni", 128, ""),
new Array ("segreteria.htm", "Segreteria", 128, ""),
new Array ("../manuale/index.htm", "Manuale completo", 512, "new.gif"),
new Array ("podcastgen1.1", "Podcast: file audio", 128, ""),

new Array ("../indexlab.htm", "INDICE DELLE SCHEDE", 1024, ""),
new Array ("prima_di_incominciare.htm", "Informazioni preliminari", 1024, ""),
new Array ("alice_vantaggi.htm", "I vantaggi di Lab. Alice", 1024, ""),
new Array ("discorso.htm", "Mostrare un programma", 1024, ""),
new Array ("ppt.htm", "Mostrare una present...", 1024, ""),
new Array ("ascolto.htm", "Fare un ascolto collettivo", 1024, ""),
new Array ("online.htm", "Fare una ricerca on-line", 1024, ""),
new Array ("es.htm", "Citare un allievo ad es...", 1024, ""),
new Array ("dvd.htm", "Vedere un dvd", 1024, ""),
new Array ("verifica.htm", "Fare una verifica scritta", 1024, ""),
new Array ("esercitazione.htm", "Fare una verifica orale", 1024, ""),
new Array ("accendi.htm", "Accendere i PC allievo", 1024, ""),
new Array ("spegni.htm", "Spegnere i PC allievo", 1024, "")
);


campiLab = new Array (
	new Array (
      0,
      "TH",
      new Array ("", "h2", "Laboratorio n.#")
   ),
	new Array (
      0,
      "TD",
      new Array ("Identificativo laboratorio:", ""),
      new Array ("", "input", "idlab#", "text", "20")
   ),
	new Array (
      0,
      "TH",
      new Array ("Tipo di acquisto:", ""),
      new Array ("Nuova licenza", "input", "tipo#", "radio", "1", "nuova", "gestioneRadio", "checked")
   ),
	new Array (
      0,
      "TD",
      new Array (" ", ""),
      new Array ("Integrazione di una licenza esistente", "input", "tipo#", "radio", "1", "esistente", "gestioneRadio")
   ),
	new Array (
      1,
      "TH",
      new Array ("", "h3", "Situazione esistente:")
   ),
	new Array (
      1,
      "TD",
      new Array ("Numero di licenze Allievo possedute:", ""),
      new Array ("", "input", "oldposti#", "text", "5", "0")
   ),
	new Array (
      1,
      "TD",
      new Array ("Con Estensione multimediale (audio attivo-comparativo)", ""),
      new Array ("", "input", "oldmm#", "checkbox", "1")
   ),
	new Array (
      2,
      "TH",
      new Array ("", "h3", "Dettagli della richiesta:")
   ),
	new Array (
      2,
      "TD",
      new Array ("Numero di licenze Allievo richieste:", ""),
      new Array ("", "input", "posti#", "text", "5", "0")
   ),
	new Array (
      2,
      "TD",
      new Array ("Con Estensione multimediale (audio attivo-comparativo)", ""),
      new Array ("", "input", "mm#", "checkbox", "1", "", "aggiungiTele")
   ),
	new Array (
      3,
      "TD",
      new Array ("Telecomandi per postazioni allievo (opzionali)", ""),
      new Array ("", "input", "tele#", "text", "5", "0")
   )
);

curLabs = 0;

function getLabId (lab)
{
   return ("lab" + (lab + 1));
}

function getLab (lab)
{
   return (document.getElementById (getLabId (lab)));
}

function creaCampi (numLabs)
{
   var datiRiga = new Array ();
   var datiCol = new Array ();

   fine = document.getElementById ("fineTabella");

   for (curLab = 0; curLab < numLabs; curLab ++)
      {
      if (getLab (curLab))
         continue;
      sezione = document.createElement ("TBODY");
      sezione.id = getLabId (curLab);
      for (cont = 0; cont < campiLab.length; cont ++)
         {
         datiRiga = campiLab [cont];
         riga = document.createElement ("TR");
         riga.level = datiRiga [0];
         if (riga.level & 1)
            riga.className = "printStuff";
         for (cont1 = 2; cont1 < datiRiga.length; cont1 ++)
            {
            col = document.createElement (datiRiga [1]);
            if (datiRiga.length == 3)
               col.colSpan = 2;

            datiCol = datiRiga [cont1];
            testo = document.createTextNode (datiCol [0]);
            if (datiCol [2] != null)
               {
               val = datiCol [2].replace (/#/gi, curLab + 1);
               campo = document.createElement (datiCol [1]);
               if (datiCol [1] == "input")
                  {
                  campo.type = datiCol [3];
                  campo.name = val;
                  campo.size = datiCol [4];
                  campo.lab = curLab;
                  if (datiCol [5])
                     campo.value = datiCol [5];
                  if (datiCol [6])
                     campo.onclick = eval (datiCol [6]);
                  if (datiCol [7])
                     campo.defaultChecked = true;
                  // patch per IE
                  if (document.forms[0].elements [val] != null)
                     document.forms[0].elements [val] = new Array (document.forms[0].elements [val], campo);
                  else
                     document.forms[0].elements [val] = campo;
                  }
               else
                  {
                  header = document.createTextNode (val);
                  campo.appendChild (header);
                  }
               col.appendChild (campo);
               }

            col.appendChild (testo);
            riga.appendChild (col);
            }
         sezione.appendChild (riga);
         }
      fine.parentNode.insertBefore (sezione, fine);
      }

   for (; curLab < curLabs; curLab ++)
      {
      if (old = getLab (curLab))
         fine.parentNode.removeChild (old);
      }

   curLabs = numLabs;
}

function _mostraNascondi (list, level, nascondi)
{
   var cont = 0;
   var cur = null;

   for (cont = 0; cont < list.length; cont ++)
      {
      cur = list.item (cont);
      // NS non gestisce correttamente il cur.level quindi si legge tramite DOM
      // e IE5 non gestisce getNamedItem
      if (cur.attributes && cur.attributes.getNamedItem)
         {
         lev = cur.attributes.getNamedItem ("level");
         if (lev)
            cur.level = lev.value;
         }
      if (cur.level == level)
         cur.className = nascondi ? "printStuff" : "";
      else
         _mostraNascondi (cur.childNodes, level, nascondi);
      }
}

function mostraNascondi (elem, level, nascondi, id)
{
   if (elem.lab == null)
      lab = document.getElementById (id);
   else
      lab = getLab (elem.lab);
   if (lab == null)
      return;
   _mostraNascondi (lab.childNodes, level, nascondi);
}

function cambiaLivello (elem, hideLevel, showLevel, id)
{
   mostraNascondi (elem, hideLevel, true, id);
   mostraNascondi (elem, showLevel, false, id);
}

function gestioneRadio ()
{
   mostraNascondi (this, 1, this.value == "nuova");

   // IE non gestisce correttamente i radio creati con createElement
   // tocca farlo a mano
   this.checked = true;
   cur = lab.getElementsByTagName ("INPUT");
   for (cont = 0; cont < cur.length; cont ++)
      {
      if (cur [cont].name == this.name && cur [cont] != this)
         cur [cont].checked = false;
      }
}

function aggiungiTele ()
{
   mostraNascondi (this, 3, ! this.checked);
}

function labsu (inc)
{
   labs = document.getElementById ("numLabs");
   val = curLabs + inc;
   if (val < 0)
      val = 0;
   labs.value = eval (val);
   creaCampi (val);
}

function tipoPrev (val)
{
   vals = val.split ('_');
   elemId = vals [0];
   action = vals [1];
   cont = 0;
   while ((elem = document.getElementById (elemId+cont)) != null)
      {
      elem.className = (action == "on") ? "" : "printStuff";
      cont ++;
      }
   if (action == "off")
      {
      labs = document.getElementById ("numLabs");
      labs.value = 0;
      creaCampi (0);
      }
}

function checkVoid (elem, msg)
{   
	if ((elem.value != null) && (elem.value.length))
      for (cont = 0; cont < elem.value.length; cont ++)
         {
         if (" \t\n\r".indexOf (elem.value [cont]) == -1)
            return (false);
         }

   alert (msg + " č vuoto!");
   elem.focus ();
   return (true);
}

function checkForSpace (elem, msg)
{
   parts = elem.value.split (/\s/);
   if (parts.length != 1)
      {
      alert (msg + " contiene degli spazi!");
      elem.focus ();
      return (true);
      }
   return (false);
}

function checkEmail (elem, msg)
{   
   if (checkVoid (elem, msg))
      return (true);
   if (checkForSpace (elem, msg))
      return (true);

   atSym = elem.value.indexOf('@');
   period = elem.value.lastIndexOf('.')
   if ((atSym < 1) || (period <= atSym + 1) || (period >= elem.value.length - 2))
      {
      alert (msg + " non ha un formato valido!");
      elem.focus ();
      return (true);
      }
   return (false);
}

function checkNumericCode (elem, msg, len)
{   
   if (checkVoid (elem, msg))
      return (true);
   if (checkForSpace (elem, msg))
      return (true);
   if (len && (elem.value.length != len))
      {
      alert (msg + " deve avere lunghezza " + len +"!");
      elem.focus ();
      return (true);
      }
   parts = elem.value.split (/[0-9]/);
   // N.B: NS conta anche le stringhe vuote (solo il separatore), IE no
   if (parts.length != elem.value.length + 1 && parts.length != 0)
      {
      alert (msg + " pu= contenere solo cifre!");
      elem.focus ();
      return (true);
      }
   return (false);
}

function checkPI (elem, msg)
{   
   if (checkNumericCode (elem, msg, 11))
      return (true);

   sum = 0;
   for (cont = 0; cont < 11; cont ++)
      {
      val = elem.value.charCodeAt (cont) - '0'.charCodeAt(0);
      if (cont & 1)
         {
         val *= 2;
         if (val > 9)
            val -= 9;
         }
      sum += val;
      }

   if (sum % 10)
      {
      alert (msg + " non č valido!");
      elem.focus ();
      return (true);
      }
      
   return (false);
}

function checkAnagrafica ()
{
   elem = document.forms[0].elements;
   tipoUtenza = elem ["tipoUtenza"].value;
   if (checkVoid (elem ["Nome"], tipoUtenza == "SCUOLA" ? "Il nome dell'Istituto" : "Il campo Ragione sociale"))
      return -1;
   if (tipoUtenza == "SCUOLA")
      if (checkVoid (elem ["TipoScuola"], "Il tipo di Istituto"))
         return -1;
   if (checkVoid (elem ["Indirizzo"], "L'indirizzo dell'Istituto"))
      return -1;
   if (checkVoid (elem ["Citta"], "Il campo Cittā"))
      return -1;
   if (checkNumericCode (elem ["CAP"], "Il campo CAP", 5))
      return -1;
   if (tipoUtenza == "SCUOLA")
      if (checkEmail (elem ["Email"], "Il campo email dell'Istituto"))
         return -1;
   if (checkNumericCode (elem ["Telefono"], "Il numero di telefono", 0))
      return -1;
   if (checkNumericCode (elem ["Fax"], "Il numero di fax", 0))
      return -1;
   if (checkPI (elem ["PIVA"], tipoUtenza == "SCUOLA" ? "Il campo Codice Fiscale" : "Il campo Partita IVA"))
      return -1;
   if (checkVoid (elem ["Responsabile"], "Il cognome del Responsabile"))
      return -1;
   if (checkEmail (elem ["EmailResp"], "Il campo email del Responsabile"))
      return -1;

   return 0;
}

stdDiv = 0;

function startPage (tdId, divId, level)
{
	var cont = 0;
   var fileName = this.location.href.substr (this.location.href.lastIndexOf ("/") + 1);
    
   window.onresize = onResize;
   window.onload = onResize;

	document.writeln('<SCRIPT type="text/javascript" for="window" event="onbeforeprint">onPrint ("hi");</SCRIPT>');
	document.writeln('<SCRIPT type="text/javascript" for="window" event="onafterprint">onPrint ("lo");</SCRIPT>');
	document.writeln('<table class="full"><tr><td id="side"><div class="menu">');

	while (cont < voci.length)
		{
		if (voci[cont][0] != fileName && (voci[cont][2] & level))
			{
			document.writeln('<p><a href="'+voci[cont][0]+'">'+voci[cont][1]);
			if (voci[cont][3] != "")
			   document.writeln('  <img src="'+voci[cont][3]+'" border="0">');
			document.writeln('</a></p>');
			}
		cont ++;
		}
   document.writeln('<p><img src="manuale/it1.gif"></p>');
	document.writeln('</div><p>&nbsp;</p></td><td id="'+tdId+'">');
	if (divId != '')
		{
		stdDiv = 1;
		document.writeln('<div class="'+divId+'">');
		}
}   

function endPage ()
{
	if (stdDiv == 1)
		document.writeln('</div>');
	document.writeln('</td></tr></table>');
}

function printTitle ()
{
	document.writeln (
		'<div class="title">'+
		    '<p><img src="manuale/titolo.gif" width="550" height="172"></p>'+
		'</div>');
}   

function imgRight (img, ext, wid, hig)
{
	document.writeln (
		'<div class="imgLo">'+
			'<p><img src="'+img+'.'+ext+'" loSrc="'+img+'.'+ext+'" hiSrc="'+img+'_print.'+ext+'" width="'+wid+'" height="'+hig+'"></p>'+
		'</div>');
}

function imgR (img, wid, hig)
{
	document.writeln (
		'<div class="imgR">'+
			'<p><img src="'+img+'" width="'+wid+'" height="'+hig+'"></p>'+
		'</div>');
}

function imgL (img, wid, hig)
{
	document.writeln (
		'<div class="imgL">'+
			'<p><img src="'+img+'" width="'+wid+'" height="'+hig+'"></p>'+
		'</div>');
}

function swf (movie)
{
	document.writeln (
      '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+
      'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0"'+
      'width="100%" height="100%">'+
      '  <param name="movie" value="'+ movie + '">'+
      '  <param name="bgcolor" value="#314395">'+
      '<embed id="NSmovie" src="' + movie + '" bgcolor="#314395" width="100%" height="100%"'+
      'name="movie" type="application/x-shockwave-flash"'+
      'pluginspage="http://www.macromedia.com/go/getflashplayer">'+
      '</object>');
}


function onPrint (mode)
{
   var cont;
   var curImg;
   var divs = document.getElementsByTagName ("DIV");
   if (divs != null)
      {
      for (cont = 0; cont < divs.length; cont ++) 
	     if (divs[cont].className == "imgLo")
		     {  
		     curImg = divs[cont].getElementsByTagName ("IMG").item (0);
           if (mode == "hi")
              curImg.src = curImg.hiSrc;
           else
              curImg.src = curImg.loSrc;
           }
		}
}


function setWidth (destId, w)
{
   dest = document.getElementById (destId);
   if (dest)
      {
      dest.style.width = w;
      if (dest.offsetWidth != w)
         dest.style.width = dest.offsetWidth;
      return (dest.style.width);
      }
   return (0);
}      

function onResize ()
{
   dest = document.getElementById ('centrata');
   if (dest)
      {
      sidebar = document.getElementById ('side');
      dest.style.marginLeft = (document.body.offsetWidth - sidebar.offsetWidth - dest.offsetWidth) / 2;
      dest.style.marginTop = (document.body.offsetHeight - dest.offsetHeight) / 2;
      }
   dest = document.getElementById ('NSmovie');
   if (dest)
      dest.height = document.body.offsetHeight;
}


