if (document.readyState === 'complete') {
  init();
} else {
  document.addEventListener('DOMContentLoaded', function() {
    init();
  });
}

function init() {
  enableNewsletterFC();
  document.getElementById('status').onchange = enableNewsletterFC;
}

function enableNewsletterFC(){
  let newsletterStatusFC = document.querySelector('input[name = "newsletterfc_status"]');
  let newsletterName = document.querySelector('input[name = "newsletter_name"]');

  if (document.getElementById('status').value == 1) {
    newsletterStatusFC.disabled = false;
    newsletterName.disabled = false;
    document.getElementById('newsletterfc_label').classList.remove('checkbox-disabled');
    document.getElementById('newsletter_name_label').classList.remove('checkbox-disabled');
  } else {
    newsletterStatusFC.removeAttribute('checked');
    newsletterName.removeAttribute('checked');
    newsletterStatusFC.checked = false;
    newsletterName.checked = false;
    newsletterStatusFC.disabled = true;
    newsletterName.disabled = true;
    document.getElementById('newsletterfc_label').classList.add('checkbox-disabled');
    document.getElementById('newsletter_name_label').classList.add('checkbox-disabled');
  }
}