﻿//************************* Messages utils ************************

// Search are there some objects checked and confirm deleting
// objectsBlock - element in which objects are placed
function ConfirmDeleting(objectsBlock) {
    var inputs = GetAllInputs(objectsBlock);
    for (var i in inputs) {
        if (inputs[i].type == 'checkbox' && inputs[i].checked)
            return confirm('Are you sure you want to delete selected objects?')
    }
    return false;
}

// Check/uncheck all checkboxes in 
function CheckAll(block, mainCheckBox) {
    var inputs = GetAllInputs(block);
    for (var i in inputs) {
        if (inputs[i].type == 'checkbox')
            inputs[i].checked = mainCheckBox.checked;
    }
}

// Get all inputs in specified html-block
function GetAllInputs(block) {
    var msgTableDiv = document.getElementById(block);
    var checkboxes = msgTableDiv.getElementsByTagName('input');
    return checkboxes;
}

function IsNullOrEmpty(text) {
    if ((text == null) || (text == '')) {
        return true;
    }
    var array = text.split("");
    for (var index in array) {
        if ((array[index] != null) && (array[index] != "") && (array[index] != " ")) {
            return false;
        }
    }
    return true;
}

function NoteTextChanged_Handler(noteTextBox, submitButton) {
    if (IsNullOrEmpty(noteTextBox.value)) {
        submitButton.disabled = 'disabled';
    }
    else {
        submitButton.disabled = '';
    }
}