// JavaScript Document
//Javascript extention functions
Array.prototype.clear=function() {
    this.length = 0;
};
  
  
NESSUNA = "N";
VERO    = "V";
FALSO   = "F";
CORRETTA= "C";
ERRATA  = "E";

NUM_QUESITI_TOOLBAR       = 10;
NUM_QUESITI_RIASSUNTO2011 = 4;
NUM_QUESITI_RIASSUNTO     = 4;
NUM_QUESITI_GRUPPO        = 4;

var eSchedaMode = {
    DoubleMode:0,
    SingleMode:1
};

var eSchedaSubMode = {
    NumberMode:0,
    LetterMode:1,    
    ModeVF:0,
    ModeVFAB:1,
    ModeVFCQC:2    
};  

var eTipoListato = {
    TIPOLISTATO_NONVALIDO:0,
    TIPOLISTATO_SCONOSCIUTO:1,
    TIPOLISTATO_AB:2,
    TIPOLISTATO_SUP:3,
    TIPOLISTATO_EDU:4,
    TIPOLISTATO_ADR:5,
    TIPOLISTATO_NOQUIZ:6,
    TIPOLISTATO_PATENTINO:7,
    TIPOLISTATO_REV_AB:8,
    TIPOLISTATO_REV_SUP:9,
    TIPOLISTATO_APC1:10,
    TIPOLISTATO_APC2:11,
    TIPOLISTATO_CQC:12,
    TIPOLISTATO_NAUTICA:13,
    TIPOLISTATO_ADR_CONS:14,
    TIPOLISTATO_ABNEW:15
};

//millisecondi di pausa per il passaggio alla risposta successiva
var nextAswTimeout=300;
var nextAswTimer=0;

function Asw(idasw, txt, tra, errlvl, errid, fig){
    this.idasw = idasw; //id della risposta
    this.txt = txt; //testo in italiano
    this.tra = tra; //traduzione in lingua
    this.errlvl = errlvl;
    this.errid = errid;
    this.fig = new Image(); //id della figura
    
    if (fig) {
        this.fig.src = fig;
    }
}

function Qst(idqst, txt, tra, fig, errlvl,errid){
    this.idqst = idqst; //id della domanda
    this.txt = txt; //testo in italiano
    this.tra = tra; //traduzione in lingua
    this.fig = new Image(); //id della figura
    this.errlvl = errlvl;
    this.errid = errid;

    if (fig) {
        this.fig.src = fig;
    }

    this.idAsws = []; //lista delle risposte
    this.SetAsw = function(idasw, txt, tra, errlvl, errid, fig){
        this.idAsws.push(new Asw(idasw, txt, tra, errlvl, errid, fig));
    };

    this.GetAsw = function(i){
        return this.idAsws[i];  
    };
}

function Scheda(listato, lingua, bilingue,tipolist){

    this.listato    = listato;  //listato in uso
    this.lingua     = lingua;   //lingua
    this.bilingue   = bilingue; //bilingue in corso
    this.tipolist   = tipolist;

    this.aswCount = 1;
    this.qstCount = 1;

    this.finished=false;
    this.corrected=false;
    this.started=false;

    this.aswMin=0;

    this.idQsts = []; //lista delle domande

    this.SetQst = function(idqst, txt, tra, fig, errlvl, errid) {
        this.idQsts.push(new Qst(idqst, txt, tra, fig, errlvl, errid));
    };

    this.GetQst = function(i){
        return this.idQsts[i];
    };

    this.rtlMode = function(){
        return (this.lingua == 6); //arabo
    };
}

var scheda;

var risposte = [];
var commenti = [];
var fig_commenti = [];

var currentAsw = 0;
var currentQst = 0;
var currentIdx = 0;
var currentGroup = 0;


var posizioneRiassunto = 0;

var colorToolbar = "#D1E6D7";
var colorSelezionato = "#FF0000";
var colorDeSelezionato = "#ADC5B5";
var colorRispostaRiassunto = "white";
var colorRispostaErrataRiassunto = "red";
var colorRispostaCorrettaRiassunto= "green";

var iMinuti  = 0;
var iSecondi = 0;

//------------------------------------------------------------------
// Funzioni comuni
//------------------------------------------------------------------
function initTest() {

    $('#iRemarks').html('');
    $('#iRemarks').css({'visibility':'hidden'});

    $('#iFigRem').css({'visibility':'hidden'});
    $('#iFigRem').attr({'src': ''});
    $('#iCommLink').attr({'href': '' });

    //oggetti scheda ministeriale
    $('#tbFooter').css({'background':'#D1E6D7'});
    $('#footer').css({'background':'#D1E6D7'});

    $('#navAvanti').css({'visibility':'visible'});
    $('#navIndietro').css({'visibility':'visible'});

    $('#correggi').css({'visibility':'hidden'});
    $('#correzione').css({'visibility':'hidden'});
    $('#spRiassunto').css({'visibility':'hidden'});
    $('#suRiassunto').css({'visibility':'hidden'});
    $('#giuRiassunto').css({'visibility':'hidden'});
    $('#fine').css({'visibility':'hidden'});
    $('#modifica').css({'visibility':'hidden'});
    $('#conferma').css({'visibility':'hidden'});

    for (var i = 1; i <= scheda.aswCount; i++) {
        numOpzione = 10 * i + 1;
        $('#opzione'+numOpzione+"Check").css({'visibility':'hidden'});

        numOpzione = 10 * i + 2;
        $('#opzione'+numOpzione+"Check").css({'visibility':'hidden'});
    }
    
    $('.opzioneRia').css('visibility','hidden');

    $('#iNavigation').css({'height':'34px'});
    $('#iBodySumm').css({'visibility':'hidden'});

    currentAsw = 0;
    currentQst = 0;
    currentIdx = 0;
    
    currentGroup=0;
    
    nextAswTimer=0;
    
    risposte.clear();
    commenti.clear();
    fig_commenti.clear();
    
    scheda.finished=false;
} 

function createScheda() {
    scheda = new Scheda(0, 0, 0, 0);     
}

function loadScheda(tipoScheda,numSchede,bitMaskLen,bitMask) {
    
    createScheda();
    
    $.getJSON("/ecom.dll/scheda",{ tipo:tipoScheda, num:numSchede, bitlen:bitMaskLen, mask:bitMask }, function(json) {

        if (json.schedaValida==1)
        {
            scheda.listato  = json.listato;
            scheda.tipolist = json.tipolistato;
            scheda.lingua   = json.lingua;
            scheda.bilingue = json.bilingue;
    
            scheda.aswMode   = parseInt(json.mq_modo); //0=VEROFALSO==DoubleMode - 1=QUIZ123=SingleMode
            scheda.aswSubMode= parseInt(json.mq_submodo);         
            scheda.qstCount  = parseInt(json.mq_quiz);
            scheda.aswCount  = parseInt(json.mq_questionquiz);
            scheda.aswMin    = parseInt(json.mq_minimo);
            
            for (i=0; i<scheda.qstCount; ++i) {
                scheda.SetQst(json.quesitiid[i],json.quesiti[i],json.quesitiTra[i],json.imgQuesiti[i],json.quesitiTraErr[i].errlvl,json.quesitiTraErr[i].errid);
            }
    
            for (i=0; i<(scheda.aswCount * scheda.qstCount); ++i) {
                var rem = i%scheda.aswCount;
                var qst = (i-rem)/scheda.aswCount;
                scheda.GetQst(qst).SetAsw(json.domandeid[i],json.domande[i],json.domandeTra[i],json.domandeTraErr[i].errlvl,json.domandeTraErr[i].errid,json.domandeImg[i]);
            }
            
            if (tipoScheda == 1 && scheda.tipolist==eTipoListato.TIPOLISTATO_ABNEW)
                $('#scheda_ministeriale').load('/scheda2011.htm',function(){
                    subLoadMin2011(json.numeroScheda,json.nomeCandidato);                
                });
            else if (tipoScheda == 1 && scheda.tipolist==eTipoListato.TIPOLISTATO_AB)
                $('#scheda_ministeriale').load('/scheda.htm',function(){
                    subLoadMin(json.numeroScheda,json.nomeCandidato);                
                });
            else 
                $('#scheda_ministeriale').load('/schedasida.htm',function(){
                    subLoadSida(json.numeroScheda,json.nomeCandidato);                
                });
    
            $('#content').toggle();
            $('#scheda_ministeriale').toggle();
            
            scheda_loaded = true;
        }
        else
            show_user_msg(json.errore,eDlgType.eatAlert);        
    });    
}

function unloadScheda() {
    currentAsw = 0;
    currentQst = 0;
    currentIdx = 0;
    
    $('#scheda_ministeriale').toggle();
    load_content('SchedeCand?action=sel_tipo');
    $('#content').toggle();
    
    scheda_loaded = false;
}

function playAudio(url2)
{
    $('#wrapper').html('<embed src="'+url2+'"  hidden=true autostart=true loop=false>');
}

//------------------------------------------------------------------
// Funzioni scheda ministeriale 2011
//------------------------------------------------------------------
function creaToolbar2011() {
    
    //toolbar superiore
    appo = '<table id=\"tbToolbarUp\" class=\"tbToolbarUp\" cellspacing=0><tr>';
    for (var i = 0; i < NUM_QUESITI_GRUPPO; i++) {
        appo = appo + '<td id=\"tbToolbarUpBtn'+(i)+'\"><a class=\"toolBarRef\" onclick="javascript:bottoneClick2011Up('+i+')" id=\"linkToolbarUp'+i+'\"><span class=\"toolBarRefText\">Domande<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;da&nbsp;&nbsp;' + ((i*10)+1) + '&nbsp;&nbsp;a&nbsp;&nbsp;' +((i+1)*10)+ '</span></a></td>';
    }
    $('#toolbarUp').html(appo);
    

    //toolbar  centrale    
    appo = '<table id=\"tbToolbarCenter\" class=\"tbToolbarCenter\" cellspacing=0><tr>';
    for (var i = 0; i < NUM_QUESITI_TOOLBAR; i++) {        
        appo = appo + '<td id=\"tbToolbarCenterBtn'+i+'\"><a class=\"toolbarRef\" onclick="javascript:bottoneClick2011Center('+i+')" id=\"linkToolbarCenter'+i+'\"><span class=\"toolBarRefText\">'+(i+1)+'</span></a></td>';
    }
    $('#toolbarCenter').html(appo);


    appo = '<table class=\"tbToolbarDown\" cellspacing=0><tr>';
    for (var i = 0; i < (scheda.aswCount * scheda.qstCount); i++) {
        appo = appo + '<a href=\"javascript:bottoneClick(' + i + ')' + '\"><td id=\"bottoneToolbar' + (i) + '\">';
        if ((i+1)<10)
            appo = appo + '<span>0' + (i + 1) + '</span></td>';
        else
            appo = appo + '<span>' + (i + 1) + '</a></span></td>';
    }
    $('#toolbarDown').html(appo);   
}

