/* Small static helpers for the quote/estimate builder form
 * (includes/estimates.php, ?csaction=create). Merged from the form's
 * several short inline script blocks, in original page order. All are
 * plain global function declarations referenced by onclick/onsubmit
 * attributes, so running from the footer is safe. */

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

function toggleSection(id) {
    const el = document.getElementById(id);

    if (el.style.display === 'none') {
        el.style.display = 'block';
    } else {
        el.style.display = 'none';
    }
}

function fillTextareaFromSelect() {
  const select = document.getElementById("mySelect");
  const textarea = document.getElementById("estDetails");

  // put the selected value into textarea
  textarea.value = select.value;
}

function formatText(command, value = null) {
  document.execCommand(command, false, value);
  document.getElementById('quoteEditor').focus();
}

function syncEditor() {
  document.getElementById('estDetails').value =
	document.getElementById('quoteEditor').innerHTML;
}

function paintopsRevealNextSupplyRow() {
	for (var n = 6; n <= 20; n++) {
		var row = document.getElementById('supplyRow' + n);
		if (row && row.style.display === 'none') {
			row.style.display = '';
			var d = document.getElementById('supplyDesc' + n);
			if (d) d.focus();
			return;
		}
	}
	window.alert('Maximum of 20 line items reached.');
}
