/* clang-format off */

//<script>
//  function g(i) { return document.getElementById(i) };
//  function sp(i){g(i).type=(g(i).type==='text'?'password':'text');}
//  var xhttp, reqTime, reqFin;
//  function setCbx(el, da) {
//    if(da == '1') {
//      el.checked = true;
//      el.style.visibility = 'visible';
//    }
//    else {
//      el.checked = false;
//      el.style.visibility = 'visible';
//    }
//  }
//  function updCbxVal(el) {
//    if (el.checked) el.value = '1';
//    else {
//      el.checked = true;
//    el.value = '0';
//      el.style.visibility = 'hidden';
//    }
//  }

static const char html_conftime_script[] PROGMEM = R"=====(
  function transmit(f) {
    if (!xhttp) {   
    reqTime = 0;
    reqFin = false;
    updCbxVal(g('NTPEnable'));
    xhttp = new XMLHttpRequest();
    xhttp.timeout = 1000;
    xhttp.overrideMimeType('application/json');
    xhttp.open('POST', 'confDataTime');
    xhttp.send(f ? (new FormData(f)) : '');
    xhttp.onreadystatechange = function () {
      if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) {
        var data = JSON.parse(xhttp.responseText);
        setCbx(g('NTPEnable'), data.NTPEnable);
        g('NTPServer1').value = data.NTPServer1;
        g('NTPServer2').value = data.NTPServer2;
        g('TZStr').value = data.TZStr;
        g('NTPSyncInt').value = data.NTPSyncInt;
        xhttp = null;
        reqFin = true;
       }
       else {
         if(!reqFin && reqTime > 10) {
           xhttp = null;
           reqFin = true;
         }
       }
     }
   }
    return false;
  }
  //transmit();
  function saveConf() {
    updCbxVal(g('NTPEnable'));
    g('frmConf').submit();
  }
  function init() {
    transmit();
  }
)====="; // html_conftime_script
//  setInterval(function () { ++reqTime; }, 1000);
//</script>

static const char html_conftime_body[] PROGMEM = R"=====(
<b>Configuration - Date &amp; Time</b>
<div class='config'>
<form id='frmConf' action='setConfTime' method='POST'>
<br>
<fieldset>
<legend>NTP-Server</legend>
<p><b>Enable NTP Time Sync</b>&nbsp;<input type='checkbox' name='NTPEnable' id='NTPEnable'></p>
<p><b>NTP Server 1</b><br><input type='text' name='NTPServer1' id='NTPServer1'></p>
<p><b>NTP Server 2</b><br><input type='text' name='NTPServer2' id='NTPServer2'></p>
<p><b>Timezone String</b><br><input type='text' name='TZStr' id='TZStr'></p>
<p class='n'>a valid TZ string (right column) from here: <br><a target='_blank' href='https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv'>zones.csv</a></p>
<p><b>NTP Sync Interval [m]</b><br><input type='text' name='NTPSyncInt' id='NTPSyncInt'></p>
</fieldset>
<div></div><br>
</form>
<div></div>
<table style='width:100%'>
<td style='width:50%'><button onclick='location="conf";' class='bgrey'>Cancel</button></td>
<td style='width:50%'><button onclick='return saveConf()' class='bred'>Save</button></td>
</tr></table>
</div>
)====="; // html_conftime_body

