'
+ ''
+ '
';
}
// Called after GF renders to pre-fill the model and haul fields
window.atPrefillGF = function() {
var p = window._atPrefill;
if (!p) return;
// input_10 = Select Your Model, input_12 = What will you be hauling
var modelField = document.querySelector('#input_1_10');
var haulField = document.querySelector('#input_1_12');
if (modelField) {
// Try to select matching option; fall back to first option
var modelOpts = modelField.querySelectorAll('option');
var matched = false;
for (var i = 0; i < modelOpts.length; i++) {
if (modelOpts[i].value === p.model) { modelOpts[i].selected = true; matched = true; break; }
}
if (!matched && modelOpts.length > 1) modelOpts[1].selected = true;
}
if (haulField) {
var haulOpts = haulField.querySelectorAll('option');
for (var j = 0; j < haulOpts.length; j++) {
if (haulOpts[j].value === p.haul || haulOpts[j].text === p.haul) { haulOpts[j].selected = true; break; }
}
}
};
function render() {
var el = document.getElementById('airtow-cfg');
if (view === 'quiz') el.innerHTML = renderQuiz();
if (view === 'result') el.innerHTML = renderResult();
if (view === 'quote') el.innerHTML = renderQuote();
}
/* ── Encode rec for inline onclick (avoids quote conflicts) ── */
function encodeRec(r) {
return "'" + btoa(unescape(encodeURIComponent(JSON.stringify(r)))) + "'";
}
/* ── Global handlers (called from inline onclick) ── */
function shouldShowStep(i) {
var id = STEPS[i].id;
// Dock: skip if weight is max OR use routes to a fixed trailer
if (id === 'dock') {
if (answers.weight === 'max') return false;
if (answers.use === 'safes' || answers.use === 'debris' || answers.use === 'refrigerated') return false;
}
// Protection: skip for debris (no enclosed dump trailers) and refrigerated
if (id === 'protection') {
if (answers.use === 'debris' || answers.use === 'refrigerated') return false;
}
// Hitch: skip for debris and refrigerated (fixed routes) and enclosed (no gooseneck option)
if (id === 'hitch') {
if (answers.use === 'debris' || answers.use === 'refrigerated') return false;
if (answers.protection === 'enclosed') return false;
}
return true;
}
function nextStep(from) {
for (var i = from + 1; i < STEPS.length; i++) { if (shouldShowStep(i)) return i; }
return STEPS.length;
}
function prevStep(from) {
for (var i = from - 1; i >= 0; i--) { if (shouldShowStep(i)) return i; }
return 0;
}
window.atPick = function(id, val) {
answers[id] = val;
// If a change makes the dock step irrelevant, clear any stale dock answer
if (!shouldShowStep(STEPS.findIndex(function(s){ return s.id === 'dock'; }))) {
answers.dock = 'ground';
}
render();
};
window.atNext = function() {
if (!answers[STEPS[step].id]) return;
var n = nextStep(step);
if (n >= STEPS.length) { view = 'result'; } else { step = n; }
render();
};
window.atBack = function() { if (step > 0) step = prevStep(step); render(); };
window.atStartQuote = function(encoded) {
selectedRec = JSON.parse(decodeURIComponent(escape(atob(encoded))));
view = 'quote'; render();
// Wait for Gravity Forms to finish rendering, then pre-fill
setTimeout(window.atPrefillGF, 800);
};
window.atBackToResult = function() { view = 'result'; render(); };
window.atRestart = function() { answers = {}; step = 0; view = 'quiz'; selectedRec = null; render(); };
/* ── Boot ── */
render();
})();