// MFindItemByIndex
// JavaScript Document
//	----------------------------------------------------------------
//	Constants:
var CONST_ERR_QUESTION = 6000;
var CONST_MSG_STATE_EXCLUDED = '6E79535F534953557178456D65744963';
var CONST_CID = '44D6005D4449435BBBF419FDC8367C08';
var CONST_WIN_NO_SYNC = '535F4F4E5F4E49570000000000434E59';
var CONST_WIN_DEL_SYNC = '4F4D45525F4E495700004C4C415F4556'; // WIN_REMOVE_ALL
var CONST_ACTION_STATE_INIT = '535F4E4F49544341614E495F45544154';
var CONST_ACTION_STATE_IN_PROGRESS = '535F4E4F495443415A4E495F45544154';
var CONST_ACTION_STATE_DONE = '535F4E4F49544341574F445F45544154';
var CONST_AssocTemplate = '';
var CONST_MESSAGES_ON_PAGE = 10;
var CONST_ShowFullFileName = true;
var CONST_CollapseFileName = true;
//	----------------------------------------------------------------
// Status attribute definitions.
var STATUS_ATTRIBUTE_NULL = 0;
var STATUS_ATTRIBUTE_AUTOMATIC = 1;
var STATUS_ATTRIBUTE_AUTOMATIC_INTERNAL = 2;
var STATUS_ATTRIBUTE_AUTOMATIC_DISABLED = 3;
var STATUS_ATTRIBUTE_ANALYZING = 4;
var STATUS_ATTRIBUTE_SYNCHRONIZING = 5;
var STATUS_ATTRIBUTE_INFORMATION_MESSAGE = 6;
var STATUS_ATTRIBUTE_IMPORTANT_MESSAGE = 7;
var STATUS_ATTRIBUTE_INCOMPLETE = 8;
var STATUS_ATTRIBUTE_ANALYZE_ENABLED = 9;
var STATUS_ATTRIBUTE_SYNCHRONIZE_ENABLED = 10;
var STATUS_ATTRIBUTE_STOP_ENABLED = 11;
//	----------------------------------------------------------------
// Synchronization types
var PATH_TYPE__NONE = 0;
var PATH_TYPE_EMPTY = 1;
var PATH_TYPE_STARTUP_DRIVE = 2;
var PATH_TYPE_WINDOWS_BASED_DRIVE = 3;
var PATH_TYPE_PROTOCOL_FTP = 4;
var PATH_TYPE_PROTOCOL_SFTP = 5;
var PATH_TYPE_PROTOCOL_AMAZON_S3 = 6;
var PATH_TYPE_PROTOCOL_OFFSITE_BOX = 7;
var PATH_TYPE_PROTOCOL_WEBDAV = 8;
var PATH_TYPE_PROTOCOL_ACTIVESYNC = 9;
var PATH_TYPE_LOCAL_ARCHIVE = 10;
var PATH_TYPE_PROTOCOL_GOOGLE_DOCS = 11;
var PATH_TYPE_PROTOCOL_AZURE = 12;
var PATH_TYPE_PROTOCOL_SKYDRIVE = 13;
var PATH_TYPE_PROTOCOL_IKIC = 14;
var PATH_TYPE_PROTOCOL_DROPBOX = 15;
var PATH_TYPE_PROTOCOL_AMAZON_CD = 16;
var PATH_TYPE_PROTOCOL_GOOGLE_CS = 17;
var PATH_TYPE_PROTOCOL_BOX_STORAGE = 18;
var PATH_TYPE_SYNC_GATEWAY = 19;
var PATH_TYPE_MAX_INDEX = 19;
//	----------------------------------------------------------------
//	Global variables:
//	----------------------------------------------------------------
var G_OnProfileChanged_called = false;
var G_OnAssocChanged_called = false;
var G_CounterRefreshFlag = false;
var G_AnalyzeHintCallCounter = 4;
var G_Folders_is_ready = false;
var G_OnDirectionChanged = false;
var G_filter_switched = false;
// G_SynchronizeHintCallCounter = 3;
var G_TabScrollingProcessNum = 0;
var G_ActiveAssocID = '';
var G_Assocs = {};
var G_ProfileExist = false;
var G_FirstAssocID = '';
var Flag_can_reload_profile = true;
var G_Shown_message = {};
G_Shown_message.msg_id = null;
G_Shown_message.collection_id = null;
// /////////////////////////////////////////////
var G_Selected_lock = false;  // Selection is forbidden
var G_Select_All = false;	// 'Select All' or 'Deselect All' button is pressed
var G_SelectedCollectionLock = false;  // Collection is being used for items' selection
var G_SelectedCollectionCoordinates = {};
G_SelectedCollectionCoordinates.top = null;
G_SelectedCollectionCoordinates.bottom = null;
G_SelectedCollectionCoordinates.left = null;
G_SelectedCollectionCoordinates.right = null;

var G_FirstSelectedMsgID = null;
var G_FirstSelectedMsgIndex = null;
var G_FirstSelectedCollectionID = null;
var G_LastSelectedMsgID = null;
var G_LastSelectedMsgIndex = null;
var G_LastSelectedCollectionID = null;
var G_MousemoveEvent = null; 		// manually generated mousemove event during messages selection
var G_MousemoveElement = null; 		// srcElement for manually generated mousemove event
var G_MousemoveIsLaunched = false; 	// manually generated mousemove event is launched
var G_ScrollButtonIsPressed = false; // Status of scrolling in collection
var G_Collection_lock = false; 		// Collection is being scrolled now by dragIt(), release()
var G_Sync_board_state = 1;
//	----------------------------------------------------------------
//	Settings of middle message (Above_message)
// 	----------------------------------------------------------------
var G_Above_message = {};
G_Above_message.msg_id = null;
G_Above_message.collection_id = null;
G_Above_message.mustshown = true;
G_Above_message.latch = false;
//	----------------------------------------------------------------
var G_Wizard_folder_num = 0;
var G_Wizard_Sync_Tree_Obj_ID = '';
var G_Wizard_Mouse_Status = false;
var G_Wizard_Browser_Status = false;
var G_WizardTypeInfoList = {};
//	----------------------------------------------------------------
var G_Folder_Type_List_folder_num = 0;
var G_Folder_Type_List_Sync_Tree_Obj_ID = '';
var G_Folder_Type_List_Mouse_Status = false;
//	----------------------------------------------------------------
var G_Caption_menu = false;
var G_Caption_menu_mustshown = false;
var G_Caption_menu_above = false;
var G_FocusInCaptionMenu = false;

var G_AssocChangedCause = '';
var G_Block = false;
var G_DEBUG = false;
var G_debug_line_number = 1;
//	----------------------------------------------------------------
//	End of global variables definitions
function Body_onload() {
  //------------------------------------------------------------------------------------------------------------------------
  G_WizardTypeInfoList_Init();
  G_WizardTypeInfoList_Refresh();
  Folder_Type_list_contents.innerHTML = BuildListTable(5, 3);
  Folder_Type_list_down_plate.innerHTML = external.LS('folder_type_List_des');
  folder_Panel_Current_Type.innerHTML = external.LS('folder_type_List');
  folder_Panel_des_Current_Type.innerHTML = external.LS('folder_type_List_des');
  Exit_full_screen_caption.innerHTML = external.LS('Display_folders_selection_panel');
  //------------------------------------------------------------------------------------------------------------------------
  // ApplicationName.innerText = external.GetAppName();
  //------------------------------------------------------------------------------------------------------------------------
  //------------------------------------------------------------------------------------------------------------------------
  ApplicationName.innerHTML = '<span><img style="position:relative; top:4px; left:-15px;" src="Pics/Logotype.png"></span>' +
		external.GetAppName() + ' ' +
		'<span style="color:#414c32; font-size:18px;">' +
		external.LS('banner_version') + ' ' + external.GetAppVersionUserStr() +
		'</span>';
  BannerSlogan.innerText = external.LS('banner_slogan');
  Select_sync_direction.innerHTML = external.LS('popup_select_direction');
  If_remove_check_lbl.innerText = external.LS('check_remove_files');
  If_remove_check_div.title = external.LS('hint_check_remove_files');
  If_rewrite_check_lbl.innerText = external.LS('check_overwrite_files');
  If_rewrite_check_div.title = external.LS('hint_check_overwrite_files');
  Change_link.innerText = external.LS('popup_change_link');
  Change_link.title = external.LS('tooltip_change_link');
  AllWayRadio.title = external.LS('tooltip_all_way_sync');
  CONST_AssocTemplate = AssocTemplate.innerHTML;
  CONST_MESSAGES_ON_PAGE = external.Method1('M_GetGlobalOption', 'ItemsPerPage');
  CONST_ShowFullFileName = external.Method1('M_GetGlobalOption', 'ShowFullFileName');
  CONST_CollapseFileName = external.Method1('M_GetGlobalOption', 'CollapseFileName');

  var State = external.Method1('M_GetGlobalOption', 'ShowBanner');
  ExtChangeBannerState(State);
  ExtOnEventLogChanged(external.Method1('M_GetGlobalOption', 'ShowEventsInProfile'));

  //------------------------------------------------------------
  var ActiveAssocObj = external.Method0('M_GetSelectedAssoc');
  G_ActiveAssocID = ActiveAssocObj.objID;
  // ------------------------------------------------------------
  LoadProfile();
  ActivateAssoc(G_ActiveAssocID);

  var AssocObj = external.ObjByID(G_ActiveAssocID);
  var Status = AssocObj.Method0('M_GetAggregatedGeneralStatus');
  UpdateAssocStatus(G_ActiveAssocID, Status);

  FillEventLog();

  ResizeWindow();

  initDHTMLAPI();
  initDrag();
}

function LoadProfile() {
  //---------------------------------------------------
  G_ProfileExist = false;
  var profile = external.Method0Own('M_GetProfile');
  if (profile == null) return G_ProfileExist;
  G_ProfileExist = true;
  //---------------------------------------------------
  var Assocs_exist = false;
  var AssocObj = profile.GetFirst();
  if (AssocObj == null) return Assocs_exist;
  Assocs_exist = true;
  // ---------------------------------------------------
  var ActiveAssoc_exist = false;
  var FirstAssocID = AssocObj.objID;
  // show all assocs from Profile
  while (AssocObj != null) {
    if (G_ActiveAssocID == AssocObj.objID) ActiveAssoc_exist = true;
    AddAssoc(AssocObj);
    var AssocObj = profile.GetNext(AssocObj);
  }
  // ----------------------------------------------------------
  var ActiveAssocObj = external.Method0('M_GetSelectedAssoc');
  if (ActiveAssocObj) {
    G_ActiveAssocID = ActiveAssocObj.objID;
    ActiveAssoc_exist = true;
  }
  //----------------------------------------------------------
  if (ActiveAssoc_exist != true) G_ActiveAssocID = FirstAssocID;
  //----------------------------------------------------------
  var JobNameListContainerObj = document.getElementById('JobNameListContainer');
  // alert(CreateJobNameList(profile.objID));
  JobNameListContainerObj.innerHTML = CreateJobNameList(profile.objID);
  return Assocs_exist;
}

//	--------------------------------------------------------------------
// initialisation of association
//	--------------------------------------------------------------------
function InitAssoc(AssocObj) {
  var AssocID = AssocObj.objID;
  //	-----------------------------------------------------------------------------------------------
  G_Assocs[AssocID] = {};
  G_Assocs[AssocID].self = AssocID;
  G_Assocs[AssocID].Folders_is_ready = false;
  G_Assocs[AssocID].FoldersQuantity = 2;
  G_Assocs[AssocID].WinningSuperTreeID = CONST_CID;		// For one/all way synchronization switch
  G_Assocs[AssocID].Folder_is_ready_array = new Array();
  G_Assocs[AssocID].OnAssocChangedCalled = false;
  G_Assocs[AssocID].TreeView = new CreateTree(AssocID, 'tree', 'TreeView_element');
  G_Assocs[AssocID].CollectionNodesExist = false;
  //	-----------------------------------------------------------------------------------------------
  AssocElement = document.getElementById('Assoc_' + AssocID);
  AssocElement.all.B_ANALYZE.innerText = external.LS('button_analyze');
  AssocElement.all.B_ANALYZE.title = external.LS('tooltip_Analyze_button');
  AssocElement.all.B_ANALYZE.association_id = AssocID;
  AssocElement.all.B_SYNC.innerText = external.LS('button_synchronize');
  AssocElement.all.B_SYNC.title = external.LS('tooltip_Sinchronize_button');
  AssocElement.all.B_SYNC.association_id = AssocID;
  AssocElement.all.B_STOP.innerText = external.LS('button_clear');
  AssocElement.all.B_STOP.title = external.LS('tooltip_Stop_button');
  AssocElement.all.B_STOP.association_id = AssocID;
  AssocElement.all.Important_warning_text.innerText = external.LS('important_warning');
  AssocElement.all.Important_warning.title = external.LS('tooltip_Important_warning');
}

//	-----------------------------------------------------------------------------------------------------------
//	AddAssoc(AssocObj) 	Creates assoc label
//					   	Adds html object for assoc,
// 						Calls	InitAssoc(AssocObj) 					- sets html assoc object by default
//								LoadAssocPaths(AssocID)					- places rootfolders objects to assoc
//								G_Assocs[AssocID].TreeView.redraw()		- redraws all collections
//
//  adds association to assoc tree, sets assoc by default and redraw it
//	-----------------------------------------------------------------------------------------------------------
function AddAssoc(AssocObj) {
  //-----------------------------
  CloseWizardMenu();
  CloseFolderTypeList();
  //-----------------------------
  var AssocID = AssocObj.objID;
  //-----------------------------
  if (TabsLabels.cells.length == 1) {
    LeftSeparatorCell = TabsLabels.insertCell(0);
    LeftSeparatorCell.height = '26px';
    LeftSeparatorCell.className = 'TabSeparatorCell';
    LeftSeparatorCell.innerHTML = '<div class="TabSeparator_3"></div>';
  } else {
    LeftSeparatorCell = TabsLabels.cells(TabsLabels.cells.length - 2);
    LeftSeparatorCell.children[0].className = 'TabSeparator_7';
  }

  NewLabelCell = TabsLabels.insertCell(TabsLabels.cells.length - 1);
  NewLabelCell.id = 'Label_' + AssocID;
  NewLabelCell.style.backgroundImage = "url('Pics/TabCaptionMid1.gif')";
  NewLabelCell.style.cursor = 'hand';
  NewLabelCell.noWrap = true;
  //---------------------------------------------------------------------------------------------------
  var status = AssocObj.Method0('M_GetAggregatedGeneralStatus');
  var status_src = 'Pics/Status_normal.gif';
  //---------------------------------------------------------------------------------------------------
  if (status == STATUS_ATTRIBUTE_NULL) status_src = 'Pics/Status_normal.gif';
  else if (status == STATUS_ATTRIBUTE_AUTOMATIC) status_src = 'Pics/Status_schedule.gif';
  else if (status == STATUS_ATTRIBUTE_AUTOMATIC_INTERNAL) status_src = 'Pics/Status_schedule.gif';
  else if (status == STATUS_ATTRIBUTE_AUTOMATIC_DISABLED) status_src = 'Pics/Status_manual.gif';
  else if (status == STATUS_ATTRIBUTE_ANALYZING) status_src = 'Pics/Status_analyze.gif';
  else if (status == STATUS_ATTRIBUTE_SYNCHRONIZING) status_src = 'Pics/Status_synchronize.gif';
  else if (status == STATUS_ATTRIBUTE_INFORMATION_MESSAGE) status_src = 'Pics/Status_information.gif';
  else if (status == STATUS_ATTRIBUTE_IMPORTANT_MESSAGE) status_src = 'Pics/Status_important.gif';
  else if (status == STATUS_ATTRIBUTE_INCOMPLETE) status_src = 'Pics/Status_incomplete.gif';
  // ---------------------------------------------------------------------------------------------------
  NewLabelCell.innerHTML = '<div oncontextmenu="TabLabelContextMenu(\'' + AssocID + '\')" ' +
		'onclick="TabLabelOnClick1(\'' + AssocID + '\')" ' +
		'style="position:relative: top:0px; left:0px; width:100%; height:26px; padding-top:3px;">' +
		'<img id="Status_img" src="' + status_src + '" ' +
		'style="position:relative; top:2px; left:0px; margin-right:3px; margin-left:-3px;">' +
		'<span tabindex="1" onkeypress="TabLabelOnClick1(\'' + AssocID + '\')" id="TabCaptionText">' +
		AssocObj.Method0('M_GetAssocName') + '</span><div>';

  RightSeparatorCell = TabsLabels.insertCell(TabsLabels.cells.length - 1);
  RightSeparatorCell.className = 'TabSeparatorCell';
  RightSeparatorCell.height = '26px';
  RightSeparatorCell.innerHTML = '<div class="TabSeparator_4">';
  TabsCaptionResized();
  // ---------------------------------------------------------------------------------------------------
  AssocsContainer.innerHTML = AssocsContainer.innerHTML + '<div id="Assoc_' + AssocID + '" ' +
		'oncontextmenu="TabLabelContextMenu(\'' + AssocID + '\')" ' +
		'style="position:absolute; width:100%; height:100%; visibility:hidden;">' +
		CONST_AssocTemplate + '</div>';

  InitAssoc(AssocObj);
  LoadAssocPaths(AssocID);
  G_Assocs[AssocID].TreeView.redraw();

  var El = document.getElementById('Assoc_' + AssocID);
  El.style.display = 'none';
}

function RemoveAllAssocsFromScreen() {
  Hint_window.style.visibility = 'hidden';
  var AssocQuantity = AssocsContainer.children.length;

  for (var i = 0; i < AssocQuantity; i++) {
    var AssocElement = AssocsContainer.children(0);
    var AssocID = AssocElement.id.replace(/Assoc_/, '');

    delete G_Assocs[AssocID];
    AssocElement.removeNode(true);

    var LeftSeparatorCell = TabsLabels.cells(0);
    var LabelCell = TabsLabels.cells(1);
    TabsLabels.deleteCell(LeftSeparatorCell.cellIndex);
    TabsLabels.deleteCell(LabelCell.cellIndex);
  }

  if (AssocQuantity > 0) {
    var LastSeparatorCell = TabsLabels.cells(0);
    TabsLabels.deleteCell(LastSeparatorCell.cellIndex);
  }
  TabsCaptionResized();
}
//	--------------------------------------------------------------------------
//	functions for deactivation of specified accosiation
function DeactivateAssoc(AssocID) {
  ExtChangeSyncBoardState(0);

  var AssocElement = document.getElementById('Assoc_' + AssocID);

  for (var i = 0; i < G_Assocs[AssocID].FoldersQuantity; i++)	{
    ExtCloseHint(AssocID, 'Syncpath_hint_' + i);
    // ----------------------------------------------
    SyncTree_elem = AssocElement.all['SyncTree' + i];
    SyncTree_elem.className = 'Unactive_panel';
    //----------------------------------------------
    Form_elem = AssocElement.all['TreeForm' + i];
    if (Form_elem) { if (Form_elem.is_changed == 'true') ChangeSyncTree(num); }
  }
  // ---------------------------------------------------------------------
  AssocElement.style.visibility = 'hidden';
  AssocElement.style.display = 'none';
  //---------------------------------------------------------------------
  var FirstLabelIndex = 1;
  var LastLabelIndex = TabsLabels.cells.length - 3;
  //---------------------------------------------------------------------
  var LabelCell = TabsLabels.cells['Label_' + AssocID];
  var LabelCellIndex = LabelCell.cellIndex;
  var LeftSeparatorCell = TabsLabels.cells(LabelCellIndex - 1);
  var RightSeparatorCell = TabsLabels.cells(LabelCellIndex + 1);
  LabelCell.style.backgroundImage = "url('Pics/TabCaptionMid1.gif')";
  //---------------------------------------------------------------------
  LeftSeparatorCell.children(0).className = 'TabSeparator_7';//	Unactive/Unactive
  RightSeparatorCell.children(0).className = 'TabSeparator_7';//	Unactive/Unactive
  if (LabelCellIndex == FirstLabelIndex) LeftSeparatorCell.children(0).className = 'TabSeparator_3';//	Empty/Unactive
  else if (LabelCellIndex == LastLabelIndex) RightSeparatorCell.children(0).className = 'TabSeparator_4';//	Unactive/Empty
}
//	-------------------------------------------------------------------------
function Deactivate_form(num, AssocID) {
  ExtCloseHint(AssocID, 'Syncpath_hint_' + num);
  AssocElement = document.getElementById('Assoc_' + AssocID);
  SyncTree_elem = AssocElement.all['SyncTree' + num];
  Form_elem = AssocElement.all['TreeForm' + num];
  if (Form_elem.is_changed == 'false') {
    SyncTree_elem.className = 'Unactive_panel';
  } else if (SyncTree_elem.contains(window.event.toElement) == false) {
    SyncTree_elem.className = 'Unactive_panel';
    ChangeSyncTree(num);
  }
}

function UpdateAssocStatistics(AssocID) {
  var AssocElement = document.getElementById('Assoc_' + AssocID);
  if (AssocElement == null) return;

  var Line_1 = '' + external.Method2('M_GetAssocUsageStatistics', AssocID, 0);
  if (Line_1 == 'undefined') Line_1 = '';
  var Line_2 = '' + external.Method2('M_GetAssocUsageStatistics', AssocID, 1);
  if (Line_2 == 'undefined') Line_2 = '';

  var Last_sync_information = document.getElementById('Last_sync_info');
  if (Last_sync_information == null) return;

  AssocElement.all.Last_sync_info.innerHTML = Line_1 + '<br/>' + Line_2;
  AssocElement.all.Last_sync_info.title = '';// external.LS("tooltip_Important_warning");
}

function CreateAllCollections(AssocID) {
	var coll_info = [
		{ type: 'warning', name: 'Important', lid: 'MM_UserMessagesImportant' },
		{ type: 'info', name: 'Information', lid: 'MM_UserMessagesInformation' },
		{ type: 'questionable', name: 'Questionable', lid: 'MM_SyncItemQuestionable' },
		{ type: 'deleted', name: 'Deleted', lid: 'USIS_SyncItemDeleted' },
		{ type: 'new', name: 'New', lid: 'USIS_SyncItemNew' },
		{ type: 'changed', name: 'Changed', lid: 'USIS_SyncItemChanged' },
		{ type: 'unchanged', name: 'Unchanged', lid: 'USIS_SyncItemUnchanged' },
		{ type: 'all', name: 'All', lid: 'MM_SyncItemsAll' },
		{ type: 'excluded', name: 'Excluded', lid: 'USIS_SyncItemExcluded' },
		{ type: 'useraction', name: 'OverwriteByUser', lid: 'MM_OverwriteByUser' },
		{ type: 'found', name: 'SyncFindItems', lid: 'MM_SyncFindItems' }
	];

	var assoc = G_Assocs[AssocID];
	for (var i=0; i<coll_info.length; i++) {
		var p = coll_info[i];
		assoc.TreeView.add_collection_node(
			external.CreateUserMessageCollection(AssocID, p.type), p.name, external.LS(p.lid));
	}
	assoc.CollectionNodesExist = true;
}

function ActivateAssoc(AssocID) {
  var AssocElement = document.getElementById('Assoc_' + AssocID);
  if (AssocElement == null) return;
  // ------------------------------------------
  AssocElement.style.display = '';
  AssocElement.style.visibility = 'visible';
  // ------------------------------------------
  var LastLabelIndex = TabsLabels.cells.length - 3;
  var FirstLabelIndex = 1;
  var LabelCell = TabsLabels.cells['Label_' + AssocID];
  var LabelCellIndex = LabelCell.cellIndex;
  var LeftSeparatorCell = TabsLabels.cells(LabelCellIndex - 1);
  var RightSeparatorCell = TabsLabels.cells(LabelCellIndex + 1);
  LabelCell.style.backgroundImage = 'url(' + "\'./Pics/TabCaptionMid2.gif" + "\')";
  // ------------------------------------------
  LeftSeparatorCell.children(0).className = 'TabSeparator_5';	// Unactive/Active
  RightSeparatorCell.children(0).className = 'TabSeparator_6';	// Active/Unactive

  if (LabelCellIndex == FirstLabelIndex) LeftSeparatorCell.children(0).className = 'TabSeparator_1';	//	Empty/Active
  if (LabelCellIndex == LastLabelIndex) RightSeparatorCell.children(0).className = 'TabSeparator_2';	//	Active/Empty

  G_ActiveAssocID = AssocID;

  if (external.Method0('M_GetSelectItemMode') == true) G_Selected_lock = false;
  else G_Selected_lock = true;

  if (G_Assocs[AssocID].CollectionNodesExist == false)
	CreateAllCollections(AssocID);

  ScrollTabLabelIntoView(AssocID);
  LoadAssocPaths(AssocID);
  //	-----------------------------------------------------------------------------------------------
  UpdateAssocStatistics(AssocID);
  //	-----------------------------------------------------------------------------------------------
  G_Assocs[AssocID].TreeView.redraw(); // !!! added because of replacing of collection nodes creating
  UpdateButtons(AssocID);
  ExtCountersRefresh();
  ExtUpdateProgressBar(AssocID, external.Method0('M_GetProgressState'), external.Method0('M_GetProgressPercent')); // New !!
  ExtRefreshAllFoldersTraffic(AssocID);
}

function FocusToAnalyze(AssocID) {
  if (AssocID != G_ActiveAssocID) {
    return;
  }
  AssocElement = document.getElementById('Assoc_' + AssocID);
  AnalyzeButtonElement = AssocElement.all.B_ANALYZE;
  if (AnalyzeButtonElement.disabled == false) {
    AnalyzeButtonElement.focus();
  }
}

function FocusToSyncpath(AssocID, num) {
  if (AssocID != G_ActiveAssocID) {
    return;
  }
  AssocElement = document.getElementById('Assoc_' + AssocID);
  TreePathDiv = AssocElement.all['TreePath' + num];
  if (TreePathDiv.disabled == false) {
    PlaceHintWindow(TreePathDiv, num);
    ExtGiveHint(AssocID, 'Syncpath_hint_' + num);
    TreePathDiv.children(0).focus();
  }
}

function SwitchSyncDirectionArrow(AssocID, NewWinningSuperTreeID) {
  var AssocObj = external.ObjByID(AssocID);
  var Assoc_element = document.getElementById('Assoc_' + AssocID);
  var SyncBoardsTableBody_element = Assoc_element.all.SyncBoardsTable.all[0];
  var FoldersQuantity = G_Assocs[AssocID].FoldersQuantity;
  var SuperTreeList = AssocObj.GetM('m_SuperTreesPtr');
  if (SuperTreeList == null) {
    alert('SuperTreeList == null');
    return 0;
  }

  var SyncTreeArray = new Array();
  var SyncTreeList_length = 0;
  var SuperTree_Obj = SuperTreeList.GetFirst();
  while (SuperTree_Obj != null) {
    SyncTreeArray[SyncTreeList_length] = {};
    SyncTree_Obj = SuperTree_Obj.GetFirst();
    if (SyncTree_Obj == null) {
      alert('SuperTree does not contain any SyncTree');
      return 0;
    }
    if (NewWinningSuperTreeID == SuperTree_Obj.objID) {
      SyncTreeArray[SyncTreeList_length].cap_arrow_direction = '_out';
      SyncTreeArray[SyncTreeList_length].radio = 'active';
    } else {
      SyncTreeArray[SyncTreeList_length].cap_arrow_direction = '';
      SyncTreeArray[SyncTreeList_length].radio = 'unactive';
    }

    //		SyncTreeArray[SyncTreeList_length].obj = SyncTree_Obj;
    SyncTreeArray[SyncTreeList_length].superID = SuperTree_Obj.objID;
    SuperTree_Obj = SuperTreeList.GetNext(SuperTree_Obj);
    SyncTreeList_length++;
  }
  if (SyncTreeList_length != FoldersQuantity) {
    alert('SyncTreeList length is not correct');
    return -1;
  }
  Assoc_element.all.TopCapArrowLeft.className = 'Cap_arrow_left' + SyncTreeArray[0].cap_arrow_direction;
  Assoc_element.all.TopCapArrowRight.className = 'Cap_arrow_right' + SyncTreeArray[1].cap_arrow_direction;
  Assoc_element.all.TopCapRadioLeft.children[0].src = 'Pics/Radio_left_' + SyncTreeArray[0].radio + '.gif';
  Assoc_element.all.TopCapRadioRight.children[0].src = 'Pics/Radio_right_' + SyncTreeArray[1].radio + '.gif';

  for (var i = 2; i < FoldersQuantity; i++) {
    var row_element = SyncBoardsTableBody_element.rows[i - 1];
    var RightArrowCell = row_element.cells[3];
    var RightRadioCell = row_element.cells[4];
    RightArrowCell.children[0].className = 'Cap_arrow_right' + SyncTreeArray[i].cap_arrow_direction;
    RightRadioCell.children[0].src = 'Pics/Radio_right_' + SyncTreeArray[i].radio + '.gif';
  }

  if (AssocID == G_ActiveAssocID) {
    if (NewWinningSuperTreeID == 'DIRECTION_ALL_WAY') {
      Caption_down_plate.all.AllWayRadio.src = 'Pics/Radio_all_way.gif';
    } else {
      Caption_down_plate.all.AllWayRadio.src = 'Pics/Radio_all_way_unactive.gif';
    }
  }
  return 1;
}

