<?php
$page_title = "Epoxy Joint Filler Calculator | Epoxy.com";
$meta_description = "Epoxy joint filler calculator. Enter joint length, depth, and width to calculate gallons required and the number of 2-gallon units needed.";
include $_SERVER['DOCUMENT_ROOT'].'/includes/header.php';
?>

<!--
File: epoxy-joint-filler-calculator.aspx
Purpose:
  Replace the existing joint filler calculator without changing file name or location.

System assumptions:
  - Inputs:
      Joint length in feet
      Joint depth in inches
      Joint width in inches
  - Conversion:
      231 cubic inches = 1 gallon
  - Packaging:
      2-gallon units
  - Output:
      Cubic inches
      Gallons decimal
      Gallons as mixed fraction rounded to nearest 1/8
      Number of 2-gallon units rounded up
      Total gallons supplied by units

Important:
  - No waste factor included
  - Customer should add allowance for real-world conditions
-->

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "WebApplication",
  "name": "Epoxy Joint Filler Calculator",
  "description": "Calculator to estimate gallons of epoxy joint filler needed from joint length, depth, and width, and the number of 2-gallon units required.",
  "applicationCategory": "Calculator",
  "operatingSystem": "All",
  "publisher": {
    "@type": "Organization",
    "name": "Epoxy.com"
  }
}
</script>

<h1>Epoxy Joint Filler Calculator</h1>

<p>
Enter the joint dimensions below to estimate how much epoxy joint filler you need.
This calculator does not include waste factor.
</p>

<div class="container" style="max-width:720px;">

  <div style="margin:1em 0;">
    <label for="lengthFeet"><strong>Joint Length</strong> (feet)</label><br />
    <input type="number" id="lengthFeet" min="0" step="0.01" style="max-width:220px;" />
  </div>

  <div style="margin:1em 0;">
    <label for="depthIn"><strong>Joint Depth</strong> (inches)</label><br />
    <input type="number" id="depthIn" min="0" step="0.01" style="max-width:220px;" />
  </div>

  <div style="margin:1em 0;">
    <label for="widthIn"><strong>Joint Width</strong> (inches)</label><br />
    <input type="number" id="widthIn" min="0" step="0.01" style="max-width:220px;" />
  </div>

  <div style="margin:1.25em 0;">
    <button type="button" onclick="calculateJointFiller()">Calculate</button>
  </div>

  <div id="calcError" style="display:none; border:1px solid #f3c2c2; background:#fff5f5; padding:1em; border-radius:6px; color:#b00000;">
  </div>

  <div id="calcResults" style="display:none; border:1px solid #ccc; padding:1em; border-radius:6px;">
    <h2 style="margin-top:0;">Results</h2>

    <p><strong>Total volume:</strong> <span id="outCubicIn"></span></p>
    <p><strong>Gallons required:</strong> <span id="outGallonsDec"></span></p>
    <p><strong>Gallons (fraction):</strong> <span id="outGallonsFrac"></span></p>

    <hr />

    <p><strong>2-gallon units (rounded up):</strong> <span id="outKits"></span></p>
    <p><strong>Total gallons supplied by units:</strong> <span id="outKitGallons"></span></p>

    <p style="margin-top:1em;">
      <em>Note:</em> This does not include waste, overfill, rough joint walls, or losses from mixing and tooling.
    </p>
  </div>

  <p style="font-size:0.95em; margin-top:1em;">
    This calculator is provided for estimating and double-checking your own calculations.
    While Epoxy.com believes the formulas used are accurate, this tool is provided "as is"
    without warranty or guarantee of accuracy. Quantities shown are based on theoretical
    coverage rates. Actual jobsite conditions, surface profile, porosity, mixing loss,
    broadcast loss, and installer technique may require additional material.
  </p>

</div>

<script>
function formatNumber(value, decimals) {
  return Number(value).toFixed(decimals);
}

function gcd(a, b) {
  a = Math.abs(a);
  b = Math.abs(b);

  while (b !== 0) {
    let t = a % b;
    a = b;
    b = t;
  }

  return a === 0 ? 1 : a;
}

function toMixedFraction(number, denomStep) {
  if (denomStep < 1) denomStep = 1;
  if (number < 0) number = Math.abs(number);

  const whole = Math.floor(number);
  const frac = number - whole;

  let numerator = Math.round(frac * denomStep);
  let denominator = denomStep;

  if (numerator === 0) {
    return String(whole);
  }

  if (numerator === denominator) {
    return String(whole + 1);
  }

  const g = gcd(numerator, denominator);
  numerator = numerator / g;
  denominator = denominator / g;

  if (whole === 0) {
    return numerator + "/" + denominator;
  }

  return whole + " " + numerator + "/" + denominator;
}

function calculateJointFiller() {
  const lengthFeet = parseFloat(document.getElementById("lengthFeet").value);
  const depthIn = parseFloat(document.getElementById("depthIn").value);
  const widthIn = parseFloat(document.getElementById("widthIn").value);

  const errorBox = document.getElementById("calcError");
  const resultsBox = document.getElementById("calcResults");

  errorBox.style.display = "none";
  errorBox.innerHTML = "";
  resultsBox.style.display = "none";

  if (isNaN(lengthFeet) || lengthFeet <= 0) {
    errorBox.innerHTML = "<strong>Error:</strong> Please enter a valid positive number for Joint Length.";
    errorBox.style.display = "block";
    return;
  }

  if (isNaN(depthIn) || depthIn <= 0) {
    errorBox.innerHTML = "<strong>Error:</strong> Please enter a valid positive number for Joint Depth.";
    errorBox.style.display = "block";
    return;
  }

  if (isNaN(widthIn) || widthIn <= 0) {
    errorBox.innerHTML = "<strong>Error:</strong> Please enter a valid positive number for Joint Width.";
    errorBox.style.display = "block";
    return;
  }

  const lengthIn = lengthFeet * 12.0;
  const cubicIn = lengthIn * depthIn * widthIn;
  const gallons = cubicIn / 231.0;

  let kits = Math.ceil(gallons / 2.0);
  if (kits < 1) kits = 1;

  const kitGallons = kits * 2.0;

  document.getElementById("outCubicIn").textContent = formatNumber(cubicIn, 2) + " cubic inches";
  document.getElementById("outGallonsDec").textContent = formatNumber(gallons, 2) + " gallons";
  document.getElementById("outGallonsFrac").textContent = toMixedFraction(gallons, 8) + " gallons (rounded to nearest 1/8)";
  document.getElementById("outKits").textContent = kits + " unit(s) of 2 gallons";
  document.getElementById("outKitGallons").textContent = formatNumber(kitGallons, 2) + " gallons";

  resultsBox.style.display = "block";
}
</script>

<?php include $_SERVER['DOCUMENT_ROOT'].'/includes/footer.php'; ?>