/* Minification failed. Returning unminified contents.
(1,10): run-time error CSS1031: Expected selector, found 'clearNotify('
(1,10): run-time error CSS1025: Expected comma or open brace, found 'clearNotify('
(5,10): run-time error CSS1031: Expected selector, found 'clearInfo('
(5,10): run-time error CSS1025: Expected comma or open brace, found 'clearInfo('
(20,10): run-time error CSS1031: Expected selector, found 'pageNotify('
(20,10): run-time error CSS1025: Expected comma or open brace, found 'pageNotify('
(33,10): run-time error CSS1031: Expected selector, found 'checkStringField('
(33,10): run-time error CSS1025: Expected comma or open brace, found 'checkStringField('
(40,10): run-time error CSS1031: Expected selector, found 'checkInt('
(40,10): run-time error CSS1025: Expected comma or open brace, found 'checkInt('
(53,10): run-time error CSS1031: Expected selector, found 'checkFloat('
(53,10): run-time error CSS1025: Expected comma or open brace, found 'checkFloat('
(64,10): run-time error CSS1031: Expected selector, found 'checkEmail('
(64,10): run-time error CSS1025: Expected comma or open brace, found 'checkEmail('
(72,10): run-time error CSS1031: Expected selector, found 'loadingOverlayManager('
(72,10): run-time error CSS1025: Expected comma or open brace, found 'loadingOverlayManager('
(76,8): run-time error CSS1030: Expected identifier, found 'addEventListener('
(76,8): run-time error CSS1031: Expected selector, found 'addEventListener('
(76,8): run-time error CSS1025: Expected comma or open brace, found 'addEventListener('
(78,2): run-time error CSS1019: Unexpected token, found ','
(78,9): run-time error CSS1031: Expected selector, found ')'
(78,9): run-time error CSS1025: Expected comma or open brace, found ')'
(79,8): run-time error CSS1030: Expected identifier, found 'addEventListener('
(79,8): run-time error CSS1031: Expected selector, found 'addEventListener('
(79,8): run-time error CSS1025: Expected comma or open brace, found 'addEventListener('
(81,2): run-time error CSS1019: Unexpected token, found ','
(81,9): run-time error CSS1031: Expected selector, found ')'
(81,9): run-time error CSS1025: Expected comma or open brace, found ')'
(83,1): run-time error CSS1019: Unexpected token, found '$'
(83,2): run-time error CSS1019: Unexpected token, found '('
(83,11): run-time error CSS1031: Expected selector, found ')'
(83,11): run-time error CSS1025: Expected comma or open brace, found ')'
(87,2): run-time error CSS1019: Unexpected token, found ')'
(90,1): run-time error CSS1019: Unexpected token, found '$'
(90,2): run-time error CSS1019: Unexpected token, found '('
(90,11): run-time error CSS1031: Expected selector, found ')'
(90,11): run-time error CSS1025: Expected comma or open brace, found ')'
(92,2): run-time error CSS1019: Unexpected token, found ')'
(122,10): run-time error CSS1031: Expected selector, found 'createModal('
(122,10): run-time error CSS1025: Expected comma or open brace, found 'createModal('
 */
function clearNotify() {
    $("#notifications").html("");
};

function clearInfo() {
    $(".alert-success").each(function (index) {
        $(this).fadeTo(5000, 500).slideUp(500, function () {
            this.remove();
        });
    });
    $(".alert-info").fadeTo(10000, 500).slideUp(500, function () {
        $(".alert-info").each(function (index) {
            $(this).fadeTo(10000, 500).slideUp(500, function () {
                this.remove();
            });
        });
    });
};

function pageNotify(msg, type = "success",) {
    note = "<div class='alert alert-";
    note += type;
    note += " alert-dismissible'><a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a>";
    note += msg;
    note += "</div>";
    $("#notifications").append(note);
    if (type == "info" || type == "success") {
        clearInfo();
    }
    window.scrollTo(0, 0);
};

function checkStringField(field, len = 3, max = 0) {
    if ((typeof field === 'string' || field instanceof String) && field.length >= len && (field.length <= max || max == 0)) {
        return true;
    }
    return false;
};

function checkInt(field, min = 0, max = 0) {
    if (!typeof field === "string" && !field instanceof String) {
        return false;
    }
    tempInt = parseInt(field)
    if (isNaN(tempInt)) {
        return false;
    }
    if ((tempInt > max && max > 0) || tempInt < min) {
        return false;
    }
    return true
};
function checkFloat(field) {
    if (!typeof field === "string" && !field instanceof String) {
        return false;
    }
    tempFloat = parseFloat(field)
    if (isNaN(tempFloat)) {
        return false;
    }
    return true
};

function checkEmail(field, len = 3) {
    if ((typeof field === 'string' || field instanceof String) && field.length >= len && field.match("[a-zA-Z0-9!#$%&'*+\-/=?^_`{|]{1,64}@[a-zA-Z0-9\-.]{1,253}\.[a-z]{2,5}")) {
        return true;
    }
    return false;
};

// LoadingOverlay START
function loadingOverlayManager(){
    $.LoadingOverlay("hide");
};

window.addEventListener("load", function () {
    setTimeout(function () { loadingOverlayManager() }, 120);
}, false);
window.addEventListener("unload", function () {
    setTimeout(function () { loadingOverlayManager() }, 120);
}, false);

$(document).ready(function (event) {
    $(".navigate-overlay").bind("click", function (event) {
        $.LoadingOverlay("show");
    });
});
// LoadingOverlay END

$(document).ready(function () {
    clearInfo();
});
/*
<div class="modal fade" id="submitPopup" style="display: none;" role="dialog" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h3 class="modal-title"><strong>Submit Stock Adjustments</strong></h3>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-sm-12" style="text-align: justify">
                        Are you sure you would like to <b>submit</b> stock take?
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <div class="row">
                    <div class="col-xs-6 text-left">
                        <button id="submitmodalAccept" class="btn btn-primary" onclick="SubmitStaged()">Yes</button>
                    </div>
                    <div class="col-xs-6">
                        <button class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
*/
function createModal(id, header, body, footer_left = '', footer_right = '<button class="btn btn-secondary" data-dismiss="modal">Cancel</button>') {

    let modalContainer = $('<div></div>').addClass('modal').addClass('fade').prop('id', id).prop('role', 'dialog').data('backdrop', 'static');
    let modal = $('<div></div>').addClass('modal-dialog');
    let modalContent = $('<div></div>').addClass('modal-content');

    let modalHeader = $('<div></div>').addClass('modal-header')
        .append('<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>')
        .append(
            $('<h3></h3>').addClass('modal-title').append($('<strong></strong>').html(header))
        );
    modalContent.append(modalHeader);

    let modalBody = $('<div></div>').addClass('modal-body').append(body);
    modalContent.append(modalBody);

    let modalFooter = $('<div></div>').addClass('modal-footer').append(
        $('<div></div>').addClass('row').append(
            $('<div></div>').addClass('col-xs-6').addClass('text-left').html(footer_left)
        ).append(
            $('<div></div>').addClass('col-xs-6').html(footer_right)
        )
    );
    modalContent.append(modalFooter);

    modal.append(modalContent);
    modalContainer.append(modal);
    $('body').append(modalContainer)
    return modalContainer;
}
