document.addEventListener("DOMContentLoaded", function () {
    var inputs = Array.from(document.getElementsByTagName("input"));
    for (i in inputs) {
        inputs[i].addEventListener("change", function () {
            var counter = 0
            for (var i = 0; i < 3; i++) {
                counter += Number(inputs[i].value);
            }
            document.getElementById("rowsum-1").innerText = counter;

            counter = 0;
            for (var i = 0; i < 3; i++) {
                counter += Number(inputs[i + 3].value);
            }
            document.getElementById("rowsum-2").innerText = counter;

            var ids = ["websum", "progsum", "adatbsum"];
            for (var j = 0; j < 3; j++) {
                counter = 0;
                for (var i = 0; i < 6; i += 3) {
                    counter += Number(inputs[i + j].value);
                }
                document.getElementById(ids[j]).innerText = counter;
            }

            var prof1 = document.getElementById("rowsum-1").innerText
            var prof2 = document.getElementById("rowsum-2").innerText
            if (Number(prof1) >= 2 * Number(prof2)) {
                document.getElementById("prof1").style.color = "red";
                document.getElementById("prof2").style.color = "black";
            } else if (Number(prof2) >= 2 * Number(prof1)) {
                document.getElementById("prof2").style.color = "red";
                document.getElementById("prof1").style.color = "black";
            } else {
                document.getElementById("prof2").style.color = "black";
                document.getElementById("prof1").style.color = "black";
            }
        });
    }
})