document.getElementById("text_bpm").style.display = "none";
document.getElementById("text_oxy").style.display = "none";
document.getElementById("text_town").style.display = "none";
document.getElementById("state_bpm_0").style.display = "none";
document.getElementById("state_bpm_1").style.display = "none";
document.getElementById("state_bpm_2").style.display = "none";
document.getElementById("state_bpm_3").style.display = "none";
document.getElementById("state_oxy_0").style.display = "none";
document.getElementById("state_oxy_1").style.display = "none";
document.getElementById("state_oxy_2").style.display = "none";
document.getElementById("state_oxy_3").style.display = "none";
document.getElementById("state_chute_0").style.display = "none";
document.getElementById("state_chute_1").style.display = "none";
document.getElementById("state_chute_2").style.display = "none";
setInterval('load_alarms()', 2000);
function load_alarms(){
  var xhr = new XMLHttpRequest();
    xhr.onload = function () {
        // Process our return data
        if (xhr.status >= 200 && xhr.status < 300) {
            // Runs when the request is successful
            console.log(JSON.stringify(xhr.responseText));
            data = JSON.parse(xhr.responseText);
            document.getElementById("value_bpm").innerHTML = data.bpm;
            document.getElementById("value_oxy").innerHTML = data.oxy;
            var state_bpm = data.state_bpm
            var state_oxy = data.state_oxy
            var state_chute = data.state_chute
            var xCritiqueBPM = document.getElementById("state_bpm_0");
            var xStableBPM = document.getElementById("state_bpm_1");
            var xSurveilleBPM = document.getElementById("state_bpm_2");
            var xNodataBPM = document.getElementById("state_bpm_3");
            var xCritiqueOxy = document.getElementById("state_oxy_0");
            var xStableOxy = document.getElementById("state_oxy_1");
            var xSurveilleOxy = document.getElementById("state_oxy_2");
            var xNodataOxy = document.getElementById("state_oxy_3");
            var xRASChute = document.getElementById("state_chute_0");
            var xDownChute = document.getElementById("state_chute_1");
            var xNodataChute = document.getElementById("state_chute_2");
            document.getElementById("text_bpm").style.display = "block";
            document.getElementById("text_oxy").style.display = "block";
            document.getElementById("text_town").style.display = "block";
            if (state_bpm == "0") {
              xCritiqueBPM.style.display = "block";
              xStableBPM.style.display = "none";
              xSurveilleBPM.style.display = "none";
              xNodataBPM.style.display = "none";
            }
            if (state_bpm == "1") {
              xCritiqueBPM.style.display = "none";
              xStableBPM.style.display = "block";
              xSurveilleBPM.style.display = "none";
              xNodataBPM.style.display = "none";
            }
            if (state_bpm == "2") {
              xCritiqueBPM.style.display = "none";
              xStableBPM.style.display = "none";
              xSurveilleBPM.style.display = "block";
              xNodataBPM.style.display = "none";
            }
            if (state_bpm == "3") {
              xCritiqueBPM.style.display = "none";
              xStableBPM.style.display = "none";
              xSurveilleBPM.style.display = "none";
              xNodataBPM.style.display = "block";
            }
            if (state_oxy == "0") {
              xCritiqueOxy.style.display = "block";
              xStableOxy.style.display = "none";
              xSurveilleOxy.style.display = "none";
              xNodataOxy.style.display = "none";
            }
            if (state_oxy == "1") {
              xCritiqueOxy.style.display = "none";
              xStableOxy.style.display = "block";
              xSurveilleOxy.style.display = "none";
              xNodataOxy.style.display = "none";
            }
            if (state_oxy == "2") {
              xCritiqueOxy.style.display = "none";
              xStableOxy.style.display = "none";
              xSurveilleOxy.style.display = "block";
              xNodataOxy.style.display = "none";
            }
            if (state_oxy == "3") {
              xCritiqueOxy.style.display = "none";
              xStableOxy.style.display = "none";
              xSurveilleOxy.style.display = "none";
              xNodataOxy.style.display = "block";
            }
            if (state_chute == "0") {
              xRASChute.style.display = "block";
              xDownChute.style.display = "none";
              xNodataChute.style.display = "none";
            }
            if (state_chute == "1") {
              xRASChute.style.display = "none";
              xDownChute.style.display = "block";
              xNodataChute.style.display = "none";
            }
            if (state_chute == "2") {
              xRASChute.style.display = "none";
              xDownChute.style.display = "none";
              xNodataChute.style.display = "block";
            }
        } else {
            // Runs when it's not
            console.log(JSON.stringify(xhr.responseText));
        }
    };
    xhr.open('GET', '/data-health');
    xhr.send();
}