function LoadAssocPaths(AssocID) {
  var AssocObj = external.ObjByID(AssocID);
  var Assoc_element = document.getElementById('Assoc_' + AssocID);
  var SyncBoardsTableBody_element = Assoc_element.all.SyncBoardsTable.all[0];
  var SuperTreeList = AssocObj.GetM('m_SuperTreesPtr');
  //-------------------------------------------------------------------------------
  if (SuperTreeList == null) return 0;
  //-------------------------------------------------------------------------------
  // Before creating of the cuppent job paths
  // function deletes previous job paths
  var tbody_length = SyncBoardsTableBody_element.rows.length;
  for (var i = tbody_length - 1; i > 0; i--)		SyncBoardsTableBody_element.deleteRow(i);
  // -------------------------------------------------------------------------------
  var SyncDirection = AssocObj.Method0('M_GetSyncDirection');
  // -------------------------------------------------------------------------------
  if ((typeof (SyncDirection) == 'string') &&
		(SyncDirection == external.AbbrToHex('DIRECTION_ALL_WAY'))) G_Assocs[AssocID].WinningSuperTreeID = CONST_CID;
  else G_Assocs[AssocID].WinningSuperTreeID = SyncDirection.objID;

  var WinningSuperTreeID = G_Assocs[AssocID].WinningSuperTreeID;
  //--------------------------------------------
  var SyncTreeArray = new Array();
  var SyncTreeList_length = 0;
  //--------------------------------------------
  var SuperTree_Obj = SuperTreeList.GetFirst();
  while (SuperTree_Obj != null) {
    SyncTreeArray[SyncTreeList_length] = {};

    SyncTree_Obj = SuperTree_Obj.GetFirst();
    if (SyncTree_Obj != null) {
      if (WinningSuperTreeID == SuperTree_Obj.objID) {
        SyncTreeArray[SyncTreeList_length].cap_arrow_direction = '_out';
        SyncTreeArray[SyncTreeList_length].radio = 'active';
      } else {
        SyncTreeArray[SyncTreeList_length].cap_arrow_direction = '';
        SyncTreeArray[SyncTreeList_length].radio = 'unactive';
      }

      SyncTreeArray[SyncTreeList_length].obj = SyncTree_Obj;
      SyncTreeArray[SyncTreeList_length].superID = SuperTree_Obj.objID;

      SuperTree_Obj = SuperTreeList.GetNext(SuperTree_Obj);
      SyncTreeList_length++;
    } else {
      alert('SuperTree does not contain any SyncTree');
      return 0;
    }
  }
  // -------------------------------------------------------------------------------
  G_Assocs[AssocID].FoldersQuantity = SyncTreeArray.length;
  delete G_Assocs[AssocID].Folder_is_ready_array;
  G_Assocs[AssocID].Folder_is_ready_array = new Array();
  Assoc_element.all.Cap_arrow_branch.className = 'Cap_arrow_branch0';
  // -------------------------------------------------------------------------------
  for (i = 0; i < 2; i++)	// First Sync board table row
  {
    var result = BuildFolderPanel(SyncBoardsTableBody_element.all['SyncTree' + i], (SyncTreeArray[i].obj).objID, i);
    G_Assocs[AssocID].Folder_is_ready_array[i] = result;
    SyncTreeArray[i].if_ready = result;
  }

  Assoc_element.all.TopCapArrowLeft.className = 'Cap_arrow_left' + SyncTreeArray[0].cap_arrow_direction;
  Assoc_element.all.TopCapArrowRight.className = 'Cap_arrow_right' + SyncTreeArray[1].cap_arrow_direction;
  Assoc_element.all.TopCapRadioLeft.innerHTML = '<img tabindex="3" src="Pics/Radio_left_' + SyncTreeArray[0].radio + '.gif" class="Cap_Radio_control" onkeypress="CapRadioHandler(\'' + AssocID + '\',\'' + SyncTreeArray[0].superID + '\')" onclick="CapRadioHandler(\'' + AssocID + '\',\'' + SyncTreeArray[0].superID + '\')" title="' + external.LS('tooltip_one_way_sync') + '" onactivate="CapMenuFocusIn()" ondeactivate="CapMenuFocusOut()">';
  Assoc_element.all.TopCapRadioRight.innerHTML = '<img tabindex="3" src="Pics/Radio_right_' + SyncTreeArray[1].radio + '.gif" class="Cap_Radio_control" onkeypress="CapRadioHandler(\'' + AssocID + '\',\'' + SyncTreeArray[1].superID + '\')" onclick="CapRadioHandler(\'' + AssocID + '\',\'' + SyncTreeArray[1].superID + '\')" title="' + external.LS('tooltip_one_way_sync') + '" onactivate="CapMenuFocusIn()" ondeactivate="CapMenuFocusOut()">';


  if (SyncTreeArray.length > 4) {
    var BoardsContainer = document.getElementById('SyncBoardsTableCell');
    // alert(BoardsContainer);
    if (BoardsContainer) {
      // BoardsContainer.style.overflow = 'auto';
      // BoardsContainer.style.width = '100%';
      BoardsContainer.style.height = '154px';
      // alert(BoardsContainer.style.height);
      // BoardsContainer.style.overflow = 'auto';

      // style="overflow: auto; overflow-y:scroll; WIDTH:100%; HEIGHT: 100%;"
    } else {
      BoardsContainer.style.height = '52px';
    }
  }

  if (SyncTreeArray.length > 2) {
    Assoc_element.all.Cap_arrow_branch.className = 'Cap_arrow_branch1';

    for (i = 2; i < (SyncTreeArray.length - 1); i++) {	// All middle forders
      var NewRow = SyncBoardsTableBody_element.insertRow();
      var EmptyFolderCell = NewRow.insertCell();
      var EmptyCell = NewRow.insertCell();
      EmptyCell.colSpan = '3';
      EmptyCell.onclick = CapMenuClick;
      EmptyCell.onmouseleave = CapMenuLeave;
      EmptyCell.onmouseenter = CapMenuEnter;
      EmptyCell.className = 'CapMenuPlate';
      var BranchCell = NewRow.insertCell();
      BranchCell.innerHTML = '<div class="Cap_arrow_branch_middle"></div>';
      BranchCell.onclick = CapMenuClick;
      BranchCell.onmouseleave = CapMenuLeave;
      BranchCell.onmouseenter = CapMenuEnter;
      BranchCell.className = 'CapMenuPlate';
      var RightArrowCell = NewRow.insertCell();
      RightArrowCell.height = '30';
      RightArrowCell.innerHTML = '<div class="Cap_arrow_right' + SyncTreeArray[i].cap_arrow_direction + '"></div>';
      RightArrowCell.onclick = CapMenuClick;
      RightArrowCell.onmouseleave = CapMenuLeave;
      RightArrowCell.onmouseenter = CapMenuEnter;
      RightArrowCell.className = 'CapMenuPlate';
      var RadioCell = NewRow.insertCell();
      RadioCell.innerHTML = '<img tabindex="3" src="Pics/Radio_right_' + SyncTreeArray[i].radio + '.gif" class="Cap_Radio_control" onkeypress="CapRadioHandler(\'' + AssocID + '\',\'' + SyncTreeArray[i].superID + '\')" onclick="CapRadioHandler(\'' + AssocID + '\',\'' + SyncTreeArray[i].superID + '\')" title="' + external.LS('tooltip_one_way_sync') + '" onactivate="CapMenuFocusIn()" ondeactivate="CapMenuFocusOut()">';
      RadioCell.onclick = CapMenuClick;
      RadioCell.onmouseleave = CapMenuLeave;
      RadioCell.onmouseenter = CapMenuEnter;
      RadioCell.className = 'CapMenuPlate';
      RadioCell.style.padding = '5px';
      var FolderCell = NewRow.insertCell();
      FolderCell.bgcolor = 'red'; // #C0C0B4
      FolderCell.style.padding = '0px';
      FolderCell.innerHTML = '<div style="position:relative; top:0; left:0;">' +
				'<div id="Syncpath_hint_' + i + '" class="Right_hint_hidden"></div>' +
				'</div>' +
				'<div id="SyncTree' + i + '" synctree_id="" style="position:relative; width:100%; border:solid 1px #c0c0b4;"></div>';

      result = BuildFolderPanel(SyncBoardsTableBody_element.all['SyncTree' + i], (SyncTreeArray[i].obj).objID, i);
      G_Assocs[AssocID].Folder_is_ready_array[i] = result;
      SyncTreeArray[i].if_ready = result;
    }

    i = SyncTreeArray.length - 1;
    // --- Last folder
    var NewRow = SyncBoardsTableBody_element.insertRow();
    var EmptyFolderCell = NewRow.insertCell();
    var EmptyCell = NewRow.insertCell();

    EmptyCell.colSpan = '3';
    EmptyCell.onclick = CapMenuClick;
    EmptyCell.onmouseleave = CapMenuLeave;
    EmptyCell.onmouseenter = CapMenuEnter;
    EmptyCell.className = 'CapMenuPlate';

    BranchCell = NewRow.insertCell();

    BranchCell.innerHTML = '<div class="Cap_arrow_branch_bottom"></div>';
    BranchCell.onclick = CapMenuClick;
    BranchCell.onmouseleave = CapMenuLeave;
    BranchCell.onmouseenter = CapMenuEnter;
    BranchCell.className = 'CapMenuPlate';

    RightArrowCell = NewRow.insertCell();

    RightArrowCell.height = '30';
    RightArrowCell.innerHTML = '<div class="Cap_arrow_right' + SyncTreeArray[i].cap_arrow_direction + '"></div>';
    RightArrowCell.onclick = CapMenuClick;
    RightArrowCell.onmouseleave = CapMenuLeave;
    RightArrowCell.onmouseenter = CapMenuEnter;
    RightArrowCell.className = 'CapMenuPlate';

    RadioCell = NewRow.insertCell();

    RadioCell.innerHTML = '<img tabindex="3" src="Pics/Radio_right_' + SyncTreeArray[i].radio + '.gif" class="Cap_Radio_control" onkeypress="CapRadioHandler(\'' + AssocID + '\',\'' + SyncTreeArray[i].superID + '\')" onclick="CapRadioHandler(\'' + AssocID + '\',\'' + SyncTreeArray[i].superID + '\')" title="' + external.LS('tooltip_one_way_sync') + '" onactivate="CapMenuFocusIn()" ondeactivate="CapMenuFocusOut()">';
    RadioCell.onclick = CapMenuClick;
    RadioCell.onmouseleave = CapMenuLeave;
    RadioCell.onmouseenter = CapMenuEnter;
    RadioCell.className = 'CapMenuPlate';
    RadioCell.style.padding = '5px';

    FolderCell = NewRow.insertCell();

    FolderCell.bgcolor = '#C0C0B4';
    FolderCell.style.padding = '0px';
    FolderCell.innerHTML = '<div style="position:relative; top:0; left:0;">' +
			'<div id="Syncpath_hint_' + i + '" class="Right_hint_hidden"></div>' +
			'</div>' +
			'<div id="SyncTree' + i + '" synctree_id="" style="position:relative; width:100%; border:solid 1px #c0c0b4;"></div>';

    result = BuildFolderPanel(SyncBoardsTableBody_element.all['SyncTree' + i], (SyncTreeArray[i].obj).objID, i);

    G_Assocs[AssocID].Folder_is_ready_array[i] = result;
    SyncTreeArray[i].if_ready = result;
    //		------------------
  }
  if (AssocID == G_ActiveAssocID) {
    if (WinningSuperTreeID == CONST_CID) {
      Caption_down_plate.all.AllWayRadio.src = 'Pics/Radio_all_way.gif';
    } else {
      Caption_down_plate.all.AllWayRadio.src = 'Pics/Radio_all_way_unactive.gif';
    }
    If_remove_check.checked = AssocObj.Method0('M_GetMimicDeleted');
    If_rewrite_check.checked = AssocObj.Method0('M_GetMimicChanged');
    ResizeWindow();
  }
  //-----------------------------------------------------------------------
  //
  //-----------------------------------------------------------------------
  var HintCalledNumber = -1;
  for (i = SyncTreeArray.length - 1; i >= 0; i--) if (SyncTreeArray[i].if_ready == false) HintCalledNumber = i;
  if (HintCalledNumber != -1) {
    G_Assocs[AssocID].Folders_is_ready = false;
    setTimeout("FocusToSyncpath('" + AssocID + "', '" + HintCalledNumber + "')", 0);
    return 0;
  }

  G_Assocs[AssocID].Folders_is_ready = true;

  return true;
}

//	--------------------------------------------------------------------------
//  Creates HTML code for Folder panel info showing
//	--------------------------------------------------------------------------

function BuildFolderPanel(SyncTreeElement, SyncTreeObjectID, FolderNum)	//	Returns true if tree is ready and false otherwise
{
  //----------------------------------------------------------------
  var SyncTreeObject = external.ObjByID(SyncTreeObjectID); // alert(SyncTreeObject);
  var WizardType = SyncTreeObject.Method0('M_GetDeviceType');
  // ----------------------------------------------------------------
  SyncTreeElement.synctree_id = SyncTreeObject.objID;
  SyncTree_path = SyncTreeObject.Method0Own('M_ToViewFilename');
  if (WizardType == PATH_TYPE__NONE || WizardType == PATH_TYPE_EMPTY) SyncTree_path = '';
  // ----------------------------------------------------------------
  if (SyncTreeObject.Method0('M_IsTreeReady') == 1) {
    if_empty_flag = 'false';
    IfTreeReady = true;
  } else {
    if_empty_flag = 'true';
    IfTreeReady = false;
  }

  // ----------------------------------------------------------------
  var Image_SRC = 0;
  //----------------------------
  var ImageSRC = G_WizardTypeInfoList[WizardType][Image_SRC];
  // ----------------------------------------------------------------
  var Button_Caption = 1;
  //----------------------------
  var ButtonCaption = G_WizardTypeInfoList[WizardType][Button_Caption];
  // ----------------------------------------------------------------
  var Folder_Type_Name = 2;
  //----------------------------
  var FolderTypeName = G_WizardTypeInfoList[WizardType][Folder_Type_Name];
  //----------------------------------------------------------------

  var sImageFilter='';
  var sButtonStyle='';
  if (SyncTreeObject.Method0('M_IsDeviceDeprecated')) {
	sImageFilter = 'gray ';
	sButtonStyle = 'visibility:hidden;';
	FolderTypeName += ' (not supported)';
  }

  SyncTreeElement.innerHTML = '<form id="TreeForm' + FolderNum + '" onSubmit="return ChangeSyncTree(' + FolderNum + ');" style="margin:0px;" title="' +
		external.LS('tooltip_sync_board_right') +
		'"  ondeactivate="Deactivate_form(' + FolderNum + ',\'' + G_ActiveAssocID + '\')" is_changed="false" is_empty="' + if_empty_flag + '">' +
		'<table  id="TreeForm' + SyncTreeObject.objID + FolderNum + '" width="100%" cellspacing="0" style="border: solid white 0px;">' + //  style="background:#5AA2B8; border: solid white 1px;" border: solid #5AA2B8 1px;
		'<tr>' +
		'<td nowrap style="border: solid white 0px;">' +
		'</td>' +
		'<td  width="100%" height="22px;" style="border: solid white 0px;" >' +
		'<table width="100%" cellspacing="0" id="' + 'DefaultPanelObj' + SyncTreeObject.objID + FolderNum + '" style="display: \'\';">' +
		'<tbody>' +
		'<tr>' +
		'<td colspan="4" nowrap>' +
		'<div style="position:relative; top:0px; left:0px; height:22px;">' +
		'<div id="TreePath' + FolderNum + '" style="position:absolute; top:0px; left:0px; width:100%; height:25px;">' +
		'<input tabindex="3" id="' + SyncTreeObject.objID + '_path" type="text" value="' + SyncTree_path +
		'" style="width:100%;  background:#f6f6f6; font-family:tahoma; font-size:10pt;" ' +
		'onkeyup="Ok_Activate(' + FolderNum + ')" ' +
    'onactivate="Activate_form(' + FolderNum + ')" ' +
    'onmousedown="event.cancelBubble = true;"' +
    'onmousemove="event.cancelBubble = true;"' +
    'onmouseup="event.cancelBubble = true;"' +
    'ondblclick="event.cancelBubble = true;"' +
		'onkeypress=" CheckPressEnter (event, this, \'' + SyncTreeObject.objID + '\',\'' + FolderNum + '\');	' +
		'">' +
		//------------------
		'</div>' +
		'</div>' +
		'</td>' +
		'</tr>' +
		'<tr>' +
		'<td nowrap>' +
		//------------------
		'<span ' +
		'style=" width:22px; height:22px; cursor: hand; display:inline-block; filter:' + sImageFilter + 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + ImageSRC + '\', sizingMethod=\'scale\');"' +
		'id="WizardPicture' + SyncTreeObject.objID + FolderNum + '"; ' +
		'onclick=\'' +
		'var SyncTree_elem = document.getElementById("Assoc_' + G_ActiveAssocID + '").all["SyncTree' + FolderNum + '"];' +
		'var SyncTreeID = SyncTree_elem.synctree_id; ' +
		'SyncTree_elem.className = "Unactive_panel"; ' +
		'G_OnProfileChanged_called = false; ' +
		'external.Method1ID("M_BrowseButtonPressedForTree","' + SyncTreeObject.objID + '"); ' +
		'if(G_OnProfileChanged_called == false)	GetBackSyncBoard(' + FolderNum + '); ' +
		'return;' +
		'\' ' +
		'></span>' +
		//------------------
		'<span style=" width:5px; height:22px;"></span>' +
		// ------------------
		// '<span unselectable style="font-size:12px; font-family:Arial; color:black; padding-top:6px;">'+
		// external.LS('folder_Panel_Type')+
		// ' </span>'+
		'</td>' +
		// -----------------------------------------------------------------------------------------------------------------------------------
		'<td width="100%">' +
		// ---------------------------------------------------------------
		'<table cellpadding = 0 cellspacing = 0 width=100%>' +
		'<tr width=100%>' +
		'<td  style = "vertical-align:center; width:100%">' +
		'<input UNSELECTABLE = \'on\'; name = "Folder_Type' + SyncTreeObject.objID + FolderNum + '" ' +
		'id = "Folder_Type' + SyncTreeObject.objID + FolderNum + '" UNSELECTABLE ' +
		'style = "cursor:hand;  margin:0; padding:0; padding-left: 2px; padding-right: 2px; width:100%; ' +
		'font-family:Tahoma; font-size:9pt; background: #c0c0b4; color: black;" ' + // background: #c0c0b4; color: #11100d;
		'title = \'' + external.LS('tooltip_sync_board_type_select') + '\'' +
		'onclick 	= "Folder_Type_list_container.SyncTreeObjectID = \'' + SyncTreeObject.objID + '\'; ' +
		'Folder_Type_list_container.FolderNum        = \'' + FolderNum + '\'; ' +
		// -----------------------------------------------------------------------------------------------
		// Folder Type List Size/Position Calculation
		//-----------------------------------------------------------------------------------------------
		'TypeListPanelRefresh (\'' + SyncTreeObject.objID + '\', \'' + FolderNum + '\'); ' +
		'G_Folder_Type_List_folder_num = \'' + FolderNum + '\'; ' +
		'G_Folder_Type_List_Sync_Tree_Obj_ID = \'' + SyncTreeObject.objID + '\';' +
		// -----------------------------------------------------------------------------------------------
		'if (Folder_Type_list_container.style.visibility == \'hidden\') ' +
		'{Folder_Type_list_container.style.visibility = \'visible\'; G_Folder_Type_List_Mouse_Status = \'true\';} ' +
		'else {Folder_Type_list_container.style.visibility = \'hidden\'; G_Folder_Type_List_Mouse_Status = \'false\';} ' +
		//-----------------------------------------------------------------------------------------------
		'"' +
		'value = \'' + FolderTypeName + '\'>' +
		'</td>' +
		//------------------------------
		'<td style = "vertical-align:center" style="cursor: hand; padding-left: 0px;">' +
		'<img src = "Pics/SelectSwitch.gif" ' +
		'title = \'' + external.LS('tooltip_sync_board_type_select') + '\'' +
		'onclick = "Folder_Type_list_container.SyncTreeObjectID = \'' + SyncTreeObject.objID + '\'; ' +
		'Folder_Type_list_container.FolderNum        = \'' + FolderNum + '\'; ' +
		// -----------------------------------------------------------------------------------------------
		// Folder Type List Size/Position Calculation
		// -----------------------------------------------------------------------------------------------
		'TypeListPanelRefresh (\'' + SyncTreeObject.objID + '\', \'' + FolderNum + '\'); ' +
		'G_Folder_Type_List_folder_num = \'' + FolderNum + '\'; ' +
		'G_Folder_Type_List_Sync_Tree_Obj_ID = \'' + SyncTreeObject.objID + '\';' +
		// -----------------------------------------------------------------------------------------------
		'if (Folder_Type_list_container.style.visibility == \'hidden\') ' +
		'{Folder_Type_list_container.style.visibility = \'visible\'; G_Folder_Type_List_Mouse_Status = \'true\';} ' +
		'else {Folder_Type_list_container.style.visibility = \'hidden\'; G_Folder_Type_List_Mouse_Status = \'false\';} ' +
		//-----------------------------------------------------------------------------------------------
		'">' +
		'</td>' +
		//------------------------------
		'<td align="right"; style= "cursor:hand"; >' +
		'<span unselectable ' +
		'id = \'' + SyncTreeObject.objID + '_traffic_del\'; ' +
		'title = \'' + external.LS('tooltip_sync_board_del_traffic') + '\' ' +
		'style="width:48px; font-size:9px; font-family:Arial; color:red; padding-top:3px; padding-right:2px;">' +
		// '-'+
		external.Method1('M_GetDeletedDataInfo', SyncTreeObject.objID) +
		' </span>' +
		//---
		'<span unselectable ' +
		'id = \'' + SyncTreeObject.objID + '_traffic_mov\'; ' +
		'title = \'' + external.LS('tooltip_sync_board_mov_traffic') + '\' ' +
		'style="width:48px; font-size:9px; font-family:Arial; color:blue; padding-bottom:3px; padding-right:2px;">' +
		// '-'+
		external.Method1('M_GetChangedDataInfo', SyncTreeObject.objID) +
		' </span>' +
		'</td>' +
  //------------------------------

		'</tr>' +
		'</table>' +
		// ---------------------------------------------------------------
		'</td>' +
		// -----------------------------------------------------------------------------------------------------------------------------------
		'<td nowrap style="border:0px; padding-left: 3px; ' + sButtonStyle + '">' +
		'<img src="Pics/Folder_button_left.gif" align="top"' +
		'id="More' + SyncTreeObject.objID + FolderNum + 'left">' +
		'<span UNSELECTABLE opened="off" title="' + external.LS('tooltip_browse_for_projectfolder') + // onclick
		'" tabindex="2" name="More' + FolderNum + '" id="More' + SyncTreeObject.objID + FolderNum + '" onClick="ExtendSyncTreeInfo(this,' + FolderNum + ',\'' + SyncTreeObject.objID + '\');"' +
		'onmouseenter=FolderButtonSelect(this) onmouseleave=FolderButtonUnselect(this) ' +
		'style="top:2px; width:1px; height: 20px; cursor:hand; padding-left:3px; padding-right:3px;' +  // width:67px;
		'font-size:11px; font-family:Arial; padding-top:3px; text-align: middle; color:black; background:url(Pics/Folder_button_center.gif) repeat-x center;"' +
		'> ' +
		ButtonCaption + ' ' +
		'</span>' +
		'<img src="Pics/Folder_button_right.gif" align="top"' +
		'id="More' + SyncTreeObject.objID + FolderNum + 'right">' +
		'</td>' +
		// -----------------------------------------------------------------------------------------------------------------------------------
		'</tr>' +
		'</tbody>' +
		'</table>' +
		// ----------------------------------------------------------------------------------------------- Wizard
		'</td>' +
		'</tr>' +
		'</table>' +

		'</form>';
  //----------------------------------------------------------------

  return IfTreeReady;
}

function CheckPressEnter(evt, htmlEl, SyncTreeObjectID, FolderNum) {
  if (evt.keyCode == 13) {
    return ChangeSyncTree(FolderNum);
  }
  return false;
}

function OnCollectionExpandIconClick(AssocID, CollectionID) {
  G_Assocs[AssocID].TreeView.click(CollectionID);
}
// -----------------------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------------------
function go_next_message(CollectionID) {
  G_Collection_lock = true;
  //-----------------------
  var collection_container = document.all[CollectionID + '_container'];
  if (collection_container == null) { G_Collection_lock = false; return; }
  // -----------------------------------------------------------------------------------------
  var msgs = external.ObjByID(CollectionID);
  var msgs_count = collection_container.children.length;
  MsgID = collection_container.children(msgs_count - 1).id;
  var new_on_page_last_msg = msgs.GetNext(msgs.ObjByID(MsgID));

  if (new_on_page_last_msg == null) {
    G_ScrollButtonIsPressed = false;
    go_last_page(CollectionID);
    G_Collection_lock = false;
    return;
  }
  var new_on_page_last_msg_id = msgs.GetNext(msgs.ObjByID(MsgID)).objID;
  //----------------------------------------------------------
  //	var MsgID = collection_container.children(0).id;
  var MsgID = collection_container.children(1).id; // first line is header line
  var message_container_element = collection_container.all[MsgID];
  if (message_container_element) message_container_element.removeNode(true);
  // -----------------------------------------------------------------------------------------
  var current_first_message_element_index = msgs.Method0('M_GetFirstVisibleMessageIndex');
  msgs.method1('M_SetFirstVisibleMessageByIndex', current_first_message_element_index + 1);
  //-----------------------

  var MsgEvenness = G_Assocs[G_ActiveAssocID].TreeView.root._children[CollectionID]._first_disp_msg_evenness;
  G_Assocs[G_ActiveAssocID].TreeView.root._children[CollectionID]._first_disp_msg_evenness = 1 - MsgEvenness;
  var new_last_message_element = document.createElement('tbody');
  collection_container.appendChild(new_last_message_element);
  //-----------------------
  var name_mode = 'Short name';
  if (CONST_CollapseFileName == false) name_mode = 'Full name';
  //-----------------------
  BuildMessageAsObject(new_last_message_element, CollectionID, new_on_page_last_msg_id, (MsgEvenness + CONST_MESSAGES_ON_PAGE) % 2, name_mode);
  //-----------------------
  G_Collection_lock = false;
  //-----------------------
  // AutoRefreshScrollers(G_ActiveAssocID, CollectionID);
  //-----------------------
  if (G_ScrollButtonIsPressed == true) {
    var AssocElement = document.getElementById('Assoc_' + G_ActiveAssocID);
    RefreshMsgScrollBar(AssocElement, CollectionID);
    window.setTimeout('go_next_message("' + CollectionID + '");', 30);
  } else {
    AutoRefreshScrollers(G_ActiveAssocID, CollectionID);
  }
}
//	--------------------------------------------------------------------------
//
//	--------------------------------------------------------------------------

function go_prev_message(CollectionID) {
  G_Collection_lock = true;
  //-----------------------
  var collection_container = document.all[CollectionID + '_container'];
  if (collection_container == null) { G_Collection_lock = false; return; }
  //-----------------------------------------------------------------------------
  var msgs = external.ObjByID(CollectionID);
  var first_visible_msg_id = msgs.Method0('M_GetFirstVisibleMessage').objID;
  var first_msg_id = msgs.GetFirst().objID;

  if (first_visible_msg_id == first_msg_id) {
    G_ScrollButtonIsPressed = false;
    go_first_page(CollectionID);
    G_Collection_lock = false;
    return;
  }
  // -----------------------------------------------------------------------------
  var msgs_count = collection_container.children.length;
  var MsgID = collection_container.children(msgs_count - 1).id;
  var message_container_element = collection_container.all[MsgID];
  if (message_container_element) message_container_element.removeNode(true);
  //-----------------------------------------------------------------------------------------
  var new_first_msg_index = msgs.Method0('M_GetFirstVisibleMessageIndex') - 1;
  msgs.method1('M_SetFirstVisibleMessageByIndex', new_first_msg_index);
  //-----------------------
  var new_first_msg_id = msgs.Method0('M_GetFirstVisibleMessage').objID;
  //-----------------------------------------------------------------------------------------
  var new_first_msg_evenness = (G_Assocs[G_ActiveAssocID].TreeView.root._children[CollectionID]._first_disp_msg_evenness + 1) % 2;
  G_Assocs[G_ActiveAssocID].TreeView.root._children[CollectionID]._first_disp_msg_evenness = new_first_msg_evenness;
  //-----------------------------------------------------------------------------------------
  var new_first_msg_element = document.createElement('tbody');
  //	collection_container.insertBefore(new_first_msg_element, collection_container.children(0));
  collection_container.insertBefore(new_first_msg_element, collection_container.children(1)); // first line is a header line
  //-----------------------
  var name_mode = 'Short name';
  if (CONST_CollapseFileName == false) name_mode = 'Full name';
  //-----------------------
  BuildMessageAsObject(new_first_msg_element, CollectionID, new_first_msg_id, new_first_msg_evenness, name_mode);
  // -----------------------------------------------------------------------------------------
  G_Collection_lock = false;
  //-----------------------
  // AutoRefreshScrollers(G_ActiveAssocID, CollectionID);
  //-----------------------
  if (G_ScrollButtonIsPressed == true) {
    var AssocElement = document.getElementById('Assoc_' + G_ActiveAssocID);
    RefreshMsgScrollBar(AssocElement, CollectionID);
    window.setTimeout('go_prev_message("' + CollectionID + '");', 30);
  } else {
    AutoRefreshScrollers(G_ActiveAssocID, CollectionID);
  }
}
//	--------------------------------------------------------------------------
//
//	--------------------------------------------------------------------------
function go_first_page(CollectionID) {
  G_Collection_lock = true;
  //-----------------------
  var msgs = G_Assocs[G_ActiveAssocID].TreeView._collections[CollectionID].obj;
  msgs.Method1('M_SetFirstVisibleMessageByIndex', 0);
  //-----------------------
  G_Assocs[G_ActiveAssocID].TreeView.root._children[CollectionID]._first_disp_msg_evenness = 1;
  G_Assocs[G_ActiveAssocID].TreeView.redraw_collection(CollectionID);
  //-----------------------
  G_Collection_lock = false;
}
//	--------------------------------------------------------------------------
//
//	--------------------------------------------------------------------------
function go_last_page(CollectionID) {
  G_Collection_lock = true;
  //-----------------------
  var msgs = G_Assocs[G_ActiveAssocID].TreeView._collections[CollectionID].obj;
  var msg_count = msgs.Method0('M_GetCount');
  var page_size = external.Method1('M_GetGlobalOption', 'ItemsPerPage');
  var msg_index = msg_count - page_size;
  if (msg_index < 0) msg_index = 0;
  // -----------------------------------------
  msgs.Method1('M_SetFirstVisibleMessageByIndex', msg_index);
  //-----------------------
  G_Assocs[G_ActiveAssocID].TreeView.root._children[CollectionID]._first_disp_msg_evenness = 1;
  G_Assocs[G_ActiveAssocID].TreeView.redraw_collection(CollectionID);
  //------------------------
  G_Collection_lock = false;
}
//	--------------------------------------------------------------------------
//
//	--------------------------------------------------------------------------
function go_prev_page(CollectionID) {
  G_Collection_lock = true;
  //-----------------------
  // var control_element = window.event.srcElement;
  var AssocElement = document.getElementById('Assoc_' + G_ActiveAssocID);
  var collection_container = AssocElement.all[CollectionID + '_container'];
  if (collection_container == null) return;
  //----------------------------------------------------------------------------------------
  var msgs = G_Assocs[G_ActiveAssocID].TreeView._collections[CollectionID].obj;
  // ----------------------------------------------------------------------------------------
  var msg_index = msgs.Method0('M_GetFirstVisibleMessageIndex');
  var page_size = external.Method1('M_GetGlobalOption', 'ItemsPerPage');

  if (msg_index < page_size) msg_index = 0;
  else msg_index = msg_index - page_size;
  // ----------------------------------------------------------------------------
  msgs.Method1('M_SetFirstVisibleMessageByIndex', msg_index);
  //-----------------------
  var MsgEvenness = G_Assocs[G_ActiveAssocID].TreeView.root._children[CollectionID]._first_disp_msg_evenness;
  G_Assocs[G_ActiveAssocID].TreeView.root._children[CollectionID]._first_disp_msg_evenness = (MsgEvenness + page_size) % 2;
  G_Assocs[G_ActiveAssocID].TreeView.redraw_collection(CollectionID);
  //-----------------------
  G_Collection_lock = false;
  //-----------------------
  if (G_ScrollButtonIsPressed == true) {
    window.setTimeout('go_prev_page("' + CollectionID + '");', 50);
  }
  //-----------------------
}
//	--------------------------------------------------------------------------
//
//	--------------------------------------------------------------------------
function go_next_page(CollectionID) {
  G_Collection_lock = true; // alert('go_next_page');
  //-----------------------
  // var control_element = window.event.srcElement;
  var AssocElement = document.getElementById('Assoc_' + G_ActiveAssocID);
  var collection_container = AssocElement.all[CollectionID + '_container'];
  if (collection_container == null) return;
  //----------------------------------------------------------------------------------------
  var msgs = G_Assocs[G_ActiveAssocID].TreeView._collections[CollectionID].obj;
  // ----------------------------------------------------------------------------------------
  var msg = msgs.Method0('M_GetFirstVisibleMessage');
  var msg_index = msgs.Method0('M_GetFirstVisibleMessageIndex');
  if (msg != null) var lastVisibleMsg = msg;
  while (msg != null) {
    msg = msgs.Method1('M_GetNextVisibleMessage', msg);
    if (msg != null) { lastVisibleMsg = msg; msg_index++; }
  }
  //----------------------------------------------------------------------------------------
  var firstVisibleMsg = msgs.GetNext(lastVisibleMsg);

  if (firstVisibleMsg != null) {
    msg_index++;
    msg_count = msgs.Method0('M_GetCount');
    page_size = external.Method1('M_GetGlobalOption', 'ItemsPerPage');
    if (msg_index + page_size >= msg_count) msg_index = msg_count - page_size;
    // ----------------------------------------------------------------------------
    msgs.Method1('M_SetFirstVisibleMessageByIndex', msg_index);
    //-----------------------
    MsgEvenness = G_Assocs[G_ActiveAssocID].TreeView.root._children[CollectionID]._first_disp_msg_evenness;
    G_Assocs[G_ActiveAssocID].TreeView.root._children[CollectionID]._first_disp_msg_evenness = (MsgEvenness + page_size) % 2;
    G_Assocs[G_ActiveAssocID].TreeView.redraw_collection(CollectionID);
  }
  //-----------------------
  G_Collection_lock = false;
  //-----------------------
  if (G_ScrollButtonIsPressed == true) {
    window.setTimeout('go_next_page("' + CollectionID + '");', 50);
  }
  //-----------------------
}
//	--------------------------------------------------------------------------
//
//	--------------------------------------------------------------------------
function CreateScrollControls(direction, if_active, CollectionID, MsgScrollersExist) {
  if (!MsgScrollersExist) {
    this.msg = '<img src="Pics/Dot.gif">'; this.page = '<img src="Pics/Dot.gif">'; this.end = '<img src="Pics/Dot.gif">';
    this.top_msg = '<img src="Pics/Dot.gif">'; this.top_page = '<img src="Pics/Dot.gif">'; this.top_end = '<img src="Pics/Dot.gif">';
    this.scroll = '<img src="Pics/Dot.gif">';
    return this;
  }

  // var dir1; var dir2; var dir3; var  dir4 = '';
  if (direction == 'next') {
    dir1 = 'next';
    dir2 = 'Next';
    dir3 = 'last';
    dir4 = 'Last';
  } else {
    dir1 = 'prev';
    dir2 = 'Prev';
    dir3 = 'first';
    dir4 = 'First';
  }
  var border_style = 'style="margin-left: 1px;"';
  var border_style_brink = 'style="margin-left: 1px;"';
  if (if_active == true) {
    this.msg = '<img onmousedown="ScrollControlDown(this, \'' + CollectionID + '\', \'' + dir1 + '_message\')" onclick="go_' + dir1 + '_message(\'' + CollectionID + '\');" ondblclick="go_' + dir1 + '_message(\'' + CollectionID + '\');" onmouseenter="ScrollControlHi(this)" onmouseleave="ScrollControlUsual(this)" onmouseup="ScrollControlUp(this)" src="Pics/' + dir2 + 'Message.gif" style="cursor:hand" title="' + external.LS('tooltip_' + dir1 + '_message') + '">';
    this.page = '<img onmousedown="ScrollControlDown(this, \'' + CollectionID + '\', \'' + dir1 + '_page\')" onclick="go_' + dir1 + '_page(\'' + CollectionID + '\');" ondblclick="go_' + dir1 + '_page(\'' + CollectionID + '\');" onmouseenter="ScrollControlHi(this)" onmouseleave="ScrollControlUsual(this)" src="Pics/' + dir2 + 'Page.gif" style="cursor:hand" title="' + external.LS('tooltip_' + dir1 + '_page') + '">';
    this.end = '<img onmousedown="ScrollControlDown(this, \'' + CollectionID + '\', \'' + dir3 + '_page\')" onclick="go_' + dir3 + '_page(\'' + CollectionID + '\');" ondblclick="go_' + dir3 + '_page(\'' + CollectionID + '\');" onmouseenter="ScrollControlHi(this)" onmouseleave="ScrollControlUsual(this)" src="Pics/To' + dir4 + '.gif" style="cursor:hand" title="' + external.LS('tooltip_' + dir3 + '_page') + '">';

    this.top_msg = '<img onmousedown="ScrollControlDown(this, \'' + CollectionID + '\', \'' + dir1 + '_message\')" onclick="go_' + dir1 + '_message(\'' + CollectionID + '\');" ondblclick="go_' + dir1 + '_message(\'' + CollectionID + '\');" onmouseenter="ScrollControlHi(this)" onmouseleave="ScrollControlUsual(this)" onmouseup="ScrollControlUp(this)" src="Pics/' + dir2 + 'Message.gif" style="cursor:hand" title="' + external.LS('tooltip_' + dir1 + '_message') + '" ' + border_style + '>';
    this.top_page = '<img onmousedown="ScrollControlDown(this, \'' + CollectionID + '\', \'' + dir1 + '_page\')" onclick="go_' + dir1 + '_page(\'' + CollectionID + '\');" ondblclick="go_' + dir1 + '_page(\'' + CollectionID + '\');" onmouseenter="ScrollControlHi(this)" onmouseleave="ScrollControlUsual(this)" src="Pics/' + dir2 + 'Page.gif" style="cursor:hand" title="' + external.LS('tooltip_' + dir1 + '_page') + '" ' + border_style + '>';
    this.top_end = '<img onmousedown="ScrollControlDown(this, \'' + CollectionID + '\', \'' + dir3 + '_page\')" onclick="go_' + dir3 + '_page(\'' + CollectionID + '\');" ondblclick="go_' + dir3 + '_page(\'' + CollectionID + '\');" onmouseenter="ScrollControlHi(this)" onmouseleave="ScrollControlUsual(this)" src="Pics/To' + dir4 + '.gif" style="cursor:hand" title="' + external.LS('tooltip_' + dir3 + '_page') + '" ' + border_style_brink + '>';
  } else {
    this.msg = '<img src="Pics/' + dir2 + 'Message_gray.gif" >';
    this.page = '<img src="Pics/' + dir2 + 'Page_gray.gif" >';
    this.end = '<img src="Pics/To' + dir4 + '_gray.gif">';

    this.top_msg = '<img src="Pics/' + dir2 + 'Message_gray.gif"  ' + border_style + '>';
    this.top_page = '<img src="Pics/' + dir2 + 'Page_gray.gif"  ' + border_style + '>';
    this.top_end = '<img src="Pics/To' + dir4 + '_gray.gif" ' + border_style_brink + '>';
  }

  //----------------------------------------------------------------------------------------------------------------------------------------------------
  // scrolling block begin
  //----------------------------------------------------------------------------------------------------------------------------------------------------
  var collection_message_list = G_Assocs[G_ActiveAssocID].TreeView._collections[CollectionID].obj;
  var message_counter_value = collection_message_list.Method0('M_GetCount');	// alert(message_counter_value);
  //----------------------------------------------------------------------------------------------------
  if (msgIndex == null) var top_message_index = collection_message_list.method0('M_GetFirstVisibleMessageIndex');
  else top_message_index = msgIndex;	 // alert(collection_message_list.method0('M_GetFirstVisibleMessageIndex') +'  '+ msgIndex);
  //----------------------------------------------------------------------------------------------------
  var bar_container_height = Math.round(100 * (CONST_MESSAGES_ON_PAGE / 10) + (CONST_MESSAGES_ON_PAGE / 10 - 1) * 90) - 7;
  if ((message_counter_value <= CONST_MESSAGES_ON_PAGE)) var factor = 0;
  else factor = (top_message_index) / (message_counter_value - CONST_MESSAGES_ON_PAGE);
  // alert((top_message_index) + '/(' + message_counter_value + '-' + CONST_MESSAGES_ON_PAGE + ')');
  var scroll_bar_y = factor * (bar_container_height - 15);
  scroll_bar_y = Math.round(scroll_bar_y);
  // ----------------------------------
  this.scroll = '<div style="position: relative; height:' + bar_container_height + ';">' +
		'<div id="' + CollectionID + 'BarWrapContainer" ' + ' collectionID="' + CollectionID + '" ' +
		'style="position: absolute; z-index:0; width:16px; height:' + bar_container_height + '; top:0; left:0; ' +
		'background:url(\'Pics/ScrBar_ground.gif\'); background-repeat:repeat-y; background-position:top left;">' +
		'<div id="' + CollectionID + 'BarWrap" class="draggable" collectionID="' + CollectionID + '"' +
		'style="position: absolute; left:0; top:' + scroll_bar_y + '; width: 16px; height:15px; border: solid black 0px; z-index:0;">' +
		'<img id="' + CollectionID + 'Bar" name="' + CollectionID + 'Bar" ' +
		' src="Pics/ScrBar.gif" width="16px" height="15px" border="0" style="cursor: hand;" ' +
		' onmouseenter="ScrollControlHi(this)" onmouseleave="ScrollControlUsual(this)">' +
		'</div>' +
		'</div>' +
		'</div>';
  //----------------------------------------------------------------------------------------------------------------------------------------------------
  // scrolling block end
  //----------------------------------------------------------------------------------------------------------------------------------------------------
  return this;
}

