/*
 * Copyright 2002-2006 Jahia Ltd
 *
 * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (JCDDL),
 * Version 1.0 (the "License"), or (at your option) any later version; you may
 * not use this file except in compliance with the License. You should have
 * received a copy of the License along with this program; if not, you may obtain
 * a copy of the License at
 *
 *  http://www.jahia.org/license/
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * Utility and Property class for the ComplexTreeDisplay. Basically, the developer should only need to change configuration
 * settings in this file.
 */
function ComplexTreeProperties(style, treePattern, listPattern, xmlTagName, entryPointURL,
                               expandServerUrl, collapseServerUrl, expandServerUrlLoaded, treeDiv) {
    this.CURRENT_STYLE = style;
    this.CURRENT_TREE_PATTERN = treePattern;
    this.CURRENT_LIST_PATTERN = listPattern;
    this.CURRENT_XML_TAG_NAME = xmlTagName;
    this.ENTRY_POINT_URL = entryPointURL;
    this.EXPAND_SERVER_URL = expandServerUrl;
    this.EXPAND_SERVER_URL_LOADED = expandServerUrlLoaded;
    this.COLLAPSE_SERVER_URL = collapseServerUrl;
    this.TREE_DIV = treeDiv;
}

ComplexTreeProperties.extention = ["doc", "xls", "ppt", "zip", "pdf", "txt", "html","htm", "wav", "mp3",
        "bmp", "jpg", "jpeg", "gif", "png", "tif", "tiff", "avi", "mpeg", "mpa", "mpg", "mpe", "mov",
        "exe","text", "rar", "tgz"];

ComplexTreeProperties.picto = ["doc", "xls", "ppt", "zip", "pdf", "txt", "html", "html", "sound", "sound",
        "img", "img", "img", "img", "img", "img", "img", "video", "video", "video", "video","video", "video",
        "exe", "txt", "rar", "zip"];

// Properties used only in ComplexTreeDisplay.js for UI looks
ComplexTreeProperties.LOADING_ID = -1;
ComplexTreeProperties.ROW_HEIGHT = (AjxEnv.isIE ? 27 : 28);
ComplexTreeProperties.SHELL_HEIGHT = 320;
ComplexTreeProperties.MIN_TREE_WIDTH = 200;
ComplexTreeProperties.MAX_DATA_HEIGHT = 550;
ComplexTreeProperties.TREE_WIDTH = 250;
ComplexTreeProperties.SASH_HEIGHT = 24;
ComplexTreeProperties.RESIZE = 50;
ComplexTreeProperties.EXPANDALL_LEVEL = 3;
ComplexTreeProperties.MAX_RETRIEVED_OBJECTS_EXPAND_ALL = 50;
ComplexTreeProperties.RELOAD_ON_COLLAPSE = false;
ComplexTreeProperties.CONTINUE_IF_EMPTY = false;

// The following values are coupled with the values kept in class org.jahia.services.version.EntryLoadRequest
// State of an object language
ComplexTreeProperties.DELETED_WORKFLOW_STATE = -2;
ComplexTreeProperties.ACTIVE_WORKFLOW_STATE = 1;
ComplexTreeProperties.STAGING_WORKFLOW_STATE = 2;
ComplexTreeProperties.WAITING_WORKFLOW_STATE = 3;
// State of an object as a whole
ComplexTreeProperties.LOCKED_STATE = 4;
ComplexTreeProperties.WARNINGS_STATE = 5;
ComplexTreeProperties.ERRORS_STATE = 6;
ComplexTreeProperties.PARTIAL_WARNINGS_STATE = 26;
// WorkFlow states
ComplexTreeProperties.STANDARD_STATE = 7;
ComplexTreeProperties.N_STEP_STATE = 8;
ComplexTreeProperties.NO_WFLOW_STATE = 9;
ComplexTreeProperties.LINKED_WFLOW_STATE = 26;
// SiteMap State && filemanger selected file
ComplexTreeProperties.EXISTING_STATE = 10;
// Versionning states
ComplexTreeProperties.SELECT_SUB_TREE = 11;
ComplexTreeProperties.UNSELECT_SUB_TREE = 12;
// FileManager images
ComplexTreeProperties.INFO = 13;
ComplexTreeProperties.PROPS = 14;
ComplexTreeProperties.IE_FOLDER = 15;
// Category images
ComplexTreeProperties.ADD_CATEGORY = 16;
ComplexTreeProperties.EDIT_CATEGORY = 17;
ComplexTreeProperties.MOVE_CATEGORY = 18;
ComplexTreeProperties.DELETE_CATEGORY = 19;

// Time based publishing states
ComplexTreeProperties.EXPIRED_BUT_WILL_BECOME_VALID = 20;
ComplexTreeProperties.EXPIRED = 21;
ComplexTreeProperties.VALID_BUT_WILL_EXPIRE = 22;
ComplexTreeProperties.VALID = 23;
ComplexTreeProperties.NOT_VALID_BUT_WILL_BECOME_VALID = 24;
ComplexTreeProperties.UNKNOWN = 25;

// Define the state images. Don't forget to append the contextPath to the icone source paths
ComplexTreeProperties.WORKFLOW_ICONS_PATH = "/jsp/jahia/engines/images/icons/workflow/";
ComplexTreeProperties.ACTIVE_ICONE_SRC = "/jsp/jahia/engines/images/icons/workflow/state_active.gif";
ComplexTreeProperties.WAITING_ICONE_SRC = "/jsp/jahia/engines/images/icons/workflow/state_waiting.gif";
ComplexTreeProperties.EDIT_ICONE_SRC = "/jsp/jahia/engines/images/icons/workflow/state_edit.gif";
ComplexTreeProperties.DELETED_ICONE_SRC = "/jsp/jahia/engines/images/icons/workflow/state_deleted.gif";
ComplexTreeProperties.ACCEPT_ICONE_SRC = "/jsp/jahia/engines/images/icons/workflow/accept.gif";
ComplexTreeProperties.REFUSE_ICONE_SRC = "/jsp/jahia/engines/images/icons/workflow/refuse.gif";
ComplexTreeProperties.LOCKED_ICONE_SRC = "/jsp/jahia/engines/images/icons/locked.gif";
ComplexTreeProperties.WARNINGS_ICONE_SRC = "/jsp/jahia/engines/images/icons/workflow/warnings.gif";
ComplexTreeProperties.PARTIAL_WARNINGS_ICONE_SRC = "/jsp/jahia/engines/images/icons/workflow/partial_warnings.gif";
ComplexTreeProperties.ERRORS_ICONE_SRC = "/jsp/jahia/engines/images/icons/workflow/errors.gif";
ComplexTreeProperties.EMPTY_SRC = "/jsp/jahia/javascript/zimbra/complexTree/empty.gif";
ComplexTreeProperties.PIX_SRC = "/jsp/jahia/javascript/zimbra/complexTree/pix.gif";
ComplexTreeProperties.IE_FOLDER_SRC = "/jsp/jahia/javascript/zimbra/complexTree/IEFolder.gif";

// Define action images. Don't forget to append the contextPath to the icone source paths
ComplexTreeProperties.UPDATE_ICONE_SRC = "/jsp/jahia/engines/images/actions/update.gif";
ComplexTreeProperties.DELETE_ICONE_SRC = "/jsp/jahia/engines/images/actions/delete.gif";

