/********************************************************************************************************************************
* Licensed Materials - Property of IBM                                                                                          *
*                                                                                                                               *
* IBM Cognos Products: AGS                                                                                                      *
*                                                                                                                               *
* (C) Copyright IBM Corp. 2005, 2008                                                                                            *
*                                                                                                                               *
* US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
*********************************************************************************************************************************/

function CList (sId, bAllowDuplicates, sStyle,oUiStyle) {
    this.m_sId = sId;
    this.m_bAllowDuplicates = bAllowDuplicates;
    this.childCount = 0;
    this.m_oUiStyle = oUiStyle;
    this.m_bDisabled = false;

    this.m_fOnContextMenu = null;
    this.m_fSingleClickFunc = null;
    this.m_fDoubleClickFunc = null;
    this.m_fDragStartFunc = null;
    this.m_fDragFunc = null;
    this.m_fDragEndFunc = null;
    this.m_fDragEnterFunc = null;
    this.m_fDragLeaveFunc = null;
    this.m_fDragOverFunc = null;
    this.m_fOnDropFunc = null;
    this.m_fEqualityFunc = null;
    
    this.listElement = document.createElement("ul");
    this.listElement.listObject = this;
    this.listElement.getParentListObject = function() {return this.listObject};
    this.listElement.style.cursor = 'default';
    this.listElement.setAttribute("id", sId);
    if (sStyle && sStyle != 'undefined')
        this.listElement.className = sStyle;
}

function CList_getListElement() {
    return this.listElement;
}

function CList_getId() {
    return this.m_sId;
}

function CList_size() {
    return this.childCount;
}

function CList_setDisabled(val) {
    this.m_bDisabled = val;
}

function CList_isDisabled() {
    return this.m_bDisabled;
}

function CList_setDblClickFunc(val) {
    this.m_fDoubleClickFunc = val;
}

function CList_setSingleClickFunc(val) {
    this.m_fSingleClickFunc = val;
}

function CList_setContextMenuClickFunc(val) {
    this.m_fOnContextMenu = val;
}

function CList_setDragStartFunc(val) {
    this.m_fDragStartFunc = val;
}

function CList_setDragFunc(val) {
    this.m_fDragFunc = val;
}

function CList_setDragEndFunc(val) {
    this.m_fDragEndFunc = val;
}

function CList_setDragEnterFunc(val) {
    this.m_fDragEnterFunc = val;
}

function CList_setDragLeaveFunc(val) {
    this.m_fDragLeaveFunc = val;
}

function CList_setDragOverFunc(val) {
    this.m_fDragOverFunc = val;
}

function CList_setOnDropFunc(val) {
    this.m_fOnDropFunc = val;
}

function CList_setEqualityFunc(val) {
    this.m_fEqualityFunc = val;
}

function CList_getDblClickFunc() {
    return this.m_fDoubleClickFunc;
}

function CList_getSingleClickFunc() {
    return this.m_fSingleClickFunc;
}

function CList_getContextMenuClickFunc() {
    return this.m_fOnContextMenu;
}
                              
function CList_getDragStartFunc() {
    return this.m_fDragStartFunc;
}

function CList_getDragFunc() {
    return this.m_fDragFunc;
}

function CList_getDragEndFunc() {
    return this.m_fDragEndFunc;
}

function CList_getDragEnterFunc() {
    return this.m_fDragEnterFunc;
}

function CList_getDragLeaveFunc() {
    return this.m_fDragLeaveFunc;
}

function CList_getDragOverFunc() {
    return this.m_fDragOverFunc;
}

function CList_getOnDropFunc() {
    return this.m_fOnDropFunc;
}

function CList_getEqualityFunc() {
    return this.m_fEqualityFunc;
}

function CList_getStyle() {
    return this.m_oUiStyle;
}

function CList_setStyle(style) {
    this.m_oUiStyle = style;
}

function CList_onmouseOver() {
    CList_doMouseOver(this);
}

function CList_doMouseOver(object) {
    if (object && object.getParentListObject().isDisabled()) {
        return;
    }

    if (typeof object.getParentListObject().getStyle() == "object") {
        object.className = object.getParentListObject().getStyle().getRolloverState();
    }
    var ul = object.getParentListObject().getListElement();
    ul.overId = object.id;
}

