// -------------------------------------
// THIS  FILE GENERATED FROM GENAUTO.CSH
// -------------------------------------

/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
   You may not modify, use, reproduce, or distribute this software 
   except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

   Based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/

var autoDiv;
var autoTable;
var focus = -1;
var isIE;


function clearAutoTable()
{
    if (autoTable)
    {
        autoTable.style.visible = false;
        for (loop = autoTable.childNodes.length -1; loop >= 0 ; loop--)
            autoTable.removeChild(autoTable.childNodes[loop]);
    }
}

function updateAutoTableFocus(element)
{
    if(focus < -1)
        focus = autoTable.childNodes.length - 1;

    if(focus > autoTable.childNodes.length - 1)
        focus = -1;

    if(focus == -1)
    {
        if (element && 
            element.focus)
            element.focus();
    }
    else if (autoTable.childNodes.length > 0)
    {
        if (autoTable.childNodes[focus].getElementsByTagName("a") &&
            autoTable.childNodes[focus].getElementsByTagName("a")[0])
            autoTable.childNodes[focus].getElementsByTagName("a")[0].focus();
        else // get any child for focus
        {
            if (autoTable.childNodes[focus].getElementsByTagName("th")                  &&
                autoTable.childNodes[focus].getElementsByTagName("th")[0]               &&
                autoTable.childNodes[focus].getElementsByTagName("th")[0].childNodes    &&
                autoTable.childNodes[focus].getElementsByTagName("th")[0].childNodes[0] &&
                autoTable.childNodes[focus].getElementsByTagName("th")[0].childNodes[0].focus)
                autoTable.childNodes[focus].getElementsByTagName("th")[0].childNodes[0].focus();
        }
    }
}

function getElementY(element, adjustment)
{
    var note = '';
    var targetTop = 0;
    if (element.offsetParent) {
        note += '1. ';
        while (element.offsetParent) {
            note += ',' + element.offsetTop;
            targetTop += element.offsetTop;
            element = element.offsetParent;
        }
        if (adjustment)
            targetTop += adjustment;
    } else if (element.y) {
        targetTop += element.y;
        note += '2.' + element.y;
    }
    return targetTop;
}

function getElementX(element, adjustment)
{
    var targetLeft = 0;
    if (element.offsetParent) {
        while (element.offsetParent) {
            targetLeft += element.offsetLeft;
            element = element.offsetParent;
        }
        if (adjustment)
            targetLeft += adjustment;
    } else if (element.x)
        targetLeft += element.x;

    return targetLeft;
}

/** The advanced search hidden div seems to be the root offsetParent.
    This function will add .

    update: both need it, as use of it follows the search form on all pages.
function moveAutoTableSearch(element)
{
    autoTable = document.getElementById("auto-table");
    autoDiv   = document.getElementById("auto-div");
    autoDiv.style.top  = ((getElementY(element, 210) + element.offsetHeight) - 203) + "px";
    autoDiv.style.left = getElementX(element, 70) - 65 + "px";   
}
    */

function moveAutoTable(element)
{
    autoTable = document.getElementById("auto-table");
    autoDiv   = document.getElementById("auto-div");
    autoDiv.style.top  = ((getElementY(element, 210) + element.offsetHeight) - 203) + "px";
    autoDiv.style.left = getElementX(element, 70) - 65 + "px";   
}

function checkAutoTable(event)
{
    if (event.keyCode == 27) // escape
    {
        clearAutoTable();
    }
    else if (event.keyCode == 37) // left
    {
        clearAutoTable();
    }
    else if (event.keyCode == 38) // up
    {
        focus--;
        updateAutoTableFocus(event);
    }
    else if (event.keyCode == 39) // right
    {
        clearAutoTable();
    }
    else if (event.keyCode == 40) // down
    {
        focus++;
        updateAutoTableFocus(event);
    }
}

// -------------------------------------
// THIS  FILE GENERATED FROM GENAUTO.CSH
// -------------------------------------

/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
   You may not modify, use, reproduce, or distribute this software 
   except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

   Based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/

var archivist;

function doArch(event)
{
    if (event.keyCode == 27 )   // escape
    {
        focus = -1;
        updateAutoTableFocus(archivist);
        return;
    }

    if (event.keyCode == 27 ||  // escape
        event.keyCode == 37 ||  // left
        event.keyCode == 38 ||  // up
        event.keyCode == 39 ||  // right
        event.keyCode == 40)    // down
    {
        return;
    }


    archivist = document.getElementById("archivist");

    moveAutoTable(archivist);

    if (archivist.value == '') { // clear data
        chooseArch('', '');
    } else {
        var url = "/ws/arch?name=" + escape(archivist.value);
        var ajax = new archObject(url);
        ajax.send();
    }
}