// Workflow type images
ComplexTreeProperties.STANDARD = "/jsp/jahia/javascript/zimbra/complexTree/jgear.gif";
ComplexTreeProperties.N_STEP = "/jsp/jahia/javascript/zimbra/complexTree/ngear.gif";
ComplexTreeProperties.NO_WFLOW = "/jsp/jahia/javascript/zimbra/complexTree/gear_forbidden.gif";
ComplexTreeProperties.LINKED = "/jsp/jahia/javascript/zimbra/complexTree/lgear.gif";

// Time based publishing images
ComplexTreeProperties.EXPIRED_BUT_WILL_BECOME_VALID_SRC = "/jsp/jahia/engines/images/icons/timebasedpublishing/yellow_clock.gif";
ComplexTreeProperties.EXPIRED_SRC = "/jsp/jahia/engines/images/icons/timebasedpublishing/red_clock.gif";
ComplexTreeProperties.VALID_BUT_WILL_EXPIRE_SRC = "/jsp/jahia/engines/images/icons/timebasedpublishing/orange_clock.gif";
ComplexTreeProperties.VALID_SRC = "/jsp/jahia/engines/images/icons/timebasedpublishing/valid_clock.gif";
ComplexTreeProperties.NOT_VALID_BUT_WILL_BECOME_VALID_SRC = "/jsp/jahia/engines/images/icons/timebasedpublishing/yellow_clock.gif";
ComplexTreeProperties.UNKNOWN_SRC = "/jsp/jahia/engines/images/icons/timebasedpublishing/grey_clock.gif";


// SiteMap
ComplexTreeProperties.EXISTING = "/jsp/jahia/javascript/zimbra/complexTree/check.gif";

// WEBDAV
ComplexTreeProperties.FILE_SRC = "/jsp/jahia/javascript/zimbra/complexTree/img.gif";
ComplexTreeProperties.FOLDER_SRC = "/jsp/jahia/javascript/zimbra/complexTree/folder.gif";
ComplexTreeProperties.COMPUTER_SRC = "/jsp/jahia/javascript/zimbra/complexTree/computer.gif";

// FILEMANAGER
ComplexTreeProperties.INFO_SRC = "/jsp/jahia/engines/images/about.gif";
ComplexTreeProperties.PROPS_SRC = "/jsp/jahia/engines/images/preferences.gif";

// CATEGORY ADMIN
ComplexTreeProperties.ADD_CATEGORY_SRC = "/jsp/jahia/javascript/zimbra/complexTree/add.gif";
ComplexTreeProperties.EDIT_CATEGORY_SRC = "/jsp/jahia/javascript/zimbra/complexTree/edit.gif";
ComplexTreeProperties.MOVE_CATEGORY_SRC = "/jsp/jahia/javascript/zimbra/complexTree/move.gif";
ComplexTreeProperties.DELETE_CATEGORY_SRC = "/jsp/jahia/javascript/zimbra/complexTree/delete.gif";

//CATEGORY PORLTET
ComplexTreeProperties.PORTLET_CATEGORY_ALLSOURCES_SRC = "/jsp/jahia/javascript/zimbra/complexTree/allsources.png";

// Define types of data/html components that can be used in the ComplexTreeDisplay
//
// For the list view and the tree
ComplexTreeProperties.I = 0;
ComplexTreeProperties.W_FLOW_CHECKBOXES = ComplexTreeProperties.I++;
ComplexTreeProperties.W_FLOW_TYPE = ComplexTreeProperties.I++;
ComplexTreeProperties.W_FLOW_IMAGES = ComplexTreeProperties.I++;
ComplexTreeProperties.VERSIONNING_CHECKBOX = ComplexTreeProperties.I++;
ComplexTreeProperties.IMAGE = ComplexTreeProperties.I++;
ComplexTreeProperties.IMAGE_LINK = ComplexTreeProperties.I++;
ComplexTreeProperties.BLANK = ComplexTreeProperties.I++;
ComplexTreeProperties.IMAGE_LINK_SAME_PAGE = ComplexTreeProperties.I++;
ComplexTreeProperties.LINK = ComplexTreeProperties.I++;
ComplexTreeProperties.LINK_SAME_PAGE = ComplexTreeProperties.I++;
ComplexTreeProperties.LINK_FCK = ComplexTreeProperties.I++;
ComplexTreeProperties.ID = ComplexTreeProperties.I++;
ComplexTreeProperties.SELECT_RADIO = ComplexTreeProperties.I++;
ComplexTreeProperties.KEY = ComplexTreeProperties.I++;
ComplexTreeProperties.SPACE = ComplexTreeProperties.I++;
ComplexTreeProperties.VERSIONNING_IMAGES = ComplexTreeProperties.I++;
ComplexTreeProperties.FILE_IMAGE = ComplexTreeProperties.I++;
ComplexTreeProperties.FILEMANAGER_CHECKBOX = ComplexTreeProperties.I++;
ComplexTreeProperties.FILEMANAGER_IMAGES = ComplexTreeProperties.I++;
ComplexTreeProperties.FILESIZE = ComplexTreeProperties.I++;
ComplexTreeProperties.LASTMODIF = ComplexTreeProperties.I++;
ComplexTreeProperties.SELECT_FOLDER = ComplexTreeProperties.I++;
ComplexTreeProperties.NEW_LINE = ComplexTreeProperties.I++;
ComplexTreeProperties.TITLE = ComplexTreeProperties.I++;
ComplexTreeProperties.CATEGORY_LAUNCHERS = ComplexTreeProperties.I++;
ComplexTreeProperties.CATEGORY_LAUNCHERS = ComplexTreeProperties.I++;
ComplexTreeProperties.CATEGORY_RADIO = ComplexTreeProperties.I++;
ComplexTreeProperties.CATEGORY_CHECKBOX = ComplexTreeProperties.I++;
ComplexTreeProperties.PORTLET_CHECKBOX = ComplexTreeProperties.I++;
ComplexTreeProperties.SELECTED_FILE = ComplexTreeProperties.I++;

// Define different styles for the ComplexTreeDisplay
ComplexTreeProperties.FILEMANAGER_STYLE = ComplexTreeProperties.I++;
ComplexTreeProperties.SIMPLE_STYLE = ComplexTreeProperties.I++;
ComplexTreeProperties.WORKFLOW_STYLE = ComplexTreeProperties.I++;
ComplexTreeProperties.SELECT_PAGE_STYLE = ComplexTreeProperties.I++;
ComplexTreeProperties.SITEMAP_STYLE = ComplexTreeProperties.I++;
ComplexTreeProperties.CATEGORY_STYLE = ComplexTreeProperties.I++;
ComplexTreeProperties.VERSIONNING_STYLE = ComplexTreeProperties.I++;
ComplexTreeProperties.FCK_STYLE = ComplexTreeProperties.I++;
ComplexTreeProperties.WEBDAV_STYLE = ComplexTreeProperties.I++;
ComplexTreeProperties.WEBDAV_SELECT_FOLDER_STYLE = ComplexTreeProperties.I++;
ComplexTreeProperties.ADMIN_CATEGORY_STYLE = ComplexTreeProperties.I++;
ComplexTreeProperties.SELECT_CATEGORY_STYLE = ComplexTreeProperties.I++;
ComplexTreeProperties.MOVE_CATEGORY_STYLE = ComplexTreeProperties.I++;
ComplexTreeProperties.PORTLET_CATEGORY_STYLE = ComplexTreeProperties.I++;