var countdownTimer;
function countDown(){    
    if ($("#scheda_ministeriale").is(":hidden")) {
        clearTimeout(countdownTimer);        
        return;
    }    

    if ((iMinuti == 0) && (iSecondi == 0)) {
        riassuntoClick2011();
        confermaClick();
        return;
    }
    iSecondi = iSecondi - 1;
    if (iSecondi < 0) {
        iSecondi = 59;
        iMinuti = iMinuti - 1;
    }
    if (iSecondi > 9) {
        strSecondi = "" + iSecondi;
    }
    else {
        strSecondi = "0" + iSecondi;
    }
    if (iMinuti > 9) {
        strMinuti = "" + iMinuti;
    }
    else {
        strMinuti = "0" + iMinuti;
    }
    $('#tempoRimanente').html(' ' + strMinuti + ' : ' + strSecondi);    
    countdownTimer = setTimeout("countDown()", 1000);
}

function indietroClick2011() {
    
    newIdx = currentIdx - 1;
    if (newIdx < 0)
       newIdx = ((scheda.aswCount * scheda.qstCount) - 1);
    
    if (currentGroup != IntDiv(newIdx/NUM_QUESITI_TOOLBAR)) {
        currentGroup = IntDiv(newIdx/NUM_QUESITI_TOOLBAR);
        restyleToolBars2011();       
    }
    
    bottoneClick2011(newIdx);
}

function avantiClick2011() {
    
    newIdx = currentIdx + 1;
    if (newIdx > ((scheda.aswCount * scheda.qstCount) - 1))
       newIdx = 0;
    
    if (currentGroup != IntDiv(newIdx/NUM_QUESITI_TOOLBAR)) {
        currentGroup = IntDiv(newIdx/NUM_QUESITI_TOOLBAR);
        restyleToolBars2011();
    }
    
    bottoneClick2011(newIdx);
}

function resetColor2011() {    
    $('#linkToolbar' + (currentQst - 1)).css({'color': colorDeSelezionato});
    $('#linkToolbarCenter' + IntDiv((currentQst-1)%NUM_QUESITI_TOOLBAR)).css({'color': colorDeSelezionato});
    $('#linkToolbarUp' + IntDiv((currentQst-1)/NUM_QUESITI_TOOLBAR)).css({'color': colorDeSelezionato});    
}
        

function bottoneClick2011Up(gruppo){
    
    var qst = ((NUM_QUESITI_TOOLBAR*gruppo)+1);
    
    if (currentGroup != gruppo) {
        currentGroup = gruppo;
        restyleToolBars2011();        
    }
    
    if (currentAsw!=1)
        currentAsw=1;

    if (currentQst!=qst)
        loadQstM2011(qst);
  
    if(currentIdx!=(qst-1)) 
        currentIdx=(qst-1);
}

function bottoneClick2011Center(numQuesito){
    
    var qst = (IntDiv(currentQst/NUM_QUESITI_TOOLBAR)* NUM_QUESITI_TOOLBAR)+ numQuesito + 1; 
    
    if (currentAsw!=1) //punta sempre 1 nel listato 2011
        currentAsw=1;

    if (currentQst != qst)
        loadQstM2011(qst);
  
    if(currentIdx!=(qst-1)) 
        currentIdx=(qst-1);
}

function bottoneClick2011(numQuesito){
    
    qst = (IntDiv(numQuesito/scheda.aswCount)+1);
    asw = (numQuesito%scheda.aswCount)+1;

    if (currentAsw!=asw)
        currentAsw=asw;

    if (currentQst != qst)
        loadQstM2011(qst);

    if(currentIdx!=numQuesito)  
        currentIdx=numQuesito;  
}

function modificaClick2011(){
    $('#linkToolbar'+ (currentQst - 1)).css('backgroundColor','transparent');
    $('#linkToolbar'+ (currentQst - 1)).css('color','colorDeSelezionato') ;    
    
    $('#conferma').css('visibility','hidden');
    $('#modifica').css('visibility','hidden');
    $('#correggi').css('visibility','hidden');
    
    $('#spRiassunto').css('visibility','hidden');
    $('#suRiassunto').css('visibility','hidden');
    $('#giuRiassunto').css('visibility','hidden');
        
    $('.opzioneRia').css('visibility','hidden');
    
    loadQstM2011(currentQst);
}

function confermaClickExec(){
    window.document.getElementById('conferma').style.visibility = 'hidden';
    window.document.getElementById('modifica').style.visibility = 'hidden';
    window.document.getElementById('correzione').style.visibility = 'visible';
    
    clearTimeout(countdownTimer);
    iMinuti = 0;
    iSecondi = 0;
    
    window.document.getElementById('tempoRimanente').innerHTML = "00:00"; 
}

function confermaClick(){
    confirmEx("Sei sicuro di voler confermare tutte le risposte date ? Con OK non avrai piu' la possibilita' di modificarle.",confermaClickExec);
}

function modificaRiassuntoClick(num){
    obj = window.document.getElementById('colImgRiassunto' + num);
    str = obj.innerHTML.substr(6);
    modificaClick(parseInt(str) - 1);
}


function spostaRiassunto2011(quanto){
    //verfica indietro
    if ((posizioneRiassunto == 0) && (quanto < 0))
        return;

    if (((posizioneRiassunto + NUM_QUESITI_RIASSUNTO2011) == (scheda.qstCount)) && (quanto > 0))
        return;

    posizioneRiassunto = posizioneRiassunto + quanto;
    componiRiassunto2011(posizioneRiassunto);
}

function subLoadMin(numeroScheda,nomeCandidato) {    
    
    initTest();

    $('#numeroScheda').html(numeroScheda);
    $('#nomeCandidato').html(nomeCandidato);
    
    for (var i = 1; i <= scheda.aswCount; i++) {

        numOpzione = 10 * i + 1;
        objImg = window.document.getElementById('iOpzione' + numOpzione);
        objImg.src = "/img/scheda/V_it.gif";

        objImg = window.document.getElementById('opzione' + numOpzione + 'Check');
        objImg.style.visibility = 'hidden';

        numOpzione = 10 * i + 2;
        objImg = window.document.getElementById('iOpzione' + numOpzione);
        objImg.src = "/img/scheda/F_it.gif";

        objImg = window.document.getElementById('opzione' + numOpzione + 'Check');
        objImg.style.visibility = 'hidden';

        $('#opzione'+i+'1').bind('click',{index:(i+'1')},function(e) {
             optionClick(e.data.index);
             selAnswerMin();

        });

        $('#opzione'+i+'2').bind('click',{index:(i+'2')},function(e) {
             optionClick(e.data.index);
             selAnswerMin();
        });
    }

    //reset delle risposte date
    resetRisposte(scheda.aswCount * scheda.qstCount);
    
    iMinuti  = 30;
    iSecondi = 0;
    
    thumbnailviewer.init();
    creaToolbar(0);
    
    //assegno la prima domanda
    currentQst = 1;
    loadQstM(currentQst);
    
    creaTabellaRiassunto();
    
    $(document).unbind('keypress');
    $(document).keypress(function(e)
        {
            switch(e.which)
            {
            case 118:
                optionClick(currentAsw+'1');
            break;
            case 102:
                optionClick(currentAsw+'2');
            break;
            }
            selAnswerMin();
        });     
}

function subLoadMin2011(numeroScheda,nomeCandidato) {  
    
    initTest();

    $('#numeroScheda').html(numeroScheda);
    $('#nomeCandidato').html(nomeCandidato);       
    
    for (var i = 1; i <= scheda.aswCount; i++) {

        numOpzione = 10 * i + 1;
        objImg = window.document.getElementById('iOpzione' + numOpzione);
        objImg.src = "/img/scheda/V_it.gif";

        objImg = window.document.getElementById('opzione' + numOpzione + 'Check');
        objImg.style.visibility = 'hidden';

        numOpzione = 10 * i + 2;
        objImg = window.document.getElementById('iOpzione' + numOpzione);
        objImg.src = "/img/scheda/F_it.gif";

        objImg = window.document.getElementById('opzione' + numOpzione + 'Check');
        objImg.style.visibility = 'hidden';

        $('#opzione'+i+'1').bind('click',{index:(i+'1')},function(e) {
             optionClick(e.data.index);
             selAnswerMin();
        });

        $('#opzione'+i+'2').bind('click',{index:(i+'2')},function(e) {
             optionClick(e.data.index);
             selAnswerMin();
        });
    }

    //reset delle risposte date
    resetRisposte(scheda.aswCount * scheda.qstCount);

    iMinuti = 30;
    iSecondi = 0;

    thumbnailviewer.init();
    creaToolbar2011();

    //assegno la prima domanda
    currentQst = 1;
    loadQstM2011(currentQst);

    creaTabellaRiassunto2011();

    $(document).unbind('keypress');
    $(document).keypress(function(e)
        {
            switch(e.which)
            {
            case 118:
                optionClick(currentAsw+'1');
            break;
            case 102:
                optionClick(currentAsw+'2');
            break;
            }
            selAnswerMin();
        });

    countDown();
}

