function open_close(element){

    if (typeof(element) != "object"){
        elements = document.getElementsByClassName(element)
        if (elements)
            element = elements[0]
    }

    var pNode = element.parentNode
    for(var i = 0; i < pNode.childNodes.length; i++){
        var node = pNode.childNodes[i]
        if(node != undefined
           && (typeof(node.setAttribute) == "function"
               || typeof(node.setAttribute) == "object"
               )
           && node != element
           && node.className != "container-block"){
            if(node.style.display == "block"){
                node.style.display = "none"
            }else {
                node.style.display = "block"
            }

        }
    }
}


function enable_disable_newsletter_checks(idsubsciber)
{
	statuscheck = document.getElementById("subscribers[" + idsubsciber + "][active]")
	nlchecks = document.getElementsByClassName("nlcheck_" + idsubsciber)
	for (i = 0; i < nlchecks.length; i++)
	{
		nlchecks[i].disabled = !statuscheck.checked
	}
}


function resource_select(element) {
    var rescode = document.getElementById("resource_code_s");
    var rescode2 = document.getElementById("resource_code");
    rescode.value = element.textContent;
    rescode2.value = element.textContent;
    return false;
}

function resolve_macro(form){
    var aj = new Ajax.Updater("macroresult", $(form).action, { parameters: $(form).serialize()} );
    ReosurceInsertionDialog.insert();
    return false;
}

var ReosurceInsertionDialog = {
    init : function() {
        //var f = $('resource_insertion_form');
        // Get the selected contents as text and place it in the input
        //alert(tinyMCEPopup.editor.selection.getContent({format : 'html'}));
        var elem = $(tinyMCEPopup.editor.selection.getNode());
        alert(elem)
        alert(elem.up());
    },

    insert : function() {
        alert("inserisco: " + $('macroresult').innerHTML + "<span></span>")
        // Insert the contents from the input into the document
        tinyMCEPopup.editor.execCommand('mceInsertRawHTML', false, $('macroresult').innerHTML + "<span></span>");
        tinyMCEPopup.close();
    }
}

function init_resource_dialog(){
    tinyMCEPopup.requireLangPack();
    tinyMCEPopup.onInit.add(ReosurceInsertionDialog.init, ReosurceInsertionDialog);
}