// Defines the patterns for the tree and listview. ComplexTreeProperties.KEY is mandatory for all tree styles as the
// first element !
ComplexTreeProperties.SIMPLE_TREE_STYLE_PATTERN = [ComplexTreeProperties.KEY, ComplexTreeProperties.LINK];
ComplexTreeProperties.SIMPLE_LIST_STYLE_PATTERN = [];

ComplexTreeProperties.FCK_TREE_STYLE_PATTERN = [ComplexTreeProperties.KEY, ComplexTreeProperties.LINK_FCK];
ComplexTreeProperties.FCK_LIST_STYLE_PATTERN = [];

ComplexTreeProperties.WORKFLOW_TREE_STYLE_PATTERN = [ComplexTreeProperties.KEY, ComplexTreeProperties.ID, ComplexTreeProperties.W_FLOW_TYPE, ComplexTreeProperties.SPACE, ComplexTreeProperties.LINK];
ComplexTreeProperties.WORKFLOW_LIST_STYLE_PATTERN = [[ComplexTreeProperties.W_FLOW_IMAGES], [ComplexTreeProperties.IMAGE, ComplexTreeProperties.SPACE, ComplexTreeProperties.W_FLOW_CHECKBOXES]];

ComplexTreeProperties.SITEMAP_TREE_STYLE_PATTERN = [ComplexTreeProperties.KEY, ComplexTreeProperties.ID, ComplexTreeProperties.LINK_SAME_PAGE];
ComplexTreeProperties.SITEMAP_LIST_STYLE_PATTERN = [[ComplexTreeProperties.IMAGE_LINK_SAME_PAGE, ComplexTreeProperties.BLANK]];

ComplexTreeProperties.SELECT_TREE_STYLE_PATTERN = [ComplexTreeProperties.KEY, ComplexTreeProperties.SELECT_RADIO, ComplexTreeProperties.ID, ComplexTreeProperties.SELECT_PAGE_STYLE, ComplexTreeProperties.SPACE, ComplexTreeProperties.LINK];
ComplexTreeProperties.SELECT_LIST_STYLE_PATTERN = [];

ComplexTreeProperties.VERSIONNING_TREE_STYLE_PATTERN = [ComplexTreeProperties.KEY, ComplexTreeProperties.ID, ComplexTreeProperties.LINK];
ComplexTreeProperties.VERSIONNING_LIST_STYLE_PATTERN = [[ComplexTreeProperties.VERSIONNING_CHECKBOX, ComplexTreeProperties.IMAGE, ComplexTreeProperties.SPACE, ComplexTreeProperties.VERSIONNING_IMAGES]];

ComplexTreeProperties.WEBDAV_TREE_STYLE_PATTERN = [ComplexTreeProperties.KEY, ComplexTreeProperties.FILE_IMAGE, ComplexTreeProperties.SPACE, ComplexTreeProperties.LINK_FCK];
ComplexTreeProperties.WEBDAV_LIST_STYLE_PATTERN = [];

ComplexTreeProperties.WEBDAV_SELECT_FOLDER_STYLE_PATTERN = [ComplexTreeProperties.KEY, ComplexTreeProperties.FILE_IMAGE, ComplexTreeProperties.SPACE, ComplexTreeProperties.SELECT_FOLDER];

ComplexTreeProperties.FILEMANAGER_TREE_STYLE_PATTERN = [ComplexTreeProperties.KEY, ComplexTreeProperties.FILE_IMAGE, ComplexTreeProperties.SPACE, ComplexTreeProperties.LINK_SAME_PAGE];
ComplexTreeProperties.FILEMANAGER_LIST_STYLE_PATTERN = [[ComplexTreeProperties.SELECTED_FILE, ComplexTreeProperties.FILEMANAGER_CHECKBOX, ComplexTreeProperties.FILE_IMAGE, ComplexTreeProperties.SPACE, ComplexTreeProperties.LINK_SAME_PAGE], [ComplexTreeProperties.FILEMANAGER_IMAGES], [ComplexTreeProperties.FILESIZE], [ComplexTreeProperties.LASTMODIF]];
ComplexTreeProperties.FILEMANAGER_ICONS_STYLE_PATTERN = [[ComplexTreeProperties.FILE_IMAGE, ComplexTreeProperties.NEW_LINE, ComplexTreeProperties.FILEMANAGER_CHECKBOX, ComplexTreeProperties.LINK_SAME_PAGE]];
ComplexTreeProperties.FILEMANAGER_TB_STYLE_PATTERN = [[ComplexTreeProperties.FILE_IMAGE, ComplexTreeProperties.NEW_LINE, ComplexTreeProperties.FILEMANAGER_CHECKBOX, ComplexTreeProperties.LINK_SAME_PAGE]];

ComplexTreeProperties.CATEGORY_ADMIN_TREE_STYLE_PATTERN = [ComplexTreeProperties.KEY, ComplexTreeProperties.TITLE, ComplexTreeProperties.SPACE, ComplexTreeProperties.CATEGORY_LAUNCHERS];
ComplexTreeProperties.CATEGORY_MOVE_TREE_STYLE_PATTERN = [ComplexTreeProperties.KEY, ComplexTreeProperties.CATEGORY_RADIO, ComplexTreeProperties.SPACE, ComplexTreeProperties.TITLE];
ComplexTreeProperties.CATEGORY_SELECT_TREE_STYLE_PATTERN = [ComplexTreeProperties.KEY, ComplexTreeProperties.CATEGORY_CHECKBOX, ComplexTreeProperties.SPACE, ComplexTreeProperties.TITLE];
ComplexTreeProperties.CATEGORY_PORTLET_TREE_STYLE_PATTERN = [ComplexTreeProperties.KEY, ComplexTreeProperties.PORTLET_CHECKBOX, ComplexTreeProperties.SPACE, ComplexTreeProperties.TITLE];


// XML Tag Names
ComplexTreeProperties.OBJECT = "object";
ComplexTreeProperties.PAGE = "page";
ComplexTreeProperties.CATEGORY = "category";

ComplexTreeProperties.COUNTER = 0;

ComplexTreeProperties.getPicto =
function (ext) {
    var f = ext.toLowerCase();
    for (var k = 0; k < ComplexTreeProperties.extention.length; k++) {
        if (f == ComplexTreeProperties.extention[k]) {
            return ComplexTreeProperties.picto[k];
        }
    }
    return "file";
}

ComplexTreeProperties.getFileTypeImageLarge =
function (ext) {
    if (ext == "dir") {
        return ComplexTreeProperties.CONTEXT + "/jsp/jahia/engines/images/types/large/folder.gif";
    }
    return ComplexTreeProperties.CONTEXT + "/jsp/jahia/engines/images/types/large/" + ComplexTreeProperties.getPicto(ext) + ".gif";
}