function subLoadSida(numeroScheda,nomeCandidato) {
    
    initTest();
        
    $('#usType').html(numeroScheda);
    $('#usCand').html(nomeCandidato);
    
    $('#AswGrouper').empty();
        
    for (var i=1; i<=scheda.aswCount;i++) {
        $('#AswGrouper').append(buildAswElement(i,i));

        switch(scheda.aswMode) {
            case eSchedaMode.SingleMode:
                $('#opzione'+i+'Check').height($('#opzione'+i).height());
                $('#opzione'+i+'Check').css({'visibility': 'hidden'});

                $('#opzione'+i).bind('click',{index:(i)},function(e) {
                    optionClick(e.data.index);
                    setNextAswTimer();
                });
            break;
            case eSchedaMode.DoubleMode:

                //restyling scheda AB 2011
                if (scheda.aswSubMode == eSchedaSubMode.ModeVFAB) 
                    restyleFrame();             

                $('#opzione'+i+'1Check').height($('#opzione'+i+'1').height());
                $('#opzione'+i+'1Check').width($('#opzione'+i+'1').width());

                offAsw = $('#opzione'+i+'1').offset();
                $('#opzione'+i+'1Check').offset({ top: offAsw.top, left: offAsw.left });

                $('#opzione'+i+'2Check').width($('#opzione'+i+'2').width());
                $('#opzione'+i+'2Check').height($('#opzione'+i+'2').height());

                offAsw = $('#opzione'+i+'2').offset();
                $('#opzione'+i+'2Check').offset({ top: offAsw.top, left: offAsw.left });

                $('#opzione'+i+'1Check').css({'visibility': 'hidden'});
                $('#opzione'+i+'2Check').css({'visibility': 'hidden'});

                $('#opzione'+i+'1').bind('click',{index:(i+'1')},function(e) {
                    optionClick(e.data.index);
                    setNextAswTimer();
                });

                $('#opzione'+i+'2').bind('click',{index:(i+'2')},function(e) {
                    optionClick(e.data.index);
                    setNextAswTimer();
                });
            break;
        }
    }

    var navBtnCount = 0;

    //personalizzazioni comportamento scheda in funzione della modalita
    switch(scheda.aswMode) {
        case eSchedaMode.SingleMode:
            navBtnCount = scheda.qstCount;
            $(document).unbind('keypress');
            
            if (scheda.aswSubMode == eSchedaSubMode.NumberMode) {
                $(document).keypress(function(e) {
                    switch(e.which)
                    {
                    case 49:
                        optionClick(1);
                        setNextAswTimer();
                    break;
                    case 50:
                        optionClick(2);
                        setNextAswTimer();
                    break;
                    case 51:
                        optionClick(3);
                        setNextAswTimer();
                    break;
                    case 52:
                        optionClick(4);
                        setNextAswTimer();
                    break;                    
                    }
                });
              }
              else {
                $(document).keypress(function(e) {
                    switch(e.which)
                    {
                    case 65:
                    case 97:
                        optionClick(1);
                        setNextAswTimer();
                    break;
                    case 66:
                    case 98:
                        optionClick(2);
                        setNextAswTimer();
                    break;
                    case 67:
                    case 99:
                        optionClick(3);
                        setNextAswTimer();
                    break;
                    case 68:
                    case 100:
                        optionClick(4);
                        setNextAswTimer();
                    break;                    
                    }
                });
              }  
        break;
        case eSchedaMode.DoubleMode:                
            navBtnCount = scheda.aswCount*scheda.qstCount;
            $(document).unbind('keypress');
            $(document).keypress(function(e) {
                switch(e.which)
                {
                case 118:
                    optionClick(currentAsw+'1');
                    setNextAswTimer();                   
                break;
                case 102:
                    optionClick(currentAsw+'2');
                    setNextAswTimer();                    
                break;
                }
            });                    
        break;
    }

    resetRisposte(navBtnCount);

    makeNavBar(navBtnCount);
    restyleNavBar(navBtnCount);

    selAnswer(0); //0-index
    
    //motore di zoom dei segnali
    thumbnailviewer.init();
}

function restyleFrame() {
        
    //restyle proporzioni del corpo scheda
    $('#iBodyImg').css({'width':'330px'});
    $('#iBodyQst').css({'margin':'0 0 0 330px'});
    
    //restyle immagine principale
    $('#iMainImg').css({'left':'75px',
                        'top':'70px'});
    
    
    //restyle immagine/area commenti
    $('#iRemarks').css({'height':'100px'});
    
    $('#iRemImg').css({'left':'115px',
                       'bottom':'35px',
                       'height':'100px',
                       'width':'100px'});
    
    $('#iFigRem').css({'width':'100px',
                       'height':'100px'});
    
    //restyle "X"
    $('img.aswCheck').css({'height':'55px'});
    
    //restyle area domanda
    $('#iQst').css({'height':'50px'});
    
    $('div.isAsw').css({'height':'210px'});
    $('div.iAswTxt').css({'height':'210px'});
    $('div.iAswNum').css({'height':'210px'});
    
    $('div.iAswTxtIta').css({'margin-right':'120px'});
    $('div.iAswTxtIta').css({'font-size':'20pt'});
    
    $('#iQstNum').css({'font-size':'30pt','right':'40px'});
    
    
    $('.iFigQuesito').css({'text-align':'center'});
    $('div.isAswBtn').css({'top':'145px'});
    
    $('.iAswNum').html('');
    
    $('#iQstAudio').remove();
    $('#iQstTxtIta').remove();
    $('#iQstTxtTra').remove();
    //$('#iAswAudio').remove();
    
    $("#iAswAudioRefWrap").css({"position":"absolute","top":-140});
    $("#iAswAudio").css({"height":50});
}



function loadQstM2011(numQst){
    
    resetColor2011();
    
    currentQst = numQst;

    numQst = numQst - 1;

    numDomanda = numQst * scheda.aswCount;
    for (var i = 1; i <= scheda.aswCount; i++) {
        window.document.getElementById('testoDomanda' + i).innerHTML = scheda.GetQst(numQst).GetAsw(i - 1).txt;
        if (scheda.bilingue && scheda.GetQst(numQst).GetAsw(i - 1).tra.length)
            $('#testoDomandaTra'+i).html('(' + scheda.GetQst(numQst).GetAsw(i - 1).tra + ')');            
        if (scheda.rtlMode())
            window.document.getElementById('testoDomandaTra' + i).style.direction = "rtl";
        
        window.document.getElementById('audioDomanda' + i + 'Ref').href = 'javascript:playAudio(\'/ecom.dll/audio?type=2&list=' + scheda.listato + '&lang=' + scheda.lingua + '&id=' + scheda.GetQst(numQst).GetAsw(i - 1).idasw + '\')';

        viewAnswersDouble((numQst * scheda.aswCount) + (i - 1));
    }
        
    var imgPath = scheda.GetQst(numQst).fig.src;
    var imgText = imgPath.substring(imgPath.lastIndexOf("/") + 1);

    if (imgText != "") {
        /*window.document.getElementById('iFigQuesito').innerHTML = 'Figura n.' + imgText.substring(0, imgText.lastIndexOf("G"));*/
        window.document.getElementById('iQuesito').src = scheda.GetQst(numQst).fig.src;
        window.document.getElementById('numQuesito').innerHTML = parseInt(numQst) + 1;
        window.document.getElementById('iQuesito').style.visibility = 'visible';
    }
    else {
        window.document.getElementById('iQuesito').style.visibility = 'hidden';
        /*window.document.getElementById('iFigQuesito').innerHTML = "";*/
        /*window.document.getElementById('iQuesito').src = "";*/        
    }
    
    $('#numQuesito').html(parseInt(numQst) + 1);    
    
    //$('#linkToolbar'+numQst).css('color',colorSelezionato);    
    $('#linkToolbarCenter' + (IntDiv(numQst%NUM_QUESITI_TOOLBAR))).css('color',colorSelezionato);
    //$('#linkToolbarUp' + (IntDiv(numQst/NUM_QUESITI_TOOLBAR))).css('color',colorSelezionato);

    //riaggiorno i controlli della prima maschera
    window.document.getElementById('tbFooter').style.background = "#D1E6D7";
    window.document.getElementById('footer').style.background = "#D1E6D7";

    window.document.getElementById('navAvanti').style.visibility = 'visible';
    window.document.getElementById('navIndietro').style.visibility = 'visible';
    
    $('#navRiassunto').css('visibility','visible');
    $('#txtRiepilogo').css('visibility','visible');
    $('#domPrec').css('visibility','visible');
    $('#domSucc').css('visibility','visible');

    //imposto di default la prima risposta
    currentAsw=1;
}

function creaTabellaRiassunto2011(){
    obj = window.document.getElementById('spRiassunto');
    riga = '<table class=\"tbRiassunto\" cellspacing=0; >\n';
    for (var i = 0; i < NUM_QUESITI_RIASSUNTO2011; i++) {
        riga = riga + '<tr class=\"rigaDomandaRiassunto\" ><td class=\"colImgRiassunto2011\"><div style="position:relative"><span class=\"numRiassunto\" id=\"numRiassunto'+i+'\"></span><img class=\"iRiassunto2011\" id=\"iRiassunto' + i + '\"></div></td>';
        riga = riga + '<td class=\"colDomandaRiassunto2011\" valign=\"top\"><div class=\"colDomandaRiassunto2011Sep\">&nbsp</div><div class=\"testoDomandaRiassunto\"><font id=\"testoDomandaRiassunto' + i + '\">&nbsp;</font></div></td>';
        //riga = riga + '<td id=\"colRispostaRiassunto' + i + VERO + '\" class=\"colRispostaRiassunto\"><div class=\"colDomandaRiassunto2011Sep\">V</div><div style=\"position:relative\";><img class=\"opzioneRia\" id=\"opzioneRia'+ i + VERO + '\" src=\"/img/scheda/X.gif\"><img src=\"/img/scheda/V_it.gif\"></div></td><td id=\"colRispostaRiassunto' + i + FALSO + '\" class=\"colRispostaRiassunto\"><div style=\"position:relative\";><img class=\"opzioneRia\" id=\"opzioneRia'+ i + FALSO + '\" src=\"/img/scheda/X.gif\"><img src=\"/img/scheda/F_it.gif\"></td><td class=\"colBottoniRiassunto\"></div></td></tr>\n';
        riga = riga + '<td valign=\"top\" id=\"colRispostaRiassunto' + i + VERO + '\" class=\"colRispostaRiassunto\"><div class=\"colDomandaRiassunto2011Sep2\">V</div><div style=\"position:relative\"><img class=\"opzioneRia\" id=\"opzioneRia'+ i + VERO + '\" src=\"/img/scheda/spunta_scheda.png\"></div></td><td valign=\"top\" id=\"colRispostaRiassunto' + i + FALSO + '\" class=\"colRispostaRiassunto\"><div class=\"colDomandaRiassunto2011Sep2\">F</div><div style=\"position:relative\"><img class=\"opzioneRia\" id=\"opzioneRia'+ i + FALSO + '\" src=\"/img/scheda/spunta_scheda.png\"></td><td class=\"colBottoniRiassunto\"></div></td></tr>\n';
        //riga = riga + '<td id=\"colRispostaRiassunto' + i + VERO + '\" class=\"colRispostaRiassunto\"><div style=\"position:relative\";><img class=\"opzioneRia\" id=\"opzioneRia'+ i + VERO + '\" src=\"img/scheda/X.gif\"></div></td><td id=\"colRispostaRiassunto' + i + FALSO + '\" class=\"colRispostaRiassunto\"><div style=\"position:relative\";><img class=\"opzioneRia\" id=\"opzioneRia'+ i + FALSO + '\" src=\"img/scheda/X.gif\"></td><td class=\"colBottoniRiassunto\"></div></td></tr>\n';        
    }
    
    riga = riga + '</table>\n';    
    riga = riga + '<div style=\"background-color:#fbc8d9;height:40px\">&nbsp;</div>';
    obj.innerHTML = riga;
}

