//
// this.build_root=function()
// this.build_collection=function(CollectionID)
// this.build_message=function(CollectionID, MsgID, MsgEvenness)
// this.build_header_message=function(CollectionID, MsgID, Mode, IsVisible)
//-----------------------------------------------------------------------------------------------------
// this.redraw_header_message=function(CollectionID, MsgID, Mode, IsVisible)
// this.redraw_collection=function(CollectionID)
// this.redraw=function()  							// redraws whole treeview
//-----------------------------------------------------------------------------------------------------
// this.add_message_node=function(CollectionID, MsgID, InsertPosition)
// this.add_collection_node=function(msgs, collectionName, caption)
// this.click=function(CollectionID)
//
// function ActivateAssoc(AssocID) 		--> G_Assocs[AssocID].TreeView.redraw();
// function AddAssoc(AssocObj) 			--> G_Assocs[AssocID].TreeView.redraw();
//-----------------------------------------------------------------------------------------------------
// function go_first_page(CollectionID) 					--> G_Assocs[G_ActiveAssocID].TreeView.redraw_collection(CollectionID);
// function go_last_page(CollectionID) 						--> G_Assocs[G_ActiveAssocID].TreeView.redraw_collection(CollectionID);
// function go_prev_page(CollectionID) 						--> G_Assocs[G_ActiveAssocID].TreeView.redraw_collection(CollectionID);
// function go_next_page(CollectionID) 						--> G_Assocs[G_ActiveAssocID].TreeView.redraw_collection(CollectionID);
// function CounterRefresh(AssocID, CollectionID, Counter) 	--> G_Assocs[AssocID].TreeView.redraw_collection(CollectionID);
// function LinkToCollectionMsg(CollectionName, MsgObjID) 	--> G_Assocs[G_ActiveAssocID].TreeView.redraw_collection(CollectionId);
// function OnSortItemClick(Sort_Type, CollectionID) 		--> G_Assocs[G_ActiveAssocID].TreeView.redraw_collection(CollectionID);
// function release(evt) 									--> G_Assocs[G_ActiveAssocID].TreeView.redraw_collection(CollectionID);
//
// /////////////////////////////////////////////////////////////////////////////////////////////////////
// 											TreeView Object
function CreateTree(AssocID, name, spanid) // main TreeView object
{
  this._name = name;       // name of object 						: "tree"
  this._spanid = spanid;     // id of existing div used for treeview : "TreeView_element" link to code of container
  this._associationID = AssocID;	//	link to association
  this._collections = {}; 		//	new Array(); that will contain collections
  this._collectionIdByName = {}; 		//	new Array(); that will contain names of collections

  this._image_collapsed = 'Pics/collapsed.gif';	// image for parent nodes	when they are collapsed
  this._image_expanded = 'Pics/expanded.gif';	// image for parent nodes	when they are expanded

  this.root = {
    _id: name + '_root',   			// name
    _childrencount: 0,				// quantity of children
    _children: []      				// children array
  };

  // /////////////////////////////////////////////////////////////////////////////////////////////////////
  // (R)
  this.build_root = function () {
    var html_code = '<div id="' + this.root._id + '" >\n';
    html_code += '<table width="100%" cellpadding="0" cellspacing="0" border="0">';

    for (i in this.root._children) {
      html_code += '<tr><td>' + this.build_collection(i) + '</td></tr>';
    }

    html_code += '</table></div>';
    return html_code;
  };

  // /////////////////////////////////////////////////////////////////////////////////////////////////////
  // (R) build interface collection from core collection
  this.build_collection = function (CollectionID) {
    //-----------------------------------------------------------------------------------------
    var collection = this.root._children[CollectionID];
    var msgs = this._collections[CollectionID].obj;
    var CollectionChildrenCount = msgs.Method0('M_GetCount');
    //-----------------------------------------------------------------------------------------
    var Important_sign = '';
    var header_menu_html = '';
    var sub_collection_html = '';
    var collection_html = '';
    //-----------------------------------------------------------------------------------------
    var MsgScrollersExist = false;
    var Prev_html = '';
    var Next_html = '';
    var Prev_exist = false;
    var Next_exist = false;
    var msg = null;
    var first_msg = null;

    var Select_html = '';
    //-----------------------------------------------------------------------------------------
    if (this._collections[CollectionID].name == 'Important') {
      var AssocElement = document.getElementById('Assoc_' + this._associationID);
      AssocElement.all.Important_warning.style.visibility = 'hidden';

      if (CollectionChildrenCount > 0) {
        AssocElement.all.Important_warning.style.visibility = 'inherit';
        Important_sign = ''; // '<span><img src="Pics/warning_small.gif"></span> ';
      }
    }
    //-----------------------------------------------------------------------------------------
    collection_html += '<div id="' + CollectionID + '" class="Collection_class"  onmousewheel="return scrollIt(\'' + CollectionID + '\');">'; // onmousewheel="return scrollIt(\''+CollectionID+'\');"

    if (CollectionChildrenCount == 0) {
      collection._empty = true;
    } else {// if (CollectionChildrenCount  > 0)
      collection._empty = false;

      if (collection._expanded == 1) {
        if (CollectionChildrenCount > external.Method1('M_GetGlobalOption', 'ItemsPerPage')) MsgScrollersExist = true;
        //----------------------------------------------------------------------------------------
        msg = msgs.GetFirst();
        first_msg = msg;
        var firstVisibleMsgID = null;
        if (msgs.Method0('M_GetFirstVisibleMessage')) firstVisibleMsgID = (msgs.Method0('M_GetFirstVisibleMessage')).objID;
        if (firstVisibleMsgID != msg.objID) { Prev_exist = true; } else { Prev_exist = false; }
        Prev_html = new CreateScrollControls('prev', Prev_exist, CollectionID, MsgScrollersExist);
        //----------------------------------------------------------------------------------------

        var SelectControlsExist = false;
        var CollectionObj = external.ObjById(CollectionID);
        CollectionSelectedItemsCount = CollectionObj.Method0('M_GetSelectedItemsCount');
        if (CollectionSelectedItemsCount > 0) SelectControlsExist = true;
        Select_html = new CreateSelectControls(CollectionID, SelectControlsExist);

        //----------------------------------------------------------------------------------------
        var MsgEvenness = 1 - collection._first_disp_msg_evenness;
        msg = msgs.Method0('M_GetFirstVisibleMessage');
        if (msg != null) var lastVisibleMsgID = msg.objID;

        while (msg != null) {
          MsgEvenness = 1 - MsgEvenness;
          sub_collection_html += this.build_message(CollectionID, msg.objID, MsgEvenness);
          msg = msgs.Method1('M_GetNextVisibleMessage', msg);
          if (msg != null) lastVisibleMsgID = msg.objID;
        }
        //----------------------------------------------------------------------------------------
        msg = msgs.GetLast();
        if (lastVisibleMsgID != msg.objID) { Next_exist = true; } else { Next_exist = false; }
        Next_html = new CreateScrollControls('next', Next_exist, CollectionID, MsgScrollersExist);
        //----------------------------------------------------------------------------------------

        //-----------------------------------------------------------------------------------------------
        // -------------------------- Collection header area begin ---------------------------------------
        //-----------------------------------------------------------------------------------------------
        collection_html += '\n' +
					'<div id="' + CollectionID + '_in" style="width:100%; position:relative; left:0;">' +
					'\n' +
					'<table class="ParentNode" border="0" cellpadding="0" cellspacing="0">' +
					'<tr>' +
					'<td valign=middle align=center oncontextmenu="StopContextMenu()">' +
					'<div style="width:30px;"><img onclick="OnCollectionExpandIconClick(\'' + this._associationID + '\',\'' + CollectionID + '\');" src="' +
					this._image_expanded + '">' +
					'</div>' +
					'</td>' +
					'<td oncontextmenu="StopContextMenu()" nowrap>' +
					'<span tabindex="4" onkeypress="OnCollectionExpandIconClick(\'' + this._associationID + '\',\'' + CollectionID + '\');" ' +
					'class="CollectionName" onclick="OnCollectionExpandIconClick(\'' + this._associationID + '\',\'' + CollectionID + '\');" ' +
					'style="cursor:hand;" title="' + external.LS('tooltip_' + this._collections[CollectionID].name + '_collection') + '">' +
					Important_sign + collection._caption + ' (<span id="' + CollectionID + '_caption">' + CollectionChildrenCount + '</span>) ' +
					'</span>';
        collection_html += '</td>' +

					'<td id="TopSelect_counter" valign="bottom" nowrap>' + Select_html.top_counter + '</td>' +

					'<td width="50%" align="left">' + '</td>' +

        //								'<td id="TopSelect_menu" valign="bottom" >'+Select_html.top_menu+'</td>'+
        //								'<td id="TopSelect_menu" valign="bottom" >'+'</td>'+

					'<td width="50%" align="left">' + '</td>' +

        //								'<td id="TopSelect_all" valign="bottom" >'+Select_html.top_button_select_all +'</td>'+
        //								'<td id="TopDeselect_all" valign="bottom" >'+Select_html.top_button_deselect_all +'</td>'+

					//						 		'<td id="TopPrev_end" valign="bottom" >'+Prev_html.top_end+'</td>'+
					//						 		'<td id="TopPrev_page" valign="bottom" >'+Prev_html.top_page+'</td>'+
					//						 		'<td id="TopPrev_msg" valign="bottom" >'+Prev_html.top_msg+'</td>'+
					//						 		'<td id="TopNext_msg" valign="bottom" >'+Next_html.top_msg+'</td>'+
					//						 		'<td id="TopNext_page" valign="bottom" >'+Next_html.top_page+'</td>'+
					//						 		'<td id="TopNext_end" valign="bottom" >'+Next_html.top_end+'</td>'+
					'</tr>' +

					'</table>' +
					'</div>' +
					'\n';
        //-----------------------------------------------------------------------------------------------
        // -------------------------- Collection header area end -----------------------------------------
        //-----------------------------------------------------------------------------------------------

        //----------------------------------------------------------------------------------------------------------------------------------------------------
        // Collection area begin -----------------------------------------------------------------------------------------------------------------------------
        //----------------------------------------------------------------------------------------------------------------------------------------------------

        collection_html += '<div id="' + CollectionID + '_message_list_container" style="position: relative;"> ' +
					//----------------------------------------------------------------------------------------------------------------------------------------------------
					'<table class="MessageList" border="0" cellspacing="0" cellpadding="0">' +
					'<tr>';
        collection_html += '<td width="100%">';
        //= =============================
        //--------------------------------------------------------------------------------------------
        // ------------------------------ Begin not for Important collection --------------------------
        //--------------------------------------------------------------------------------------------
        var csName = this._collections[CollectionID].name;
        if (!(csName == 'Important' || csName == 'Information')) {
          //----------------------------------------------------
          //----------------------------------------------------
          msgs = external.ObjByID(CollectionID);
          //----------------------------------------------------
          var AssocObj = external.ObjByID(G_ActiveAssocID);
          var SuperTreeList = AssocObj.GetM('m_SuperTreesPtr');
          var SuperTree_Obj = SuperTreeList.GetFirst();
          SuperTree_Obj = SuperTreeList.GetNext(SuperTree_Obj);
          //-------------------------------------------------------------------------------------------------------------------------------------------------------
          //		Head line with sort items - Winner Item will be replaced by Selected Items menu button (When SelectedITemsCounter > 0)
          //-------------------------------------------------------------------------------------------------------------------------------------------------------
          var sort_header_menu_html = BuildCollectionSortHeaderMenu(CollectionID);
          var WinningTreeID = CONST_WIN_NO_SYNC; // Vovas function
          var sort_select_header_menu_html = BuildCollectionSortSelectHeaderMenu(first_msg, MsgEvenness, CollectionID, WinningTreeID, true);

          header_menu_html = sort_header_menu_html;


          CollectionObj = external.ObjById(CollectionID);
          var SelectedItemsQuantity = CollectionObj.Method0('M_GetSelectedItemsCount');

          if (SelectedItemsQuantity > 0) header_menu_html = sort_select_header_menu_html; // select_header_menu_html;
          //= =========================
          collection_html += '<table id="' + CollectionID + '_container" sub_id="' + CollectionID + '" ' +
						'width="100%" border="0" cellspacing="0" cellpadding="0" class="Collection_Table" ' +
						'>' +
						header_menu_html +
						sub_collection_html +
						'</table>';
          //--------------------------------------------------------------------------------------------
          // ------------------------------ End not for Important collection ----------------------------
          //--------------------------------------------------------------------------------------------
        } else	// for Important collection
        {
          header_menu_html = BuildImportantCollectionHeader(CollectionID, csName);

          collection_html += '<table id="' + CollectionID + '_container" sub_id="' + CollectionID + '" ' +
						'width="100%" border="0" cellspacing="0" cellpadding="0" class="Collection_Table">';
          collection_html += header_menu_html;
          collection_html += sub_collection_html +
						'</table>';
        }

        collection_html += '</td>' +

					'<td class="MsgCollectionScrollBar" style="width:16px; height:100%; border-bottom: solid 1px #787864; border-top: solid 1px #787864; border-right: solid 1px #787864;">' +
					//-----------------------------------------------------------------
					'<table height="100%" style="background:#c0c0b4;" width="16px" border="0" cellpadding="0" cellspacing="0" id="' + CollectionID + '_ScrollBar">' +

					'<tr><td id="Prev_end"   style="padding-top: 1px;">' + Prev_html.end + '</td></tr>' +
					'<tr><td id="Prev_page"  style="padding-top: 1px;">' + Prev_html.page + '</td></tr>' +
					'<tr><td id="Prev_msg"   style="padding-top: 1px;">' + Prev_html.msg + '</td></tr>';
        collection_html += '<tr><td id="Scroll_all" style="padding-top: 1px;">' + Prev_html.scroll + '</td></tr>';
        collection_html += '<tr><td id="Next_msg"   style="padding-top: 1px;">' + Next_html.msg + '</td></tr>' +
					'<tr><td id="Next_page"  style="padding-top: 1px;">' + Next_html.page + '</td></tr>' +
					'<tr><td id="Next_end"   style="padding-top: 1px;">' + Next_html.end + '</td></tr>' +
					'<tr height="100%">' +
					'<td height="100%" style="padding-top: 1px;">' +
					'<img src="Pics/Dot.gif">' +
					'</td>' +
					'</tr>' +
					'</table>' +
					//----------------------------------------------------------------
					'</td>';

        collection_html += '</tr></table></div>';
      } else // if(collection._expanded == 0)
      {
        collection_html += '\n<div id="' + CollectionID + '_in" style="width:100%; position:relative; left:0;">\n' +
					'<table class="ParentNode" border="0" cellpadding="0" cellspacing="0">' +
					'<tr><td valign=middle align=center oncontextmenu="StopContextMenu()">' +
					'<div style="width:30px;"><img  onclick="OnCollectionExpandIconClick(\'' +
					this._associationID + '\',\'' + CollectionID + '\');" src="' + this._image_collapsed +
					'"></div></td><td oncontextmenu="StopContextMenu()" nowrap>' +
					'<span tabindex="4" onkeypress="OnCollectionExpandIconClick(\'' +
					this._associationID + '\',\'' + CollectionID + '\');" class="CollectionName" ' +
					'onclick="OnCollectionExpandIconClick(\'' + this._associationID + '\',\'' + CollectionID + '\');" ' +
					'style="cursor:hand;" title="' + external.LS('tooltip_' + this._collections[CollectionID].name + '_collection') + '">' +
					Important_sign + collection._caption + ' (<span id="' +
					CollectionID + '_caption">' + CollectionChildrenCount + '</span>)</span> ';
        collection_html += '</td><td width="100%"></td></tr></table></div>\n';
      }
    }
    collection_html += '</div>\n\n';
    return collection_html;
  };

  // /////////////////////////////////////////////////////////////////////////////////////////////////////
  // (R)
  this.build_message = function (CollectionID, MsgID, MsgEvenness) {
    var msg = external.ObjByID(MsgID);
    var name_mode = 'Short name';
    if (CONST_CollapseFileName == false) name_mode = 'Full name';
    message_html = FillMsgNode(msg, MsgEvenness, CollectionID, name_mode);
    return message_html;
  };

  // /////////////////////////////////////////////////////////////////////////////////////////////////////

  this.build_header_message = function (CollectionID, MsgID, Mode, IsVisible) {
    var msg = external.ObjByID(MsgID);
    var message_html = '';

    if (Mode == 'sort') { message_html = BuildCollectionSortHeaderMenu(CollectionID); } else if (Mode == 'select') {
      var TreeID = CONST_WIN_NO_SYNC;	// Vovas function
      message_html = BuildCollectionSortSelectHeaderMenu(msg, MsgEvenness, CollectionID, TreeID, IsVisible);
    }
    return message_html;
  };

  // /////////////////////////////////////////////////////////////////////////////////////////////////////

  this.redraw_message = function (CollectionID, MsgID) {
    if (G_Collection_lock == true) return;

    if ((G_Above_message.msg_id == MsgID) && (G_Above_message.collection_id == CollectionID)) G_Above_message.mustshown = false;

    G_Shown_message.collection_id = null;
    G_Shown_message.msg_id = null;
    //------------------------------------
    var msg = external.ObjByID(MsgID);
    if (msg == null) return;
    //------------------------------------
    var AssocID = msg.GetM('m_SlnDoAssocSyncWPtr').objID;
    if (G_Assocs[AssocID].TreeView._collections[CollectionID] == null) return;
    //------------------------------------
    var collection_container = document.getElementById('Assoc_' + AssocID).all[CollectionID + '_container'];
    //------------------------------------
    var message_element = collection_container.children[MsgID];
    if (message_element == null) {
      return;
    } else if (message_element.exist == 'false') {
      return;
    }
    //------------------------------------
    if (message_element.className.match(/Msg_Odd/)) MsgEvenness = 1;
    else if (message_element.className.match(/Msg_Even/)) MsgEvenness = 0;
    else if (message_element.className.match(/Msg_Selected/)) MsgEvenness = message_element.MsgEvenness;

    BuildMessageAsObject(message_element, CollectionID, MsgID, MsgEvenness);
  };

  // /////////////////////////////////////////////////////////////////////////////////////////////////
  // G_Assocs[G_ActiveAssocID].TreeView.redraw_header_message(CollectionID, MsgID, Mode, IsVisible);
  this.redraw_header_message = function (CollectionID, MsgID, Mode, IsVisible) {
    //	var AssocElement = document.getElementById('Assoc_'+this._associationID);
    //  	var collection_element = AssocElement.all[CollectionID];
    //	if (collection_element != null)
    //  		{
    var header_element = document.getElementById(CollectionID + '_header_line_container');
    if (!header_element) header_element = document.getElementById('SelectedMenu_' + CollectionID);


    //		var header_element = collection_element.getElementById('SelectedMenu_'+CollectionID);
    if (header_element != null) {
      header_element.outerHTML = this.build_header_message(CollectionID, MsgID, Mode, IsVisible);
    }
    //		}
  };

  // /////////////////////////////////////////////////////////////////////////////////////////////////
  // (R)
  this.redraw = function ()  // function redraws whole treeview
  {
    var AssocElement = document.getElementById('Assoc_' + this._associationID);
    var ele = AssocElement.all[this._spanid];
    ele.innerHTML = this.build_root();
  };

  // /////////////////////////////////////////////////////////////////////////////////////////////////
  // (R)
  this.redraw_collection = function (CollectionID) {
    var AssocElement = document.getElementById('Assoc_' + this._associationID);
    var collection_element = AssocElement.all[CollectionID];
    if (collection_element != null) {
      if (this._collections[CollectionID].timer_id) {
        clearInterval(this._collections[CollectionID].timer_id);
        this._collections[CollectionID].timer_id = null;
      }

      collection_element.outerHTML = this.build_collection(CollectionID);

      var name = this._collections[CollectionID].name;
      if ((name == 'Important') && (this.root._children[CollectionID]._expanded) && (!this.root._children[CollectionID]._empty)) {
        this._collections[CollectionID].timer_id = setInterval('important_sign_winking("' + CollectionID + '");', 600);
      }
    }
  };

  // /////////////////////////////////////////////////////////////////////////////////////////////////
  // (R)
  this.add_collection_node = function (msgs, collectionName, caption)      // adds node
  {
    var CollectionID = msgs.objID;
    this._collections[CollectionID] = {};
    this._collections[CollectionID].obj = msgs;
    this._collections[CollectionID].name = collectionName;
    if (this._collections[CollectionID].sort == null) { this._collections[CollectionID].sort = 'sort_by_default'; }
    this._collectionIdByName[collectionName] = CollectionID;
    var collection_node = {};
    collection_node._caption = caption;

    // get collection state from core
    var expanded = this._collections[CollectionID].obj.Method0('M_GetCollectionState');
    collection_node._expanded = expanded;

    if (msgs == null) {
      alert('add_collection_node: CollectionObj (msgs) == null');
      collection_node._empty = true;
    } else {
      var first_message = msgs.GetFirst();
      if (first_message == null) {
        collection_node._empty = true;
      } else {
        collection_node._first_disp_msg_evenness = 1;
        collection_node._empty = false;
      }
    }
    this.root._childrencount++;
    this.root._children[CollectionID] = collection_node;
    return collection_node;
  };

  // /////////////////////////////////////////////////////////////////////////////////////////////////

  this.add_message_node = function (CollectionID, MsgID, InsertPosition)      // adds node
  {
    //	if (CollectionID) {
    //		var name = G_Assocs[G_ActiveAssocID].TreeView._collections[CollectionID].name;
    //		if (name == 'OverwriteByUser') alert('add_message_node - OverwriteByUser');
    //	}

    if (this._collections[CollectionID] == null) return;
    var collection = this.root._children[CollectionID];
    var msgs = this._collections[CollectionID].obj;
    if (msgs == null) alert('msgs == null');
    //--------------------------------------------------------------------------------------------
    if (collection._empty == true) {
      collection._empty = false;
      collection._first_disp_msg_evenness = 1;
      G_Assocs[AssocID].TreeView.redraw_collection(CollectionID);
      return;
    }
    //---------------------------------------------------------------------------------------------
    if (collection._expanded == 1) {
      var msg_page_shift = 1;	// first element in message table is header line (is not sync item)
      var collection_container_element = document.getElementById('Assoc_' + this._associationID).all[CollectionID + '_container'];
      if (collection_container_element.children) var msg_page_length = collection_container_element.children.length - msg_page_shift;
      else return;
      if (msg_page_length < CONST_MESSAGES_ON_PAGE) {
        //-------------------------------------------------------------------------------------
        var new_message_element = document.createElement('tbody');

        if (InsertPosition == -1) {
          collection_container_element.appendChild(new_message_element);
          BuildMessageAsObject(new_message_element, CollectionID, MsgID, (collection._first_disp_msg_evenness + msg_page_length) % 2);
        } else {  // (InsertPosition + msg_page_shift) - first element in message table is header line - Name -Size - Time - Direction
          collection_container_element.insertBefore(new_message_element, collection_container_element.children(InsertPosition + msg_page_shift));
          var MsgEvenness = (collection._first_disp_msg_evenness + InsertPosition) % 2;
          BuildMessageAsObject(new_message_element, CollectionID, MsgID, MsgEvenness);

          for (var i = (InsertPosition + 1); i <= msg_page_length; i++) {
            if (MsgEvenness == 0) { collection_container_element.children(i).className = 'Msg_Odd'; MsgEvenness = 1; } else { collection_container_element.children(i).className = 'Msg_Even'; MsgEvenness = 0; }
          }
        }
      }
      //---------------------------------------------------------------------------------------
      else // if (msg_page_length >=CONST_MESSAGES_ON_PAGE)
      {
        var new_message_element = document.createElement('tbody');
        var removed_message_element = collection_container_element.children((CONST_MESSAGES_ON_PAGE - 1) + msg_page_shift);
        if (removed_message_element) collection_container_element.removeChild(removed_message_element);
        else alert('element(' + ((CONST_MESSAGES_ON_PAGE - 1) + msg_page_shift) + ') do not exist');
        if (InsertPosition == -1) {
          collection_container_element.appendChild(new_message_element);
          BuildMessageAsObject(new_message_element, CollectionID, MsgID, (collection._first_disp_msg_evenness + msg_page_length) % 2);
        } else {
          collection_container_element.insertBefore(new_message_element, collection_container_element.children(InsertPosition + msg_page_shift));
          var MsgEvenness = (collection._first_disp_msg_evenness + InsertPosition) % 2;
          BuildMessageAsObject(new_message_element, CollectionID, MsgID, MsgEvenness);
          var i;
          for (i = InsertPosition + 1; i < CONST_MESSAGES_ON_PAGE; i++) {
            if (MsgEvenness == 0) { collection_container_element.children(i).className = 'Msg_Odd'; MsgEvenness = 1; } else { collection_container_element.children(i).className = 'Msg_Even'; MsgEvenness = 0; }
          }
        }
      }
      // --------if (msg_page_length >=CONST_MESSAGES_ON_PAGE) end------------------------------
    }
  };

  // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  this.click = function (CollectionID) {
    this.root._children[CollectionID]._expanded = 1 - this.root._children[CollectionID]._expanded;
    this._collections[CollectionID].obj.Method1('M_SetCollectionState', this.root._children[CollectionID]._expanded);
    this.redraw_collection(CollectionID);
  };

  return this;
}  // CreateTree() end
