<!--hide this script from non-javascript-enabled browsers

//////////////////////////////////////////////////////////
//
// Periodic Table of Data
//
// Produced by Presenting Science
//  www.PresentingScience.com
//
// Copyright (C) Royal Society of Chemistry &
//		 Presenting Science 2004
//
//////////////////////////////////////////////////////////

var theTable = null;
var debug = false;
var cookieName="IdtEScores";


function initTable(game)
{
	theTable = document.Table;
	if (theTable && theTable.isLoaded()==1) {
		theTable.setBack(0, 0, 0);
		theTable.setFore(255, 255, 255);
		theTable.selectAll(0);
		setLevel(0);
		setBlind();
		setGame(game);
	}
	else {
		trace("re-trying initTable");
		setTimeout("initTable("+game+")", 500);
	}

}

function closePopups() {
    if (helpWindow && !helpWindow.closed) {
        helpWindow.close();
    }
}

var helpWindow = null;

function showHelp(helpFile) {
    if (helpWindow && !helpWindow.closed) {
        helpWindow.location = helpFile;
        helpWindow.focus();
    }
    else {
        var w = 700;
        var h = 420;
        var l = 0;
        var t = 0;
        helpWindow = window.open(helpFile,
            "helpWindow",
            "status=no,scrollbars=yes,resizable=yes,"+
            "width="+w+",height="+h+
            ",top="+t+",left="+l);
    }
}

function handleKeyPress(e)
{
alert("handleKeyPress()");
    var Key;
    if (document.layers)
        Key = e.which;
    else
        Key = window.event.keyCode;
    if (Key != 0)
        alert("Key pressed! ASCII-value: " + Key);

    return true;
}

function writeHighScores()
{
    trace("writeHighScores()");
    writeCookie(cookieName, theTable.getHighScores());
}

function showHighScores()
{
    theTable.showHighScores();
}

function addHighScore()
{
    trace("Adding high score: ");
}

function setGame(i)
{
    if (theTable.inProgress()) {
        stopGame();
    }
    if (!theTable.inProgress())
        theTable.setGame(i);
}

function setLevel(i)
{
    if (theTable.inProgress()) {
        stopGame();
    }
    if (!theTable.inProgress())
        theTable.setLevel(i);
}

function startGame()
{
    trace("startGame()");
    if (theTable.inProgress()) {
        stopGame();
    }
    if (!theTable.inProgress())
        theTable.startGame();
}

function stopGame()
{
    if (theTable.inProgress())
        if (confirm("Do you want to stop the present game?"))
            theTable.stopGame();
}

function showFirstLetter() {
    trace("showFirstLetter()");
    theTable.showFirstLetter();
}

function showGroup() {
    trace("showGroup()");
    theTable.showGroup();
}

function showPeriod() {
    trace("showPeriod()");
    theTable.showPeriod();
}

function nextElement() {
    trace("nextElement()");
    theTable.nextElement();
}

function setBlind() {
    var b = document.form.blind.checked? 1 : 0;
    trace("setBlind(): "+b);
    if (theTable.inProgress()) {
        stopGame();
    }
    if (!theTable.inProgress())
    	theTable.setHideAllInfo(b);
	var newb = theTable.getHideAllInfo();
	document.form.blind.checked = newb==1;
}

 /**
  * General purpose: extract and return the labelled cookie
  */
 function readCookie(label) {
    var c = document.cookie;
    var pos = c.indexOf(label);
    if (pos != -1) {
         var start = pos+label.length;
         var d = c.substring(start, c.length)
         var end = d.indexOf(";");
         if (end == -1) end = d.length;
         var h = d.substring(0, end);
         h = unescape(h);
         if (h.length>0) {
            return h;
        }
    }
    return "";
 }

 /**
  * General purpose: write the labelled cookie
  */
 function writeCookie(label, value) {
     var nextYear = new Date();
     nextYear.setFullYear(nextYear.getFullYear()+1);	// Will last for one year
     document.cookie = label+escape(value) + "; expires=" + nextYear.toGMTString();
 }


function trace(msg)
{
    if (debug) alert(msg);
}
// stop hiding -->

