
function abbrDetails(e, abbr, name, name_en, www)
{
    if (!document.getElementsByTagName) {
        return;
    }

    // remove previous details boxes
    var testClass = new RegExp("(^|\\s)keyword_details(\\s|$)");
    var elements = document.getElementsByTagName('span');
    for (var i=0; i<elements.length; i++) {
        if (testClass.test(elements[i].className)) {
            elements[i].parentNode.style.position = 'static';
            elements[i].parentNode.removeChild(elements[i]);
        }
    }
    e.parentNode.style.position = 'relative';

    var details = document.createElement('span');
    details.className = 'keyword_details';
    details.setAttribute('class', 'keyword_details');
    details.onclick = function () { this.parentNode.style.position = 'static'; this.parentNode.removeChild(this); };

    // recreate the abbreviation
    var details_abbr = document.createElement('abbr');
    details_abbr.title = name;
    details_abbr.setAttribute('title', name);
    details_abbr.className = 'bold';
    details_abbr.setAttribute('class', 'bold');
    details_abbr.appendChild(document.createTextNode(abbr.replace('<sub>2</sub>', '2').replace('<sub>x</sub>', 'x')));
    details.appendChild(details_abbr);
    details.appendChild(document.createTextNode(': '));

    // create the name of organisation
    var details_name = document.createElement('span');
    details_name.className = 'bold';
    details_name.setAttribute('class', 'bold');
    details_name.appendChild(document.createTextNode(name));
    details.appendChild(details_name);

    // create the english name of the organisation
    if (name_en.length>0 && name_en != name) {
        var br2 = document.createElement('br');
        details.appendChild(br2);
        var details_name_en = document.createElement('span');
        details_name_en.className = 'italic';
        details_name_en.setAttribute('class', 'italic');
        details_name_en.appendChild(document.createTextNode(name_en));
        details.appendChild(details_name_en);
    }

    // create the URL link
    if (www.length>0) {
        var br3 = document.createElement('br');
        details.appendChild(br3);
        var details_a = document.createElement('a');
        details_a.className = 'url bold';
        details_a.setAttribute('class', 'url bold');
        details_a.setAttribute('href', www);
        //details_a.setAttribute('rel', 'external');
        details_a.target = '_blank';
        details_a.appendChild(document.createTextNode(www));
        details.appendChild(details_a);
    }

    e.parentNode.insertBefore(details, e);
}

function clickFree(e)
{
    var tmp = e;
    while (tmp) {
        if (tmp.onclick || ( tmp.getAttribute && tmp.getAttribute('href'))) {
            return false;
        }
        tmp = tmp.parentNode;
    }
    return true;
}

function externalLinks()
{
    if (!document.getElementsByTagName) {
        return;
    }
    var anchors = document.getElementsByTagName('a');
    for (var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];
        if (anchor.getAttribute && anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external') {
            anchor.target = '_blank';
        }
    }
}

function abbr_plain_txt(an)
{
    var abbr_txt = an.firstChild.nodeValue;
    if (an.firstChild != an.lastChild) {
        for (var j=1; j<an.childNodes.length; j++) {
            if (an.childNodes[j].childNodes) {
                abbr_txt += an.childNodes[j].firstChild.nodeValue;
            } else {
                abbr_txt += an.childNodes[j].nodeValue;
            }
        }
    }
    return abbr_txt;
}

function abbrClicks()
{
    if (!document.getElementsByTagName) {
        return;
    }
    var abbrs = document.getElementsByTagName('abbr');
    for (var i=0; i<abbrs.length; i++) {
        if (abbrs[i].firstChild.nodeValue != 'FEAST' && clickFree(abbrs[i])) {
            var details_parent = document.createElement('span');
            details_parent.className = 'keyword_parent';
            abbrs[i].parentNode.insertBefore(details_parent, abbrs[i]);
            var abbr = abbrs[i].cloneNode(true);
            abbrs[i].parentNode.removeChild(abbrs[i]);
            details_parent.appendChild(abbr);
            abbr.style.cursor = 'pointer';
            abbr.onclick = function() { abbrDetails(this, abbr_plain_txt(this), this.getAttribute('title'), '', ''); };
        }
    }

}
function extraMarkUp()
{
    externalLinks();
    abbrClicks();
}

document.onload = extraMarkUp();