function riassuntoClick2011(){
    posizioneRiassunto = 0;
    
    window.document.getElementById('conferma').style.visibility = 'visible';
    window.document.getElementById('modifica').style.visibility = 'visible';   

     
    componiRiassunto2011(0);
    
    window.document.getElementById('spRiassunto').style.visibility = 'visible';
    window.document.getElementById('suRiassunto').style.visibility = 'visible';
    window.document.getElementById('giuRiassunto').style.visibility = 'visible';
    window.document.getElementById('tbFooter').style.background = "#FBC8D9";
    window.document.getElementById('footer').style.background = "#FBC8D9";


    window.document.getElementById('navAvanti').style.visibility = 'hidden';
    window.document.getElementById('navIndietro').style.visibility = 'hidden';
    
    $('#navRiassunto').css('visibility','hidden');
    $('#txtRiepilogo').css('visibility','hidden');
    $('#domPrec').css('visibility','hidden');
    $('#domSucc').css('visibility','hidden');
}

function componiRiassunto2011(iniziaDa){
    
    for (var i = iniziaDa; i < NUM_QUESITI_RIASSUNTO2011 + iniziaDa; i++) {
        quesito = i - iniziaDa;
        
        $('#iRiassunto'  + quesito).attr('src',scheda.GetQst(i).fig.src);
        $('#numRiassunto'+ quesito).html(i+1);        
        
        if (scheda.GetQst(i).fig.src != "") 
            $('#iRiassunto'  + quesito).width(65);                    
        else 
            $('#iRiassunto'  + quesito).width(0);        
        
        $('#testoDomandaRiassunto'+quesito).html(scheda.GetQst(i).GetAsw(0).txt);                        
                
        if (risposte[i] == NESSUNA || risposte[i] == (NESSUNA + ERRATA)) {
            $('#opzioneRia'+quesito+VERO).css('visibility','hidden');
            $('#opzioneRia'+quesito+FALSO).css('visibility','hidden');
            
            $('#colRispostaRiassunto'+quesito+VERO).css('background','white');
            $('#colRispostaRiassunto'+quesito+FALSO).css('background','white');            
        }
        else if (risposte[i] == VERO) {
            $('#opzioneRia'+quesito+'V').css('visibility','visible');
            $('#opzioneRia'+quesito+'F').css('visibility','hidden');             
        }
        else if (risposte[i] == FALSO) {
            $('#opzioneRia'+quesito+'V').css('visibility','hidden');
            $('#opzioneRia'+quesito+'F').css('visibility','visible');
        }
        else if (risposte[i] == (VERO + ERRATA)) {
            $('#opzioneRia'+quesito+'V').css('visibility','visible');
            $('#opzioneRia'+quesito+'F').css('visibility','hidden');
            
            $('#colRispostaRiassunto'+quesito+VERO).css('background',colorRispostaErrataRiassunto);
            $('#colRispostaRiassunto'+quesito+FALSO).css('background','white');           

        }
        else if (risposte[i] == (FALSO + ERRATA)) {
            $('#opzioneRia'+quesito+'V').css('visibility','hidden');
            $('#opzioneRia'+quesito+'F').css('visibility','visible');
            
            $('#colRispostaRiassunto'+quesito+FALSO).css('background',colorRispostaErrataRiassunto);
            $('#colRispostaRiassunto'+quesito+VERO).css('background','white');
        }
        else if (risposte[i] == (VERO + CORRETTA)) {
            $('#opzioneRia'+quesito+'V').css('visibility','visible');
            $('#opzioneRia'+quesito+'F').css('visibility','hidden');
            
            $('#colRispostaRiassunto'+quesito+VERO).css('background',colorRispostaCorrettaRiassunto);
            $('#colRispostaRiassunto'+quesito+FALSO).css('background','white');
        }
        else if (risposte[i] == (FALSO + CORRETTA)) {
            $('#opzioneRia'+quesito+'V').css('visibility','hidden');
            $('#opzioneRia'+quesito+'F').css('visibility','visible');
            
            $('#colRispostaRiassunto'+quesito+FALSO).css('background',colorRispostaCorrettaRiassunto);
            $('#colRispostaRiassunto'+quesito+VERO).css('background','white');
        }
    }
}

function correctTestMin() {

    scheda.corrected = true;
    iErrate = 0;
    iCorrette = 0;

    $.getJSON("/ecom.dll/schedacorr", { risposte: risposte }, function(json){

        //flag termine test
        scheda.finished=true;

        for (i = 0; i < (scheda.qstCount*scheda.aswCount); ++i) {
            if (json.risposte[i] == CORRETTA) {
                risposte[i] = risposte[i] + CORRETTA;
                iCorrette++;
            }
            else {
                risposte[i] = risposte[i] + ERRATA;
                iErrate++;
            }

            commenti[i] = json.commenti[i];
        }

        doc = window.document;

        doc.getElementById('correggi').style.visibility = 'visible';
        doc.getElementById('fine').style.visibility = 'visible';

        doc.getElementById('risposteEsatte').innerHTML = "&nbsp;" + iCorrette;
        doc.getElementById('risposteErrate').innerHTML = "&nbsp;" + iErrate;

        if (iCorrette >= scheda.aswMin)
            doc.getElementById('esito').innerHTML = "&nbsp; IDONEO";
        else
            doc.getElementById('esito').innerHTML = "&nbsp; NON IDONEO";

        componiRiassunto(1);
    });
}

function correctTestMin2011() {

    scheda.corrected = true;
    iErrate = 0;
    iCorrette = 0;

    $.getJSON("/ecom.dll/schedacorr", { risposte: risposte }, function(json){

        //flag termine test
        scheda.finished=true;

        for (i = 0; i < (scheda.qstCount*scheda.aswCount); ++i) {
            if (json.risposte[i] == CORRETTA) {
                risposte[i] = risposte[i] + CORRETTA;
                iCorrette++;
            }
            else {
                risposte[i] = risposte[i] + ERRATA;
                iErrate++;
            }

            commenti[i] = json.commenti[i];
        }

        $('#correggi').css('visibility','visible');        
        $('#fine').css('visibility','visible');
        
        $('#risposteEsatte').html("&nbsp;" + iCorrette);
        $('#risposteErrate').html("&nbsp;" + iErrate);
        
        if (iCorrette >= scheda.aswMin)
            $('#esito').html("&nbsp; IDONEO");          
        else
            $('#esito').html("&nbsp; NON IDONEO");

        componiRiassunto2011(0);
    });
}

function selAnswerMin() {
    /* avanti automatico sulla ministeriale=>commentato sembra "scomodo"
    if ((currentAsw + 1)>scheda.aswCount)
        setTimeout(avantiClick,nextAswTimeout);
    else
        currentAsw = (currentAsw + 1);
    */
    if (!((currentAsw + 1)>scheda.aswCount))
        currentAsw = (currentAsw + 1);
}



//------------------------------------------------------------------
// Funzioni scheda SIDA
//------------------------------------------------------------------
// JavaScript Document
function IntDiv(quotient) {
    return ( quotient >= 0 ) ? Math.floor(quotient) : Math.ceil(quotient);
}

//costruzione di un elemento risposta
function buildAswElement(idx,txt) {
    var ret;
    ret="<div id=\"iAsw"+idx+"\" class=\"isAsw\">"+
        "<div id=\"iAsw"+idx+"Btn\" class=\"isAswBtn\">"+
        "<div>";

    switch(scheda.aswMode) {
        case eSchedaMode.SingleMode:
            if (eSchedaSubMode.NumberMode==scheda.aswSubMode) {
                ret = ret + "<span><img id=\"opzione"+idx+"Check\" class=\"opzioneCheck\" src= \"/img/scheda/X.gif\"></span>"+
                            "<span><img class=\"aswCheck\" id=\"opzione"+idx+"\" src=\"/img/scheda/"+idx+"_it.gif\"/></span>";
            }
            else {
                ret = ret + "<span><img id=\"opzione"+idx+"Check\" class=\"opzioneCheck\" src= \"/img/scheda/X.gif\"></span>"+
                            "<span><img class=\"aswCheck\" id=\"opzione"+idx+"\" src=\"/img/scheda/"+String.fromCharCode(64+idx)+"_it.gif\"/></span>";
            }
        break;
        case eSchedaMode.DoubleMode:
            ret = ret + "<span><img id=\"opzione"+idx+"1Check\" class=\"opzioneCheck\" src= \"/img/scheda/X.gif\"></span>"+
                        "<span><img id=\"opzione"+idx+"2Check\" class=\"opzioneCheck\" src= \"/img/scheda/X.gif\"></span>"+
                        "<span><img class=\"aswCheck\" id=\"opzione"+idx+"1\" src=\"/img/scheda/V_it.gif\"/></span>"+
                        "<span><img class=\"aswCheck\" id=\"opzione"+idx+"2\" src=\"/img/scheda/F_it.gif\"/></span>";
        break;
    }

    ret=ret+"</div>"+
            "<div id=\"iAswAudioRefWrap\"><a id=\"iAswAudioRef"+idx+"\"><img id=\"iAswAudio\" src= \"./img/scheda/audio2.png\"/></a></div></div>"+                        
            "<div class=\"iAswNumTxt\" id=\"iAswNumTxt"+idx+"\">"+
                "<div class=\"iAswNum\" id=\"iAswNum"+idx+"\"><span style=\"height: 30px;\">"+idx+"</span><img border=\"0\" class=\"iAswFig\" id=\"iAswFig"+idx+"\" src=\"\"/></div>"+
                "<div class=\"iAswTxt\" id=\"iAswTxt"+idx+"\">"+
                    "<div class=\"iAswTxtIta\" id=\"iAswTxtIta"+idx+"\"></div>"+
                    "<div class=\"iAswTxtTra\" id=\"iAswTxtTra"+idx+"\"></div>"+                    
                "</div>"+
            "</div>"+
         "</div>";

    return ret;
}

function goToNext() {
    
    currentIdx = currentIdx + 1;

    switch(scheda.aswMode) {
        case eSchedaMode.SingleMode:
            if (currentIdx > ((scheda.qstCount) - 1))
                currentIdx = 0;
        break;
        case eSchedaMode.DoubleMode:
            if (currentIdx > ((scheda.aswCount * scheda.qstCount) - 1))
                currentIdx = 0;
        break;
    }
    
    var found=false;
    for(i=currentIdx; i<(scheda.aswCount * scheda.qstCount); i++) {    
        if (risposte[i]==NESSUNA) {
            currentIdx = i;
            found=true;
            break;
        }
    }
    
    if (found==false) {
        for(i=0; i<currentIdx; i++) {    
            if (risposte[i]==NESSUNA) {
                currentIdx = i;                
                break;
            }
        }
    }
        
    selAnswer(currentIdx);
}

