verifyCTCJSVersion("1.1.1");

function requestCollectionChangeStatus(collection_id) {

    if (!dialog || dialog == null) {
        var dialogEvents = new wow.Event({
            onInit: function(event) {
                var viewport = wow.getViewportSize();
                var cont = document.getElementById("shadow_container");
                cont.style.height = (viewport.height - 100) + "px";
                var cont_pos = wow.computeObjectPosition(cont, false);
                var list = document.getElementById("collection_card_box_list");
                var list_pos = wow.computeObjectPosition(list, false);
                list.style.height = (cont.offsetHeight + cont_pos.y - list_pos.y - 40) + "px";
            },
            onUpdate: function(event) {
                var viewport = wow.getViewportSize();
                var cont = document.getElementById("shadow_container");
                cont.style.height = (viewport.height - 100) + "px";
                var cont_pos = wow.computeObjectPosition(cont, false);
                var list = document.getElementById("collection_card_box_list");
                var list_pos = wow.computeObjectPosition(list, false);
                list.style.height = (cont.offsetHeight + cont_pos.y - list_pos.y - 40) + "px";
            },
            onClose: function(event) {
                dialog.destroy();
                dialog = null;
                document.location = document.location;
            }
        });
        dialog = new wow.WDialog.Dialog("dialog_box");
        dialog.addEventListener(dialogEvents);
    }

    return !dialog.open("/ajax/collection_change_status.php?collection_id=" + collection_id);

    return false;
}

function ajaxCollectionChangeStatus(action) {

    var frm = document.getElementById("form_data");
    if (frm) {
        var collection_id = frm["collection_id"].value;
        var status = wow.getRadioValue(frm["status"], null);
        var uri = '/ajax/collection_change_status.php?' + (action ? 'action=' + action : '') +
                                                    '&collection_id=' + collection_id +
                                                    '&status=' + status;
        return !dialog.update(uri, true);
    }

    return false;
}

function requestCollectionFaults(collection_id) {

    if (!dialog || dialog == null) {
        var dialogEvents = new wow.Event({
            onInit: function(event) {
                var viewport = wow.getViewportSize();
                var cont = document.getElementById("shadow_container");
                cont.style.height = (viewport.height - 100) + "px";
                var cont_pos = wow.computeObjectPosition(cont, false);
                var list = document.getElementById("collection_card_box_list");
                var list_pos = wow.computeObjectPosition(list, false);
                list.style.height = (cont.offsetHeight + cont_pos.y - list_pos.y - 40) + "px";
            },
            onUpdate: function(event) {
                var viewport = wow.getViewportSize();
                var cont = document.getElementById("shadow_container");
                cont.style.height = (viewport.height - 100) + "px";
                var cont_pos = wow.computeObjectPosition(cont, false);
                var list = document.getElementById("collection_card_box_list");
                var list_pos = wow.computeObjectPosition(list, false);
                list.style.height = (cont.offsetHeight + cont_pos.y - list_pos.y - 40) + "px";
            },
            onClose: function(event) {
                dialog.destroy();
                dialog = null;
            }
        });
        dialog = new wow.WDialog.Dialog("dialog_box");
        dialog.addEventListener(dialogEvents);
    }

    return !dialog.open("/ajax/collection_faults.php?collection_id=" + collection_id);

    return false;
}

function ajaxCollectionFaults(page, action) {

    var frm = document.getElementById("form_data");
    if (frm) {
        var collection_id = frm["collection_id"].value;
        var album_section_id = frm["album_section_id"] ? frm["album_section_id"].value : -1;
        var search_string = frm["search_string"].value;
        var edition = frm["edition"] ? frm["edition"].value : -1;
        var uri = '/ajax/collection_faults.php?' + 'collection_id=' + collection_id +
                                                   '&p=' + page +
                                                   (action ? 'action=' + action : '') +
                                                   '&album_section_id=' + album_section_id +
                                                   '&search_string=' + escape(search_string) +
                                                   '&edition=' + edition;
        return !dialog.update(uri, true);
    }

    return false;
}