ComplexTreeProperties.getFileTypeImageTbnail =
function (ext, key) {
    if (ext == "dir") {
        return ComplexTreeProperties.CONTEXT + "/jsp/jahia/engines/images/types/tbnail/folder.gif";
    }
    var picto = ComplexTreeProperties.getPicto(ext);
    if (picto.indexOf("img") > -1) {
        if (key.indexOf("_th_64") > -1) {
            return ComplexTreeProperties.webdavPath + key;
        }

        var thName = key.substring(0, key.length - 4);
        thName += "_th_64." + ext;

        return ComplexTreeProperties.webdavPath + thName;
    } else {
        return ComplexTreeProperties.CONTEXT + "/jsp/jahia/engines/images/types/tbnail/" + picto + ".gif";
    }
}

ComplexTreeProperties.getFileTypeImage =
function (ext) {
    if (ext == "root") {
        return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.COMPUTER_SRC;
    } else if (ext == "dir") {
        return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.FOLDER_SRC;
    }
    return ComplexTreeProperties.CONTEXT + "/jsp/jahia/engines/images/types/" + ComplexTreeProperties.getPicto(ext) + ".gif";
}

/**
 * Returns the image source path depending on the state value
 */
ComplexTreeProperties.getImageSrc =
function (state) {
    state = parseInt(state, 10);
    switch (state) {
        case ComplexTreeProperties.ACTIVE_WORKFLOW_STATE:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.ACTIVE_ICONE_SRC;

        case ComplexTreeProperties.STAGING_WORKFLOW_STATE:
            ComplexTreeProperties.DOUBLE_BUTTONS = false;
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.EDIT_ICONE_SRC;

        case ComplexTreeProperties.WAITING_WORKFLOW_STATE:
            ComplexTreeProperties.DOUBLE_BUTTONS = true;
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.WAITING_ICONE_SRC;

        case ComplexTreeProperties.DELETED_WORKFLOW_STATE:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.DELETED_ICONE_SRC;

        case ComplexTreeProperties.LOCKED_STATE:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.LOCKED_ICONE_SRC;

        case ComplexTreeProperties.WARNINGS_STATE:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.WARNINGS_ICONE_SRC;

        case ComplexTreeProperties.PARTIAL_WARNINGS_STATE:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.PARTIAL_WARNINGS_ICONE_SRC;

        case ComplexTreeProperties.ERRORS_STATE:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.ERRORS_ICONE_SRC;

        case ComplexTreeProperties.STANDARD_STATE:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.STANDARD;

        case ComplexTreeProperties.N_STEP_STATE:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.N_STEP;

        case ComplexTreeProperties.NO_WFLOW_STATE:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.NO_WFLOW;

        case ComplexTreeProperties.LINKED_WFLOW_STATE:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.LINKED;

        case ComplexTreeProperties.EXISTING_STATE:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.EXISTING;

        case ComplexTreeProperties.SELECT_SUB_TREE:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.ACCEPT_ICONE_SRC;

        case ComplexTreeProperties.UNSELECT_SUB_TREE:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.REFUSE_ICONE_SRC;

        case ComplexTreeProperties.INFO:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.INFO_SRC;

        case ComplexTreeProperties.PROPS:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.PROPS_SRC;

        case ComplexTreeProperties.IE_FOLDER:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.IE_FOLDER_SRC;

        case ComplexTreeProperties.ADD_CATEGORY:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.ADD_CATEGORY_SRC;

        case ComplexTreeProperties.EDIT_CATEGORY:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.EDIT_CATEGORY_SRC;

        case ComplexTreeProperties.MOVE_CATEGORY:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.MOVE_CATEGORY_SRC;

        case ComplexTreeProperties.DELETE_CATEGORY:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.DELETE_CATEGORY_SRC;

        case ComplexTreeProperties.EXPIRED_BUT_WILL_BECOME_VALID:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.EXPIRED_BUT_WILL_BECOME_VALID_SRC;

        case ComplexTreeProperties.EXPIRED:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.EXPIRED_SRC;

        case ComplexTreeProperties.VALID:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.VALID_SRC;

        case ComplexTreeProperties.VALID_BUT_WILL_EXPIRE:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.VALID_BUT_WILL_EXPIRE_SRC;

        case ComplexTreeProperties.NOT_VALID_BUT_WILL_BECOME_VALID:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.NOT_VALID_BUT_WILL_BECOME_VALID_SRC;

        case ComplexTreeProperties.UNKNOWN:
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.UNKNOWN_SRC;

        case -3:
            ComplexTreeProperties.Error = true;
            return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.PIX_SRC;

        default:
            if (state >= 100 && state <= 999) {
                // it is an extended state
                if (state.toString().charAt(1) == '3' || state == 600) {
                    ComplexTreeProperties.DOUBLE_BUTTONS = true;
                }
                return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.WORKFLOW_ICONS_PATH + state + '.png';
            } else {
                DBG.println("ComplexTreeProperties.getImageSrc - Not Found: " + state);
                ComplexTreeProperties.Error = true;
                return ComplexTreeProperties.CONTEXT + ComplexTreeProperties.EMPTY_SRC;
            }
    }
}

/**
 * Returns the size of the pattern depending on the type
 */
ComplexTreeProperties.getPatternItemSize =
function(type) {
    switch (type) {
        case ComplexTreeProperties.BLANK:
        case ComplexTreeProperties.SPACE:
        case ComplexTreeProperties.NEW_LINE:
            return 0;

        case ComplexTreeProperties.ID:
        case ComplexTreeProperties.KEY:
        case ComplexTreeProperties.FILESIZE:
        case ComplexTreeProperties.LASTMODIF:
        case ComplexTreeProperties.TITLE:
            return 1;

        case ComplexTreeProperties.LINK:
        case ComplexTreeProperties.LINK_SAME_PAGE:
        case ComplexTreeProperties.LINK_FCK:
        case ComplexTreeProperties.IMAGE:
        case ComplexTreeProperties.SELECT_RADIO:
        case ComplexTreeProperties.FILEMANAGER_CHECKBOX:
        case ComplexTreeProperties.SELECT_FOLDER:
        case ComplexTreeProperties.CATEGORY_RADIO:
        case ComplexTreeProperties.CATEGORY_CHECKBOX:
        case ComplexTreeProperties.SELECTED_FILE:
            return 2;

        case ComplexTreeProperties.SELECT_PAGE_STYLE:
        case ComplexTreeProperties.FILE_IMAGE:
        case ComplexTreeProperties.IMAGE_LINK:
        case ComplexTreeProperties.IMAGE_LINK_SAME_PAGE:
        case ComplexTreeProperties.W_FLOW_TYPE:
        case ComplexTreeProperties.PORTLET_CHECKBOX:
            return 3;

        case ComplexTreeProperties.W_FLOW_CHECKBOXES:
        case ComplexTreeProperties.VERSIONNING_CHECKBOX:
            return 4;

        case ComplexTreeProperties.VERSIONNING_IMAGES:
            return 6;

        case ComplexTreeProperties.FILEMANAGER_IMAGES:
            return 9;

        case ComplexTreeProperties.W_FLOW_IMAGES:
        case ComplexTreeProperties.CATEGORY_LAUNCHERS:
            return 12;

        default:
            DBG.println("ComplexTreeProperties.getPatternItemSize - Not Found: " + type);
            return 0;
    }
}

/**
 * Calculates and returns the how many values are required for a particular pattern item
 */
