function toggleFade(id) {
  const el = document.getElementById(id);
  if (!el) return;
  el.classList.toggle("show");
}

    (function() {
        var dateField = document.getElementById('jobDate');
        dateField.addEventListener('change', function() {
            var parts = this.value.split('-');
            if (parts.length !== 3) return;
            document.getElementById('pyear').value = parseInt(parts[0], 10);
            document.getElementById('pmonth').value = parseInt(parts[1], 10);
            document.getElementById('pday').value = parseInt(parts[2], 10);
        });
    })();

(function() {
    // "# Day Job" (and Paint Colors) only makes sense once this is an
    // actual scheduled Job, for a Quote (or Estimate/Bid) it has no
    // meaningful value yet, so hide it rather than clutter the form.
    // Active as soon as "Job" is picked, whether that's a brand new
    // record or editing an existing one.
    function updateJobOnlyFieldsVisibility() {
        var statusField = document.getElementById('recordStatus');
        var isJob = statusField && statusField.value === 'job';
        ['job-only-reqdays', 'job-only-paintcolors'].forEach(function(id) {
            var el = document.getElementById(id);
            if (el) el.style.display = isJob ? '' : 'none';
        });
    }

    updateJobOnlyFieldsVisibility(); // both #recordStatus and these fields already exist in the DOM at this point
    document.addEventListener('DOMContentLoaded', updateJobOnlyFieldsVisibility);
    document.addEventListener('change', function(e) {
        if (e.target.id === 'recordStatus') updateJobOnlyFieldsVisibility();
    });
})();