//	--------------------------------------------------------------------------
//
//	--------------------------------------------------------------------------

function RefreshMsgScrollers(AssocElement, direction, if_active, CollectionID, MsgScrollersExist) {
  var collection_scrollbar = AssocElement.all[CollectionID + '_ScrollBar'];
  if (collection_scrollbar == null) return;
  var Scroll_controls = new CreateScrollControls(direction, if_active, CollectionID, MsgScrollersExist);
  if (direction == 'next') {
    dir2 = 'Next';
  } else {
    dir2 = 'Prev';
  }
  collection_scrollbar.all[dir2 + '_msg'].innerHTML = Scroll_controls.msg;
  collection_scrollbar.all[dir2 + '_page'].innerHTML = Scroll_controls.page;
  collection_scrollbar.all[dir2 + '_end'].innerHTML = Scroll_controls.end;
  collection_scrollbar.all.Scroll_all.innerHTML = Scroll_controls.scroll;
  //	collection_top_scrollbar.all['Top'+dir2+'_msg'].innerHTML = Scroll_controls.top_msg;
  //	collection_top_scrollbar.all['Top'+dir2+'_page'].innerHTML = Scroll_controls.top_page;
  //	collection_top_scrollbar.all['Top'+dir2+'_end'].innerHTML = Scroll_controls.top_end;
}
//-------------------------------------------------------------------------------------------------
function RefreshMsgScrollBar(AssocElement, CollectionID) {
  var collection_scrollbar = AssocElement.all[CollectionID + '_ScrollBar'];
  if (collection_scrollbar == null) return;
  // var collection_top_scrollbar = AssocElement.all[CollectionID+'_in'];
  //----------------------------------------------------------------------------------------------------------------------------------------------------
  // scrolling block begin
  // ----------------------------------------------------------------------------------------------------------------------------------------------------
  var collection_message_list = G_Assocs[G_ActiveAssocID].TreeView._collections[CollectionID].obj;
  var message_counter_value = collection_message_list.Method0('M_GetCount');
  //----------------------------------
  if (msgIndex == null) var top_message_index = collection_message_list.method0('M_GetFirstVisibleMessageIndex');
  else var top_message_index = msgIndex;
  //----------------------------------
  var bar_container_height = Math.round(100 * (CONST_MESSAGES_ON_PAGE / 10) + (CONST_MESSAGES_ON_PAGE / 10 - 1) * 90) - 7;
  if ((message_counter_value <= CONST_MESSAGES_ON_PAGE)) var factor = 0;
  else var factor = (top_message_index) / (message_counter_value - CONST_MESSAGES_ON_PAGE);

  var scroll_bar_y = factor * (bar_container_height - 15);
  scroll_bar_y = Math.round(scroll_bar_y);
  //----------------------------------
  var scroll_html = '<div style="position: relative; height:' + bar_container_height + ';">' +
		'<div id="' + CollectionID + 'BarWrapContainer" ' + ' collectionID="' + CollectionID + '" ' +
		'style="position: absolute; z-index:0; width:16px; height:' + bar_container_height + '; top:0; left:0; ' +
		'background:url(\'Pics/ScrBar_ground.gif\'); background-repeat:repeat-y; background-position:top left;">' +

		'<div id="' + CollectionID + 'BarWrap" class="draggable" collectionID="' + CollectionID + '"' +
		'style="position: absolute; left:0; top:' + scroll_bar_y + '; width: 16px; height:15px; border: solid black 0px; z-index:0;">' +
		'<img id="' + CollectionID + 'Bar" name="' + CollectionID + 'Bar" ' +
		' src="Pics/ScrBar.gif" width="16px" height="15px" border="0" style="cursor: hand;" ' +
		' onmouseenter="ScrollControlHi(this)" onmouseleave="ScrollControlUsual(this)">' +
		'</div>' +

		'</div>' +
		'</div>';

  //----------------------------------------------------------------------------------------------------------------------------------------------------
  // scrolling block end
  // ----------------------------------------------------------------------------------------------------------------------------------------------------
  // var Scroll_controls = new CreateScrollControls(direction, if_active, CollectionID, MsgScrollersExist);
  collection_scrollbar.all.Scroll_all.innerHTML = scroll_html;
}

//-------------------------------------------------------------------------------------------------
function ScrollControlHi(control_element) {
  if (G_ScrollButtonIsPressed == false) {
    var control_src = control_element.src;
    if (control_src == null) return;
    control_element.src = control_src.replace(/.gif/, '_hi.gif');
  }
}

function ScrollControlUsual(control_element) {
  var control_src = control_element.src;
  if (control_src == null) return;
  control_element.src = control_src.replace(/(_hi)?.gif/, '.gif');
}

function ScrollControlUp(control_element) {
  var control_src = control_element.src;
  if (control_src == null) return;
  //	control_element.src = control_src.replace(/(_hi)?.gif/,"_hi.gif");
  G_ScrollButtonIsPressed = false;
}

function ScrollControlDown(control_element, collection_id, mode) {
  if (control_element == null) return;
  if (control_element.tagName != 'IMG') return;

  var control_src = control_element.src;	// Error 1152 occurred at 1-5-2
  if (control_src == null) return;
  control_element.src = control_src.replace(/(_hi)?.gif/, '.gif');

  G_ScrollButtonIsPressed = true;

  if (mode == 'next_message') go_next_message(collection_id);
  if (mode == 'prev_message') go_prev_message(collection_id);
  if (mode == 'next_page') go_next_page(collection_id);
  if (mode == 'prev_page') go_prev_page(collection_id);
}
//-------------------------------------------------------------------------------------------------
function CounterRefresh(AssocID, CollectionID, Counter) {
  var collection = G_Assocs[AssocID].TreeView._collections[CollectionID];
  if (collection) { var collection_message_list = G_Assocs[AssocID].TreeView._collections[CollectionID].obj; } else { var collection_message_list = null; }

  if (collection_message_list != null) {
    var collection_node = G_Assocs[AssocID].TreeView.root._children[CollectionID];
    //-----------------------------------------------------------------------------------------------------
    // if it is required collection initialization in GUI
    // -----------------------------------------------------------------------------------------------------
    if ((collection_node._empty == true) && (collection_node._expanded == false)) {
      collection_node._empty = false;
      collection_node._first_disp_msg_evenness = 1;
      G_Assocs[AssocID].TreeView.redraw_collection(CollectionID);
    }
    if (Counter == 0) G_Assocs[AssocID].TreeView.redraw_collection(CollectionID);
    //-----------------------------------------------------------------------------------------------------
    //	counter refreshing
    //-----------------------------------------------------------------------------------------------------
    var association_element = document.getElementById('Assoc_' + AssocID);
    var collection_caption_element = association_element.all[CollectionID + '_caption'];
    if (collection_caption_element) collection_caption_element.innerHTML = Counter;
  }
}

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

function FillMsgNode(MsgObj, MsgEvenness, CollectionID, NameMode) {
  var msg_html = '';

  var TbodyClass = 'Msg_Odd';
  var Msg_selected = MsgObj.Method0('M_GetSelectedState');
  if (Msg_selected == true) TbodyClass = 'Msg_Selected';
  else if (MsgEvenness == 0) TbodyClass = 'Msg_Even';

  if (MsgObj.IsSyncItemMsg()) {
    //------------------------------------------------------
    solution = MsgObj.GetObjM('m_SolutionWPtr');
    if (solution == null) {
      // alert("solution == null");
      return '';
    }
    //------------------------------------------------------
    var WinningTreeID = solution.Method0('M_GetWinningActionAsID'); // DU solution.GetM('MM_WinningTreeID');
    if (WinningTreeID == CONST_WIN_NO_SYNC) {
      Radio_dont_sync = 'true';
      Radio_del_sync = 'false';
    } else if (WinningTreeID == CONST_WIN_DEL_SYNC)// DELL_ALL
    {
      Radio_dont_sync = 'false';
      Radio_del_sync = 'true';
    } else {
      Radio_dont_sync = 'false';
      Radio_del_sync = 'false';
    }
    //------------------------------------------------------
    var AssocObj = MsgObj.GetM('m_SlnDoAssocSyncWPtr');
    var SuperTreeList = AssocObj.GetM('m_SuperTreesPtr');
    var SolutionActionState = solution.Method0('M_GetActionState');// DU solution.GetM('MM_ActionState');
    if (SolutionActionState == CONST_ACTION_STATE_INIT) // ACTION_STATE_INIT
    {
      var Menu_handler = 'onmouseenter="ShowFM()" onmouseleave="HideFM()" onclick="OnPopupClick()" oncontextmenu="StopContextMenu()" msg_id="' + MsgObj.objID + '" collection_id="' + CollectionID + '"';
      var If_gray = '';
      var Progress = '';
      if (solution.Method0('M_GetAvailableItemForSynchronization') == false) {
        Menu_handler = '';
        If_gray = '_gray';
        var Progress = '';
      }
    } else if (SolutionActionState == CONST_ACTION_STATE_IN_PROGRESS) // ACTION_STATE_IN_PROGRESS
    {
      var Menu_handler = '';
      var If_gray = '';
      var Progress = '_progressed';
    } else if (SolutionActionState == CONST_ACTION_STATE_DONE) // ACTION_STATE_DONE
    {
      var Menu_handler = '';
      var If_gray = '_gray';
      var Progress = '';
    } else {
      alert('FillMsgNode3: SolutionActionState == ' + SolutionActionState + ' is out of range');
    }
    // -------------------------------------------------------------------
    SyncTreeArray = new Array();
    var i = 0;
    var Missing_active = false;
    var SuperTree_Obj = SuperTreeList.GetFirst();
    while (SuperTree_Obj != null) {
      SyncTreeArray[i] = {};
      SyncTree_Obj = SuperTree_Obj.GetFirst();
      SyncTreeArray[i].obj = SyncTree_Obj;
      SyncTreeArray[i].id = SuperTree_Obj.objID; // DU SyncTree_Obj.GetM('MM_TreeID');
      SyncTreeArray[i].SyncItemCharacteristics = new CreateSyncItemCharacteristics(solution, SuperTree_Obj, CollectionID, Msg_selected, NameMode);
      SyncTreeArray[i].SyncItemCharacteristics.device_number = i;
      //--------------------------------------------------------------------------------
      if ((WinningTreeID != CONST_WIN_NO_SYNC) && ((WinningTreeID != CONST_WIN_DEL_SYNC))) {
        if (SyncTreeArray[i].id == WinningTreeID) {
          SyncTreeArray[i].arrow_direction = 'out' + If_gray + Progress;
          SyncTreeArray[i].radio = 'active';
          SyncTreeArray[i].radio_handler = 'onclick=OnArrowClick("' + solution.objID + '","' + SyncTreeArray[i].id + '") style="cursor:hand"';

          if (SyncTreeArray[i].SyncItemCharacteristics.if_missing == true) {
            Missing_active = true;
          }
        } else // item is not a winner
        if (SyncTreeArray[i].SyncItemCharacteristics.if_available == false) {
          SyncTreeArray[i].arrow_direction = 'no' + '_gray';
          SyncTreeArray[i].radio = 'unactive';
          SyncTreeArray[i].radio_handler = '';
        } else {
          SyncTreeArray[i].arrow_direction = 'in' + If_gray + Progress;
          SyncTreeArray[i].radio = 'unactive';
          SyncTreeArray[i].radio_handler = 'onclick=OnArrowClick("' + solution.objID + '","' + SyncTreeArray[i].id + '") style="cursor:hand"';
        }
      } else if (WinningTreeID == CONST_WIN_NO_SYNC) {
        SyncTreeArray[i].arrow_direction = 'no' + If_gray + Progress;
        SyncTreeArray[i].radio = 'unactive';
        SyncTreeArray[i].radio_handler = 'onclick=OnArrowClick("' + solution.objID + '","' + SyncTreeArray[i].id + '") style="cursor:hand"';
        if (SyncTreeArray[i].SyncItemCharacteristics.if_available == false) {
          SyncTreeArray[i].radio_handler = '';
          SyncTreeArray[i].arrow_direction = 'no' + '_gray';
        }
      } else if (WinningTreeID == CONST_WIN_DEL_SYNC) {
        SyncTreeArray[i].arrow_direction = 'no' + If_gray + Progress;
        SyncTreeArray[i].radio = 'unactive';
        SyncTreeArray[i].radio_handler = 'onclick=OnArrowClick("' + solution.objID + '","' + SyncTreeArray[i].id + '") style="cursor:hand"';
        if (SyncTreeArray[i].SyncItemCharacteristics.if_available == false) {
          SyncTreeArray[i].radio_handler = '';
          SyncTreeArray[i].arrow_direction = 'no' + '_gray';
        }
      }

      SuperTree_Obj = SuperTreeList.GetNext(SuperTree_Obj);
      i++;
    }
    //---------------------------------------------------------------------------
    var SyncTreeList_length = i;
    if (Missing_active == true) {
      for (i = 0; i < SyncTreeList_length; i++) {
        if (SyncTreeArray[i].arrow_direction == 'in' + If_gray + Progress) {
          SyncTreeArray[i].arrow_direction = 'del' + If_gray + Progress;
        }
      }
    }
    //---------------------------------------------------------------------------
    if (WinningTreeID == CONST_WIN_DEL_SYNC) {
      for (i = 0; i < SyncTreeList_length; i++) {
        if (SyncTreeArray[i].SyncItemCharacteristics.if_available == false) {
          SyncTreeArray[i].arrow_direction = 'no' + '_gray';
        } else { SyncTreeArray[i].arrow_direction = 'del' + If_gray + Progress; }
      }
    }
    //---------------------------------------------------------------------------
    // New!
    if (WinningTreeID == CONST_WIN_NO_SYNC) {
      for (i = 0; i < SyncTreeList_length; i++) {
        if (SyncTreeArray[i].SyncItemCharacteristics.if_available == false) {
          SyncTreeArray[i].arrow_direction = 'no' + '_gray';
        } else { SyncTreeArray[i].arrow_direction = 'no' + If_gray + Progress; }
      }
    }
    //---------------------------------------------------------------------------
    var Gray0 = '';
    var Gray1 = '';

    if (SyncTreeArray[0].SyncItemCharacteristics.if_available == false) Gray0 = '_gray';
    if (SyncTreeArray[1].SyncItemCharacteristics.if_available == false) Gray1 = '_gray';

    if (SyncTreeList_length == 2) {
      msg_html = '<tbody id="' + MsgObj.objID + '" CollectionID="' + CollectionID + '" class="' + TbodyClass + '" MsgEvenness="' + MsgEvenness + '" if_dont_sync="' + Radio_dont_sync +
				'" if_del_sync="' + Radio_del_sync + '" msg_type="2" exist="true" oncontextmenu="OnMsgContextMenu();" ' +
				'onclick="msg_node_onclick();" ' +
				'onmousedown="msg_node_onmousedown();" ' +
				'onmouseup="msg_node_onmouseup();" ' +
				'onmousemove="msg_node_onmousemove();" ' +
				'onmousewheel="msg_node_onmousewheel();" ' +
				'>' +
				'<tr class="Single_row">' +
				//-------------------------------------------------------------------------
				CreateSyncItemCharacteristicsHTML(SyncTreeArray[0].SyncItemCharacteristics) +
				//-------------------------------------------------------------------------
				'<td class="Left_cell" ' + Menu_handler + '>' +
				'<img src="Pics/Radio_left_' + SyncTreeArray[0].radio + Gray0 + '.gif" ' +
				'title="' + external.LS('hint_Winner') + '" ' +
				'class="Radio_control" ' + SyncTreeArray[0].radio_handler + '></td>' +
				//-------------------------------------------------------------------------
				'<td class="Middle_cell" height="100%" ' + Menu_handler + '>' +
				'<div id="Base_' + MsgObj.objID + '" class="Back_plate"><div class="Arrow_left_' + SyncTreeArray[0].arrow_direction + '"></div></div></td>' +
				//-------------------------------------------------------------------------
				'<td class="Middle_cell" height="100%" ' + Menu_handler + '>' +
				'<div class="Back_plate"><div class="Arrow_mid_single' + If_gray + '"></div></div></td>' +
				//-------------------------------------------------------------------------
				'<td class="Middle_cell" height="100%" ' + Menu_handler + '>' +
				'<div class="Back_plate"><div class="Arrow_right_' + SyncTreeArray[1].arrow_direction + '"></div></div></td>' +
				//-------------------------------------------------------------------------
				'<td class="Right_cell" ' + Menu_handler + '>' +
				'<img src="Pics/Radio_right_' + SyncTreeArray[1].radio + Gray1 + '.gif" ' +
				'title="' + external.LS('hint_Winner') + '" ' +
				'class="Radio_control" ' + SyncTreeArray[1].radio_handler + '></td>' +
				//-------------------------------------------------------------------------
				CreateSyncItemCharacteristicsHTML(SyncTreeArray[1].SyncItemCharacteristics) +
				//-------------------------------------------------------------------------
				'</tr>' +
				'</tbody>';
    }
    if (SyncTreeList_length > 2) {
      msg_html = '<tbody id="' + MsgObj.objID + '" CollectionID="' + CollectionID + '" class="' + TbodyClass + '" MsgEvenness="' + MsgEvenness + '" if_dont_sync="' + Radio_dont_sync +
				'" if_del_sync="' + Radio_del_sync + '" msg_type="3" exist="true" oncontextmenu="OnMsgContextMenu();"' +
				'onclick="msg_node_onclick();" ' +
				'onmousedown="msg_node_onmousedown();" ' +
				'onmouseup="msg_node_onmouseup();" ' +
				'onmousemove="msg_node_onmousemove();" ' +
				'onmousewheel="msg_node_onmousewheel();" ' +
				'>';
      // First row
      msg_html += '<tr class="First_row">' + CreateSyncItemCharacteristicsHTML(SyncTreeArray[0].SyncItemCharacteristics) +
				'<td class="Left_cell" ' + Menu_handler + '>' +
				'<img src="Pics/Radio_left_' + SyncTreeArray[0].radio + Gray0 + '.gif" ' +
				'title="' + external.LS('hint_Winner') + '" ' +
				'class="Radio_control" ' + SyncTreeArray[0].radio_handler + '></td>' +
				'<td class="Middle_cell" height="100%" ' + Menu_handler + '>' +
				'<div class="Back_plate"><div class="Arrow_left_' + SyncTreeArray[0].arrow_direction + '"></div></div></td>' +
				'<td class="Middle_cell" height="100%" ' + Menu_handler + '>' +
				'<div id="Base_up_' + MsgObj.objID + '" class="Back_plate"><div class="Arrow_mid_top' + If_gray + '"></div></div></td>' +
				'<td class="Middle_cell" height="100%" ' + Menu_handler + '><div class="Back_plate">' +
				'<div class="Arrow_right_' + SyncTreeArray[1].arrow_direction + '"></div></div></td>' +
				'<td class="Right_cell" ' + Menu_handler + '>' +
				'<img src="Pics/Radio_right_' + SyncTreeArray[1].radio + Gray1 + '.gif" ' +
				'title="' + external.LS('hint_Winner') + '" ' +
				'class="Radio_control" ' + SyncTreeArray[1].radio_handler + '></td>' +
				CreateSyncItemCharacteristicsHTML(SyncTreeArray[1].SyncItemCharacteristics) + '</tr>';
      // Middle rows
      for (i = 2; i < SyncTreeList_length - 1; i++) {
        var Gray = '';
        if (SyncTreeArray[i].SyncItemCharacteristics.if_available == false) Gray = '_gray';

        msg_html += '<tr class="Mid_row">' + CreateSyncItemCharacteristicsHTML(null) +
					'<td class="Left_cell" ' + Menu_handler + '>' + '</td>' +
					'<td class="Middle_cell" height="100%" ' + Menu_handler + '>' + '<div class="Back_plate">' + '</div></td>' +
					'<td class="Middle_cell" height="100%" ' + Menu_handler + '>' + '<div class="Back_plate">' + '<div class="Arrow_mid_mid' + If_gray + '"></div></div></td>' +
					'<td class="Middle_cell" height="100%" ' + Menu_handler + '>' + '<div class="Back_plate">' + '<div class="Arrow_right_' + SyncTreeArray[i].arrow_direction + '"></div></div></td>' +
					'<td class="Right_cell" ' + Menu_handler + '>' +
					'<img src="Pics/Radio_right_' + SyncTreeArray[i].radio + Gray + '.gif" ' +
					'title="' + external.LS('hint_Winner') + '" ' +
					'class="Radio_control" ' + SyncTreeArray[i].radio_handler + '></td>' +
					CreateSyncItemCharacteristicsHTML(SyncTreeArray[i].SyncItemCharacteristics) + '</tr>';
      }
      // Last row
      var Gray = '';
      if (SyncTreeArray[SyncTreeList_length - 1].SyncItemCharacteristics.if_available == false) Gray = '_gray';

      msg_html += '<tr class="Last_row">' + CreateSyncItemCharacteristicsHTML(null) +
				'<td class="Left_cell" ' + Menu_handler + '>' + '</td>' +
				'<td class="Middle_cell" height="100%" ' + Menu_handler + '>' + '<div class="Back_plate"></div></td>' +
				'<td class="Middle_cell" height="100%" ' + Menu_handler + '>' + '<div id="Base_down_' + MsgObj.objID +
				'" class="Back_plate"><div class="Arrow_mid_bottom' + If_gray + '"></div></div></td>' +
				'<td class="Middle_cell" height="100%" ' + Menu_handler + '>' + '<div class="Back_plate">' +
				'<div class="Arrow_right_' + SyncTreeArray[SyncTreeList_length - 1].arrow_direction + '"></div></div></td>' +
				'<td class="Right_cell" ' + Menu_handler + '>' +
				'<img id="radio_left" src="Pics/Radio_right_' + SyncTreeArray[SyncTreeList_length - 1].radio + Gray + '.gif" ' +
				'title="' + external.LS('hint_Winner') + '" ' +
				'class="Radio_control" ' +
				SyncTreeArray[SyncTreeList_length - 1].radio_handler + '></td>' +
				CreateSyncItemCharacteristicsHTML(SyncTreeArray[SyncTreeList_length - 1].SyncItemCharacteristics) + '</tr>';
      msg_html += '</tbody>';
    }
    return msg_html;
  }

  msg_html = '<tbody id="' + MsgObj.objID + '" class="' + TbodyClass + '" exist="true" oncontextmenu="OnMsgContextMenu()"><tr class="Single_row">' +
		'<td colspan="11" class="info_msg">' +
		'<span id="Link' + CollectionID + MsgObj.objID + '"></span>' +
		CreateImportantMsgText(MsgObj) +
		CreateMsgButtons(MsgObj) +
		'</td></tr></tbody>';
  return msg_html;
}

