﻿var totalWidth, totalLength, optGap, boardWidth, boardAndGap, boards, allGaps, actualGap, linealBoards, minLast, boardLength, joistSpacing, boardThick; function SetDeck() { SetNumeric(); minLast = 25; CalcDeck(); } function CalcDeck() { totalWidth = parseFloat(document.getElementById("txtTotalWidth").value); if (totalWidth < 100 || totalWidth > 100000 || isNaN(totalWidth)) { alert("Deck width must be between 1000 and 100000"); document.getElementById("txtTotalWidth").focus(); return; } totalLength = parseFloat(document.getElementById("txtTotalLength").value); if (isNaN(totalLength)) { document.getElementById("txtTotalLength").value = "0"; totalLength = 0; } optGap = parseFloat(document.getElementById("_txtOptGap").value); if (optGap < 1 || optGap > 20 || isNaN(optGap)) { alert("Optimal Gap must be between 1 and 20"); document.getElementById("_txtOptGap").focus(); return; } boardWidth = parseFloat(document.getElementById("txtBoardWidth").value); if (boardWidth < 20 || boardWidth > 600 || isNaN(boardWidth)) { alert("Board width must be between 20 and 600"); document.getElementById("txtBoardWidth").focus(); return; } boardThick = parseFloat(document.getElementById("txtBoardThick").value); if (boardThick < 19 || boardThick > 100 || isNaN(boardThick)) { alert("Board thickness must be between 19 and 100"); document.getElementById("txtBoardThick").focus(); return; } boardLength = parseFloat(document.getElementById("txtBoardLength").value); if (boardLength < 1000 || boardLength > 20000 || isNaN(boardLength)) { alert("Board width must be between 1000 and 20000"); document.getElementById("txtBoardLength").focus(); return; } joistSpacing = parseFloat(document.getElementById("txtJoistSpacing").value); if (joistSpacing < 200 || joistSpacing > 1000 || isNaN(joistSpacing)) { alert("Joist Spacing must be between 200 and 1000"); document.getElementById("txtJoistSpacing").focus(); return; } boards = Math.floor((totalWidth + optGap) / (boardWidth + optGap)); allGaps = totalWidth - (boards * boardWidth); actualGap = allGaps / (boards - 1); boardAndGap = boardWidth + actualGap; document.getElementById("btnSubBoard").disabled = false; document.getElementById("btnAddBoard").disabled = false; document.getElementById("btnCutLast").disabled = false; UpdateResults(0); } function Board(d) { if (d == 1) { if (allGaps > boardWidth) boards++; else { document.getElementById("btnAddBoard").disabled = true; alert("Won't Fit"); return; } } else { if (actualGap < 20) boards--; else { document.getElementById("btnSubBoard").disabled = true; alert("Gaps are too large"); return; } } allGaps = totalWidth - (boards * boardWidth); actualGap = allGaps / (boards - 1); boardAndGap = boardWidth + actualGap; linealBoards = boards * totalLength; document.getElementById("btnSubBoard").disabled = false; document.getElementById("btnAddBoard").disabled = false; document.getElementById("btnCutLast").disabled = false; UpdateResults(0); } function UpdateResults(lastBoard) { DoRun(); linealBoards = boards * totalLength; document.getElementById("spnBoards").innerHTML = boards; document.getElementById("spnGap").innerHTML = RoundTo(actualGap, 1); document.getElementById("spnLineal").innerHTML = CommaFormat(linealBoards); var wastePercent = parseFloat(document.getElementById("ddWaste").value); var linealPlus = linealBoards + (linealBoards * wastePercent / 100); document.getElementById("spnLinealPlus").innerHTML = CommaFormat(linealPlus); document.getElementById("spnPercentWaste").innerHTML = wastePercent; document.getElementById("spnBoardLength").innerHTML = boardLength; var totalBoards = Math.ceil(linealPlus / boardLength); document.getElementById("spnTotalBoards").innerHTML = totalBoards; var deckVolume = (totalBoards * boardLength * boardWidth * boardThick) * .000000001; document.getElementById("spnDeckVolume").innerHTML = RoundTo(deckVolume, 3); var joists = Math.ceil(totalLength / joistSpacing) + 1; document.getElementById("spnJoists").innerHTML = joists; var fasteners = (joists * boards * 2); if (totalLength > boardLength) fasteners += (totalBoards * 2); document.getElementById("spnFasteners").innerHTML = fasteners; var desc = ""; if (lastBoard == 0) desc = boards + " Courses @ " + boardWidth + " wide, with " + (boards - 1) + " gaps of " + RoundTo(actualGap, 1) + " mm"; else { desc = (boards - 1) + " Courses @ " + boardWidth + " wide + 1 @ " + lastBoard + " wide, with " + (boards - 1) + " gaps of " + RoundTo(actualGap, 1) + "mm"; document.getElementById("spnBoards").innerHTML += " (Last Board = " + lastBoard + ")"; } desc += "<br />" + totalBoards + " Boards @ " + CommaFormat(boardLength) + " X " + boardWidth + " X " + boardThick + " (includes " + wastePercent + "% waste) = " + RoundTo(deckVolume, 3) + "m&sup3;"; document.getElementById("spnDesc").innerHTML = desc; } function DoRun() { var running = ""; var r = 0; var everyXth = document.getElementById("cbEveryBoard").checked; var everyX = document.getElementById("ddEveryBoard").value; for (var i = 0; i < boards - 1; i++) { r += boardAndGap; if (i % everyX == (everyX - 1)) running += "<span class=\"CalcAnswers2\">" + Math.round(r) + "</span>, "; else if (!everyXth) running += Math.round(r) + ", "; } running = running.substring(0, running.length - 2); document.getElementById("spnBoardRun").innerHTML = running; } function CutLast() { var lastBoard = Math.round(totalWidth % (boardWidth + optGap)); if (lastBoard > 0) boards = Math.ceil(totalWidth / boardAndGap); if (lastBoard < minLast) { if (confirm("With " + optGap + "mm gaps, the last board width is too small (" + Math.round(lastBoard) + "mm)\n\r\n\rWould you like to adjust gaps for min last board = " + minLast + "mm ?")) { var adj = minLast - lastBoard; actualGap -= (adj / (boards - 1)); boardAndGap = boardWidth + actualGap; lastBoard = minLast; } else return; } actualGap = optGap; boardAndGap = boardWidth + actualGap; document.getElementById("btnAddBoard").disabled = true; document.getElementById("btnCutLast").disabled = true; UpdateResults(Math.round(lastBoard)); } function Reset() { document.getElementById("btnSubBoard").disabled = true; document.getElementById("btnAddBoard").disabled = true; document.getElementById("btnCutLast").disabled = true; } function RoundTo(val, places) { places = Math.pow(10, places); d = Math.round(val * places) / places; return d; }