var Schema,                // indice schema scelto da utente
    Arretrati=false,       // presenza o assenza arretrati (select)
    Risolto,               // schema risolto (1) / ancora da risolvere (0)
    alfabeto="abcdefghijklmnopqrstuvwxyz",
    Secs, Mins, Ores,      // dati per timer
    TimerId=null,          // timer
    VediTimer=true,        // flag visibilitas timer
    VediInfo=false,        // flag visibilitas info e credit
    HtmlSchema="";         // codice schema (visualizzazione info e credit)

InfoEtCrediti=
"<img src=\"CruciOnLine\/soluzione.gif\" width=\"26\" height=\"26\">: "+
"Mostra soluzione<br>"+
"<img src=\"CruciOnLine\/reload.gif\" width=\"26\" height=\"26\">: "+
"Reset schema (ricomincia dall\'inizio)<br>"+
"<img src=\"CruciOnLine\/crono.gif\" width=\"26\" height=\"26\">: "+
"Mostra / nasconde timer<br>"+
"<img src=\"CruciOnLine\/zoomp.gif\" width=\"26\" height=\"26\">: "+
"Aumenta zoom schema<br>"+
"<img src=\"CruciOnLine\/zoomm.gif\" width=\"26\" height=\"26\">: "+
"Diminuisce zoom schema<br>"+
"<img src=\"CruciOnLine\/info.gif\" width=\"26\" height=\"26\">: "+
"Mostra / nasconde info e crediti<br><br><br>"+
"www.fantasitaly.com";

function crctag(n)
// costruisce tag per elemento contenente layout schemi o altro
{
  return("crc"+n);
}

function scegli_schema()
// reagisce a scelta schema
{
  if (!document.scelta) // se non ci sono arretrati
  {
    Schema=0;           // indice = 0 (unico schema presente)
    Arretrati=false;    // assenza di arretrati
  }
  else                  // altrimenti
  {
    Schema=document.scelta.scelta_utente.selectedIndex;
                        // indice tratto da select
    Arretrati=true;     // presenza di arretrati
  }

  nuovo_schema();       // invoca inizializzazione schema scelto
}

function vedi_info()
// mostra / nasconde schermata info e crediti
{
  if (!VediInfo)
  {
    if (document.scelta)
      document.getElementById("scelta_utente").disabled=true;
    // blocca scelta schema, se c'e'
    VediInfo=true;
    HtmlSchema=document.getElementById("crcsk").innerHTML;
    document.getElementById("crcsk").innerHTML=InfoEtCrediti;
  }
  else
  {
    if (document.scelta)
      document.getElementById("scelta_utente").disabled=false;
    // sblocca scelta schema, se c'e'
    VediInfo=false;
    document.getElementById("crcsk").innerHTML=HtmlSchema;
  }
}

function vediTimer()
// visualizza timer (se visualizzazione attiva)
{
  if (VediTimer)
    document.getElementById("timer").value=(Ores<10?"0":"")+Ores+":"+
      (Mins<10?"0":"")+Mins+":"+(Secs<10?"0":"")+Secs;
  else
    document.getElementById("timer").value="";
}

function vediNonVediTimer()
// commuta fra timer visibile e timer non visibile
{
  VediTimer=!VediTimer;

  vediTimer();
}

function aggiornaTimer()
// thread per aggiornamento sec, min e ore timer e visualizzazione
{
  Secs++;
  if (Secs==60)
  {
    Secs=0;
    Mins++;
  }
  if (Mins==60)
  {
    Mins=0;
    Ores++;
  }

  vediTimer();

  TimerId=setTimeout("aggiornaTimer()",1000);
}

function startTimer()
// partenza timer
{
  resetTimer();
  timerId=setTimeout("aggiornaTimer()",1000);
}

function stopTimer()
// fermata timer
{
  if (TimerId)
  {
    clearTimeout(TimerId);
    TimerId=null;
  }
}

function resetTimer()
// inizializzazione timer
{
  VediTimer=true;
  Secs=0;
  Mins=0;
  Ores=0;
}