function CList_onmouseOut() {
    CList_doMouseOut(this);
}

function CList_doMouseOut(object) {
    if (object && object.getParentListObject().isDisabled()) {
        return;
    }

    if (typeof object.getParentListObject().getStyle() == "object") {
        object.className = object.getParentListObject().getStyle().getNormalState();
    }
    var ul = object.getParentListObject().getListElement();
    ul.overId = "";
}

function CList_doClick(event,object) {
    if (object && object.getParentListObject().isDisabled()) {    
        return;
    }

    if (event.ctrlKey) {
        CList_ctrlClicked(object);
    } else if (event.shiftKey) {
        CList_shiftClicked(object);
    } else {
        CList_clicked(object);
    }
}

function CList_clicked(object) {
    var parent = object.getParentListObject();
    var ul = parent.getListElement();
    ul.selectedId = object.id;
    if (object.isSelected && parent.getSelectedNodes().length < 2) {
        parent.deSelectAll();
    } else {
        parent.deSelectAll();
        parent.selectNodeList(object);
    }
}

function CList_shiftClicked(object) {
    var parent = object.getParentListObject();
    parent.deSelectAll();
    var ul = parent.getListElement();
    var startIndex = parent.indexById(ul.selectedId);
    var endIndex = parent.indexById(object.id);

    if (startIndex >= endIndex) {
        endIndex = startIndex;
        startIndex = parent.indexById(object.id);
    }

    parent.selectRange(startIndex,endIndex);
}

function CList_ctrlClicked(object) {
    var parent = object.getParentListObject();
    var ul = parent.getListElement();
    ul.selectedId = object.id;
    if (object.isSelected) {
        parent.deSelectNodeList(object);
    } else {
        parent.selectNodeList(object);
    }
}

function CList_selectRange(start,end) {
    var ul = this.getListElement();
    for (var i = start; i <= end; ++i) {
        var li = ul.childNodes[i];
        if (li && li.tagName == 'LI') {
            this.selectNodeList(li);
        }
    }
}

function CList_selectNodeList(object) {
    object.onclick = CList_singleClickCaller;
    if (typeof this.getStyle() == "object") {
        object.className = this.getStyle().getDepressedState();
    }
    object.onmouseover = null;
    object.onmouseout = null;
    object.isSelected = true;
}

function CList_deSelectNodeList(object) {
    if (typeof this.getStyle() == "object") {
        object.className = this.getStyle().getNormalState();
    }
    object.onmouseover = CList_onmouseOver;
    object.onmouseout = CList_onmouseOut;
    object.isSelected = false;
}

function CList_deSelectAll () {
    var ul = this.getListElement();
    for (var i = 0; i < ul.childNodes.length; ++i) {
        var li = ul.childNodes[i];
        if (li && li.tagName == 'LI') {
            this.deSelectNodeList(li);
        }
    }
}

function CList_getAllItems() {
    return this.item(0, this.childCount);
}

function CList_getAllNodes() {
    var result = new Array();
    var ul = this.getListElement();
    for (var i = 0; i < ul.childNodes.length; ++i) {
        var li = ul.childNodes[i];
        if (li && li.tagName == 'LI') {
            result.push(li);
        }
    }

    return result;
}

function CList_getAllSelectedItems () {
    var result = new Array();
    var ul = this.getListElement();
    for (var i = 0; i < ul.childNodes.length; ++i) {
        var li = ul.childNodes[i];
        if (li && li.tagName == 'LI' && li.isSelected) {
            //Should ever be only one here from our side
            //of the border at least. This is the node
            //The user has given for us to insert.
            result.push(li.childNodes.item(0));
        }
    }
    return result;
}

function CList_getNodeByIndex (idx) {
    var ul = this.getListElement();
    if (ul.childNodes.length > 0) {
        return ul.childNodes[idx];
    }
    return null;
}

function CList_getNodeByProperty(value, property) {
    var result = new Array();
    var ul = this.getListElement();
    for (var i = 0; i < ul.childNodes.length; ++i) {
        var li = this.getNodeByIndex(i);
        if (li && li.tagName == 'LI' && li[property] == value) {
            result.push(li);
        }
    }
    return result;
}

