// To use this script organizationId and publicFolderUri variables should be predefined and initialized.  
var rom_orgMode = null;
var rom_showRoot = null;
function rom_init() {
    rom_orgMode = organizationId != null && organizationId != "";
    rom_showRoot = !rom_orgMode;
}
var rom_repositoryModifier = function (rootObj) {
    var updatedRootObj;
    if (rom_orgMode && rootObj.children != null) {
        var publicFolder;
        var ch = rootObj.children;
        var newCh = [];
        for (var i=0; i<ch.length; i++) {
            if (ch[i].uri == publicFolderUri) {
                publicFolder = ch[i];
            } else {
                newCh.push(ch[i]);
            }
        }
        rootObj.children = newCh;

        updatedRootObj = {type:'superroot',label:'',extra:{}};
        updatedRootObj.children = [rootObj, publicFolder];
    } else {
        updatedRootObj = rootObj;
    }

    return updatedRootObj;
}
var rom_findNodeChildByMetaName = function(node, name) {
    if (node.param && node.param.type == 'superroot') {
        var publicNode;
        var rootNode;
        if (node.childs[0].param.id == 'public') {
            publicNode = node.childs[0];
            rootNode = node.childs[1];
        } else {
            publicNode = node.childs[1];
            rootNode = node.childs[0];
        }

        if (name == 'public') {
            return publicNode;
        } else {
            node = rootNode;
        }
    }
    if (node.hasChilds()) {
        for (var i = 0; i < node.childs.length; i++) {
            if (node.childs[i].param.id == name) {
                return node.childs[i];
            }
        }
    }
    return null;
}