function goToBack() {

    currentIdx = currentIdx - 1;

    switch(scheda.aswMode) {
        case eSchedaMode.SingleMode:
            if (currentIdx < 0)
                currentIdx = ((scheda.qstCount) - 1);
        break;
        case eSchedaMode.DoubleMode:
            if (currentIdx < 0)
                currentIdx = ((scheda.aswCount * scheda.qstCount) - 1);
        break;
    }
        
    var found=false;
    for(i=currentIdx; i>=0; i--) {    
        if (risposte[i]==NESSUNA) {
            currentIdx = i;
            found=true;
            break;
        }
    }
    
    if (found==false) {
        for(i=(scheda.aswCount * scheda.qstCount); i>currentIdx; i--) {    
            if (risposte[i]==NESSUNA) {
                currentIdx = i;                
                break;
            }
        }
    }
    
    selAnswer(currentIdx);
}

function selAnswerNext(){

    if (checkAnswers()) {
        if (scheda.corrected==false)
            confirmEx("Test finito, correggo tutte le risposte date?",correctTest);            
        else        
            showSummary();
    }
    else {
        goToNext();
    }
    
    unsetNextAswTimer();   
}

function selAnswerBack(){
    
    if (checkAnswers()) {
        if (scheda.corrected==false) 
            confirmEx("Test finito, correggo tutte le risposte date?",correctTest);
        else 
            showSummary();
    }
    else 
        goToBack();
        
    unsetNextAswTimer();
}

function showSummary() {
    $('#iNavigation').css({'height':'0px'});

    $('#iBodySumm').width($('#iBody').width());
    $('#iBodySumm').height($('#iBody').height());
    /*
    $('#iBodySumm').offset($('#iBody').offset());
    */
    $('#iBodySumm').css({'top':'0px'});
    $('#iBodySumm').css({'visibility':'visible'});
}

function showRemarks(idx) {

    if (commenti[idx]) {
        $('#iRemarks').html(commenti[idx]);
        $('#iRemarks').css({'visibility':'visible'});
    }
    else {
        $('#iRemarks').html('');
        $('#iRemarks').css({'visibility':'hidden'});
    }

    var imgPath = fig_commenti[idx];
    var imgText = "";
    if ((typeof imgPath!="undefined") && (imgPath!=""))
        imgText = imgPath.substring(imgPath.lastIndexOf("/")+1);

    if (imgText!="") {
        $('#iFigRem').css({'visibility':'visible'});
        $('#iFigRem').attr({'src': fig_commenti[idx]});
        $('#iRemImgFig').html('Figura n.'+imgText.substring(0,imgText.lastIndexOf("m")));
        $('#iCommLink').attr({'href': fig_commenti[idx].replace("m.","g.")});
        $('#iRemImgFig').html('Figura n.'+imgText.substring(0,imgText.lastIndexOf("m")));
    }
    else {
        $('#iFigRem').css({'visibility':'hidden'});
        $('#iFigRem').attr({'src': ''});
        $('#iCommLink').attr({'href': '' });
        $('#iRemImgFig').html('');
    }
}
function selAnswer(idx) {

    var qst,asw;
    
    //deselezione sulla barra di navigazione
    $('.iNavBtn').css({'border':'1px solid #000000'});

    //logica selezione domanda
    switch(scheda.aswMode) {
        case eSchedaMode.SingleMode:
            qst=idx+1;
            asw=1;

            $('#iNavBtn'+idx).css({'border':'1px solid #ffff00'});
        break;
        case eSchedaMode.DoubleMode:
            qst = (IntDiv(idx/scheda.aswCount)+1);
            asw = (idx%scheda.aswCount)+1;

            $('#iNavBtn'+idx).css({'border':'1px solid #ffff00'});
        break;
    }

    if (!scheda.finished) {        
        if (scheda.aswMode == eSchedaMode.DoubleMode) {
            $('#iAswNum' + currentAsw).css({'background': 'url(../img/scheda/bg_asw_num.jpg)'});
            $('#iAswTxt' + currentAsw).css({'background': 'url(../img/scheda/bg_asw_txt.jpg)'});
    
            $('#iAswNum' + asw).css({'background': 'url(../img/scheda/bg_asw_num_sel.jpg)'});
            $('#iAswTxt' + asw).css({'background': 'url(../img/scheda/bg_asw_txt_sel.jpg)'});
            
        }
    }
    else {
        showRemarks(idx);
    }

    if (currentAsw!=asw)
        currentAsw=asw;

    if (currentQst != qst)
        loadQst(qst);

    if(currentIdx!=idx) {
        currentIdx=idx;
    }
    
    if (checkAnswers() && scheda.corrected==false) 
        confirmEx("Test finito, correggo tutte le risposte date?",correctTest);
}

//selezione della risposta relativa sempre alla stessa domanda (non dalla navigazione)
//idx 0-indexed (0,1,2)
function selAnswerLiteDouble(idx) {
    return;

    var newIdx = ((currentQst-1)*scheda.aswCount)+idx;

    if (idx != (currentIdx % scheda.aswCount)) {

        //deselezione/selezione navigazione
        $('#iNavBtn' + currentIdx).css({'border': '1px solid #000000'});
        $('#iNavBtn' + newIdx).css({'border': '1px solid #ffff00'});

        if (!scheda.finished) {
            $('#iAswNum' + currentAsw).css({'background': 'url(../img/scheda/bg_asw_num.jpg)'});
            $('#iAswTxt' + currentAsw).css({'background': 'url(../img/scheda/bg_asw_txt.jpg)'});


            //deselzione/selezione sfondo risposta
            $('#iAswNum' + (idx + 1)).css({'background': 'url(../img/scheda/bg_asw_num_sel.jpg)'});
            $('#iAswTxt' + (idx + 1)).css({'background': 'url(../img/scheda/bg_asw_txt_sel.jpg)'});
        }

        if (currentAsw != (idx + 1))
            currentAsw = (idx + 1);
        if (currentIdx != newIdx)
            currentIdx = newIdx;
    }
    else {
        if (scheda.finished)
            showRemarks(idx);
    }

    $('#iNavBtn'+newIdx).css({'background':'#ffd42b'});
}

function selAnswerLiteSingle(idx) {
    if (currentAsw != (idx + 1))
        currentAsw = (idx + 1);

    $('#iNavBtn'+(currentQst-1)).css({'background':'#ffd42b'});
}


function restyleNavBar(countBtns) {

    for(i=0;i<countBtns;i++) {
        var risp=risposte[i];

        if (risp.charAt(0)==NESSUNA) {
            $('#iNavBtn' + i).css({'background': '#d4d4d4'});
            $('#iNavBtn' + i).css({'border': '1px solid #000000'});
        }

        if (risp.charAt(1)==CORRETTA)
            $('#iNavBtn'+i).css({'background':'#00ff00'});

        if (risp.charAt(1)==ERRATA)
            $('#iNavBtn'+i).css({'background':'#ff0000'});
    }
}

function restyleToolBars() {
    $('#bottoneToolbar'+(currentQst-1)).css({'background':colorToolbar});
    $('#linkToolbar'+(currentQst-1)).css({'color':'white'});
}

function restyleToolBars2011() {
    
    $('#tbToolbarCenter  td').css({'background':'white'});
    for (var i = 0; i < NUM_QUESITI_TOOLBAR; i++) {        
        var idx = (currentGroup*10)+(i); 
        
        $('#linkToolbarCenter'+i).html('<span class=\"toolBarRefText\">'+(idx+1)+'</span>');
        if (risposte[idx] != NESSUNA)            
            $('#tbToolbarCenterBtn'+i).css({'background':colorToolbar});
        
    }
        
    for(i=0;i<NUM_QUESITI_GRUPPO;i++) {
        complete=true;
        for(j=0;j<NUM_QUESITI_TOOLBAR;j++) {
            if (risposte[(i*10)+j] == NESSUNA)
                complete=false;
            else
                $('#bottoneToolbar'+((i*10)+j)).css({'background':colorToolbar});
        }        
        if (complete)
            $('#tbToolbarUpBtn'+i).css({'background':colorToolbar});
    }
}

function makeNavBar(countBtns) {

    var offMain = $('#iNavigation').offset();

    //impostati di default, width e height non sono ancora valorizzati
    var w = 972; //$('#iNavigation').width();
    var h = 34;  //$('#iNavigation').height();

    var pmarg_y = 0.6;

    var perc  = 20;
    var perc2 = 20;

    var sp11,sp12;
    var sp21,sp22;
    var singleCellW,singleBtn;

    //primo calcolo
    singleCellW = IntDiv(w/scheda.qstCount);
    sp12 = IntDiv((w-(singleCellW*scheda.qstCount))/2);
    sp11 = IntDiv((singleCellW*perc/200));

    singleCellW = singleCellW - (sp11*2);

    switch(scheda.aswMode) {
        case eSchedaMode.SingleMode:
            //tutto azzero vale solo il primo calcolo
            singleBtn = singleCellW;
            sp22 = 0;
            sp21 = 0;
        break;
        case eSchedaMode.DoubleMode:
            singleBtn = IntDiv(singleCellW/scheda.aswCount);
            sp22 = IntDiv((singleCellW-(singleBtn*scheda.aswCount))/2);
            sp21 = IntDiv((singleBtn*perc2/200));

            singleBtn = singleBtn - (sp21*2);
        break;
    }

    var off_x=sp12 - (sp11+sp22+sp21);

    for(i=0;i<countBtns;i++) {
        var idBtn = "iNavBtn"+i;

        var t ="<div id=\""+idBtn+"\" class=\"iNavBtn\" ></div>";

        var mar_y = IntDiv(h*pmarg_y);
        var off_y = IntDiv(mar_y/2);
        var heightBtn = h-mar_y;

        $('#iNavigation').append(t);

        //dimensionamento
        $('#'+idBtn).height(heightBtn);
        $('#'+idBtn).width(singleBtn);

        if ((i%scheda.aswCount)==0 || (scheda.aswMode==eSchedaMode.SingleMode))
            off_x=off_x+((sp11+sp22+sp21)*2);
        else
            off_x=off_x+sp21+sp21;

        //posizionamento
        $('#'+idBtn).offset({ top: offMain.top+off_y, left: offMain.left+off_x });

        off_x = off_x + singleBtn;

        $('#'+idBtn).bind('click',{index:i},function(e) {
            selAnswer(e.data.index);
        });
    }
}

function resizeQstFontSize(txt,lingua) {    
    
    var fontSizeIta = new Array(14,16,18);
    var fontSizeTra;    
    if ((lingua==6) || (lingua==7))
        fontSizeTra = new Array(12,14,16);
    else
        fontSizeTra = new Array(10,12,14);
        
    if (txt.length>200) {
        $('#iQstTxtIta').css('font-size',fontSizeIta[0]+'px');       
        $('#iQstTxtTra').css('font-size',fontSizeTra[0]+'px');        
    }
    else if (txt.length>100) {
        $('#iQstTxtIta').css('font-size',fontSizeIta[1]+'px');
        $('#iQstTxtTra').css('font-size',fontSizeTra[1]+'px');
    }
    else {
        $('#iQstTxtIta').css('font-size',fontSizeIta[2]+'px');
        $('#iQstTxtTra').css('font-size',fontSizeTra[2]+'px');
    }
}