function CList_getNodeById(id) {
    //only one with this id
    var nodeArray = this.getNodeByProperty(id, 'id')

    if (nodeArray.length == 1) {
        return nodeArray[0];
    }

    return null;
}

function CList_getSelectedNodes () {
    return this.getNodeByProperty(true,'isSelected');
    /*
    var result = new Array();
    
    
    var ul = this.getListElement();
    
    for (var i = 0; i < ul.childNodes.length; ++i) {
        var li = ul.childNodes[i];
        if (li && li.tagName == 'LI' && li.isSelected) {
            result.push(li);
        }
    }
    return result;
    */
}

function CList_containsItem(value) {
    if (this.getEqualityFunc() != null) {
        var equalFunc = this.getEqualityFunc();
        return equalFunc(this,value);
    }
    return false;
}

function CList_item(start,end) {
    var ul = this.getListElement();
    if (start && !end || end == 'undefined') {
        //Return the actual node inside the LI
        return ul.childNodes[start].childNodes.item(0);
    }

    var result = new Array();

    for (var i = start; i <= end; ++i) {
        var li = ul.childNodes[i];
        if (li && li.tagName == 'LI') {
            result.push(li.childNodes.item(0));
        }
    }

    return result;
}

function CList_add(node,index,existingId) {
    if (!this.m_bAllowDuplicates && this.getEqualityFunc() != null && this.containsItem(node)) {
        //We should not allow duplicates and we have an equality check functions and item
        //exists.
        return false;
    }
    
    var el = this.getListElement();
    var referenceNode =null;

    if (index && index != 'undefined') {
        referenceNode = el.childNodes[index];
    } else if (el.overId && el.overId != "") {
        referenceNode = this.getNodeById(el.overId);
    } else if (this.getSelectedNodes().length == 1) {
        referenceNode = this.getSelectedNodes()[0];
    }

    var insertNode = CList_createNode(this,existingId);
    insertNode.appendChild(node);

    if (referenceNode) {
        el.insertBefore(insertNode,referenceNode);
    } else {
        el.appendChild(insertNode);
    }
    
    insertNode.style.height="16px";

    this.deSelectAll();
    this.selectNodeList(insertNode);

    return true;
}

function CList_removeSelected() {
    var selectedNodes = this.getSelectedNodes();
    var ul = this.getListElement();

    for (var i=0; i < selectedNodes.length;i++) {
        ul.removeChild(selectedNodes[i]);
        --this.childCount;
    }
}

function CList_remove(index) {
    if (!index || index == 'undefined') {
        index = 0;
    }

    var ul = this.getListElement();
    if (ul && ul.hasChildNodes && ul.removeChild) {
        var node = ul.childNodes[index]
        ul.removeChild(node);
    }
    --this.childCount;
}

function CList_removeAllNodes() {
    var rootNode = this.getListElement();
    if (rootNode && rootNode.hasChildNodes && rootNode.removeChild) {
        while (rootNode.hasChildNodes()) {
            rootNode.removeChild(rootNode.firstChild);
        }
    }
    this.childCount = 0;
}

function CList_createNode(parent,existingId) {
    var li = document.createElement('li');
    CList_disableAllEvents(li);
    li.onmouseover = CList_onmouseOver;
    li.onmouseout = CList_onmouseOut;
    li.onclick = CList_singleClickCaller;
    li.ondblclick = CList_doubleClickCaller;
    li.oncontextmenu = CList_contextMenuCaller;
    li.ondragstart = CList_dragStartCaller;
    li.ondrag = CList_dragCaller;
    li.ondragend = CList_dragEndCaller;
    li.ondragenter = CList_dragEnterCaller;
    li.ondragleave = CList_dragLeaveCaller;
    li.ondragover = CList_dragOverCaller;
    li.ondrop = CList_OnDropCaller;
    
    ++parent.childCount;
    if (existingId == undefined) {
        li.setAttribute('id',parent.getId() + parent.childCount);
    }
    else {
        li.setAttribute('id',existingId);    
    }
    
    li.listObject = parent;
    li.getParentListObject = function() {return this.listObject};
    return li;
}

function CList_indexById(id) {
    if (!id || id == 'undefined') {
        return;
    }

    var result = 0;
    var ul = this.getListElement();
    for (var i = 0; i < ul.childNodes.length; ++i) {
        var li = ul.childNodes[i];
        if (li && li.tagName == 'LI' && id == li.id) {
            result = i;
            break;
        }
    }
    return result;
}

