function openWindow(url, windowName, width, height) {

    var ah = screen.availHeight;
    var aw = screen.availWidth;

    var ph = ah / 2 - (height / 2);
    var pw = aw / 2 - (width / 2);

    var popup = window.open(url, windowName, 'modal=yes,width=' + width + ',height=' + height + ',status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,left=' + pw + ',top=' + ph);
    popup.focus();
}

function confirmRemove(url) {
    if (confirm("Are you sure?")) {
        window.location = url;
    }
}

function populateFilename(fromField, toField) {
   
    var indexOfSlash = fromField.value.lastIndexOf("/");
    if (indexOfSlash < 0) {
        indexOfSlash = fromField.value.lastIndexOf("\\");
    }
    if (indexOfSlash < 0) {
        indexOfSlash = 0;
    }

    toField.value = fromField.value.substring(indexOfSlash + 1, fromField.value.length);
}

/**
 * @params - instances of elemenets with type <input type="text">
 * isNotBlankFields([element1] [,element2] [,element3] ... )
 */
function isNotBlankFields() {
    for (var i = 0; i < isNotBlankFields.arguments.length; i++) {
        if (isNotBlankFields.arguments[i].value.length == 0) {
            return false;
        }
    }
    return true;
}

function checkAll(checkboxes) {
    if (!checkboxes.length) {
        checkboxes.checked = true;
    } else {
        for (var i = 0; i < checkboxes.length; i++) {
            checkboxes[i].checked = true;
        }
    }
}

function uncheckAll(checkboxes) {
    if (!checkboxes.length) {
        checkboxes.checked = false;
    } else {
        for (var i = 0; i < checkboxes.length; i++) {
            checkboxes[i].checked = false;
        }
    }
}

function toggleVisibility(elementId) {
    var element = document.getElementById(elementId);
    if (element.style.display == 'none') {
        element.style.display = 'block';
    } else {
        element.style.display = 'none';
    }
}

window.textbox_set_value = function(elementId, value) {
    var oTextBox = document.getElementById(elementId);
    if (oTextBox != null) {
        oTextBox.value = value;
    }
}