ComplexTreeProperties.getPatternItemLength =
function (pattern) {
    var result = new Array(pattern.length);
    for (var i = 0; i < pattern.length; i++) {
        var count = 0;
        for (var j = 0; j < pattern[i].length; j++) {
            count += ComplexTreeProperties.getPatternItemSize(pattern[i][j]);
        }
        result[i] = count;
        delete count;
    }
    return result;
}

/**
 * Method that interprets parameters of a javascript function and replaces them with the correct value
 */
ComplexTreeProperties.decodeOnClickURL =
function (url, objectInfo) {
    if ((url.indexOf("'key'") > -1 || url.indexOf("\"key\"") > -1)) {
        if (objectInfo.canWrite != "true") return false;
        var reg = new RegExp("(key)", "g");
        url = url.replace(reg, escape(objectInfo.url));
        delete reg;
    } else if ((url.indexOf("'folderUrl'") > -1 || url.indexOf("\"folderUrl\"") > -1)) {
        if (objectInfo.canRead != "true") return false;
        var reg = new RegExp("(folderUrl)", "g");
        url = url.replace(reg, ComplexTreeProperties.webdavPath + escape(objectInfo.url));
        delete reg;
    }
    return url;
}

/**
 * Extracts data from a pageInfo hashtable and returns an Array of values in the order defined by the pattern
 */
ComplexTreeProperties.getDataFromObjectInfo =
function(objectInfo, patternItem, colId, props, ctree) {
    var style = parseInt(patternItem, 10);
    switch (style) {
        case ComplexTreeProperties.KEY:
            return [objectInfo.key];

        case ComplexTreeProperties.ID:
            return [objectInfo.id];

        case ComplexTreeProperties.TITLE:
            return [objectInfo.title];

        case ComplexTreeProperties.FILESIZE:
            return [objectInfo.fileSize];

        case ComplexTreeProperties.LASTMODIF:
            return [objectInfo.lastModif];

        case ComplexTreeProperties.CATEGORY_RADIO:
            return [objectInfo.id, objectInfo.disable];

        case ComplexTreeProperties.CATEGORY_CHECKBOX:
            return [objectInfo.id, objectInfo.checked];

        case ComplexTreeProperties.PORTLET_CHECKBOX:
            return [objectInfo.id, objectInfo.checked,objectInfo.allsources];

        case ComplexTreeProperties.LINK:
        case ComplexTreeProperties.LINK_SAME_PAGE:
            var redLink = objectInfo.warnings || objectInfo.partialWarnings || objectInfo.errors || objectInfo.locked;
            if (objectInfo.dir) {
                if (objectInfo.dir == "dir") {
                    if (ctree && ctree._urlToUseOnclick) {
                        return [[ComplexTreeProperties.decodeOnClickURL(ctree._urlToUseOnclick, objectInfo), redLink], objectInfo.title];
                    } else {
                        return [[objectInfo.title, redLink], null];
                    }
                } else if (objectInfo.dir == "root") {
                    return [[objectInfo.title, redLink], null];
                } else {
                    return [["javascript:go(\"sendForm\", true, \"" + escape(objectInfo.url) + "\");", redLink], objectInfo.title];
                }
            } else {
                if (ctree && ctree._urlToUseOnclick)
                    return [[ComplexTreeProperties.decodeOnClickURL(ctree._urlToUseOnclick, objectInfo), redLink], objectInfo.title];
                else
                    return [[objectInfo.url, redLink], objectInfo.title];
            }

        case ComplexTreeProperties.LINK_FCK:
            if (objectInfo.dir) {
                if (objectInfo.dir != "root" && objectInfo.dir != "dir") {
                    return [["javascript:Set(\"" + ComplexTreeProperties.webdavPath + escape(objectInfo.url) + "\");void(0);", redLink], objectInfo.title];
                } else {
                    return [[objectInfo.title, redLink], null];
                }

            } else {
                return [["javascript:Set(\"" + escape(objectInfo.url) + "\");void(0);"], objectInfo.title];
            }

        case ComplexTreeProperties.SELECT_FOLDER:
            if (objectInfo.dir) {
                if (objectInfo.dir == "dir") {
                    if (ctree && ctree._urlToUseOnclick) {
                        if (objectInfo.canRead == "true") {
                            var url = ComplexTreeProperties.decodeOnClickURL(ctree._urlToUseOnclick, objectInfo);
                            if (!url)
                                return [objectInfo.title, null];
                            else
                                return [url, objectInfo.title];
                        } else
                            return [objectInfo.title, null];
                    } else {
                        return [objectInfo.url, objectInfo.title];
                    }
                } else {
                    return [objectInfo.title, null];
                }

            } else {
                if (ctree._urlToUseOnclick) {
                    return [ComplexTreeProperties.decodeOnClickURL(ctree._urlToUseOnclick, objectInfo), objectInfo.title];
                } else {
                    return [objectInfo.url, objectInfo.title];
                }
            }

        case ComplexTreeProperties.SELECT_PAGE_STYLE:
            if (objectInfo.displayImage) {
                return [ComplexTreeProperties.getTimeBasedPublishingLauncher(objectInfo), objectInfo.displayImage, objectInfo.key];
            }
            return [null, null,null];

        case ComplexTreeProperties.W_FLOW_TYPE:
            if (ComplexTreeProperties.activeTab) {
                if (objectInfo.activeTab && objectInfo.displayImage) {
                    return [ComplexTreeProperties.getWorkflowLauncher(objectInfo.activeTab, objectInfo.key), objectInfo.displayImage, objectInfo.activeTab];
                }
            }
            return [null, null, null];

        case ComplexTreeProperties.W_FLOW_CHECKBOXES:
            if (objectInfo[colId] && objectInfo[colId][4] && !objectInfo[colId][3]) {
                var result = new Array(4);
                result[0] = "checkbox|" + colId + "|" + objectInfo.key +
                            (objectInfo[colId][4] ? "|" + objectInfo[colId][4] : "");
                result[1] = objectInfo[colId][1];
                if (objectInfo[colId][5]) {
                    result[2] = "checkbox|" + colId + "|" + objectInfo.key +
                                (objectInfo[colId][5] ? "|" + objectInfo[colId][5] : "");
                    result[3] = objectInfo[colId][1];
                } else {
                    result[2] = null;
                    result[3] = null;
                }
                return result;

            } else {
                return [null, null, null, null];
            }

        case ComplexTreeProperties.FILE_IMAGE:
            var tmp = objectInfo.dir;
            if (tmp == "root")
                return [tmp, "root", objectInfo];
            else if (tmp == "dir")
                return [tmp, "folder", objectInfo];
            else
                return [tmp, "file", objectInfo];

        case ComplexTreeProperties.IMAGE:
            if (objectInfo[colId]) {
                return [objectInfo[colId][0], objectInfo[colId][0]];
            }
            return [null, null];

        case ComplexTreeProperties.SELECTED_FILE:
            var divElem = document.getElementById("file_id");
            if (divElem && divElem.value == objectInfo.key) {
                delete divElem;
                return [ComplexTreeProperties.EXISTING_STATE, ComplexTreeProperties.EXISTING_STATE];
            }
            delete divElem;
            return [" ", null];

        case ComplexTreeProperties.VERSIONNING_CHECKBOX:
            if (objectInfo[colId]) {
                return [ComplexTreeProperties.COUNTER, "checkbox_" + objectInfo.key + "_" + objectInfo.parentID + "_" + colId, objectInfo[colId][1], objectInfo[colId][3]];
            } else {
                return [null, null, null, null];
            }

        case ComplexTreeProperties.IMAGE_LINK:
        case ComplexTreeProperties.IMAGE_LINK_SAME_PAGE:
            if (objectInfo[colId]) {
                return [objectInfo[colId][2], objectInfo[colId][0], objectInfo[colId][0]];
            } else {
                return [null, null, null];
            }

        case ComplexTreeProperties.VERSIONNING_IMAGES:
            var res;
            if (objectInfo[colId]) {
                res = ["javascript:selectSubTree('checkbox_" + ComplexTreeProperties.COUNTER + "', 'select', '" + colId + "')",
                    ComplexTreeProperties.SELECT_SUB_TREE, "",
                    "javascript:selectSubTree('checkbox_" + ComplexTreeProperties.COUNTER + "', 'unselect', '" + colId + "')",
                    ComplexTreeProperties.UNSELECT_SUB_TREE, ""];
                ComplexTreeProperties.COUNTER++;
            } else {
                res = [null, null, null, null, null, null];
            }
            return res;

        case ComplexTreeProperties.SELECT_RADIO:
            return [objectInfo.id, "sourcePageID"];

        case ComplexTreeProperties.FILEMANAGER_CHECKBOX:
            var res = [ComplexTreeProperties.COUNTER, objectInfo.key];
            ComplexTreeProperties.COUNTER++;
            return res;

        case ComplexTreeProperties.FILEMANAGER_IMAGES:
            if (objectInfo.info) {
                var res = [objectInfo.info[0], objectInfo.info[1], objectInfo.info[2]];
            } else {
                var res = [null, null, null];
                return res;
            }

            if (objectInfo.locked) {
                res[res.length] = objectInfo.locked[0];
                res[res.length] = objectInfo.locked[1];
                res[res.length] = objectInfo.locked[2];
            } else {
                res[res.length] = null;
                res[res.length] = null;
                res[res.length] = null;
            }
            if (objectInfo.dir == "dir" && AjxEnv.isIE) {
                res[res.length] = objectInfo.url;
                res[res.length] = ComplexTreeProperties.IE_FOLDER;
                res[res.length] = objectInfo.url;
            } else {
                res[res.length] = null;
                res[res.length] = null;
                res[res.length] = null;
            }
            return res;

        case ComplexTreeProperties.W_FLOW_IMAGES:
            var res = new Array();
            if (objectInfo.errors) {
                res[res.length] = objectInfo.errors;
                res[res.length] = ComplexTreeProperties.ERRORS_STATE;
                res[res.length] = "Blocking validation errors";
            } else {
                res[res.length] = null;
                res[res.length] = null;
                res[res.length] = null;
            }
            if (objectInfo.partialWarnings) {
                res[res.length] = objectInfo.partialWarnings;
                res[res.length] = ComplexTreeProperties.PARTIAL_WARNINGS_STATE;
                res[res.length] = "Partially blocking validation errors";
            } else {
                res[res.length] = null;
                res[res.length] = null;
                res[res.length] = null;
            }
            if (objectInfo.warnings) {
                res[res.length] = objectInfo.warnings;
                res[res.length] = ComplexTreeProperties.WARNINGS_STATE;
                res[res.length] = "Validation warnings";
            } else {
                res[res.length] = null;
                res[res.length] = null;
                res[res.length] = null;
            }
            if (objectInfo.locked) {
                res[res.length] = objectInfo.locked;
                res[res.length] = ComplexTreeProperties.LOCKED_STATE;
                res[res.length] = "Object is locked";
            } else {
                res[res.length] = null;
                res[res.length] = null;
                res[res.length] = null;
            }
            return res;

        case ComplexTreeProperties.CATEGORY_LAUNCHERS:
            var res = new Array();
            if (objectInfo.add) {
                res[res.length] = objectInfo.add;
                res[res.length] = ComplexTreeProperties.ADD_CATEGORY;
                res[res.length] = "add";
            } else {
                res[res.length] = null;
                res[res.length] = null;
                res[res.length] = null;
            }
            if (objectInfo.edit) {
                res[res.length] = objectInfo.edit;
                res[res.length] = ComplexTreeProperties.EDIT_CATEGORY;
                res[res.length] = "edit";
            } else {
                res[res.length] = null;
                res[res.length] = null;
                res[res.length] = null;
            }
            if (objectInfo.move) {
                res[res.length] = objectInfo.move;
                res[res.length] = ComplexTreeProperties.MOVE_CATEGORY;
                res[res.length] = "move";
            } else {
                res[res.length] = null;
                res[res.length] = null;
                res[res.length] = null;
            }
            if (objectInfo.remove) {
                res[res.length] = objectInfo.remove;
                res[res.length] = ComplexTreeProperties.DELETE_CATEGORY;
                res[res.length] = "remove";
            } else {
                res[res.length] = null;
                res[res.length] = null;
                res[res.length] = null;
            }
            return res;

        default:
            DBG.println("ComplexTreeProperties.getDataFromObjectInfo - Not Found: " + patternItem);
            return null;
    }
}