function CList_contextMenuCaller(evt)
{
    //get the event in a cross-browser fashion
    evt = (evt) ? evt : ((event) ? event : null);

    //cancel any text selection
    CList_clearSelection();

    //prevent the event from bubbling to other elements
    CList_cancelBub(evt);

    var rootNode = this.getParentListObject();

    if (rootNode.getContextMenuClickFunc() != null && !rootNode.isDisabled())
    {
        var contextMenuFunc = rootNode.getContextMenuClickFunc();
        contextMenuFunc(evt);
        CList_cancelBub(evt);
        if (!document.all)
        {
            evt.preventDefault();
        }
        return false;
    }
}

function CList_singleClickCaller(evt)
{
    if (this.parentNode.listObject.isDisabled()) {
        return;
    }

    //get the event in a cross-browser fashion
    evt = (evt) ? evt : ((event) ? event : null);

    if ((evt.keyCode != null) && (evt.keyCode != 13) && (evt.keyCode != 0))
    {
        return false;
    }

    //cancel any text selection
    CList_clearSelection();

    //prevent the event from bubbling to other elements
    CList_cancelBub(evt);

    var rootNode = this.getParentListObject();

    if (rootNode.isDisabled()) {
        return;
    }

    CList_doClick(evt,this);

    if (rootNode.getSingleClickFunc() != null)
    {
        var singleClickFunc = rootNode.getSingleClickFunc();
        singleClickFunc(evt);
        CList_cancelBub(evt);
        if (!document.all)
        {
            evt.preventDefault();
        }
        return false;
    }
}

function CList_doubleClickCaller(evt)
{
    if (this.parentNode.listObject.isDisabled()) {
        return;
    }

    //get the event in a cross-browser fashion
    evt = (evt) ? evt : ((event) ? event : null);

    //cancel any text selection
    CList_clearSelection();

    //prevent the event from bubbling to other elements
    CList_cancelBub(evt);

    var rootNode = this.getParentListObject();

    if (rootNode.getDblClickFunc() != null && !rootNode.isDisabled())
    {
        var doubleClickFunc = rootNode.getDblClickFunc();
        doubleClickFunc(evt);
        CList_cancelBub(evt);
        if (!document.all)
        {
            evt.preventDefault();
        }
        return false;
    }
}

function CList_dragStartCaller(evt)
{
    if (this.parentNode.listObject.isDisabled()) {
        return;
    }

    //get the event in a cross-browser fashion
    evt = (evt) ? evt : ((event) ? event : null);

    //cancel any text selection
    CList_clearSelection();

    //prevent the event from bubbling to other elements
    CList_cancelBub(evt);

    var rootNode = this.getParentListObject();

    if (rootNode.getDragStartFunc() != null && !rootNode.isDisabled())
    {
        var dragStartFunc = rootNode.getDragStartFunc();
        dragStartFunc(evt);
        CList_cancelBub(evt);
        if (!document.all)
        {
            evt.preventDefault();
        }
        return false;
    }
}

function CList_dragCaller(evt)
{
    if (this.parentNode.listObject.isDisabled()) {
        return;
    }

    //get the event in a cross-browser fashion
    evt = (evt) ? evt : ((event) ? event : null);

    //cancel any text selection
    CList_clearSelection();

    //prevent the event from bubbling to other elements
    CList_cancelBub(evt);

    var rootNode = this.getParentListObject();

    if (rootNode.getDragFunc() != null && !rootNode.isDisabled())
    {
        var dragFunc = rootNode.getDragFunc();
        dragFunc(evt);
        CList_cancelBub(evt);
        if (!document.all)
        {
            evt.preventDefault();
        }
        return false;
    }
}

function CList_dragEndCaller(evt)
{
    if (this.parentNode.listObject.isDisabled()) {
        return;
    }

    //get the event in a cross-browser fashion
    evt = (evt) ? evt : ((event) ? event : null);

    //cancel any text selection
    CList_clearSelection();

    //prevent the event from bubbling to other elements
    CList_cancelBub(evt);

    var rootNode = this.getParentListObject();

    if (rootNode.getDragEndFunc() != null && !rootNode.isDisabled())
    {
        var dragEndFunc = rootNode.getDragEndFunc();
        dragEndFunc(evt);
        CList_cancelBub(evt);
        if (!document.all)
        {
            evt.preventDefault();
        }
        return false;
    }
}

