<!-- script start
// faces.js
// Link buttons
GIF_Dn_buttons = new Array("../common/choose2", "../common/partIII2");
SRCbuttons = new Array("choose", "partIII");

// Suppress disturbing possible JS-errors
function errorHandler()
{
  // Particularly an undefined object if
  // mouse pointer was resting on an image
  // at page loading.
  // (Has no effect on program)
  return true;
}
window.onerror = errorHandler;

var A1  = new Image();
A1.src  = 'mark.gif';

// Fill array with image files
var imageArray = new Array("reset.gif", "Newton.jpg", "Eliot2.jpg", "Mozart.jpg","Wittg2.jpg",
"Leibniz.jpg","Pascal2.jpg","Kovas.jpg","Sand2.jpg","emanuel2.jpg", "Vinci.jpg", "Beav1.jpg",
"chatter2.jpg", "JSMill3.jpg", "Darwin.jpg", "Descart.jpg", "Russell2.jpg", "sm_Alb.jpg",
"Curie.jpg", "goethe.jpg", "Hawking.jpg", "hyp2.jpg", "avicenna.jpg", "fischer2.jpg", "Ramanuja.jpg",
"Plato.jpg", "Agnesi.jpg", "Confuciu.jpg", "Maya.jpg");

var NO_OF_IMAGES = imageArray.length - 1;

// Allocate space for image-portrait links
var imageLink = new Array();
for( var idx=0; idx < NO_OF_IMAGES; idx++)
  imageLink[idx] = "";

// This serie of numbers represent the correct corresponding
// ordering of portraits in the second image que to
// the first image que (Which are referenced numbered 1-28).
var correctLowerImageSerie = new Array(27, 25, 21, 22, 10, 26, 5, 13, 7, 17, 18, 24, 20, 11, 15, 6, 1, 9, 19, 12, 3, 8, 14, 2, 16, 4, 23, 28);

function LockImage(nSection)
{
    with( document.facesform)
    {
        if(nSection == 0)
            bLockN.value = true;
        else
            bLockP.value = true;
    }
}

function UnLockImages(nSection)
{
    with( document.facesform)
    {
        if(nSection == 0)
            bLockN.value = false;
        else
            bLockP.value = false;
    }
}

function isLocked(nSection)
{
    with( document.facesform)
    {
        if(nSection == 0)
        {
            if( bLockN.value == "true")
                return 1;
        }
        else
        {
            if( bLockP.value == "true")
                return 1;
        }
    }

 return 0;
}

function resetOld(imgName)
{
    // Reset old marked images
    var ResetGIF = "reset.gif";
    var MarkGIF  = "mark.gif";

    if( document.images)
    {
        if( document[imgName].src.indexOf(MarkGIF) > 0)
            document[imgName].src = ResetGIF;
    }
}

function markNew(imgName, nIdx, nSel)
{
    // Mark new images
    var MarkGIF  = "mark.gif";

    if( nSel == parseInt(nIdx))
        document[imgName].src = MarkGIF;
}

function putPortrait(imgName, nIdx, nSel)
{
    // Put portrait to marked image
    if( document.facesform.nLink.value == parseInt(nIdx))
        document[imgName].src = imageArray[nSel-1]
}

function markImage(nSel)
{
    // Check if ímage locked (Names section)
    if(isLocked(0)) return;

    // Unlock images (Portraits section)
    UnLockImages(1);

    document.facesform.nLink.value = nSel;

    // Reset old marked images
    // when marking new.
    for( var nIdx = 1; nIdx <= NO_OF_IMAGES; nIdx++)
    {
        resetOld("A" + nIdx);
        markNew("A" + nIdx, nIdx, nSel);
    }
}

function putImage(nSel)
{
    // Check if ímage locked (Portraits section)
    if(isLocked(1)) return;

    // Unlock images (Names section)
    UnLockImages(0);

    // Put portrait to marked image
    for( var nIdx = 1; nIdx <= NO_OF_IMAGES; nIdx++)
    {
        putPortrait("A" + nIdx, nIdx, nSel);
    }

    // Store que number for the put portrait.
    imageLink[document.facesform.nLink.value-1] = nSel-1;
}

function resetImages()
{
    var ResetGIF = "reset.gif";

    // Reset image links
    for( var idx=0; idx < NO_OF_IMAGES; idx++)
      imageLink[idx] = "";

    // Unlock images
    UnLockImages(0); UnLockImages(1);

    // Reset images
    for( var nIdx = 1; nIdx <= NO_OF_IMAGES; nIdx++)
    {
        document["A" + nIdx].src = ResetGIF;
    }

    // Start image #
    document.facesform.nLink.value = 1;
}

function evaluateImages()
{
    var nSumCorrect = 0;
    var strWrongAlt = "";

    // Check imageLink[] against correct values.
    for( var i = 0; i < NO_OF_IMAGES; i++)
    {
        if( imageLink[i] == correctLowerImageSerie[i] )
            nSumCorrect += 1;
        else
            strWrongAlt = WrongAlt(parseInt(i+1)+"-"+correctLowerImageSerie[i], strWrongAlt);
    }

    EvalMessage("IDENTIFY THEIR PORTRAITS",nSumCorrect,strWrongAlt,28);
}
// script end -->