function resizeAswFontSize(txt,lingua) {
    
    var fontSizeIta; 
    var fontSizeTra;    
    
    if (scheda.aswSubMode == eSchedaSubMode.ModeVFAB) {
        fontSizeIta = new Array(14,16,18);
        if ((lingua==6) || (lingua==7))
            fontSizeTra = new Array(14,16,18);
        else
            fontSizeTra = new Array(12,14,16);
    }
    else {
        fontSizeIta = new Array(10,12,14);
        if ((lingua==6) || (lingua==7))
            fontSizeTra = new Array(10,12,14);
        else
            fontSizeTra = new Array(8,10,12);
    }
    
    if (txt.length>200) {
        $('#iAswTxtIta' + i).css('font-size',fontSizeIta[0]+'px');        
        $('#iAswTxtTra' + i).css('font-size',fontSizeTra[0]+'px');
    }
    else if (txt.length>100) {
        $('#iAswTxtIta' + i).css('font-size',fontSizeIta[1]+'px');
        $('#iAswTxtTra' + i).css('font-size',fontSizeTra[1]+'px');        
    }
    else {
        $('#iAswTxtIta' + i).css('font-size',fontSizeIta[2]+'px');
        $('#iAswTxtTra' + i).css('font-size',fontSizeTra[2]+'px');        
    }   
}

function getErrImage(level) {
    return "/img/scheda/att_"+level+".png";
}

function showTraErr(url,lvl) {
    $.get(url, function(data) {
        if (lvl<5)
            $.modaldialog.warning(data);
        else
            $.modaldialog.error(data);
    });    
}

function warningEx(txt,callYes) {
    var options =  {
        timeout: 0,
        width: 350,
        callbackFnc: callYes
	};
        
    $.modaldialog.warning(txt,options);    
}

function confirmEx(txt,callYes) {
    var options =  {
        timeout: 0,
        width: 350,
        callbackFnc: callYes
	};
        
    $.modaldialog.prompt(txt,options);    
}


function successEx(txt) {
    var options =  {        
		timeout: 0,
        width: 350
	};
        
    $.modaldialog.success(txt,options);    
}

function loadQst(numQst) {

    currentQst = numQst;

    var idx=numQst-1;

    $('#iQstNum').text(numQst);
    
    $('#iQstTxtIta').text(scheda.GetQst(idx).txt);
        
    resizeQstFontSize(scheda.GetQst(idx).txt,scheda.lingua);
    
    $('#iQstAudioRef').attr({
        'href': 'javascript:playAudio(\'/ecom.dll/audio?type=1&list=' + scheda.listato + '&lang=' + scheda.lingua + '&id=' + scheda.GetQst(idx).idqst + '\')'
    });
    
    if (parseInt(scheda.GetQst(idx).errlvl)>1) {
        $('#iQstTxtTra').text(scheda.GetQst(idx).tra);       
    }
    else {
        $('#iQstTxtTra').text(scheda.GetQst(idx).tra);
    }
            

    if (scheda.rtlMode())
        $('#iQstTxtTra').css({'direction':'rtl','text-align':'right'});

    for (i = 1; i <= scheda.aswCount; i++) {
       
        resizeAswFontSize(scheda.GetQst(idx).GetAsw(i - 1).txt,scheda.lingua);
        
        $('#iAswTxtIta' + i).text(scheda.GetQst(idx).GetAsw(i - 1).txt);

        if ($('#iAswFig'+i).length) //se non è nella modalità di risposta singola
        {
            var imgPath = scheda.GetQst(idx).GetAsw(i - 1).fig.src;
            var imgText = imgPath.substring(imgPath.lastIndexOf("/")+1);
            
            if (imgText!="") {
                $('#iAswFig'+i).css({'visibility':'visible'});
                $('#iAswFig'+i).attr({'src': scheda.GetQst(idx).GetAsw(i - 1).fig.src});
                $('#iAswNum'+i).css({'width':'76px'});
                $('#iAswTxt'+i).css({'margin':'0 0 0 76px'});                           
            }
            else {
                $('#iAswFig'+i).css({'visibility':'hidden'});
                $('#iAswFig'+i).attr({'src': ''});   
                $('#iAswNum'+i).css({'width':'30px'});
                $('#iAswTxt'+i).css({'margin':'0 0 0 30px'});         
            }
        }
       
        //controllo errori di traduzione 
        if (parseInt(scheda.GetQst(idx).GetAsw(i-1).errlvl)>1) {
            $('#iAswTxtTra' + i).text(scheda.GetQst(idx).GetAsw(i - 1).tra);
            $('#iAswTxtTra' + i).prepend("<a style=\"cursor:pointer\" onclick='javascript:showTraErr(\"/ecom.dll/errtra?type=1&list=" + scheda.listato + "&lang=" + scheda.lingua + "&id=" + scheda.GetQst(idx).GetAsw(i-1).errid+"\","+scheda.GetQst(idx).GetAsw(i-1).errlvl+")'><img id=\"iAswErrTra\" src=\""+getErrImage(parseInt(scheda.GetQst(idx).GetAsw(i-1).errlvl))+"\"/></a> ");
            
            //lavora con tutti gli elementi già creati...
            
            //$('#modalWnd').jqm({ajax:'/ecom.dll/errtra?type=1&list=' + scheda.listato + '&lang=' + scheda.lingua + '&id=' + scheda.GetQst(idx).GetAsw(i-1).errid, trigger: 'a.jqModal'});
        }
        else {
            $('#iAswTxtTra' + i).empty();
            $('#modalWnd').empty();                
            $('#iAswTxtTra' + i).text(scheda.GetQst(idx).GetAsw(i - 1).tra);
        }
        
        $('#iAswAudioRef'+i).attr({
            'href': 'javascript:playAudio(\'/ecom.dll/audio?type=2&list=' + scheda.listato + '&lang=' + scheda.lingua + '&id=' + scheda.GetQst(idx).GetAsw(i - 1).idasw + '\')'
        });

        //per le schede a modalità singola tutte le risposte sono selezionate
        if (scheda.aswMode == eSchedaMode.SingleMode) {
            $('#iAswNum' + (i)).css({'background': 'url(../img/scheda/bg_asw_num_sel.jpg)'});
            $('#iAswTxt' + (i)).css({'background': 'url(../img/scheda/bg_asw_txt_sel.jpg)'  });
        }

        if (scheda.rtlMode())
            $('#iAswTxtTra' + i).css({'direction':'rtl','text-align':'right'});

        if (scheda.finished) {

            switch(scheda.aswMode) {
                case eSchedaMode.SingleMode:
                    var risp = risposte[currentQst - 1];

                    if (risp.charAt(1)==CORRETTA && ((parseInt(risp.charAt(0))==i) || (((risp.charAt(0).charCodeAt(0))-64)==i))) {
                        $('#iAswNum' + i).css({'background': 'url(../img/scheda/bg_asw_num_ok.jpg)'});
                        $('#iAswTxt' + i).css({'background': 'url(../img/scheda/bg_asw_txt_ok.jpg)'});
                    }

                    if (risp.charAt(1)==ERRATA) {
                        if ((parseInt(risp.charAt(0))==i) || (((risp.charAt(0).charCodeAt(0))-64)==i)) {                                                             
                            $('#iAswNum' + i).css({'background': 'url(../img/scheda/bg_asw_num_ko.jpg)'});
                            $('#iAswTxt' + i).css({'background': 'url(../img/scheda/bg_asw_txt_ko.jpg)'});
                        }
                        if ((parseInt(risp.charAt(2))==i) || (((risp.charAt(2).charCodeAt(0))-64)==i)) {
                            $('#iAswNum' + i).css({'background': 'url(../img/scheda/bg_asw_num_ok.jpg)'});
                            $('#iAswTxt' + i).css({'background': 'url(../img/scheda/bg_asw_txt_ok.jpg)'});
                        }
                    }
                break;
                case eSchedaMode.DoubleMode:
                    //calcolo dell'indice relativo alla risposta data
                    var rispid = ((currentQst - 1) * scheda.aswCount) + (parseInt(i,10)-1);

                    if (risposte[rispid] == (VERO + CORRETTA) || risposte[rispid] == (FALSO + CORRETTA) || risposte[rispid] == ('1' + CORRETTA) || risposte[rispid] == ('2' + CORRETTA) || risposte[rispid] == ('3' + CORRETTA)) {
                        $('#iAswNum' + i).css({'background': 'url(../img/scheda/bg_asw_num_ok.jpg)'});
                        $('#iAswTxt' + i).css({'background': 'url(../img/scheda/bg_asw_txt_ok.jpg)'});
                    }

                    if (risposte[rispid] == (VERO + ERRATA) || risposte[rispid] == (FALSO + ERRATA) || risposte[rispid] == (NESSUNA + ERRATA) || risposte[rispid] == ('1' + ERRATA) || risposte[rispid] == ('2' + ERRATA) || risposte[rispid] == ('3' + ERRATA)) {
                        $('#iAswNum' + i).css({'background': 'url(../img/scheda/bg_asw_num_ko.jpg)'});
                        $('#iAswTxt' + i).css({'background': 'url(../img/scheda/bg_asw_txt_ko.jpg)'});
                    }
                break;
            }
        }

        if (scheda.aswMode==eSchedaMode.DoubleMode)
            viewAnswersDouble((idx*scheda.aswCount)+(i-1));
    }

    if (scheda.aswMode==eSchedaMode.SingleMode)
        viewAnswersSingle(idx);

    var imgPath = scheda.GetQst(idx).fig.src;
    var imgText = imgPath.substring(imgPath.lastIndexOf("/")+1);

    if (imgText!="") {
        $('#iQuesito').css({'visibility':'visible'});
        $('#iQuesito').attr({'src': scheda.GetQst(idx).fig.src});
        $('#iBodyImgFig').html('Figura n.'+imgText.substring(0,imgText.lastIndexOf("m")));
        $('#iQuesitoLink').attr({'href': scheda.GetQst(idx).fig.src.replace("m.","g.")});               
    }
    else {
        $('#iQuesito').css({'visibility':'hidden'});
        $('#iQuesito').attr({'src': ''});
        $('#iQuesitoLink').attr({'href': ''});
        $('#iBodyImgFig').html('');
    }
}