function CList_dragEnterCaller(evt)
{
    if (this.parentNode.listObject.isDisabled()) {
        return;
    }

    //get the event in a cross-browser fashion
    evt = (evt) ? evt : ((event) ? event : null);

    // set the cursor shape
    evt.dataTransfer.dropEffect="move";

    //cancel any text selection
    CList_clearSelection();

    //prevent the event from bubbling to other elements
    CList_cancelBub(evt);

    var rootNode = this.getParentListObject();

    if (rootNode.getDragEnterFunc() != null && !rootNode.isDisabled())
    {
        var dragEnterFunc = rootNode.getDragEnterFunc();
        dragEnterFunc(evt);
        CList_cancelBub(evt);
        if (!document.all)
        {
            evt.preventDefault();
        }
    }

    return false;
}

function CList_dragLeaveCaller(evt)
{
    //get the event in a cross-browser fashion
    evt = (evt) ? evt : ((event) ? event : null);
    
    //cancel any text selection
    CList_clearSelection();

    //prevent the event from bubbling to other elements
    CList_cancelBub(evt);

    var rootNode = this.getParentListObject();

    if (rootNode.isDisabled()) {
        return;
    }

    var liNode = CList_getUINode(evt,this);

    if (liNode.isSelected) {
        rootNode.selectNodeList(liNode);
    } else {
        CList_doMouseOut(liNode);
    }

    if (rootNode.getDragLeaveFunc() != null)
    {
        var dragOverFunc = rootNode.getDragLeaveFunc();
        dragLeaveFunc(evt);
        CList_cancelBub(evt);
        if (!document.all)
        {
            evt.preventDefault();
        }
    }
    return false;
}

function CList_dragOverCaller(evt)
{
    if (this.parentNode.listObject.isDisabled()) {
        return;
    }

    //get the event in a cross-browser fashion
    evt = (evt) ? evt : ((event) ? event : null);
    
    //cancel any text selection
    CList_clearSelection();

    //prevent the event from bubbling to other elements
    CList_cancelBub(evt);

    var rootNode = this.getParentListObject();

    if (rootNode.isDisabled()) {
        return;
    }

    var liNode = CList_getUINode(evt,this);

    CList_doMouseOver(liNode);

    if (rootNode.getDragOverFunc() != null)
    {
        var dragOverFunc = rootNode.getDragOverFunc();
        dragOverFunc(evt);
        CList_cancelBub(evt);
        if (!document.all)
        {
            evt.preventDefault();
        }
    }
    return false;
}

function CList_OnDropCaller(evt)
{
    if (this.parentNode.listObject.isDisabled()) {
        return;
    }

    //get the event in a cross-browser fashion
    evt = (evt) ? evt : ((event) ? event : null);
    
    //cancel any text selection
    CList_clearSelection();

    //prevent the event from bubbling to other elements
    CList_cancelBub(evt);

    var rootNode = this.getParentListObject();

    if (rootNode.isDisabled()) {
        return;
    }

    var liNode = CList_getUINode(evt,this);

    if (rootNode.getOnDropFunc() != null)
    {
        var onDropFunc = rootNode.getOnDropFunc();
        onDropFunc(evt);
        CList_cancelBub(evt);
        if (!document.all)
        {
            evt.preventDefault();
        }
    }
    return false;
}

//find the element that the event occurred
function CList_getUINode (evt,parent)
{
    //get the element that trapped the event in a cross-browser fashion
	var	uiNode = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);

	//check to see if this is a text node.
	while (uiNode.tagName != 'LI')
	{
	    if (uiNode.parentNode.getAttribute('id').toString().localeCompare(parent.id) != 0) {
	        //We have reached the parent UL stop here.
	        break;
	    }
		//this is a text node, get the parent node
		uiNode = uiNode.parentNode;
	}

	return uiNode;
}