/**
 * Returns an HTML String depending on the type and the data
 *
 * @param   itemId Used for checkboxes. In the case od a DwtListView, we need to remember in which ListItem the
 *          checkbox belongs so we can update the ListItem data when the users clicks on the checkbox.
 */
ComplexTreeProperties.getHtml =
function(type, data, enable, props) {
    if (type == ComplexTreeProperties.SPACE) return "&nbsp;";
    if (type == ComplexTreeProperties.NEW_LINE) return "<br/>";
    if (type == ComplexTreeProperties.BLANK) {
        return AjxEnv.isIE ? "<img src='" + ComplexTreeProperties.getImageSrc(-1) + "' alt='' border='0' />" : "&nbsp;";
    }
    if ((data[0] == null || data[0].length == 0) && type == ComplexTreeProperties.W_FLOW_CHECKBOXES) {
        return AjxEnv.isIE ? "<img src='" + ComplexTreeProperties.getImageSrc(-1) + "' alt='' border='0' />" : "&nbsp;";
    }
    if ((data[0] == null || data[0].length == 0) && type != ComplexTreeProperties.W_FLOW_IMAGES) return "";
    switch (type) {
        case ComplexTreeProperties.KEY:
            return " ";

        case ComplexTreeProperties.FILESIZE:
        case ComplexTreeProperties.LASTMODIF:
        case ComplexTreeProperties.TITLE:
            return " " + data[0] + " ";

        case ComplexTreeProperties.ID:
        //DBG.println("PID: " + data[0]);
            return " [" + data[0] + "] ";

        case ComplexTreeProperties.W_FLOW_CHECKBOXES:
            var res = "<input ondblclick='uncheck(\"" + "checkA" + ComplexTreeProperties.COUNTER + "\")' id='checkA" + ComplexTreeProperties.COUNTER + "' name='" + data[0] + "' value='" + data[0] + "' type='radio' " + (enable ? "" : " disabled='disabled' ") + (data[1] ? "checked='checked'" : "") + "/>";
            ComplexTreeProperties.COUNTER++;
            if (data[2] && ComplexTreeProperties.DOUBLE_BUTTONS) {
                res += "<input ondblclick='uncheck(\"" + "checkR" + ComplexTreeProperties.COUNTER + "\")' id='checkR" + ComplexTreeProperties.COUNTER + "' name='" + data[0] + "' value='" + data[2] + "' type='radio' " + (enable ? "" : " disabled='disabled' ") + (data[3] ? "checked='checked'" : "") + "/>";
                ComplexTreeProperties.COUNTER++;
                ComplexTreeProperties.DOUBLE = true;
            }
            return  res;

        case ComplexTreeProperties.VERSIONNING_CHECKBOX:
        //alert("CHECKBOX: " + data[0] + ", " + data[1] + ", " + data[2] + ", " + data[3]);
            return "<input id='checkbox_" + data[0] + "' name='" + data[1] + "' type='checkbox' " + (data[3] ? " disabled='disabled' " : "") + (data[2] ? "checked='checked'" : "") + "/>";

        case ComplexTreeProperties.FILEMANAGER_CHECKBOX:
            return "<input onclick='getFileManagerBar(this)' id='checkbox_" + data[0] + "' name='" + data[1] + "' type='checkbox' />";

        case ComplexTreeProperties.FILE_IMAGE:
            if (props && props.CURRENT_LIST_PATTERN == ComplexTreeProperties.FILEMANAGER_ICONS_STYLE_PATTERN) {
                return "<img onmouseover='this.style.cursor=\"pointer\"' onclick='javascript:openManager(\"" + data[2].key + "\", \"info\");' src='" + ComplexTreeProperties.getFileTypeImageLarge(data[0]) + "' alt='" + data[1] + "' border='0' />";
            } else if (props && props.CURRENT_LIST_PATTERN == ComplexTreeProperties.FILEMANAGER_TB_STYLE_PATTERN) {
                return "<img onmouseover='this.style.cursor=\"pointer\"' onclick='javascript:openManager(\"" + data[2].key + "\", \"info\");' src='" + ComplexTreeProperties.getFileTypeImageTbnail(data[0], data[2].url) + "' alt='" + data[1] + "' border='0' />";
            } else {
                return "<img src='" + ComplexTreeProperties.getFileTypeImage(data[0]) + "' alt='" + data[1] + "' border='0' />";
            }

        case ComplexTreeProperties.SELECTED_FILE:
        case ComplexTreeProperties.IMAGE:
        //alert("IMAGE: " + data[0] + ", " + data[1]);
            ComplexTreeProperties.CONTINUE_IF_EMPTY = true;
            if (data[0] == " ") return " ";
            return "<img src='" + ComplexTreeProperties.getImageSrc(data[0]) + "' title='' alt='" + data[1] + "' border='0' " + (data[0].length == 3 ? " width='12'" : "") + "/>";


        case ComplexTreeProperties.IMAGE_LINK:
        //DBG.println("IMAGE_LINK: " + data[0] + ", " + data[1] + ", " + data[2]);
            var image = parseInt(data[1], 10);
            if (image == ComplexTreeProperties.NO_WFLOW_STATE || image == ComplexTreeProperties.LINKED_WFLOW_STATE) {
                return "<img src='" + ComplexTreeProperties.getImageSrc(image) + "' title='" + data[2] + "' alt='" + data[2] + "' border='0' />";
            }
            if (image == -1) {
                return "<img src='" + ComplexTreeProperties.getImageSrc(-1) + "' alt='' border='0' />";
            }
            return "<a target='_blank' href=\"" + data[0] + "\"><img src='" + ComplexTreeProperties.getImageSrc(image) +
                   "' title='" + data[2] + "' alt='" + data[2] + "' border='0' /></a>";

        case ComplexTreeProperties.IMAGE_LINK_SAME_PAGE:
        //DBG.println("IMAGE_LINK: " + data[0] + ", " + data[1] + ", " + data[2]);
            var image = parseInt(data[1], 10);
            if (image == ComplexTreeProperties.NO_WFLOW_STATE || image == ComplexTreeProperties.LINKED_WFLOW_STATE) {
                return "<img src='" + ComplexTreeProperties.getImageSrc(image) +
                       "' title='" + data[2] + "' alt='" + data[2] + "' border='0' />";
            }
            if (image == -1) {
                return "<img src='" + ComplexTreeProperties.getImageSrc(-1) + "' alt='' border='0' />";
            }
            var width = image > 100 && image <= 999 ? " width='12'" : "";
            return "<a href=\"" + data[0] + "\"><img src='" + ComplexTreeProperties.getImageSrc(image) +
                   "' title='' alt='" + data[2] + "' border='0' " + width + "/></a>";

        case ComplexTreeProperties.W_FLOW_TYPE:
        //DBG.println("W_FLOW_TYPE: " + data[0] + ", " + data[1] + ", " + data[2]);
            var image = parseInt(data[1], 10);
            if (!image || !data[0]) return "";
            if (image == ComplexTreeProperties.NO_WFLOW_STATE || image == ComplexTreeProperties.LINKED_WFLOW_STATE) {
                return "<img src='" + ComplexTreeProperties.getImageSrc(image) +
                       "' title='" + data[2] + "' alt='" + data[2] + "' border='0' />";
            }
            if (image == -1) {
                return "<img src='" + ComplexTreeProperties.getImageSrc(-1) + "' alt='' border='0' />";
            }
            return "<a href=\"" + data[0] + "\"><img src='" + ComplexTreeProperties.getImageSrc(image) +
                   "' title='" + data[2] + "' alt='" + data[2] + "' border='0' /></a>";

        case ComplexTreeProperties.SELECT_PAGE_STYLE:
        //DBG.println("W_FLOW_TYPE: " + data[0] + ", " + data[1] + ", " + data[2]);
            var image = parseInt(data[1], 10);
            if (!image || !data[0]) return "";
            return "<img src='" + ComplexTreeProperties.getImageSrc(image) + "' id='img_" + data[2] +
                   "' title='" + data[2] + "' alt='" + data[2] + "' border='0' " + " onClick=\"" + data[0] + "\" />";

        case ComplexTreeProperties.LINK:
        //DBG.println("LINK: " + data[0] + ", " + data[1]);
            if (data[0][1]) {
                return "<a target='_blank' class='redlink' href='" + data[0][0] + "'>" + data[1] + "</a>";
            } else {
                return "<a target='_blank' class='link' href='" + data[0][0] + "'>" + data[1] + "</a>";
            }


        case ComplexTreeProperties.LINK_SAME_PAGE:
        case ComplexTreeProperties.LINK_FCK:
        //DBG.println("LINK_SAME_PAGE: " + data[0] + ", " + data[1]);
            if (!data[1])
                return "<span class='pointer'>" + data[0][0] + "</span>";
            else if (data[0][0].indexOf("javascript") > -1)
                return "<a class='blacklink' href='" + data[0][0] + "'>" + data[1] + "</a>";
            else
                if (data[0][1]) {
                    return "<a class='redlink' href='" + data[0][0] + "'>" + data[1] + "</a>";
                } else {
                    return "<a class='link' href='" + data[0][0] + "'>" + data[1] + "</a>";
                }

        case ComplexTreeProperties.SELECT_FOLDER:
            if (data[1] == null)
                return " " + data[0] + " ";
            else
                return "<a class='link' href='" + data[0] + "'>" + data[1] + "</a>";

        case ComplexTreeProperties.SELECT_RADIO:
            return "<input type='radio' name='" + data[1] + "' value='" + data[0] + "'" + (enable ? "" : " disabled='disabled' ") + "/>";

        case ComplexTreeProperties.VERSIONNING_IMAGES:
            return "<a href=\"" + data[0] + "\"><img src='" + ComplexTreeProperties.getImageSrc(parseInt(data[1], 10)) +
                   "' alt='" + data[2] + "' border='0' /></a>\n" +
                   "<a href=\"" + data[3] + "\"><img src='" + ComplexTreeProperties.getImageSrc(parseInt(data[4], 10)) +
                   "' alt='" + data[5] + "' border='0' /></a>";

        case ComplexTreeProperties.W_FLOW_IMAGES:
            var image = parseInt(data[1], 10);
            var res = "";
            if (data[0]) {
                tmp = "<a href=\"" + data[0] + "\"><img src='" + ComplexTreeProperties.getImageSrc(image) +
                      "' title='" + data[2] + "' alt='" + data[2] + "' border='0' /></a>\n";
                res += tmp;
            }
            image = parseInt(data[4], 10);
            if (data[3]) {
                tmp = "<a href=\"" + data[3] + "\"><img src='" + ComplexTreeProperties.getImageSrc(image) +
                      "' title='" + data[5] + "' alt='" + data[5] + "' border='0' /></a>\n";
                res += tmp;
            }
            image = parseInt(data[7], 10);
            if (data[6]) {
                tmp = "<a href=\"" + data[6] + "\"><img src='" + ComplexTreeProperties.getImageSrc(image) +
                      "' title='" + data[8] + "' alt='" + data[8] + "' border='0' /></a>\n";
                res += tmp;
            }
            image = parseInt(data[10], 10);
            if (data[9]) {
                tmp = "<a href=\"" + data[9] + "\"><img src='" + ComplexTreeProperties.getImageSrc(image) +
                      "' title='" + data[11] + "' alt='" + data[11] + "' border='0' /></a>\n";
                res += tmp;
            }
            return res;

        case ComplexTreeProperties.FILEMANAGER_IMAGES:
            var image = parseInt(data[1], 10);
            var res = "";
            if (data[0]) {
                tmp = "<a href=\"" + data[0] + "\"><img src='" + ComplexTreeProperties.getImageSrc(image) +
                      "' title='" + data[2] + "' alt='" + data[2] + "' border='0' /></a>\n";
                res += tmp;
            }
            image = parseInt(data[4], 10);
            if (data[3]) {
                tmp = "<a href=\"" + data[3] + "\"><img src='" + ComplexTreeProperties.getImageSrc(image) +
                      "' title='" + data[5] + "' alt='" + data[5] + "' border='0' /></a>\n";
                res += tmp;
            }
            image = parseInt(data[7], 10);
            if (data[6]) {
                tmp = "<a target='_new' folder='" + ComplexTreeProperties.webdavPath + escape(data[6]) +
                      "' style='behavior:url(#default#AnchorClick)'><img src='" + ComplexTreeProperties.getImageSrc(image) +
                      "' alt='IE Folder' border='0' /></a>\n";
                res += tmp;
            }
            return res;

        case ComplexTreeProperties.CATEGORY_LAUNCHERS:
            var res = "";
            var image = parseInt(data[1], 10);
            if (data[0]) {
                tmp = "<a href=\"" + data[0] + "\"><img src='" + ComplexTreeProperties.getImageSrc(image) +
                      "' title='" + data[2] + "' alt='" + data[2] + "' border='0' /></a>\n";
                res += tmp;
            }
            image = parseInt(data[4], 10);
            if (data[3]) {
                tmp = "<a href=\"" + data[3] + "\"><img src='" + ComplexTreeProperties.getImageSrc(image) +
                      "' title='" + data[5] + "' alt='" + data[5] + "' border='0' /></a>\n";
                res += tmp;
            }
            image = parseInt(data[7], 10);
            if (data[6]) {
                tmp = "<a href=\"" + data[6] + "\"><img src='" + ComplexTreeProperties.getImageSrc(image) +
                      "' title='" + data[8] + "' alt='" + data[8] + "' border='0' /></a>\n";
                res += tmp;
            }
            image = parseInt(data[10], 10);
            if (data[9]) {
                tmp = "<a href=\"" + data[9] + "\"><img src='" + ComplexTreeProperties.getImageSrc(image) +
                      "' title='" + data[11] + "' alt='" + data[11] + "' border='0' /></a>\n";
                res += tmp;
            }
            return res;

        case ComplexTreeProperties.CATEGORY_RADIO:
            return "<input type='radio' name='newParentKey' " + (data[1] ? "disabled='disabled'" : "") + " value='" + data[0] + "' />";

        case ComplexTreeProperties.CATEGORY_CHECKBOX:
            return "<input onclick='javascript:clicked(this)' type='checkbox' " + (data[1] ? "checked='checked'" : "") + " name='category_" + data[0] + "' />";

        case ComplexTreeProperties.PORTLET_CHECKBOX:
            var imgAllSources = "<img src='" + ComplexTreeProperties.CONTEXT + ComplexTreeProperties.PORTLET_CATEGORY_ALLSOURCES_SRC + "' />"
            return "<input onclick='javascript:this.value=true;' type='checkbox' " + (data[1] ? "checked='checked'" : "") + " name='category_" + data[0] + "' />" + (data[2] ? imgAllSources : "");

        default:
            DBG.println("ComplexTreeProperties.getHtml - Not Found: " + type);
            return null;
    }
}

