<!--
// location.js
GIF_Dn_buttons = new Array("../common/choose2", "../common/partII2");
SRCbuttons = new Array("choose", "partII");

// Inform that probably wrong browser
function errorHandler()
{
  alert("Are you sure you have Netscape version >= 4.0\nor Internet Explorer version >= 4.0?")
  return true;
}
window.onerror = errorHandler;

// Initialize the registry
var keyRegistry = new Object;

keyRegistry["E"] = new Array("Bookmark", "Europe");
keyRegistry["A"] = new Array("Bookmark", "Asia");
keyRegistry["U"] = new Array("Bookmark", "USA");

var DELTA = 10; // Tolerance (px)

// Test if captureEvents method exists
nn4 = (document.captureEvents);

var bIEmouseDown = false;
whichEl = null;
    
var dx, dy;

var dragObj = new Array();
var mapObj = new Array();

// DATA
var mapPersPosArray   = new Array( 400,97, 318,252, 381,319, 431,131, 223,193, 31,141, 61,166, 152,62, 236,102, 267,17, 199,166, 233,149,
144,89, 388,41, 209,121, 39,321, 288,82, 40,71, 57,121, 235,156, 360,175);
var mapPersNamesArray = new Array( "Confucius", "Plato", "Hypatia", "Avicenna", "Leonardo da Vinci", "René Descartes", "Blaise Pascal",
"Isaac Newton", "Gottfried Leibniz", "E. Swedenborg", "Maria G. Agnesi", "Wolfgang A. Mozart", "John Stuart Mill", "Sonja Kovalevskaya",
"Albert Einstein", "Srinivasa Ramanujan", "Maria Curie", "Stephen W. Hawking", "Simone de Beauvoir", "Bobby Fisher", "Maya Chiburdanidze");
var mapPersPlaceArray = new Array( "Shandong, China", "Athens, Greece", "Alexandria, Egypt", "Bukhara, Uzbekistan", "Florence, Italy",
"Touraine, France", "Clermont-Ferrand, France", "Grantham, England", "Leipzig, Germany", "Stockholm, Sweden", "Milan, Italy",
"Salzburg, Austria", "London, England", "Moscow, Russia", "Ulm, Germany", "Erode, India", "Warsaw, Poland", "Oxford, England", "Paris, France",
"Chicago, U.S.A.", "Kutaisi, Georgia");

var NO_OF_PERSONS = mapPersNamesArray.length;

if( nn4)
    document.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.KEYPRESS);
else
    document.onselectstart = checkElem;

document.onkeypress  = doAccessKeys;

document.onmousedown = startDrag;
document.onmouseup   = endDrag;
document.onmousemove = moveIt;
document.onmouseover = cursorShape;

function doAccessKeys(e)
{
    if( nn4)
    { // Map event object
        event = e;
        event.keyCode = e.which;
        event.srcElement = e.target;
    }

    if( event == null)
        event = e;

    var key = String.fromCharCode(event.keyCode).toUpperCase();
    var entry = keyRegistry[key]

    if(( entry != null) && ( event.srcElement.type == null))
    {
        document.location.hash = entry[1];
        return false;
    }
}

function startDrag(e)
{
    currentObj = whichObj(e);

    if( nn4)
    {
      // Take care of possible MouseDown in Link Button
      document.routeEvent(e);
      document.captureEvents(Event.MOUSEMOVE);
    }
    else
      bIEmouseDown = true;
}

function moveIt(e)
{
    if( nn4 && currentObj != null)
    {
        dragObj[currentObj].left = e.pageX - dx;
        dragObj[currentObj].top = e.pageY - dy;
    }
    else if( bIEmouseDown && currentObj != null)
    {
        dragObj[currentObj].left = event.clientX - dx;
        dragObj[currentObj].top = event.clientY - dy;
    }
}

function endDrag()
{
    whichEl = currentObj = null;

    if( nn4)
      document.releaseEvents(Event.MOUSEMOVE);
    else
      bIEmouseDown = false;
}

function reloadPage()
{
    window.location.reload();
}

