<!--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 = true;
var ctrlKeyPressed = 0;

/* The first three selected elements */
var start1 = "H";
var start2 = "He";
var start3 = "Li";

function initTable() {
	
    theTable = document.Table;
	if (theTable && theTable.isLoaded()==1) {
		theTable.setClickableElements(1, 1);
		theTable.setBack(0, 0, 0);
		theTable.setFore(255, 255, 255);
		theTable.selectAll(1);
		theTable.setClickMode(0);
	
		var d = document.form.selectProperties;
		var i, n = theTable.getNProperties();
	
		for (i=0; i<n; i++) {
		   d.options[i] = new Option(theTable.getPropertyName(i), i, i==0, i==0);
		}
	
		getClickMode();
	}
	else
		setTimeout("initTable()", 500);
}

function closePopups()
{
    if (listWindow && !listWindow.closed) {
        listWindow.close();
    }
	
}

function setVisualisationProperty() {
    var sel = document.form.selectProperties.selectedIndex;
    var style = document.form.scheme.selectedIndex;
    var prop = document.form.selectProperties.options[sel].text;
    theTable.setVisualisationProperty(prop, style);
}

// Called by the applet to refresh the list
function update() {
    if (listWindow && !listWindow.closed) {
        listWindow.updateList();
    }
    for (i=0; i<nWindows; i++) {
        if (graphWindows[i] && !graphWindows[i].closed) {
            graphWindows[i].updateGraph();
        }
    }
}

function isSelected(i) {
	return theTable.isSelected(i);	
}

function getSelected() {
	return theTable.getSelected();
}

var listWindow = null;

function showList() {
    if (listWindow && !listWindow.closed) {
        listWindow.location = "list.htm";
        listWindow.focus();
    }
    else {
        var w = 600;
        var h = screen.height-100;
        var l = 0;
        var t = 0;
        listWindow = window.open("list.htm",
            "ListWindow",
            "status=yes,scrollbars=auto,resizable=yes,"+
            "width="+w+",height="+h+
            ",top="+t+",left="+l);
    }
}

var graphWindows = new Array;
var nWindows = 0;

function showGraph() {
	var w = 750;
	var h = 500;
	var l = (screen.width - w)/2;
	var t = (screen.height - h)/2;
	graphWindow = window.open("../graph/index.htm",
		"GraphWindow"+nWindows,
		"status=yes,scrollbars=no,resizable=yes,"+
		"width="+w+",height="+h+
		",top="+t+",left="+l);
	graphWindows[nWindows++] = graphWindow;
}

var energyWindow = null;

function showEnergy() {
    start1 = theTable.getSelectedElement(1);
    start2 = theTable.getSelectedElement(2);
    start3 = theTable.getSelectedElement(3);

    if (start1.length<1 && start2.length<1 && start3.length<1 ) {
        start1 = "H";
        start2 = "He";
        start3 = "Li";
    }
    if (energyWindow && !energyWindow.closed) {
        energyWindow.location = "../energy/index.htm";
        energyWindow.focus();
    }
    else {
        var w = 750;
        var h = 500;
        var l = (screen.width - w)/2;
        var t = (screen.height - h)/2;
        energyWindow = window.open("../energy/index.htm",
            "EnergyWindow",
            "status=yes,scrollbars=auto,resizable=yes,"+
            "width="+w+",height="+h+
            ",top="+t+",left="+l);
    }
}

var dotcrossWindow = null;

function showDotCross() {
    start1 = theTable.getSelectedElement(1);
    start2 = theTable.getSelectedElement(2);
    start3 = theTable.getSelectedElement(3);

    if (start1.length<1 && start2.length<1 && start3.length<1 ) {
        start1 = "H";
        start2 = "He";
        start3 = "Li";
    }
    if (dotcrossWindow && !dotcrossWindow.closed) {
        dotcrossWindow.location = "../dotcross/index.htm";
        dotcrossWindow.focus();
    }
    else {
        var w = 750;
        var h = 500;
        var l = (screen.width - w)/2;
        var t = (screen.height - h)/2;
        dotcrossWindow = window.open("../dotcross/index.htm",
            "DotCrossWindow",
            "status=yes,scrollbars=auto,resizable=yes,"+
            "width="+w+",height="+h+
            ",top="+t+",left="+l);
    }
}

var elementWindow = null;

function showElement() {
    start1 = theTable.getSelectedElementIndex(1);
    showElementWindow();
}

function showElementWindow() {
    if (elementWindow && !elementWindow.closed) {	
        elementWindow.setElement(start1);//location = "element.htm";
        elementWindow.focus();
    }
    else {
        var w = 460;
        var h = 500;
        var l = (screen.width - w)/2;
        var t = (screen.height - h)/2;
		
        elementWindow = window.open("element.htm",
            "ElementWindow",
            "status=yes,scrollbars=auto,resizable=yes,"+
            "width="+w+",height="+h+
            ",top="+t+",left="+l);
    }
}

function doElement(x) {
    start1 = x;		
    showElementWindow();
}

function selectAll() {
    theTable.selectAll(1);
}
function selectNone() {
    theTable.selectAll(0);
}
function invertSelection() {
    theTable.invertSelection();
}
function selectGroup(g) {
    theTable.selectGroup(g, ctrlKeyPressed);
}
function selectPeriod(p) {
    theTable.selectPeriod(p, ctrlKeyPressed);
}
function selectBlock(b) {
    theTable.selectBlock(b, ctrlKeyPressed);
}
function selectLanthanides() {
    theTable.selectLanthanides(ctrlKeyPressed);
}
function selectActinides() {
    theTable.selectActinides(ctrlKeyPressed);
}
function selectDate() {
    var year = document.form.date.value;
    if (year.length>0) {
        theTable.selectDate(year);
    }
}
function selectElement() {
    var element = document.form.elementName.value;
    if (element.length>0) {
        document.form.elementName.value = theTable.selectElementAndReport(element);
    }
}

function ctrlPressed(e) {
    ctrlKeyPressed = window.Event ? e.modifiers & Event.CONTROL_MASK : window.event.ctrlKey ? 1 : 0;
    return true;
}

function writeStatus(stat) {
   status = stat;
}

function changeClickMode() {
    if (theTable) {
        var mode = document.form.ClickToSelect.checked? 1 : 0;
        theTable.setClickMode(mode);
    }
}

function setClickMode(i) {
    if (theTable) {
        theTable.setClickMode(i);
		getClickMode();
    }
}

function getClickMode() {
	if (theTable) {
	    var click = theTable.getClickMode();
		document.form.clickMode0.checked = click==0;
		document.form.clickMode1.checked = click==1;
	}
}

function trace(msg)
{
    if (debug) alert(msg);
}
// stop hiding -->