//numOpzione es: 11 o 12 o 21...
function optionClickLite(numOpzione){

    numOpzione= "" + numOpzione;

    vis = $('#opzione' + numOpzione + 'Check').css('visibility');

    if ((vis=='')||(vis=='hidden')) {

        $('#opzione' + numOpzione + 'Check').css({'visibility': 'visible'});

        switch(scheda.aswMode) {
            case eSchedaMode.SingleMode:
                if (numOpzione!=currentAsw && !scheda.finished)
                    $('#opzione' + currentAsw + 'Check').css({'visibility': 'hidden'});
            break;
        }
    }   
}

//numOpzione es: 11 o 12 o 21...
function optionClick(numOpzione){

    numOpzione= "" + numOpzione;

    if (!scheda.finished)
        storeAnswer(numOpzione.substr(0,1), numOpzione.substr(1,1));

    vis = $('#opzione' + numOpzione + 'Check').css('visibility');

    if ((vis=='')||(vis=='hidden')) {

        switch(scheda.aswMode) {
            case eSchedaMode.SingleMode:
                $('.opzioneCheck').css({'visibility': 'hidden'});
                $('#opzione' + numOpzione + 'Check').css({'visibility': 'visible'});
            break;
            case eSchedaMode.DoubleMode:
                $('#opzione' + numOpzione + 'Check').css({'visibility': 'visible'});
                numOpzione=parseInt(numOpzione,10);
                resto = numOpzione%2;
                if (resto==1)
                    numOpzione=numOpzione+1;

                if (resto==0)
                    numOpzione=numOpzione-1;

                $('#opzione' + numOpzione + 'Check').css({'visibility': 'hidden'});
            break;
        }
    }

    if (!scheda.corrected)
        $('#iNavBtn'+currentIdx).css({'background':'#ffd42b'});

    //solo per la scheda ministeriale c'e' questa evidenziazione del controllo
    if (tipo_scheda==1 && allAnswers()) {
        if (scheda.tipolist==eTipoListato.TIPOLISTATO_ABNEW)
            restyleToolBars2011();
        else
            restyleToolBars();
    }
}

function allAnswers(){
  var j = parseInt((currentQst-1)*scheda.aswCount);
  for (var i=0; i<scheda.aswCount;i++){
    if (risposte[j+i]==NESSUNA){
      return(false);
    }
  }
  return(true);
}

//memorizzazione della risposta data nell'array delle risposte
function storeAnswer(numDom, vero) {
    switch(scheda.aswMode) {
            case eSchedaMode.SingleMode:
                if (scheda.aswSubMode==eSchedaSubMode.NumberMode)
                    risposte[currentQst-1]= numDom;
                else
                    risposte[currentQst-1]= String.fromCharCode(64+parseInt(numDom));                    
            break;
            case eSchedaMode.DoubleMode:
                //calcolo dell'indice relativo alla risposta data
                idxAsw = ((currentQst-1) * scheda.aswCount) + (parseInt(numDom,10)-1);
                risposte[idxAsw]= (vero=='1') ? VERO : FALSO;
                
                currentIdx = idxAsw;
            break;
        }
  
    if (scheda.started==false)
        scheda.started=true;
}

//verifica se sono state date tutte le risposte
function checkAnswers() {
    for(i=0; i<(scheda.aswCount * scheda.qstCount); i++)
        if (risposte[i]==NESSUNA)
            return false;

    return true;
}

function viewAnswersSingle(idx){

    var risp=risposte[idx];

    for(i=1;i<=scheda.aswCount;i++)
        $('#opzione' + i + 'Check').css({'visibility': 'hidden'});
    
    if (scheda.aswSubMode == eSchedaSubMode.NumberMode) {
        switch(risp.charAt(0)) {
            case '1':   optionClickLite('1');       break;
            case '2':   optionClickLite('2');       break;
            case '3':   optionClickLite('3');       break;
            case '4':   optionClickLite('4');       break;        
        }   
    }
    else {
        switch(risp.charAt(0)) {
            case 'A':   optionClickLite('1');       break;
            case 'B':   optionClickLite('2');       break;
            case 'C':   optionClickLite('3');       break;
            case 'D':   optionClickLite('4');       break;        
        }        
    }
    
}
//visualizzazione delle risposte date in funzione dei valore contenuti nell'
//array delle risposte
function viewAnswersDouble(idx){
    var asw = (idx%scheda.aswCount)+1;

    if (risposte[idx]==NESSUNA){
        $('#opzione'+asw+'1Check').css({'visibility':'hidden'});
        $('#opzione'+asw+'2Check').css({'visibility':'hidden'});
    }

    var risp=risposte[idx];

    if (risp.charAt(0) == 'V') {
        optionClick(asw+'1');
    }

    if (risp.charAt(0) == 'F') {
        optionClick(asw+'2');
    }
}

//correzione del test completato
function correctTest() {

    scheda.corrected = true;
    iErrate=0;
    iCorrette=0;

    $.getJSON("/ecom.dll/schedacorr", { risposte: risposte }, function(json) {

        //flag termine test
        scheda.finished=true;

        for (i=0; i<risposte.length; ++i) {
          if (json.risposte[i]==CORRETTA) {
            risposte[i] = risposte[i] + json.risposte[i];
            iCorrette++;
          }
          else {
            risposte[i] = risposte[i] + json.risposte[i];
            iErrate++;
          }
          commenti[i] = json.commenti[i];
          fig_commenti[i] = json.fig_commenti[i];
        }

        //formattazione esito
        $('#iSummCounter1').text('Risposte corrette:'+iCorrette);
        $('#iSummCounter2').text('Risposte errate:'+iErrate);

        if (iCorrette < scheda.aswMin) {
            $('#iSummResult2').text('NON SUFFICIENTE');
            $('#iSummResult3').text('è necessario seguire le lezioni a scuola, leggere bene i commenti agli errori e continuare ad esercitarsi');
        }
        else {
            $('#iSummResult2').text('SUFFICIENTE');
            $('#iSummResult3').text('congratulazioni, è necessario continuare ad esercitarsi con costanza per completare il programma di studio');
        }

        switch(scheda.aswMode) {
            case eSchedaMode.SingleMode:
                navBtnCount = scheda.qstCount;
            break;
            case eSchedaMode.DoubleMode:
                navBtnCount = scheda.aswCount*scheda.qstCount;
            break;
        }

        selAnswer(0);

        restyleNavBar(navBtnCount);

        successEx("Correzione terminata, clicca i pulsanti rossi della barra per la visione degli errori fatti.");
    });
}


function resetRisposte(count) {
    for (var i = 0; i < count; i++)
        risposte[i] = NESSUNA;
}

function exitTest() {
            
    if (scheda.started) {
        if (!scheda.corrected) {
            warningEx("Attenzione, il test non è ancora finito, correggo comunque la scheda?",correctTest);            
        }
        else if (!scheda.finished) {
            warningEx("Attenzione, il test non è ancora finito, esco comunque?",unloadScheda);            
        }
        else {
            unloadScheda();            
        }
    }  
    else {
        confirmEx("La scheda è stata aperta, ma non iniziata? Esco comunque?",unloadScheda);        
    }     
}




//------------------------------------------------------------------
// Funzioni scheda ministeriale 
//------------------------------------------------------------------
function avantiClick(){
    if (currentQst == scheda.qstCount) {
        riassuntoClick();
        return;
    }

    $('#linkToolbar' + (currentQst - 1)).css({
        'color': colorDeSelezionato
    });
    currentQst = currentQst + 1;
    loadQstM(currentQst);
}

function bottoneClick(numQuesito){
    window.document.getElementById('linkToolbar' + (currentQst - 1)).style.color = colorDeSelezionato;
    currentQst = numQuesito + 1;
    loadQstM(currentQst);
}


function componiRiassunto(iniziaDa){

    for (var i = iniziaDa; i < NUM_QUESITI_RIASSUNTO + iniziaDa; i++) {
        quesito = i - iniziaDa;
        window.document.getElementById('colImgRiassunto' + quesito).innerHTML = "&nbsp;" + (i);
        window.document.getElementById('testoQuesitoRiassunto' + quesito).innerHTML = scheda.GetQst(i - 1).txt;
        window.document.getElementById('iRiassunto' + quesito).src = scheda.GetQst(i - 1).fig.src;

        if (scheda.GetQst(i - 1).fig.src != "")
            window.document.getElementById('iRiassunto' + quesito).style.width = '80px';
        else
            window.document.getElementById('iRiassunto' + quesito).style.width = '0px';

        for (var j = 0; j < scheda.aswCount; j++) {
            numDomanda = "" + quesito + (j + 1);
            iDomanda = ((i - 1) * scheda.aswCount) + j;
            window.document.getElementById('testoDomandaRiassunto' + numDomanda).innerHTML = scheda.GetQst(i - 1).GetAsw(j).txt;
            if (risposte[iDomanda] == NESSUNA || risposte[iDomanda] == (NESSUNA + ERRATA)) {
                window.document.getElementById('colRispostaRiassunto' + numDomanda + VERO).style.background = "white";
                window.document.getElementById('colRispostaRiassunto' + numDomanda + FALSO).style.background = "white";
                window.document.getElementById('colRispostaRiassunto' + numDomanda + VERO).innerHTML = "&nbsp;";
            }
            else {
                if (risposte[iDomanda] == VERO) {
                    window.document.getElementById('colRispostaRiassunto' + numDomanda + risposte[iDomanda]).style.background = "#0099CC";
                    window.document.getElementById('colRispostaRiassunto' + numDomanda + FALSO).style.background = "white";
                }
                else
                    if (risposte[iDomanda] == FALSO) {
                        window.document.getElementById('colRispostaRiassunto' + numDomanda + risposte[iDomanda]).style.background = "#0099CC";
                        window.document.getElementById('colRispostaRiassunto' + numDomanda + VERO).style.background = "white";
                    }
                    else
                        if (risposte[iDomanda] == (VERO + ERRATA)) {
                            window.document.getElementById('colRispostaRiassunto' + numDomanda + VERO).style.background = colorRispostaErrataRiassunto;
                            window.document.getElementById('colRispostaRiassunto' + numDomanda + VERO).style.color = "white";
                            //window.document.getElementById('colRispostaRiassunto'+numDomanda+VERO).innerHTML=commenti[iDomanda];
                            window.document.getElementById('colRispostaRiassunto' + numDomanda + FALSO).style.background = "white";
                            window.document.getElementById('colRispostaRiassunto' + numDomanda + FALSO).innerHTML = "&nbsp;";
                        }
                        else
                            if (risposte[iDomanda] == (FALSO + ERRATA)) {
                                window.document.getElementById('colRispostaRiassunto' + numDomanda + FALSO).style.background = colorRispostaErrataRiassunto;
                                //window.document.getElementById('colRispostaRiassunto'+numDomanda+FALSO).innerHTML=commenti[iDomanda];
                                window.document.getElementById('colRispostaRiassunto' + numDomanda + FALSO).style.color = "white";
                                window.document.getElementById('colRispostaRiassunto' + numDomanda + VERO).style.background = "white";
                                window.document.getElementById('colRispostaRiassunto' + numDomanda + VERO).innerHTML = "&nbsp;";
                            }
                            else
                                if (risposte[iDomanda] == (VERO + CORRETTA)) {
                                    window.document.getElementById('colRispostaRiassunto' + numDomanda + VERO).style.background = colorRispostaCorrettaRiassunto;
                                    window.document.getElementById('colRispostaRiassunto' + numDomanda + FALSO).style.background = "white";
                                    window.document.getElementById('colRispostaRiassunto' + numDomanda + FALSO).innerHTML = "&nbsp;";
                                }
                                else
                                    if (risposte[iDomanda] == (FALSO + CORRETTA)) {
                                        window.document.getElementById('colRispostaRiassunto' + numDomanda + FALSO).style.background = colorRispostaCorrettaRiassunto;
                                        window.document.getElementById('colRispostaRiassunto' + numDomanda + VERO).style.background = "white";
                                        window.document.getElementById('colRispostaRiassunto' + numDomanda + VERO).innerHTML = "&nbsp;";
                                    }
            }
        }
    }
}

