/* ============================================================
ConcreteQuantity: single-page patch for 5 missing tools
------------------------------------------------------------
WHY THIS FILE EXISTS
The shared V6 script only builds 12 tools. The batch 2 (P3)
script does contain builders for patio, sidewalk, sonotube,
countertop and sealer, but on these 5 standalone pages no
calculator form renders at all (verified live 26 Oct 2026).
This patch is self contained: it builds the form itself when
#ccSingle is empty and window.CC_SINGLE is one of the 5 tools.
It does not modify V6, P3 or P4, and it never builds a second
panel if one already exists.
DEPLOY CONSTRAINT (read before deploying):
Do NOT also add the batch2-tools.js script tag to these 5
pages while this patch is present, or two calculator panels
will render. This patch replaces P3 on these pages.
MARKUP CONVENTIONS (same classes V6 uses, so the existing
V6 stylesheet styles this patch with no new CSS):
.cc-panel, .cc-phead, .cc-formula, .cc-grid, .cc-field,
.cc-unitrow, .cc-funit, .cc-quickbtns, .cc-out, .cc-results,
.cc-netwaste, .cc-nwcol, .cc-sub, .cc-working, .cc-note,
.cc-actions, .cc-reset, .cc-error, .cc-empty, .wasteSel,
.wasteCustom, .curSym
CONSTANTS (site standards, same as V6 and P3):
27 ft3 per yd3; 80 lb bag = 0.60 ft3; 60 lb = 0.45 ft3;
40 lb = 0.30 ft3; 50 lb = 0.375 ft3 (V6/P3); 25 kg = 0.0117 m3;
20 kg = 0.0094 m3; density 150 lb/ft3 (2400 kg/m3);
1 gallon = 3.78541 litres; countertop mix 0.43 ft3 per 47 lb bag.
============================================================ */
(function(){
"use strict";
/* ---------- shared helpers (mirrors V6) ---------- */
function num(v){ v = parseFloat(v); return (isFinite(v) && v > 0) ? v : 0; }
function ceilSafe(x){ return Math.ceil(x - 1e-9) || 0; }
function fmt(v, d){
if(!isFinite(v)) return '0';
var s = v.toFixed(d === undefined ? 2 : d);
if(s.indexOf('.') >= 0) s = s.replace(/\.?0+$/, '');
return s;
}
function esc(s){
return String(s).replace(/&/g,'&').replace(//g,'>').replace(/"/g,'"');
}
var TO_FT = { ft:1, 'in':1/12, m:3.28084, cm:0.0328084, mm:0.00328084 };
var TO_IN = { 'in':1, ft:12, m:39.3701, cm:0.393701, mm:0.0393701 };
function toFt(v, u){ v = parseFloat(v); if(!isFinite(v)) return 0; return v * (TO_FT[u] || 1); }
function toIn(v, u){ v = parseFloat(v); if(!isFinite(v)) return 0; return v * (TO_IN[u] || 1); }
function convertVal(v, fromU, toU, kind){
v = parseFloat(v); if(!isFinite(v)) return '';
var base = (kind === 'len') ? TO_FT : TO_IN;
var out = v * (base[fromU] || 1) / (base[toU] || 1);
return String(Math.round(out * 10000) / 10000);
}
var BAG = { b80:0.60, b60:0.45, b50:0.375, b40:0.30 };
var BAGKG = { k25:0.0117, k20:0.0094 };
function bagsNeeded(ft3){
ft3 = num(ft3);
return { b80:ceilSafe(ft3/BAG.b80), b60:ceilSafe(ft3/BAG.b60),
b50:ceilSafe(ft3/BAG.b50), b40:ceilSafe(ft3/BAG.b40) };
}
function bagsNeededM3(m3){
m3 = num(m3);
return { k25:ceilSafe(m3/BAGKG.k25), k20:ceilSafe(m3/BAGKG.k20) };
}
function weightLb(ft3){ return num(ft3) * 150; }
function weightKg(m3){ return num(m3) * 2400; }
function trucks(yd3){ return ceilSafe(num(yd3) / 10); }
/* ---------- field markup (mirrors V6 fieldHTML) ---------- */
function unitSelectHTML(fieldId, kind, defUnit){
var list = (kind === 'len' || kind === 'sm') ? ['ft','in','m','cm','mm']
: (kind === 'yd3' ? ['yd3','m3','ft3'] : []);
if(!list.length) return '';
var opts = '';
list.forEach(function(u){
opts += '';
});
return '';
}
function fieldHTML(f){
var isDim = (f.kind === 'len' || f.kind === 'sm' || f.kind === 'yd3');
var sel = isDim ? unitSelectHTML(f.id, f.kind, f.defUnit || 'ft') : '';
var suffix = (f.kind === 'usd') ? '$' : '';
var quick = '';
if(f.quick && f.quick.length){
quick = '
' + R.jointCount + ' control joint line' + (R.jointCount === 1 ? '' : 's') + ' (at ' + fmt(R.jointSpacing, 1) + ' ft spacing)' +
'' + fmt(R.jointsFt, 1) + ' ft of joints' +
'' + fmt(2 * tIn, 0) + ' to ' + fmt(3 * tIn, 0) + ' ft joint spacing rule (2 to 3x thickness)' +
'' + fmt(R.dropIn, 2) + ' in drainage fall over the length
';
if(R.cost > 0) h += '
' + CUR + fmt(R.cost) + ' estimated material cost
';
h += '
Estimates only. Bag yields per manufacturer specs (80 lb = 0.60 ft3, 60 lb = 0.45 ft3, 40 lb = 0.30 ft3). Cut control joints at least one quarter of the slab thickness deep, and keep panels close to square (no side more than 1.5 times the other). Always confirm the final order with your supplier.
';
h += resetHTML() + '
';
return h;
},
links: ['slab','sidewalk','driveway','cost','sonotube','sealer'],
verified: 'Patio thickness 4 in typical (minimum 3 to 3.5 in; 3,000 to 4,000 PSI mix). Control joint spacing in feet 2 to 3 times slab thickness in inches, depth at least one quarter of slab thickness. Drainage slope 1/8 to 1/4 in per ft (2% maximum). Bag yields per manufacturer specifications (Quikrete). Density 150 lb/ft3 (2,400 kg/m3).'
},
sidewalk: {
title: 'Sidewalk and Walkway Concrete Calculator',
formula: 'Volume = Length x Width x Thickness / 27 (cubic yards)',
fields: [
{ id:'l', label:'Length', kind:'len', ph:'50', defUnit:'ft' },
{ id:'w', label:'Width', kind:'len', ph:'4', defUnit:'ft' },
{ id:'t', label:'Thickness', kind:'sm', ph:'4', defUnit:'in', quick:[3,4,5] }
],
extrasHTML: function(){
return '
' +
'
' +
wasteRowHTML(10) + priceFieldHTML('price', 'Price per yd3', '150');
},
extraFields: [ { id:'price', label:'Price per yd3', kind:'usd' } ],
empty: 'Enter the walkway size above.',
validate: function(panel, vals){
if(!vals.l || !vals.w || !vals.t) return this.empty;
return null;
},
toImp: function(vals, units){
return { l:toFt(vals.l, units.l), w:toFt(vals.w, units.w), t:toIn(vals.t, units.t), price:num(vals.price) };
},
render: function(imp, vals, units, panel, waste){
var crossSel = panel.querySelector('.crossSel');
var cross = crossSel ? (parseFloat(crossSel.value) || 2) : 2;
imp.waste = waste;
var R = calcSidewalk(imp);
var h = '
Estimates only. Bag yields per manufacturer specs (80 lb = 0.60 ft3, 60 lb = 0.45 ft3, 40 lb = 0.30 ft3). Tool or saw-cut the joints at least one quarter of the slab thickness deep. On soft ground or where vehicles will cross, step the thickness up to 5 or 6 in and confirm the final order with your supplier.
';
h += resetHTML() + '
';
return h;
},
links: ['slab','patio','driveway','curb','cost','sealer'],
verified: 'Sidewalk thickness 4 in typical (minimum 3 in; 3,000 PSI mix). Joint spacing matched to width for square panels. Wire mesh allowance x 1.10. Cross slope 1 to 2% (2% maximum). Bag yields per manufacturer specifications (Quikrete). Density 150 lb/ft3 (2,400 kg/m3).'
},
sonotube: {
title: 'Sonotube Concrete Pier Calculator',
formula: 'Volume per tube = pi x (diameter / 2)^2 x depth (cubic feet)',
fields: [
{ id:'dia', label:'Tube diameter', kind:'sm', ph:'12', defUnit:'in', quick:[8,10,12,16] },
{ id:'depth', label:'Tube depth', kind:'sm', ph:'48', defUnit:'in' },
{ id:'n', label:'Number of piers', kind:'num', ph:'8' }
],
extrasHTML: function(){
return '
' +
'
With this on, the volume is worked out over the full depth plus 6 in, as the page specifies (a 48 in tube is calculated over 54 in).
Warning: the tube depth (' + fmt(R.depthIn, 1) + ' in) is shallower than the frost depth you entered. IRC R403.1.4 requires exterior footings to extend below the local frost line. Confirm the required depth with your building department.
';
} else if(R.belowFrost === true){
h += '
Good: the tube depth (' + fmt(R.depthIn, 1) + ' in) reaches below the frost depth you entered.
';
}
h += '
Buy ' + fmt(R.tubeBuyLen, 0) + ' in tube length per pier (depth + 12 in for levelling)
';
if(R.bagCost > 0) h += '
' + CUR + fmt(R.bagCost) + ' estimated 80 lb bag cost
';
h += '
Estimates only. Bag yields per manufacturer specs (80 lb = 0.60 ft3, 60 lb = 0.45 ft3, 40 lb = 0.30 ft3). Sonotube is a brand name for cardboard pier forms (also called concrete tube or pier form). This sizes the concrete only: pier diameter, spacing and reinforcement for structural loads must be confirmed with your local code or a qualified professional.
';
h += resetHTML() + '
';
return h;
},
links: ['posthole','footing','column','cost','patio','sidewalk'],
verified: 'Tube volume per SlabCalc (12 in x 48 in tube holds 3.14 ft3; about 6 bags of 80 lb with 10% waste). Common diameters 8 to 24 in; 10 to 12 in for standard deck posts. Frost line per IRC R403.1.4 (near zero in the Deep South, 48 to 60 in in northern states). Gravel base allowance 6 in. Tube length buy allowance 6 to 12 in. Bag yields per manufacturer specifications (Quikrete). Density 150 lb/ft3 (2,400 kg/m3).'
},
countertop: {
title: 'Concrete Countertop Calculator',
formula: 'Volume = Length x Width x Thickness (cubic feet); bags = volume / bag yield',
fields: [
{ id:'l', label:'Length', kind:'len', ph:'8', defUnit:'ft' },
{ id:'w', label:'Width', kind:'len', ph:'2', defUnit:'ft' },
{ id:'t', label:'Thickness', kind:'sm', ph:'1.5', defUnit:'in', quick:[1.5,2] }
],
extrasHTML: function(){
return '
' +
'
' +
wasteRowHTML(10) + priceFieldHTML('priceBag', 'Price per bag', '7');
},
extraFields: [ { id:'priceBag', label:'Price per bag', kind:'usd' } ],
empty: 'Enter the countertop size above.',
validate: function(panel, vals){
if(!vals.l || !vals.w || !vals.t) return this.empty;
return null;
},
toImp: function(vals, units){
return { l:toFt(vals.l, units.l), w:toFt(vals.w, units.w), t:toIn(vals.t, units.t), priceBag:num(vals.priceBag) };
},
render: function(imp, vals, units, panel, waste){
var msel = panel.querySelector('.mixSel');
var mix = msel ? msel.value : 'ct';
var R = calcCountertop({ l:imp.l, w:imp.w, t:imp.t, mix:mix, waste:waste, priceBag:imp.priceBag });
var mixName = R.isCt ? 'countertop mix (0.43 ft3 per 47 lb bag)' : 'standard 80 lb mix (0.60 ft3 per bag)';
var h = '
' + fmt(R.weightPerFt2, 2) + ' lb per ft2 (check your cabinets can carry this)
';
if(R.bagCost > 0) h += '
' + CUR + fmt(R.bagCost) + ' estimated bag cost
';
h += '
Estimates only. Concrete countertops are heavy: at 1.5 to 2 in they weigh about 19 to 25 lb per square foot, so confirm your cabinets and floor can carry the load before you pour. Cast at 1.5 to 2 in; seal the finished top with a food-safe sealer and reseal every 2 to 3 years. Confirm bag counts with your supplier.
';
h += resetHTML() + '
';
return h;
},
links: ['slab','mix','bags','patio','cost','sealer'],
verified: 'Standard thickness 1.5 to 2 in; minimum 1.5 in. Countertop mix coverage 0.43 ft3 per 47 lb bag (can be cast as thin as 1 in). Typical weight 19 to 25 lb per ft2 at 1.5 to 2 in. Standard 80 lb bag yield 0.60 ft3 per QUIKRETE. Density 150 lb/ft3 (2,400 kg/m3).'
},
sealer: {
title: 'Concrete Sealer Coverage Calculator',
formula: 'Gallons = surface area / coverage rate per coat (sum both coats)',
fields: [
{ id:'l', label:'Length', kind:'len', ph:'20', defUnit:'ft' },
{ id:'w', label:'Width', kind:'len', ph:'40', defUnit:'ft' }
],
extrasHTML: function(){
return '
' +
'
' +
'
' +
'
' +
'ft2/gal
' +
'
' +
'
' +
'ft2/gal
' +
priceFieldHTML('priceGal', 'Price per gallon', '');
},
extraFields: [
{ id:'r1', label:'First coat coverage', kind:'num' },
{ id:'r2', label:'Second coat coverage', kind:'num' },
{ id:'priceGal', label:'Price per gallon', kind:'usd' }
],
empty: 'Enter the surface size above.',
validate: function(panel, vals){
if(!vals.l || !vals.w) return this.empty;
return null;
},
toImp: function(vals, units){
function rate(v, d){ v = parseFloat(v); return (isFinite(v) && v > 0) ? v : d; }
return { l:toFt(vals.l, units.l), w:toFt(vals.w, units.w),
r1:rate(vals.r1, 300), r2:rate(vals.r2, 450), priceGal:num(vals.priceGal) };
},
render: function(imp, vals, units, panel, waste){
var csel = panel.querySelector('.coatsSel');
var coats = csel ? (parseInt(csel.value, 10) === 1 ? 1 : 2) : 2;
var R = calcSealer({ l:imp.l, w:imp.w, coats:coats, r1:imp.r1, r2:imp.r2, priceGal:imp.priceGal });
var h = '
Sealer needed
';
h += nwCol('First coat (' + fmt(imp.r1, 0) + ' ft2/gal)', [[fmt(R.g1), 'Gallons'], [fmt(R.g1 * 3.78541), 'Litres'], [fmt(R.area, 0) + ' ft2', 'surface area']]);
if(coats === 2){
h += nwCol('Second coat (' + fmt(imp.r2, 0) + ' ft2/gal)', [[fmt(R.g2), 'Gallons'], [fmt(R.g2 * 3.78541), 'Litres'], ['apply after the first coat is tack free', 'timing']]);
} else {
h += nwCol('One coat selected', [[fmt(R.total), 'Gallons total'], [fmt(R.litres), 'Litres'], ['two coats protect better', 'note']]);
}
h += '
Estimates only. Coverage varies with surface texture, porosity and weather: check the rate on your product label and adjust the fields above. Seal concrete that is at least 28 days old. Keep foot traffic off for 24 hours and vehicles off for 72 hours after sealing.
';
h += resetHTML() + '
';
return h;
},
links: ['patio','driveway','sidewalk','slab','cost','weight'],
verified: 'First coat 250 to 350 ft2 per gallon on broomed concrete (300 to 450 troweled); second coat 300 to 600 ft2 per gallon. Tool defaults 300 ft2/gal first coat, 450 ft2/gal second coat (midpoints of the published bands); both adjustable. Seal at 28 days. 1 gallon = 3.78541 litres.'
}
};
/* ---------- panel build, calc wiring, toggles, boot ---------- */
function calcPanel(tool, panel){
var box = panel.querySelector('.cc-out');
if(!box) return;
if(tool.syncExtras) tool.syncExtras(panel);
var rv = readVals(panel);
var verr = tool.validate ? tool.validate(panel, rv.vals) : null;
if(verr){ box.innerHTML = emptyHTML(verr); return; }
var imp = tool.toImp(rv.vals, rv.units);
var waste = readWaste(panel);
var html = tool.render(imp, rv.vals, rv.units, panel, waste);
html += relatedHTML(tool.links) + verifiedHTML(tool.verified);
box.innerHTML = html;
var rb = box.querySelector('[data-act="reset"]');
if(rb) rb.addEventListener('click', function(){
panel.querySelectorAll('input').forEach(function(i){
if(i.type === 'checkbox'){ i.checked = false; } else { i.value = ''; }
});
calcPanel(tool, panel);
});
}
function wireSelectConvert(panel, tool){
panel.querySelectorAll('select.cc-funit').forEach(function(sel){
sel.addEventListener('change', function(){
var fid = sel.getAttribute('data-funit');
var inp = panel.querySelector('input[data-fid="' + fid + '"]');
if(!inp || !inp.value){ calcPanel(tool, panel); return; }
var field = null;
(tool.fields || []).concat(tool.extraFields || []).forEach(function(f){ if(f.id === fid) field = f; });
if(!field) return;
var oldU = sel.getAttribute('data-prev') || field.defUnit || 'ft';
var newU = sel.value;
if(oldU !== newU) inp.value = convertVal(inp.value, oldU, newU, field.kind);
sel.setAttribute('data-prev', newU);
calcPanel(tool, panel);
});
sel.setAttribute('data-prev', sel.value);
});
}
function wireQuick(panel, tool){
panel.querySelectorAll('[data-quick]').forEach(function(b){
b.addEventListener('click', function(){
var fid = b.getAttribute('data-qfid');
var inp = panel.querySelector('input[data-fid="' + fid + '"]');
var sel = panel.querySelector('select.cc-funit[data-funit="' + fid + '"]');
if(!inp) return;
var qv = b.getAttribute('data-quick');
if(sel && (sel.value === 'm' || sel.value === 'cm' || sel.value === 'mm')){
var cm = parseFloat(qv) * 2.54;
if(sel.value === 'm') inp.value = fmt(cm / 100, 3);
else if(sel.value === 'cm') inp.value = fmt(cm, 1);
else inp.value = fmt(cm * 10, 0);
} else {
inp.value = qv;
if(sel) sel.value = 'in';
}
panel.querySelectorAll('[data-qfid="' + fid + '"]').forEach(function(x){ x.classList.remove('on'); });
b.classList.add('on');
calcPanel(tool, panel);
});
});
}
/* Header unit toggle, P3 style: convert every length/thickness/
volume field by its data-kind, flip its unit select, and keep
data-prev in step. Price, waste, shape and count fields are
never touched. */
function wireHeaderToggle(panel, tool){
var ui = document.getElementById('p3uImp'), um = document.getElementById('p3uMet');
function apply(target){
panel.querySelectorAll('select.cc-funit').forEach(function(sel){
var fid = sel.getAttribute('data-funit');
var inp = panel.querySelector('input[data-fid="' + fid + '"]');
if(!inp) return;
var kind = inp.getAttribute('data-kind');
var tgt = null;
if(target === 'imp'){
if(kind === 'len') tgt = 'ft'; else if(kind === 'sm') tgt = 'in'; else if(kind === 'yd3') tgt = 'yd3';
} else {
if(kind === 'len') tgt = 'm'; else if(kind === 'sm') tgt = 'cm'; else if(kind === 'yd3') tgt = 'm3';
}
if(!tgt) return;
if(inp.value) inp.value = convertVal(inp.value, sel.value, tgt, kind);
sel.value = tgt;
sel.setAttribute('data-prev', tgt);
});
if(ui) ui.classList.toggle('on', target === 'imp');
if(um) um.classList.toggle('on', target === 'met');
calcPanel(tool, panel);
}
if(ui) ui.onclick = function(){ apply('imp'); };
if(um) um.onclick = function(){ apply('met'); };
/* Currency button: cycle the symbol used by price displays. */
var uc = document.getElementById('p3uCur');
function paintCur(){
if(uc) uc.textContent = (CUR === '£' ? '£ GBP' : (CUR === '€' ? '€ EUR' : '$ USD'));
panel.querySelectorAll('.curSym').forEach(function(s){ s.textContent = CUR; });
}
if(uc) uc.onclick = function(){
CUR = (CUR === '$') ? '£' : ((CUR === '£') ? '€' : '$');
paintCur();
calcPanel(tool, panel);
};
paintCur();
}
function buildPanel(tool, id){
var p = document.createElement('div');
p.className = 'cc-panel on';
p.id = 'ccp-' + id;
p.setAttribute('role', 'tabpanel');
var inner = '