Source: tooltipfighters.js

/**
 * Displays the tooltip of the fighter comparision between two years
 * @param e event that triggered the call
 */
function displayToolTipBoxfighters(e) {
    console.log("displayToolTipBox");
    console.log(e);
    var pos = document.getElementById("loadFighters");
    pos.innerHTML = "";

    var tooltip = document.getElementById("tooltip-span");
    tooltip.style.display = "block";
    tooltip.innerHTML = "";

    var fighterTable = document.createElement("table");
    fighterTable.cellSpacing = 0;
    fighterTable.cellPadding = 2;
    tooltip.appendChild(fighterTable);


    var countKaempfer = 17;


    var enTotal1 = 0;
    var esTotal1 = 0;
    var enTotal2 = 0;
    var esTotal2 = 0;
    Object.keys(e).forEach(function (key) {
        var x = e[key];

        var trClubName = document.createElement("tr");
        fighterTable.appendChild(trClubName);
        var tdClubName1 = document.createElement("td");
        trClubName.appendChild(tdClubName1);
        // TODO cal span
        var trHeader1 = document.createElement("tr");
        fighterTable.appendChild(trHeader1);
        var tdKAHeader1 = document.createElement("th");
        trHeader1.appendChild(tdKAHeader1);
        var tdNameHeader1 = document.createElement("th");
        trHeader1.appendChild(tdNameHeader1);
        var tdES1Header1 = document.createElement("th");
        trHeader1.appendChild(tdES1Header1);
        var tdES2Header1 = document.createElement("th");
        trHeader1.appendChild(tdES2Header1);
        var tdEN2Header1 = document.createElement("th");
        trHeader1.appendChild(tdEN2Header1);
        var trHeader2 = document.createElement("tr");
        fighterTable.appendChild(trHeader2);
        var tdKAHeader2 = document.createElement("th");
        trHeader2.appendChild(tdKAHeader2);
        var tdNameHeader2 = document.createElement("th");
        trHeader2.appendChild(tdNameHeader2);
        tdNameHeader2.innerHTML = "Name";
        tdNameHeader2.style.textAlign = "left";
        var tdES1Header2 = document.createElement("th");
        trHeader2.appendChild(tdES1Header2);
        tdES1Header2.innerHTML = "S";
        tdES1Header2.style.textAlign = "center";
        var tdEN1Header2 = document.createElement("th");
        trHeader2.appendChild(tdEN1Header2);
        tdEN1Header2.innerHTML = "N";
        tdEN1Header2.style.borderRight = "solid 1px #000";
        tdEN1Header2.style.textAlign = "center";
        var tdES2Header2 = document.createElement("th");
        trHeader2.appendChild(tdES2Header2);
        tdES2Header2.innerHTML = "S";
        tdES2Header2.style.textAlign = "center";
        var tdEN2Header2 = document.createElement("th");
        trHeader2.appendChild(tdEN2Header2);
        tdEN2Header2.innerHTML = "N";
        tdEN2Header2.style.textAlign = "center";
        var i = 0;
        var year1 = null;
        var year2 = null;
        var club = null;
        Object.keys(x).forEach(function (key2) {
                console.log("i: " + i);
                var fighter = x[key2];

                if (fighter["name1"] == null && fighter["name2"] == null) {
                    return;
                }
                var esValue1 = fighter["ES1"] == null ? 0 : fighter["ES1"];
                var enValue1 = fighter["EN1"] == null ? 0 : fighter["EN1"];
                var esValue2 = fighter["ES2"] == null ? 0 : fighter["ES2"];
                var enValue2 = fighter["EN2"] == null ? 0 : fighter["EN2"];
                enTotal2 += parseInt(enValue2);
                esTotal2 += parseInt(esValue2);
                enTotal1 += parseInt(enValue1);
                esTotal1 += parseInt(esValue1);
                if (countKaempfer > i++) {


                    if (club === null && fighter["name1"] != null && fighter["name2"] != null) {
                        club = fighter["name1"] != null ? fighter["name1"] : fighter["name2"];
                        tdClubName1.colSpan = 6;
                        tdClubName1.innerHTML = '<b>' + club + '</b>';
                        tdClubName1.style.textAlign = "left";
                    }
                    if (year1 === null && fighter["year1"] != null) {
                        year1 = fighter["year1"];
                        tdES1Header1.innerHTML = year1;
                        tdES1Header1.style.textAlign = "center";
                        tdES1Header1.colSpan = 2;
                        tdES1Header1.style.borderRight = "solid 1px #000";

                    }
                    if (year2 === null && fighter["year2"] != null) {
                        year2 = fighter["year2"];
                        tdES2Header1.innerHTML = year2;
                        tdES2Header1.style.textAlign = "center";
                        tdES2Header1.colSpan = 2;
                    }

                    var fighterTr = document.createElement("tr");
                    fighterTable.appendChild(fighterTr);
                    var tdKA = document.createElement("td");
                    fighterTr.appendChild(tdKA);
                    tdKA.innerHTML = '<div class="colorbox ' + (fighter["legionaer"] == 0 ? "S" : "L") + '">&nbsp;</div>';

                    var tdName = document.createElement("td");
                    fighterTr.appendChild(tdName);
                    tdName.innerHTML = fighter["GivennameFirstname1"] == null ? fighter["GivennameFirstname2"] : fighter["GivennameFirstname1"];

                    if(esValue1 == 0 && enValue1 == 0) {
                        var tdNA = document.createElement("td");
                        fighterTr.appendChild(tdNA);
                        tdNA.colSpan = 2;
                        tdNA.innerHTML = "-";
                        tdNA.style.textAlign = "center";
                        tdNA.style.borderRight = "solid 1px #000";

                    } else {
                        var tdES1 = document.createElement("td");
                        fighterTr.appendChild(tdES1);
                        tdES1.innerHTML = esValue1;
                        tdES1.style.textAlign = "center";

                        var tdEN1 = document.createElement("td");
                        fighterTr.appendChild(tdEN1);
                        tdEN1.innerHTML = enValue1;
                        tdEN1.style.textAlign = "center";
                        tdEN1.style.borderRight = "solid 1px #000";
                    }

                    if(esValue2 == 0 && enValue2 == 0) {
                        var tdNA = document.createElement("td");
                        fighterTr.appendChild(tdNA);
                        tdNA.colSpan = 2;
                        tdNA.innerHTML = "-";
                        tdNA.style.textAlign = "center";

                    } else {
                        var tdES2 = document.createElement("td");
                        fighterTr.appendChild(tdES2);
                        tdES2.innerHTML = esValue2;
                        tdES2.style.textAlign = "center";

                        var tdEN2 = document.createElement("td");
                        fighterTr.appendChild(tdEN2);
                        tdEN2.innerHTML = enValue2;
                        tdEN2.style.textAlign = "center";
                    }

                    /*
                    var tdMaxS = document.createElement("td");
                    fighterTr.appendChild(tdMaxS);
                    tdMaxS.innerHTML = fighter["MaxSiege"] == null ? 0 : fighter["MaxSiege"];
                    tdMaxS.style.textAlign = "center";
                    var tdMaxN = document.createElement("td");
                    fighterTr.appendChild(tdMaxN);
                    tdMaxN.innerHTML = fighter["MaxDefeat"] == null ? 0 : fighter["MaxDefeat"];
                    tdMaxN.style.textAlign = "center"; // */
                }
                if (countKaempfer == i) {
                    var fighterTr = document.createElement("tr");
                    fighterTable.appendChild(fighterTr);

                    var tdKA = document.createElement("td");
                    fighterTr.appendChild(tdKA);
                    tdKA.style.textAlign = "center";
                    tdKA.innerHTML = '...';

                    var tdName = document.createElement("td");
                    fighterTr.appendChild(tdName);
                    tdName.style.textAlign = "center";
                    tdName.innerHTML = '...';

                    var tdES1 = document.createElement("td");
                    fighterTr.appendChild(tdES1);
                    tdES1.innerHTML = '...';
                    tdES1.style.textAlign = "center";

                    var tdEN1 = document.createElement("td");
                    fighterTr.appendChild(tdEN1);
                    tdEN1.innerHTML = '...';
                    tdEN1.style.textAlign = "center";
                    tdEN1.style.borderRight = "solid 1px #000";

                    var tdES2 = document.createElement("td");
                    fighterTr.appendChild(tdES2);
                    tdES2.innerHTML = '...';
                    tdES2.style.textAlign = "center";

                    var tdEN2 = document.createElement("td");
                    fighterTr.appendChild(tdEN2);
                    tdEN2.innerHTML = '...';
                    tdEN2.style.textAlign = "center";
                }
            }
        );

    });
    console.log("totals")
    console.log(esTotal1);
    console.log(enTotal1);
    console.log(esTotal2);
    console.log(enTotal2);

    //-------------------------------------Gesamt-----------------------------------
    var tr6 = document.createElement("tr");
    fighterTable.appendChild(tr6);
    var color6 = document.createElement("td");
    tr6.appendChild(color6);
    var c6div = document.createElement("div");
    c6div.className = "colorbox";
    c6div.innerHTML = "&nbsp;";
    color6.appendChild(c6div);
    var tb6 = document.createElement("td");
    tr6.appendChild(tb6);
    tb6.innerHTML = "Gesamt";
    var tb6Siege = document.createElement("td");
    tb6Siege.style.textAlign = "center";
    tr6.appendChild(tb6Siege);
    tb6Siege.innerHTML = esTotal1;
    var tb6Niederlage = document.createElement("td");
    tb6Niederlage.style.textAlign = "center";
    tr6.appendChild(tb6Niederlage);
    tb6Niederlage.innerHTML = enTotal1;
    var tb60Siege = document.createElement("td");
    tb6Siege.style.textAlign = "center";
    tr6.appendChild(tb60Siege);
    tb60Siege.innerHTML = esTotal2;
    var tb60Niederlage = document.createElement("td");
    tb60Niederlage.style.textAlign = "center";
    tr6.appendChild(tb60Niederlage);
    tb60Niederlage.innerHTML = enTotal2;

    color6.style.borderTop = "1px solid black";
    tb6.style.borderTop = "1px solid black";
    tb6Siege.style.borderTop = "1px solid black";
    tb6Niederlage.style.borderTop = "1px solid black";
    tb60Siege.style.borderTop = "1px solid black";
    tb60Niederlage.style.borderTop = "1px solid black";

    $('.L').css('background-image', 'url(logos/JudogiRot.png)');
    $('.S').css('background-image', 'url(logos/JudogiBlau.png)');
}

// hides tool tip box
/**
 * Hides the fighter tooltip box
 */
function hideToolTipBoxfighters() {
    var tooltip = document.getElementById("tooltip-span");
    tooltip.style.display = "none";
}