        function checkIntegerInput(sId) {
            var el = document.getElementById(sId);
            var val = parseInt(el.value);
            if (val.toString() != el.value || val > 1000) {
                el.style.backgroundColor = 'rgb(240,128,128)';
                el.focus();
                // alert("Введено не целое числ или число больше 1000");
                return false;
            }
            else {
                el.style.backgroundColor = 'rgb(144,238,144)';
                return true;
            }
        }

        function checkSelectInput(sId) {
            var el = document.getElementById(sId);
            var val = el.selectedIndex;
            if (val == 0) {
                el.style.backgroundColor = 'rgb(240,128,128)';
                el.focus();
                //alert("Продукт не выбран");
                return false;                
            }
            else {
                el.style.backgroundColor = 'rgb(144,238,144)';
                return true;                
            }
        }

        function calc() {
            var elResult        = document.getElementById("inputResult");
            var elAmountOS      = document.getElementById("inputAmountOS");
            var elAmountOffice  = document.getElementById("inputAmountOffice");
            
            var elProduct = document.getElementById("selectProducts");
            var elOfficeProduct = document.getElementById("selectOfficeProducts");

            if (checkIntegerInput("inputAmountOS") && checkIntegerInput("inputAmountOffice") && checkSelectInput("selectProducts") && checkSelectInput("selectOfficeProducts")) {
                elResult.value =
                    CurrencyFormatted(parseFloat(elAmountOS.value) * parseFloat(elProduct.options[elProduct.selectedIndex].value) 
                    + parseFloat(elAmountOffice.value) * parseFloat(elOfficeProduct.options[elOfficeProduct.selectedIndex].value));
            }
            else
                elResult.value = "";
        }

        function CurrencyFormatted(amount) {
            var i = parseFloat(amount);
            if (isNaN(i)) { i = 0.00; }
            var minus = '';
            if (i < 0) { minus = '-'; }
            i = Math.abs(i);
            i = parseInt((i + .005) * 100);
            i = i / 100;
            s = new String(i);
            if (s.indexOf('.') < 0) { s += '.00'; }
            if (s.indexOf('.') == (s.length - 2)) { s += '0'; }
            s = minus + s;
            return s;
        }
        