function CList_disableAllEvents(element) {
    if (document.all)
    {
        element.attachEvent("onmouseover", function() {window.status='';return true;});
        element.attachEvent("onmouseout", function() {window.status='';return true;});
        element.attachEvent("onmouseup", function(e) {window.status='';CList_clearSelection();CList_cancelBub(e);e.returnValue = false;});
        element.attachEvent("onmousedown", function(e) {window.status='';CList_clearSelection();CList_cancelBub(e);e.returnValue = false;});
        element.attachEvent("onmousemove", function(e) {window.status='';CList_clearSelection();CList_cancelBub(e);e.returnValue = false;});
        element.attachEvent("onclick", function(e) {window.status='';CList_clearSelection();CList_cancelBub(e);e.returnValue = false;});
        element.attachEvent("ondblclick", function(e) {window.status='';CList_clearSelection();CList_cancelBub(e);e.returnValue = false;});
    }
    else
    {
        element.addEventListener("mouseover", function() {window.status='';return false;}, true);
        element.addEventListener("mouseout", function() {window.status='';return false;}, true);
        element.addEventListener("mouseup", function(e) {window.status='';e.preventDefault();return false;}, true);
        element.addEventListener("mousedown", function(e) {window.status='';e.preventDefault();return false;}, true);
        element.addEventListener("mousemove", function(e) {window.status='';e.preventDefault();return false;}, true);
        element.addEventListener("click", function(e) {window.status='';e.preventDefault();return false;}, true);
        element.addEventListener("dblclick", function(e) {window.status='';CList_clearSelection();CList_cancelBub(e);e.preventDefault();return false;}, true);
    }
}

//prevent the event from bubbling to other elements
function CList_cancelBub(evt)
{
    //get the event in a cross-browser fashion
    evt = (evt) ? evt : ((event) ? event : null);

    //prevent the click from proceeding to other nodes
    if (typeof evt.cancelBubble != 'undefined')
    {
        evt.cancelBubble = true;
    }

    if (typeof evt.stopPropagation != 'undefined')
    {
        evt.stopPropagation();
    }
}

function CList_clearSelection()
{
    if (typeof document.selection != 'undefined' && document.selection.createRange().text != "")
    {
        //IE specific
        document.selection.empty();
    }
    else if (typeof window.getSelection == 'function' && typeof window.getSelection() == "object")
    {
        //NS6 specific
        window.getSelection().removeAllRanges();
    }
}

function CList_up(nodeId)
{
    var node = this.getNodeById(nodeId);
    
    if (node != null && node.childNodes.length==1) {
    
        var index = this.indexById(nodeId);
        
        //is the node already at the top of the list?
        if (index > 0) {
            var newPos = index-1;
            var el = this.getListElement();    
            var previousNode = el.childNodes[newPos];

            //create the new node
            var insertNode = CList_createNode(this,nodeId);
            var nodeContent = node.childNodes[0];
            insertNode.appendChild(nodeContent);
            
            //remove the old one
            this.remove(index);

            //insert the node
            el.insertBefore(insertNode,previousNode);
            
            this.selectRange(newPos,newPos);
        }
    }
}
function CList_down(nodeId)
{
    var index = this.indexById(nodeId);
    var node = this.getNodeById(nodeId);
    
    if (node != null && node.childNodes.length==1) {
    
        var lastIndex = this.size()-1;
        
        //the position of the sibling underneath the one to be inserted
        var nextSiblingPos = index+2;
        
        //the position of the new item
        var newPos = index+1
        if (nextSiblingPos > lastIndex) {
            this.toBottom(nodeId);
        }
        //is the node already the last item in the list?
        else if (index < lastIndex) {
            var el = this.getListElement();    
            var nextNode = el.childNodes[nextSiblingPos];

            //create the new node
            var insertNode = CList_createNode(this,nodeId);
            var nodeContent = node.childNodes[0];
            insertNode.appendChild(nodeContent);
            
            //remove the old one
            this.remove(index);

            //insert the node
            el.insertBefore(insertNode,nextNode);
            
            this.selectRange(index+1,index+1);
        }
    }    
}
function CList_toTop(nodeId)
{
    var node = this.getNodeById(nodeId);
    
    if (node != null && node.childNodes.length==1) {
        var index = this.indexById(nodeId);
    
        //is the node already the first item in the list?
        if (index > 0) {
            this.remove(index);
            var el = this.getListElement();    
            var firstNode = el.childNodes[0];

            //create the new node
            var nodeContent = node.childNodes[0];
            var insertNode = CList_createNode(this,nodeId);
            insertNode.appendChild(nodeContent);
            
            //place the node at the top
            el.insertBefore(insertNode,firstNode);
            
            this.selectRange(0,0);
        }
    }
}

