DynamicActions = {
    update: function(path) {
        if (DynamicActionResponder) {

            var s = new Array();
            for (var i = 0; i < document.getElementById("list").elements.length; i++) {
                var e = document.getElementById("list").elements[i];
                if (e.type == "checkbox" && e.name != "check_all" && e.name != "live") {
                    if (e.checked && e.id && e.id.indexOf("row") == 0) {
                        var num = e.id.substring("row".length, e.id.length);
                        s[s.length] = document.getElementById("list")["path" + num].value;
                    }
                }
            }

            DynamicActionResponder.getActions(path, s, DynamicActions._updateActions);
        }
    },

    execute: function(action, params, inputs, enctype) {
        var list = document.getElementById("list");

        list.returnaction.value = list.action.value;
        list.returnactionparams.value = list.actionparams.value;
        list.actionpage.value = list.page.value;

        if (params) {
            for (var i = 0; i < params.length; i++) {
                var name = params[i][0];
                var value = params[i][1];

                if (!list[name]) {
                    var h = list.ownerDocument.createElement("input");
                    h.setAttribute("type", "hidden");
                    h.setAttribute("name", name);
                    h.setAttribute("value", value);
                    list.appendChild(h);
                }
            }
        }

        if (inputs) {
            for (var i = 0; i < inputs.length; i++) {
                var name = inputs[i];
                var value = DynamicActions.getFieldValue(name);

                if (!list[name]) {
                    var h = list.ownerDocument.createElement("input");
                    h.setAttribute("type", "hidden");
                    h.setAttribute("name", name);
                    h.setAttribute("value", value);
                    list.appendChild(h);
                }
            }
        }

        if (enctype) {
            list.encoding = enctype;
            // hidden Feld "action" entfernen, da IE nicht zwischen
            // Form-Attribiute "action" und hidden Feld "action" unterscheidet
            list.removeChild(list.action);
            var a = list.getAttribute("action") + "?action=" + action;
            list.setAttribute("action", a);
            document.forms[0].action = a;
        } else {
            list.action.value = action;
        }

        if (self.dialog) {
            Windows.closeAll();
            setTimeout("document.getElementById('list').submit();", 700);
        } else {
            list.submit();
        }
    },

    selectAll : function (flag, path) {
        for (var i = 0; i < document.getElementById("list").elements.length; i++) {
            var e = document.getElementById("list").elements[i];
            if (e.type == "checkbox" && e.name.indexOf("row") == 0) {
                e.checked = flag;
            }
        }

        DynamicActions.update(path);
    },

    getFieldValue: function(name) {
        var element = document.getElementById(name);
        // find element by name "name" if no element with id "name" was found
        if (element == null) {
            var elements = document.getElementsByName(name);
            if (elements.length > 0 && elements[0].type == 'radio') {
                element = elements[0];
            }
        }

        var value;
        if (element.type == "radio") {
            var values = document.getElementsByName(name);
            for (var j = 0; j < values.length; j++) {
                if (values[j].checked) {
                    value = values[j].value;
                    break;
                }
            }
        } else if (element.type == "checkbox") {
            value = element.checked;
        } else if (element.nodeName == "select") {
            value = element.options[element.selectedIndex].value;
        } else {
            value = element.value;
        }
        return value;
    },

    toggle: function(id) {
        var s = document.getElementById(id).style;
        var d = s.display;
        if (d == 'none') {
            s.display = 'block';
        } else {
            s.display = 'none';
        }
    },

    hide: function() {
        if (document.actionId) {
            var s = document.getElementById(document.actionId).style;
            s.display = 'none';
            document.actionId = undefined;
        }
    },

    show: function(id) {
        if (document.actionId != id) {
            document.showActionId = id;
            if (document.hideTimeout) {
                clearTimeout(document.hideTimeout);
                document.hideTimeout = undefined;
            }
            if (document.showTimeout) {
                clearTimeout(document.showTimeout);
                document.showTimeout = undefined;
            }
            DynamicActions.hide();
            document.showTimeout = setTimeout("DynamicActions._show('" + id + "')", 500)
        }
    },

    cancelshow: function(id) {
        if (document.showActionId == id) {
            clearTimeout(document.showTimeout);
            document.showTimeout = undefined;
            document.showActionId = undefined;
        }
    },

    _show: function(id) {
        var s = document.getElementById(id).style;
        s.display = 'block';
        document.actionId = id;
        document.showActionId = undefined;
        document.hideTimeout = setTimeout("DynamicActions.hide()", 3000)
    },

    _updateActions: function(data) {
        for (var i = 0; i < data.length; i++) {

            var a = data[i];
            var type = a['type'];

            if (type == "javascript") {
                eval(a['script']);
            } else {
                var id = a['id'];
                var html = a['html'];

                var node = $(id);
                if (node) {
                    var parent = node.parentNode;
                    var dummy = document.createElement("div");
                    dummy.innerHTML = html;
                    parent.replaceChild(dummy.firstChild, node);

                    node = $(id);
                    if (!node.hasChildNodes()) {
                        parent.style.display = 'none';
                    }
                }
            }
        }
    },

    _getParentByTagName: function(node, name) {

        var p = node.parentNode;
        while (p != null && p.tagName.toLowerCase() != name) {
            p = p.parentNode;
        }

        return p;
    },

    _getParentByClassName: function(node, className) {

        var p = node.parentNode;
        while (p != null && p.className != className) {
            p = p.parentNode;
        }

        return p;
    }
}

function select(id) {
    DynamicActions.selectAll(false);
    var a = document.getElementsByTagName("a");
    var link;
    for (var i = 0; i < a.length; i++) {
        if (decodeURI(a[i].href).indexOf("javascript:select('" + id + "')") == 0) {
            link = a[i];
            break;
        }
    }

    var tr;
    var p = link.parentNode;
    while (p != null) {
        if (p.tagName.toLowerCase() == "tr") {
            tr = p;
            break;
        }
        p = p.parentNode;
    }

    var ins = tr.getElementsByTagName("input");
    for (var i = 0; i < ins.length; i++) {
        if (ins[i].type == 'checkbox') {
            ins[i].checked = true;
            break;
        }
    }
}