function BuildMessageAsObject(message_tbody_element, CollectionID, MessageID, MsgEvenness, NameMode) {
  if (NameMode === undefined) NameMode = 'Short name';

  var MsgObj = external.ObjByID(MessageID);
  var AssocObj = MsgObj.GetM('m_SlnDoAssocSyncWPtr');

  var Tbody_Class = 'Msg_Odd';
  var Msg_selected = MsgObj.Method0('M_GetSelectedState');
  if (Msg_selected == true) Tbody_Class = 'Msg_Selected';
  else if (MsgEvenness == 0) Tbody_Class = 'Msg_Even';

  message_tbody_element.id = MessageID;
  message_tbody_element.CollectionID = CollectionID;
  message_tbody_element.MsgEvenness = MsgEvenness;
  message_tbody_element.className = Tbody_Class;
  message_tbody_element.oncontextmenu = OnMsgContextMenu;
  //--------------------------------------------------------------------
  var tbody_length = message_tbody_element.rows.length;
  for (i = 0; i < tbody_length; i++)	message_tbody_element.deleteRow();
  // --------------------------------------------------------------------
  if (MsgObj.IsSyncItemMsg()) {
    solution = MsgObj.GetObjM('m_SolutionWPtr');
    if (solution == null) {
      // alert("solution == null");
      return '';
    }
    // -------------------------------------------------------------
    var WinningTreeID = solution.Method0('M_GetWinningActionAsID'); // DU solution.GetM('MM_WinningTreeID');
    if (WinningTreeID == CONST_WIN_NO_SYNC) {
      Radio_dont_sync = 'true';
      Radio_del_sync = 'false';
    } else if (WinningTreeID == CONST_WIN_DEL_SYNC) {
      Radio_dont_sync = 'false';
      Radio_del_sync = 'true';
    } else {
      Radio_dont_sync = 'false';
      Radio_del_sync = 'false';
    }
    //-------------------------------------------------------------
    var AssocObj = MsgObj.GetM('m_SlnDoAssocSyncWPtr');
    var SuperTreeList = AssocObj.GetM('m_SuperTreesPtr');
    var SolutionActionState = solution.Method0('M_GetActionState');// DU solution.GetM('MM_ActionState');
    if (SolutionActionState == CONST_ACTION_STATE_INIT) // ACTION_STATE_INIT
    {
      var Menu_handlers_on = true;
      var If_gray = '';
      var Progress = '';
    } else if (SolutionActionState == CONST_ACTION_STATE_IN_PROGRESS) // ACTION_STATE_IN_PROGRESS
    {
      var Menu_handlers_on = false;
      var If_gray = '';
      var Progress = '_progressed';
    } else if (SolutionActionState == CONST_ACTION_STATE_DONE) // ACTION_STATE_DONE
    {
      var Menu_handlers_on = false;
      var If_gray = '_gray';
      var Progress = '';
    } else {
      alert('BuildMessageAsObject3: SolutionActionState == ' + SolutionActionState + ' is out of range');
    }
    // -------------------------------------------------------------
    SyncTreeArray = new Array();
    var i = 0;
    var Missing_active = false;
    SuperTree_Obj = SuperTreeList.GetFirst();
    while (SuperTree_Obj != null) {
      SyncTreeArray[i] = {};
      SyncTree_Obj = SuperTree_Obj.GetFirst();
      SyncTreeArray[i].obj = SyncTree_Obj;
      SyncTreeArray[i].id = SuperTree_Obj.objID;
      SyncTreeArray[i].SyncItemCharacteristics = new CreateSyncItemCharacteristics(solution, SuperTree_Obj, CollectionID, Msg_selected, NameMode);
      SyncTreeArray[i].SyncItemCharacteristics.device_number = i;
      if ((WinningTreeID != CONST_WIN_NO_SYNC) && (WinningTreeID != CONST_WIN_DEL_SYNC)) {
        if (SyncTreeArray[i].id == WinningTreeID) {
          SyncTreeArray[i].arrow_direction = 'out' + If_gray + Progress;
          SyncTreeArray[i].radio = 'active';
          SyncTreeArray[i].radio_handler = 'onclick=OnArrowClick("' + solution.objID + '","' + SyncTreeArray[i].id + '") style="cursor:hand"';
          if (SyncTreeArray[i].SyncItemCharacteristics.if_missing == true) {
            Missing_active = true;
          }
        } else // if item is not winner
        if (SyncTreeArray[i].SyncItemCharacteristics.if_available == false) {
          SyncTreeArray[i].arrow_direction = 'no' + '_gray';
          SyncTreeArray[i].radio = 'unactive';
          SyncTreeArray[i].radio_handler = '';
        } else {
          SyncTreeArray[i].arrow_direction = 'in' + If_gray + Progress;
          SyncTreeArray[i].radio = 'unactive';
          SyncTreeArray[i].radio_handler = 'onclick=OnArrowClick("' + solution.objID + '","' + SyncTreeArray[i].id + '") style="cursor:hand"';
        }
      } else {
        SyncTreeArray[i].arrow_direction = 'no' + If_gray + Progress;
        SyncTreeArray[i].radio = 'unactive';
        SyncTreeArray[i].radio_handler = 'onclick=OnArrowClick("' + solution.objID + '","' + SyncTreeArray[i].id + '") style="cursor:hand"';
        if (SyncTreeArray[i].SyncItemCharacteristics.if_available == false) {
          SyncTreeArray[i].radio_handler = '';
          SyncTreeArray[i].arrow_direction = 'no' + '_gray';
        }
        if (SyncTreeArray[i].SyncItemCharacteristics.if_syncability == false) {
          SyncTreeArray[i].radio_handler = '';
          SyncTreeArray[i].arrow_direction = 'no' + '_gray';
          Menu_handlers_on = false;
          If_gray = '_gray';
        }
      }
      SuperTree_Obj = SuperTreeList.GetNext(SuperTree_Obj);
      i++;
    }
    // -----------------------------------------------------------
    var SyncTreeList_length = i;
    if (Missing_active == true) {
      for (i = 0; i < SyncTreeList_length; i++) {
        if (SyncTreeArray[i].arrow_direction == 'in' + If_gray + Progress) {
          SyncTreeArray[i].arrow_direction = 'del' + If_gray + Progress;
        }
      }
    }
    //----------------------------------------------------------
    if (WinningTreeID == CONST_WIN_DEL_SYNC) {
      for (i = 0; i < SyncTreeList_length; i++) {
        if (SyncTreeArray[i].SyncItemCharacteristics.if_available == false) {
          SyncTreeArray[i].arrow_direction = 'no' + '_gray';
        } else {
          SyncTreeArray[i].arrow_direction = 'del' + If_gray + Progress;
        }
      }
    }
    //----------------------------------------------------------
    // New!
    if (WinningTreeID == CONST_WIN_NO_SYNC) {
      for (i = 0; i < SyncTreeList_length; i++) {
        if (SyncTreeArray[i].SyncItemCharacteristics.if_available == false) {
          SyncTreeArray[i].arrow_direction = 'no' + '_gray';
        } else { SyncTreeArray[i].arrow_direction = 'no' + If_gray + Progress; }
      }
    }
    // ----------------------------------------------------------
    if (SyncTreeList_length == 2) {
      message_tbody_element.if_dont_sync = Radio_dont_sync;
      message_tbody_element.if_del_sync = Radio_del_sync;
      message_tbody_element.msg_type = '2';
      message_tbody_element.exist = 'true';
      message_tbody_element.onclick = msg_node_onclick;
      message_tbody_element.onmousedown = msg_node_onmousedown;
      message_tbody_element.onmouseup = msg_node_onmouseup;
      message_tbody_element.onmousemove = msg_node_onmousemove;
      message_tbody_element.onmousewheel = msg_node_onmousewheel;
      message_tbody_element.id = MessageID;
      message_tbody_element.CollectionID = CollectionID;

      var main_line_element = message_tbody_element.insertRow();
      main_line_element.className = 'Single_row';
      //----------------------------------------
      CreateSyncItemCharacteristicsTD(main_line_element, SyncTreeArray[0].SyncItemCharacteristics);
      //----------------------------------------
      Left_radio_element = main_line_element.insertCell();
      Left_radio_element.className = 'Left_cell';
      //----------------------------------------
      Left_arrow_element = main_line_element.insertCell();
      Left_arrow_element.className = 'Middle_cell';
      Left_arrow_element.height = '100%';
      Left_arrow_element.innerHTML = '<div id="Base_' + MsgObj.objID + '" class="Back_plate"><div class="Arrow_left_' + SyncTreeArray[0].arrow_direction + '"></div></div>';
      //----------------------------------------
      Mid_arrow_element = main_line_element.insertCell();
      Mid_arrow_element.className = 'Middle_cell';
      Mid_arrow_element.height = '100%';
      Mid_arrow_element.innerHTML = '<div class="Back_plate"><div class="Arrow_mid_single' + If_gray + '" ></div></div>';
      //----------------------------------------
      Right_arrow_element = main_line_element.insertCell();
      Right_arrow_element.className = 'Middle_cell';
      Right_arrow_element.height = '100%';
      Right_arrow_element.innerHTML = '<div class="Back_plate"><div class="Arrow_right_' + SyncTreeArray[1].arrow_direction + '"></div></div>';
      //----------------------------------------
      Right_radio_element = main_line_element.insertCell();
      Right_radio_element.className = 'Right_cell';
      // ----------------------------------------
      CreateSyncItemCharacteristicsTD(main_line_element, SyncTreeArray[1].SyncItemCharacteristics);
      //----------------------------------------
      if (Menu_handlers_on == true) {
        var Gray0 = '';
        var Gray1 = '';
        if (SyncTreeArray[0].SyncItemCharacteristics.if_available == false) Gray0 = '_gray';
        if (SyncTreeArray[1].SyncItemCharacteristics.if_available == false) Gray1 = '_gray';
        //----------------------------------------
        Left_radio_element.onmouseenter = ShowFM;
        Left_radio_element.onmouseleave = HideFM;
        Left_radio_element.onclick = OnPopupClick;
        Left_radio_element.oncontextmenu = OnPopupContextMenu;
        Left_radio_element.msg_id = MsgObj.objID;
        Left_radio_element.collection_id = CollectionID;
        Left_radio_element.innerHTML = '<img src="Pics/Radio_left_' + SyncTreeArray[0].radio + Gray0 + '.gif" class="Radio_control" ' + SyncTreeArray[0].radio_handler + '>';
        //----------------------------------------
        Left_arrow_element.onmouseenter = ShowFM;
        Left_arrow_element.onmouseleave = HideFM;
        Left_arrow_element.onclick = OnPopupClick;
        Left_arrow_element.oncontextmenu = OnPopupContextMenu;
        Left_arrow_element.msg_id = MsgObj.objID;
        Left_arrow_element.collection_id = CollectionID;
        //----------------------------------------
        Mid_arrow_element.onmouseenter = ShowFM;
        Mid_arrow_element.onmouseleave = HideFM;
        Mid_arrow_element.onclick = OnPopupClick;
        Mid_arrow_element.oncontextmenu = OnPopupContextMenu;
        Mid_arrow_element.msg_id = MsgObj.objID;
        Mid_arrow_element.collection_id = CollectionID;
        // ----------------------------------------
        Right_radio_element.onmouseenter = ShowFM;
        Right_radio_element.onmouseleave = HideFM;
        Right_radio_element.onclick = OnPopupClick;
        Right_radio_element.oncontextmenu = OnPopupContextMenu;
        Right_radio_element.msg_id = MsgObj.objID;
        Right_radio_element.collection_id = CollectionID;
        Right_radio_element.innerHTML = '<img src="Pics/Radio_right_' + SyncTreeArray[1].radio + Gray1 + '.gif" class="Radio_control" ' + SyncTreeArray[1].radio_handler + '>';
        //----------------------------------------
        Right_arrow_element.onmouseenter = ShowFM;
        Right_arrow_element.onmouseleave = HideFM;
        Right_arrow_element.onclick = OnPopupClick;
        Right_arrow_element.oncontextmenu = OnPopupContextMenu;
        Right_arrow_element.msg_id = MsgObj.objID;
        Right_arrow_element.collection_id = CollectionID;
      } else {
        Left_radio_element.innerHTML = '<div class="Without_radio"></div>';
        Right_radio_element.innerHTML = '<div class="Without_radio"></div>';
      }
    }

    if (SyncTreeList_length > 2) {
      message_tbody_element.if_dont_sync = Radio_dont_sync;
      message_tbody_element.if_del_sync = Radio_del_sync;
      message_tbody_element.msg_type = '3';
      message_tbody_element.exist = 'true';
      message_tbody_element.onclick = msg_node_onclick;
      message_tbody_element.onmousedown = msg_node_onmousedown;
      message_tbody_element.onmouseup = msg_node_onmouseup;
      message_tbody_element.onmousemove = msg_node_onmousemove;
      message_tbody_element.onmousewheel = msg_node_onmousewheel;
      message_tbody_element.id = MessageID;
      message_tbody_element.CollectionID = CollectionID;
      // First row
      var first_row_element = message_tbody_element.insertRow();
      first_row_element.className = 'First_row';
      CreateSyncItemCharacteristicsTD(first_row_element, SyncTreeArray[0].SyncItemCharacteristics);

      Left_radio_element = first_row_element.insertCell();
      Left_radio_element.className = 'Left_cell';

      Left_arrow_element = first_row_element.insertCell();
      Left_arrow_element.className = 'Middle_cell';
      Left_arrow_element.height = '100%';
      Left_arrow_element.innerHTML = '<div class="Back_plate"><div class="Arrow_left_' + SyncTreeArray[0].arrow_direction + '"></div></div>';

      Mid_arrow_element = first_row_element.insertCell();
      Mid_arrow_element.className = 'Middle_cell';
      Mid_arrow_element.height = '100%';
      Mid_arrow_element.innerHTML = '<div id="Base_up_' + MsgObj.objID + '" class="Back_plate"><div class="Arrow_mid_top' + If_gray + '" ></div></div>';

      Right_arrow_element = first_row_element.insertCell();
      Right_arrow_element.className = 'Middle_cell';
      Right_arrow_element.height = '100%';
      Right_arrow_element.innerHTML = '<div class="Back_plate"><div class="Arrow_right_' + SyncTreeArray[1].arrow_direction + '"></div></div>';

      Right_radio_element = first_row_element.insertCell();
      Right_radio_element.className = 'Right_cell';

      if (Menu_handlers_on == true) {
        Left_radio_element.onmouseenter = ShowFM;
        Left_radio_element.onmouseleave = HideFM;
        Left_radio_element.onclick = OnPopupClick;
        Left_radio_element.oncontextmenu = OnPopupContextMenu;
        Left_radio_element.msg_id = MsgObj.objID;
        Left_radio_element.collection_id = CollectionID;
        var Gray = '';
        if (SyncTreeArray[0].SyncItemCharacteristics.if_available == false) Gray = '_gray';
        Left_radio_element.innerHTML = '<img src="Pics/Radio_left_' + SyncTreeArray[0].radio + Gray + '.gif" class="Radio_control" ' + SyncTreeArray[0].radio_handler + '>';
        Left_arrow_element.onmouseenter = ShowFM;
        Left_arrow_element.onmouseleave = HideFM;
        Left_arrow_element.onclick = OnPopupClick;
        Left_arrow_element.oncontextmenu = OnPopupContextMenu;
        Left_arrow_element.msg_id = MsgObj.objID;
        Left_arrow_element.collection_id = CollectionID;

        Mid_arrow_element.onmouseenter = ShowFM;
        Mid_arrow_element.onmouseleave = HideFM;
        Mid_arrow_element.onclick = OnPopupClick;
        Mid_arrow_element.oncontextmenu = OnPopupContextMenu;
        Mid_arrow_element.msg_id = MsgObj.objID;
        Mid_arrow_element.collection_id = CollectionID;

        Right_arrow_element.onmouseenter = ShowFM;
        Right_arrow_element.onmouseleave = HideFM;
        Right_arrow_element.onclick = OnPopupClick;
        Right_arrow_element.oncontextmenu = OnPopupContextMenu;
        Right_arrow_element.msg_id = MsgObj.objID;
        Right_arrow_element.collection_id = CollectionID;

        Right_radio_element.onmouseenter = ShowFM;
        Right_radio_element.onmouseleave = HideFM;
        Right_radio_element.onclick = OnPopupClick;
        Right_radio_element.oncontextmenu = OnPopupContextMenu;
        Right_radio_element.msg_id = MsgObj.objID;
        Right_radio_element.collection_id = CollectionID;
        if (SyncTreeArray[1].SyncItemCharacteristics.if_available == false) Gray = '_gray';
        Right_radio_element.innerHTML = '<img src="Pics/Radio_right_' + SyncTreeArray[1].radio + Gray + '.gif" class="Radio_control" ' + SyncTreeArray[1].radio_handler + '>';
      } else {
        Left_radio_element.innerHTML = '<div class="Without_radio"></div>';
        Right_radio_element.innerHTML = '<div class="Without_radio"></div>';
      }

      CreateSyncItemCharacteristicsTD(first_row_element, SyncTreeArray[1].SyncItemCharacteristics);

      for (i = 2; i < SyncTreeList_length - 1; i++)	// Middle rows
      {
        var middle_row_element = message_tbody_element.insertRow();
        middle_row_element.className = 'Mid_row';
        CreateSyncItemCharacteristicsTD(middle_row_element, null);
        Left_radio_element = middle_row_element.insertCell();
        Left_radio_element.className = 'Left_cell';
        Left_radio_element.innerHTML = '';

        Left_arrow_element = middle_row_element.insertCell();
        Left_arrow_element.className = 'Middle_cell';
        Left_arrow_element.height = '100%';
        Left_arrow_element.innerHTML = '<div class="Back_plate"></div>';

        Mid_arrow_element = middle_row_element.insertCell();
        Mid_arrow_element.className = 'Middle_cell';
        Mid_arrow_element.height = '100%';
        Mid_arrow_element.innerHTML = '<div class="Back_plate"><div class="Arrow_mid_mid' + If_gray + '" ></div>';

        Right_arrow_element = middle_row_element.insertCell();
        Right_arrow_element.className = 'Middle_cell';
        Right_arrow_element.height = '100%';
        Right_arrow_element.innerHTML = '<div class="Back_plate"><div class="Arrow_right_' + SyncTreeArray[i].arrow_direction + '"></div></div>';

        Right_radio_element = middle_row_element.insertCell();
        Right_radio_element.className = 'Right_cell';

        if (Menu_handlers_on == true) {
          Left_radio_element.onmouseenter = ShowFM;
          Left_radio_element.onmouseleave = HideFM;
          Left_radio_element.onclick = OnPopupClick;
          Left_radio_element.oncontextmenu = OnPopupContextMenu;
          Left_radio_element.msg_id = MsgObj.objID;
          Left_radio_element.collection_id = CollectionID;

          Left_arrow_element.onmouseenter = ShowFM;
          Left_arrow_element.onmouseleave = HideFM;
          Left_arrow_element.onclick = OnPopupClick;
          Left_arrow_element.oncontextmenu = OnPopupContextMenu;
          Left_arrow_element.msg_id = MsgObj.objID;
          Left_arrow_element.collection_id = CollectionID;

          Mid_arrow_element.onmouseenter = ShowFM;
          Mid_arrow_element.onmouseleave = HideFM;
          Mid_arrow_element.onclick = OnPopupClick;
          Mid_arrow_element.oncontextmenu = OnPopupContextMenu;
          Mid_arrow_element.msg_id = MsgObj.objID;
          Mid_arrow_element.collection_id = CollectionID;

          Right_arrow_element.onmouseenter = ShowFM;
          Right_arrow_element.onmouseleave = HideFM;
          Right_arrow_element.onclick = OnPopupClick;
          Right_arrow_element.oncontextmenu = OnPopupContextMenu;
          Right_arrow_element.msg_id = MsgObj.objID;
          Right_arrow_element.collection_id = CollectionID;

          Right_radio_element.onmouseenter = ShowFM;
          Right_radio_element.onmouseleave = HideFM;
          Right_radio_element.onclick = OnPopupClick;
          Right_radio_element.oncontextmenu = OnPopupContextMenu;
          Right_radio_element.msg_id = MsgObj.objID;
          Right_radio_element.collection_id = CollectionID;
          var Gray = '';
          if (SyncTreeArray[i].SyncItemCharacteristics.if_available == false) Gray = '_gray';
          Right_radio_element.innerHTML = '<img src="Pics/Radio_right_' + SyncTreeArray[i].radio + Gray + '.gif" class="Radio_control" ' + SyncTreeArray[i].radio_handler + '>';
        } else {
          Right_radio_element.innerHTML = '<div class="Without_radio"></div>';
        }

        CreateSyncItemCharacteristicsTD(middle_row_element, SyncTreeArray[i].SyncItemCharacteristics);
      }
      // Last row
      var last_row_element = message_tbody_element.insertRow();
      last_row_element.className = 'Last_row';
      CreateSyncItemCharacteristicsTD(last_row_element, null);
      Left_radio_element = last_row_element.insertCell();
      Left_radio_element.className = 'Left_cell';
      Left_radio_element.innerHTML = '';

      Left_arrow_element = last_row_element.insertCell();
      Left_arrow_element.className = 'Middle_cell';
      Left_arrow_element.height = '100%';
      Left_arrow_element.innerHTML = '<div class="Back_plate"></div>';

      Mid_arrow_element = last_row_element.insertCell();
      Mid_arrow_element.className = 'Middle_cell';
      Mid_arrow_element.height = '100%';
      Mid_arrow_element.innerHTML = '<div id="Base_down_' + MsgObj.objID + '" class="Back_plate"><div class="Arrow_mid_bottom' + If_gray + '" ></div>';

      Right_arrow_element = last_row_element.insertCell();
      Right_arrow_element.className = 'Middle_cell';
      Right_arrow_element.height = '100%';
      Right_arrow_element.innerHTML = '<div class="Back_plate"><div class="Arrow_right_' + SyncTreeArray[SyncTreeList_length - 1].arrow_direction + '"></div></div>';

      Right_radio_element = last_row_element.insertCell();
      Right_radio_element.className = 'Right_cell';

      if (Menu_handlers_on == true) {
        Left_radio_element.onmouseenter = ShowFM;
        Left_radio_element.onmouseleave = HideFM;
        Left_radio_element.onclick = OnPopupClick;
        Left_radio_element.oncontextmenu = OnPopupContextMenu;
        Left_radio_element.msg_id = MsgObj.objID;
        Left_radio_element.collection_id = CollectionID;

        Left_arrow_element.onmouseenter = ShowFM;
        Left_arrow_element.onmouseleave = HideFM;
        Left_arrow_element.onclick = OnPopupClick;
        Left_arrow_element.oncontextmenu = OnPopupContextMenu;
        Left_arrow_element.msg_id = MsgObj.objID;
        Left_arrow_element.collection_id = CollectionID;

        Mid_arrow_element.onmouseenter = ShowFM;
        Mid_arrow_element.onmouseleave = HideFM;
        Mid_arrow_element.onclick = OnPopupClick;
        Mid_arrow_element.oncontextmenu = OnPopupContextMenu;
        Mid_arrow_element.msg_id = MsgObj.objID;
        Mid_arrow_element.collection_id = CollectionID;

        Right_arrow_element.onmouseenter = ShowFM;
        Right_arrow_element.onmouseleave = HideFM;
        Right_arrow_element.onclick = OnPopupClick;
        Right_arrow_element.oncontextmenu = OnPopupContextMenu;
        Right_arrow_element.msg_id = MsgObj.objID;
        Right_arrow_element.collection_id = CollectionID;

        Right_radio_element.onmouseenter = ShowFM;
        Right_radio_element.onmouseleave = HideFM;
        Right_radio_element.onclick = OnPopupClick;
        Right_radio_element.oncontextmenu = OnPopupContextMenu;
        Right_radio_element.msg_id = MsgObj.objID;
        Right_radio_element.collection_id = CollectionID;
        var Gray = '';
        if (SyncTreeArray[SyncTreeList_length - 1].SyncItemCharacteristics.if_available == false) Gray = '_gray';
        Right_radio_element.innerHTML = '<img src="Pics/Radio_right_' + SyncTreeArray[SyncTreeList_length - 1].radio + Gray + '.gif" class="Radio_control" ' + SyncTreeArray[SyncTreeList_length - 1].radio_handler + '>';
      } else {
        Right_radio_element.innerHTML = '<div class="Without_radio"></div>';
      }

      CreateSyncItemCharacteristicsTD(last_row_element, SyncTreeArray[SyncTreeList_length - 1].SyncItemCharacteristics);
    }
  } else	// Message is not sync item
  {
    message_tbody_element.exist = 'true';
    message_tbody_element.oncontextmenu = OnMsgContextMenu;
    var single_row_element = message_tbody_element.insertRow();
    single_row_element.className = 'Single_row';
    mainline_cell_element = single_row_element.insertCell();
    mainline_cell_element.className = 'info_msg';
    mainline_cell_element.colSpan = '11';
    mainline_cell_element.innerHTML = '<span id="Link' + CollectionID + MsgObj.objID + '"></span>' +
			CreateImportantMsgText(MsgObj) +
			CreateMsgButtons(MsgObj);
  }
  return '';
}
// /////////////////////////////////////////////////////////////////////////////////////////////
//	create HTML container for sync item according "SyncItemCharacteristics" variable
function CreateSyncItemCharacteristicsHTML(SyncItemCharacteristics) {
  //
  var name = '';
  var name_title = '';
  var size = '';
  var size_title = '';
  var time = '';
  var time_title = '';
  var state = '';
  var state_title = '';
  var state_style = '';
  var class_name = '';

  var encoded_name = '';
  var encoded_short_name = '';

  if (SyncItemCharacteristics != null) {
    encoded_name = SyncItemCharacteristics.encoded_name;
    encoded_short_name = SyncItemCharacteristics.encoded_short_name;

    if (SyncItemCharacteristics.state == '') {
      name = SyncItemCharacteristics.name;
      if (SyncItemCharacteristics.selected) name_title = external.LS('tooltip_file_name_selected');
      else name_title = external.LS('tooltip_file_name');
      if (G_Selected_lock == true) name_title = '';
      size = SyncItemCharacteristics.size;
      size_title = external.LS('tooltip_file_size');
      time = SyncItemCharacteristics.time;
      time_title = external.LS('tooltip_file_time');
    }

    if (SyncItemCharacteristics.state != '') {
      name = SyncItemCharacteristics.name;
      if (SyncItemCharacteristics.selected) name_title = external.LS('tooltip_file_name_selected');
      else name_title = external.LS('tooltip_file_name');
      if (G_Selected_lock == true) name_title = '';
      state = SyncItemCharacteristics.state;
      state_title = external.LS('tooltip_file_state');
      if (SyncItemCharacteristics.if_missing == true) state_style = ' class="DoesNotExist" '; // 'style="color:#ca0000;"';
      if (SyncItemCharacteristics.if_syncability == false) state_style = ' style="color:gray;" ';
      if (SyncItemCharacteristics.if_available == false) state_style = ' style="color:gray;" ';
    }
  }

  var name_html = '<td class="SyncAttrName"  title="' + name_title + '" width="50%" ' +
		'encoded_name="' + encoded_name + '" ' +
		'encoded_short_name="' + encoded_short_name + '">' + name + '</td>';
  var size_html = '<td class="SyncAttrSize"  title="' + size_title + '" ><span style="width:40px">' + size + '</span></td>';
  //------------------------------------------------------------------------
  if (SyncItemCharacteristics != null) {
    class_name = 'SyncAttrTime2';
    if (SyncItemCharacteristics.device_number == 0) class_name = 'SyncAttrTime';
  } else class_name = 'SyncAttrTime';
  //------------------------------------------------------------------------
  var time_html = '<td class="' + class_name + '" title="' + time_title + '" nowrap><span style="width:90px">' + time + '</span></td>';
  //------------------------------------------------------------------------
  if (SyncItemCharacteristics != null) {
    class_name = 'SyncAttrState2';
    if (SyncItemCharacteristics.device_number == 0) class_name = 'SyncAttrState';
  } else class_name = 'SyncAttrState';
  //------------------------------------------------------------------------
  var state_html = '<td class="' + class_name + '" title="' + state_title + '" colspan="2" valign="middle" align="center" nowrap ' + ' >' +
		'<span style="width:137px" ' + state_style + '>' + state + '</span></td>';
  //------------------------------------------------------------------------
  if (state != '') Item_html = name_html + state_html;
  else Item_html = name_html + size_html + time_html;

  return Item_html;
}

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

function CreateSyncItemCharacteristicsTD(Row_element, SyncItemCharacteristics) {
  var class_name = '';

  if (SyncItemCharacteristics == null) {
    class_name = 'SyncAttrTime';

    name_element = Row_element.insertCell();
    name_element.width = ' 50%';
    name_element.className = 'SyncAttrName';
    name_element.innerHTML = '';
    name_element.encoded_name = '';
    name_element.encoded_short_name = '';
    size_element = Row_element.insertCell();
    size_element.className = 'SyncAttrSize';
    size_element.innerHTML = '<span style="width:40px"></span>';
    time_element = Row_element.insertCell();
    time_element.className = class_name;
    time_element.noWrap = true;
    time_element.innerHTML = '<span style="width:90px"></span>';
    return;
  }
  if (SyncItemCharacteristics.state == '') {
    class_name = 'SyncAttrTime2';
    if (SyncItemCharacteristics.device_number == 0) class_name = 'SyncAttrTime';

    name_element = Row_element.insertCell();
    name_element.width = '50%';
    name_element.className = 'SyncAttrName';
    if (SyncItemCharacteristics.selected) name_element.title = external.LS('tooltip_file_name_selected');
    else name_element.title = external.LS('tooltip_file_name');
    if (G_Selected_lock == true) name_element.title = '';
    name_element.innerHTML = SyncItemCharacteristics.name;
    name_element.encoded_name = SyncItemCharacteristics.encoded_name;
    name_element.encoded_short_name = SyncItemCharacteristics.encoded_short_name;
    size_element = Row_element.insertCell();
    size_element.className = 'SyncAttrSize';
    size_element.title = external.LS('tooltip_file_size');
    size_element.innerHTML = '<span style="width:40px">' + SyncItemCharacteristics.size + '</span>';
    time_element = Row_element.insertCell();
    time_element.className = class_name;
    time_element.noWrap = true;
    time_element.title = external.LS('tooltip_file_time');
    time_element.innerHTML = '<span style="width:90px">' + SyncItemCharacteristics.time + '</span>';
  } else {
    class_name = 'SyncAttrState2';
    if (SyncItemCharacteristics.device_number == 0) class_name = 'SyncAttrState';

    var stateClass = '';

    name_element = Row_element.insertCell();
    name_element.className = 'SyncAttrName';
    if (SyncItemCharacteristics.selected) name_element.title = external.LS('tooltip_file_name_selected');
    else name_element.title = external.LS('tooltip_file_name');
    if (G_Selected_lock == true) name_element.title = '';
    name_element.width = '50%';
    name_element.innerHTML = SyncItemCharacteristics.name;
    name_element.encoded_name = SyncItemCharacteristics.encoded_name;
    name_element.encoded_short_name = SyncItemCharacteristics.encoded_short_name;
    state_element = Row_element.insertCell();
    state_element.className = class_name;
    state_element.title = external.LS('tooltip_file_state');
    state_element.colSpan = '2';
    state_element.align = 'center';
    state_element.noWrap = true;
    if (SyncItemCharacteristics.if_missing == true) {
      // state_element.style.color="red";
      stateClass = ' class="DoesNotExist" ';
      if (SyncItemCharacteristics.if_syncability == false) state_element.style.color = 'gray';
    } else if (SyncItemCharacteristics.if_available == false) {
      state_element.style.color = 'gray';
      // if (SyncItemCharacteristics.if_syncability == true) state_element.style.color="red";
    }
    state_element.innerHTML = '<span style="width:137px" ' + stateClass + '>' + SyncItemCharacteristics.state + '</span>';
  }
  return;
}
// /////////////////////////////////////////////////////////////////////////////////////////////
function OpenSyncRoot(SyncTreeID) {
  var e = window.event;
  if (!e.ctrlKey) external.Method1ID('M_OpenButtonPressedForTree', SyncTreeID);
}
// /////////////////////////////////////////////////////////////////////////////////////////////
//	create an object
// /////////////////////////////////////////////////////////////////////////////////////////////
function CreateSyncItemCharacteristics(solution, SuperTree_Obj, CollectionID, ItemSelection, NameMode) {
  //	--------------------------------------------------------------------------------------------
  //	picture for item (syncitem (by default), file, folder, link to important message)
  this.picture = '<img src="Pics/SyncItem.gif" style="margin-right:5px;">';
  this.root_name = '';
  this.sync_type_name = '';			//  root sync folder name
  this.sync_type_picture = '';		//  picture corresponding to interaction protocol for root folder
  this.name = '';				//	path to Sync Item
  this.encoded_name = '';
  this.short_name = '';				//	path to Sync Item
  this.encoded_short_name = '';
  this.size = '';				//	size of Sync Item (file)
  this.time = '';				//	time of Sync Item (file)
  this.state = '';				//	AfterSyncState is one of three - created, deleted, modified
  this.if_missing = false;		//	if the file does not exist in
  this.if_available = true;		//	if the file is available for processing
  this.if_syncability = solution.Method0('M_GetAvailableItemForSynchronization'); // item will be synced or not
  this.selected = false;
  this.device_number = null;
  //	--------------------------------------------------------------------------------------------
  var str_not_available = false;
  var file_SIC = solution.Method1Own('M_GetSyncItemCharacteristicsBySuperTree', SuperTree_Obj);
  var Tree_Is_Ready = SuperTree_Obj.Method0('M_IsTreeReady');
  // --------------------------------------------------------------------------------------------------
  var separator = '?';
  var levels_of_item_path_collection = solution.Method1Own('M_GetItemCollection', SuperTree_Obj);
  var separator = levels_of_item_path_collection.Method0('M_GetDelimiter');
  //--------------------------------------------------------------------------------------------------
  var SyncTreeObject = SuperTree_Obj.GetFirst();
  var SyncRootPath = '';
  this.root_name = SyncTreeObject.Method0Own('M_ToFilename');
  if (CONST_ShowFullFileName == true) SyncRootPath = this.root_name;
  //----------------------------------------------------------------
  var WizardType = SyncTreeObject.Method0('M_GetDeviceType');
  var Image_SRC = 0;
  this.sync_type_picture = G_WizardTypeInfoList[WizardType][Image_SRC];
  var Folder_Type_Name = 2;
  this.sync_type_name = G_WizardTypeInfoList[WizardType][Folder_Type_Name];
  // ----------------------------------------------------------------
  var path_levels = [];
  var path_level_html = null;
  // -------------------------------------------------------------------------------------------------
  // if item is not available
  // -------------------------------------------------------------------------------------------------
  if (Tree_Is_Ready == false) str_not_available = true;
  if (file_SIC == null) str_not_available = true;

  if (str_not_available == true) {
    this.if_available = false;
    this.state = external.LS('str_not_available');

    var is_dir1 = solution.Method0('M_IsCanHaveChildren');
    if (is_dir1) this.picture = '<img src="Pics/FolderGray.gif" style="margin-right:5px;">';
    else this.picture = '<img src="Pics/FileGray.gif" style="margin-right:5px;">';

    var path = '<span style="color:gray;" >' + SyncRootPath + '</span>';
    var root_path = '<span style="gray;" >' + this.root_name + '</span>';

    var level_of_item_path = levels_of_item_path_collection.GetFirst();

    path_levels.push(root_path);

    while (level_of_item_path != null) {
      var part_of_item_path = level_of_item_path.Method1('M_ToFilename', SuperTree_Obj);
      part_of_item_path = ModifyFileNameWithWrap(part_of_item_path);
      path_level_html = separator + '<wbr><span style="color:gray;" >' + part_of_item_path + '</span>';

      path += path_level_html;
      path_levels.push(path_level_html);

      level_of_item_path = levels_of_item_path_collection.GetNext(level_of_item_path);
    }
    this.name = path;

    this.name = this.name.replace(/\\/g, separator + '<wbr>');

    var missed_path = '<span class="' + MsgPathLevelClass + '" >' + separator + '</span>' +
			'<wbr><span onclick="onMissedPathClick();" ' +
			'onmouseover="OnMouseOverPath()" onmouseout="OnMouseOutPath()" class="' + MsgPathLevelClass + '" ' +
			'title="' + external.LS('tooltip_open_the_item') + '" >' + '...' + '</span>';

    if (path_levels.length == 1) {
      this.short_name = path_levels[0];
    }
    if (path_levels.length == 2) {
      this.short_name = missed_path + path_levels[1];
      if (path_levels[1].indexOf('></span>') >= 0) this.short_name = path_levels[1];
    }
    if (path_levels.length >= 3) {
      this.short_name = missed_path + path_levels[path_levels.length - 2] + path_levels[path_levels.length - 1];
    }
    //		this.short_name = path_levels[path_levels.length - 2] + path_levels[path_levels.length - 1];
    this.short_name = this.short_name.replace(/\\/g, separator + '<wbr>');

    this.name = this.picture + this.name;
    //		this.short_name = this.picture + this.short_name;
    this.short_name = '<div style="height: 16px; width: 100%; white-space: normal; word-wrap: normal; text-overflow:clip; overflow: hidden;">' +
			this.picture +
			this.short_name +
			'</div>';

    this.encoded_name = encodeURIComponent(this.name);
    this.encoded_short_name = encodeURIComponent(this.short_name);

    if (NameMode == 'Short name') this.name = this.short_name;

    return this;
  }
  //= ===================================================================================================
  // 			Item is available - Creating clickable parts of path
  //= ===================================================================================================
  var MsgPathLevelClass = 'MsgPathLevel';
  var ClassTail = '';
  if (ItemSelection == true) { MsgPathLevelClass = 'MsgPathLevel_selected'; this.selected = true; }

  var path = '<span onclick="OpenSyncRoot(\'' + SyncTreeObject.objID +
		'\')"  onmouseover="OnMouseOverPath()" onmouseout="OnMouseOutPath()" class="' + MsgPathLevelClass + '" ' +
		'title="' + external.LS('tooltip_open_the_rootfolder') + '">' +
		SyncRootPath + '</span>';

  var root_path = '<span onclick="OpenSyncRoot(\'' + SyncTreeObject.objID +
		'\')"  onmouseover="OnMouseOverPath()" onmouseout="OnMouseOutPath()" class="' + MsgPathLevelClass + '" ' +
		'title="' + external.LS('tooltip_open_the_rootfolder') + '">' +
		this.root_name + '</span>';

  path_levels.push(root_path);

  var level_of_item_path = levels_of_item_path_collection.GetFirst();
  while (level_of_item_path != null) {
    var part_of_item_path = level_of_item_path.Method1('M_ToFilename', SuperTree_Obj);
    part_of_item_path = ModifyFileNameWithWrap(part_of_item_path);
    if (level_of_item_path.Method1('M_GetItemExistenceBySuperTree', SuperTree_Obj) == false) {
      ClassTail = '_DoesNotExist';
      path_level_html = '<span class="' + MsgPathLevelClass + ClassTail + '" >' + separator + '</span>' +
				'<wbr><span class="' + MsgPathLevelClass + ClassTail + '" >' + part_of_item_path + '</span>';

      path += path_level_html;
      path_levels.push(path_level_html);
    } else {
      ClassTail = '';
      path_level_html = '<span class="' + MsgPathLevelClass + ClassTail + '" >' + separator + '</span>' +
				'<wbr><span onclick="ShowItem(\'' + level_of_item_path.objID + '\', \'' + SuperTree_Obj.objID + '\')" ';
      path_level_html += 'onmouseover="OnMouseOverPath()" onmouseout="OnMouseOutPath()" class="' + MsgPathLevelClass + ClassTail + '" ' +
				'title="' + external.LS('tooltip_open_the_item') + '" >' + part_of_item_path + '</span>';

      path += path_level_html;
      path_levels.push(path_level_html);
    }
    level_of_item_path = levels_of_item_path_collection.GetNext(level_of_item_path);
  }
  this.name = path;
  //= ===================================================================================================
  var missed_path = '<span class="' + MsgPathLevelClass + '" >' + separator + '</span>' +
		'<wbr><span onclick="onMissedPathClick();" ' +
		'onmouseover="OnMouseOverPath()" onmouseout="OnMouseOutPath()" class="' + MsgPathLevelClass + '" ' +
		'title="' + external.LS('tooltip_open_the_item') + '" >' + '...' + '</span>';

  if (path_levels.length == 1) {
    this.short_name = path_levels[0];
  }
  if (path_levels.length == 2) {
    this.short_name = missed_path + path_levels[1];
    if (path_levels[1].indexOf('></span>') >= 0) this.short_name = path_levels[1];
  }
  if (path_levels.length >= 3) {
    this.short_name = missed_path + path_levels[path_levels.length - 2] + path_levels[path_levels.length - 1];
  }
  if (CONST_ShowFullFileName == true) this.short_name = path_levels[0] + this.short_name;
  //= ===================================================================================================
  // End of Creating clickable parts of path
  //= ===================================================================================================
  // var is_not_exist = file_SIC.GetM('m_bMissing');
  var is_not_exist = file_SIC.Method0('M_IsMissing'); // New!!!
  var SolutionActionState = solution.Method0('M_GetActionState');// DU solution.GetM('MM_ActionState');
  if (SolutionActionState == CONST_ACTION_STATE_DONE) {
    var AfterActionState = solution.Method1Own('M_GetActionDoneUserStrBySuperTree', SuperTree_Obj);
    if (AfterActionState != null) this.state = AfterActionState;
  }
  //----------------------------------------------------
  var itemPicture = '';
  var itemTooltip = '';
  var is_dir = solution.Method0('M_IsCanHaveChildren');
  var itemId_in_important_collection = solution.Method0('M_GetLinkID');
  //----------------------------------------------------
  if (is_dir) {
    this.size = '<span class="' + MsgPathLevelClass + '" >' + external.LS('str_folder') + '</span>';
    itemTooltip = external.LS('tooltip_open_the_folder');
    if (is_not_exist) itemPicture = 'Pics/FolderGray.gif';
    else itemPicture = 'Pics/Folder.gif';
  } else {	// if item is file
    var file_size = file_SIC.Method0('M_GetFileSizeStr');
    if (file_size != null) this.size = '<span class="' + MsgPathLevelClass + '" >' + file_size + '</span>';
    itemTooltip = external.LS('tooltip_open_the_file');
    if (is_not_exist) itemPicture = 'Pics/FileGray.gif';
    else {
      // if the item has link to "important message"
      if (CONST_CID != itemId_in_important_collection) {
        itemPicture = 'Pics/Warning_small.gif';
        itemTooltip = external.LS('tooltip_goto_important_message');
      } else {
        itemPicture = external.Method2('M_GetAssociationFileImage', solution, SuperTree_Obj);
        if (itemPicture == null) itemPicture = 'Pics/File.gif';
      }
    }
  }

  if (is_not_exist) {
    // alert(this.state + '-');
    if (this.state != external.LS('str_deleted')) // made by Core
    { this.state = external.LS('str_not_exist'); }
    this.if_missing = true;
    this.picture = '<img src="' + itemPicture + '" style="margin-right:5px; margin-bottom:-4px;">';

    this.name = this.picture + this.name;
    //		this.short_name = this.picture + this.short_name;
    this.short_name = '<div style="height: 16px; width: 100%; white-space: normal; word-wrap: normal; text-overflow:clip; overflow: hidden;">' +
			this.picture +
			this.short_name +
			'</div>';
    this.encoded_name = encodeURIComponent(this.name);
    this.encoded_short_name = encodeURIComponent(this.short_name);

    if (NameMode == 'Short name') this.name = this.short_name;

    return this;
  }

  var file_time = file_SIC.Method0('M_GetFiletimeStr');
  if (file_time != null) this.time = '<span class="' + MsgPathLevelClass + '" >' + file_time + '</span>';
  level_of_item_path = levels_of_item_path_collection.GetLast();
  // if the item has link to "important message"
  if (CONST_CID != itemId_in_important_collection) {
    this.picture = '<img src="' + itemPicture + '" ' +
			'id="Link' + CollectionID + solution.ObjID + '"' +
			'title="' + itemTooltip + '" ' +
			'style="cursor:hand; margin-right:5px; margin-bottom:-4px;" ' +
			'onclick=LinkToCollectionMsg("Important","' + itemId_in_important_collection + '")>';
  } else {
    this.picture = '<img src="' + itemPicture + '" style="cursor:hand; margin-right:5px; margin-bottom:-4px;"' +
			'title="' + itemTooltip + '" ' +
			'onclick="ShowItem(\'' + level_of_item_path.objID + '\', \'' + SuperTree_Obj.objID + '\')">';
  }

  this.name = this.picture + this.name;
  //	this.short_name = this.picture + this.short_name;
  this.short_name = '<div style="height: 16px; width: 100%; white-space: normal; word-wrap: normal; text-overflow:clip; overflow: hidden;">' +
		this.picture +
		this.short_name +
		'</div>';

  this.encoded_name = encodeURIComponent(this.name);
  this.encoded_short_name = encodeURIComponent(this.short_name);

  if (NameMode == 'Short name') this.name = this.short_name;

  return this;
}
// (R)
function ModifyFileNameWithWrap(FileName) {
  var length = FileName.length;
  var NewFileName = '';
  for (var i = 0; i < length; i++) {
    // Checking if the char is an emoji: surrogate pair of the lead and the trail code units
    var lead = FileName.charCodeAt(i);
    if ((lead >= 0xd800) && (lead <= 0xdbff) && (length >= i + 1)) {
      var trail = FileName.charCodeAt(i + 1);
      if ((trail >= 0xdc00) && (trail <= 0xdfff)) {
        NewFileName += String.fromCharCode(lead, trail);
        i++;
        continue;
      }
    }
    // Checking if the char is an emoji modifier and adding the word break if not
    var chCode = FileName.charCodeAt(i);
    if ((i > 0) &&
        (chCode < 0x203C || chCode > 0x3299) &&
        (chCode !== 0x200D) &&
        (chCode !== 0xfe0f)) { NewFileName += '<wbr>'; }
    NewFileName += String.fromCharCode(chCode);
  }
  return NewFileName;
}
// (R)
function onMissedPathClick(e) {
  var e = window.event;
  var parentElement = e.srcElement.parentNode;
  while (parentElement.tagName.toLowerCase() != 'tbody') { parentElement = parentElement.parentNode; }

  if (parentElement.tagName.toLowerCase() == 'tbody') {
    var tbodyClass = parentElement.className;
    var MsgEvenness = 1;
    if (tbodyClass == 'Msg_Even') MsgEvenness = 0;

    var CollectionID = parentElement.CollectionID;
    var MessageID = parentElement.id;
    var message_tbody_element = parentElement;
    var NameMode = 'Full name';

    BuildMessageAsObject(message_tbody_element, CollectionID, MessageID, MsgEvenness, NameMode);
  }
}