function archObject(url) {
    this.url = url;
    var req = init();
    req.onreadystatechange = processRequest;

    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
        {
            isIE = true;
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest ()
    {
        if (req.readyState == 4 && req.status == 200)
            processArch(req.responseXML);
    }

    this.send = function()
    {
        req.open("GET", url, true);
        req.send(null);
    }
}

function processArch(responseXML)
{
    clearAutoTable();

    var archList = responseXML.getElementsByTagName("list")[0];
    if (archList)
    {
        if (archList.childNodes.length > 0)
            autoTable.setAttribute("style", "border:1px solid #ccc;padding:2px;background-color:#fff;");
        else
            focus = -1;

        var lastTypeId = 0;

        for (loop = 0; loop < archList.childNodes.length; loop++)
        {
            var arch = archList.childNodes[loop];

            var listName = '';
            var name     = '';
            var archId    = '';

            if (arch.getElementsByTagName("list-name")[0])
                listName = arch.getElementsByTagName("list-name")[0].childNodes[0].nodeValue;
            else if (arch.getElementsByTagName("name")[0])
                listName = arch.getElementsByTagName("name")[0].childNodes[0].nodeValue;

            if (arch.getElementsByTagName("name")[0])
                name = arch.getElementsByTagName("name"         )[0].childNodes[0].nodeValue;

            if (arch.getElementsByTagName("id")[0])
                archId   = arch.getElementsByTagName("id"        )[0].childNodes[0].nodeValue;

            var row;
            var nameCell;

            if (isIE)
            {
                row = autoTable.insertRow(autoTable.rows.length);
                nameCell = row.insertCell(0);
            }
            else
            {
                row = document.createElement("tr");
                nameCell = document.createElement("td");
                row.appendChild(nameCell);
                autoTable.appendChild(row);
            }

            row.className = "popupRow";
            nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;");
            nameCell.setAttribute("onmouseover", "this.style.background='#fff';this.style.padding='3px 5px 4px 6px';");
            nameCell.setAttribute("onmouseout",  "this.style.background='#e0dcc6';this.style.padding='3px 5px 4px 6px';");

            var linkElement = document.createElement("a");
            linkElement.className = "popupItem";
            linkElement.setAttribute("style", "color:#006699;border:none;");
            linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
            linkElement.setAttribute("href", "javascript:void chooseArch('" + name   + "','" +
                                                                             archId + "')");
            if (listName)
                linkElement.appendChild(document.createTextNode(listName));
            else
                linkElement.appendChild(document.createTextNode(name));
            nameCell.appendChild(linkElement);
        }

        updateAutoTableFocus(archivist);
    }
}

function chooseArch(name, archId)
{
    archivist.value = name;

    var o = document.getElementById("archivistId");
    if (o)
        o.value = archId;

    clearAutoTable();
    updateAutoTableFocus(archivist);
}


/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
   You may not modify, use, reproduce, or distribute this software 
   except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

   Based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/

var recordist;

function doRec(event)
{
    if (event.keyCode == 27 )   // escape
    {
        focus = -1;
        updateAutoTableFocus(recordist);
        return;
    }

    if (event.keyCode == 27 ||  // escape
        event.keyCode == 37 ||  // left
        event.keyCode == 38 ||  // up
        event.keyCode == 39 ||  // right
        event.keyCode == 40)    // down
    {
        return;
    }


    recordist = document.getElementById("recordist");

    moveAutoTable(recordist);

    if (recordist.value == '') { // clear data
        chooseRec('', '');
    } else {
        var url = "/ws/rec?name=" + escape(recordist.value);
        var ajax = new recObject(url);
        ajax.send();
    }
}

function recObject(url) {
    this.url = url;
    var req = init();
    req.onreadystatechange = processRequest;

    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
        {
            isIE = true;
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest ()
    {
        if (req.readyState == 4 && req.status == 200)
            processRec(req.responseXML);
    }

    this.send = function()
    {
        req.open("GET", url, true);
        req.send(null);
    }
}

function processRec(responseXML)
{
    clearAutoTable();

    var recList = responseXML.getElementsByTagName("list")[0];
    if (recList)
    {
        if (recList.childNodes.length > 0)
            autoTable.setAttribute("style", "border:1px solid #ccc;padding:2px;background-color:#fff;");
        else
            focus = -1;

        var lastTypeId = 0;

        for (loop = 0; loop < recList.childNodes.length; loop++)
        {
            var rec = recList.childNodes[loop];

            var listName = '';
            var name     = '';
            var recId    = '';

            if (rec.getElementsByTagName("list-name")[0])
                listName = rec.getElementsByTagName("list-name")[0].childNodes[0].nodeValue;
            else if (rec.getElementsByTagName("name")[0])
                listName = rec.getElementsByTagName("name")[0].childNodes[0].nodeValue;

            if (rec.getElementsByTagName("name")[0])
                name = rec.getElementsByTagName("name"         )[0].childNodes[0].nodeValue;

            if (rec.getElementsByTagName("id")[0])
                recId   = rec.getElementsByTagName("id"        )[0].childNodes[0].nodeValue;

            var row;
            var nameCell;

            if (isIE)
            {
                row = autoTable.insertRow(autoTable.rows.length);
                nameCell = row.insertCell(0);
            }
            else
            {
                row = document.createElement("tr");
                nameCell = document.createElement("td");
                row.appendChild(nameCell);
                autoTable.appendChild(row);
            }

            row.className = "popupRow";
            nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;");
            nameCell.setAttribute("onmouseover", "this.style.background='#fff';this.style.padding='3px 5px 4px 6px';");
            nameCell.setAttribute("onmouseout",  "this.style.background='#e0dcc6';this.style.padding='3px 5px 4px 6px';");

            var linkElement = document.createElement("a");
            linkElement.className = "popupItem";
            linkElement.setAttribute("style", "color:#006699;border:none;");
            linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
            linkElement.setAttribute("href", "javascript:void chooseRec('" + name   + "','" +
                                                                             recId + "')");
            if (listName)
                linkElement.appendChild(document.createTextNode(listName));
            else
                linkElement.appendChild(document.createTextNode(name));
            nameCell.appendChild(linkElement);
        }

        updateAutoTableFocus(recordist);
    }
}

function chooseRec(name, recId)
{
    recordist.value = name;

    var o = document.getElementById("recordistId");
    if (o)
        o.value = recId;

    clearAutoTable();
    updateAutoTableFocus(recordist);
}


// -------------------------------------
// THIS  FILE GENERATED FROM GENAUTO.CSH
// -------------------------------------

/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
   You may not modify, use, reproduce, or distribute this software 
   except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

   Based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/

var behavFunc;

function doBehavFunc(event)
{
    if (event.keyCode == 27 )   // escape
    {
        focus = -1;
        updateAutoTableFocus(behavFunc);
        return;
    }

    if (event.keyCode == 27 ||  // escape
        event.keyCode == 37 ||  // left
        event.keyCode == 38 ||  // up
        event.keyCode == 39 ||  // right
        event.keyCode == 40)    // down
    {
        return;
    }


    behavFunc = document.getElementById("behavFunc");

    moveAutoTable(behavFunc);

    if (behavFunc.value == '') { // clear data
        chooseBehavFunc('', '');
    } else {
        var url = "/ws/bf?name=" + escape(behavFunc.value);
        var ajax = new bfObject(url);
        ajax.send();
    }
}

function bfObject(url) {
    this.url = url;
    var req = init();
    req.onreadystatechange = processRequest;

    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
        {
            isIE = true;
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest ()
    {
        if (req.readyState == 4 && req.status == 200)
            processBehavFunc(req.responseXML);
    }

    this.send = function()
    {
        req.open("GET", url, true);
        req.send(null);
    }
}

function processBehavFunc(responseXML)
{
    clearAutoTable();

    var bfList = responseXML.getElementsByTagName("list")[0];
    if (bfList)
    {
        if (bfList.childNodes.length > 0)
            autoTable.setAttribute("style", "border:1px solid #ccc;padding:2px;background-color:#fff;");
        else
            focus = -1;

        var lastTypeId = 0;

        for (loop = 0; loop < bfList.childNodes.length; loop++)
        {
            var bf = bfList.childNodes[loop];

            var listName = '';
            var name     = '';
            var bfId    = '';

            if (bf.getElementsByTagName("list-name")[0])
                listName = bf.getElementsByTagName("list-name")[0].childNodes[0].nodeValue;
            else if (bf.getElementsByTagName("name")[0])
                listName = bf.getElementsByTagName("name")[0].childNodes[0].nodeValue;

            if (bf.getElementsByTagName("name")[0])
                name = bf.getElementsByTagName("name"         )[0].childNodes[0].nodeValue;

            if (bf.getElementsByTagName("id")[0])
                bfId   = bf.getElementsByTagName("id"        )[0].childNodes[0].nodeValue;

            var row;
            var nameCell;

            if (isIE)
            {
                row = autoTable.insertRow(autoTable.rows.length);
                nameCell = row.insertCell(0);
            }
            else
            {
                row = document.createElement("tr");
                nameCell = document.createElement("td");
                row.appendChild(nameCell);
                autoTable.appendChild(row);
            }

            row.className = "popupRow";
            nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;");
            nameCell.setAttribute("onmouseover", "this.style.background='#fff';this.style.padding='3px 5px 4px 6px';");
            nameCell.setAttribute("onmouseout",  "this.style.background='#e0dcc6';this.style.padding='3px 5px 4px 6px';");

            var linkElement = document.createElement("a");
            linkElement.className = "popupItem";
            linkElement.setAttribute("style", "color:#006699;border:none;");
            linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
            linkElement.setAttribute("href", "javascript:void chooseBehavFunc('" + name   + "','" +
                                                                             bfId + "')");
            if (listName)
                linkElement.appendChild(document.createTextNode(listName));
            else
                linkElement.appendChild(document.createTextNode(name));
            nameCell.appendChild(linkElement);
        }

        updateAutoTableFocus(behavFunc);
    }
}

function chooseBehavFunc(name, bfId)
{
    behavFunc.value = name;

    var o = document.getElementById("behavFuncId");
    if (o)
        o.value = bfId;

    clearAutoTable();
    updateAutoTableFocus(behavFunc);
}


// -------------------------------------
// THIS  FILE GENERATED FROM GENAUTO.CSH
// -------------------------------------

/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
   You may not modify, use, reproduce, or distribute this software 
   except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

   Based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/

var namedBehav;

function doNamedBehav(event)
{
    if (event.keyCode == 27 )   // escape
    {
        focus = -1;
        updateAutoTableFocus(namedBehav);
        return;
    }

    if (event.keyCode == 27 ||  // escape
        event.keyCode == 37 ||  // left
        event.keyCode == 38 ||  // up
        event.keyCode == 39 ||  // right
        event.keyCode == 40)    // down
    {
        return;
    }


    namedBehav = document.getElementById("namedBehav");

    moveAutoTable(namedBehav);

    if (namedBehav.value == '') { // clear data
        chooseNamedBehav('', '');
    } else {
        var url = "/ws/nb?name=" + escape(namedBehav.value);
        var ajax = new nbObject(url);
        ajax.send();
    }
}

function nbObject(url) {
    this.url = url;
    var req = init();
    req.onreadystatechange = processRequest;

    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
        {
            isIE = true;
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest ()
    {
        if (req.readyState == 4 && req.status == 200)
            processNamedBehav(req.responseXML);
    }

    this.send = function()
    {
        req.open("GET", url, true);
        req.send(null);
    }
}

function processNamedBehav(responseXML)
{
    clearAutoTable();

    var nbList = responseXML.getElementsByTagName("list")[0];
    if (nbList)
    {
        if (nbList.childNodes.length > 0)
            autoTable.setAttribute("style", "border:1px solid #ccc;padding:2px;background-color:#fff;");
        else
            focus = -1;

        var lastTypeId = 0;

        for (loop = 0; loop < nbList.childNodes.length; loop++)
        {
            var nb = nbList.childNodes[loop];

            var listName = '';
            var name     = '';
            var nbId    = '';

            if (nb.getElementsByTagName("list-name")[0])
                listName = nb.getElementsByTagName("list-name")[0].childNodes[0].nodeValue;
            else if (nb.getElementsByTagName("name")[0])
                listName = nb.getElementsByTagName("name")[0].childNodes[0].nodeValue;

            if (nb.getElementsByTagName("name")[0])
                name = nb.getElementsByTagName("name"         )[0].childNodes[0].nodeValue;

            if (nb.getElementsByTagName("id")[0])
                nbId   = nb.getElementsByTagName("id"        )[0].childNodes[0].nodeValue;

            var row;
            var nameCell;

            if (isIE)
            {
                row = autoTable.insertRow(autoTable.rows.length);
                nameCell = row.insertCell(0);
            }
            else
            {
                row = document.createElement("tr");
                nameCell = document.createElement("td");
                row.appendChild(nameCell);
                autoTable.appendChild(row);
            }

            row.className = "popupRow";
            nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;");
            nameCell.setAttribute("onmouseover", "this.style.background='#fff';this.style.padding='3px 5px 4px 6px';");
            nameCell.setAttribute("onmouseout",  "this.style.background='#e0dcc6';this.style.padding='3px 5px 4px 6px';");

            var linkElement = document.createElement("a");
            linkElement.className = "popupItem";
            linkElement.setAttribute("style", "color:#006699;border:none;");
            linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
            linkElement.setAttribute("href", "javascript:void chooseNamedBehav('" + name   + "','" +
                                                                             nbId + "')");
            if (listName)
                linkElement.appendChild(document.createTextNode(listName));
            else
                linkElement.appendChild(document.createTextNode(name));
            nameCell.appendChild(linkElement);
        }

        updateAutoTableFocus(namedBehav);
    }
}

function chooseNamedBehav(name, nbId)
{
    namedBehav.value = name;

    var o = document.getElementById("namedBehavId");
    if (o)
        o.value = nbId;

    clearAutoTable();
    updateAutoTableFocus(namedBehav);
}


/*  Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
    You may not modify, use, reproduce, or distribute this software 
    except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

    This based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/



var country;
var countryId;
var subnational1;
var subnational1Id;
var subnational2;
var subnational2Id;
var geoType;


function doGeo(event, n)
{
    if (event.keyCode == 27 ||  // escape
        event.keyCode == 37 ||  // left
        event.keyCode == 38 ||  // up
        event.keyCode == 39 ||  // right
        event.keyCode == 40)    // down
    {
        return;
    }

    geoType = n;

    country        = document.getElementById("country");
    countryId      = document.getElementById("countryId");
    subnational1   = document.getElementById("subnational1");
    subnational1Id = document.getElementById("subnational1Id");
    subnational2   = document.getElementById("subnational2");
    subnational2Id = document.getElementById("subnational2Id");


    var byUrl = '';

    if (geoType == 2)
    {
        if (countryId && countryId.value)
            byUrl = "&country=" + countryId.value;
    }
    else if (geoType == 3)
    {
        if (subnational1Id && subnational1Id.value)
            byUrl = "&subnational1=" + subnational1Id.value;
        else if (countryId && countryId.value)
            byUrl = "&country=" + countryId.value;
    }

    var tmp = getGeoNameByType();

    moveAutoTable(tmp);

    if (tmp.value == '') { // clear data
        chooseGeo(geoType, '', '', '', '', '', '', '', '');
    } else {
        var url = "/ws/geo?name=" + escape(tmp.value) + "&type=" + escape(geoType) + byUrl;
        var ajax = new geoObject(url);
        ajax.send();
    }
}

function geoObject(url) {
    this.url = url;
    var req = init();
    req.onreadystatechange = processRequest;

    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
        {
            isIE = true;
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest ()
    {
        if (req.readyState == 4 && req.status == 200)
            processGeo(req.responseXML);
    }

    this.send = function() {
        req.open("GET", url, true);
        req.send(null);
    }
}

function processGeo(responseXML)
{
    clearAutoTable();

    var geoList = responseXML.getElementsByTagName("list")[0];
    if (geoList)
    {
        if (geoList.childNodes.length > 0)
            autoTable.setAttribute("style", "border:1px solid #ccc;padding:2px;background-color:#fff;");
        else
        {
            getGeoIdByType().value = '';
            focus = -1;
        }

        for (loop = 0; loop < geoList.childNodes.length; loop++)
        {
            var geo = geoList.childNodes[loop];

            var countryId      = '';
            var country        = '';
            var subnational1Id = '';
            var subnational1   = '';
            var subnational2Id = '';
            var subnational2   = '';
            var lat            = '';
            var listName       = '';
            var lon            = '';

            if (geo.getElementsByTagName("id1")[0])
                countryId   = geo.getElementsByTagName("id1"  )[0].childNodes[0].nodeValue;

            if (geo.getElementsByTagName("name1")[0])
                country = geo.getElementsByTagName("name1")[0].childNodes[0].nodeValue;

            if (geo.getElementsByTagName("id2")[0])
                subnational1Id   = geo.getElementsByTagName("id2"  )[0].childNodes[0].nodeValue;

            if (geo.getElementsByTagName("name2")[0])
                subnational1 = geo.getElementsByTagName("name2")[0].childNodes[0].nodeValue;

            if (geo.getElementsByTagName("id3")[0])
                subnational2Id   = geo.getElementsByTagName("id3"  )[0].childNodes[0].nodeValue;

            if (geo.getElementsByTagName("name3")[0])
                subnational2 = geo.getElementsByTagName("name3")[0].childNodes[0].nodeValue;

            if (geo.getElementsByTagName("lat")[0])
                lat      = geo.getElementsByTagName("lat"      )[0].childNodes[0].nodeValue;

            if (geo.getElementsByTagName("list-name")[0])
                listName = geo.getElementsByTagName("list-name")[0].childNodes[0].nodeValue;

            if (geo.getElementsByTagName("lon")[0])
                lon      = geo.getElementsByTagName("lon"      )[0].childNodes[0].nodeValue;

            var row;
            var nameCell;
            if (isIE)
            {
                row = autoTable.insertRow(autoTable.rows.length);
                nameCell = row.insertCell(0);
            }
            else
            {
                row = document.createElement("tr");
                nameCell = document.createElement("td");
                row.appendChild(nameCell);
                autoTable.appendChild(row);
            }

            row.className = "popupRow";
            nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;");
            nameCell.setAttribute("onmouseover", "this.style.background='#fff';this.style.padding='3px 5px 4px 6px';");
            nameCell.setAttribute("onmouseout",  "this.style.background='#e0dcc6';this.style.padding='3px 5px 4px 6px';");

            var linkElement = document.createElement("a");
            linkElement.className = "popupItem";
            linkElement.setAttribute("style", "color:#006699;border:none;");
            linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
            linkElement.setAttribute("href", "javascript:void chooseGeo('','" + 
                                                                        countryId        + "','" + 
                                                                        country          + "','" +
                                                                        subnational1Id   + "','" + 
                                                                        subnational1     + "','" +
                                                                        subnational2Id   + "','" + 
                                                                        subnational2     + "','" +
                                                                        lat              + "','" +
                                                                        lon              + "')");
            linkElement.appendChild(document.createTextNode(listName));
            nameCell.appendChild(linkElement);
        }

        updateAutoTableFocus(getGeoNameByType());
    }
}

/**
 *  When clearing data, type sets the level below to clear it.
 */
function chooseGeo(type, id1, name1, id2, name2, id3, name3, lat, lon)
{
    if (type && type != '')
    {
        if (type <= 3)
        {
            subnational2Id.value = id3; 
            subnational2.value = name3;

            if (type <= 2)
            {
                subnational1Id.value = id2;
                subnational1.value = name2;

                if (type <= 1)
                {
                    countryId.value = id1;
                    country.value = name1;
                }
            }
        }
    }
    else
    {
        countryId.value      = id1;
        subnational1Id.value = id2;
        subnational2Id.value = id3; 
        country.value        = name1;
        subnational1.value   = name2;
        subnational2.value   = name3;
    }

    if (lat != '' && lon != '')
    {
        var latObject = document.getElementById("latitude");
        var lonObject = document.getElementById("longitude");
        var o = document.getElementById("latLonTypeId");

        if (latObject && lonObject && o)
        {
            if ((latObject.value == '' && lonObject.value == '') || (o.value = 8))
            {
                latObject.value = lat;
                lonObject.value = lon;

                if (o)
                    o.value = 8;
            }
        }
    }

    clearAutoTable();
    updateAutoTableFocus(getGeoNameByType());
}

function getGeoIdByType()
{
    var tmp;
    if (geoType == "1")
        tmp = countryId;
    else if (geoType == "2")
        tmp = subnational1Id;
    else if (geoType == "3")
        tmp = subnational2Id;

    return tmp;
}

function getGeoNameByType()
{
    var tmp;
    if (geoType == "1")
        tmp = country;
    else if (geoType == "2")
        tmp = subnational1;
    else if (geoType == "3")
        tmp = subnational2;

    return tmp;
}

// -------------------------------------
// THIS  FILE GENERATED FROM GENAUTO.CSH
// -------------------------------------

/*  Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
    You may not modify, use, reproduce, or distribute this software 
    except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

    This based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/



var geophys1;
var geophys1Id;
var geophys2;
var geophys2Id;
var geophys3;
var geophys3Id;
var geophysType;


function doGeophys(event, n)
{
    if (event.keyCode == 27 ||  // escape
        event.keyCode == 37 ||  // left
        event.keyCode == 38 ||  // up
        event.keyCode == 39 ||  // right
        event.keyCode == 40)    // down
    {
        return;
    }

    geophysType = n;

    geophys1        = document.getElementById("geophys1");
    geophys1Id      = document.getElementById("geophys1Id");
    geophys2   = document.getElementById("geophys2");
    geophys2Id = document.getElementById("geophys2Id");
    geophys3   = document.getElementById("geophys3");
    geophys3Id = document.getElementById("geophys3Id");


    var byUrl = '';

    if (geophysType == 2)
    {
        if (geophys1Id && geophys1Id.value)
            byUrl = "&geophys1=" + geophys1Id.value;
    }
    else if (geophysType == 3)
    {
        if (geophys2Id && geophys2Id.value)
            byUrl = "&geophys2=" + geophys2Id.value;
        else if (geophys1Id && geophys1Id.value)
            byUrl = "&geophys1=" + geophys1Id.value;
    }

    var tmp = getGeophysNameByType();

    moveAutoTable(tmp);

    if (tmp.value == '') { // clear data
        chooseGeophys(geophysType, '', '', '', '', '', '', '', '');
    } else {
        var url = "/ws/geophys?name=" + escape(tmp.value) + "&type=" + escape(geophysType) + byUrl;
        var ajax = new geophysObject(url);
        ajax.send();
    }
}

function geophysObject(url) {
    this.url = url;
    var req = init();
    req.onreadystatechange = processRequest;

    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
        {
            isIE = true;
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest ()
    {
        if (req.readyState == 4 && req.status == 200)
            processGeophys(req.responseXML);
    }

    this.send = function() {
        req.open("GET", url, true);
        req.send(null);
    }
}

function processGeophys(responseXML)
{
    clearAutoTable();

    var geophysList = responseXML.getElementsByTagName("list")[0];
    if (geophysList)
    {
        if (geophysList.childNodes.length > 0)
            autoTable.setAttribute("style", "border:1px solid #ccc;padding:2px;background-color:#fff;");
        else
        {
            getGeophysIdByType().value = '';
            focus = -1;
        }

        for (loop = 0; loop < geophysList.childNodes.length; loop++)
        {
            var geophys = geophysList.childNodes[loop];

            var geophys1Id      = '';
            var geophys1        = '';
            var geophys2Id = '';
            var geophys2   = '';
            var geophys3Id = '';
            var geophys3   = '';
            var lat            = '';
            var listName       = '';
            var lon            = '';

            if (geophys.getElementsByTagName("id1")[0])
                geophys1Id   = geophys.getElementsByTagName("id1"  )[0].childNodes[0].nodeValue;

            if (geophys.getElementsByTagName("name1")[0])
                geophys1 = geophys.getElementsByTagName("name1")[0].childNodes[0].nodeValue;

            if (geophys.getElementsByTagName("id2")[0])
                geophys2Id   = geophys.getElementsByTagName("id2"  )[0].childNodes[0].nodeValue;

            if (geophys.getElementsByTagName("name2")[0])
                geophys2 = geophys.getElementsByTagName("name2")[0].childNodes[0].nodeValue;

            if (geophys.getElementsByTagName("id3")[0])
                geophys3Id   = geophys.getElementsByTagName("id3"  )[0].childNodes[0].nodeValue;

            if (geophys.getElementsByTagName("name3")[0])
                geophys3 = geophys.getElementsByTagName("name3")[0].childNodes[0].nodeValue;

            if (geophys.getElementsByTagName("lat")[0])
                lat      = geophys.getElementsByTagName("lat"      )[0].childNodes[0].nodeValue;

            if (geophys.getElementsByTagName("list-name")[0])
                listName = geophys.getElementsByTagName("list-name")[0].childNodes[0].nodeValue;

            if (geophys.getElementsByTagName("lon")[0])
                lon      = geophys.getElementsByTagName("lon"      )[0].childNodes[0].nodeValue;

            var row;
            var nameCell;
            if (isIE)
            {
                row = autoTable.insertRow(autoTable.rows.length);
                nameCell = row.insertCell(0);
            }
            else
            {
                row = document.createElement("tr");
                nameCell = document.createElement("td");
                row.appendChild(nameCell);
                autoTable.appendChild(row);
            }

            row.className = "popupRow";
            nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;");
            nameCell.setAttribute("onmouseover", "this.style.background='#fff';this.style.padding='3px 5px 4px 6px';");
            nameCell.setAttribute("onmouseout",  "this.style.background='#e0dcc6';this.style.padding='3px 5px 4px 6px';");

            var linkElement = document.createElement("a");
            linkElement.className = "popupItem";
            linkElement.setAttribute("style", "color:#006699;border:none;");
            linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
            linkElement.setAttribute("href", "javascript:void chooseGeophys('','" + 
                                                                        geophys1Id        + "','" + 
                                                                        geophys1          + "','" +
                                                                        geophys2Id   + "','" + 
                                                                        geophys2     + "','" +
                                                                        geophys3Id   + "','" + 
                                                                        geophys3     + "','" +
                                                                        lat              + "','" +
                                                                        lon              + "')");
            linkElement.appendChild(document.createTextNode(listName));
            nameCell.appendChild(linkElement);
        }

        updateAutoTableFocus(getGeophysNameByType());
    }
}

/**
 *  When clearing data, type sets the level below to clear it.
 */
function chooseGeophys(type, id1, name1, id2, name2, id3, name3, lat, lon)
{
    if (type && type != '')
    {
        if (type <= 3)
        {
            geophys3Id.value = id3; 
            geophys3.value = name3;

            if (type <= 2)
            {
                geophys2Id.value = id2;
                geophys2.value = name2;

                if (type <= 1)
                {
                    geophys1Id.value = id1;
                    geophys1.value = name1;
                }
            }
        }
    }
    else
    {
        geophys1Id.value      = id1;
        geophys2Id.value = id2;
        geophys3Id.value = id3; 
        geophys1.value        = name1;
        geophys2.value   = name2;
        geophys3.value   = name3;
    }

    if (lat != '' && lon != '')
    {
        var latObject = document.getElementById("latitude");
        var lonObject = document.getElementById("longitude");
        var o = document.getElementById("latLonTypeId");

        if (latObject && lonObject && o)
        {
            if ((latObject.value == '' && lonObject.value == '') || (o.value = 8))
            {
                latObject.value = lat;
                lonObject.value = lon;

                if (o)
                    o.value = 8;
            }
        }
    }

    clearAutoTable();
    updateAutoTableFocus(getGeophysNameByType());
}

function getGeophysIdByType()
{
    var tmp;
    if (geophysType == "1")
        tmp = geophys1Id;
    else if (geophysType == "2")
        tmp = geophys2Id;
    else if (geophysType == "3")
        tmp = geophys3Id;

    return tmp;
}

function getGeophysNameByType()
{
    var tmp;
    if (geophysType == "1")
        tmp = geophys1;
    else if (geophysType == "2")
        tmp = geophys2;
    else if (geophysType == "3")
        tmp = geophys3;

    return tmp;
}

/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
   You may not modify, use, reproduce, or distribute this software 
   except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

   Based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/

var locality;

function doLoc(event)
{
    if (event.keyCode == 27 )   // escape
    {
        focus = -1;
        updateAutoTableFocus(locality);
        return;
    }

    if (event.keyCode == 27 ||  // escape
        event.keyCode == 37 ||  // left
        event.keyCode == 38 ||  // up
        event.keyCode == 39 ||  // right
        event.keyCode == 40)    // down
    {
        return;
    }


    locality = document.getElementById("locality");

    moveAutoTable(locality);

    if (locality.value == '') { // clear data
        chooseLoc('', '', '', '');
    } else {
        var url = "/ws/loc?name=" + escape(locality.value);
        var ajax = new loc(url);
        ajax.send();
    }
}

function loc(url) {
    this.url = url;
    var req = init();
    req.onreadystatechange = processRequest;

    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
        {
            isIE = true;
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest ()
    {
        if (req.readyState == 4 && req.status == 200)
            processLoc(req.responseXML);
    }

    this.send = function()
    {
        req.open("GET", url, true);
        req.send(null);
    }
}

function processLoc(responseXML)
{
    clearAutoTable();

    var locList = responseXML.getElementsByTagName("loc-list")[0];
    if (locList)
    {
        if (locList.childNodes.length > 0)
            autoTable.setAttribute("style", "border:1px solid #ccc;padding:2px;background-color:#fff;");
        else
            focus = -1;

        var lastTypeId = 0;

        for (loop = 0; loop < locList.childNodes.length; loop++)
        {
            var loc = locList.childNodes[loop];

            var lat      = '';
            var listName = '';
            var lon      = '';
            var name     = '';
            var typeId   = '';
            var typeName = '';

            if (loc.getElementsByTagName("lat")[0])
                lat = loc.getElementsByTagName("lat"           )[0].childNodes[0].nodeValue;

            if (loc.getElementsByTagName("list-name")[0])
                listName = loc.getElementsByTagName("list-name")[0].childNodes[0].nodeValue;

            if (loc.getElementsByTagName("lon")[0])
                lon = loc.getElementsByTagName("lon"           )[0].childNodes[0].nodeValue;

            if (loc.getElementsByTagName("name")[0])
                name = loc.getElementsByTagName("name"         )[0].childNodes[0].nodeValue;

            if (loc.getElementsByTagName("type-id")[0])
                typeId   = loc.getElementsByTagName("type-id"  )[0].childNodes[0].nodeValue;

            if (loc.getElementsByTagName("type-name")[0])
                typeName = loc.getElementsByTagName("type-name")[0].childNodes[0].nodeValue;


            var row;
            var nameCell;

            if (typeId != lastTypeId) // add header row for source of lat/long
            {
                if (isIE)
                {
                    row = autoTable.insertRow(autoTable.rows.length);
                    nameCell = row.insertCell(0);
                }
                else
                {
                    row = document.createElement("tr");
                    nameCell = document.createElement("th");
                    row.appendChild(nameCell);
                    autoTable.appendChild(row);
                }

                row.className = "popupRow";
                nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;font-weight:bold;text-align=center;");

                var text;
                if (typeId == 4)
                    text = 'Getty TGN';
                else if (typeId == 6)
                    text = 'Isler Gazzeteer';
                else
                    text = 'database name here...';

                var linkElement = document.createElement("a");
                linkElement.className = "popupItem";
                linkElement.setAttribute("style", "color:#666;border:none;text-align:center;");
                linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
                linkElement.setAttribute("href", "javascript:;");
                linkElement.appendChild(document.createTextNode(text + ':'));
                nameCell.appendChild(linkElement);

                lastTypeId = typeId;
            }

            if (isIE)
            {
                row = autoTable.insertRow(autoTable.rows.length);
                nameCell = row.insertCell(0);
            }
            else
            {
                row = document.createElement("tr");
                nameCell = document.createElement("td");
                row.appendChild(nameCell);
                autoTable.appendChild(row);
            }

            row.className = "popupRow";
            nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;");
            nameCell.setAttribute("onmouseover", "this.style.background='#fff';this.style.padding='3px 5px 4px 6px';");
            nameCell.setAttribute("onmouseout",  "this.style.background='#e0dcc6';this.style.padding='3px 5px 4px 6px';");

            var linkElement = document.createElement("a");
            linkElement.className = "popupItem";
            linkElement.setAttribute("style", "color:#006699;border:none;");
            linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
            linkElement.setAttribute("href", "javascript:void chooseLoc('" + name   + "','" +
                                                                             lat    + "','" +
                                                                             lon    + "','" +
                                                                             typeId + "')");
            linkElement.appendChild(document.createTextNode(listName));
            nameCell.appendChild(linkElement);
        }

        updateAutoTableFocus(locality);
    }
}

function chooseLoc(name, lat, lon, type)
{
    locality.value = name;

    var latObject = document.getElementById("latitude");
    var lonObject = document.getElementById("longitude");

    if (latObject && 
        lonObject && 
        lat && 
        lon && 
        lat != '' && 
        lon != '')
    {
        latObject.value = lat;
        lonObject.value = lon;
    }

    if (type)
    {
        var o = document.getElementById("latLonTypeId");
        if (o)
            o.value = type;
    }

    clearAutoTable();
    updateAutoTableFocus(locality);
}


// -------------------------------------
// THIS  FILE GENERATED FROM GENAUTO.CSH
// -------------------------------------

/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
   You may not modify, use, reproduce, or distribute this software 
   except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

   Based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/

var taxon;

function doTaxon(event)
{
    if (event.keyCode == 27 )   // escape
    {
        focus = -1;
        updateAutoTableFocus(taxon);
        return;
    }

    if (event.keyCode == 27 ||  // escape
        event.keyCode == 37 ||  // left
        event.keyCode == 38 ||  // up
        event.keyCode == 39 ||  // right
        event.keyCode == 40)    // down
    {
        return;
    }


    taxon = document.getElementById("taxon");

    moveAutoTable(taxon);

    if (taxon.value == '') { // clear data
        chooseTaxon('', '');
    } else {
        var url = "/ws/t?name=" + escape(taxon.value);
        var ajax = new tObject(url);
        ajax.send();
    }
}

function tObject(url) {
    this.url = url;
    var req = init();
    req.onreadystatechange = processRequest;

    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
        {
            isIE = true;
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest ()
    {
        if (req.readyState == 4 && req.status == 200)
            processTaxon(req.responseXML);
    }

    this.send = function()
    {
        req.open("GET", url, true);
        req.send(null);
    }
}

function processTaxon(responseXML)
{
    clearAutoTable();

    var tList = responseXML.getElementsByTagName("list")[0];
    if (tList)
    {
        if (tList.childNodes.length > 0)
            autoTable.setAttribute("style", "border:1px solid #ccc;padding:2px;background-color:#fff;");
        else
            focus = -1;

        var lastTypeId = 0;

        for (loop = 0; loop < tList.childNodes.length; loop++)
        {
            var t = tList.childNodes[loop];

            var listName = '';
            var name     = '';
            var tId    = '';

            if (t.getElementsByTagName("list-name")[0])
                listName = t.getElementsByTagName("list-name")[0].childNodes[0].nodeValue;
            else if (t.getElementsByTagName("name")[0])
                listName = t.getElementsByTagName("name")[0].childNodes[0].nodeValue;

            if (t.getElementsByTagName("name")[0])
                name = t.getElementsByTagName("name"         )[0].childNodes[0].nodeValue;

            if (t.getElementsByTagName("id")[0])
                tId   = t.getElementsByTagName("id"        )[0].childNodes[0].nodeValue;

            var row;
            var nameCell;

            if (isIE)
            {
                row = autoTable.insertRow(autoTable.rows.length);
                nameCell = row.insertCell(0);
            }
            else
            {
                row = document.createElement("tr");
                nameCell = document.createElement("td");
                row.appendChild(nameCell);
                autoTable.appendChild(row);
            }

            row.className = "popupRow";
            nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;");
            nameCell.setAttribute("onmouseover", "this.style.background='#fff';this.style.padding='3px 5px 4px 6px';");
            nameCell.setAttribute("onmouseout",  "this.style.background='#e0dcc6';this.style.padding='3px 5px 4px 6px';");

            var linkElement = document.createElement("a");
            linkElement.className = "popupItem";
            linkElement.setAttribute("style", "color:#006699;border:none;");
            linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
            linkElement.setAttribute("href", "javascript:void chooseTaxon('" + name   + "','" +
                                                                             tId + "')");
            if (listName)
                linkElement.appendChild(document.createTextNode(listName));
            else
                linkElement.appendChild(document.createTextNode(name));
            nameCell.appendChild(linkElement);
        }

        updateAutoTableFocus(taxon);
    }
}

function chooseTaxon(name, tId)
{
    taxon.value = name;

    var o = document.getElementById("taxonId");
    if (o)
        o.value = tId;

    clearAutoTable();
    updateAutoTableFocus(taxon);
}


// -------------------------------------
// THIS  FILE GENERATED FROM GENAUTO.CSH
// -------------------------------------

/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
   You may not modify, use, reproduce, or distribute this software 
   except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

   Based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/

var taxonCommon;

function doTaxonCommon(event)
{
    if (event.keyCode == 27 )   // escape
    {
        focus = -1;
        updateAutoTableFocus(taxonCommon);
        return;
    }

    if (event.keyCode == 27 ||  // escape
        event.keyCode == 37 ||  // left
        event.keyCode == 38 ||  // up
        event.keyCode == 39 ||  // right
        event.keyCode == 40)    // down
    {
        return;
    }


    taxonCommon = document.getElementById("taxonCommon");

    moveAutoTable(taxonCommon);

    if (taxonCommon.value == '') { // clear data
        chooseTaxonCommon('', '');
    } else {
        var url = "/ws/tc?name=" + escape(taxonCommon.value);
        var ajax = new tcObject(url);
        ajax.send();
    }
}

function tcObject(url) {
    this.url = url;
    var req = init();
    req.onreadystatechange = processRequest;

    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
        {
            isIE = true;
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest ()
    {
        if (req.readyState == 4 && req.status == 200)
            processTaxonCommon(req.responseXML);
    }

    this.send = function()
    {
        req.open("GET", url, true);
        req.send(null);
    }
}

function processTaxonCommon(responseXML)
{
    clearAutoTable();

    var tcList = responseXML.getElementsByTagName("list")[0];
    if (tcList)
    {
        if (tcList.childNodes.length > 0)
            autoTable.setAttribute("style", "border:1px solid #ccc;padding:2px;background-color:#fff;");
        else
            focus = -1;

        var lastTypeId = 0;

        for (loop = 0; loop < tcList.childNodes.length; loop++)
        {
            var tc = tcList.childNodes[loop];

            var listName = '';
            var name     = '';
            var tcId    = '';

            if (tc.getElementsByTagName("list-name")[0])
                listName = tc.getElementsByTagName("list-name")[0].childNodes[0].nodeValue;
            else if (tc.getElementsByTagName("name")[0])
                listName = tc.getElementsByTagName("name")[0].childNodes[0].nodeValue;

            if (tc.getElementsByTagName("name")[0])
                name = tc.getElementsByTagName("name"         )[0].childNodes[0].nodeValue;

            if (tc.getElementsByTagName("id")[0])
                tcId   = tc.getElementsByTagName("id"        )[0].childNodes[0].nodeValue;

            var row;
            var nameCell;

            if (isIE)
            {
                row = autoTable.insertRow(autoTable.rows.length);
                nameCell = row.insertCell(0);
            }
            else
            {
                row = document.createElement("tr");
                nameCell = document.createElement("td");
                row.appendChild(nameCell);
                autoTable.appendChild(row);
            }

            row.className = "popupRow";
            nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;");
            nameCell.setAttribute("onmouseover", "this.style.background='#fff';this.style.padding='3px 5px 4px 6px';");
            nameCell.setAttribute("onmouseout",  "this.style.background='#e0dcc6';this.style.padding='3px 5px 4px 6px';");

            var linkElement = document.createElement("a");
            linkElement.className = "popupItem";
            linkElement.setAttribute("style", "color:#006699;border:none;");
            linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
            linkElement.setAttribute("href", "javascript:void chooseTaxonCommon('" + name   + "','" +
                                                                             tcId + "')");
            if (listName)
                linkElement.appendChild(document.createTextNode(listName));
            else
                linkElement.appendChild(document.createTextNode(name));
            nameCell.appendChild(linkElement);
        }

        updateAutoTableFocus(taxonCommon);
    }
}

function chooseTaxonCommon(name, tcId)
{
    taxonCommon.value = name;

    var o = document.getElementById("taxonCommonId");
    if (o)
        o.value = tcId;

    clearAutoTable();
    updateAutoTableFocus(taxonCommon);
}


// -------------------------------------
// THIS  FILE GENERATED FROM GENAUTO.CSH
// -------------------------------------

/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
   You may not modify, use, reproduce, or distribute this software 
   except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

   Based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/

var searchRecordist;

function doSearchRec(event)
{
    if (event.keyCode == 27 )   // escape
    {
        focus = -1;
        updateAutoTableFocus(searchRecordist);
        return;
    }

    if (event.keyCode == 27 ||  // escape
        event.keyCode == 37 ||  // left
        event.keyCode == 38 ||  // up
        event.keyCode == 39 ||  // right
        event.keyCode == 40)    // down
    {
        return;
    }


    searchRecordist = document.getElementById("searchRecordist");

    moveAutoTable(searchRecordist);

    if (searchRecordist.value == '') { // clear data
        chooseSearchRec('', '');
    } else {
        var url = "/ws/rec?name=" + escape(searchRecordist.value);
        var ajax = new searchRecObject(url);
        ajax.send();
    }
}

function searchRecObject(url) {
    this.url = url;
    var req = init();
    req.onreadystatechange = processRequest;

    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
        {
            isIE = true;
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest ()
    {
        if (req.readyState == 4 && req.status == 200)
            processSearchRec(req.responseXML);
    }

    this.send = function()
    {
        req.open("GET", url, true);
        req.send(null);
    }
}

function processSearchRec(responseXML)
{
    clearAutoTable();

    var recList = responseXML.getElementsByTagName("list")[0];
    if (recList)
    {
        if (recList.childNodes.length > 0)
            autoTable.setAttribute("style", "border:1px solid #ccc;padding:2px;background-color:#fff;");
        else
            focus = -1;

        var lastTypeId = 0;

        for (loop = 0; loop < recList.childNodes.length; loop++)
        {
            var rec = recList.childNodes[loop];

            var listName = '';
            var name     = '';
            var recId    = '';

            if (rec.getElementsByTagName("list-name")[0])
                listName = rec.getElementsByTagName("list-name")[0].childNodes[0].nodeValue;
            else if (rec.getElementsByTagName("name")[0])
                listName = rec.getElementsByTagName("name")[0].childNodes[0].nodeValue;

            if (rec.getElementsByTagName("name")[0])
                name = rec.getElementsByTagName("name"         )[0].childNodes[0].nodeValue;

            if (rec.getElementsByTagName("id")[0])
                recId   = rec.getElementsByTagName("id"        )[0].childNodes[0].nodeValue;

            var row;
            var nameCell;

            if (isIE)
            {
                row = autoTable.insertRow(autoTable.rows.length);
                nameCell = row.insertCell(0);
            }
            else
            {
                row = document.createElement("tr");
                nameCell = document.createElement("td");
                row.appendChild(nameCell);
                autoTable.appendChild(row);
            }

            row.className = "popupRow";
            nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;");
            nameCell.setAttribute("onmouseover", "this.style.background='#fff';this.style.padding='3px 5px 4px 6px';");
            nameCell.setAttribute("onmouseout",  "this.style.background='#e0dcc6';this.style.padding='3px 5px 4px 6px';");

            var linkElement = document.createElement("a");
            linkElement.className = "popupItem";
            linkElement.setAttribute("style", "color:#006699;border:none;");
            linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
            linkElement.setAttribute("href", "javascript:void chooseSearchRec('" + name   + "','" +
                                                                             recId + "')");
            if (listName)
                linkElement.appendChild(document.createTextNode(listName));
            else
                linkElement.appendChild(document.createTextNode(name));
            nameCell.appendChild(linkElement);
        }

        updateAutoTableFocus(searchRecordist);
    }
}

function chooseSearchRec(name, recId)
{
    searchRecordist.value = name;

    var o = document.getElementById("searchRecordistId");
    if (o)
        o.value = recId;

    clearAutoTable();
    updateAutoTableFocus(searchRecordist);
}


// -------------------------------------
// THIS  FILE GENERATED FROM GENAUTO.CSH
// -------------------------------------

/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
   You may not modify, use, reproduce, or distribute this software 
   except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

   Based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/

var searchArchivist;

function doSearchArch(event)
{
    if (event.keyCode == 27 )   // escape
    {
        focus = -1;
        updateAutoTableFocus(searchArchivist);
        return;
    }

    if (event.keyCode == 27 ||  // escape
        event.keyCode == 37 ||  // left
        event.keyCode == 38 ||  // up
        event.keyCode == 39 ||  // right
        event.keyCode == 40)    // down
    {
        return;
    }


    searchArchivist = document.getElementById("searchArchivist");

    moveAutoTable(searchArchivist);

    if (searchArchivist.value == '') { // clear data
        chooseSearchArch('', '');
    } else {
        var url = "/ws/arch?name=" + escape(searchArchivist.value);
        var ajax = new searchArchObject(url);
        ajax.send();
    }
}

function searchArchObject(url) {
    this.url = url;
    var req = init();
    req.onreadystatechange = processRequest;

    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
        {
            isIE = true;
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest ()
    {
        if (req.readyState == 4 && req.status == 200)
            processSearchArch(req.responseXML);
    }

    this.send = function()
    {
        req.open("GET", url, true);
        req.send(null);
    }
}

function processSearchArch(responseXML)
{
    clearAutoTable();

    var archList = responseXML.getElementsByTagName("list")[0];
    if (archList)
    {
        if (archList.childNodes.length > 0)
            autoTable.setAttribute("style", "border:1px solid #ccc;padding:2px;background-color:#fff;");
        else
            focus = -1;

        var lastTypeId = 0;

        for (loop = 0; loop < archList.childNodes.length; loop++)
        {
            var arch = archList.childNodes[loop];

            var listName = '';
            var name     = '';
            var archId    = '';

            if (arch.getElementsByTagName("list-name")[0])
                listName = arch.getElementsByTagName("list-name")[0].childNodes[0].nodeValue;
            else if (arch.getElementsByTagName("name")[0])
                listName = arch.getElementsByTagName("name")[0].childNodes[0].nodeValue;

            if (arch.getElementsByTagName("name")[0])
                name = arch.getElementsByTagName("name"         )[0].childNodes[0].nodeValue;

            if (arch.getElementsByTagName("id")[0])
                archId   = arch.getElementsByTagName("id"        )[0].childNodes[0].nodeValue;

            var row;
            var nameCell;

            if (isIE)
            {
                row = autoTable.insertRow(autoTable.rows.length);
                nameCell = row.insertCell(0);
            }
            else
            {
                row = document.createElement("tr");
                nameCell = document.createElement("td");
                row.appendChild(nameCell);
                autoTable.appendChild(row);
            }

            row.className = "popupRow";
            nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;");
            nameCell.setAttribute("onmouseover", "this.style.background='#fff';this.style.padding='3px 5px 4px 6px';");
            nameCell.setAttribute("onmouseout",  "this.style.background='#e0dcc6';this.style.padding='3px 5px 4px 6px';");

            var linkElement = document.createElement("a");
            linkElement.className = "popupItem";
            linkElement.setAttribute("style", "color:#006699;border:none;");
            linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
            linkElement.setAttribute("href", "javascript:void chooseSearchArch('" + name   + "','" +
                                                                             archId + "')");
            if (listName)
                linkElement.appendChild(document.createTextNode(listName));
            else
                linkElement.appendChild(document.createTextNode(name));
            nameCell.appendChild(linkElement);
        }

        updateAutoTableFocus(searchArchivist);
    }
}

function chooseSearchArch(name, archId)
{
    searchArchivist.value = name;

    var o = document.getElementById("searchArchivistId");
    if (o)
        o.value = archId;

    clearAutoTable();
    updateAutoTableFocus(searchArchivist);
}


/*  Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
    You may not modify, use, reproduce, or distribute this software 
    except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

    This based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/



var searchCountry;
var searchCountryId;
var searchSubnational1;
var searchSubnational1Id;
var searchSubnational2;
var searchSubnational2Id;
var searchGeoType;


function doSearchGeo(event, n)
{
    if (event.keyCode == 27 ||  // escape
        event.keyCode == 37 ||  // left
        event.keyCode == 38 ||  // up
        event.keyCode == 39 ||  // right
        event.keyCode == 40)    // down
    {
        return;
    }

    searchGeoType = n;

    searchCountry        = document.getElementById("searchCountry");
    searchCountryId      = document.getElementById("searchCountryId");
    searchSubnational1   = document.getElementById("searchSubnational1");
    searchSubnational1Id = document.getElementById("searchSubnational1Id");
    searchSubnational2   = document.getElementById("searchSubnational2");
    searchSubnational2Id = document.getElementById("searchSubnational2Id");


    var byUrl = '';

    if (searchGeoType == 2)
    {
        if (searchCountryId && searchCountryId.value)
            byUrl = "&searchCountry=" + searchCountryId.value;
    }
    else if (searchGeoType == 3)
    {
        if (searchSubnational1Id && searchSubnational1Id.value)
            byUrl = "&searchSubnational1=" + searchSubnational1Id.value;
        else if (searchCountryId && searchCountryId.value)
            byUrl = "&searchCountry=" + searchCountryId.value;
    }

    var tmp = getSearchGeoNameByType();

    moveAutoTable(tmp);

    if (tmp.value == '') { // clear data
        chooseSearchGeo(searchGeoType, '', '', '', '', '', '', '', '');
    } else {
        var url = "/ws/geo?name=" + escape(tmp.value) + "&type=" + escape(searchGeoType) + byUrl;
        var ajax = new searchGeoObject(url);
        ajax.send();
    }
}

function searchGeoObject(url) {
    this.url = url;
    var req = init();
    req.onreadystatechange = processRequest;

    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
        {
            isIE = true;
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest ()
    {
        if (req.readyState == 4 && req.status == 200)
            processSearchGeo(req.responseXML);
    }

    this.send = function() {
        req.open("GET", url, true);
        req.send(null);
    }
}

function processSearchGeo(responseXML)
{
    clearAutoTable();

    var searchGeoList = responseXML.getElementsByTagName("list")[0];
    if (searchGeoList)
    {
        if (searchGeoList.childNodes.length > 0)
            autoTable.setAttribute("style", "border:1px solid #ccc;padding:2px;background-color:#fff;");
        else
        {
            getSearchGeoIdByType().value = '';
            focus = -1;
        }

        for (loop = 0; loop < searchGeoList.childNodes.length; loop++)
        {
            var searchGeo = searchGeoList.childNodes[loop];

            var searchCountryId      = '';
            var searchCountry        = '';
            var searchSubnational1Id = '';
            var searchSubnational1   = '';
            var searchSubnational2Id = '';
            var searchSubnational2   = '';
            var lat            = '';
            var listName       = '';
            var lon            = '';

            if (searchGeo.getElementsByTagName("id1")[0])
                searchCountryId   = searchGeo.getElementsByTagName("id1"  )[0].childNodes[0].nodeValue;

            if (searchGeo.getElementsByTagName("name1")[0])
                searchCountry = searchGeo.getElementsByTagName("name1")[0].childNodes[0].nodeValue;

            if (searchGeo.getElementsByTagName("id2")[0])
                searchSubnational1Id   = searchGeo.getElementsByTagName("id2"  )[0].childNodes[0].nodeValue;

            if (searchGeo.getElementsByTagName("name2")[0])
                searchSubnational1 = searchGeo.getElementsByTagName("name2")[0].childNodes[0].nodeValue;

            if (searchGeo.getElementsByTagName("id3")[0])
                searchSubnational2Id   = searchGeo.getElementsByTagName("id3"  )[0].childNodes[0].nodeValue;

            if (searchGeo.getElementsByTagName("name3")[0])
                searchSubnational2 = searchGeo.getElementsByTagName("name3")[0].childNodes[0].nodeValue;

            if (searchGeo.getElementsByTagName("lat")[0])
                lat      = searchGeo.getElementsByTagName("lat"      )[0].childNodes[0].nodeValue;

            if (searchGeo.getElementsByTagName("list-name")[0])
                listName = searchGeo.getElementsByTagName("list-name")[0].childNodes[0].nodeValue;

            if (searchGeo.getElementsByTagName("lon")[0])
                lon      = searchGeo.getElementsByTagName("lon"      )[0].childNodes[0].nodeValue;

            var row;
            var nameCell;
            if (isIE)
            {
                row = autoTable.insertRow(autoTable.rows.length);
                nameCell = row.insertCell(0);
            }
            else
            {
                row = document.createElement("tr");
                nameCell = document.createElement("td");
                row.appendChild(nameCell);
                autoTable.appendChild(row);
            }

            row.className = "popupRow";
            nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;");
            nameCell.setAttribute("onmouseover", "this.style.background='#fff';this.style.padding='3px 5px 4px 6px';");
            nameCell.setAttribute("onmouseout",  "this.style.background='#e0dcc6';this.style.padding='3px 5px 4px 6px';");

            var linkElement = document.createElement("a");
            linkElement.className = "popupItem";
            linkElement.setAttribute("style", "color:#006699;border:none;");
            linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
            linkElement.setAttribute("href", "javascript:void chooseSearchGeo('','" + 
                                                                        searchCountryId        + "','" + 
                                                                        searchCountry          + "','" +
                                                                        searchSubnational1Id   + "','" + 
                                                                        searchSubnational1     + "','" +
                                                                        searchSubnational2Id   + "','" + 
                                                                        searchSubnational2     + "','" +
                                                                        lat              + "','" +
                                                                        lon              + "')");
            linkElement.appendChild(document.createTextNode(listName));
            nameCell.appendChild(linkElement);
        }

        updateAutoTableFocus(getSearchGeoNameByType());
    }
}

/**
 *  When clearing data, type sets the level below to clear it.
 */
function chooseSearchGeo(type, id1, name1, id2, name2, id3, name3, lat, lon)
{
    if (type && type != '')
    {
        if (type <= 3)
        {
            searchSubnational2Id.value = id3; 
            searchSubnational2.value = name3;

            if (type <= 2)
            {
                searchSubnational1Id.value = id2;
                searchSubnational1.value = name2;

                if (type <= 1)
                {
                    searchCountryId.value = id1;
                    searchCountry.value = name1;
                }
            }
        }
    }
    else
    {
        searchCountryId.value      = id1;
        searchSubnational1Id.value = id2;
        searchSubnational2Id.value = id3; 
        searchCountry.value        = name1;
        searchSubnational1.value   = name2;
        searchSubnational2.value   = name3;
    }

    if (lat != '' && lon != '')
    {
        var latObject = document.getElementById("latitude");
        var lonObject = document.getElementById("longitude");
        var o = document.getElementById("latLonTypeId");

        if (latObject && lonObject && o)
        {
            if ((latObject.value == '' && lonObject.value == '') || (o.value = 8))
            {
                latObject.value = lat;
                lonObject.value = lon;

                if (o)
                    o.value = 8;
            }
        }
    }

    clearAutoTable();
    updateAutoTableFocus(getSearchGeoNameByType());
}

function getSearchGeoIdByType()
{
    var tmp;
    if (searchGeoType == "1")
        tmp = searchCountryId;
    else if (searchGeoType == "2")
        tmp = searchSubnational1Id;
    else if (searchGeoType == "3")
        tmp = searchSubnational2Id;

    return tmp;
}

function getSearchGeoNameByType()
{
    var tmp;
    if (searchGeoType == "1")
        tmp = searchCountry;
    else if (searchGeoType == "2")
        tmp = searchSubnational1;
    else if (searchGeoType == "3")
        tmp = searchSubnational2;

    return tmp;
}

// -------------------------------------
// THIS  FILE GENERATED FROM GENAUTO.CSH
// -------------------------------------

/*  Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
    You may not modify, use, reproduce, or distribute this software 
    except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

    This based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/



var searchGeophys1;
var searchGeophys1Id;
var searchGeophys2;
var searchGeophys2Id;
var searchGeophys3;
var searchGeophys3Id;
var searchGeophysType;


function doSearchGeophys(event, n)
{
    if (event.keyCode == 27 ||  // escape
        event.keyCode == 37 ||  // left
        event.keyCode == 38 ||  // up
        event.keyCode == 39 ||  // right
        event.keyCode == 40)    // down
    {
        return;
    }

    searchGeophysType = n;

    searchGeophys1        = document.getElementById("searchGeophys1");
    searchGeophys1Id      = document.getElementById("searchGeophys1Id");
    searchGeophys2   = document.getElementById("searchGeophys2");
    searchGeophys2Id = document.getElementById("searchGeophys2Id");
    searchGeophys3   = document.getElementById("searchGeophys3");
    searchGeophys3Id = document.getElementById("searchGeophys3Id");


    var byUrl = '';

    if (searchGeophysType == 2)
    {
        if (searchGeophys1Id && searchGeophys1Id.value)
            byUrl = "&searchGeophys1=" + searchGeophys1Id.value;
    }
    else if (searchGeophysType == 3)
    {
        if (searchGeophys2Id && searchGeophys2Id.value)
            byUrl = "&searchGeophys2=" + searchGeophys2Id.value;
        else if (searchGeophys1Id && searchGeophys1Id.value)
            byUrl = "&searchGeophys1=" + searchGeophys1Id.value;
    }

    var tmp = getSearchGeophysNameByType();

    moveAutoTable(tmp);

    if (tmp.value == '') { // clear data
        chooseSearchGeophys(searchGeophysType, '', '', '', '', '', '', '', '');
    } else {
        var url = "/ws/geophys?name=" + escape(tmp.value) + "&type=" + escape(searchGeophysType) + byUrl;
        var ajax = new searchGeophysObject(url);
        ajax.send();
    }
}

function searchGeophysObject(url) {
    this.url = url;
    var req = init();
    req.onreadystatechange = processRequest;

    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
        {
            isIE = true;
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest ()
    {
        if (req.readyState == 4 && req.status == 200)
            processSearchGeophys(req.responseXML);
    }

    this.send = function() {
        req.open("GET", url, true);
        req.send(null);
    }
}

function processSearchGeophys(responseXML)
{
    clearAutoTable();

    var searchGeophysList = responseXML.getElementsByTagName("list")[0];
    if (searchGeophysList)
    {
        if (searchGeophysList.childNodes.length > 0)
            autoTable.setAttribute("style", "border:1px solid #ccc;padding:2px;background-color:#fff;");
        else
        {
            getSearchGeophysIdByType().value = '';
            focus = -1;
        }

        for (loop = 0; loop < searchGeophysList.childNodes.length; loop++)
        {
            var searchGeophys = searchGeophysList.childNodes[loop];

            var searchGeophys1Id      = '';
            var searchGeophys1        = '';
            var searchGeophys2Id = '';
            var searchGeophys2   = '';
            var searchGeophys3Id = '';
            var searchGeophys3   = '';
            var lat            = '';
            var listName       = '';
            var lon            = '';

            if (searchGeophys.getElementsByTagName("id1")[0])
                searchGeophys1Id   = searchGeophys.getElementsByTagName("id1"  )[0].childNodes[0].nodeValue;

            if (searchGeophys.getElementsByTagName("name1")[0])
                searchGeophys1 = searchGeophys.getElementsByTagName("name1")[0].childNodes[0].nodeValue;

            if (searchGeophys.getElementsByTagName("id2")[0])
                searchGeophys2Id   = searchGeophys.getElementsByTagName("id2"  )[0].childNodes[0].nodeValue;

            if (searchGeophys.getElementsByTagName("name2")[0])
                searchGeophys2 = searchGeophys.getElementsByTagName("name2")[0].childNodes[0].nodeValue;

            if (searchGeophys.getElementsByTagName("id3")[0])
                searchGeophys3Id   = searchGeophys.getElementsByTagName("id3"  )[0].childNodes[0].nodeValue;

            if (searchGeophys.getElementsByTagName("name3")[0])
                searchGeophys3 = searchGeophys.getElementsByTagName("name3")[0].childNodes[0].nodeValue;

            if (searchGeophys.getElementsByTagName("lat")[0])
                lat      = searchGeophys.getElementsByTagName("lat"      )[0].childNodes[0].nodeValue;

            if (searchGeophys.getElementsByTagName("list-name")[0])
                listName = searchGeophys.getElementsByTagName("list-name")[0].childNodes[0].nodeValue;

            if (searchGeophys.getElementsByTagName("lon")[0])
                lon      = searchGeophys.getElementsByTagName("lon"      )[0].childNodes[0].nodeValue;

            var row;
            var nameCell;
            if (isIE)
            {
                row = autoTable.insertRow(autoTable.rows.length);
                nameCell = row.insertCell(0);
            }
            else
            {
                row = document.createElement("tr");
                nameCell = document.createElement("td");
                row.appendChild(nameCell);
                autoTable.appendChild(row);
            }

            row.className = "popupRow";
            nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;");
            nameCell.setAttribute("onmouseover", "this.style.background='#fff';this.style.padding='3px 5px 4px 6px';");
            nameCell.setAttribute("onmouseout",  "this.style.background='#e0dcc6';this.style.padding='3px 5px 4px 6px';");

            var linkElement = document.createElement("a");
            linkElement.className = "popupItem";
            linkElement.setAttribute("style", "color:#006699;border:none;");
            linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
            linkElement.setAttribute("href", "javascript:void chooseSearchGeophys('','" + 
                                                                        searchGeophys1Id        + "','" + 
                                                                        searchGeophys1          + "','" +
                                                                        searchGeophys2Id   + "','" + 
                                                                        searchGeophys2     + "','" +
                                                                        searchGeophys3Id   + "','" + 
                                                                        searchGeophys3     + "','" +
                                                                        lat              + "','" +
                                                                        lon              + "')");
            linkElement.appendChild(document.createTextNode(listName));
            nameCell.appendChild(linkElement);
        }

        updateAutoTableFocus(getSearchGeophysNameByType());
    }
}

/**
 *  When clearing data, type sets the level below to clear it.
 */
function chooseSearchGeophys(type, id1, name1, id2, name2, id3, name3, lat, lon)
{
    if (type && type != '')
    {
        if (type <= 3)
        {
            searchGeophys3Id.value = id3; 
            searchGeophys3.value = name3;

            if (type <= 2)
            {
                searchGeophys2Id.value = id2;
                searchGeophys2.value = name2;

                if (type <= 1)
                {
                    searchGeophys1Id.value = id1;
                    searchGeophys1.value = name1;
                }
            }
        }
    }
    else
    {
        searchGeophys1Id.value      = id1;
        searchGeophys2Id.value = id2;
        searchGeophys3Id.value = id3; 
        searchGeophys1.value        = name1;
        searchGeophys2.value   = name2;
        searchGeophys3.value   = name3;
    }

    if (lat != '' && lon != '')
    {
        var latObject = document.getElementById("latitude");
        var lonObject = document.getElementById("longitude");
        var o = document.getElementById("latLonTypeId");

        if (latObject && lonObject && o)
        {
            if ((latObject.value == '' && lonObject.value == '') || (o.value = 8))
            {
                latObject.value = lat;
                lonObject.value = lon;

                if (o)
                    o.value = 8;
            }
        }
    }

    clearAutoTable();
    updateAutoTableFocus(getSearchGeophysNameByType());
}

function getSearchGeophysIdByType()
{
    var tmp;
    if (searchGeophysType == "1")
        tmp = searchGeophys1Id;
    else if (searchGeophysType == "2")
        tmp = searchGeophys2Id;
    else if (searchGeophysType == "3")
        tmp = searchGeophys3Id;

    return tmp;
}

function getSearchGeophysNameByType()
{
    var tmp;
    if (searchGeophysType == "1")
        tmp = searchGeophys1;
    else if (searchGeophysType == "2")
        tmp = searchGeophys2;
    else if (searchGeophysType == "3")
        tmp = searchGeophys3;

    return tmp;
}

// -------------------------------------
// THIS  FILE GENERATED FROM GENAUTO.CSH
// -------------------------------------

/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
   You may not modify, use, reproduce, or distribute this software 
   except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

   Based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/

var searchNamedBehav;

function doSearchNamedBehav(event)
{
    if (event.keyCode == 27 )   // escape
    {
        focus = -1;
        updateAutoTableFocus(searchNamedBehav);
        return;
    }

    if (event.keyCode == 27 ||  // escape
        event.keyCode == 37 ||  // left
        event.keyCode == 38 ||  // up
        event.keyCode == 39 ||  // right
        event.keyCode == 40)    // down
    {
        return;
    }


    searchNamedBehav = document.getElementById("searchNamedBehav");

    moveAutoTable(searchNamedBehav);

    if (searchNamedBehav.value == '') { // clear data
        chooseSearchNamedBehav('', '');
    } else {
        var url = "/ws/nb?name=" + escape(searchNamedBehav.value);
        var ajax = new nbObject(url);
        ajax.send();
    }
}

function nbObject(url) {
    this.url = url;
    var req = init();
    req.onreadystatechange = processRequest;

    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
        {
            isIE = true;
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest ()
    {
        if (req.readyState == 4 && req.status == 200)
            processSearchNamedBehav(req.responseXML);
    }

    this.send = function()
    {
        req.open("GET", url, true);
        req.send(null);
    }
}

function processSearchNamedBehav(responseXML)
{
    clearAutoTable();

    var nbList = responseXML.getElementsByTagName("list")[0];
    if (nbList)
    {
        if (nbList.childNodes.length > 0)
            autoTable.setAttribute("style", "border:1px solid #ccc;padding:2px;background-color:#fff;");
        else
            focus = -1;

        var lastTypeId = 0;

        for (loop = 0; loop < nbList.childNodes.length; loop++)
        {
            var nb = nbList.childNodes[loop];

            var listName = '';
            var name     = '';
            var nbId    = '';

            if (nb.getElementsByTagName("list-name")[0])
                listName = nb.getElementsByTagName("list-name")[0].childNodes[0].nodeValue;
            else if (nb.getElementsByTagName("name")[0])
                listName = nb.getElementsByTagName("name")[0].childNodes[0].nodeValue;

            if (nb.getElementsByTagName("name")[0])
                name = nb.getElementsByTagName("name"         )[0].childNodes[0].nodeValue;

            if (nb.getElementsByTagName("id")[0])
                nbId   = nb.getElementsByTagName("id"        )[0].childNodes[0].nodeValue;

            var row;
            var nameCell;

            if (isIE)
            {
                row = autoTable.insertRow(autoTable.rows.length);
                nameCell = row.insertCell(0);
            }
            else
            {
                row = document.createElement("tr");
                nameCell = document.createElement("td");
                row.appendChild(nameCell);
                autoTable.appendChild(row);
            }

            row.className = "popupRow";
            nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;");
            nameCell.setAttribute("onmouseover", "this.style.background='#fff';this.style.padding='3px 5px 4px 6px';");
            nameCell.setAttribute("onmouseout",  "this.style.background='#e0dcc6';this.style.padding='3px 5px 4px 6px';");

            var linkElement = document.createElement("a");
            linkElement.className = "popupItem";
            linkElement.setAttribute("style", "color:#006699;border:none;");
            linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
            linkElement.setAttribute("href", "javascript:void chooseSearchNamedBehav('" + name   + "','" +
                                                                             nbId + "')");
            if (listName)
                linkElement.appendChild(document.createTextNode(listName));
            else
                linkElement.appendChild(document.createTextNode(name));
            nameCell.appendChild(linkElement);
        }

        updateAutoTableFocus(searchNamedBehav);
    }
}

function chooseSearchNamedBehav(name, nbId)
{
    searchNamedBehav.value = name;

    var o = document.getElementById("searchNamedBehavId");
    if (o)
        o.value = nbId;

    clearAutoTable();
    updateAutoTableFocus(searchNamedBehav);
}


// -------------------------------------
// THIS  FILE GENERATED FROM GENAUTO.CSH
// -------------------------------------

/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
   You may not modify, use, reproduce, or distribute this software 
   except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

   Based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/

var searchBehavFunc;

function doSearchBehavFunc(event)
{
    if (event.keyCode == 27 )   // escape
    {
        focus = -1;
        updateAutoTableFocus(searchBehavFunc);
        return;
    }

    if (event.keyCode == 27 ||  // escape
        event.keyCode == 37 ||  // left
        event.keyCode == 38 ||  // up
        event.keyCode == 39 ||  // right
        event.keyCode == 40)    // down
    {
        return;
    }


    searchBehavFunc = document.getElementById("searchBehavFunc");

    moveAutoTable(searchBehavFunc);

    if (searchBehavFunc.value == '') { // clear data
        chooseSearchBehavFunc('', '');
    } else {
        var url = "/ws/bf?name=" + escape(searchBehavFunc.value);
        var ajax = new bfObject(url);
        ajax.send();
    }
}

function bfObject(url) {
    this.url = url;
    var req = init();
    req.onreadystatechange = processRequest;

    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
        {
            isIE = true;
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest ()
    {
        if (req.readyState == 4 && req.status == 200)
            processSearchBehavFunc(req.responseXML);
    }

    this.send = function()
    {
        req.open("GET", url, true);
        req.send(null);
    }
}

function processSearchBehavFunc(responseXML)
{
    clearAutoTable();

    var bfList = responseXML.getElementsByTagName("list")[0];
    if (bfList)
    {
        if (bfList.childNodes.length > 0)
            autoTable.setAttribute("style", "border:1px solid #ccc;padding:2px;background-color:#fff;");
        else
            focus = -1;

        var lastTypeId = 0;

        for (loop = 0; loop < bfList.childNodes.length; loop++)
        {
            var bf = bfList.childNodes[loop];

            var listName = '';
            var name     = '';
            var bfId    = '';

            if (bf.getElementsByTagName("list-name")[0])
                listName = bf.getElementsByTagName("list-name")[0].childNodes[0].nodeValue;
            else if (bf.getElementsByTagName("name")[0])
                listName = bf.getElementsByTagName("name")[0].childNodes[0].nodeValue;

            if (bf.getElementsByTagName("name")[0])
                name = bf.getElementsByTagName("name"         )[0].childNodes[0].nodeValue;

            if (bf.getElementsByTagName("id")[0])
                bfId   = bf.getElementsByTagName("id"        )[0].childNodes[0].nodeValue;

            var row;
            var nameCell;

            if (isIE)
            {
                row = autoTable.insertRow(autoTable.rows.length);
                nameCell = row.insertCell(0);
            }
            else
            {
                row = document.createElement("tr");
                nameCell = document.createElement("td");
                row.appendChild(nameCell);
                autoTable.appendChild(row);
            }

            row.className = "popupRow";
            nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;");
            nameCell.setAttribute("onmouseover", "this.style.background='#fff';this.style.padding='3px 5px 4px 6px';");
            nameCell.setAttribute("onmouseout",  "this.style.background='#e0dcc6';this.style.padding='3px 5px 4px 6px';");

            var linkElement = document.createElement("a");
            linkElement.className = "popupItem";
            linkElement.setAttribute("style", "color:#006699;border:none;");
            linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
            linkElement.setAttribute("href", "javascript:void chooseSearchBehavFunc('" + name   + "','" +
                                                                             bfId + "')");
            if (listName)
                linkElement.appendChild(document.createTextNode(listName));
            else
                linkElement.appendChild(document.createTextNode(name));
            nameCell.appendChild(linkElement);
        }

        updateAutoTableFocus(searchBehavFunc);
    }
}

function chooseSearchBehavFunc(name, bfId)
{
    searchBehavFunc.value = name;

    var o = document.getElementById("searchBehavFuncId");
    if (o)
        o.value = bfId;

    clearAutoTable();
    updateAutoTableFocus(searchBehavFunc);
}


// -------------------------------------
// THIS  FILE GENERATED FROM GENAUTO.CSH
// -------------------------------------

/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
   You may not modify, use, reproduce, or distribute this software 
   except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

   Based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/

var searchTaxon;

function doSearchTaxon(event)
{
    if (event.keyCode == 27 )   // escape
    {
        focus = -1;
        updateAutoTableFocus(searchTaxon);
        return;
    }

    if (event.keyCode == 27 ||  // escape
        event.keyCode == 37 ||  // left
        event.keyCode == 38 ||  // up
        event.keyCode == 39 ||  // right
        event.keyCode == 40)    // down
    {
        return;
    }


    searchTaxon = document.getElementById("searchTaxon");

    moveAutoTable(searchTaxon);

    if (searchTaxon.value == '') { // clear data
        chooseSearchTaxon('', '');
    } else {
        var url = "/ws/t?name=" + escape(searchTaxon.value);
        var ajax = new searchTObject(url);
        ajax.send();
    }
}

function searchTObject(url) {
    this.url = url;
    var req = init();
    req.onreadystatechange = processRequest;

    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
        {
            isIE = true;
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest ()
    {
        if (req.readyState == 4 && req.status == 200)
            processSearchTaxon(req.responseXML);
    }

    this.send = function()
    {
        req.open("GET", url, true);
        req.send(null);
    }
}

function processSearchTaxon(responseXML)
{
    clearAutoTable();

    var tList = responseXML.getElementsByTagName("list")[0];
    if (tList)
    {
        if (tList.childNodes.length > 0)
            autoTable.setAttribute("style", "border:1px solid #ccc;padding:2px;background-color:#fff;");
        else
            focus = -1;

        var lastTypeId = 0;

        for (loop = 0; loop < tList.childNodes.length; loop++)
        {
            var t = tList.childNodes[loop];

            var listName = '';
            var name     = '';
            var tId    = '';

            if (t.getElementsByTagName("list-name")[0])
                listName = t.getElementsByTagName("list-name")[0].childNodes[0].nodeValue;
            else if (t.getElementsByTagName("name")[0])
                listName = t.getElementsByTagName("name")[0].childNodes[0].nodeValue;

            if (t.getElementsByTagName("name")[0])
                name = t.getElementsByTagName("name"         )[0].childNodes[0].nodeValue;

            if (t.getElementsByTagName("id")[0])
                tId   = t.getElementsByTagName("id"        )[0].childNodes[0].nodeValue;

            var row;
            var nameCell;

            if (isIE)
            {
                row = autoTable.insertRow(autoTable.rows.length);
                nameCell = row.insertCell(0);
            }
            else
            {
                row = document.createElement("tr");
                nameCell = document.createElement("td");
                row.appendChild(nameCell);
                autoTable.appendChild(row);
            }

            row.className = "popupRow";
            nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;");
            nameCell.setAttribute("onmouseover", "this.style.background='#fff';this.style.padding='3px 5px 4px 6px';");
            nameCell.setAttribute("onmouseout",  "this.style.background='#e0dcc6';this.style.padding='3px 5px 4px 6px';");

            var linkElement = document.createElement("a");
            linkElement.className = "popupItem";
            linkElement.setAttribute("style", "color:#006699;border:none;");
            linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
            linkElement.setAttribute("href", "javascript:void chooseSearchTaxon('" + name   + "','" +
                                                                             tId + "')");
            if (listName)
                linkElement.appendChild(document.createTextNode(listName));
            else
                linkElement.appendChild(document.createTextNode(name));
            nameCell.appendChild(linkElement);
        }

        updateAutoTableFocus(searchTaxon);
    }
}

function chooseSearchTaxon(name, tId)
{
    searchTaxon.value = name;

    var o = document.getElementById("searchTaxonId");
    if (o)
        o.value = tId;

    clearAutoTable();
    updateAutoTableFocus(searchTaxon);
}


// -------------------------------------
// THIS  FILE GENERATED FROM GENAUTO.CSH
// -------------------------------------

/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. 
   You may not modify, use, reproduce, or distribute this software 
   except in compliance with the terms of the License at: 
       http://developer.sun.com/berkeley_license.html

   Based on:
       http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
*/

var searchTaxonCommon;

function doSearchTaxonCommon(event)
{
    if (event.keyCode == 27 )   // escape
    {
        focus = -1;
        updateAutoTableFocus(searchTaxonCommon);
        return;
    }

    if (event.keyCode == 27 ||  // escape
        event.keyCode == 37 ||  // left
        event.keyCode == 38 ||  // up
        event.keyCode == 39 ||  // right
        event.keyCode == 40)    // down
    {
        return;
    }


    searchTaxonCommon = document.getElementById("searchTaxonCommon");

    moveAutoTable(searchTaxonCommon);

    if (searchTaxonCommon.value == '') { // clear data
        chooseSearchTaxonCommon('', '');
    } else {
        var url = "/ws/tc?name=" + escape(searchTaxonCommon.value);
        var ajax = new searchTcObject(url);
        ajax.send();
    }
}

function searchTcObject(url) {
    this.url = url;
    var req = init();
    req.onreadystatechange = processRequest;

    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
        {
            isIE = true;
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest ()
    {
        if (req.readyState == 4 && req.status == 200)
            processSearchTaxonCommon(req.responseXML);
    }

    this.send = function()
    {
        req.open("GET", url, true);
        req.send(null);
    }
}

function processSearchTaxonCommon(responseXML)
{
    clearAutoTable();

    var tcList = responseXML.getElementsByTagName("list")[0];
    if (tcList)
    {
        if (tcList.childNodes.length > 0)
            autoTable.setAttribute("style", "border:1px solid #ccc;padding:2px;background-color:#fff;");
        else
            focus = -1;

        var lastTypeId = 0;

        for (loop = 0; loop < tcList.childNodes.length; loop++)
        {
            var tc = tcList.childNodes[loop];

            var listName = '';
            var name     = '';
            var tcId    = '';

            if (tc.getElementsByTagName("list-name")[0])
                listName = tc.getElementsByTagName("list-name")[0].childNodes[0].nodeValue;
            else if (tc.getElementsByTagName("name")[0])
                listName = tc.getElementsByTagName("name")[0].childNodes[0].nodeValue;

            if (tc.getElementsByTagName("name")[0])
                name = tc.getElementsByTagName("name"         )[0].childNodes[0].nodeValue;

            if (tc.getElementsByTagName("id")[0])
                tcId   = tc.getElementsByTagName("id"        )[0].childNodes[0].nodeValue;

            var row;
            var nameCell;

            if (isIE)
            {
                row = autoTable.insertRow(autoTable.rows.length);
                nameCell = row.insertCell(0);
            }
            else
            {
                row = document.createElement("tr");
                nameCell = document.createElement("td");
                row.appendChild(nameCell);
                autoTable.appendChild(row);
            }

            row.className = "popupRow";
            nameCell.setAttribute("style", "background-color:#e0dcc6;padding:3px 5px 4px 6px;border:2px solid #fff;");
            nameCell.setAttribute("onmouseover", "this.style.background='#fff';this.style.padding='3px 5px 4px 6px';");
            nameCell.setAttribute("onmouseout",  "this.style.background='#e0dcc6';this.style.padding='3px 5px 4px 6px';");

            var linkElement = document.createElement("a");
            linkElement.className = "popupItem";
            linkElement.setAttribute("style", "color:#006699;border:none;");
            linkElement.setAttribute("onkeydown", "checkAutoTable(event);");
            linkElement.setAttribute("href", "javascript:void chooseSearchTaxonCommon('" + name   + "','" +
                                                                             tcId + "')");
            if (listName)
                linkElement.appendChild(document.createTextNode(listName));
            else
                linkElement.appendChild(document.createTextNode(name));
            nameCell.appendChild(linkElement);
        }

        updateAutoTableFocus(searchTaxonCommon);
    }
}

function chooseSearchTaxonCommon(name, tcId)
{
    searchTaxonCommon.value = name;

    var o = document.getElementById("searchTaxonCommonId");
    if (o)
        o.value = tcId;

    clearAutoTable();
    updateAutoTableFocus(searchTaxonCommon);
}



// .
// autoSearchCustom.js
// This is custom javascript that couldn't be generated from an existing file.
// .