function creaTabellaRiassunto(){
    obj = window.document.getElementById('spRiassunto');
    riga = '<table class=\"tbRiassunto\" cellspacing=0; >\n';
    for (var i = 0; i < NUM_QUESITI_RIASSUNTO; i++) {
        riga = riga + '<tr class=\"rigaQuesitoRiassunto\"> <td class=\"colImgRiassunto\">';
        riga = riga + '&nbsp;<img class=\"iRiassunto\" id=\"iRiassunto' + i + '\"></td>';
        riga = riga + '<td class=\"colQuesitoRiassunto\"><font  id=\"testoQuesitoRiassunto' + i + '\" class=\"testoQuesitoRiassunto\">&nbsp;</font></td>';
        riga = riga + '<td class=\"colRispostaRiassuntoHead\">V</td><td class=\"colRispostaRiassuntoHead\">F</td><td class=\"colBottoniRiassunto\"></td></tr>\n';

        for (var j = 1; j <= scheda.aswCount; j++) {
            numDomanda = "" + i + j;
            iDomanda = (i * scheda.aswCount) + j;
            if (j == 1)
                riga = riga + '<tr style="height:25px" ><td class=\"colImgBlank\"><a href=\"javascript:modificaRiassuntoClick(' + j + ');\"><font class=\"testoNumeroRiassunto\" id=\"colImgRiassunto' + i + '\">&nbsp;</font></a></td>';
            else
                riga = riga + '<tr style="height:25px"><td class=\"colImgBlank\">&nbsp;</td>';
            riga = riga + '<td class=\"colDomandaRiassunto\"><font id=\"testoDomandaRiassunto' + numDomanda + '\" class=\"testoDomandaRiassunto\">&nbsp;</font></td>';
            riga = riga + '<td id=\"colRispostaRiassunto' + numDomanda + VERO + '\" class=\"colRispostaRiassunto\">&nbsp;</td><td id=\"colRispostaRiassunto' + numDomanda + FALSO + '\" class=\"colRispostaRiassunto\">&nbsp;</td><td class=\"colBottoniRiassunto\"></td></tr>\n';
        }
    }
    riga = riga + '</table><table class=\"tbSpazioNullo\"><tr id=\"rowSeparatore\" class=\"rowSeparatore\"><td></td></tr></table>\n';

    obj.innerHTML = riga;
}

function creaToolbar(inizio){
    obj = window.document.getElementById('toolbar');
    appo = '<table class=\"tbToolbar\" cellspacing=0><tr>';
    for (var i = inizio; i < NUM_QUESITI_TOOLBAR + inizio; i++) {
        apice = "'";
        appo = appo + '<a href=\"javascript:bottoneClick(' + i + ')' + '\"><td id=\"bottoneToolbar' + (i) + '\">';
        appo = appo + '<span> &nbsp;' + '<a id=\"linkToolbar' + (i) + '\" href=\"javascript:bottoneClick(' + i + ')' + '\">' + (i + 1) + '&nbsp;' + '</a></span></td></a>';
    }
    appo = appo + '<td><a href=\"javascript:riassuntoClick()\"><img class=iOpzione src=\"/img/scheda/riassunto.jpg\"></a></td></tr></table>';
    obj.innerHTML = appo;
}

function indietroClick(){
    if (currentQst == 1) {
        return;
    }
    $('#linkToolbar' + (currentQst - 1)).css({
        'color': colorDeSelezionato
    });
    currentQst = currentQst - 1;
    loadQstM(currentQst);
}

function spostaRiassunto(quanto){
    //verfica indietro
    if ((posizioneRiassunto == 1) && (quanto < 0)) 
        return;

    if (((posizioneRiassunto + NUM_QUESITI_RIASSUNTO) == (scheda.qstCount + 1)) && (quanto > 0))
        return;

    posizioneRiassunto = posizioneRiassunto + quanto;
    componiRiassunto(posizioneRiassunto);
}

function riassuntoClick(){
    posizioneRiassunto = 1;
    window.document.getElementById('conferma').style.visibility = 'visible';
    window.document.getElementById('modifica').style.visibility = 'visible';
    componiRiassunto(1);
    window.document.getElementById('spRiassunto').style.visibility = 'visible';
    window.document.getElementById('suRiassunto').style.visibility = 'visible';
    window.document.getElementById('giuRiassunto').style.visibility = 'visible';
    //window.document.getElementById('guida').style.visibility='hidden';

    window.document.getElementById('tbFooter').style.background = "#FBC8D9";
    window.document.getElementById('footer').style.background = "#FBC8D9";

    window.document.getElementById('navAvanti').style.visibility = 'hidden';
    window.document.getElementById('navIndietro').style.visibility = 'hidden';
}

function modificaClick(numQuesito){
    window.document.getElementById('linkToolbar' + (currentQst - 1)).style.backgroundColor = "transparent";
    window.document.getElementById('linkToolbar' + (currentQst - 1)).style.color = colorDeSelezionato;

    window.document.getElementById('conferma').style.visibility = 'hidden';
    window.document.getElementById('modifica').style.visibility = 'hidden';
    window.document.getElementById('spRiassunto').style.visibility = 'hidden';
    window.document.getElementById('suRiassunto').style.visibility = 'hidden';
    window.document.getElementById('giuRiassunto').style.visibility = 'hidden';

    currentQst = numQuesito;
    loadQstM(currentQst);
}

function loadQstM(numQst){

    numQst = numQst - 1;

    if (numQst == (scheda.qstCount - 1))
        window.document.getElementById('imgAvanti').src = "/img/scheda/riassunto.jpg";
    else
        window.document.getElementById('imgAvanti').src = "/img/scheda/avanti.gif";

    numDomanda = numQst * scheda.aswCount;
    for (var i = 1; i <= scheda.aswCount; i++) {
        window.document.getElementById('testoDomanda' + i).innerHTML = scheda.GetQst(numQst).GetAsw(i - 1).txt;
        if (scheda.bilingue && scheda.GetQst(numQst).GetAsw(i - 1).tra.length)
            $('#testoDomandaTra'+i).html('(' + scheda.GetQst(numQst).GetAsw(i - 1).tra + ')');
        if (scheda.rtlMode())
            window.document.getElementById('testoDomandaTra' + i).style.direction = "rtl";

        window.document.getElementById('audioDomanda' + i + 'Ref').href = 'javascript:playAudio(\'/ecom.dll/audio?type=2&list=' + scheda.listato + '&lang=' + scheda.lingua + '&id=' + scheda.GetQst(numQst).GetAsw(i - 1).idasw + '\')';

        viewAnswersDouble((numQst * scheda.aswCount) + (i - 1));
    }

    window.document.getElementById('testoQuesito').innerHTML = scheda.GetQst(numQst).txt;
    window.document.getElementById('audioQuesitoRef').href = 'javascript:playAudio(\'/ecom.dll/audio?type=1&list=' + scheda.listato + '&lang=' + scheda.lingua + '&id=' + scheda.GetQst(numQst).idqst + '\')';

    if (scheda.bilingue && scheda.GetQst(numQst).tra.length)
        $('#testoQuesitoTra').html('(' + scheda.GetQst(numQst).tra + ')');
    if (scheda.rtlMode())
        window.document.getElementById('testoQuesitoTra').style.direction = "rtl";

    var imgPath = scheda.GetQst(numQst).fig.src;
    var imgText = imgPath.substring(imgPath.lastIndexOf("/") + 1);

    if (imgText != "") {
        window.document.getElementById('iQuesito').style.visibility = 'visible';
        /*window.document.getElementById('iFigQuesito').innerHTML = 'Figura n.' + imgText.substring(0, imgText.lastIndexOf("G"));*/
        window.document.getElementById('iQuesito').src = scheda.GetQst(numQst).fig.src;
        window.document.getElementById('iQuesitoLink').href = scheda.GetQst(numQst).fig.src;
        window.document.getElementById('numQuesito').innerHTML = parseInt(numQst) + 1;
    }
    else {
        window.document.getElementById('iQuesito').style.visibility = 'hidden';
        /*window.document.getElementById('iFigQuesito').innerHTML = "";*/
        window.document.getElementById('iQuesito').src = "";
        window.document.getElementById('iQuesitoLink').href = "";
    }
    window.document.getElementById('numQuesito').innerHTML = parseInt(numQst) + 1;
    window.document.getElementById('linkToolbar' + numQst).style.color = colorSelezionato;


    if (NUM_QUESITI_TOOLBAR < scheda.qstCount) {
        alert("NUM_QUESITI_TOOLBAR < scheda.qstCount");
        inizio = scheda.qstCount - NUM_QUESITI_TOOLBAR;
        if (inizio < numQst) {
            creaToolbar(inizio);
        }
        else {
            creaToolbar(numQst);
        }
    }

    //riaggiorno i controlli della prima maschera
    window.document.getElementById('tbFooter').style.background = "#D1E6D7";
    window.document.getElementById('footer').style.background = "#D1E6D7";

    window.document.getElementById('navAvanti').style.visibility = 'visible';
    window.document.getElementById('navIndietro').style.visibility = 'visible';

    //imposto di default la prima risposta
    currentAsw=1;
}

function setNextAswTimer() {
    if (nextAswTimer==0) //non c'e' gia un timer attivo 
        nextAswTimer = setTimeout(selAnswerNext,nextAswTimeout);                  
}

function unsetNextAswTimer() {
    if (nextAswTimer!=0) //reset eventuale timer avanzamento risposta
        nextAswTimer = 0;
}