function ShowItem(SolutionID, SuperTreeID) {
  var e = window.event;
  if (!e.ctrlKey) external.ShowItem(SuperTreeID, SolutionID);
}

function CreateWarningMessage(pMsg) {
	var sDesc = pMsg.Method0('M_GetMessageDesc');
	var sRes = pMsg.Method0('M_GetTimeStamp');
	sRes += ' <span class="msg_icon" style="background-image:url(Pics/Warning_msg.png)"></span>';
	if (sDesc)
		sRes += external.LS1('warning_in', sDesc);
	else
		sRes += external.LS('warning');
	sRes += ': <span style="color:#8a6100">' + pMsg.Method0('M_GetWarningDesc') + '</span> ';
	return sRes;
}

function CreateErrorMessage(pMsg) {
	var sRes = pMsg.Method0('M_GetTimeStamp');
	sRes += ' <span class="msg_icon" style="background-image: url(Pics/Error_msg.png)"></span>';
	sRes += pMsg.Method0('M_GetMessageDesc');
	sRes += ': <span style="color:#db0f0f">' + pMsg.Method0('M_GetGroupDesc') + '</span> ';
	return sRes;
}

function CreateAutoRetryErrorMessage(pMsg) {
	var sRes = pMsg.Method0('M_GetTimeStamp');
	sRes += ' <span class="msg_icon" style="background-image: url(Pics/Auto_retry_msg.png)"></span>';
	sRes += external.LS1('auto_retry_msg_item', pMsg.Method0('M_GetAutoRetryPeriod'));
	sRes += ': ' + pMsg.Method0('M_GetMessageDesc');
	sRes += ': <span style="color:#db0f0f">' + pMsg.Method0('M_GetGroupDesc') + '</span> ';
	return sRes;
}

function CreateImportantMsgText(pMsg) {
	switch (pMsg.Method0('M_GetMessageType')) {
		case 1:
			return CreateWarningMessage(pMsg);
		case 2:
			return CreateErrorMessage(pMsg);
		case 3:
			return CreateAutoRetryErrorMessage(pMsg);
		default:
			return pMsg.ToString();
	}
}

function OnlineHelpForError(msgID) {
	var pMsg = external.ObjByID(msgID);
	if (pMsg)
		pMsg.Method0('M_OpenOnlineHelp');
}

function OnErrorDetailsFunc(msgID) {
	var errors_info = [
		{ m: 'M_GetSystemErrorCode', lid: 'system_error_details' },
		{ m: 'M_GetSystemErrorDesc', lid: 'system_desc_details' },
		{ m: 'M_GetErrorDesc', lid: 'engine_desc_details' },
		{ m: 'M_GetSrcItemDesc', lid: 'src_item_details' },
		{ m: 'M_GetDstItemDesc', lid: 'dst_item_details' },
		{ m: 'M_GetCtxDesc', lid: 'ctx_error_details' }
	];

	var sRes, sMsg, sLoc;
	var error = document.getElementById('error_' + msgID);
	if (!error)
		return;

	if (error.style.display == 'none') {
		var pMsg = external.ObjByID(msgID);
		if (!pMsg)
			return;

		sRes = '<span onmouseover=OnMouseOverPath() onmouseout=OnMouseOutPath() onclick=OnlineHelpForError("' + msgID + '") ' +
			'style="cursor:hand; color:blue; display:inline-block; margin-bottom:5px; padding:0; text-decoration:underline; font-weight:bold;">' +
			external.LS('error_online_help') + '</span>';

		for (var i=0; i<errors_info.length; i++) {
			var pErr = errors_info[i];
			sMsg = pMsg.Method0(pErr.m);
			if (sMsg)
				sRes += '<br/> ' + external.LS(pErr.lid) + ': ' + sMsg;
		}

		error.style.display = 'block';
	}
	else
		error.style.display = 'none';

	error.innerHTML = sRes;
}

function CreateMsgButtons(MsgObj) {
	var extended_info = false;
	var buttons_html = '';
	var msg_buttons = MsgObj.Method0('M_GetButtons');
	if (!msg_buttons)
		return buttons_html;

	buttons_html = '<br/><div style="white-space:nowrap; margin-left:-4px;">';
	var button = msg_buttons.GetFirst();
	while (button) {
		switch(button.Method0('M_GetType')) {
			case 0:
				buttons_html += '<button onclick=OnMsgButton("' + button.objID + '") class="msg_button">' +
					button.ToString() + '</button>';
				break;
			case 1:
				buttons_html += '<span ' +
					'onmouseover=OnMouseOverPath() onmouseout=OnMouseOutPath() ' +
					'onclick=OnMsgButton("' + button.objID + '") ' +
					'style="cursor:hand; color:blue; margin-left:15px; text-decoration:underline; vertical-align:middle;">' +
					'' + button.ToString() + '' + '</span>';
				break;
			case 3:
				buttons_html += '<span ' +
					'onmouseover=OnMouseOverPath() onmouseout=OnMouseOutPath() ' +
					'onclick=' + button.Method0('M_GetInternalMethod') + '("' + MsgObj.objID + '") ' +
					'style="cursor:hand; color:blue; margin-left:15px; text-decoration:underline; vertical-align:middle;">' +
					'' + button.ToString() + '' + '</span>';
				extended_info = true;
				break;
		}
		button = msg_buttons.GetNext(button);
	}

	if (extended_info)
		buttons_html += '<div id="error_' + MsgObj.objID + '" style="display:none; padding: 5px 0 5px 5px;"/>';

	return buttons_html + '</div>';
}

function OnArrowClick(SolutionID, TreeID) {// alert("SolutionID= " + SolutionID);
  var solution = external.ObjByID(SolutionID); // alert("TreeID= " + TreeID);
  solution.Method1ID('M_AlternativeSelected', TreeID);
}

function OnMsgButton(button_objID) {
  external.Method1('M_ButtonPressed', button_objID);
}

function Ok_Activate(num) {
  Form_elem = document.getElementById('Assoc_' + G_ActiveAssocID).all['TreeForm' + num];
  SyncTreeID = Form_elem.parentElement.synctree_id;
  new_path = Form_elem.all[SyncTreeID + '_path'].value;
  if (Form_elem.is_empty == 'false') {
    old_path = external.ObjByID(SyncTreeID).Method0Own('M_ToViewFilename');
  } else {
    old_path = '';
  }
  if (new_path != old_path)  // Wizard
  {
    //	Form_elem.all["TreeOk"+num].disabled = false;
    //	Form_elem.all["TreeCancel"+num].disabled = false;
    //	Form_elem.all["TreeOk"+num].style.backgroundImage = "url(Pics/Folder_button.gif)";
    //	Form_elem.all["TreeCancel"+num].style.backgroundImage = "url(Pics/Folder_button.gif)";
    //	Form_elem.all["TreeOk"+num].style.cursor = "hand";
    //	Form_elem.all["TreeCancel"+num].style.cursor = "hand";
    Form_elem.is_changed = 'true';
  } else {
    //	Form_elem.all["TreeOk"+num].disabled = true;
    //	Form_elem.all["TreeCancel"+num].disabled = true;
    //	Form_elem.all["TreeOk"+num].style.backgroundImage = "url(Pics/Folder_button_off.gif)";
    //	Form_elem.all["TreeCancel"+num].style.backgroundImage = "url(Pics/Folder_button_off.gif)";
    //	Form_elem.all["TreeOk"+num].style.cursor = "none";
    //	Form_elem.all["TreeCancel"+num].style.cursor = "none";
    Form_elem.is_changed = 'false';
  }
}
//	------------------------------------------------------------------------------
//	get SyncTree condition from profile
//	------------------------------------------------------------------------------
function GetBackSyncBoard(num) {
  SyncTree_elem = document.getElementById('Assoc_' + G_ActiveAssocID).all['SyncTree' + num];
  SyncTreeID = SyncTree_elem.synctree_id;
  SyncTreeObj = external.ObjByID(SyncTreeID);
  //----------------------------------------------------------------
  var WizardURL = SyncTreeObj.Method0Own('M_ToFilename');
  if (WizardURL == null) WizardURL = '';
  SyncTree_elem.all[SyncTreeID + '_path'].value = WizardURL;
  SyncTree_elem.all['TreeForm' + num].is_changed = 'false';
  // ----------------------------------------------------------------
  if (SyncTreeObj.Method0('M_IsTreeReady') == 1) if_empty = 'false';
  else if_empty = 'true';
  SyncTree_elem.all['TreeForm' + num].is_empty = if_empty;
  // ----------------------------------------------------------------
  ResizeWindow();
}

function GetBackAllSyncBoards(AssocID) {
  //----------------------------------------------------------------
  if (AssocID != G_ActiveAssocID) { alert('Request to refresh sync boards for unactive association is declined.'); return false; }
  for (var num = 0; num < G_Assocs[AssocID].FoldersQuantity; num++) {
    var Assoc_elem = document.getElementById('Assoc_' + AssocID);
    if (Assoc_elem) {
      //----------------------------------------------------------------
      //   actions for sync panel
      //----------------------------------------------------------------
      var SyncTree_elem = Assoc_elem.all['SyncTree' + num];
      SyncTreeID = SyncTree_elem.synctree_id;
      SyncTreeObj = external.ObjByID(SyncTreeID);
      // ----------------------------------------------------------------
      var WizardURL = SyncTreeObj.Method0Own('M_ToFilename');
      // var WizardObj  = SyncTreeObject.Method0Own('M_GetWizard');
      // WizardURL = WizardObj.Method0('M_GetURL');
      SyncTree_elem.all[SyncTreeID + '_path'].value = WizardURL;
      SyncTree_elem.all['TreeForm' + num].is_changed = 'false';
      // ----------------------------------------------------------------
      if (SyncTreeObj.Method0('M_IsTreeReady') == 1) if_empty = 'false';
      else if_empty = 'true';
      SyncTree_elem.all['TreeForm' + num].is_empty = if_empty;
      //----------------------------------------------------------------
      //   actions for wizard panel
      //----------------------------------------------------------------
      //----------------------------------------------------------------
    }
  }
  ResizeWindow();
  return true;
}

function Activate_form(num) {
  SyncTree_obj = document.getElementById('Assoc_' + G_ActiveAssocID).all['SyncTree' + num];
  {
    SyncTree_obj.className = 'Active_panel';
  }
}

function CancelSyncTree(num) {
  var SyncTree_elem = document.getElementById('Assoc_' + G_ActiveAssocID).all['SyncTree' + num];
  SyncTree_elem.className = 'Unactive_panel';
  GetBackSyncBoard(num);
}

function BrowseSyncTree(num) {
  var SyncTree_elem = document.getElementById('Assoc_' + G_ActiveAssocID).all['SyncTree' + num];
  var SyncTreeID = SyncTree_elem.synctree_id;
  SyncTree_elem.className = 'Unactive_panel';
  G_OnProfileChanged_called = false;
  external.Method1ID('M_BrowseButtonPressedForTree', SyncTreeID);
  if (G_OnProfileChanged_called == false) {
    GetBackSyncBoard(num);
  }
}

function OpenSyncTree(num) {
  SyncTree_elem = document.getElementById('Assoc_' + G_ActiveAssocID).all['SyncTree' + num];
  SyncTreeID = SyncTree_elem.synctree_id;
  ChangeSyncTree(num);
  external.Method1ID('M_OpenButtonPressedForTree', SyncTreeID);
}

function FolderButtonSelect(button) {
  document.all[button.id + 'left'].src = 'Pics/Folder_button_selected_left.gif';
  button.style.backgroundImage = 'url(Pics/Folder_button_selected_center.gif)';
  document.all[button.id + 'right'].src = 'Pics/Folder_button_selected_right.gif';
}

function FolderButtonUnselect(button) {
  document.all[button.id + 'left'].src = 'Pics/Folder_button_left.gif';
  button.style.backgroundImage = 'url(Pics/Folder_button_center.gif)';
  document.all[button.id + 'right'].src = 'Pics/Folder_button_right.gif';
}

function WizardButtonSelect(button) {
  button.style.backgroundImage = 'url(Pics/Folder_button_selected.gif)';
}

function WizardButtonUnselect(button) {
  button.style.backgroundImage = 'url(Pics/Folder_button.gif)';
}

function MainButtonSelect(button) {
  button.style.backgroundImage = 'url(Pics/Main_button_selected.gif)';
}

function MainButtonUnselect(button) {
  button.style.backgroundImage = 'url(Pics/Main_button.gif)';
}
function ConfigButtonSelect(button) {
  button.style.backgroundImage = 'url(Pics/Config_button_selected.gif)';
}

function ConfigButtonUnselect(button) {
  button.style.backgroundImage = 'url(Pics/Config_button.gif)';
}

function ConfigButtonOnClick(button) {
  external.Method0('M_OpenJobProperties');
}
//	called after changing one of rootfolder names
//	-------------------------------------------------------------------------
function ChangeSyncTree(num) {
  ExtCloseHint(G_ActiveAssocID, 'Syncpath_hint_' + num);
  AssocElement = document.getElementById('Assoc_' + G_ActiveAssocID);
  SyncTree_elem = AssocElement.all['SyncTree' + num];
  SyncTreeID = SyncTree_elem.synctree_id;
  SyncTree_elem.className = 'Unactive_panel';
  Form_elem = AssocElement.all['TreeForm' + num];
  // ---------------------------------------------------------------------
  Form_elem.is_changed = 'false';
  if (AssocElement.all[SyncTreeID + '_w_path']) { new_path = AssocElement.all[SyncTreeID + '_w_path'].value; } else { new_path = AssocElement.all[SyncTreeID + '_path'].value; }
  // ---------------------------------------------------------------------
  G_Assocs[G_ActiveAssocID].OnAssocChangedCalled = false;
  if (new_path != '') {
    var solution = external.method0Own('M_GetDoProfileSyncSolution');
    solution.SafeChangeTreePathAndUpdateProfile(SyncTreeID, new_path);
  }
  GetBackSyncBoard(num);

  return false;
}

function Analyze_onclick() {
  AnalyzeButtonElement = window.event.srcElement;
  // AnalyzeButtonElement.style.backgroungImage='url(Pics/Main_button.gif)';
  // AnalyzeButtonElement.style.backgroungImage='url(Pics/Main_button_off.gif)';
  AssocID = AnalyzeButtonElement.association_id;
  ExtCloseHint(AssocID, 'Analyze_hint');
  AssocObj = external.ObjByID(AssocID);
  AssocObj.CommandAnalyze();
  G_Selected_lock = false;
}

function Synchronize_onclick() {
  SynchronizeButtonElement = window.event.srcElement;
  AssocID = SynchronizeButtonElement.association_id;
  ExtCloseHint(AssocID, 'Analyze_hint');
  //	ExtCloseHint(AssocID, 'Synchronize_hint');
  AssocObj = external.ObjByID(AssocID);
  AssocObj.CommandSynchronize();
}

function Stop_onclick() {
  StopButtonElement = window.event.srcElement;
  AssocID = StopButtonElement.association_id;
  AssocObj = external.ObjByID(AssocID);
  AssocObj.CommandStop();
}

function CloseAnalyzeHint() {
  AnalyzeButtonElement = window.event.srcElement;
  ExtCloseHint(AnalyzeButtonElement.association_id, 'Analyze_hint');
}

function UpdateButtons(AssocID) {
  var AssocElement = document.getElementById('Assoc_' + AssocID);
  if (AssocElement == null) return;
  //----------------------------------------------------------------------------------
  var AssocObj = external.ObjByID(AssocID);
  if (G_Assocs[AssocID].Folders_is_ready == true) {
    var FolderArray_length = G_Assocs[AssocID].Folder_is_ready_array.length;
    for (var i = 0; i < FolderArray_length; i++) {
      DisableFSP(AssocID, i, !AssocObj.StatusAnalyze, true);
    }
  } else {
    var FolderArray_length = G_Assocs[AssocID].Folder_is_ready_array.length;
    for (var i = 0; i < FolderArray_length; i++) {
      DisableFSP(AssocID, i, false, G_Assocs[AssocID].Folder_is_ready_array[i]);
    }
  }
  // ------------------------------------------------------------------------------------ Wizard
  var MainButtonDisabled = [!AssocObj.StatusAnalyze, !AssocObj.StatusSynchronize, !AssocObj.StatusStop];
  var MainButtonType = ['B_ANALYZE', 'B_SYNC', 'B_STOP'];
  var _Cursor = '';
  var _Image = '';
  for (var i = 0; i < MainButtonType.length; i++) {
    AssocElement.all[MainButtonType[i]].disabled = MainButtonDisabled[i];
    _Disabled = AssocElement.all[MainButtonType[i]].disabled;
    if (_Disabled) { _Cursor = 'none'; } else { _Cursor = 'hand'; }
    if (_Disabled) { _Image = 'url(Pics/Main_button_off.gif)'; } else { _Image = 'url(Pics/Main_button.gif)'; }
    if (AssocElement.all[MainButtonType[i]].style.backgroundImage) AssocElement.all[MainButtonType[i]].style.backgroundImage = _Image;
    if (AssocElement.all[MainButtonType[i]].style.cursor) AssocElement.all[MainButtonType[i]].style.cursor = _Cursor;
  }
  //------------------------------------------------------------------------------------
}

function UpdateButtonsTitle(AssocID, Status) {
  var AssocElement = document.getElementById('Assoc_' + AssocID);
  if (Status == STATUS_ATTRIBUTE_ANALYZING ||
		Status == STATUS_ATTRIBUTE_SYNCHRONIZING) AssocElement.all.B_STOP.innerText = external.LS('button_stop');
  else AssocElement.all.B_STOP.innerText = external.LS('button_clear');
}

function UpdateAssocStatus(AssocID, status) {
  //---------------------------------------------------------------------------------------------------------
  var AssocElement = document.getElementById('Assoc_' + AssocID);
  if (!AssocElement) return;
  //---------------------------------------------------------------------------------------------------------
  var LabelCell = TabsLabels.cells['Label_' + AssocID];
  if (!LabelCell) return;// DU: the association tab has not been added yet
  // ---------------------------------------------------------------------------------------------------------
  var SyncBoardsTable_element = AssocElement.all.SyncBoardsTable;
  if (status == STATUS_ATTRIBUTE_ANALYZING) SyncBoardsTable_element.className = 'Analyze_State';
  else if (status == STATUS_ATTRIBUTE_SYNCHRONIZING) SyncBoardsTable_element.className = 'Sync_State';
  else SyncBoardsTable_element.className = 'Normal_State';
  //---------------------------------------------------------------------------------------------------------
  var LabelImg = LabelCell.all.Status_img;
  if (status == STATUS_ATTRIBUTE_NULL) LabelImg.src = 'Pics/Status_normal.gif';
  else if (status == STATUS_ATTRIBUTE_AUTOMATIC) LabelImg.src = 'Pics/Status_schedule.gif';
  else if (status == STATUS_ATTRIBUTE_AUTOMATIC_INTERNAL) LabelImg.src = 'Pics/Status_schedule.gif';
  else if (status == STATUS_ATTRIBUTE_AUTOMATIC_DISABLED) LabelImg.src = 'Pics/Status_manual.gif';
  else if (status == STATUS_ATTRIBUTE_ANALYZING) LabelImg.src = 'Pics/Status_analyze.gif';
  else if (status == STATUS_ATTRIBUTE_SYNCHRONIZING) LabelImg.src = 'Pics/Status_synchronize.gif';
  else if (status == STATUS_ATTRIBUTE_INFORMATION_MESSAGE) LabelImg.src = 'Pics/Status_information.gif';
  else if (status == STATUS_ATTRIBUTE_IMPORTANT_MESSAGE) LabelImg.src = 'Pics/Status_important.gif';
  else if (status == STATUS_ATTRIBUTE_INCOMPLETE) LabelImg.src = 'Pics/Status_incomplete.gif';
  // ---------------------------------------------------------------------------------------------------------
  UpdateButtonsTitle(AssocID, status);
  //---------------------------------------------------------------------------------------------------------
}

function DisableFSP(AssocID, FSPnum, if_disabled, Open_is_enabled) {
  var AssocElement2 = document.getElementById('Assoc_' + AssocID);
  var SyncTree_element = AssocElement2.all['SyncTree' + FSPnum];
  SyncTree_element.all['TreePath' + FSPnum].disabled = if_disabled;

  if (AssocID == G_ActiveAssocID) {
    var SyncTree_elem = document.getElementById('Assoc_' + G_ActiveAssocID).all['SyncTree' + FSPnum];
    var SyncTreeID = SyncTree_elem.synctree_id;
    SyncTree_element.all['More' + SyncTreeID + FSPnum + 'left'].src = 'Pics/Folder_button_left.gif';
    SyncTree_element.all['More' + SyncTreeID + FSPnum].style.backgroundImage = 'url(Pics/Folder_button_center.gif)'; // Wizard
    SyncTree_element.all['More' + SyncTreeID + FSPnum + 'right'].src = 'Pics/Folder_button_right.gif';
  }
  return;
}

function PlaceHintWindow(element, num) {
  if (element == null) { return; }

  var _left = -300 + element.offsetWidth;
  var _top = 47;

  while (element.tagName != 'BODY') {
    _left += element.offsetLeft;
    _top += element.offsetTop;
    element = element.offsetParent;
  }
  Hint_window.hint_number = num;
  Hint_window.style.left = _left;
  Hint_window.style.top = _top;
}

function ScrollToImportant() {
  AssocID = G_ActiveAssocID;
  ImportantID = G_Assocs[AssocID].TreeView._collectionIdByName.Important;
  if (G_Assocs[AssocID].TreeView.root._children[ImportantID]._expanded == 0) {
    OnCollectionExpandIconClick(AssocID, ImportantID);
  }
  ImportantCollectionElement = document.getElementById('Assoc_' + AssocID).all[ImportantID];
  ImportantCollectionElement.scrollIntoView();
}

function TabsCaptionResized() {
  if (TabsCaption.scrollLeft > 0) {
    LeftTabScroller.src = 'Pics/TabCaptionScroller1.gif';
    LeftTabScroller.onmousedown = LeftTabScrollerDown;
    LeftTabScroller.onmouseup = TabScrollerReleased;
    LeftTabScroller.onmouseleave = TabScrollerReleased;
  } else {
    LeftTabScroller.src = 'Pics/TabCaptionScroller0.gif';
    LeftTabScroller.onmousedown = '';
  }
  if (TabsCaption.scrollWidth - TabsCaption.clientWidth - TabsCaption.scrollLeft > 0) {
    RightTabScroller.src = 'Pics/TabCaptionScroller2.gif';
    RightTabScroller.onmousedown = RightTabScrollerDown;
    RightTabScroller.onmouseup = TabScrollerReleased;
    RightTabScroller.onmouseleave = TabScrollerReleased;
  } else {
    RightTabScroller.src = 'Pics/TabCaptionScroller0.gif';
    RightTabScroller.onmousedown = '';
  }
}

function TabLabelOnClick1(AssocID) {
  external.Method1('M_SelectAssoc', external.ObjByID(AssocID));
  var ActiveProfile = external.Method0Own('M_GetProfile');
  RefreshJobNameList(ActiveProfile.objID);
}

function TabLabelContextMenu(AssocID) {
  window.event.cancelBubble = true;
  var AssocObj = external.ObjByID(AssocID);
  if (AssocObj) external.ShowContextMenu(AssocObj, CONST_CID);
}

function ScrollTabLabelIntoView(AssocID) {
  LabelCell = TabsLabels.cells['Label_' + AssocID];
  LeftLabelOut = TabsCaption.scrollLeft - LabelCell.offsetLeft + 15;
  RightLabelOut = (LabelCell.offsetLeft + LabelCell.offsetWidth + 16) - (TabsCaption.scrollLeft + TabsCaption.clientWidth);
  //----------------------------------------------------------------------------------------
  if ((LeftLabelOut < 0) && (RightLabelOut < 0)) return;
  else if (LeftLabelOut < 0) ScrollTabToPixels('Right', RightLabelOut);
  else if (RightLabelOut < 0) ScrollTabToPixels('Left', LeftLabelOut);
  else if ((LeftLabelOut > 0) && (RightLabelOut > 0)) {
    if (LeftLabelOut > RightLabelOut) ScrollTabToPixels('Right', RightLabelOut);
    else ScrollTabToPixels('Left', LeftLabelOut);
  }
}

function LeftTabScrollerDown() {
  G_TabScrollingProcessNum++;
  RightTabScroller.src = 'Pics/TabCaptionScroller2.gif';
  RightTabScroller.onmousedown = RightTabScrollerDown;
  RightTabScroller.onmouseup = TabScrollerReleased;
  RightTabScroller.onmouseleave = TabScrollerReleased;
  ScrollTabTo('Left', G_TabScrollingProcessNum);
}

function RightTabScrollerDown() {
  G_TabScrollingProcessNum++;
  LeftTabScroller.src = 'Pics/TabCaptionScroller1.gif';
  LeftTabScroller.onmousedown = LeftTabScrollerDown;
  LeftTabScroller.onmouseup = TabScrollerReleased;
  LeftTabScroller.onmouseleave = TabScrollerReleased;
  ScrollTabTo('Right', G_TabScrollingProcessNum);
}

function TabScrollerReleased() {
  G_TabScrollingProcessNum++;
}

function ScrollTabTo(Direction, ProcessNum) {
  if (ProcessNum == G_TabScrollingProcessNum) {
    if (Direction == 'Left') {
      if (TabsCaption.scrollLeft > 5) {
        TabsCaption.scrollLeft -= 5;
        window.setTimeout("ScrollTabTo('Left'," + ProcessNum + ')', 5);
      } else {
        TabsCaption.scrollLeft = 0;
        LeftTabScroller.src = 'Pics/TabCaptionScroller0.gif';
        LeftTabScroller.onmousedown = '';
      }
    }
    if (Direction == 'Right') {
      if (TabsCaption.scrollWidth - TabsCaption.clientWidth - TabsCaption.scrollLeft > 5) {
        TabsCaption.scrollLeft += 5;
        window.setTimeout("ScrollTabTo('Right'," + ProcessNum + ')', 5);
      } else {
        TabsCaption.scrollLeft = TabsCaption.scrollWidth - TabsCaption.clientWidth;
        RightTabScroller.src = 'Pics/TabCaptionScroller0.gif';
        RightTabScroller.onmousedown = '';
      }
    }
  }
}

function ScrollTabToPixels(Direction, PixelNumber) {
  if (Direction == 'Left') {
    if (PixelNumber > TabsCaption.scrollLeft) PixelNumber = TabsCaption.scrollLeft;
    TabsCaption.scrollLeft = TabsCaption.scrollLeft - PixelNumber;
  }
  if (Direction == 'Right') {
    var temp = TabsCaption.scrollWidth - TabsCaption.clientWidth - TabsCaption.scrollLeft;
    if (PixelNumber > temp) PixelNumber = temp;
    TabsCaption.scrollLeft = TabsCaption.scrollLeft + PixelNumber;
  }
  TabsCaptionResized();
}

function CloseAnalizeHint() {
  AnalyzeButtonElement = window.event.srcElement;
  AssocID = AnalyzeButtonElement.association_id;
  ExtCloseHint(AssocID, 'Analyze_hint');
}

function ShowFM() {
  if (window.event.shiftKey) return;
  if (window.event.ctrlKey) return;

  var Src_cell = window.event.srcElement;
  G_Above_message.msg_id = Src_cell.msg_id;
  G_Above_message.collection_id = Src_cell.collection_id;
  window.setTimeout("OpenMenu(\'" + Src_cell.msg_id + "\', \'" + Src_cell.collection_id + "\')", 250);
}

function HideFM() {
  if (G_Above_message.latch == false) {
    var Src_cell = window.event.srcElement;
    G_Above_message.msg_id = null;

    G_Above_message.collection_id = null;

    if (G_Above_message.mustshown == false) {
      window.setTimeout("LeadUp(\'" + Src_cell.msg_id + "\', \'" + Src_cell.collection_id + "\')", 10);
    }
    //		Debug_window.innerHTML += (G_debug_line_number++)+' HideFM: Shown = '+G_Shown_message.msg_id+' Above = '+G_Above_message.msg_id+' : '+G_Above_message.mustshown+'<br>';
    window.setTimeout("CloseMenu(\'" + Src_cell.msg_id + "\', \'" + Src_cell.collection_id + "\')", 500);
  }
}
//	-------------------------------------------------------------------------------------------------
//	Function for requesting of Vova's context menu
//	-------------------------------------------------------------------------------------------------
function OnMsgContextMenu() {
  window.event.cancelBubble = true;
  element = window.event.srcElement;
  while (element.tagName != 'TBODY') {
    element = element.parentElement;
  }
  // show context menu if object exist
  if (element.id) {
    var MessageObj = external.ObjByID(element.id);
    if (MessageObj != null) {
      if (MessageObj.IsSyncItemMsg()) {
        var Solution = MessageObj.GetM('m_SolutionWPtr');
        if (Solution != null) {
          while (!element.sub_id) {
            element = element.parentElement;
          }
          external.ShowContextMenu(Solution, element.sub_id);
        }
      } else {
        external.ShowContextMenu(MessageObj, CONST_CID);
      }
    }
  }
}
//	-------------------------------------------------------------------------------------------------
//	alert('Cover/Show millde item for accosiation' );
//	-------------------------------------------------------------------------------------------------
function OnPopupClick() {
  if (G_Above_message.mustshown == true) {
    G_Above_message.mustshown = false;
    CloseMenu(G_Above_message.msg_id, G_Above_message.collection_id);
  } else {
    G_Above_message.mustshown = true;
    OpenMenu(G_Above_message.msg_id, G_Above_message.collection_id);
  }
}

function OnPopupContextMenu() {
  //	alert('OnPopupContextMenu()');
}

function LeadUp(msg_id, CollectionID) {
  if ((G_Above_message.msg_id != msg_id) || (G_Above_message.collection_id != CollectionID)) {
    G_Above_message.mustshown = true;
  }
}
//	------------------------------------------------------------------------------------------
//	alert("open menu - middle item for association");
function OpenMenu(msg_id, CollectionID) {
  if ((G_Above_message.collection_id == CollectionID) && (G_Above_message.msg_id == msg_id) &&
		(G_Above_message.mustshown == true) && (G_Shown_message.msg_id != msg_id)) {
    CloseMenu(G_Shown_message.msg_id, G_Shown_message.collection_id);
    CloseSelectedMenu(G_Shown_message.msg_id, G_Shown_message.collection_id);

    // Get first element with specific ID
    var Collection_element = document.getElementById(CollectionID + '_container'); if (Collection_element == null) return;
    //	Get the message by ID
    var Msg_element = Collection_element.all[msg_id];
    //-----------------------------------------------------------------------------------------
    // New added for menu of deleted item
    if (Msg_element == null) return;
    //-----------------------------------------------------------------------------------------
    //	Set the class for message alert(Msg_element.outerHTML);
    Msg_element.oldClassName = Msg_element.className;
    Msg_element.className = 'Msg_Edited';
    Msg_element.className = Msg_element.className + ' Exp';
    // if item must be shown
    if (Msg_element.msg_type == '2') {
      var Base_up_element = Msg_element.all['Base_' + msg_id];
      var Base_down_element = Base_up_element;
    } else {
      var Base_up_element = Msg_element.all['Base_up_' + msg_id];
      var Base_down_element = Msg_element.all['Base_down_' + msg_id];
    }

    // if it must to do nothing	---------------------------------------------------------------------------------------------
    if (Msg_element.if_dont_sync == 'true') var picture = 'Pics/Radio_no_active.gif';
    else var picture = 'Pics/Radio_no_unactive.gif';

    var MsgObj = external.ObjByID(msg_id);
    var solution = MsgObj.GetObjM('m_SolutionWPtr');
    var Dont_sync_pic = '<img src="' + picture + '" onclick=OnArrowClick("' +
			solution.objID + '","' + CONST_WIN_NO_SYNC + '") style="cursor:hand" title="' + external.LS('hint_Winner_Nothing') + '">';
    // if it must to delete all	---------------------------------------------------------------------------------------------
    if (Msg_element.if_del_sync == 'true') var picture = 'Pics/Radio_del_active.gif';
    else var picture = 'Pics/Radio_del_unactive.gif';

    var MsgObj = external.ObjByID(msg_id);
    var solution = MsgObj.GetObjM('m_SolutionWPtr');
    var Del_sync_pic = '<img src="' + picture + '" onclick=OnArrowClick("' +
			solution.objID + '","' + CONST_WIN_DEL_SYNC + '") style="cursor:hand" title="' + external.LS('hint_Winner_Delete_All') + '">';
    //  -------------------------------------------------------------------------------------------------------------------------

    var Up_plate = document.createElement('div');
    var Down_plate = document.createElement('div');

    Base_down_element.className = 'Back_plate1';
    Base_up_element.appendChild(Up_plate);
    Base_down_element.appendChild(Down_plate);

    Up_plate.id = 'Up_plate';
    Up_plate.className = 'Up_plate_style_' + Msg_element.msg_type;

    var CaptionClass = 'MsgPopupCaption';
    if (MsgObj.Method0('M_GetSelectedState') == true) CaptionClass += '_selected';
    Up_plate.innerHTML = '<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td class="' + CaptionClass + '" width="100%" align="center"><marquee behavior="alternate" direction="right" scrollamount="1">' + external.LS('popup_menu_select') + '</marquee></td></tr></table>';

    Down_plate.id = 'Down_plate';
    Down_plate.className = 'Down_plate_style_' + Msg_element.msg_type;

    var MoreRefClass = 'More_ref';
    if (MsgObj.Method0('M_GetSelectedState') == true) MoreRefClass += '_selected';
    Down_plate.innerHTML = '<table width="100%" cellspacing="0" cellpadding="0">' +
			'<tr>' +
			'<td class="Down_plate_cell" style="padding-left:5px;">' +
			'<span class="' + MoreRefClass + '" onclick="OnUserMsgMoreButtonClick(\'' + msg_id + '\', \'' + CollectionID + '\')">' +
			external.LS('popup_menu_more') +
			'</span>' +
			'</td>' +
			'<td class="Down_plate_cell" width="100%">' +
			'<img src="Pics/Dot.gif">' +
			Dont_sync_pic +
			'</td>' +
			'<td class="Down_plate_cell" style="padding-right:7px;">' +
			Del_sync_pic + '</td>' +
			'</tr>' +
			'</table>';
    //	-------------------------------------------------------------------------------------------------------------------------
    G_Shown_message.msg_id = msg_id;
    G_Shown_message.collection_id = CollectionID;
  }
}

