window.addEventListener("load", function() {
  const elModeSel=document.getElementsByClassName("form-ctl__select")[0];

  function _modeChanged() {
    const elKeyDelegateCnt=document.getElementsByClassName("form-cnt__KEY-DELEGATE-cnt")[0];
    const elKeyCnt=document.getElementsByClassName("form-cnt__KEY-cnt")[0];
    const aelModePtr=document.getElementsByClassName("form-ctl__mode-ptr");

    if ( elModeSel.selectedIndex==0 )
    {
      elKeyDelegateCnt.classList.add("KEY-cnt--hidden");
      aelModePtr[0].classList.remove("mode-ptr--hidden");
      aelModePtr[1].classList.add("mode-ptr--hidden");
    }
    else {
      if ( elModeSel.selectedIndex==1 )
        elKeyCnt.classList.remove("KEY-cnt--hidden");
      else
        elKeyCnt.classList.add("KEY-cnt--hidden");
      elKeyDelegateCnt.classList.remove("KEY-cnt--hidden");
      aelModePtr[0].classList.add("mode-ptr--hidden");
      aelModePtr[1].classList.remove("mode-ptr--hidden");
    }
  }

  elModeSel.addEventListener("change", _modeChanged);
  _modeChanged();


  const aelRB=document.getElementsByClassName("form-ctl__radio-btn");
  const elFile=document.getElementsByClassName("file__input-file")[0];
  const elName=document.getElementsByClassName("file__cnt__name")[0];

  function _genRBSelected() { elFile.value=""; elName.value=""; }
  aelRB[0].addEventListener("click", _genRBSelected);
  aelRB[1].addEventListener("click", _genRBSelected);
  aelRB[2].addEventListener("click", function(){ elFile.click(); });


  elFile.addEventListener("change", function() {
    if ( this.files[0] ) {
      elName.value=this.files[0].name;
      aelRB[2].checked=true;
    }
    else {
      elName.value="";
      aelRB[0].checked=true;
    }
  } );
} );
