    var currentAnchor = null;

    var tabRectOn  = null;
    var tabRectOff = null;
    var tabCircOn  = null;
    var tabCircOff = null;

    var formMulchCalc = null;

    var imageRect = null;
    var imageCirc = null;

    var varArea = null;

    var divWidth    = null;
    var divLength   = null;
    var divDiameter = null;

    var varWF = null;
    var varWI = null;
    var varLF = null;
    var varLI = null;
    var varHF = null;
    var varHI = null;
    var varDF = null;
    var varDI = null;

    var buttonCalculate = null;
    var buttonReset     = null;

    var divResult   = null;
    var divSolution = null;

    function initializeMulch()
    {
      tabRectOn  = document.getElementById('tabrecton');
      tabRectOff = document.getElementById('tabrectoff');
      tabCircOn  = document.getElementById('tabcircon');
      tabCircOff = document.getElementById('tabcircoff');

      formMulchCalc = document.getElementById('formmulchcalc');

      imageRect = document.getElementById('mulchcalc_rect3d');
      imageCirc = document.getElementById('mulchcalc_circ3d');

      varArea = document.getElementById('area');

      divWidth    = document.getElementById('divwidth');
      divLength   = document.getElementById('divlength');
      divDiameter = document.getElementById('divdiameter');

      varWF = document.getElementById('varwf');
      varWI = document.getElementById('varwi');
      varLF = document.getElementById('varlf');
      varLI = document.getElementById('varli');
      varHF = document.getElementById('varhf');
      varHI = document.getElementById('varhi');
      varDF = document.getElementById('vardf');
      varDI = document.getElementById('vardi');

      buttonCalculate = document.getElementById('buttoncalculate');
      buttonReset     = document.getElementById('buttonreset');

      divResult   = document.getElementById('divresult');
      divSolution = document.getElementById('divsolution');

      varWF.onkeyup = checkWF;
      varWI.onkeyup = checkWI;
      varLF.onkeyup = checkLF;
      varLI.onkeyup = checkLI;
      varHF.onkeyup = checkHF;
      varHI.onkeyup = checkHI;
      varDF.onkeyup = checkDF;
      varDI.onkeyup = checkDI;

      tabRectOff.onclick = tabRectFunc;
      tabCircOff.onclick = tabCircFunc;

      buttonCalculate.onclick = updateAnchor;
      buttonReset.onclick     = resetAnchor;

      setInterval("checkAnchor()", 500);
    }

    function checkAnchor()
    {
      if(currentAnchor != document.location.hash)
      {
        currentAnchor = document.location.hash;

        if(currentAnchor != "")
          printResult();
      }
    }

    function resetAnchor()
    {
      document.location.hash = "area="+varArea.value+"&wf=0&wi=0&lf=0&li=0&hf=0&hi=0&df=0&di=0";

      document.title = "Crown Recycling Facility LLC. - Colored Mulch";

      checkAnchor();
    }

    function updateAnchor()
    {
      checkWF(); checkWI(); checkLF(); checkLI(); checkHF(); checkHI(); checkDF(); checkDI();
      document.location.hash =  "area="+varArea.value+"&wf="+varWF.value+"&wi="+varWI.value+"&lf="+varLF.value+"&li="+varLI.value+"&hf="+varHF.value+"&hi="+varHI.value+"&df="+varDF.value+"&di="+varDI.value;

      var currentDate = new Date();
      var dateTime = currentDate.getFullYear()+"-"+currentDate.getMonth()+"-"+currentDate.getDate()+", "+currentDate.getHours()+"."+currentDate.getMinutes()+"."+currentDate.getSeconds();

      document.title = "Crown Recycling Facility LLC. - Colored Mulch Calculator Results from "+dateTime;

      checkAnchor();
    }

    function checkWF() { varWF.value = varWF.value.replace(/[^0-9]/g, ''); }
    function checkWI() { varWI.value = varWI.value.replace(/[^0-9]/g, ''); }
    function checkLF() { varLF.value = varLF.value.replace(/[^0-9]/g, ''); }
    function checkLI() { varLI.value = varLI.value.replace(/[^0-9]/g, ''); }
    function checkHF() { varHF.value = varHF.value.replace(/[^0-9]/g, ''); }
    function checkHI() { varHI.value = varHI.value.replace(/[^0-9]/g, ''); }
    function checkDF() { varDF.value = varDF.value.replace(/[^0-9]/g, ''); }
    function checkDI() { varDI.value = varDI.value.replace(/[^0-9]/g, ''); }

    function tabRectFunc()
    {
      imageRect.style.display = "block";
      imageCirc.style.display = "none";

      varArea.value = "rect";

      tabRectOff.style.display = "none";
      tabRectOn.style.display  = "block";
      tabCircOn.style.display  = "none";
      tabCircOff.style.display = "block";

      divWidth.style.display = "block";
      divLength.style.display = "block";
      divDiameter.style.display = "none";

      updateAnchor();
    }

    function tabCircFunc()
    {
      imageCirc.style.display = "block";
      imageRect.style.display = "none";

      varArea.value = "circ";

      tabCircOff.style.display = "none";
      tabCircOn.style.display  = "block";
      tabRectOn.style.display  = "none";
      tabRectOff.style.display = "block";

      divWidth.style.display = "none";
      divLength.style.display = "none";
      divDiameter.style.display = "block";

      updateAnchor();
    }

    function calculateResult(variables)
    {
      var variablesSplit = variables.split("&");

      var areaSplit = variablesSplit[0].split("=");

      var widthFeet      = variablesSplit[1].split("=");
      var widthInches    = variablesSplit[2].split("=");
      var lengthFeet     = variablesSplit[3].split("=");
      var lengthInches   = variablesSplit[4].split("=");
      var heightFeet     = variablesSplit[5].split("=");
      var heightInches   = variablesSplit[6].split("=");
      var diameterFeet   = variablesSplit[7].split("=");
      var diameterInches = variablesSplit[8].split("=");

      var areaType = areaSplit[1];

      if(areaType == "rect")
        tabRectFunc();
      else
        tabCircFunc();

      varWF.value = widthFeet[1] = widthFeet[1] == "" ? 0 : widthFeet[1];
      varWI.value = widthInches[1] = widthInches[1] == "" ? 0 : widthInches[1];
      varLF.value = lengthFeet[1] = lengthFeet[1] == "" ? 0 : lengthFeet[1];
      varLI.value = lengthInches[1] = lengthInches[1] == "" ? 0 : lengthInches[1];
      varHF.value = heightFeet[1] = heightFeet[1] == "" ? 0 : heightFeet[1];
      varHI.value = heightInches[1] = heightInches[1] == "" ? 0 : heightInches[1];
      varDF.value = diameterFeet[1] = diameterFeet[1] == "" ? 0 : diameterFeet[1];
      varDI.value = diameterInches[1] = diameterInches[1] == "" ? 0 : diameterInches[1];

      var widthTotal  = (parseInt(widthFeet[1])*12)+parseInt(widthInches[1]);
      var lengthTotal = (parseInt(lengthFeet[1])*12)+parseInt(lengthInches[1]);
      var heightTotal = (parseInt(heightFeet[1])*12)+parseInt(heightInches[1]);
      var diameterTotal = (parseInt(diameterFeet[1])*12)+parseInt(diameterInches[1]);

      if(areaType == "rect")
        return (widthTotal*lengthTotal*heightTotal)/46656;
      else
        return (Math.PI*(diameterTotal/2)*(diameterTotal/2)*heightTotal)/46656;
    }

    function calculateSolution(cuYds)
    {
      var bulkMax = 90;

      if(cuYds > bulkMax)
      {
        var bulkMaxLoads  = parseInt(cuYds / bulkMax);
        var leftoverCuYds = cuYds % bulkMax;
        var extraLoad     = 0;

        if(leftoverCuYds > 0 && leftoverCuYds <= 10)
          extraLoad = 10;
        else if(leftoverCuYds > 10 && leftoverCuYds <= 20)
          extraLoad = 20;
        else if(leftoverCuYds > 20 && leftoverCuYds <= 30)
          extraLoad = 30;
        else if(leftoverCuYds > 30 && leftoverCuYds <= 40)
          extraLoad = 40;
        else if(leftoverCuYds > 40 && leftoverCuYds <= 50)
          extraLoad = 50;
        else if(leftoverCuYds > 50 && leftoverCuYds <= 80)
          extraLoad = 80;
        else if(leftoverCuYds > 80 && leftoverCuYds < 90)
        {
          extraLoad = 0;
          bulkMaxLoads++;
        }
        else
          return "";

        if(extraLoad == 0)
          return 'Crown Recycling Facility LLC. can fulfill your needs with a bulk delivery of <span class="b">'+bulkMaxLoads+'x '+bulkMax+' cubic yards</span> of mulch.';
        else
          return 'Crown Recycling Facility LLC. can fulfill your needs with a bulk delivery of <span class="b">'+bulkMaxLoads+'x '+bulkMax+'</span> and <span class="b">1x '+extraLoad+' cubic yards</span> of mulch.';
      }
      else
      {
        var bulkLoad = 0;

        if(cuYds > 0 && cuYds <= 10)
          bulkLoad = 10;
        else if(cuYds > 10 && cuYds <= 20)
          bulkLoad = 20;
        else if(cuYds > 20 && cuYds <= 30)
          bulkLoad = 30;
        else if(cuYds > 30 && cuYds <= 40)
          bulkLoad = 40;
        else if(cuYds > 40 && cuYds <= 50)
          bulkLoad = 50;
        else if(cuYds > 50 && cuYds <= 80)
          bulkLoad = 80;
        else if(cuYds > 80 && cuYds <= 90)
          bulkLoad = 90;
        else
          return "";
      }

      return 'Crown Recycling Facility LLC. can fulfill your needs with a bulk delivery of <span class="b">1x '+bulkLoad+' cubic yards</span> of mulch.';
    }

    function printResult()
    {
      var cubicYards = calculateResult(currentAnchor).toFixed(2);

      var resultText = cubicYards == 0 ? "" : 'You need <span class="b">'+cubicYards+' cubic yards</span> of mulch.';

      divResult.innerHTML = '<span class="b">RESULT:</span> '+resultText;
      divSolution.innerHTML = '<span class="b">SOLUTION:</span> '+calculateSolution(parseFloat(cubicYards));
    }

    window.onload = initializeMulch;