function CList_toBottom(nodeId)
{
    var node = this.getNodeById(nodeId);
    
    if (node != null && node.childNodes.length==1) {
    
        var index = this.indexById(nodeId);
        var lastIndex = this.size()-1;
        
        //is the node already at the bottom of the list?
        if (index < lastIndex) {
            this.remove(index);
            var el = this.getListElement();    

            //create the new node
            var nodeContent = node.childNodes[0];
            var insertNode = CList_createNode(this,nodeId);
            insertNode.appendChild(nodeContent);
            
            //place the node at the bottom
            el.appendChild(insertNode);
            
            this.selectRange(lastIndex,lastIndex);
        }
    }
}

CList.prototype.getAllSelectedItems = CList_getAllSelectedItems;
CList.prototype.getSelectedNodes = CList_getSelectedNodes;
CList.prototype.selectRange = CList_selectRange;
CList.prototype.selectNodeList = CList_selectNodeList;
CList.prototype.deSelectNodeList = CList_deSelectNodeList;
CList.prototype.deSelectAll = CList_deSelectAll;

CList.prototype.size = CList_size;
CList.prototype.getAllItems = CList_getAllItems;
CList.prototype.getAllNodes = CList_getAllNodes;
CList.prototype.getNodeByIndex = CList_getNodeByIndex;
CList.prototype.getNodeByProperty = CList_getNodeByProperty;
CList.prototype.getNodeById = CList_getNodeById;
CList.prototype.containsItem = CList_containsItem;

CList.prototype.up = CList_up;
CList.prototype.down = CList_down;
CList.prototype.toTop = CList_toTop;
CList.prototype.toBottom = CList_toBottom;

CList.prototype.add = CList_add;
CList.prototype.item = CList_item;
CList.prototype.remove = CList_remove;
CList.prototype.removeSelected = CList_removeSelected;
CList.prototype.removeAllNodes = CList_removeAllNodes;

CList.prototype.getId = CList_getId;
CList.prototype.setStyle = CList_setStyle;
CList.prototype.getStyle = CList_getStyle;
CList.prototype.getListElement = CList_getListElement;
CList.prototype.indexById = CList_indexById;

CList.prototype.setDisabled = CList_setDisabled;
CList.prototype.isDisabled = CList_isDisabled;

CList.prototype.setDblClickFunc = CList_setDblClickFunc;
CList.prototype.setSingleClickFunc = CList_setSingleClickFunc;
CList.prototype.setContextMenuClickFunc = CList_setContextMenuClickFunc;
CList.prototype.getDblClickFunc = CList_getDblClickFunc;
CList.prototype.getSingleClickFunc = CList_getSingleClickFunc;
CList.prototype.getContextMenuClickFunc = CList_getContextMenuClickFunc;

CList.prototype.setDragStartFunc = CList_setDragStartFunc;
CList.prototype.setDragFunc = CList_setDragFunc;
CList.prototype.setDragEndFunc = CList_setDragEndFunc;
CList.prototype.setDragEnterFunc = CList_setDragEnterFunc;
CList.prototype.setDragLeaveFunc = CList_setDragLeaveFunc;
CList.prototype.setDragOverFunc = CList_setDragOverFunc;
CList.prototype.setOnDropFunc = CList_setOnDropFunc;
CList.prototype.setEqualityFunc = CList_setEqualityFunc;

CList.prototype.getDragStartFunc = CList_getDragStartFunc;
CList.prototype.getDragFunc = CList_getDragFunc;
CList.prototype.getDragEndFunc = CList_getDragEndFunc;
CList.prototype.getDragEnterFunc = CList_getDragEnterFunc;
CList.prototype.getDragLeaveFunc = CList_getDragLeaveFunc;
CList.prototype.getDragOverFunc = CList_getDragOverFunc;
CList.prototype.getOnDropFunc = CList_getOnDropFunc;
CList.prototype.getEqualityFunc = CList_getEqualityFunc;