function evaluateLabels()
{
    var nSumCorrect = 0;
    var strWrongAlt = "";

    // Check if at correct coordinates
    for( var PersIdx = 0; PersIdx < NO_OF_PERSONS; PersIdx++)
    {
        // Choose map
        if( PersIdx == 0 || PersIdx == 15)	// Confucius & Ramanujan
            mapIdx = 1;
        else if((PersIdx > 0 && PersIdx < 19) || PersIdx == 20)	// ... Maya C.
            mapIdx = 0;
        else if( PersIdx == 19)	// Fisher
            mapIdx = 2;
/*
		if(PersIdx == 20)
		{
			alert("mapObj[mapIdx].left=" + mapObj[mapIdx].left);
			alert("mapPersPosArray[2 * PersIdx]=" + mapPersPosArray[2 * PersIdx]);
			alert("dragObj[PersIdx].top=" + dragObj[PersIdx].top);
			alert("mapObj[mapIdx].top=" + mapObj[mapIdx].top);
			alert("mapPersPosArray[2 * PersIdx + 1]=" + mapPersPosArray[2 * PersIdx + 1]);
		}	
*/		
        if( nn4)
        {
           bCorrectPlacement = (( dragObj[PersIdx].left > mapObj[mapIdx].left + mapPersPosArray[2 * PersIdx] - DELTA ) &&
           ( dragObj[PersIdx].left < mapObj[mapIdx].left + mapPersPosArray[2 * PersIdx] + DELTA ) &&
           ( dragObj[PersIdx].top > mapObj[mapIdx].top + mapPersPosArray[2 * PersIdx + 1] - DELTA ) &&
           ( dragObj[PersIdx].top < mapObj[mapIdx].top + mapPersPosArray[2 * PersIdx + 1] + DELTA ));
        }
        else
        {
           bCorrectPlacement = (( dragObj[PersIdx].pixelLeft > mapObj[mapIdx].pixelLeft + mapPersPosArray[2 * PersIdx] - DELTA ) &&
           ( dragObj[PersIdx].pixelLeft < mapObj[mapIdx].pixelLeft + mapPersPosArray[2 * PersIdx] + DELTA ) &&
           ( dragObj[PersIdx].pixelTop > mapObj[mapIdx].pixelTop + mapPersPosArray[2 * PersIdx + 1] - DELTA ) &&
           ( dragObj[PersIdx].pixelTop < mapObj[mapIdx].pixelTop + mapPersPosArray[2 * PersIdx + 1] + DELTA ));
        }

        if( bCorrectPlacement)
        {
            nSumCorrect += 1;
        }
        else
        {
            strWrongAlt = WrongAlt(mapPersNamesArray[PersIdx]+" - "+mapPersPlaceArray[PersIdx], strWrongAlt);
        }
    }

    EvalMessage("LOCATE THEIR BIRTH-PLACES",nSumCorrect,strWrongAlt,21);
}

function init()
{
    var NO_OF_MAPS = 3;

    if( nn4)
    {
        layerRef = "document.layers";
        styleRef = "";
    }
    else
    {
        layerRef = "document.all";
        styleRef = ".style";
    }       

    // Define the 'dragable' layers (labels)
    for( var idx = 0; idx < NO_OF_PERSONS; idx++)
    {
        dragObj[idx] = eval(layerRef + "['label' + idx]" + styleRef);
    }

    // Define the maps
    for( var idx = 0; idx < NO_OF_MAPS; idx++)
    {
        mapObj[idx] = eval(layerRef + "['map' + idx]" + styleRef);
    }
}

function whichObj(e)
{
    // Check which object has been hit
    var hit= null;

    if( nn4)
    {
      for( var i = 0; i < dragObj.length; i++)
      {
        if ((dragObj[i].left < e.pageX) && 
            (dragObj[i].left + dragObj[i].clip.width > e.pageX) &&
            (dragObj[i].top < e.pageY) && 
            (dragObj[i].top + dragObj[i].clip.height > e.pageY))
            {
              hit= i;
              dx = e.pageX - dragObj[i].left;
              dy = e.pageY - dragObj[i].top;
              break;
            }
      }
    }
    else
    {
      whichEl = event.srcElement;

      for( var i = 0; i < dragObj.length; i++)
      {
        if ((dragObj[i].pixelLeft < event.clientX + document.body.scrollLeft) && 
            (dragObj[i].pixelLeft + dragObj[0].pixelWidth > event.clientX + document.body.scrollLeft) &&
            (dragObj[i].pixelTop < event.clientY + document.body.scrollTop) && 
            (dragObj[i].pixelTop + dragObj[0].pixelHeight > event.clientY + document.body.scrollTop))
        {
              hit= i;
              dx= event.clientX - dragObj[i].pixelLeft;
              dy= event.clientY - dragObj[i].pixelTop;
              break;
        }
      }
    }

    return hit;
}

function checkElem()
{
    if( whichEl != null)
    {
        return false
    }
}

function cursorShape()
{
    if( event.srcElement.drag)
    {
         event.srcElement.style.cursor = "move"
    }
}
// -->