/**
 * Similar to getHtml but for multiple items
 */
ComplexTreeProperties.getHtmls =
function (pattern, data, enable, props) {
    var result = "";
    var count = 0;
    for (var i = 0; i < pattern.length; i++) {
        var tmp = new Array();
        for (var j = 0; j < ComplexTreeProperties.getPatternItemSize(pattern[i]); j++) {
            tmp[j] = data[count];
            count++;
        }
        result += ComplexTreeProperties.getHtml(pattern[i], tmp, enable, props);
        // If the first pattern is empty, break.
        if ((result.length == 0 || ComplexTreeProperties.Error) && ! ComplexTreeProperties.CONTINUE_IF_EMPTY) {
            ComplexTreeProperties.Error = false;
            return result;
        }
        ComplexTreeProperties.CONTINUE_IF_EMPTY = false;
    }
    return result;
}

/**
 *
 */
ComplexTreeProperties.getWorkflowLauncher =
function (param, objectKey) {
    return "javascript:handleActionChanges('display&display=" + param + "&obj=" + objectKey + "');";
}

ComplexTreeProperties.getTimeBasedPublishingLauncher =
function (objectInfo) {
    var launcher = "handleTimeBasedPublishing(event,'";
    launcher += objectInfo.timeBasedPublishingActionURL;
    launcher += "','";
    launcher += objectInfo.key;
    launcher += "','/op/edit/pid/";
    launcher += objectInfo.timeBasedPublishingPageId;
    launcher += "','";
    launcher += objectInfo.timeBasedPublishingDialogTitle;
    launcher += "');";
    return launcher;
}

