﻿// JScript File

var volSolidsArray = new Array();
volSolidsArray[0] = "PE-70 Epoxy||.7";
volSolidsArray[1] = "Indurethane 6600||.64";
volSolidsArray[2] = "Induraguard||.74";
volSolidsArray[3] = "Indurazinc MC67||.67";
volSolidsArray[4] = "Perma-Clean II||.60";
volSolidsArray[5] = "Ceramapure TL 70||.70";
volSolidsArray[6] = "Ceramapure PL 90||.90";
volSolidsArray[7] = "Aquanaut II||.36";
volSolidsArray[8] = "RC-70 Epoxy||.70";
volSolidsArray[9] = "Perma-Clean 100||1";
volSolidsArray[10] = "Perma-Safe 100||1";
volSolidsArray[11] = "Indurethane 6700 Flat||.67";
volSolidsArray[12] = "PermaClear Fluorourethane||.52";


var constVolSolidsSquareFootMeasure = 1604;

function drawGrid(pricePerGallon, dft, transferEfficiency, selectedItem) {
    var rows = volSolidsArray.length;
    var oTbl = document.createElement("Table");
    oTbl.border = 1;
    oTbl.cellPadding = 3;
    createHeader(oTbl);
    
    if (selectedItem.length > 0) { // only show one product
        for (var i = 0; i < volSolidsArray.length; i++) { 
            if (volSolidsArray[i].split('||')[0] == selectedItem) {
                var oTR = oTbl.insertRow(1);
                insertColumns(oTR, i, pricePerGallon, dft, transferEfficiency);
            }
        }
    } else { // show all products
        for(var i = 0; i < rows; i++) {
           var oTR = oTbl.insertRow(i+1);
           insertColumns(oTR, i, pricePerGallon, dft, transferEfficiency);
        }
    }
    document.getElementById("grid").innerHTML = "";
    document.getElementById("grid").appendChild(oTbl);
}

function drawProductDropdown() {
    document.write("<select id='product'>");
    document.write("<option value=''>Show All</option>");
    for (var i = 0; i < volSolidsArray.length; i++) {
        var item = volSolidsArray[i].split('||')[0];
        document.write("<option value='" + item + "'>" + item + "</option>");
    }
    document.write("</select>");
}

function createHeader(oTbl) {
    var oTR = oTbl.insertRow(0);
    oTR.setAttribute("style", "font-weight:bold;");
    var oTD = oTR.insertCell(0); 
    oTD.innerHTML = "Product Name";
    oTD = oTR.insertCell(1); 
    oTD.innerHTML = "Coverage";
    oTD = oTR.insertCell(2); 
    oTD.innerHTML = "Material Cost";
}

function insertColumns(oTR, rowCount, pricePerGallon, dft, transferEfficiency) {
    var oTD = oTR.insertCell(0);  
    oTD.innerHTML = volSolidsArray[rowCount].split('||')[0]; // product name
    oTD = oTR.insertCell(1);
    var coverageArea = calculateCoverage(volSolidsArray[rowCount].split('||')[1], transferEfficiency, dft);
    oTD.innerHTML = Math.round(coverageArea) + " ft2 /gal"; // square foot coverage
    oTD = oTR.insertCell(2);
    if (pricePerGallon != "") {
        oTD.innerHTML = "$" + Math.round(pricePerGallon / coverageArea * 100000) /100000 + " /ft2"; // cost per sq ft ??
    }
}

function calculateCoverage(volSolidsPercent, transferEfficiency, dft) {
    return (constVolSolidsSquareFootMeasure * volSolidsPercent * (transferEfficiency/100)) / dft;
}
