<!DOCTYPE html>
<html>

<head>
    <title>
        hand -- operationsM5
    </title>
</head>

<body id="bodyHand"
    style="margin:2px; font-family: monospace; font-weight:bold; background-color:#000000; color:#00ff92">

    <div id="handField">
        <input id="handInput" style="display:inline" type="text" minlength="2" maxlength="15" size="17"
            onpropertychange="hand()" />
        <div id="resultAreaPrice" style="display:inline; font-size:22px;"></div>
    </div>

    <div id="codeNotFound" style="display:none;color: #F69420;"></div>
    
    <div id="resultArea" style="font-size:16px;">
        <div id="resultAreaCode" style="color: #FFFFFF;"></div>
        <div id="resultAreaTitle"></div>
        <div id="resultAreaExpression" style="color: #FFFFFF;"></div>
        <div style="text-align: left;">
            <div id="resultAreaStoc1"></div>
            <!-- <div id="resultAreaStoc2"></div> -->
            <div id="resultAreaStoc3"></div>
            <!-- <div id="resultAreaStoc4"></div> -->
            <div id="resultAreaStoc5" style="color: #FFFFFF;"></div>
        </div>
    </div>

    <div id="timestamp" style="color: #426942;"></div>

    <table id="counterContainer" style="color: #696969;width:90%;border-style:none">
        <tr>
            <td id="counterOContainer" background-color:#000000"</td>
            <td id="counterXContainer" background-color:#000000"</td>
        </tr>
    </table>

    

    <script>
        var timestamp = document.getElementById("timestamp");
        timestamp.innerText = dsTimestamp;
    </script>

    <script>
        var counterO = 0;
        var counterX = 0;
        var codInput = "";
        var handInput = document.getElementById("handInput");

        var resultArea = document.getElementById("resultArea");
        var codeNotFound = document.getElementById("codeNotFound");

        var resultAreaCode = document.getElementById("resultAreaCode");
        var resultAreaTitle = document.getElementById("resultAreaTitle");
        var resultAreaExpression = document.getElementById("resultAreaExpression");
        var resultAreaPrice = document.getElementById("resultAreaPrice");
        var resultAreaStoc1 = document.getElementById("resultAreaStoc1");
        // var resultAreaStoc2 = document.getElementById("resultAreaStoc2");
        var resultAreaStoc3 = document.getElementById("resultAreaStoc3");
        // var resultAreaStoc4 = document.getElementById("resultAreaStoc4");
        var resultAreaStoc5 = document.getElementById("resultAreaStoc5");

        var stocDist = ["d", "b", "m", "c", "t"];
        var handOutputStocInGest = "";

        function hand() {
            if (event.propertyName == 'value') {

                codInput = handInput.value;
                var found = false;

                if (codInput.substring(codInput.length - 1) == "#") {

                    resultAreaCode.innerText = "";
                    resultAreaTitle.innerText = "";
                    resultAreaExpression.innerText = "";
                    resultAreaPrice.innerText = "";
                    resultAreaStoc1.innerText = "";
                    // resultAreaStoc2.innerText = "";
                    resultAreaStoc3.innerText = "";
                    // resultAreaStoc4.innerText = "";
                    resultAreaStoc5.innerText = "";

                    var cod = (handInput.value.toString()).replace("#", "");
                    resultAreaCode.innerText = cod;

                    var cPrefixDictionary = { "c97800": "a", "c97801": "b", "c97802": "c", "c97803": "d", "c97804": "e", "c97805": "f", "c97806": "g", "c97807": "h", "c97808": "i", "c97809": "j", "c97810": "k", "c97811": "l", "c97812": "m", "c97813": "n", "c97814": "o", "c97815": "p", "c97816": "q", "c97817": "r", "c97818": "s", "c97819": "t", "c50505": "u" };
                    var codMini = "";
                    if (cod.length < 6) {
                        codMini = "c" + cod;
                    } else {
                        var cPrefix = "c" + cod.substring(0, 5);
                        var cRest = cod.substring(5);
                        if (cPrefixDictionary[cPrefix] !== undefined) {
                            codMini = "c" + cPrefixDictionary[cPrefix] + cRest;
                        } else {
                            codMini = "c" + cod;
                        }
                    }

                    handInput.value = "";

                    var teps = "";

_tepsGeneratorPlaceholder_

                    if (found == false) {
                        resultArea.style.display = "none";
                        codeNotFound.style.display = "block";
                        codeNotFound.innerHTML = "Nu am gasit <br>" + cod;
                        counterX++;
                    } else {
                        resultArea.style.display = "block";
                        codeNotFound.style.display = "none";
                        var tepsList = teps.split("|");

                        var handOutputTitle = tepsList[0];
                        resultAreaTitle.innerText = handOutputTitle;

                        var handOutputExpression = tepsList[1];
                        var handOutputExpressionDec = "";
                        if (handOutputExpression == "badExpr" || handOutputExpression == ".") {
                            handOutputExpressionDec = handOutputExpression;
                        } else {
                            var dataExprDDdictionaryDec = { "1": "01", "2": "02", "3": "03", "4": "04", "5": "05", "6": "06", "7": "07", "8": "08", "9": "09", "a": "10", "b": "11", "c": "12", "d": "13", "e": "14", "f": "15", "g": "16", "h": "17", "i": "18", "j": "19", "k": "20", "l": "21", "m": "22", "n": "23", "o": "24", "p": "25", "q": "26", "r": "27", "s": "28", "t": "29", "u": "30", "v": "31" };
                            var dataExprPMMPYdictionaryDec = { "a": "p01p2", "b": "p02p2", "c": "p03p2", "d": "p04p2", "e": "p05p2", "f": "p06p2", "g": "p07p2", "h": "p08p2", "i": "p09p2", "j": "p10p2", "k": "p11p2", "l": "p12p2" };
                            var exprList = handOutputExpression.split("/");
                            var dataExprEnc = exprList[1];
                            var dataExprEncFirstChar = dataExprEnc.substring(0, 1);
                            var dataExprEncSecondChar = dataExprEnc.substring(1, 2);
                            var dataExprEncThirdChar = dataExprEnc.substring(2);
                            handOutputExpressionDec = [exprList[0], ((dataExprDDdictionaryDec[dataExprEncFirstChar] + dataExprPMMPYdictionaryDec[dataExprEncSecondChar]).split("p")).join(".") + dataExprEncThirdChar, exprList[2]].join("/");
                        }
                        resultAreaExpression.innerText = handOutputExpressionDec;

                        var handOutputPriceMini = tepsList[2];
                        var handOutputPrice = "";
                        if (/\./.test(handOutputPriceMini) == true) {
                            handOutputPrice = handOutputPriceMini;
                        } else {
                            handOutputPrice = handOutputPriceMini + ".99";
                        }
                        resultAreaPrice.innerText = handOutputPrice.toString();

                        var handOutputDistribution = "";
                        if (tepsList[3] == "Z") {
                            handOutputDistribution = "0_0_0_0_0";
                        } else {
                            handOutputDistribution = tepsList[3];
                        }

                        var handOutputDistributionList = handOutputDistribution.split("_")
                        document.getElementById("resultAreaStoc1").innerText = stocDist[0].toUpperCase() + " : " + handOutputDistributionList[0];
                        // document.getElementById("resultAreaStoc2").innerText = stocDist[1].toUpperCase() + " : " + handOutputDistributionList[1];
                        document.getElementById("resultAreaStoc3").innerText = stocDist[2].toUpperCase() + " : " + handOutputDistributionList[1];
                        // document.getElementById("resultAreaStoc4").innerText = stocDist[3].toUpperCase() + + " : " + handOutputDistributionList[3];
                        var totalQty = Number(handOutputDistributionList[0]) + Number(handOutputDistributionList[1]);
                        // var totalQty = Number(handOutputDistributionList[0]) + Number(handOutputDistributionList[1]) + Number(handOutputDistributionList[2]);
                        document.getElementById("resultAreaStoc5").innerText = stocDist[4].toUpperCase() + " : " + totalQty;
                    }
                    document.getElementById("counterOContainer").innerText = "o{" + counterO + "}";
                    document.getElementById("counterXContainer").innerText = "x{" + counterX + "}";
                }
            }
        }
    </script>

</body>

</html>