var vortaroformularo;
var vortaroteksto;
var centra;
var menuo;

var StartoFunkcioj = new Array();
UziStartoFunkciojn();
AldoniStartoFunkcion('preparu()');

function preparu() {
    vortaroformularo = document.getElementById('vortaroformularo');
    vortaroteksto = document.getElementById('vortaroteksto');
    centra = document.getElementById('centra');
    menuo = document.getElementById('menuo');
    prilaboriMenuon();
    InstaliSuperBiblon(centra);
}

prilaboriMenuon = function() {
    if (document.all) {
        var lioj = menuo.getElementsByTagName('li');
        for (var x = 0; x < lioj.length; x++) {
            lioj[x].onmouseover = function() {
                this.className = "musumo";
            }
            lioj[x].onmouseout = function() {
                this.className = "";
            }
        }
    }
}

function ProtektuRetadreson(komenco, fino, teksto) {
    document.write( '<a href="mailto:' + komenco + '@' + fino + '">' );
    if (teksto == "") {
        document.write( ''+ komenco + '@' + fino + '' );
    } else if (teksto == "xx") {
        document.write( '<img class="ridulo" src="/img/aspekto/retadreso.gif" alt="" />' );
    } else {
        document.write( ''+ teksto.replace('(x)', '<img class="ridulo" src="/img/aspekto/at.gif" alt="" />') +'' );
    }
    document.write( '</a>' );
}

function riceviFlashSonludigilon(flashnomo) {
    if (window.document[flashnomo]) {
        return window.document[flashnomo];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[flashnomo]) return document.embeds[flashnomo];
    } else {
        return document.getElementById(flashnomo);
    }
}

function sendiAlFlash(sono) {
    flashsonludigilo = riceviFlashSonludigilon('sonigilo');
    flashsonludigilo.StopPlay();
    flashsonludigilo.SetVariable("/:ligo", sono);
    flashsonludigilo.Play();
}

function MontriKashiVortaron() {
    if (vortaroformularo) {
        if (!vortaroformularo.style.display || vortaroformularo.style.display == 'none') {
            vortaroteksto.style.display = 'none';
            vortaroformularo.style.display = 'block';
        } else {
            vortaroteksto.style.display = 'block';
            vortaroformularo.style.display = 'none';
        }
    }
}

/* Mastrumado de pluraj startofunkcioj */
function PlenumiStartoFunkciojn() {
    for (var x = 0; x < StartoFunkcioj.length; x++) {
        eval(StartoFunkcioj[x]);
    }
}

function UziStartoFunkciojn() {
    window.onload = PlenumiStartoFunkciojn;
}

function AldoniStartoFunkcion(f) {
    StartoFunkcioj[StartoFunkcioj.length] = f;
}

var TitolSercho = new RegExp("^<h2>(.*?)</h2>");
function InstaliSuperBiblon(kie) {
    var superbibloj = troviKlase("SuperBibl",kie);
    for (var x = 0; x < superbibloj.length; x++) {
        superbibloj[x].enhavo = superbibloj[x].title;
        var titolo = superbibloj[x].enhavo.match(TitolSercho);
        if (titolo != null && titolo[1]) {
            superbibloj[x].titolo = titolo[1];
            superbibloj[x].enhavo = superbibloj[x].enhavo.replace(TitolSercho,'');
        }
        superbibloj[x].title = '';
        superbibloj[x].onmouseover = SuperEk;
        superbibloj[x].onmouseout = SuperFor;
    }
}

function troviKlase(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}

function klavopremo(textarea,maks) {
    if(textarea.value.length > maks)
        textarea.value = textarea.value.substring(0,maks);
}

function simbolkalkulo(textarea, textfield, maks) {
    n = maks - textarea.value.length;
    textfield.value = "" + n;
}