function CloseMenu(msg_id, CollectionID) {
  Aboveflag = (G_Above_message.collection_id == CollectionID) && (G_Above_message.msg_id == msg_id);
  if ((!Aboveflag || (G_Above_message.mustshown == false)) && (G_Shown_message.msg_id == msg_id) && (G_Shown_message.collection_id == CollectionID) && (G_Shown_message.msg_id != null)) {
    // find string in collection
    var Collection_element = document.getElementById(CollectionID + '_container');
    if (Collection_element == null) {
      return;
    }
    // find message for(in) element
    var Msg_element = Collection_element.all[msg_id];
    if (Msg_element == null) {
      return;
    }
    //	change view to normal
    Msg_element.className = Msg_element.oldClassName;

    Msg_element.className = Msg_element.className.replace(/ Exp/, '');

    //	find up_plate in message
    var Up_plate = Msg_element.all.Up_plate;
    if (Up_plate == null) return;
    Up_plate.outerHTML = '';// Up_plate.removeNode(true);
    //	find Down_plate in message
    var Down_plate = Msg_element.all.Down_plate;
    if (Down_plate == null) return;
    Down_plate.outerHTML = '';// Down_plate.removeNode(true);

    //	change to normal state
    if (Msg_element.msg_type == '2') Base_down_element = Msg_element.all['Base_' + msg_id];
    else Base_down_element = Msg_element.all['Base_down_' + msg_id];

    Base_down_element.className = 'Back_plate';
    G_Shown_message.msg_id = null;
    //				Debug_shown_msg.innerText = 'null';
    G_Shown_message.collection_id = null;
    //				Debug_shown_collection.innerText = 'null';
  }
}

function AddTreeToAssoc() {
  var AssocObj = external.ObjByID(G_ActiveAssocID);
  AssocObj.Method0('M_CreateNewSyncTreeInAssoc');
  //	ExtOnAssocChanged(G_ActiveAssocID);
  ExtOnProfileChanged();
}

function DeleteTreeFromAssoc(AssocID, SuperTreeID) {
  var AssocObj = external.ObjByID(AssocID);
  var SuperTreeList = AssocObj.GetM('m_SuperTreesPtr');
  var SuperTree = SuperTreeList.ObjByID(SuperTreeID);
  SuperTreeList.Method1('M_RemoveKey', SuperTree);
  ExtOnProfileChanged();
}

function OnUserMsgMoreButtonClick(MessageID, CollectionID) {
  window.event.cancelBubble = true;
  G_Above_message.latch = true;
  var MessageObj = external.ObjByID(MessageID);
  var Solution = MessageObj.GetM('m_SolutionWPtr');
  external.ShowContextMenu(Solution, CollectionID);
  G_Above_message.latch = false;
  return;
}

function CapMenuLinkClick() {
  if (G_Caption_menu == false) {
    G_Caption_menu_mustshown = true;
    G_Caption_menu_above = true;
    Hint_window.style.visibility = 'hidden';
    Change_link_container.style.visibility = 'hidden';
    OpenCaptionMenu();
    var Assoc_element = document.getElementById('Assoc_' + G_ActiveAssocID);
    Assoc_element.all.TopCapRadioLeft.children[0].focus();
  }
}

function CapMenuClick() {
  if (G_Caption_menu == false) {
    CapMenuLinkClick();
  } else {
    G_Caption_menu_mustshown = false;
    CloseCaptionMenu();
  }
}

function CapMenuFocusIn() {
  //	Debug_window.innerHTML = 'CapMenuFocusIn(): '+window.event.srcElement.tagName+'<br>'+Debug_window.innerHTML;
  G_FocusInCaptionMenu = true;
}

function CapMenuFocusOut() {
  //	Debug_window.innerHTML = 'CapMenuFocusOut(): '+window.event.srcElement.tagName+' to '+event.toElement.tagName+'<br>'+Debug_window.innerHTML;
  if (G_Block == false) {
    G_FocusInCaptionMenu = false;
    window.setTimeout('HandleCaptionMenu()', 10);
  } else {
    G_Block = false;
  }
}

function HandleCaptionMenu() {
  if (G_FocusInCaptionMenu == false) {
    //		Debug_window.innerHTML = 'HandleCaptionMenu() before close<br>'+Debug_window.innerHTML;
    G_Caption_menu_mustshown = false;
    CloseCaptionMenu();
  }
}

function CapMenuEnter() {
  G_Caption_menu_above = true;
  //	G_Caption_menu_mustshown = true;
  window.setTimeout('OpenCaptionMenu()', 10);
}

function CapMenuLeave() {
  //	Debug_window.innerHTML = 'CapMenuLeave()<br>'+Debug_window.innerHTML;
  G_Caption_menu_above = false;
  window.setTimeout('CloseCaptionMenu()', 10);
}

function OpenCaptionMenu() { // alert('OpenCaptionMenu');
  //	Debug_window.innerHTML = 'OpenCaptionMenu: G_Caption_menu_above = '+G_Caption_menu_above+'; G_Caption_menu = '+G_Caption_menu+' G_Caption_menu_mustshown = '+G_Caption_menu_mustshown+'<br>'+Debug_window.innerHTML;
  if ((G_Caption_menu_above == true) && (G_Caption_menu_mustshown == true)) {
    AssocElement = document.getElementById('Assoc_' + G_ActiveAssocID);
    if (!AssocElement) return;
    SyncBoardsTable_element = AssocElement.all.SyncBoardsTable;
    if (!SyncBoardsTable_element) return;
    SyncBoardsTable_element.className = 'Exp';
    if (G_Assocs[G_ActiveAssocID].WinningSuperTreeID == CONST_CID) {
      Caption_down_plate.all.AllWayRadio.src = 'Pics/Radio_all_way.gif';
    } else {
      Caption_down_plate.all.AllWayRadio.src = 'Pics/Radio_all_way_unactive.gif';
    }
    var AssocObj = external.ObjByID(G_ActiveAssocID);
    If_remove_check.checked = AssocObj.Method0('M_GetMimicDeleted');
    If_rewrite_check.checked = AssocObj.Method0('M_GetMimicChanged');
    Caption_up_plate.style.visibility = 'visible';
    Caption_down_plate.style.visibility = 'visible';
    G_Caption_menu = true;
  }
}

function CloseCaptionMenu() {
  if ((G_Caption_menu_above == false) || ((G_Caption_menu == true) && (G_Caption_menu_mustshown == false))) {
    AssocElement = document.getElementById('Assoc_' + G_ActiveAssocID);
    SyncBoardsTable_element = AssocElement.all.SyncBoardsTable;
    //----------------------------------------------------------------------------------------------------------------
    var state = 'Normal_State';
    var AssocObj = external.ObjByID(G_ActiveAssocID);
    if (AssocObj != null) {
      if ((AssocObj.Method1('M_GetStatusAttribute', STATUS_ATTRIBUTE_ANALYZING) == 1) &&
				(AssocObj.Method1('M_GetStatusAttribute', STATUS_ATTRIBUTE_INFORMATION_MESSAGE) == 0) &&
				(AssocObj.Method1('M_GetStatusAttribute', STATUS_ATTRIBUTE_IMPORTANT_MESSAGE) == 0)) state = 'Analyze_State';
      else if (AssocObj.Method1('M_GetStatusAttribute', STATUS_ATTRIBUTE_SYNCHRONIZING) == 1) state = 'Sync_State';
    }
    SyncBoardsTable_element.className = state;
    //----------------------------------------------------------------------------------------------------------------
    Change_link_container.style.visibility = 'visible';
    Caption_up_plate.style.visibility = 'hidden';
    Caption_down_plate.style.visibility = 'hidden';
    G_Caption_menu = false;
    G_Caption_menu_mustshown = false;
  }
}

function ResizeWindow() {
  var AssocElement = document.getElementById('Assoc_' + G_ActiveAssocID);
  if (AssocElement == null) {
    return;
  }
  if (Hint_window.hint_number != '') {
    var element = AssocElement.all['TreePath' + Hint_window.hint_number];
    PlaceHintWindow(element, Hint_window.hint_number);
  }

  var _left = 240;
  var element1 = AssocElement.all.SyncBoardsTable;
  var _width = element1.offsetWidth - 500;
  var _top_h = element1.offsetHeight;
  var _top = 0;
  //---------------------------------------
  while (element1.tagName != 'BODY') {
    _left += element1.offsetLeft;
    _top += element1.offsetTop;
    element1 = element1.offsetParent;
  }
  //---------------------------------------
  var _center = (_width / 2) + _left;
  //---------------------------------------
  if (G_Sync_board_state == 1) {
    if (Change_link_container) {
      if (Change_link_container.style) {
        Change_link_container.style.left = _left + 30;
        // Change_link_container.style.width = _width - 40;
        if ((_width - 40) > 0) Change_link_container.style.width = _width - 40; else Change_link_container.style.width = 1;
        Change_link_container.style.top = _top + 24;
      }
    }
    //---------------------------------------
    Caption_up_plate.style.left = _center - 84;
    Caption_up_plate.style.width = 190;
    var _top_up = Caption_up_plate.offsetHeight;
    Caption_up_plate.style.top = _top - _top_up;
    //---------------------------------------
    Caption_down_plate.style.left = _center - 84;
    Caption_down_plate.style.width = 190;
    Caption_down_plate.style.top = _top + _top_h;
  }
  //-----------------------------------------------------------
  // Wizard Panel & Folder_Type_List Panel Size/Position Calculation
  //-----------------------------------------------------------
  if (document.getElementById('TreeForm' + G_Wizard_folder_num)) {
    WizardPanelRefresh(G_Wizard_Sync_Tree_Obj_ID, G_Wizard_folder_num, true);
  }

  if (document.getElementById('TreeForm' + G_Folder_Type_List_folder_num)) {
    TypeListPanelRefresh(G_Folder_Type_List_Sync_Tree_Obj_ID, G_Folder_Type_List_folder_num);
  }
  // -----------------------------------------------------------
}

function ManualOn() {
  AssocElement = document.getElementById('Assoc_' + G_ActiveAssocID);
  AssocElement.all.Manual_switch.className = 'Switch_control_active';
  AssocElement.all.Auto_switch.className = 'Switch_control_unactive';
  AssocElement.all.Control_buttons_panel.innerHTML = Manual_template.innerHTML;
  // ---------------------
  AssocElement.all.B_ANALYZE.innerText = external.LS('button_analyze');
  AssocElement.all.B_ANALYZE.title = external.LS('tooltip_Analyze_button');
  AssocElement.all.B_ANALYZE.association_id = G_ActiveAssocID;
  AssocElement.all.B_SYNC.innerText = external.LS('button_synchronize');
  AssocElement.all.B_SYNC.title = external.LS('tooltip_Sinchronize_button');
  AssocElement.all.B_SYNC.association_id = G_ActiveAssocID;
  AssocElement.all.B_STOP.innerText = external.LS('button_stop');
  AssocElement.all.B_STOP.title = external.LS('tooltip_Stop_button');
  AssocElement.all.B_STOP.association_id = G_ActiveAssocID;
  AssocElement.all.Important_warning_text.innerText = external.LS('important_warning');
  AssocElement.all.Important_warning.title = external.LS('tooltip_Important_warning');
  UpdateButtons(G_ActiveAssocID);
}

function AutoOn() {
  AssocElement = document.getElementById('Assoc_' + G_ActiveAssocID);
  AssocElement.all.Manual_switch.className = 'Switch_control_unactive';
  AssocElement.all.Auto_switch.className = 'Switch_control_active';
  AssocElement.all.Control_buttons_panel.innerHTML = Auto_template.innerHTML;
}

function CapRadioHandler(AssocID, SuperTreeID)	// For DU: Used if one way sync turn on
{
  window.event.cancelBubble = true;
  G_Assocs[AssocID].WinningSuperTreeID = SuperTreeID;
  var AssocObj = external.ObjByID(AssocID);

  G_AssocChangedCause = 'SyncDirectionChanged';
  AssocObj.Method1ID('M_SetSyncDirection', SuperTreeID);	// For DU: set one way sync
  G_AssocChangedCause = '';
}

function CapAllWayOn()	// For DU: Used if one way sync turn off
{
  window.event.cancelBubble = true;
  G_Assocs[G_ActiveAssocID].WinningSuperTreeID = CONST_CID;
  var AssocObj = external.ObjByID(G_ActiveAssocID);
  G_AssocChangedCause = 'SyncDirectionChanged';
  AssocObj.Method1ID('M_SetSyncDirection', 'DIRECTION_ALL_WAY');	// For DU: set all way sync
  G_AssocChangedCause = '';
  // DU: we'll get an event about paths has changed. LoadAssocPaths(G_ActiveAssocID);
}

function CaptionCheckBoxClick(element) {
  window.event.cancelBubble = true;
  var AssocObj = external.ObjByID(G_ActiveAssocID);
  if (element.id == 'If_remove_check') {
    G_AssocChangedCause = 'Propagate_set';
    AssocObj.Method1('M_SetMimicDeleted', element.checked);
    G_AssocChangedCause = '';
  } else if (element.id == 'If_rewrite_check') {
    G_AssocChangedCause = 'Propagate_set';
    AssocObj.Method1('M_SetMimicChanged', element.checked);
    G_AssocChangedCause = '';
  }
}


function CaptionLabelClick(element) {
  window.event.cancelBubble = true;
}

function BlockFocusOut() {
  G_Block = true;
}

function ButtonContextMenu() {
  window.event.cancelBubble = true;
}

function StopContextMenu() {
  window.event.cancelBubble = true;
}

function Debug() {
  //	G_Block = true;
  //	Debug_window.innerHTML = 'Debug()<br>'+Debug_window.innerHTML;
  //	AssocElement = document.getElementById('Assoc_'+G_ActiveAssocID);
  //	external.StrToDebugFile(AssocElement.outerHTML);
}
function OnMouseOverPath() {
  event.srcElement.OldClassName = event.srcElement.className;
  event.srcElement.className = 'VisitedItem';
}

function OnMouseOutPath() {
  event.srcElement.className = event.srcElement.OldClassName;
}

function LinkToCollectionMsg(CollectionName, MsgObjID) {
  var AssocContainer = document.getElementById('Assoc_' + G_ActiveAssocID);
  var CollectionId = G_Assocs[G_ActiveAssocID].TreeView._collectionIdByName[CollectionName];
  //--------------------------------------------------------------------------------
  if (G_Assocs[G_ActiveAssocID].TreeView.root._children[CollectionId]._expanded == 0) {
    OnCollectionExpandIconClick(G_ActiveAssocID, CollectionId);
  }
  //--------------------------------------------------------------------------------
  var LinkID = 'Link' + CollectionId + MsgObjID;
  var LinkItem = document.getElementById(LinkID);
  if (LinkItem == null) {
    var CollectionObj = external.ObjById(CollectionId);
    var msg = CollectionObj.Method1('M_GetItemBySolutionID', MsgObjID);
    if (msg == null) return;
    var solution = msg.GetObjM('m_SolutionWPtr');

    if (solution.objID == MsgObjID) {
      var counter = 0;
      var msgs = G_Assocs[G_ActiveAssocID].TreeView._collections[CollectionId].obj;
      var msg2 = msgs.GetLast();
      var solution2 = msg2.GetObjM('m_SolutionWPtr');

      while ((solution2.objID != MsgObjID) && (counter < CONST_MESSAGES_ON_PAGE)) {
        msg2 = msgs.GetPrev(msg2);
        solution2 = msg2.GetObjM('m_SolutionWPtr');
        counter = counter + 1;
      }

      if (counter == CONST_MESSAGES_ON_PAGE) {
        var msg_index = CollectionObj.Method1('M_GetMessageIndexByID', msg.objID);
        CollectionObj.Method1('M_SetFirstVisibleMessageByIndex', msg_index);
      } else {
        for (i = CONST_MESSAGES_ON_PAGE; i > counter + 1; i--) {
          msg2 = msgs.GetPrev(msg2);
          solution2 = msg2.GetObjM('m_SolutionWPtr');
        }
        var msg_index = CollectionObj.Method1('M_GetMessageIndexByID', msg2.objID);
        CollectionObj.Method1('M_SetFirstVisibleMessageByIndex', msg_index);
      }
      G_Assocs[G_ActiveAssocID].TreeView.redraw_collection(CollectionId);
      LinkItem = document.getElementById(LinkID);
      if (LinkItem != null) LinkItem.scrollIntoView(true);
    } else if (msg.objID == msgs.GetLast().objID) {
      alert('LinkItem is not found');
    }
  } else {
    LinkItem.scrollIntoView(true);
  }
}

function OnSortItemClick(Sort_Type, CollectionID) {
  if (((Sort_Type == 'name_1') || (Sort_Type == 'name_2')) && (G_Select_All == true)) { G_Select_All = false; return; }

  var Last_Sort_Info = 'Sort_by_default';
  var New_Sort_Info = 'Sort_by_default';
  //----------------------------------------------------
  var msgs = external.ObjByID(CollectionID);
  var Last_Sort_ID = msgs.Method0('M_GetSortingCriterion');
  var TreeID = msgs.Method0('M_GetSortingTree');
  //----------------------------------------------------
  var AssocObj = external.ObjByID(G_ActiveAssocID);
  var SuperTreeList = AssocObj.GetM('m_SuperTreesPtr');
  var SuperTree_Obj = SuperTreeList.GetFirst();
  var Tree_0_ID = SuperTree_Obj.objID;
  SuperTree_Obj = SuperTreeList.GetNext(SuperTree_Obj);
  var Tree_1_ID = SuperTree_Obj.objID;
  //-----------------------------------------------------------------------------------------------
  if ((Last_Sort_ID == '646E6563736544435174726F53676E69') && (TreeID == Tree_0_ID)) { Last_Sort_Info = 'Sort_by_name_down_1'; } else
  if ((Last_Sort_ID == '69646E6563734143464974726F53676E') && (TreeID == Tree_0_ID)) { Last_Sort_Info = 'Sort_by_name_up_1'; } else
  if ((Last_Sort_ID == '646E6563736544436B74726F53676E69') && (TreeID == Tree_0_ID)) { Last_Sort_Info = 'Sort_by_size_down_1'; } else
  if ((Last_Sort_ID == '69646E6563734143604974726F53676E') && (TreeID == Tree_0_ID)) { Last_Sort_Info = 'Sort_by_size_up_1'; } else
  if ((Last_Sort_ID == '646E6563736544435F74726F53676E69') && (TreeID == Tree_0_ID)) { Last_Sort_Info = 'Sort_by_time_down_1'; } else
  if ((Last_Sort_ID == '69646E6563734143544974726F53676E') && (TreeID == Tree_0_ID)) { Last_Sort_Info = 'Sort_by_time_up_1'; }
  // -----------------------------------------------------------------------------------------------
  else
  if ((Last_Sort_ID == '646E6563736544435174726F53676E69') && (TreeID == Tree_1_ID)) { Last_Sort_Info = 'Sort_by_name_down_2'; } else
  if ((Last_Sort_ID == '69646E6563734143464974726F53676E') && (TreeID == Tree_1_ID)) { Last_Sort_Info = 'Sort_by_name_up_2'; } else
  if ((Last_Sort_ID == '646E6563736544436B74726F53676E69') && (TreeID == Tree_1_ID)) { Last_Sort_Info = 'Sort_by_size_down_2'; } else
  if ((Last_Sort_ID == '69646E6563734143604974726F53676E') && (TreeID == Tree_1_ID)) { Last_Sort_Info = 'Sort_by_size_up_2'; } else
  if ((Last_Sort_ID == '646E6563736544435F74726F53676E69') && (TreeID == Tree_1_ID)) { Last_Sort_Info = 'Sort_by_time_down_2'; } else
  if ((Last_Sort_ID == '69646E6563734143544974726F53676E') && (TreeID == Tree_1_ID)) { Last_Sort_Info = 'Sort_by_time_up_2'; }
  //-----------------------------------------------------------------------------------------------
  else
  if ((Last_Sort_ID == '646E6563736544434374726F53676E69')) { Last_Sort_Info = 'Sort_by_winner_down'; } else
  if ((Last_Sort_ID == '69646E6563734143744974726F53676E')) { Last_Sort_Info = 'Sort_by_winner_up'; }
  //-----------------------------------------------------------------------------------------------
  if (Sort_Type == 'name_1') {
    if (Last_Sort_Info != 'Sort_by_name_up_1') New_Sort_Info = 'Sort_by_name_up_1';
    else New_Sort_Info = 'Sort_by_name_down_1';
  }
  if (Sort_Type == 'name_2') {
    if (Last_Sort_Info != 'Sort_by_name_up_2') New_Sort_Info = 'Sort_by_name_up_2';
    else New_Sort_Info = 'Sort_by_name_down_2';
  }
  //-----------------------
  if (Sort_Type == 'size_1') {
    if (Last_Sort_Info != 'Sort_by_size_up_1') New_Sort_Info = 'Sort_by_size_up_1';
    else New_Sort_Info = 'Sort_by_size_down_1';
  }
  if (Sort_Type == 'size_2') {
    if (Last_Sort_Info != 'Sort_by_size_up_2') New_Sort_Info = 'Sort_by_size_up_2';
    else New_Sort_Info = 'Sort_by_size_down_2';
  }
  //-----------------------
  if (Sort_Type == 'time_1') {
    if (Last_Sort_Info != 'Sort_by_time_up_1') New_Sort_Info = 'Sort_by_time_up_1';
    else New_Sort_Info = 'Sort_by_time_down_1';
  }
  if (Sort_Type == 'time_2') {
    if (Last_Sort_Info != 'Sort_by_time_up_2') New_Sort_Info = 'Sort_by_time_up_2';
    else New_Sort_Info = 'Sort_by_time_down_2';
  }
  //-----------------------
  if (Sort_Type == 'winner') {
    if (Last_Sort_Info != 'Sort_by_winner_up') New_Sort_Info = 'Sort_by_winner_up';
    else New_Sort_Info = 'Sort_by_winner_down';
  }
  //-----------------------
  G_Assocs[G_ActiveAssocID].TreeView._collections[CollectionID].sort = New_Sort_Info;
  //-----------------------

  var AssocObj = external.ObjByID(G_ActiveAssocID);
  var SuperTreeList = AssocObj.GetM('m_SuperTreesPtr');
  var SuperTree_Obj = SuperTreeList.GetFirst();
  var Tree_0_ID = SuperTree_Obj.objID;
  SuperTree_Obj = SuperTreeList.GetNext(SuperTree_Obj);
  var Tree_1_ID = SuperTree_Obj.objID;
  //------------------------------------------------------------------------------------------------------------------
  if ((New_Sort_Info == 'Sort_by_name_down_1')) { New_Sort_ID = '646e6563736544435174726f53676e69'; TreeID = Tree_0_ID; } else
  if ((New_Sort_Info == 'Sort_by_name_up_1')) { New_Sort_ID = '69646e6563734143464974726f53676e'; TreeID = Tree_0_ID; } else
  if ((New_Sort_Info == 'Sort_by_size_down_1')) { New_Sort_ID = '646e6563736544436b74726f53676e69'; TreeID = Tree_0_ID; } else
  if ((New_Sort_Info == 'Sort_by_size_up_1')) { New_Sort_ID = '69646e6563734143604974726f53676e'; TreeID = Tree_0_ID; } else
  if ((New_Sort_Info == 'Sort_by_time_down_1')) { New_Sort_ID = '646e6563736544435f74726f53676e69'; TreeID = Tree_0_ID; } else
  if ((New_Sort_Info == 'Sort_by_time_up_1')) { New_Sort_ID = '69646e6563734143544974726f53676e'; TreeID = Tree_0_ID; }
  // -------------------------------------------------------------------------------------------------------------------
  else
  if ((New_Sort_Info == 'Sort_by_name_down_2')) { New_Sort_ID = '646e6563736544435174726f53676e69'; TreeID = Tree_1_ID; } else
  if ((New_Sort_Info == 'Sort_by_name_up_2')) { New_Sort_ID = '69646e6563734143464974726f53676e'; TreeID = Tree_1_ID; } else
  if ((New_Sort_Info == 'Sort_by_size_down_2')) { New_Sort_ID = '646e6563736544436b74726f53676e69'; TreeID = Tree_1_ID; } else
  if ((New_Sort_Info == 'Sort_by_size_up_2')) { New_Sort_ID = '69646e6563734143604974726f53676e'; TreeID = Tree_1_ID; } else
  if ((New_Sort_Info == 'Sort_by_time_down_2')) { New_Sort_ID = '646e6563736544435f74726f53676e69'; TreeID = Tree_1_ID; } else
  if ((New_Sort_Info == 'Sort_by_time_up_2')) { New_Sort_ID = '69646e6563734143544974726f53676e'; TreeID = Tree_1_ID; }
  //-----------------------------------------------------------------------------------------------
  else
  if (New_Sort_Info == 'Sort_by_winner_down') { New_Sort_ID = '646e6563736544434374726f53676e69'; } else
  if (New_Sort_Info == 'Sort_by_winner_up') { New_Sort_ID = '69646e6563734143744974726f53676e'; }
  //-----------------------------------------------------------------------------------------------
  msgs.Method2('M_SetSortingCriterion', New_Sort_ID, TreeID);

  // msgs.Method1('M_SetFirstVisibleMessageByIndex', 0);
  G_Assocs[G_ActiveAssocID].TreeView.redraw_collection(CollectionID);
  //-----------------------------------------------------------------------------------------------
}
//---------------------------------------------------------------------------------------------------------
// DHTML Library
//---------------------------------------------------------------------------------------------------------
// Global variables
var isCSS;

var isW3C;

var isIE4;

var isNN4;

var isIE6CSS;

// Initialization after loading
function initDHTMLAPI() // Ok
{
  if (document.images) {
    isCSS = (document.body && document.body.style) ? true : false;
    isW3C = (isCSS && document.getElementById) ? true : false;
    isIE4 = (isCSS && document.all) ? true : false;
    isNN4 = (document.layers) ? true : false;
    isIE6CSS = (document.compatMode && document.compatMode.indexOf('CSS1') >= 0) ? true : false;
  }
}

//
function seekLayer(doc, name) {
  var theObj;
  for (var i = 0; i < doc.layers.length; i++) {
    if (doc.layers.name == name) {
      theObj = doc.layers[i];
      break;
    }
  }
  if (doc.layers[i].document.layers.length > 0) {
    theObj = seekLayer(document.layers[i], document.name);
  }
  return theObj;
}

//
function getRawObject(obj) {
  var theObj;
  if (typeof obj == 'string') {
    if (isW3C) theObj = document.getElementById(obj);
    else if (isIE4) theObj = document.all(obj);
    else if (isNN$) theObj = seekLayer(document, obj);
  } else theObj = obj;
  return theObj;
}

//
function getObject(obj) {
  var theObj = getRawObject(obj);
  if (theObj && isCSS) {
    theObj = theObj.style;
  }
  return theObj;
}

//
function shiftTo(obj, x, y) {
  var theObj = getObject(obj);
  if (theObj) {
    if (isCSS) {
      var units = (typeof theObj.left == 'string') ? 'px' : 0;
      theObj.left = x + units;
      theObj.top = y + units;
    } else if (isNN4) theObj.moveTo(x, y);
  }
}

//
function shiftBy(obj, deltaX, deltaY) {
  var theObj = getObject(obj);
  if (theObj) {
    if (isCSS) {
      var units = (typeof theObj.left == 'string') ? 'px' : 0;
      theObj.left = getObjectLeft(obj) + deltaX + units;
      theObj.top = getObjectTop(obj) + deltaY + units;
    } else if (isNN4) theObj.moveBy(deltaX, deltaY);
  }
}

//
function setZIndex(obj, zOrder) {
  var theObj = getObject(obj);
  if (theObj) theObj.zIndex = zOrder;
}

//
function setBGColor(obj, color) {
  var theObj = getObject(obj);
  if (theObj) {
    if (isNN4) theObj.bgColor = color;
    else if (isCSS) theObj.backgroundColor = color;
  }
}

//
function show(obj) {
  var theObj = getObject(obj);
  if (theObj) {
    theObj.visibility = 'visible';
  }
}
//
function hide(obj) {
  var theObj = getObject(obj);
  if (theObj) {
    theObj.visibility = 'hidden';
  }
}

//
function getObjectLeft(obj) {
  var elem = getRawObject(obj);
  var result = 0;
  if (document.defaultView) {
    var style = document.defaultView;
    var cssDecl = style.getComputedStyle(elem, '');
    result = cssDecl.getPropertyValue('left');
  } else if (elem.currentStyle) result = elem.currentStyle.left;
  else if (elem.style) result = elem.style.left;
  else if (isNN4) result = elem.left;
  return parseInt(result);
}

//
function getObjectTop(obj) {
  var elem = getRawObject(obj);
  var result = 0;
  if (document.defaultView) {
    var style = document.defaultView;
    var cssDecl = style.getComputedStyle(elem, '');
    result = cssDecl.getPropertyValue('top');
  } else if (elem.currentStyle) result = elem.currentStyle.top;
  else if (elem.style) result = elem.style.top;
  else if (isNN4) result = elem.top;
  return parseInt(result);
}

//
function getObjectWidth(obj) {
  var elem = getRawObject(obj);
  var result = 0;
  if (elem.offsetWidth) result = elem.offsetWidth;
  else if (elem.clip && elem.clip.width) result = elem.clip.width;
  else if (elem.style && elem.style.pixelWidth) result = elem.style.pixelWidth;
  return parseInt(result);
}
//
function getObjectHeight(obj) {
  var elem = getRawObject(obj);
  var result = 0;
  if (elem.offsetHeight) result = elem.offsetHeight;
  else if (elem.clip && elem.clip.height) result = elem.clip.height;
  else if (elem.style && elem.style.pixelHeight) result = elem.style.pixelHeight;
  return parseInt(result);
}

//
function getInsideWindowWidth() {
  if (window.innerWidth) return window.innerWidth;
  else if (isIE6CSS) return document.body.parentElement.clientWidth;
  else if (document.body && document.body.clientWidth) return document.body.clientWidth;
  return 0;
}

//
function getInsideWindowHeight() {
  if (window.innerHeight) return window.innerHeight;
  else if (isIE6CSS) return document.body.parentElement.clientHeight;
  else if (document.body && document.body.clientWidth) return document.body.clientHeight;
  return 0;
}
//---------------------------------------------------------------------------------------------------------
// DRAGIMAGE Library
//---------------------------------------------------------------------------------------------------------
// Global variables
var selectedObj;
var containerObj;
var offsetX;
var offsetY;
var BarX; var BarY;
var msgIndex = null;
var BarHeight; var ContainerHeight;
var firstElement;

function setSelectedElem(evt) {
  var target = (evt.target) ? evt.target : evt.srcElement;
  //------------------------------------------
  var divID = (target.name && target.src) ? target.name + 'Wrap' : '';
  if (divID) {
    selectedObj = document.getElementById(divID);
    setZIndex(selectedObj, 100);
    var ContainerDivID = divID + 'Container';
    if (ContainerDivID) containerObj = document.getElementById(ContainerDivID);
    return;
  }
  //------------------------------------------
  // page block
  //------------------------------------------
  divID = (target.collectionID) ? target.id : '';
  if (divID) {
    var Obj = document.getElementById(target.collectionID + 'BarWrap');
    if (Obj.offsetTop < evt.offsetY) go_next_page(target.collectionID);
    else go_prev_page(target.collectionID);
    return;
  }
  //------------------------------------------
  containerObj = null;
  selectedObj = null;
  return;
}
//------------------------------------------------------------------------------------------
function engage(evt) {
  evt = (evt) ? evt : event;
  setSelectedElem(evt);
  if (selectedObj) {
    document.body.setCapture();
    offsetX = evt.clientX - ((selectedObj.offsetLeft) ? selectedObj.offsetLeft : 0);
    offsetY = evt.clientY - ((selectedObj.offsetTop) ? selectedObj.offsetTop : 0);
    return false;
  }
  return true;
}
//------------------------------------------------------------------------------------------
var latch = false;

function dragIt(evt) {
  evt = (evt) ? evt : event;
  var x; var y; var width; var height;

  if (selectedObj) {
    G_Collection_lock = true;

    selectedObj.innerHTML = '<image src="Pics/ScrBar_moved.gif">';

    x = evt.clientX - offsetX;
    y = evt.clientY - offsetY;
    width = getObjectWidth(selectedObj);
    height = getObjectHeight(selectedObj);
    container_width = getObjectWidth(containerObj);
    container_height = getObjectHeight(containerObj);
    BarHeight = height;
    ContainerHeight = container_height;
    x = (x < 0) ? 0 : ((x + width > container_width) ? container_width - width : x);
    y = (y < 0) ? 0 : ((y + height > container_height) ? container_height - height : y);
    shiftTo(selectedObj, x, y);
    BarX = x;
    BarY = y;
    //----------------------------------
    var CollectionID = selectedObj.collectionID;

    if (latch == false) {
      //----------------------------------------------------------------------------------
      var AssocElement = document.getElementById('Assoc_' + G_ActiveAssocID);
      var collection_container = AssocElement.all[CollectionID + '_container'];

      if (collection_container != null) {
        i = 0 + 1; // first string is a header
        if (collection_container.children(i) != null) {
          while (collection_container.children(i)) {
            collection_container.children(i).className = 'Msg_Even';
            i++;
          }
        }
      }
      // -----------------------------------------------------------------------------------
      latch = true;
    }
    var collection = G_Assocs[G_ActiveAssocID].TreeView._collections[CollectionID];
    if (collection) { var msgs = G_Assocs[G_ActiveAssocID].TreeView._collections[CollectionID].obj; } else { var msgs = null; }

    if (msgs != null) {
      var factor = y / (container_height - height);
      var counter_value = msgs.Method0('M_GetCount');
      var new_first_message_element_number = Math.round(factor * (counter_value - CONST_MESSAGES_ON_PAGE));
      //------------------------------------------
      msgIndex = new_first_message_element_number;
    }
    //----------------------------------
    evt.cancelBubble = true;
    return false;
  }

  // return true;
  return false; // it forbids action by default
}
//------------------------------------------------------------------------------------------

function release(evt) {
  if (selectedObj) {
    var CollectionID = selectedObj.collectionID;
    var collection = G_Assocs[G_ActiveAssocID].TreeView._collections[CollectionID];
    if (collection) { var msgs = G_Assocs[G_ActiveAssocID].TreeView._collections[CollectionID].obj; } else { var msgs = null; }
    if ((msgs) && (msgIndex)) msgs.method1('M_SetFirstVisibleMessageByIndex', msgIndex);
    else msgs.method1('M_SetFirstVisibleMessageByIndex', 0);

    var CollectionID = selectedObj.collectionID;
    G_Assocs[G_ActiveAssocID].TreeView.redraw_collection(CollectionID);

    setZIndex(selectedObj, 0);
    document.body.releaseCapture();
    firstElement = null;
    selectedObj = null;
    latch = false;
    msgIndex = null;

    G_Collection_lock = false;
    //	G_ScrollButtonIsPressed = false;
  }
  G_ScrollButtonIsPressed = false;
}
//------------------------------------------------------------------------------------------

function initDrag() {
  document.onmousedown = engage;
  document.onmousemove = dragIt;
  document.onmouseup = release;
  document.onmousewheel = scrollIt;
  return;
}
//------------------------------------------------------------------------------------------
var wheel_lock = false;

function scrollIt(CollectionID) {
  //-----------------------------------
  if (wheel_lock == true) return false;
  //-----------------------------------
  var br = getCollectionMsgsBoundingRectangle(CollectionID); // Collection will be scrolled if mouse is above collection messages only
  var mousexy = coords(event);
  if ((mousexy[0] < br.left) || (mousexy[0] > (br.right + 16)) || (mousexy[1] < br.top) || (mousexy[1] > br.bottom)) {
    return false;
  }
  //-----------------------------------
  event.cancelBubble = false;

  if (!G_Assocs[G_ActiveAssocID]) return true;
  if (!G_Assocs[G_ActiveAssocID].TreeView._collections[CollectionID]) return true;
  if (G_Assocs[G_ActiveAssocID].TreeView._collections[CollectionID].obj) var collection_message_list = G_Assocs[G_ActiveAssocID].TreeView._collections[CollectionID].obj;
  else return true;

  wheel_lock = true;
  event.cancelBubble = true;

  var message_counter_value = collection_message_list.Method0('M_GetCount');
  var items_per_page = external.Method1('M_GetGlobalOption', 'ItemsPerPage');
  if (message_counter_value > items_per_page) {
    var collection_node = G_Assocs[G_ActiveAssocID].TreeView.root._children[CollectionID];
    var first_msg_index = collection_message_list.Method0('M_GetFirstVisibleMessageIndex');
    //----------------------------------------------------------------------------------------------------------------------------------------
    if ((event.wheelDelta > 0) && (first_msg_index > 0) && (collection_node._expanded == true)) { go_prev_message(CollectionID); wheel_lock = false; return false; } else if ((event.wheelDelta < 0) && (first_msg_index < message_counter_value - items_per_page) && (collection_node._expanded == true)) { go_next_message(CollectionID); wheel_lock = false; return false; }
    wheel_lock = false; return true;
    //----------------------------------------------------------------------------------------------------------------------------------------
  }
  wheel_lock = false; return true;
}

// ----------------------------------------------------------------------------------------
// defines states of scrollbar elements
// ----------------------------------------------------------------------------------------
function AutoRefreshScrollers(AssocID, CollectionID) {
  //----------------------------------------------------------------------------------------
  if (G_Collection_lock == true) return;
  //----------------------------------------------------------------------------------------
  if (G_Assocs[AssocID] == null) return;
  if (G_Assocs[AssocID].TreeView == null) return;
  if (G_Assocs[AssocID].TreeView._collections[CollectionID] == null) return;
  var msgs = G_Assocs[AssocID].TreeView._collections[CollectionID].obj;
  if (msgs == null) return;
  //----------------------------------------------------------------------------------------
  var msgs_count = msgs.Method0('M_GetCount');
  var msgs_per_page = external.Method1('M_GetGlobalOption', 'ItemsPerPage');
  //----------------------------------------------------------------------------------------
  var first_msg = msgs.GetFirst();
  var last_msg = msgs.GetLast();
  var first_msg_id = null;
  var last_msg_id = null;

  if ((first_msg != null) && (last_msg != null)) {
    first_msg_id = first_msg.objID;
    last_msg_id = last_msg.objID;
  } else return;
  //----------------------------------------------------------------------------------------
  var msg = msgs.Method0('M_GetFirstVisibleMessage');
  var firstVisibleMsgID = '';
  if (msg != null) firstVisibleMsgID = msg.objID;
  var lastVisibleMsgID = '';
  if (msg != null) lastVisibleMsgID = msg.objID;
  while (msg != null) {
    msg = msgs.Method1('M_GetNextVisibleMessage', msg);
    if (msg != null) { lastVisibleMsgID = msg.objID; }
  }
  //----------------------------------------------------------------------------------------
  var MsgScrollersExist = null;
  var prev_state = null;
  var next_state = null;

  if (msgs_per_page < msgs_count) {
    MsgScrollersExist = true;
    //---------------------------------------------------------
    if (first_msg_id == firstVisibleMsgID) prev_state = false;
    else prev_state = true;
    //---------------------------------------------------------
    if (last_msg_id == lastVisibleMsgID) next_state = false;
    else next_state = true;
    //---------------------------------------------------------
  } else {
    MsgScrollersExist = false;
    prev_state = false;
    next_state = false;
  }
  //----------------------------------------------------------------------------------------
  var assoc_element = document.getElementById('Assoc_' + AssocID);

  RefreshMsgScrollers(assoc_element, 'prev', prev_state, CollectionID, MsgScrollersExist);
  RefreshMsgScrollers(assoc_element, 'next', next_state, CollectionID, MsgScrollersExist);
}

function ChangeMessageIntoRemovedObject(message_tbody_element, CollectionID, MessageID, MsgEvenness) {
  message_tbody_element.id = MessageID;
  message_tbody_element.CollectionID = CollectionID;
  message_tbody_element.className = 'Msg_Removed';
  message_tbody_element.oncontextmenu = 'return;';

  for (i in message_tbody_element.children) {
    if (i.onclick) i.onclick = 'return;';
    if (i.onmouseleave) i.onmouseleave = 'return;';
    if (i.onmouseenter) i.onmouseenter = 'return;';
  }
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
// Wizard unit begin
//-----------------------------------------------------------------------------------------------------------------------------------------------
// Function is being used online context help

function ToDomainWithNewBrowser(Domain) {
  // var Domain = " https://offsitebox.com/terms.aspx";
  // var Domain = "http://offsitebox.com/";
  external.OpenURLInNewBrowser(Domain);
}
// --------------------------------------------------------------------------------
// To recalculate Position and Size of Wizard panel (used in ResizeWindow())
function GetPositionAndSizeOf(ElementID) {
  var offsetTrail = document.getElementById(ElementID); // alert('offsetTrail='+offsetTrail);
  var _width = 100; if (offsetTrail) _width = offsetTrail.offsetWidth;
  var _height = 100; if (offsetTrail) _height = offsetTrail.offsetHeight;
  var offsetLeft = 0;
  var offsetTop = 0;
  while (offsetTrail) {
    offsetLeft += offsetTrail.offsetLeft;
    offsetTop += offsetTrail.offsetTop;
    offsetTrail = offsetTrail.offsetParent;
  }
  return { left: offsetLeft, top: offsetTop, width: _width, height: _height };
}
//--------------------------------------------------------------------------------
document.onclick = DocumentOnClick;

function DocumentOnClick() {
  FolderTypeListOnCLick();
  WizardMenuOnCLick();
}

function FolderTypeListOnCLick() {
  if (Folder_Type_list_container) {
    if ((G_Folder_Type_List_Mouse_Status == false) && (Folder_Type_list_container.style.visibility == 'visible')) {
      window.setTimeout('CloseFolderTypeList()', 10);
    }
  }
}
//--------------------------------------------------------------------------------
function FolderTypeListEnter() {
  G_Folder_Type_List_Mouse_Status = true;
}
//--------------------------------------------------------------------------------
function FolderTypeListLeave() {
  G_Folder_Type_List_Mouse_Status = false;
}
// --------------------------------------------------------------------------------
function CloseFolderTypeList() {
  var element = document.getElementById('Folder_Type_list_container');
  if (element) element.style.visibility = 'hidden';
}
//--------------------------------------------------------------------------------
function WizardMenuOnCLick() {
  if ((G_Wizard_Mouse_Status == false) && (Wizard_container.style.visibility == 'visible') && (G_Wizard_Browser_Status == false)) {
    window.setTimeout('CloseWizardMenu()', 10);
  }
  G_Wizard_Browser_Status = false;
}
//--------------------------------------------------------------------------------
function WizardMenuEnter() {
  G_Wizard_Mouse_Status = true;
}
//--------------------------------------------------------------------------------
function WizardMenuLeave() {
  G_Wizard_Mouse_Status = false;
}
// --------------------------------------------------------------------------------
function CloseWizardMenu() {
  element = document.getElementById('Wizard_container');
  if (element) element.style.visibility = 'hidden';
}

function CreateWizardButtons(SyncTreeObjectID, FolderNum) {
  var HtmlElement = '<table width=100% style="border: solid black 0px;">' +
		'<tbody>' +
		'<tr>' +
		'<td colspan=\'3\'>' +
		'</td>' +
		'</tr>' +
		'<tr>' +

		'<td> ' +
		'</td>' +

		'<td width=1% nowrap> ';
  //-------------------------------------------------------------------------------------------------------
  var SyncTreeObject = external.ObjByID(SyncTreeObjectID);
  //-------------------------------------------------------------------------------------------------------
  var Button_Standard_Ok_Enabled = true;
  var Button_Standard_Cancel_Enabled = true;
  //----------------------------------------------
  if (document.getElementById('More' + SyncTreeObject.objID + FolderNum).Button_Standard_Ok_Enabled == false) Button_Standard_Ok_Enabled = false;
  if (document.getElementById('More' + SyncTreeObject.objID + FolderNum).Button_Standard_Cancel_Enabled == false) Button_Standard_Cancel_Enabled = false;

  // ------------ Standard Ok ------------------------------------------------------------------------------

  if (Button_Standard_Ok_Enabled) {
    HtmlElement += '<span title="' + external.LS('tooltip_FSP_Ok') +
			'" tabindex="200" type="submit" name="TreeOk' + FolderNum + '" id="TreeOk' + FolderNum + '" onclick="return ChangeSyncTreeFromWizard(' + FolderNum + ');"' +
			'onmouseenter=WizardButtonSelect(this) onmouseleave=WizardButtonUnselect(this) style="width:67px; height: 20px; ' +
			'font-size:11px; font-family:Arial; padding-top:3px; text-align: center; color:black; ' +
			'background:url(Pics/Folder_button.gif) background-position:top left; cursor:hand;">' + external.LS('button_ok') + '</span>';
  }

  // ------------ Standard Cancel --------------------------------------------------------------------------

  if (Button_Standard_Cancel_Enabled) {
    HtmlElement += '<span title="' + external.LS('tooltip_FSP_Cancel') +
			'" tabindex="201" name="TreeCancel' + FolderNum + '" id="TreeCancel' + FolderNum + '" onclick="WizardMenuLeave();"' +
			'onmouseenter=WizardButtonSelect(this) onmouseleave=WizardButtonUnselect(this) style="width:67px; height: 20px; ' +
			'font-size:11px; font-family:Arial; text-color: black; padding-top:3px; text-align: center; color:black; ' +
			'background:url(Pics/Folder_button.gif) background-position:top left; cursor:hand;">' + external.LS('button_cancel') + '</span>';
  }

  //-------------------------------------------------------------------------------------------------------

  HtmlElement += '</td>' +
		'</tr>' +
		'</tbody></table>';

  return HtmlElement;
}
// Wizard PathProperty types.
G_CheckBoxControl = 0;
G_InputControl = 1;
G_ListControl = 2;
// Additional types.
G_PasswordControl = 3;
G_PathControl = 4;
G_LinkControl = 5;

function CreateWizardItem(FolderNum, SyncTreeObjectID, WizardObj, WPObjID) {
  var ItemHTML = '';

  var WPropertyType = WizardObj.Method1('M_GetPropertyUIType', WPObjID);
  if ((WPropertyType == G_InputControl) ||
		(WPropertyType == G_CheckBoxControl) ||
		(WPropertyType == G_PasswordControl)) ItemHTML += CreateInputWizardItem(FolderNum, SyncTreeObjectID, G_CurrentWizard, WPObjID);
  else if (WPropertyType == G_ListControl) ItemHTML += CreateListWizardItem(FolderNum, SyncTreeObjectID, G_CurrentWizard, WPObjID);
  else if (WPropertyType == G_PathControl) ItemHTML += CreateInputWizardItem(FolderNum, SyncTreeObjectID, G_CurrentWizard, WPObjID);
  else if (WPropertyType == G_LinkControl) ItemHTML += CreateLinkWizardItem(FolderNum, SyncTreeObjectID, G_CurrentWizard, WPObjID);

  return ItemHTML;
}

var G_CurrentWizard = null;

function CreateWizardBody(FolderNum, SyncTreeObjectID) {
  var SyncTreeObject = external.ObjByID(SyncTreeObjectID);
  G_CurrentWizard = SyncTreeObject.Method0Own('M_GetWizard');
  var WPListObj = G_CurrentWizard.Method0Own('M_Properties');
  var WPObjID = WPListObj.Method0('M_GetFirstItem');
  //-------------------------------------------
  var WizardHTML = '<table width=100%><tbody>';
  while (WPObjID != null) {
    var WPropertyVisible = G_CurrentWizard.Method1('M_IsPropertyVisible', WPObjID);
    if (WPropertyVisible) WizardHTML += CreateWizardItem(FolderNum, SyncTreeObjectID, G_CurrentWizard, WPObjID);
    else WizardHTML += '';
    WPObjID = WPListObj.Method1ID('M_GetNextItem', WPObjID);

    // var WPropertyValue =  WizardObj.Method1( 'M_GetProperty',WPObjID); alert(WPropertyValue); //ok
    // var WPropertyType =  WizardObj.Method1( 'M_GetPropertyUIType',WPObjID); alert(WPropertyType); //ok
    // var WPropertyVisible =  WizardObj.Method1( 'M_IsPropertyVisible',WPObjID); alert(WPropertyVisible); //ok
    // var WPCaption =  WizardObj.Method1( 'M_CaptionProperty',WPObjID); alert(WPCaption); //ok
    // var WPDescription =  WizardObj.Method1( 'M_DescriptionProperty',WPObjID); alert(WPDescription); //ok
    // var WPInputRegExp =  WizardObj.Method1( 'M_GetPropertyInputRegExp',WPObjID); alert(WPInputRegExp); //ok
  }
  WizardHTML += '</tbody></table>';
  //-------------------------------------------

  return WizardHTML;
}


function CreateInputWizardItem(FolderNum, SyncTreeObjectID, WizardObj, WPObjID) {
  //-----------------------------------------------------------------------------------------------------------------
  // var SyncTreeObject = external.ObjByID(SyncTreeObjectID);
  // var WizardObj   = SyncTreeObject.Method0Own('M_GetWizard');
  //-----------------------------------------------------------------------------------------------------------------
  var WPropertyType = G_CurrentWizard.Method1('M_GetPropertyUIType', WPObjID);
  var WPropertyValue = G_CurrentWizard.Method1('M_GetProperty', WPObjID);
  var WPCaption = G_CurrentWizard.Method1('M_CaptionProperty', WPObjID);
  var WPDescription = G_CurrentWizard.Method1('M_DescriptionProperty', WPObjID);
  //-----------------------------------------------------------------------------------------------------------------
  var width = 'width:100%';
  if (WPropertyType == G_CheckBoxControl) width = '';
  // -----------------------------------------------------------------------------------------------------------------
  var corrected_property_value = '';
  var property_type = 'text';
  var ButtonHTML = '';
  var CheckBoxHTML = '';

  if (WPropertyType == G_InputControl) {
    corrected_property_value += 'value="' + WPropertyValue + '" ';
    property_type = 'text';
  } else if (WPropertyType == G_PasswordControl) {
    corrected_property_value += 'value="' + WPropertyValue + '" ';
    property_type = 'password';
    CheckBoxHTML +=
			'<table cellspacing=0 cellpading=0 style=\'border-collapse: collapse;\'>' +
			'<tbody>' +
			'<tr style=\'border:0px; padding:0px; border-collapse: collapse;\'>' +
			'<td style=\'border:0px; padding:0px; border-collapse: collapse; margin: 0px; padding: 0px;\'>';

    if (ApplicationName.innerText != "VH-sync 'n' Go" && ApplicationName.innerText == '') {
      CheckBoxHTML += '<input tabindex=102 ' +
				'id=\'PasswordCheckBox' + SyncTreeObjectID + WPObjID + '\' ' +
				'type=\'checkbox\' ' +
				'style=\'border: solid 1px black; background:#f6f6f6; font-family:tahoma; font-size:10pt;\' ' +
				'onclick=  \'' +
				// 'try {' +
				// 'event.cancelBubble = true;' +
				// 'var v1= "text"; ' +
				// 'var v2= "password"; ' +
				'var PasswordObj = document.getElementById("' + SyncTreeObjectID + WPObjID + '"); ' +
				'var value = PasswordObj.value; ' +
				'var Str = new String(PasswordObj.parentNode.innerHTML); ' +
				'if (PasswordObj.type == "password") {Str = Str.replace("password", "text");} ' +
				'if (PasswordObj.type == "text")     {Str = Str.replace("INPUT", "INPUT type=password "); } ' +
				'PasswordObj.parentNode.innerHTML = Str; ' +
				'PasswordObj = document.getElementById("' + SyncTreeObjectID + WPObjID + '"); ' +
				'if (PasswordObj.type == "text") {PasswordObj.value = value;} ' +
				'if (PasswordObj.type == "password") ; ' +
				// '}' +
				// 'catch(e) {' +
				// 'window.status = e.message; ' +
				// '}' +
				'\' ' +
				'nextElementID=\'' + SyncTreeObjectID + WPObjID + '\' ' +
				'>';
    }

    CheckBoxHTML += '</td>' +
			'<td width=100% ' +
			'style=\'font-family:tahoma; font-size:9pt; font-weight: 500; color: #ffffff; padding-left:10px;\' ' +
			'>';

    if (ApplicationName.innerText != "VH-sync 'n' Go" && ApplicationName.innerText == '') { CheckBoxHTML += '<span>' + external.LS('wizard_password_control') + '</span>'; }

    CheckBoxHTML += '</td>' +
			'</tr>' +
			'</tbody>' +
			'</table>';
  } else if (WPropertyType == G_CheckBoxControl) {
    if (WPropertyValue == 1) corrected_property_value += 'checked ';
    property_type = 'checkbox';
  } else if (WPropertyType == G_PathControl) {
    corrected_property_value += 'value="' + WPropertyValue + '" ';
    ButtonHTML +=
			'<table cellspacing=0 cellpading=0 style=\'border-collapse: collapse;\'>' +
			'<tbody>' +
			'<tr style=\'border:0px; padding:0px; border-collapse: collapse;\'>' +
			'<td style=\'border:0px; padding:0px; border-collapse: collapse;\'>' +
			'<img src=\'Pics/Folder_button_left.gif\' ' +
			'id=\'WizardBrowse' + SyncTreeObjectID + FolderNum + 'left\'>' +
			'</td>' +
			'<td style=\'border:0px; padding:0px; border-collapse: collapse; margin: 0px; padding: 0px;\'>' +

			'<span ' +
			'unselectable ' +
			'opened=\'off\' ' +
			'title=\'' + 'Open Browse Window' + '\' ' +
			'tabindex=2 ' +
			'id=\'WizardBrowse' + SyncTreeObjectID + FolderNum + '\' ' +
			'onClick=\' ' +
			//----------
			'ChangeSyncTreeFromWizard(' + FolderNum + '); ' +
			'G_Wizard_Browser_Status = true; ' +
			'var SyncTreeObject = external.ObjByID("' + SyncTreeObjectID + '"); ' +
			'WizardObj = SyncTreeObject.Method0Own("M_GetWizard"); ' +
			'var Path = WizardObj.Method1("M_PropertyHelper" ,"' + WPObjID + '");' +
			'if (Path != null) {' +
			'WizardObj.Method2("M_SetProperty", "' + WPObjID + '", Path); ' +
			'WizardObj.Method0("M_ApplyCharacteristics"); ' +
			'GetBackSyncBoard(' + FolderNum + '); ' +
			'} ' +
			'return; ' +
			'\' ' +
			//----------
			'onmouseenter=FolderButtonSelect(this) onmouseleave=FolderButtonUnselect(this) ' +
			'style="top:0px; width:67px; height: 22px; cursor:hand; padding-left:0px; padding-right:0px;' +
			'font-size:11px; font-family:Arial; padding-top:3px; text-align: center; color:black; ' +
			'background:url(Pics/Folder_button_center.gif) repeat-x center;"' +
			'> ' +
			external.LS('button_browse') +
			'</span>' +

			'</td>' +
			'<td style="border:0px; padding:0px; border-collapse: collapse; margin: 0px; padding: 0px;">' +
			'<img src=\'Pics/Folder_button_right.gif\'' +
			'id=\'WizardBrowse' + SyncTreeObjectID + FolderNum + 'right\'>' +
			'</td>' +
			'</tr>' +
			'</tbody>' +
			'</table>';
  }
  //-----------------------------------------------------------------------------------------------------------------
  var WPEventsHolders = '';
  if ((WPropertyType == G_InputControl) || (WPropertyType == G_PasswordControl)) {
    WPEventsHolders = 'onclick=\'OnInputItemClick(this)\' ' +
			'onkeydown=\'OnInputItemKeyDown(event, this, "' + SyncTreeObjectID + '", "' + WPObjID + '")\' ' +
			'onkeypress=\'OnInputItemKeyPressed(event, this, "' + SyncTreeObjectID + '", "' + WPObjID + '")\' ' +
			'onblur=\'OnInputItemBlur(this, "' + SyncTreeObjectID + '", "' + WPObjID + '")\' ';
  } else if (WPropertyType == G_CheckBoxControl) {
    // alert('G_CheckBoxControl');
    WPEventsHolders = // 'onclick=\'OnInputItemClick(this)\' ' +
			// 'onkeydown=\'OnInputItemKeyDown(event, this, "' + SyncTreeObjectID + '", "' + WPObjID + '")\' ' +
			// 'onkeypress=\'OnInputItemKeyPressed(event, this, "' + SyncTreeObjectID + '", "' + WPObjID + '")\' ' +
			// 'onblur=\'OnInputItemBlur(this, "' + SyncTreeObjectID + '", "' + WPObjID + '")\' ';
			'onclick=\'SaveChangesInWizard(G_Wizard_folder_num); GetBackWizardBoard(G_Wizard_folder_num);\' ';
    // 'onclick=\'alert(G_Wizard_folder_num);\' ';
  }
  //-----------------------------------------------------------------------------------------------------------------
  var ItemHTML = '<tr>' +
		'<td ' +
		'nowrap ' +
		'unselectable ' +
		' align=right ' +
		'width=1% ' +
		'style=\'font-family:tahoma; font-size:10pt; color: black; font-weight: bold;\' ' +
		'>' +
		WPCaption +
		'</td>' +
		'<td>' +
		'<input tabindex=102 ' +
		'id=\'' + SyncTreeObjectID + WPObjID + '\' ' +
		'type=\'' + property_type + '\' ' +
		corrected_property_value +
		'style=\'' + width + '; border: solid 1px black; background:#f6f6f6; font-family:tahoma; font-size:10pt;\' ' +
		'onkeyup=\'Ok_Activate(' + FolderNum + ')\' ' +
		'onactivate=\'Activate_form(' + FolderNum + ')\' ' +
		// 'onclick=\'OnInputItemClick(this)\' ' +
		// 'onkeydown=\'OnInputItemKeyDown(event, this, "' + SyncTreeObjectID + '", "' + WPObjID + '")\' ' +
		// 'onkeypress=\'OnInputItemKeyPressed(event, this, "' + SyncTreeObjectID + '", "' + WPObjID + '")\' ' +
		// 'onblur=\'OnInputItemBlur(this, "' + SyncTreeObjectID + '", "' + WPObjID + '")\' ' +
		'nextElementID=\'' + SyncTreeObjectID + WPObjID + '\' ' +
		WPEventsHolders +
		'>' +
		'</td>' +
		'</tr>' +
		'<tr>' +
		'<td>' +
		'</td>' +
		'<td>' +
		ButtonHTML +
		CheckBoxHTML +
		'</td>' +
		'</tr>' +
		'<tr>' +
		'<td colspan=2 ' +
		'width=100% ' +
		'style=\'font-family:tahoma; font-size:10pt; color: black; padding-left:15px;\' ' +
		'>' +
		WPDescription +
		'</td>' +
		'</tr>';
  //-----------------------------------------------------------------------------------------------------------------
  return ItemHTML;
}
// --------------------------------------------------------------------------------
//	For input/checkbox items in wizard panel
// --------------------------------------------------------------------------------
var CurrentInputItemID = '';
//--------------------------------------------------------------------------------
function user_set_input_type(input, type) {
  try {
    switch (type) {
    default:
    case 'text':
    {
      input.type = 'text';
      break;
    }
    case 'password':
    {
      input.type = 'password';
      break;
    }
    }
  } catch (e) {
    window.status = e.message;
  }
}

function isValidEmail(email) {
  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  return reg.test(email);
}

// --------------------------------------------------------------------------------
function OnInputItemClick(HtmlElement) {
  // alert(G_Wizard_folder_num);
  // SaveChangesInWizard(G_Wizard_folder_num);
  // GetBackWizardBoard(G_Wizard_folder_num);

  // HtmlElement.setActive();
  // HtmlElement.select();

  /*
	if(HtmlElement.id != CurrentInputItemID)
		{
		HtmlElement.setActive();
		HtmlElement.select();
		CurrentInputItemID = HtmlElement.id;
		}
	else
		{
		}

        */
}
// --------------------------------------------------------------------------------
function OnInputItemKeyDown(evt, HtmlElement, wizardHolderID, saveMethod) {
  // if (evt.keyCode == 13) SaveInputItemValue(HtmlElement, wizardHolderID,'M_Set'+saveMethod);
}

function OnInputItemKeyPressed(evt, HtmlElement, wizardHolderID, saveMethod) {
  if (evt.keyCode == 13) {
    // SaveInputItemValue(HtmlElement, wizardHolderID,'M_Set'+saveMethod);
    //-----------------------------------------------------------------------
    // if (HtmlElement.nextElementID)
    //	{
    //	var nextElement = document.getElementById(HtmlElement.nextElementID);
    //	nextElement.setActive();
    //	nextElement.select();
    //	}
    // return false;

    ChangeSyncTreeFromWizard(G_Wizard_folder_num);
    return false;
  } else if (evt.keyCode == 27) {
    // HtmlElement.value = wizardObj.Method0('M_Get'+saveMethod);
    return false;
  }
  return true;
}

function OnInputItemBlur(HtmlElement, wizardHolderID, saveMethod) {
  // alert(G_Wizard_folder_num);
  // SaveChangesInWizard(G_Wizard_folder_num);
  // GetBackWizardBoard(G_Wizard_folder_num);

  // SaveInputItemValue(HtmlElement, wizardHolderID, 'M_Set'+saveMethod);
  // var wizardHolder = external.ObjByID(wizardHolderID);
  // var wizardObj  = wizardHolder.Method0Own('M_GetWizard');
  // wizardObj.Method0('M_ApplyCharacteristics');
}

function SaveInputItemValue(HtmlElement, wizardHolderID, saveMethod) {
  // var wizardHolder = external.ObjByID(wizardHolderID);
  // var wizardObj  = wizardHolder.Method0Own('M_GetWizard');
  // wizardObj.Method1(saveMethod, HtmlElement.value);
  if (HtmlElement.nextElementID) {
    var nextElement = document.getElementById(HtmlElement.nextElementID);
    nextElement.setActive();
    nextElement.select();
  }
}

function CreateLinkWizardItem(FolderNum, SyncTreeObjectID, WizardObj, WPObjID) {
  //-----------------------------------------------------------------------------------------------------------------
  var WPropertyValue = G_CurrentWizard.Method1('M_GetProperty', WPObjID);
  var WPCaption = G_CurrentWizard.Method1('M_CaptionProperty', WPObjID);
  var WPDescription = G_CurrentWizard.Method1('M_DescriptionProperty', WPObjID);
  //-----------------------------------------------------------------------------------------------------------------
  var ItemHTML = '<tr>' +
		'<td ' +
		'nowrap ' +
		'unselectable ' +
		' align=right ' +
		'width=1% ' +
		'style=\'font-family:tahoma; font-size:10pt; color: black; font-weight: bold;\' ' +
		'>' +
		WPCaption +
		'</td>' +
		'<td>' +
		'<span ' +
		'unselectable ' +
		'opened=\'off\' ' +
		'title=\'' + WPCaption + ' ' + WPropertyValue + '\' ' +
		'tabindex=2 ' +
		'id=\'WizardLink' + SyncTreeObjectID + FolderNum + '\' ' +
		'onClick=\' ' +
		//----------
		'var SyncTreeObject = external.ObjByID("' + SyncTreeObjectID + '"); ' +
		'WizardObj = SyncTreeObject.Method0Own("M_GetWizard"); ' +
		'var Res = WizardObj.Method1("M_PropertyHelper" ,"' + WPObjID + '");' +
		'if (Res != null) { CloseWizardMenu(); }' +
		'return; ' +
		'\' ' +
		// ----------
		// 'style="top:0px; width:67px; height: 22px; cursor:hand; padding-left:0px; padding-right:0px;' +
		// 'font-size:10pt; font-family:tahoma; padding-top:0px; text-align: center; color:#0077CC;" '+
		'style="top:0px; width:100%; height: 1%; cursor:hand;  text-decoration: underline; font-weight: bold;' +
		'font-size:10pt; font-family:tahoma; padding-top:0px; text-align: left; color:#0077CC;" ' +
		'> ' +
		WPropertyValue +
		'</span>' +
		'</td>' +
		'</tr>' +
		'<tr>' +
		'<td colspan=2 ' +
		'width=100% ' +
		'style=\'font-family:tahoma; font-size:10pt; color: black; padding-left:15px;\' ' +
		'>' +
		WPDescription +
		'</td>' +
		'</tr>';
  //-----------------------------------------------------------------------------------------------------------------
  return ItemHTML;
}

function CreateListWizardItem(FolderNum, SyncTreeObjectID, WizardObj, WPObjID) {
  //-----------------------------------------------------------------------------------------------------------------
  var WPropertyValue = G_CurrentWizard.Method1('M_GetProperty', WPObjID);
  var WPCaption = G_CurrentWizard.Method1('M_CaptionProperty', WPObjID);
  var WPDescription = G_CurrentWizard.Method2('M_DescriptionForAvailableState', WPObjID, WPropertyValue);
  //-----------------------------------------------------------------------------------------------------------------

  var ListHTML = '<SELECT ' +
		'tabindex=1 ' +
		'style=\'border: 1px solid black; width:50%\' ' +
		'id=\'' + SyncTreeObjectID + WPObjID + '\' ' +
		'SyncTreeObjectID=\'' + SyncTreeObjectID + '\' ' +
		'WPObjID=\'' + WPObjID + '\' ' +
		'size=1 ' +
		'onClick=\'event.cancelBubble = true;\' ' +
		'onChange=\'OnWizardListSelectChange(this);\' ' +
		'onMouseDown=\'RefreshWizardList(this);\' ' +
		'onMouseEnter=\'RefreshWizardList(this);\' ' +
		' >';
  // -----------------------------------------------------------------
  var ListObject = WizardObj.Method1Own('M_GetAvailableStates', WPObjID);
  if (ListObject) {
    var ListElement = ListObject.GetFirst();
    var IsSelected = '';
    while (ListElement != null) {
      var sLetter = ListElement.ToString();
      // -----------------------
      if (WPropertyValue == sLetter) { IsSelected = 'SELECTED '; } else { IsSelected = ''; }
      //-----------------------

      ListHTML += '<option value=\'' + sLetter + '\' ' +
				IsSelected +
				'style=\' font-size:8px; background:white; color:#11100d;\'> ' +
				sLetter +
				'</option>';
      //-----------------------
      ListElement = ListObject.GetNext(ListElement);
      //-----------------------
    }
  } else {
    ListHTML += '<option value=\'' + sLetter + '\'' +
			' style=\'font-size:8px; background:white; color:#11100d;\'> ' +
			// external.LS('wizard_Compress_Level_Type_List_None_Tip')+
			'</option>';
  }
  //-----------------------------------------------------------------
  ListHTML += '</SELECT>';
  //* ****************************************************************
  var ItemHTML = '<tr>' +
		'<td ' +
		'nowrap ' +
		'width=1% ' +
		'align=right ' +
		'id=\'' + SyncTreeObjectID + WPObjID + 'Label\' ' +
		'unselectable ' +
		'class=\'wizardLabel\' ' +
		'style=\'font-family:tahoma; font-size:10pt; color: black; font-weight: bold;\' ' +
		'>' +
		WPCaption +
		'</td>' +
		'<td width=100% style= \'border: 0px solid black;\' >' +
		ListHTML +
		'</td>' +
		'</tr>' +
		'<tr>' +


		'<td ' +
		'id=\'' + SyncTreeObjectID + WPObjID + 'Description\' ' +
		'colspan=2 ' +
		'unselectable ' +
		'style=\'font-family:tahoma; font-size:10pt; color: black; padding-left:15px;\' ' +
		'style=\'visibility:inherit; display:inline;\' ' +
		'class=\'wizardDescription\' ' +
		'>' +
		'<span>' +
		WPDescription +
		'</span>' +
		'</td>' +
		'</tr>';
  //-----------------------------------------------------------------------------------------------------------------

  return ItemHTML;
}

function OnWizardListSelectChange(SelectObj) {
  var WPropertyValue = SelectObj.options[SelectObj.selectedIndex].value.toString();
  //------------------------------
  var WPDescription = G_CurrentWizard.Method2('M_DescriptionForAvailableState', SelectObj.WPObjID, WPropertyValue);
  var DescriptionObjectID = SelectObj.id + 'Description';
  var DescriptionObject = document.getElementById(DescriptionObjectID);
  //------------------------------
  var newTextNode = document.createTextNode(CorrectedString(WPDescription));
  if (DescriptionObject) DescriptionObject.replaceChild(newTextNode, DescriptionObject.firstChild);
  else alert('List Description Object is not found');
  // alert('OnWizardListSelectChange');
  SaveChangesInWizard(G_Wizard_folder_num);
  GetBackWizardBoard(G_Wizard_folder_num);
}

function CorrectedString(SourseString) {
  var SubStrings = SourseString.split(' ');
  var corrected_string = '';
  for (i = 0; i < SubStrings.length; i++) {
    if (SubStrings[i] != '' &&
			SubStrings[i] != null &&
			SubStrings[i] != String.fromCharCode(0) &&
			SubStrings[i] != String.fromCharCode(10) &&
			SubStrings[i] != String.fromCharCode(11) &&
			SubStrings[i] != String.fromCharCode(13)) corrected_string += SubStrings[i] + ' ';
  }
  return corrected_string;
}


function RefreshWizardList(SelectObj) {

}

function CancelSyncTreeFromWizard(FolderNum) {
  var SyncTree_elem = document.getElementById('Assoc_' + G_ActiveAssocID).all['SyncTree' + FolderNum];
  SyncTree_elem.className = 'Unactive_panel';
  GetBackWizardBoard(FolderNum);
}


function ChangeSyncTreeFromWizard(FolderNum) {
  ExtCloseHint(G_ActiveAssocID, 'Syncpath_hint_' + FolderNum);
  AssocElement = document.getElementById('Assoc_' + G_ActiveAssocID);
  SyncTree_elem = AssocElement.all['SyncTree' + FolderNum];
  SyncTreeObjectID = SyncTree_elem.synctree_id;
  SyncTree_elem.className = 'Unactive_panel';
  Form_elem = AssocElement.all['TreeForm' + FolderNum];
  // ---------------------------------------------------------------------
  SaveChangesInWizard(FolderNum);
  //---------------------------------------------------------------------
  G_CurrentWizard.Method0('M_ApplyCharacteristics');
  Form_elem.is_changed = 'false';
  // ---------------------------------------------------------------------
  G_Assocs[G_ActiveAssocID].OnAssocChangedCalled = false;
  var WizardPanelElement = document.getElementById('Wizard_container');
  if (WizardPanelElement) { WizardPanelElement.style.visibility = 'hidden'; }
  GetBackSyncBoard(FolderNum);
  // ---------------------------------------------------------------------
  return false;
}

function SaveChangesInWizard(FolderNum) // ok
{
  var WPListObj = G_CurrentWizard.Method0Own('M_Properties');
  var WPObjID = WPListObj.Method0('M_GetFirstItem');
  var SyncTreeObjectID = G_Wizard_Sync_Tree_Obj_ID;
  //-------------------------------------------
  while (WPObjID != null) {
    var WPropertyVisible = G_CurrentWizard.Method1('M_IsPropertyVisible', WPObjID);

    if (WPropertyVisible) {
      var WPropertyType = G_CurrentWizard.Method1('M_GetPropertyUIType', WPObjID);
      if ((WPropertyType == G_InputControl) ||
				(WPropertyType == G_PasswordControl)) {
        var property_html_obj = document.getElementById(SyncTreeObjectID + WPObjID);
        if (property_html_obj != null) {
          var property_value = property_html_obj.value;
          G_CurrentWizard.Method2('M_SetProperty', WPObjID, property_value);
        }
      } else if (WPropertyType == G_CheckBoxControl) {
        var property_html_obj = document.getElementById(SyncTreeObjectID + WPObjID);
        if (property_html_obj != null) {
          var property_value = document.getElementById(SyncTreeObjectID + WPObjID).checked;
          if (property_value == true) G_CurrentWizard.Method2('M_SetProperty', WPObjID, 1);
          else G_CurrentWizard.Method2('M_SetProperty', WPObjID, 0);
        }
      } else if (WPropertyType == G_ListControl) {
        var property_html_obj = document.getElementById(SyncTreeObjectID + WPObjID); // alert(property_html_obj);
        if (property_html_obj != null) {
          var property_value = property_html_obj.options[property_html_obj.selectedIndex].value.toString(); // alert(property_value);
          G_CurrentWizard.Method2('M_SetProperty', WPObjID, property_value);
        }
      } else if (WPropertyType == G_PathControl) {
        var property_html_obj = document.getElementById(SyncTreeObjectID + WPObjID);
        if (property_html_obj != null) {
          var property_value = property_html_obj.value;
          G_CurrentWizard.Method2('M_SetProperty', WPObjID, property_value);
        }
      }
    }
    WPObjID = WPListObj.Method1ID('M_GetNextItem', WPObjID);
  }
}

function GetBackWizardBoard(FolderNum) // ok
{
  var WPListObj = G_CurrentWizard.Method0Own('M_Properties');
  var WPObjID = WPListObj.Method0('M_GetFirstItem');
  var SyncTreeObjectID = G_Wizard_Sync_Tree_Obj_ID;
  //-------------------------------------------
  var WizardHTML = '<table width=100%><tbody>';
  while (WPObjID != null) {
    var WPropertyVisible = G_CurrentWizard.Method1('M_IsPropertyVisible', WPObjID);
    if (WPropertyVisible) WizardHTML += CreateWizardItem(FolderNum, SyncTreeObjectID, G_CurrentWizard, WPObjID);
    else WizardHTML += '';
    WPObjID = WPListObj.Method1ID('M_GetNextItem', WPObjID);
  }
  WizardHTML += '</tbody></table>';
  //-------------------------------------------

  Wizard_contents.innerHTML = WizardHTML;

  return false;
}
//  -------------------------------------------------------------------------
//  called on click of "Browse.../Configure..." button of sync folder panel
//  -------------------------------------------------------------------------
function ExtendSyncTreeInfo(WizardObj, FolderNum, SyncTreeObjectID) {
  G_Wizard_Mouse_Status = true;
  var SyncTreeObject = external.ObjByID(SyncTreeObjectID);
  var DeviceType = SyncTreeObject.Method0('M_GetDeviceType');

  if (DeviceType == PATH_TYPE__NONE ||
		DeviceType == PATH_TYPE_EMPTY) {
    var SyncTree_elem = document.getElementById('Assoc_' + G_ActiveAssocID).all['SyncTree' + FolderNum];
    var SyncTreeID = SyncTree_elem.synctree_id;
    SyncTree_elem.className = 'Unactive_panel';
    G_OnProfileChanged_called = false;
    external.Method1ID('M_BrowseButtonPressedForTree', SyncTreeID);
    if (G_OnProfileChanged_called == false) GetBackSyncBoard(FolderNum);
    return;
  }
  // ------------------------------------------------------------------------------------------------------------------
  if (FolderNum != G_Wizard_folder_num) { Wizard_container.style.visibility = 'hidden'; }
  // ------------------------------------------------------------------------------------------------------------------
  // Wizard Panel Size/Position Calculation
  WizardPanelRefresh(SyncTreeObjectID, FolderNum, false);
}
// ------------------------------------------------------------------------------------------------------------------
// Wizard Panel Refresh
function WizardPanelRefresh(SyncTreeObjectID, FolderNum, PanelIsFilled) {
  // ------------------------------------------------------------------------------------------------------------------
  // Wizard Panel Size/Position Calculation
  // ------------------------------------------------------------------------------------------------------------------
  var MainDivInfo = GetPositionAndSizeOf('Main_div');

  var WizardPanelInfo = GetPositionAndSizeOf('TreeForm' + SyncTreeObjectID + FolderNum);

  Wizard_container.style.top = WizardPanelInfo.top - 20;
  Wizard_container.style.left = WizardPanelInfo.left + 1;
  Wizard_container.style.height = WizardPanelInfo.height;
  Wizard_container.style.width = WizardPanelInfo.width + 400;
  //------------------------
  G_Wizard_folder_num = FolderNum;
  G_Wizard_Sync_Tree_Obj_ID = SyncTreeObjectID;
  //------------------------
  if (G_Wizard_folder_num > 1) Wizard_container.style.top = WizardPanelInfo.top;
  if (G_Wizard_folder_num > 0) Wizard_container.style.left = WizardPanelInfo.left - 399;
  //------------------------------------------------------------------------------------------------------------------
  // Fill and display sync folder wizard panel
  if (!PanelIsFilled) {
    Wizard_contents.innerHTML = CreateWizardBody(FolderNum, SyncTreeObjectID);
    Wizard_down_plate.innerHTML = CreateWizardButtons(SyncTreeObjectID, FolderNum);
    Wizard_up_plate.innerHTML = external.LS('wizard_Header');
    //------------------------
    Wizard_container.SyncTreeObjectID = SyncTreeObjectID;
    Wizard_container.FolderNum = FolderNum;
    Wizard_container.style.visibility = 'visible';
  }
}
// ------------------------------------------------------------------------------------------------------------------
// Folder Type List Panel Size/Position Calculation
function TypeListPanelRefresh(SyncTreeObjectID, FolderNum) {
  if (document.getElementById('TreeForm' + FolderNum)) {
    var WizardPanelInfo = GetPositionAndSizeOf('TreeForm' + SyncTreeObjectID + FolderNum);

    Folder_Type_list_container.style.height = parseInt(WizardPanelInfo.height);
    Folder_Type_list_container.style.width = 400;
    Folder_Type_list_container.style.top = parseInt(WizardPanelInfo.top) + 50;

    if (FolderNum > 0) {
      var MainDivInfo = GetPositionAndSizeOf('Main_div');
      Folder_Type_list_container.style.left = parseInt(MainDivInfo.width) - parseInt(Folder_Type_list_container.style.width) - 36;
      if (parseInt(WizardPanelInfo.left) < parseInt(Folder_Type_list_container.style.left)) Folder_Type_list_container.style.left = parseInt(WizardPanelInfo.left) + 1;
    } else {
      Folder_Type_list_container.style.left = parseInt(WizardPanelInfo.left) + 1;
    }
  }
}
//-------------------------------------------------------------------------------------------------------------------------
// INSTRUCTION : HOW TO ADD A NEW SYNCHRONIZATION FOLDER TYPE INTO GUI
//-------------------------------------------------------------------------------------------------------------------------
// To add a new synchronization type you need to
// 1. add global variable PATH_TYPE_new_type_name = PATH_TYPE_MAX_INDEX + 1;
// 2. change the value of the global variable PATH_TYPE_MAX_INDEX = PATH_TYPE_MAX_INDEX + 1;
// 3. add 'folder_Panel_new_type_name' and	'folder_Panel_des_new_type_name' localization strings
// 4. addfour a string into function G_WizardTypeInfoList_Init():
// G_WizardTypeInfoList[PATH_TYPE_new_type_name]={};
// add four strings into function 	G_WizardTypeInfoList_Refresh():
// G_WizardTypeInfoList[PATH_TYPE_new_type_name][Image_SRC] = 'Pics/Wizard_new_type_name.png';
// G_WizardTypeInfoList[PATH_TYPE_new_type_name][Button_Caption] = external.LS("button_browse");
// G_WizardTypeInfoList[PATH_TYPE_new_type_name][Folder_Type_Name] = external.LS('folder_Panel_new_type_name');
// G_WizardTypeInfoList[PATH_TYPE_new_type_name][Folder_Type_Description] = external.LS('folder_Panel_des_new_type_name');
// -------------------------------------------------------------------------------------------------------------------------
function G_WizardTypeInfoList_Refresh() {
  var Image_SRC = 0;
  var Button_Caption = 1;
  var Folder_Type_Name = 2;
  var Folder_Type_Description = 3;

  G_WizardTypeInfoList[PATH_TYPE__NONE][Image_SRC] = 'Pics/Wizard_No.png';
  G_WizardTypeInfoList[PATH_TYPE__NONE][Button_Caption] = external.LS('button_browse');
  G_WizardTypeInfoList[PATH_TYPE__NONE][Folder_Type_Name] = external.LS('device_0_name');
  G_WizardTypeInfoList[PATH_TYPE__NONE][Folder_Type_Description] = external.LS('device_0_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_EMPTY][Image_SRC] = 'Pics/Wizard_No.png';
  G_WizardTypeInfoList[PATH_TYPE_EMPTY][Button_Caption] = external.LS('button_browse');
  G_WizardTypeInfoList[PATH_TYPE_EMPTY][Folder_Type_Name] = external.LS('device_0_name');
  G_WizardTypeInfoList[PATH_TYPE_EMPTY][Folder_Type_Description] = external.LS('device_0_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_STARTUP_DRIVE][Image_SRC] = 'Pics/Wizard_Removable_Drive.png';
  G_WizardTypeInfoList[PATH_TYPE_STARTUP_DRIVE][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_STARTUP_DRIVE][Folder_Type_Name] = external.LS('device_0_name');
  G_WizardTypeInfoList[PATH_TYPE_STARTUP_DRIVE][Folder_Type_Description] = external.LS('device_0_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_WINDOWS_BASED_DRIVE][Image_SRC] = 'Pics/Wizard_Folder.png';
  G_WizardTypeInfoList[PATH_TYPE_WINDOWS_BASED_DRIVE][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_WINDOWS_BASED_DRIVE][Folder_Type_Name] = external.LS('device_0_name');
  G_WizardTypeInfoList[PATH_TYPE_WINDOWS_BASED_DRIVE][Folder_Type_Description] = external.LS('device_0_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_FTP][Image_SRC] = 'Pics/Wizard_Ftp_Server.png';
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_FTP][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_FTP][Folder_Type_Name] = external.LS('device_4_name');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_FTP][Folder_Type_Description] = external.LS('device_4_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_SFTP][Image_SRC] = 'Pics/Wizard_Sftp_Server.png';
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_SFTP][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_SFTP][Folder_Type_Name] = external.LS('device_5_name');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_SFTP][Folder_Type_Description] = external.LS('device_5_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_AMAZON_S3][Image_SRC] = 'Pics/Wizard_Amazon_S3.png';
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_AMAZON_S3][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_AMAZON_S3][Folder_Type_Name] = external.LS('device_6_name');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_AMAZON_S3][Folder_Type_Description] = external.LS('device_6_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_OFFSITE_BOX][Image_SRC] = 'Pics/Wizard_Offsite_Box.png';
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_OFFSITE_BOX][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_OFFSITE_BOX][Folder_Type_Name] = external.LS('device_7_name');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_OFFSITE_BOX][Folder_Type_Description] = external.LS('device_7_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_WEBDAV][Image_SRC] = 'Pics/Wizard_WebDAV.png';
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_WEBDAV][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_WEBDAV][Folder_Type_Name] = external.LS('device_8_name');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_WEBDAV][Folder_Type_Description] = external.LS('device_8_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_ACTIVESYNC][Image_SRC] = 'Pics/Wizard_ActiveSync.png';
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_ACTIVESYNC][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_ACTIVESYNC][Folder_Type_Name] = external.LS('device_9_name');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_ACTIVESYNC][Folder_Type_Description] = external.LS('device_9_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_LOCAL_ARCHIVE][Image_SRC] = 'Pics/Wizard_Local_Archive.png';
  G_WizardTypeInfoList[PATH_TYPE_LOCAL_ARCHIVE][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_LOCAL_ARCHIVE][Folder_Type_Name] = external.LS('device_10_name');
  G_WizardTypeInfoList[PATH_TYPE_LOCAL_ARCHIVE][Folder_Type_Description] = external.LS('device_10_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_GOOGLE_DOCS][Image_SRC] = 'Pics/Wizard_Google_Docs.png';
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_GOOGLE_DOCS][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_GOOGLE_DOCS][Folder_Type_Name] = external.LS('device_11_name');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_GOOGLE_DOCS][Folder_Type_Description] = external.LS('device_11_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_AZURE][Image_SRC] = 'Pics/Wizard_Windows_Azure.png';
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_AZURE][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_AZURE][Folder_Type_Name] = external.LS('device_12_name');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_AZURE][Folder_Type_Description] = external.LS('device_12_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_SKYDRIVE][Image_SRC] = 'Pics/Wizard_SkyDrive.png';
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_SKYDRIVE][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_SKYDRIVE][Folder_Type_Name] = external.LS('device_13_name');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_SKYDRIVE][Folder_Type_Description] = external.LS('device_13_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_IKIC][Image_SRC] = 'Pics/Wizard_IKIC.png';
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_IKIC][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_IKIC][Folder_Type_Name] = external.LS('device_14_name');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_IKIC][Folder_Type_Description] = external.LS('device_14_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_DROPBOX][Image_SRC] = 'Pics/Wizard_Dropbox.png';
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_DROPBOX][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_DROPBOX][Folder_Type_Name] = external.LS('device_15_name');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_DROPBOX][Folder_Type_Description] = external.LS('device_15_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_AMAZON_CD][Image_SRC] = 'Pics/Wizard_Amazon_Cloud_Drive.png';
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_AMAZON_CD][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_AMAZON_CD][Folder_Type_Name] = external.LS('device_16_name');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_AMAZON_CD][Folder_Type_Description] = external.LS('device_16_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_GOOGLE_CS][Image_SRC] = 'Pics/Wizard_Google_Cloud_Storage.png';
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_GOOGLE_CS][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_GOOGLE_CS][Folder_Type_Name] = external.LS('device_17_name');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_GOOGLE_CS][Folder_Type_Description] = external.LS('device_17_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_BOX_STORAGE][Image_SRC] = 'Pics/Wizard_Box.png';
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_BOX_STORAGE][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_BOX_STORAGE][Folder_Type_Name] = external.LS('device_18_name');
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_BOX_STORAGE][Folder_Type_Description] = external.LS('device_18_desc');
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_SYNC_GATEWAY][Image_SRC] = 'Pics/Wizard_SyncGateway.png';
  G_WizardTypeInfoList[PATH_TYPE_SYNC_GATEWAY][Button_Caption] = external.LS('button_configure');
  G_WizardTypeInfoList[PATH_TYPE_SYNC_GATEWAY][Folder_Type_Name] = external.LS('device_19_name');
  G_WizardTypeInfoList[PATH_TYPE_SYNC_GATEWAY][Folder_Type_Description] = external.LS('device_19_desc');
}

function G_WizardTypeInfoList_Init() {
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE__NONE] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_EMPTY] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_STARTUP_DRIVE] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_WINDOWS_BASED_DRIVE] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_FTP] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_SFTP] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_AMAZON_S3] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_OFFSITE_BOX] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_WEBDAV] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_ACTIVESYNC] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_LOCAL_ARCHIVE] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_GOOGLE_DOCS] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_AZURE] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_SKYDRIVE] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_IKIC] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_DROPBOX] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_AMAZON_CD] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_GOOGLE_CS] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_PROTOCOL_BOX_STORAGE] = {};
  // 	---------
  G_WizardTypeInfoList[PATH_TYPE_SYNC_GATEWAY] = {};
}
//* ***************************************************
// Functions list for Folder Type Panel
//* ***************************************************

// function TypeListShiftCorrection (ListShift, TypeNumber)
// function FirstTypeNumberForRow(ListShift, RowNumber, RowSize)

// function BuildListTable(ColumnQuantity, ListShift)
// function BuildListMapTable (ColumnQuantity, ListShift)
// function BuildListElementRow (ColumnQuantity, RowNumber, ListShift)
// function BuildListElement (Caption, Description, IconPath, TypeNumber)
// function OnFolderTypeListSelectChange (SelectObj, SyncTreeObjectID, FolderNum, SelectedFolderTypeNumber)

function OnFolderTypeListSelectChange(SelectObj, SyncTreeObjectID, FolderNum, SelectedFolderTypeNumber) {
  var SyncTreeObject = external.ObjByID(SyncTreeObjectID);
  if ((SelectedFolderTypeNumber >= 0) && (SelectedFolderTypeNumber <= PATH_TYPE_MAX_INDEX)) { SyncTreeObject.Method1('M_ChangeDeviceType', SelectedFolderTypeNumber); }
  // -------------------------------------------------------------------------
  GetBackSyncBoard(FolderNum);
}

function TypeIsEliminated(TypeNumber) {
  // ������ ��� �����������/���������� ��������� � ��������������:

  // local;ftp;sftp;dav;amazon_s3;allwaycloud;wm;zip,
  // google_drive;microsoft_asure;microsoft_onedrive;
  // ikeepincloud;dropbox;amazon_cloud_drive;google_cloud_storage;box;sg

  // included_devices & excluded_devices

  // HKLM\Software\SyncApp
  // HKLM\Software\wow6432Node\SyncApp

  var TypeIsSupported = external.Method1('M_IsDeviceSupported', TypeNumber); // alert (TypeNumber + ' - ' + TypeIsSupported);
  var TypeIsEliminated = true;
  if (TypeIsSupported == 1) { TypeIsEliminated = false; }
  if (TypeNumber > PATH_TYPE_MAX_INDEX) { TypeIsEliminated = false; }
  return TypeIsEliminated;
}

function TypeListShiftCorrection(ListShift, TypeNumber) {
  var CORRECTION = 0;

  for (i = ListShift; i < TypeNumber; i++) {
    if (TypeIsEliminated(i) == true) CORRECTION++;
  }

  return CORRECTION;
}

function FirstTypeNumberForRow(ListShift, RowNumber, RowSize) {
  var TypeNumber = ListShift;
  var QuantityOfTypesAlreadyDisplayed = RowNumber * RowSize;
  var Counter = 0;

  for (i = ListShift; (i <= PATH_TYPE_MAX_INDEX) && (Counter < QuantityOfTypesAlreadyDisplayed); i++) {
    if (TypeIsEliminated(i) == false) Counter++;
  }

  if (i <= PATH_TYPE_MAX_INDEX) TypeNumber = i;

  return TypeNumber;
}

function BuildListElement(Caption, Description, IconPath, TypeNumber) {
  //------------------------------------------------------------------------------------------------------
  var Visibility = '';
  var SelectedElementBackgroundColor = '#E4E4D7';

  if (TypeNumber > PATH_TYPE_MAX_INDEX || (TypeIsEliminated(TypeNumber) == true)) {
    Visibility = 'display:none;';
    /*
	Caption = external.LS('folder_type_List');
	Caption = Caption.replace(/\'/g, '');
	Caption = Caption.replace(/\"/g, '');
	Description = external.LS('folder_type_List_des');
	Description = Description.replace(/\'/g, '');
	Description = Description.replace(/\"/g, '');
	*/
    Caption = '';
    Description = '';
    IconPath = 'Pics/Wizard_Folder.png';
    SelectedElementBackgroundColor = 'transparent';
  }
  //------------------------------------------------------------------------------------------------------
  var listElementStyle = 'style = "background-color:transparent;" ';

  var listElementAttributes = 'width = "64px"  align = "center" rowspan = "1" UNSELECTABLE = "on" ';

  var listElementOnMouseOver = 'onmouseover = "this.style.backgroundColor=\'' + SelectedElementBackgroundColor +
		'\'; this.style.color=\'white\'; this.style.borderStyle=\'none\'; ' +
		'folder_Panel_Current_Type.innerHTML = \'' + Caption + '\'; ' +
		'folder_Panel_des_Current_Type.innerHTML = \'' + Description + '\';" ';

  var listElementOnMouseOut = 'onmouseout  = "this.style.backgroundColor=\'transparent\'; this.style.color=\'black\'; ' +
		'folder_Panel_Current_Type.innerHTML = external.LS(\'folder_type_List\'); ' +
		'folder_Panel_des_Current_Type.innerHTML = Folder_Type_list_down_plate.innerHTML;" ';

  var listElementOnClick = 'onclick	  = "var Tag_ID =\'Folder_Type\'+ Folder_Type_list_container.SyncTreeObjectID + Folder_Type_list_container.FolderNum; ' +
		'var Tag_Object = document.getElementById(Tag_ID); ' +
		'if (Tag_Object != null) {Tag_Object.value =\'' + Caption + '\';} ' +
		'Folder_Type_list_container.style.visibility = \'hidden\'; ' +
		'OnFolderTypeListSelectChange (this, Folder_Type_list_container.SyncTreeObjectID, Folder_Type_list_container.FolderNum, ' + TypeNumber + ');" ';
  if ((TypeNumber > PATH_TYPE_MAX_INDEX) || (TypeIsEliminated(TypeNumber) == true)) listElementOnClick = '';

  var TypeIconStyle = 'style = "width:32px; height:32px; display:inline-block; position:relative; left:5px; top:0px; ' +
		'filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + IconPath + '\', sizingMethod=\'scale\'); ' + Visibility + '" ';

  var TypeIconAttributes = 'UNSELECTABLE = "on" ';
  //------------------------------------------------------------------------------------------------------
  var listElementHTML = '<td ' + listElementStyle + listElementAttributes + listElementOnMouseOver + listElementOnMouseOut + listElementOnClick + ' >';
  listElementHTML += '<span ' + TypeIconStyle + TypeIconAttributes + ' >' + '</span>';
  listElementHTML += '</td>';
  //------------------------------------------------------------------------------------------------------
  return listElementHTML;
}


function BuildListElementRow(ColumnQuantity, RowNumber, ListShift) {
  //------------------------------------------------------------------------------------------------------
  var IconPath = '';
  var Caption = '';
  var Description = '';
  var TypeNumber = FirstTypeNumberForRow(ListShift, RowNumber, ColumnQuantity);
  //------------------------------------------------------------------------------------------------------
  var listElementsRowStyle = 'style = "background-color:transparent;" ';
  var listElementsRowAttributes = 'height = "64px" UNSELECTABLE = "on" ';
  //------------------------------------------------------------------------------------------------------
  var listElementsRowHTML = '<tr ' + listElementsRowStyle + listElementsRowAttributes + ' >';
  for (var i = 0; i < ColumnQuantity; i++) {
    while (TypeIsEliminated(TypeNumber) == true) TypeNumber++;
    if (TypeNumber <= PATH_TYPE_MAX_INDEX) {
      IconPath = G_WizardTypeInfoList[TypeNumber][0];
      Caption = G_WizardTypeInfoList[TypeNumber][2];
      Caption = Caption.replace(/\'/g, '');
      Caption = Caption.replace(/\"/g, '');
      Description = G_WizardTypeInfoList[TypeNumber][3];
      Description = Description.replace(/\'/g, '');
      Description = Description.replace(/\"/g, '');
    }
    listElementsRowHTML += BuildListElement(Caption, Description, IconPath, TypeNumber);
    TypeNumber++;
  }
  listElementsRowHTML += '</tr>';
  //------------------------------------------------------------------------------------------------------
  return listElementsRowHTML;
}


function BuildListMapTable(ColumnQuantity, ListShift) {
  var Correction = TypeListShiftCorrection(ListShift, PATH_TYPE_MAX_INDEX + 1);
  //------------------------------------------------------------------------------------------------------
  var RowNumber = 0;
  var MissedIndexsNumber = Correction;
  var RowQuantity = ((PATH_TYPE_MAX_INDEX + 1 - ListShift - MissedIndexsNumber) / ColumnQuantity);
  if (RowQuantity > parseInt((PATH_TYPE_MAX_INDEX + 1 - ListShift - MissedIndexsNumber) / ColumnQuantity)) { RowQuantity = parseInt((PATH_TYPE_MAX_INDEX + 1 - ListShift - MissedIndexsNumber) / ColumnQuantity) + 1; }
  //------------------------------------------------------------------------------------------------------
  var listMapTableStyle = 'style = "background-color:transparent; cursor:pointer; border-bottom:1 #808080 solid; ' +
		'border-top:1 #808080 solid; color: black; font-family:Arial; font-size:12px;" ';
  var listMapTableAttributes = 'width = "400px" UNSELECTABLE = "on" ';
  //------------------------------------------------------------------------------------------------------
  var listMapHTML = '<table id="Folder_Type_list_map_table" ' + listMapTableStyle + listMapTableAttributes + ' ><tbody>';
  for (var i = 0; i < RowQuantity; i++) {
    listMapHTML += BuildListElementRow(ColumnQuantity, RowNumber, ListShift);
    RowNumber++;
  }
  listMapHTML += '</tbody></table>';
  //------------------------------------------------------------------------------------------------------
  return listMapHTML;
}

function BuildListTable(ColumnQuantity, ListShift) {
  //------------------------------------------------------------------------------------------------------
  var listTableStyle = 'style = "cursor:pointer; border:0 #0000A0 solid; background-image:url(\'Pics/CMP_mid.gif\'); ' +
		'background-repeat:repeat; background-position:center bottom;" ';
  var listTableAttributes = 'cellspacing = "0" cellpadding = "0" width = "100%" UNSELECTABLE = "on" ';
  //------------------------------------------------------------------------------------------------------
  var listHTML = '<table id="Folder_Type_list_table" ' + listTableStyle + listTableAttributes + '><tbody>';
  listHTML += '<tr UNSELECTABLE = "on"><td UNSELECTABLE = "on">';
  listHTML += BuildListMapTable(ColumnQuantity, ListShift);
  listHTML += '</td></tr>';
  listHTML += '</tbody></table>';
  //------------------------------------------------------------------------------------------------------
  return listHTML;
}

function CreateJobNameList(ProfileID) {
  var Profile = external.Method0Own('M_GetProfile');
  if (ProfileID != Profile.objID) return '';

  var ProfileID = Profile.objID;
  var ActiveAssocObj = external.Method0('M_GetSelectedAssoc');

  var ListHTML = '<SELECT ' +
		'tabindex=1 ' +
		'style=\'border: 1px solid black; height:26px; width:200px; background:transparent;\' ' +
		'id=\'' + ProfileID + '_JobNameList' + '\' ' +
		'size=1 ' +
		// 'onClick=\'event.cancelBubble = true;\' '+
		'onChange=\'OnJobNameListSelectChange(this);\' ' +
		// 'onMouseDown=\'RefreshJobNameList("' + ProfileID + '");\' ' +
		// 'onMouseEnter=\'RefreshJobNameList("' + ProfileID + '");\' '+
		' >';
  //---------------------------------------------------
  if (Profile != null) {
    var IsSelected = '';

    var AssocObj = Profile.GetFirst();
    while (AssocObj != null) {
      //-------------------------------------------
      ListItemValue = AssocObj.Method0('M_GetAssocName');
      // -----------------------
      if (AssocObj.objID == G_ActiveAssocID) { IsSelected = 'SELECTED '; } else { IsSelected = ''; }
      //-----------------------
      if (ActiveAssocObj) {
        if (AssocObj.objID == ActiveAssocObj.objID) { IsSelected = 'SELECTED '; } else { IsSelected = ''; }
      }
      // -----------------------
      ListHTML += '<option value=\'' + AssocObj.objID + '\' ' +
				IsSelected +
        'style=\'width:400px; font-size:8px; background:white; color:#11100d; background:#c0c0b4\'> ' +
        ListItemValue +
				'</option>';
      // -------------------------------------------
      AssocObj = Profile.GetNext(AssocObj);
    }
  }
  //---------------------------------------------------
  ListHTML += '</SELECT>';

  return ListHTML;
}

function OnJobNameListSelectChange(SelectObj) {
  var NewActiveAssocID = SelectObj.options[SelectObj.selectedIndex].value.toString();
  DeactivateAssoc(G_ActiveAssocID);
  external.Method1('M_SelectAssoc', external.ObjByID(NewActiveAssocID));
  ActivateAssoc(NewActiveAssocID);
}

function RefreshJobNameList(ProfileID) {
  var Profile = external.Method0Own('M_GetProfile');
  if (Profile) {
    var JobNameListContainerObj = document.getElementById('JobNameListContainer');

    if (ProfileID == Profile.objID) { JobNameListContainerObj.innerHTML = CreateJobNameList(Profile.objID); } else JobNameListContainerObj.innerHTML = '';
  } else alert('Profile is NULL');
}

function getEventLogRecordClass(nSeverity) {
	return nSeverity >= 7000 ? "event-icon icon-e" :
		nSeverity >= 5000 ? "event-icon icon-w" : "event-icon";
}

function createEventLogRec(tbl, nSeverity, sTime, sMsg) {
	if (tbl) {
		var row = tbl.insertRow(0);
		var c1 = row.insertCell(-1);	c1.innerHTML = '<span>[' + sTime + ']</span>';
		var c2 = row.insertCell(-1);	c2.innerHTML = '<i class="' + getEventLogRecordClass(nSeverity) + '"></i>';
		var c3 = row.insertCell(-1);	c3.innerHTML = sMsg;
	}
}

function GetEventLogTable() {
	return document.getElementById('event-log-tbl');
}

function FillEventLog() {
	var tbl = GetEventLogTable();
	if (!tbl)
		return;

	var pMsgs = external.Method0Own('M_GetEventLogMsgs');
	if (!pMsgs)
		return;

	var pMsg = pMsgs.GetFirst();
	while (pMsg) {
		createEventLogRec(tbl, 
			pMsg.Method0('M_GetSeverity'),
			pMsg.Method0('M_GetTimeStamp'),
			pMsg.Method0('M_GetMessageText'));
		pMsg = pMsgs.GetNext(pMsg);
	}
}

function OnAddEventLogMsg(nSeverity, sTime, sMsg) {
	createEventLogRec(GetEventLogTable(), nSeverity, sTime, sMsg);
}

function OnRemoveEventLogMsg(nCount) {
	var tbl = GetEventLogTable();
	if (!tbl)
		return;

	var nLen = tbl.rows.length;
	if (nLen)
		for (var i=nLen-1; i>=nCount; i--)
			tbl.deleteRow(i);
}

function ExtOnEventLogChanged(nState) {
	var el = document.getElementById('Main_Table');
	el.className = nState ? "" : "event-log-hidden";
}

function OnJobRenamed(jobID) {
	var pAssoc = external.ObjByID(jobID);
	if (pAssoc) {
		TabsLabels.cells['Label_' + jobID].all.TabCaptionText.innerText = pAssoc.Method0('M_GetAssocName');
		var pProfile = external.Method0Own('M_GetProfile');
		if (pProfile)
			RefreshJobNameList(pProfile.objID);
	}
}

function ClientGate(csRequest) {}
function OnJobGroupStatusChanged(groupID, status) {}
function OnNewJobCreated(jobID) { ExtOnProfileChanged(); }
function OnJobDeleted(jobID) { ExtOnProfileChanged(); }
function OnJobsReordered() { ExtOnProfileChanged(); }
