home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 June / comonline0602.iso / software / cogitum / cociter.exe / CogitumH.___ / HTML / COGTRACKER.JS < prev    next >
Encoding:
Text File  |  2001-08-08  |  81.5 KB  |  3,169 lines

  1.  
  2. var ctfFailure    =  0;
  3. var ctfReloaded    = -1;
  4. var ctfSuccess    =  1;
  5.  
  6.  
  7. var goBase = null;
  8. var goTreeXSL = null;
  9. var goListXSL = null;
  10. var gsDefPath = "C:\\Co-Citer.c-c";
  11. var gsCurrentPath = "";
  12.  
  13. //var imgEdit = null;
  14. //var imgFragmentExpand = null;
  15. //var imgFramentDelete = null;
  16.  
  17. var goCurrentFolderUIN = -1;
  18. var gnSortBy = -1;
  19. var gnSortDirection = -1;
  20. var gbFilterByFolder = true;
  21. var goVisibilityOptions = null;
  22.  
  23. //var arButtonSortNames = new Array("ctsName", "ctsDate", "ctsText", "ctsComment", "ctsURL");
  24. var arAttributeNames = new Array("@Name", "@CreationDate", "@Text", "@Comment", "@BaseURL");
  25. //var arButtonDirNames = new Array( "ctsAscending", "ctsDescending");
  26. var arDirectionSigns = new Array( "+", "-");
  27.  
  28. L_Cogitum_Citates = " - Cogitum Co-Citer";
  29.  
  30. L_Unable_To_Create = "Script was unable to initialize XML control.";
  31. L_Failed_To_Load_File = "Failed to load file.";
  32. L_Confirm_Fragment_Deletion = "Are you sure that you want to delete this citation?";
  33. L_Confirm_Multiple_Fragments_Deletion = "Are you sure that you want to delete selected citations?";
  34. L_Confirm_Folder_Deletion = "Are you sure that you want to delete this folder?\n\nThis will also delete all citations residing in it.";
  35. L_Undetermined_Sort = "Undetermined sort criteria.";
  36. L_Fragment_Not_Found = "Citation not found.";
  37. L_Folder_Not_Found = "Folder not found.";
  38. L_Dont_Delete_Root    = "Root folder cannot be deleted.";
  39. L_Dont_Delete_Unsorted    = "This is a system folder, which means that it cannot be deleted.";
  40. L_NODE_ALREADY_EXISTS    = "Folder with the same name already exists.\n\nPlease select another name.";
  41. L_Database_Cannot_Be_Moved = "Currently selected folder is the root folder of the database.\n\nIt cannot be moved.";
  42. L_SystemFolder_Cannot_Be_Moved = "Currently selected folder is a system folder, which means that it cannot be moved.";
  43.  
  44. L_Outside_Modification = "The file has been modified by another program.\nIt will be reloaded.";
  45. L_NO_FRAGMENTS_HTML    = "<DIV Class='NoCitates'> There are no citations in this folder.</DIV>";
  46. L_LOADING_HTML = "<DIV Class='NoCitates'> Loading. Please wait...</DIV>";
  47.  
  48. L_Failed_To_Lock_File = "Failed to lock the file.";
  49. L_FAILED_TO_ADD_NODE = "Failed to add folder to database";
  50.  
  51. L_FailedToGenerateTempFile = "Failed to create temporary file.";
  52.  
  53. L_Transform_Failed = "Transform failed.\n\nLooks like something is wrong.";
  54. L_Unable_To_Save_A_File = "Failed to write to a file:\n";
  55. L_HTML_FAIL_DIAG = "\n\nEither a file could not be created or text cannot be saved in it.";
  56.  
  57. L_NOTHING_TO_EXPORT = "No exportable fields are visible.\n\nTurn one of them on and try again.";
  58. L_NOTHING_TO_EXPORT_TO_HTML = "There are no citations to export.\n\nNeither current folder, nor its subfolders contain citations.";
  59.  
  60. L_OP_FAILED = "Operation failed with the following error:\n\n";
  61. L_BUSY = "Program is busy servicing a dialog.\n\nClose dialogs you opened and try again.";
  62.  
  63.  
  64. /*
  65. function fnInitialize() {
  66.  
  67.     try {
  68.         var qq = new String(cxbiRoot);
  69.     }
  70.     catch (err) {
  71.         alert(">" + err + "<" );
  72.         //if (err == "[object Error]") {
  73.             if (confirm("Reload?")) {
  74.                 window.location.reload();
  75.                 return;
  76.                 
  77.             }
  78.         //};
  79.     };
  80.  
  81.         fnLoadFile();
  82. };
  83. */
  84.  
  85. function fnCreateXMLctl() {
  86.     var someBase = null;
  87.     
  88.     try {
  89.         someBase = new ActiveXObject("Microsoft.XMLDOM");
  90.     }
  91.     catch (err) {
  92.         someBase = null;
  93.     };
  94.     if (someBase == null) {
  95.         return null;
  96.     };
  97.     someBase.async = false;
  98.     return someBase;
  99. };
  100.  
  101. function fnLoadFile(sPath, bDoNotAddToRecentFilesList) {
  102.         var ctlTree = fnGetTreeHolder();
  103.         var ctlCitates = fnGetCitatesHolder();
  104.  
  105.     if (goVisibilityOptions == null) {
  106.         goVisibilityOptions = new Object();
  107.                 goVisibilityOptions.bShowFieldNames = ! fnGetSetting(ccsVHideFieldNames , 0, true);
  108.         goVisibilityOptions.bShowTitle    = fnGetSetting(ccsVShowTitle , 0, true);
  109.         goVisibilityOptions.bShowDate    = fnGetSetting(ccsVShowDate , 0, true);
  110.         goVisibilityOptions.bShowText    = fnGetSetting(ccsVShowText , 0, true);
  111.         goVisibilityOptions.bShowComment= fnGetSetting(ccsVShowComment , 0, true);
  112.         goVisibilityOptions.bShowURL    = fnGetSetting(ccsVShowURL , 0, true);
  113.  
  114.         if (     ( ! goVisibilityOptions.bShowTitle ) &&
  115.             ( ! goVisibilityOptions.bShowDate ) &&
  116.             ( ! goVisibilityOptions.bShowText ) &&
  117.             ( ! goVisibilityOptions.bShowComment ) &&
  118.             ( ! goVisibilityOptions.bShowURL ) ) {
  119.         
  120.             goVisibilityOptions.bShowTitle = 
  121.             goVisibilityOptions.bShowDate = 
  122.             goVisibilityOptions.bShowText = 
  123.             goVisibilityOptions.bShowComment = 
  124.             goVisibilityOptions.bShowURL =  true;
  125.                 };
  126.     };
  127.     
  128.     if (goBase == null) {
  129.         goBase = fnCreateXMLctl();
  130.         goBase.loadXML("");
  131.     }
  132.     else {
  133.         goBase.loadXML("");
  134.     };
  135.  
  136.     ctlTree.innerHTML = ""; 
  137.     ctlCitates.innerHTML = "";
  138.  
  139.     if (goBase == null) {
  140.         alert(L_Unable_To_Create);
  141.         return;
  142.     };
  143.  
  144.     if (sPath == null) {
  145.         sPath = gsDefPath;
  146.     };
  147.  
  148.     gsCurrentPath = sPath;
  149.  
  150. try {
  151.     fnGetHelperObject().LockFile(sPath);
  152. }
  153. catch (err) {
  154.     alert(L_Failed_To_Lock_File);
  155.     return;
  156. };
  157.  
  158. try {    
  159.  
  160.     
  161.     if ( ! fnCheckedInitializeFile(goBase, sPath) ) {
  162.         throw (L_Failed_To_Load_File);
  163.     };
  164.     
  165.     if ( ! fnCheckVersion(goBase) ) {
  166.         if ( ! fnConfirmConversion(goBase) ) {
  167.             throw "";
  168.         }
  169.         else {
  170.             if ( ! fnPerformConversion(goBase) ) {
  171.                 throw "";
  172.             };
  173.         };
  174.     };
  175.  
  176.     if (bDoNotAddToRecentFilesList == null)
  177.         bDoNotAddToRecentFilesList = false;
  178.             
  179.     if ( ! bDoNotAddToRecentFilesList ) {
  180.             fnSetSetting(ccsStLastFile, sPath);
  181.  
  182.         fnAddHistorySetting(ccsStPreviousFile, sPath);
  183.     };
  184.  
  185.  
  186.     //Ensure that all CogTracker:ctNODE have their UINs
  187.     var oNodesList = goBase.selectNodes("/root/CogTracker:ctDATABASE|//CogTracker:ctNODE|//CogTracker:ctFRAGMENT");
  188.     for (i = 0; i < oNodesList.length; i++) {
  189.         fnGetElementUIN(goBase, oNodesList.item(i));
  190.     };
  191.     
  192.     if (goTreeXSL == null) {
  193.         goTreeXSL = fnCreateXMLctl();
  194.         if (goTreeXSL == null) {
  195.             throw(L_Unable_To_Create);
  196.         };
  197.         
  198.         //goTreeXSL.load("ctTree.xsl");
  199.         goTreeXSL.load(top.document.frames.ctToolBars.document.all.ctTree.XMLDocument);
  200.  
  201.     }        
  202.  
  203.     if (goListXSL == null) {
  204.         goListXSL = fnCreateXMLctl();
  205.         if (goListXSL == null) {
  206.             throw(L_Unable_To_Create);
  207.         };
  208.         
  209.         //goListXSL.load("ctList.xsl");
  210.                 goListXSL.load(top.document.frames.ctToolBars.document.all.ctList.XMLDocument);
  211.     }        
  212.  
  213.  
  214.  
  215.     var ctDATABASE = goBase.selectSingleNode("/root/CogTracker:ctDATABASE");
  216.     
  217.         if (goCurrentFolderUIN == -1) {
  218.             goCurrentFolderUIN = parseInt(ctDATABASE.getAttribute(cxbiAttCurrentNode));
  219.             if (isNaN(goCurrentFolderUIN)) {
  220.                 goCurrentFolderUIN = ctDATABASE.getAttribute(cxbiAttUIN);
  221.                 ctDATABASE.setAttribute(cxbiAttCurrentNode, goCurrentFolderUIN);
  222.             };
  223.         }
  224.         else {
  225.             ctDATABASE.setAttribute(cxbiAttCurrentNode, goCurrentFolderUIN);
  226.         };
  227.         var ctCurFolder = goBase.selectSingleNode("//*[@UIN='" + goCurrentFolderUIN + "']");
  228.         if (ctCurFolder == null) {
  229.         goCurrentFolderUIN = ctDATABASE.getAttribute(cxbiAttUIN);
  230.             ctDATABASE.setAttribute(cxbiAttCurrentNode, goCurrentFolderUIN);
  231.  
  232.         };
  233.  
  234.     var szHTML = goBase.transformNode(goTreeXSL);
  235.     if (szHTML == null || szHTML == "") {
  236.         throw(L_Transform_Failed);
  237.     };
  238.     
  239.     
  240.     //ctlTree.insertAdjacentHTML("afterBegin", szHTML);
  241.     ctlTree.innerHTML = szHTML;     
  242.     //ctlTree.insertAdjacentHTML("afterBegin","<OPTION>");
  243.  
  244.         var sTitle = "";
  245.     if (sPath != null && sPath != "") {
  246.         sTitle = fnGetHelperObject().AbbreviateFileName(sPath);
  247.     };
  248.  
  249.     if (sTitle != null && sTitle != "") {
  250.         document.title = sTitle + L_Cogitum_Citates;
  251.     }
  252.     else {
  253.         document.title = L_Cogitum_Citates;
  254.     };
  255.  
  256.         fnSortBy(-1, -1, //arButtonSortNames[gnSortBy], gnSortDirection, 
  257.                 false);
  258.  
  259.     
  260.         // no call here -- the event will be fired after tree initialization
  261.     //OnFolderChanged();
  262.  
  263.     fnGetHelperObject().UnlockFile(sPath);
  264. }
  265. catch(err) {
  266.     fnGetHelperObject().UnlockFile(sPath);
  267.  
  268.     if (err != null && err != "") {
  269.         if (err.description != null) {
  270.             alert(L_OP_FAILED + err.description);
  271.         }
  272.         else {
  273.             alert(err);
  274.         };
  275.     };
  276. }
  277. finally {
  278. };
  279.  
  280. //NOTE: This code will be executed even when error occurs
  281.  
  282. };
  283.  
  284. function fnGetBrowserObject() {
  285.     //return top.frames.ctToolBars.ctlBrowser;
  286.     return go_ctlBrowser;
  287. };
  288.  
  289. function fnOpenFile() {
  290.     var sOldFileName = gsCurrentPath;
  291.     var OLDCurrentFolderUIN = goCurrentFolderUIN;
  292.     var ctlBrowser = fnGetBrowserObject();
  293.  
  294.         
  295.     top.fnGetMainToolbar().all.OpenButton.ct_unstick();
  296.  
  297.     if ( fnBrowseForFile(gsCurrentPath, L_Open_Dialog_Title) ) {
  298.  
  299.         var ctfResult = fnPrepareToChangeDatabase();
  300.         if (ctfResult != ctfFailure) {
  301.             fnSaveChangedDatabase();
  302.         };
  303.  
  304.         goCurrentFolderUIN = -1;
  305.         fnLoadFile(ctlBrowser.FileName);
  306.     }
  307.     else {
  308.         ctlBrowser.FileName = sOldFileName;
  309.     };
  310.  
  311.  
  312. };
  313.  
  314. var popupTimeout = -1;
  315. function fnShowRecentList() {
  316.  
  317.     if (popupTimeout != -1) {
  318.         window.clearTimeout(popupTimeout);
  319.             popupTimeout = -1;
  320.     };
  321.  
  322.  
  323.     var Helper = fnGetHelperObject();
  324.  
  325.         var RecentFiles =  fnGetHistorySettings(ccsStPreviousFile);
  326.  
  327.         if (RecentFiles == null || RecentFiles.length == 0) {
  328.  
  329.             top.fnGetMainToolbar().all.ShowPreviousFiles.ct_unstick();
  330.         popupTimeout = window.setTimeout(fnMouseOutOfButton, 500);
  331.  
  332.             return;
  333.     }
  334.     
  335.     Helper.PopupMenuCreate();
  336.  
  337.     for (var i = 0; i < RecentFiles.length; i++) {
  338.         //Helper.PopupMenuAppendItem(RecentFiles[i],
  339.         Helper.PopupMenuAppendPathItem(RecentFiles[i],
  340.              i + 1, true, false);
  341.  
  342.     };
  343.     
  344.         var MenuButton = fnGetMainToolbar().all.OpenButton;
  345.     
  346.     
  347.     var nLeft = 0; var nTop = 0;
  348.         
  349.         nLeft += MenuButton.offsetLeft +  0 + 
  350.             MenuButton.document.body.offsetLeft +
  351.             MenuButton.document.parentWindow.screenLeft;
  352.  
  353.         nTop += MenuButton.offsetTop +  MenuButton.offsetHeight +
  354.             MenuButton.document.body.offsetTop +
  355.             MenuButton.document.parentWindow.screenTop;
  356.  
  357.  
  358.         var res = Helper.PopupMenuTrack(nLeft, nTop, top.oHTA.applicationName);
  359.  
  360.         Helper.PopupMenuDestroy();
  361.  
  362.         top.fnGetMainToolbar().all.ShowPreviousFiles.ct_unstick();
  363.         
  364.         if ((res > 0) && ( res < RecentFiles.length + 1) ) {
  365.         //fnSaveChangedDatabase();
  366.                    var ctfResult = fnPrepareToChangeDatabase();
  367.         if (ctfResult != ctfFailure) {
  368.             fnSaveChangedDatabase();
  369.         };
  370.  
  371.  
  372.         goCurrentFolderUIN = -1;
  373.         if (RecentFiles[res-1] != null && RecentFiles[res-1] != "")
  374.             fnLoadFile(RecentFiles[res-1]);
  375.     };
  376.  
  377.  
  378. //    popupTimeout = window.setTimeout(fnMouseOutOfButton, 500);
  379.  
  380. };
  381.  
  382. function fnMouseOutOfButton() {
  383.     if (popupTimeout != -1) {
  384.         window.clearTimeout(popupTimeout);
  385.             popupTimeout = -1;
  386.     };
  387.  
  388.     top.fnGetMainToolbar().all.ShowPreviousFiles.ct_mouseout();
  389.     top.fnGetMainToolbar().all.OpenButton.ct_mouseout();
  390. };
  391.  
  392. var nNodes = 0;
  393. function OnTransformNode() {
  394.     nNodes ++;
  395.     fnGetCitatesHolder().innerText = nNodes.toString();
  396.     document.recalc(true);
  397.     window.status = nNodes.toString();
  398.     return true;
  399. };
  400.  
  401. var FolderChangeTimer = -1;
  402. var GszHTML = "";
  403. function fnTransferItem(some) {
  404.     if ( some == null ) {
  405.         some = 0;
  406.     };
  407.  
  408.     window.clearTimeout(FolderChangeTimer);
  409.     FolderChangeTimer = -1;
  410.  
  411.     
  412.     var nPos = 0;
  413.  
  414.     for (i = 0; (i < 20) && (nPos > -1); i ++) {
  415.         nPos = GszHTML.indexOf("<HR />", nPos + 1);
  416.     };
  417.  
  418.  
  419.     var ctlCitates = fnGetCitatesHolder();
  420.  
  421.     if (nPos != -1) {
  422.         nPos += 6;
  423.  
  424.  
  425.             //alert(GszHTML.slice(nPos-10, nPos));
  426.         ctlCitates.insertAdjacentHTML("beforeEnd",
  427.                 GszHTML.slice(0, nPos));
  428.  
  429.         GszHTML  = GszHTML.slice(nPos);
  430.         //alert("'" + GszHTML.slice(0, 10) + "'");
  431.  
  432.         FolderChangeTimer =
  433.             window.setTimeout(fnTransferItem, 200);
  434.     }
  435.     else {
  436.         if (GszHTML != "") {
  437.             ctlCitates.insertAdjacentHTML("beforeEnd",
  438.                 GszHTML);
  439.             GszHTML = "";
  440.         };
  441.  
  442.         fnHideWaitCursor();
  443.  
  444.     };
  445.  
  446.  
  447.  
  448. };
  449.  
  450. function OnFolderChanged(some) {
  451.  
  452.     var ctlCitates = fnGetCitatesHolder();
  453.  
  454.     if (some == null)
  455.         some = false;
  456.     
  457.     
  458.     ctlCitates.innerHTML = "";
  459.     GszHTML = "";
  460.     if (FolderChangeTimer != -1) {
  461.         window.clearTimeout(FolderChangeTimer);
  462.                 FolderChangeTimer = -1;
  463.     };
  464.  
  465.     if (!some)
  466.         fnShowWaitCursor();
  467. nNodes = 0;
  468.  
  469.     if (goListXSL == null) {
  470.         goListXSL = fnCreateXMLctl();
  471.         if (goListXSL == null) {
  472.             alert(L_Unable_To_Create);
  473.  
  474.             fnHideWaitCursor();
  475.  
  476.             return;
  477.         };
  478.         
  479.     }
  480.     else {
  481.         goListXSL.loadXML("");
  482.     };
  483.  
  484.     //goListXSL.load("ctList.xsl");
  485.     goListXSL.load(top.document.frames.ctToolBars.document.all.ctList.XMLDocument);
  486.     
  487.     try {
  488.         goCurrentFolderUIN = fnGetFolderTreeUIN();
  489.         //ctlTree.all.tags("SELECT")[0].options[ctlTree.all.tags("SELECT")[0].selectedIndex].value;
  490.     }
  491.     catch(err) {
  492.         goCurrentFolderUIN = -1;
  493.     };
  494.     var ctDATABASE = goBase.selectSingleNode("/root/CogTracker:ctDATABASE");
  495.     
  496.     if (goCurrentFolderUIN != -1) {
  497.         ctDATABASE.setAttribute(cxbiAttCurrentNode, goCurrentFolderUIN);
  498.     };
  499.  
  500.     if (gbFilterByFolder) {
  501.         var oFilters = goListXSL.selectNodes("//xsl:template[@match='root']/xsl:apply-templates/@select");
  502.         for (i = 0; i < oFilters.length; i++) {
  503.             oFilters[i].nodeValue = ".//*[@UIN=" + goCurrentFolderUIN + "]";
  504.         };
  505.     }
  506.     else {
  507.         var oFilters = goListXSL.selectNodes("//xsl:template[@match='root']/xsl:apply-templates");
  508.         for (i = 0; i < oFilters.length; i++) {
  509.             oFilters[i].setAttribute("select", "//CogTracker:ctFRAGMENT");
  510.                         oFilters[i].setAttribute("order-by",
  511.                                 arDirectionSigns[gnSortDirection].toString() +
  512.                     arAttributeNames[gnSortBy].toString());
  513.         };
  514.     };
  515.  
  516.     var oSorts = goListXSL.selectNodes("//xsl:apply-templates[@select='./CogTracker:ctFRAGMENT']/@order-by");
  517.     for (i = 0; i < oSorts.length; i++) {
  518.         oSorts[i].nodeValue = arDirectionSigns[gnSortDirection].toString() +
  519.                     arAttributeNames[gnSortBy].toString();
  520.     };
  521.     
  522.     
  523.     var ssnFieldsParent = 
  524.             goListXSL.selectSingleNode("//TABLE[@CLASS='Fragment']/TBODY");
  525.     var ssnTitleAndDate = 
  526.             goListXSL.selectSingleNode("//TR[@CLASS='TitleAndDate']");
  527.     
  528.     var ssnFragmentTools = goListXSL.selectSingleNode("//NOBR[@CLASS='FragmentTools']");
  529.     var ssnDate = goListXSL.selectSingleNode("//xsl:if[@test='@CreationDate']");
  530.     var ssnText = goListXSL.selectSingleNode("//TR[@CLASS='Text']");
  531.     var ssnComment = goListXSL.selectSingleNode("//TR[@CLASS='Comment']");
  532.     var ssnBaseURL = goListXSL.selectSingleNode("//TR[@CLASS='BaseURL']");
  533.     
  534.     
  535.     if ( ! goVisibilityOptions.bShowTitle ) {
  536.         var ssnFragmentToolsHolder = null;            
  537.         if ( goVisibilityOptions.bShowText) {
  538.             ssnFragmentToolsHolder = ssnText;
  539.         }
  540.         else if (goVisibilityOptions.bShowComment) {
  541.             ssnFragmentToolsHolder = ssnComment;
  542.         }
  543.         else if (goVisibilityOptions.bShowURL) {
  544.             ssnFragmentToolsHolder = ssnBaseURL;
  545.         };
  546.         
  547.         if (ssnFragmentToolsHolder) {
  548.             ssnFieldTitle = ssnFragmentToolsHolder.selectSingleNode(".//TD[@CLASS='FieldTitle']");
  549.             ssnFieldTitle.appendChild(ssnFragmentTools.parentNode.removeChild(ssnFragmentTools));
  550.         };
  551.     
  552.         ssnFieldsParent.removeChild(ssnTitleAndDate);
  553.     }
  554.     else if ( ! goVisibilityOptions.bShowDate ) {
  555.         ssnDate.parentNode.removeChild(ssnDate);
  556.     };
  557.  
  558.     if ( ! goVisibilityOptions.bShowText ) {
  559.         ssnFieldsParent.removeChild(ssnText);
  560.     };
  561.     
  562.     if ( ! goVisibilityOptions.bShowComment ) {
  563.         ssnFieldsParent.removeChild(ssnComment);
  564.     };
  565.     
  566.     if ( ! goVisibilityOptions.bShowURL ) {
  567.         ssnFieldsParent.removeChild(ssnBaseURL);
  568.     };
  569.     
  570.         if ( ! goVisibilityOptions.bShowFieldNames ) {
  571.         ssnFieldsParent.parentNode.setAttribute("COLS", 2);
  572.  
  573.         var ssnColGroup = ssnFieldsParent.parentNode.selectSingleNode("./COLGROUP");
  574.         ssnColGroup.removeChild(ssnColGroup.firstChild);
  575.                 ssnColGroup.lastChild.setAttribute("STYLE", "width:98%;");
  576.  
  577.                 var allFieldTitles = ssnFieldsParent.selectNodes(
  578.                     "//TD[@CLASS='FieldTitle']");
  579.         for (var i = 0; i < allFieldTitles.length; i ++) {
  580.             allFieldTitles[i].parentNode.removeChild(allFieldTitles[i]);
  581.         };
  582.             
  583.         };
  584.     
  585.     /*
  586.         = true;
  587.     */
  588.  
  589.     //goBase.ontransformnode = OnTransformNode;
  590.  
  591.     
  592. /*
  593.         goListXSL.load("ctList.xsl");
  594.     var ctCurFolder =
  595.         goBase.selectSingleNode("//*[@UIN='" +
  596.                 goCurrentFolderUIN + "']");
  597.     
  598.     var ctFragList = ctCurFolder.selectNodes("./CogTracker:ctFRAGMENT");
  599.     var i = 0;
  600.     top.ctTitleBar.document.body.innerText="Loading...";
  601.         ctlCitates.innerHTML = "";
  602.         var startTime = new Date();
  603.     for (i = 0; i < ctFragList.length; i++) {
  604.         var szHTML = ctFragList.item(i).transformNode(goListXSL);
  605.         ctlCitates.insertAdjacentHTML("beforeEnd", szHTML);
  606.                 top.ctTitleBar.document.body.innerText="Loading... " + i.toString();
  607.     };
  608.     var endTime = new Date();
  609.     alert (endTime.getTime() - startTime.getTime());
  610.     //alert("Transformed");
  611.     return;
  612. */
  613.  
  614.         var startTime = new Date();
  615.  
  616.     var szHTML = goBase.transformNode(goListXSL);
  617.     //szHTML = "";
  618.         //goBase.ontransformnode = null;
  619.         /*
  620.         var fso = new ActiveXObject("Scripting.FileSystemObject");
  621.         var a = fso.CreateTextFile("C:\\MarkUp.htm", true);
  622.         a.WriteLine(szHTML);
  623.         a.Close();
  624.  
  625.         */
  626.  
  627.         // LINEBREAKS
  628.         szHTML = szHTML.replace(/!BR\/!/g, "<BR/>");
  629.  
  630.     var endTransTime = new Date();
  631.  
  632.     if (szHTML == null) {
  633.         alert(L_Transform_Failed);
  634.         fnHideWaitCursor();
  635.         return;
  636.     };
  637.  
  638.     ctlCitates.document.selection.empty();
  639.  
  640.         if (szHTML == "") {
  641.         szHTML=L_NO_FRAGMENTS_HTML;
  642.                 ctlCitates.innerHTML = szHTML;
  643.                 fnHideWaitCursor();
  644.     }
  645.     else {
  646.         var i = 0;
  647.         var nPos = 0;
  648.  
  649.         for (i = 0; (i < 10) && (nPos > -1); i ++) {
  650.             nPos = szHTML.indexOf("<HR", nPos + 1);
  651.         };
  652.  
  653.  
  654.         if (nPos != -1) {
  655.             nPos += 5;
  656.                         GszHTML = szHTML;
  657.                         szHTML = "";
  658.                         fnTransferItem(0);
  659.  
  660.                         /*
  661.             if (!some)  {
  662.                 ctlCitates.innerHTML = szHTML.slice(0, nPos);
  663.                 szHTML = "";
  664.                 FolderChangeTimer =
  665.                     window.setTimeout("OnFolderChanged(1)", 50);
  666.             }
  667.             else {
  668.                 ctlCitates.insertAdjacentHTML("beforeEnd",
  669.                     szHTML.slice(nPos));
  670.                 szHTML = "";
  671.             };
  672.                         */
  673.         }
  674.         else {
  675.             ctlCitates.innerHTML = szHTML;
  676.                         szHTML = "";
  677.             fnHideWaitCursor();
  678.         };
  679.     };
  680.     
  681.     //ctlCitates.innerHTML = szHTML;
  682.  
  683.  
  684.     var endTime = new Date();
  685. /*
  686.     alert ( "All time:" + 
  687.         ( endTime.getTime() - startTime.getTime() ) + "\n" +
  688.         "Tranform time:" + 
  689.         ( endTransTime.getTime() - startTime.getTime() ) + "\n" +
  690.         "Apply time:" +
  691.         ( endTime.getTime() - endTransTime.getTime() ) + "\n"
  692.          );
  693. */
  694.         //FocusHolder.innerHTML = szHTML;
  695.         //FocusHolder.runtimeStyle = "block";
  696.  
  697.     /*
  698.     var oTexts = ctlCitates.all["FragmentText"];
  699.     if (oTexts == null) {
  700.         fnHideWaitCursor();
  701.         return;
  702.     };
  703.         */
  704.     /*
  705.         //<!-- Auto-resize development delayed -->
  706.  
  707.     var oTextRange = document.body.createTextRange();
  708.     for (i = 0; i < oTexts.length; i++) {
  709.         var oBoundingRect = oTexts[i].getBoundingClientRect();
  710.         oTextRange.moveToElementText(oTexts[i]);
  711.         var oClientRects  = oTextRange.getClientRects();
  712.         
  713.         //var nMaxWidth = 0;
  714.         var nSumHeight = 0;
  715.         for (j = 0; j < oClientRects.length; j++) {
  716.         //    nMaxWidth = Math.max(oClientRects[j].right - oClientRects[j].left, nMaxWidth);
  717.             nSumHeight += oClientRects[j].bottom - oClientRects[j].top;
  718.         };
  719.         
  720.         //alert("Bounding\n Width:" + (oBoundingRect.right - oBoundingRect.left).toString() +
  721.         //    "\n Height:" + (oBoundingRect.bottom - oBoundingRect.top).toString() +
  722.         //    "\nSummarized\n Width:" + nMaxWidth.toString() +
  723.         //    "\n Height:" + nSumHeight.toString());
  724.         
  725.                 if (oClientRects.length <= 4) {
  726.         //if (nSumHeight < (oBoundingRect.bottom - oBoundingRect.top) ) {
  727.             oTexts[i].runtimeStyle.height = nSumHeight + 2 + "px";
  728.             oTexts[i].runtimeStyle.overflow = "hidden";
  729.                     oTexts[i].parentNode.parentNode.all.ExpandCollapse.runtimeStyle.display = "none";
  730.         }
  731.         else {
  732.             oTexts[i].runtimeStyle.height = "6em";//(oBoundingRect.bottom - oBoundingRect.top);
  733.             oTexts[i].runtimeStyle.overflow = "auto";
  734.                     oTexts[i].parentNode.parentNode.all.ExpandCollapse.runtimeStyle.display = "";
  735.         };
  736.     };
  737.         */
  738.     
  739.     if (some)
  740.         fnHideWaitCursor();
  741. };
  742.  
  743. function fnStartChange(someNode) {
  744.     var oTextNode = null;
  745.     var arTextNames = new Array("FragmentTitle", "FragmentText", "FragmentComment", "BaseURLText");
  746.     
  747.     for ( i = 0; (i < arTextNames.length) && (oTextNode == null); i++) {
  748.         try {
  749.             oTextNode = someNode.parentNode.parentNode.all[arTextNames[i]];
  750.         }
  751.         catch (err) {
  752.             oTextNode = null;
  753.         };
  754.     };
  755.     
  756.     if (oTextNode == null) {
  757.         alert ("Not found.");
  758.         return;
  759.     }
  760.     var oDateField = oTextNode.parentNode.all["FragmentDate"];
  761.     if (oDateField != null) {
  762.         oDateField.runtimeStyle.display = "none";
  763.     };
  764.  
  765.     var oTextRange = oTextNode.document.body.createTextRange();
  766.     var sText = oTextNode.innerText;
  767.         oTextRange.moveToElementText(oTextNode);
  768.     var oBoundingRect = oTextNode.getBoundingClientRect();
  769.     var oClientRects  = oTextRange.getClientRects();
  770.  
  771.     if (oBoundingRect.bottom - oBoundingRect.top - 2 <= 0) {
  772.         // Rectanle may be empty...
  773.         oTextNode.innerText = " ";
  774.         oTextRange.moveToElementText(oTextNode);
  775.         oBoundingRect = oTextNode.getBoundingClientRect();
  776.         oClientRects  = oTextRange.getClientRects();
  777.         oTextNode.innerText = sText;
  778.         if (oBoundingRect.bottom - oBoundingRect.top - 2 <= 0) {
  779.             oBoundingRect.bottom += 16;
  780.         };
  781.     };
  782.     
  783.     //alert(oBoundingRect.bottom - oBoundingRect.top);
  784.  
  785.         oTextNode.innerHTML =
  786.             "<TEXTAREA CLASS='RenameEdit' id='RenameEdit' name='RenameEdit'"+
  787.                 "STYLE='WIDTH: 100%; HEIGHT:" + 
  788.             (oBoundingRect.bottom - oBoundingRect.top - ((oClientRects.length >1) ?(2):(0)) )
  789.             /*oTextNode.offsetHeight*/ + "px; " +
  790.  
  791.             /*( (oClientRects.length > 1) ?
  792.                 (*/"overflow: auto;'"/*) :
  793.                 ("overflow: hidden;'") )  */+
  794. //            " StdHeight=" + 
  795. //                (oBoundingRect.bottom - oBoundingRect.top - 2) + 
  796.             " onblur='top.fnEditOnAccept(this);'" +
  797.             " onkeypress='top.fnEditOnKey(this);'" + 
  798. //            " onkeyup='fnEditOnChange();'" + 
  799.  
  800.             // LINEBREAKS
  801.             " WRAP='hard'" +
  802.  
  803.             " >" +
  804.             // LINEBREAKS
  805.             //fnRemoveWhiteSpaces(sText) +
  806.  
  807.             sText +
  808.                         //(oBoundingRect.bottom - oBoundingRect.top).toString() + 
  809.             "</TEXTAREA>";
  810.  
  811.     //oTextNode.all.RenameEdit.width = oTextNode.offsetWidth;
  812.     //oTextNode.all.RenameEdit.height = oTextNode.offsetHeight;
  813.     if (oTextNode.currentStyle.overflow == "auto")
  814.         oTextNode.runtimeStyle.overflow = "hidden";
  815.     
  816.     oTextNode.runtimeStyle.marginTop = "0px";
  817.     oTextNode.runtimeStyle.marginBottom = "0px";
  818.     oTextNode.runtimeStyle.paddingTop = "0px";
  819.     oTextNode.runtimeStyle.paddingBottom = "0px";
  820.  
  821.     // LINEBREAKS
  822.     oTextNode.all["RenameEdit"].oldText = sText;
  823.     //oTextNode.all["RenameEdit"].oldText = fnRemoveWhiteSpaces(sText);
  824.  
  825.         oTextNode.all["RenameEdit"].select();
  826.     oTextNode.all["RenameEdit"].focus();
  827.         
  828.     //oTextRange.execCommand("InsertTextArea", false, "RenameEdit");
  829.     //oTextNode.all["RenameEdit"].innerText = sText;
  830.         /*
  831.         if (oTextNode.id != "FragmentText") {
  832.         var nWidth = oTextNode.offsetWidth;
  833.         var nHeight= oTextNode.offsetHeight;
  834.         if (oTextNode.parentNode.all.FragmentDate != null) {
  835.             nWidth -= oTextNode.parentNode.all.FragmentDate.offsetWidth + 5;
  836.         }
  837.         //oTextNode.offsetWidth;
  838.         oTextNode.innerHTML = "<INPUT Class='RenameEdit' id='RenameEdit' name='RenameEdit' TYPE='text' Value='" + oTextNode.innerText + "'></INPUT>";
  839.         oTextNode.all.RenameEdit.width = nWidth;
  840.         oTextNode.all.RenameEdit.Height = nHeight;
  841.         oTextNode.runtimeStyle.marginTop = "0px";
  842.         oTextNode.runtimeStyle.marginBottom = "0px";
  843.         oTextNode.runtimeStyle.paddingTop = "0px";
  844.         oTextNode.runtimeStyle.paddingBottom = "0px";
  845.     }
  846.     else {
  847.         oTextNode.innerHTML = 
  848.             "<TEXTAREA CLASS='RenameEdit' STYLE='WIDTH: 100%; HEIGHT:" + 
  849.             oTextNode.offsetHeight + "px; overflow: auto;'" + ">" + oTextNode.innerText + "</TEXTAREA>";
  850.     };
  851.         */
  852. };
  853.  
  854. function fnApplyFragmentPropertyChangeToBase(someUIN, someAttributeName, someText) {
  855.  
  856.     var ctfResult = fnPrepareToChangeDatabase();
  857.  
  858.     if (ctfResult == ctfFailure)
  859.         return false;
  860.         
  861.  
  862.     var ctFragment = goBase.selectSingleNode(
  863.         "//" +
  864.             ( (gbFilterByFolder) ?
  865.                 ( "*[@UIN='" +
  866.                 goCurrentFolderUIN.toString() + 
  867.                 "']/") : 
  868.                 ("")
  869.             ) + 
  870.         "CogTracker:ctFRAGMENT[@UIN='" +
  871.                 someUIN.toString() +
  872.                 "']");
  873.     if (ctFragment == null) {
  874.         alert(L_Fragment_Not_Found);
  875.  
  876.         fnGetHelperObject().UnlockFile(gsCurrentPath);
  877.  
  878.         return false;
  879.     }
  880.  
  881.     ctFragment.setAttribute(someAttributeName, someText);
  882.  
  883.     fnSaveChangedDatabase();
  884.  
  885.  
  886.     if (ctfResult == ctfReloaded) {
  887.         OnFolderChanged();
  888.         return false;
  889.     };
  890.  
  891.     return true;
  892. };
  893.  
  894. function fnEditOnAccept(oTextEdit) {
  895.     //alert("EditOnAccept");
  896.     //var oTextEdit = event.srcElement;
  897.            var oContainerNode = oTextEdit.parentNode;
  898.     var oUIN = oContainerNode.parentNode.parentNode.parentNode.parentNode.UIN;
  899.  
  900.     oTextEdit.onblur="";
  901.     
  902.     var sPropertyName = "";
  903.     switch (oContainerNode.id) {
  904.         case "FragmentTitle":
  905.             sPropertyName = cxbiAttName;
  906.             break;
  907.         case "FragmentText":
  908.             sPropertyName = cxbiAttText;
  909.             break;
  910.         case "FragmentComment":
  911.             sPropertyName = cxbiAttComment;
  912.             break;
  913.         case "BaseURLText":
  914.             sPropertyName = cxbiAttURL;
  915.             break;
  916.     };
  917.  
  918.     var sText = oTextEdit.innerText;
  919.     // LINEBREAKS
  920.     var sDBText = sText.replace(/\r\n/g, "!BR/!")
  921.     
  922.     //var sText = fnRemoveWhiteSpaces(oTextEdit.innerText);
  923.  
  924.     if ( ! fnApplyFragmentPropertyChangeToBase(oUIN, sPropertyName, sDBText)) {
  925.         //oTextEdit.newText = oTextEdit.oldText;
  926.         return;
  927.     }
  928.     else {
  929.     };
  930.  
  931.            oTextEdit.newText = sText;
  932.  
  933.         fnEditRestoreFromEdit(oTextEdit);
  934. };
  935. function fnEditOnKey(oTextEdit) {
  936.     var event = oTextEdit.document.parentWindow.event;
  937.  
  938.     if (event.keyCode == 0x0D && ( ! event.shiftKey) ){
  939.         fnEditOnAccept(oTextEdit);
  940.         event.returnValue = false;
  941.         event.cancelBubble = true;
  942.     }
  943.     else if (event.keyCode == 0x1B){
  944.         event.srcElement.newText = event.srcElement.oldText;
  945.         fnEditRestoreFromEdit(oTextEdit);
  946.         event.returnValue = false;
  947.         event.cancelBubble = true;
  948.     }
  949.     // LINEBREAKS
  950.     
  951.     else if (event.keyCode == 0x0A ||
  952.          (event.keyCode == 0x0D && event.shiftKey == true) ){
  953.         //event.shiftKey = false;
  954.         event.keyCode = 0x0D;
  955.     };
  956.         
  957. };
  958. /*
  959. function fnEditOnChange() {
  960.     var oTextEdit = event.srcElement;
  961.  
  962.         var oTextRange = oTextEdit.createTextRange();
  963.     oTextRange.moveToElementText(oTextEdit);
  964.     var oClientRects  = oTextRange.getClientRects();
  965.     
  966.     var i = 0;
  967.     var nTotalHeight = 0;
  968.     for (i = 0; i < oClientRects.length; i++) {
  969.         nTotalHeight += oClientRects[i].bottom - oClientRects[i].top;
  970.     };
  971.  
  972.     if (nTotalHeight > oTextEdit.clientHeight) {
  973.         oTextEdit.runtimeStyle.height = nTotalHeight;
  974.     }
  975.     else if (nTotalHeight < oTextEdit.clientHeight) {
  976.         if (nTotalHeight > oTextEdit.StdHeight) {
  977.             oTextEdit.runtimeStyle.height = nTotalHeight;
  978.         }
  979.         else {
  980.             oTextEdit.runtimeStyle.height = oTextEdit.StdHeight;
  981.         };
  982.     };
  983. };
  984. */
  985. function fnEditRestoreFromEdit(oTextEdit) {
  986.     //alert("RestoreFromEdit");
  987.     //var oTextEdit = event.srcElement;
  988.     oTextEdit.onblur="";
  989.     oTextEdit.onchange="";
  990.         //oTextEdit.fire("onblur");
  991.  
  992.         oTextEdit.runtimeStyle.display = "none";
  993.  
  994.     var oTextNode = oTextEdit.parentNode;
  995.  
  996.         fnGetRightToolbar().all.FocusHolder.focus();
  997.  
  998.     if (oTextNode.id != "BaseURLText") {
  999.         oTextNode.innerText = oTextEdit.newText;
  1000.     }
  1001.     else {
  1002.         var sText = oTextEdit.newText;
  1003.         oTextNode.innerHTML =
  1004.             "<A TARGET='_blank' CLASS='BaseURL' Name='BaseURL' " +
  1005.             "id='BaseURL'></A>";
  1006.         var oAnchor = oTextNode.all["BaseURL"];
  1007.                 oAnchor.href = sText;
  1008.                 oAnchor.innerText = sText;
  1009.     };
  1010.     oTextNode.runtimeStyle.marginTop = "";
  1011.     oTextNode.runtimeStyle.marginBottom = "";
  1012.     oTextNode.runtimeStyle.paddingTop = "";
  1013.     oTextNode.runtimeStyle.paddingBottom = "";
  1014.  
  1015.     if (oTextNode.currentStyle.overflow == "hidden")
  1016.         oTextNode.runtimeStyle.overflow = "auto";
  1017.  
  1018.     var oDateField = oTextNode.parentNode.all["FragmentDate"];
  1019.     if (oDateField != null) {
  1020.         oDateField.runtimeStyle.display = "";
  1021.     };
  1022.  
  1023.         document.body.focus();
  1024.  
  1025.     //document.all["FocusHolder"].focus();
  1026.  
  1027.     //oTextNode.focus();
  1028.     //oTextEdit.parentElement.parentElement.focus();
  1029.     //window.setTimeout("top.fnGetRightToolbar().click();top.document.frames.ctRightFrame.focus();", 10);
  1030.  
  1031. };
  1032.  
  1033. L_Must_Select_Fragment = "You should select at least one citation to use this command.";
  1034.  
  1035. function fnBuildSelectedTablesArray(someSelectionOnlyFlag) {
  1036.  
  1037.     var oRightDocument = top.fnGetCitatesHolder().document;
  1038.  
  1039.     document.frames.ctRightFrame.fnExpandSelection();
  1040.  
  1041.  
  1042.     var oRange = oRightDocument.selection.createRange();
  1043.         oRightDocument.selection.empty();
  1044.  
  1045.     var oEmptyRange = oRange.duplicate();
  1046.     oEmptyRange.collapse();
  1047.  
  1048.     var bSelectionExists = ! oEmptyRange.isEqual(oRange);
  1049.  
  1050.     if (someSelectionOnlyFlag && ! bSelectionExists) {
  1051.         alert(L_Must_Select_Fragment);
  1052.  
  1053.         return null;
  1054.     };
  1055.  
  1056.     var collTables = oRightDocument.getElementsByTagName("TABLE");
  1057.     var arrTables = new Array();
  1058.     var oTmpArray = new Array(1);
  1059.  
  1060.     for (var oRunner = new Enumerator(collTables); !oRunner.atEnd();
  1061.             oRunner.moveNext()) {
  1062.         var oCurrItem = oRunner.item();
  1063.              
  1064.         if (oCurrItem.className != "Fragment" ||
  1065.             oCurrItem.UIN == null ||
  1066.             oCurrItem.UIN == "") {
  1067.  
  1068.             continue;
  1069.         };
  1070.  
  1071.         if ( bSelectionExists ) {
  1072.             var oElementRange = oRightDocument.body.createTextRange();
  1073.             oElementRange.moveToElementText(oCurrItem);
  1074.  
  1075.             if ( ! oRange.inRange(oElementRange)) {
  1076.  
  1077.                 continue;
  1078.             }
  1079.         };
  1080.  
  1081.         oTmpArray[0] = oCurrItem;
  1082.         arrTables = arrTables.concat(oTmpArray);
  1083.     };
  1084.     
  1085.     if (arrTables.length == 0) {
  1086.         if (someSelectionOnlyFlag)
  1087.             alert(L_Must_Select_Fragment);
  1088.  
  1089.         return null;
  1090.     };
  1091.     var oResult = new Object();
  1092.     oResult.arrTables = arrTables;
  1093.     oResult.oRange = ( (bSelectionExists) ? (oRange) : (null) );
  1094.  
  1095.     return oResult;
  1096.  
  1097. };
  1098.  
  1099. function fnExpandCollapseFraments(bExpand) {
  1100.     var oResult = fnBuildSelectedTablesArray(false);
  1101.  
  1102.     if ( ! oResult ) {
  1103.         return;
  1104.     };
  1105.  
  1106.     var arrTables = oResult.arrTables;
  1107.     var oRange = oResult.oRange;
  1108.  
  1109.     for (var i = 0; i < arrTables.length; i ++) {
  1110.     
  1111.         fnPerformExpandCollapse(
  1112.             arrTables[i].all["ExpandCollapse"],
  1113.             arrTables[i].all["FragmentText"], 
  1114.             ( (bExpand) ? (cecExpand) : (cecCollapse) ) );
  1115.     };
  1116.     
  1117.     if (oRange)
  1118.         oRange.select();
  1119. };
  1120.  
  1121. var cecCollapse = 0;
  1122. var cecExpand = 1;
  1123. var cecToggleState = 2;
  1124.  
  1125. function fnPerformExpandCollapse(someButtonNode, someFragmentTextNode, someFlag) {
  1126.  
  1127.     if ( ( someFragmentTextNode.currentStyle.overflow == "auto" && 
  1128.             someFlag == cecToggleState) ||
  1129.             (someFlag == cecExpand)
  1130.         ) {
  1131.         
  1132.         someFragmentTextNode.runtimeStyle.overflow = "visible";
  1133.         someButtonNode.src = "FragmentCollapse.gif";
  1134.         someButtonNode.runtimeStyle.display = "inline";
  1135.     }
  1136.     else if ( ( someFragmentTextNode.currentStyle.overflow == "visible" && 
  1137.             someFlag == cecToggleState) ||
  1138.             (someFlag == cecCollapse)
  1139.         ) {
  1140.         someFragmentTextNode.runtimeStyle.overflow = "auto";
  1141.         // Alex: this shouldn't be so, but this helps fix the bug
  1142.         //         with single-line texts disappearing after restoring.
  1143.         someFragmentTextNode.parentElement.innerHTML = 
  1144.                         someFragmentTextNode.parentElement.innerHTML;
  1145.                     
  1146.         someButtonNode.src = "FragmentExpand.gif";
  1147.         someButtonNode.runtimeStyle.display = "inline";
  1148.     }
  1149.     else if (someFragmentTextNode.currentStyle.overflow == "hidden") {
  1150.         // Development of auto-resize delayed
  1151.         //    someButtonNode.runtimeStyle.display = "none";
  1152.     };
  1153. };
  1154.  
  1155. function fnExpandCollapseText(someNode)
  1156. {
  1157.     fnPerformExpandCollapse(someNode, 
  1158.         someNode.parentNode.parentNode.all.FragmentText, 
  1159.         cecToggleState);
  1160. };
  1161.  
  1162. var tmpNewFolderUIN = -1;
  1163. function fnNewFolderToBase(someUIN, someName) {
  1164.     var ctfResult = fnPrepareToChangeDatabase();
  1165.  
  1166.         tmpNewFolderUIN = -1;
  1167.  
  1168.     if (ctfResult != ctfFailure) {
  1169.         var ctSelected = goBase.selectSingleNode(
  1170.             "//*[@UIN='" + someUIN.toString() +"']");
  1171.           if (ctSelected == null) {
  1172.               alert(L_Folder_Not_Found);
  1173.  
  1174.             fnGetHelperObject().UnlockFile(gsCurrentPath);
  1175.  
  1176.  
  1177.                         return ctfFailure;
  1178.           };
  1179.  
  1180.  
  1181.         var ctElement = goBase.createElement(cxbiNODE);
  1182.  
  1183.         var NewUIN = fnCreateNewUIN(goBase);
  1184.                 tmpNewFolderUIN = NewUIN;
  1185.         ctElement.setAttribute(cxbiAttUIN, NewUIN);
  1186.         ctElement.setAttribute(cxbiAttName, someName);
  1187.         ctElement.text = "\n\t";
  1188.  
  1189.         ctSelected.appendChild(ctElement);
  1190.  
  1191.         fnSaveChangedDatabase();
  1192.  
  1193.                 /*Make database be reparsed*/
  1194.                 /*
  1195.                 var oTmpBase = fnCreateXMLctl();
  1196.                 goBase.save(oTmpBase);
  1197.                 goBase.loadXML("");
  1198.                 oTmpBase.save(goBase);
  1199.                 */
  1200.         var sXML = new String(goBase.xml);
  1201.         goBase.loadXML("");
  1202.         goBase.loadXML(sXML);
  1203.     };
  1204.  
  1205.     return ctfResult;
  1206. };
  1207.  
  1208. function fnNewFolder()
  1209. {
  1210.     var bOK = true;
  1211.         var sNewName = "";
  1212.     do {
  1213.         bOK = true;
  1214.     
  1215.         var NewDialogHeight = "140px";
  1216.         var NewDialogWidth = "220px";
  1217.         var xPos =  document.body.clientLeft +
  1218.                 document.body.clientWidth/2;
  1219.         var yPos =  document.body.clientTop +
  1220.                 document.body.clientHeight/2;
  1221.  
  1222.         xPos -= parseInt(NewDialogWidth.slice(0,NewDialogWidth.length-2), 10)/2;
  1223.         yPos -= parseInt(NewDialogHeight.slice(0,NewDialogHeight.length-2), 10)/2;
  1224.         sNewName = showModalDialog("ctNewNode.htm", "folder", 
  1225.             "help:no; resizable:no; status:no; center:no;" + 
  1226.             " dialogLeft:"    + xPos.toString() + "px;" +
  1227.             "dialogTop:"    + yPos.toString() + "px;" + 
  1228.             "dialogHeight:" +  NewDialogHeight + ";" + 
  1229.             "dialogWidth:"  +  NewDialogWidth + ";");
  1230.  
  1231.         if (sNewName == "" || sNewName == null)
  1232.             return;
  1233.         sNewName = fnRemoveWhiteSpaces(sNewName);
  1234.  
  1235.         if (sNewName == "" || sNewName == null)
  1236.             return;
  1237.         
  1238. //TEMP: non-hierarchical add..
  1239.         var ctNODE = goBase.selectSingleNode(
  1240.             "//*[@UIN='" + goCurrentFolderUIN
  1241.             //ctlTree.all.tags("SELECT")[0].options(0).value.toString()
  1242.             +"']");
  1243.           if (ctNODE == null) {
  1244.               alert(L_Folder_Not_Found);
  1245.               return ctfFailure;
  1246.           };
  1247.  
  1248. /*
  1249. //TEMP: non-hierarchical add..
  1250.           var ctChildNodes = ctNODE.selectNodes("./CogTracker:ctNODE");
  1251.           for (i = 0; i < ctChildNodes.length; i++) {
  1252.             var sNodeNameUppered = ctChildNodes[i].getAttribute(cxbiAttName);
  1253.             sNodeNameUppered = sNodeNameUppered.toUpperCase();
  1254.             var sNewNameUppered = sNewName;
  1255.             sNewNameUppered = sNewNameUppered.toUpperCase();
  1256.  
  1257.             if (sNodeNameUppered == sNewNameUppered) {
  1258.                 alert(L_NODE_ALREADY_EXISTS);
  1259.                 bOK = false;
  1260.                 break;
  1261.             };
  1262.         };
  1263. */
  1264.         if ( fnNodeHasChildWithName(ctNODE, sNewName) ) {
  1265.             alert(L_NODE_ALREADY_EXISTS);
  1266.             bOK = false;
  1267.         };
  1268.     } while (!bOK);
  1269.  
  1270.       if (fnNewFolderToBase(/*ctlTree.all.tags("SELECT")[0].options(0).value*/
  1271. //TEMP: non-hierarchical add..
  1272.                   goCurrentFolderUIN, sNewName) != ctfFailure) {
  1273.  
  1274.         fnGetTreeHolder().all.FoldersTree.CreateNewNode(goCurrentFolderUIN,
  1275.             sNewName, tmpNewFolderUIN);
  1276.         /*
  1277.                 var oSelect = ctlTree.all.tags("SELECT")[0];
  1278.         if (oSelect) {
  1279.             var oOption = document.createElement("OPTION");
  1280.             oSelect.options.add(oOption);
  1281.             oOption.innerText = sNewName;
  1282.             oOption.value = tmpNewFolderUIN;
  1283.  
  1284.             oSelect.selectedIndex = oSelect.options.length - 1;
  1285.  
  1286.             OnFolderChanged();
  1287.         };
  1288.                 */
  1289.       };
  1290. };
  1291.  
  1292. function fnRenameFolderToBase(someUIN, someName)
  1293. {
  1294.     var ctfResult = fnPrepareToChangeDatabase();
  1295.  
  1296.     if (ctfResult != ctfFailure) {
  1297.         var ctSelected = goBase.selectSingleNode(
  1298.             "//*[@UIN='" + someUIN.toString() +"']");
  1299.           if (ctSelected == null) {
  1300.               alert(L_Folder_Not_Found);
  1301.  
  1302.             fnGetHelperObject().UnlockFile(gsCurrentPath);
  1303.  
  1304.  
  1305.                         return ctfFailure;
  1306.           };
  1307.  
  1308.  
  1309.         ctSelected.setAttribute(cxbiAttName, someName);
  1310.  
  1311.         fnSaveChangedDatabase();
  1312.     };
  1313.  
  1314.     return ctfResult;
  1315. };
  1316.  
  1317. function fnRenameFolder()
  1318. {
  1319.     var bOK = true;
  1320.         var sNewName = "";
  1321.         var sOldName = "";
  1322.         {
  1323.             //var oSelect = ctlTree.all.tags("SELECT")[0];
  1324.         sOldName = //fnRemoveWhiteSpaces(oSelect.options[oSelect.selectedIndex].innerText);
  1325.             fnGetTreeHolder().all.FoldersTree.GetCurrentNodeName();
  1326.     };
  1327.  
  1328.     do {
  1329.         bOK = true;
  1330.     
  1331.         var NewDialogHeight = "140px";
  1332.         var NewDialogWidth = "220px";
  1333.         var xPos =  document.body.clientLeft +
  1334.                 document.body.clientWidth/2;
  1335.         var yPos =  document.body.clientTop +
  1336.                 document.body.clientHeight/2;
  1337.  
  1338.         xPos -= parseInt(NewDialogWidth.slice(0,NewDialogWidth.length-2), 10)/2;
  1339.         yPos -= parseInt(NewDialogHeight.slice(0,NewDialogHeight.length-2), 10)/2;
  1340.  
  1341.         sNewName = showModalDialog("ctRenameNode.htm", sOldName, 
  1342.             "help:no; resizable:no; status:no; center:no;" + 
  1343.             " dialogLeft:"    + xPos.toString() + "px;" +
  1344.             "dialogTop:"    + yPos.toString() + "px;" + 
  1345.             "dialogHeight:" +  NewDialogHeight + ";" + 
  1346.             "dialogWidth:"  +  NewDialogWidth + ";");
  1347.  
  1348.         if (sNewName == "" || sNewName == null)
  1349.             return;
  1350.         sNewName = fnRemoveWhiteSpaces(sNewName);
  1351.  
  1352.         if (sNewName == "" || sNewName == null || sNewName == sOldName)
  1353.             return;
  1354.         
  1355. //TEMP: non-hierarchical add..
  1356.         var ctNODE = goBase.selectSingleNode(
  1357.             "//*[@UIN='" + goCurrentFolderUIN
  1358.             /*ctlTree.all.tags("SELECT")[0].options(0).value.toString()*/
  1359.             +"']");
  1360.         if ( isNaN(parseInt(ctNODE.getAttribute(cxbiAttIsDatabase))) ||
  1361.              parseInt(ctNODE.getAttribute(cxbiAttIsDatabase) != true) ) {
  1362.  
  1363.               if (ctNODE == null || ctNODE.parentNode == null) {
  1364.                   alert(L_Folder_Not_Found);
  1365.                   return ctfFailure;
  1366.               };
  1367.             
  1368.                         ctNODE = ctNODE.parentNode;
  1369.  
  1370.  
  1371. //TEMP: non-hierarchical add..
  1372.               var ctChildNodes = ctNODE.selectNodes("./CogTracker:ctNODE");
  1373.                   //"/root/CogTracker:ctDATABASE|//CogTracker:ctNODE");
  1374.               for (i = 0; i < ctChildNodes.length; i++) {
  1375.                   if (ctChildNodes[i].getAttribute(cxbiAttUIN) ==
  1376.                     goCurrentFolderUIN) {
  1377.  
  1378.                     continue;                
  1379.                             };
  1380.  
  1381.                 
  1382.  
  1383.  
  1384.                 var sNodeNameUppered = ctChildNodes[i].getAttribute(cxbiAttName);
  1385.                 sNodeNameUppered = sNodeNameUppered.toUpperCase();
  1386.                 var sNewNameUppered = sNewName;
  1387.                 sNewNameUppered = sNewNameUppered.toUpperCase();
  1388.  
  1389.                 if (sNodeNameUppered == sNewNameUppered) {
  1390.                     alert(L_NODE_ALREADY_EXISTS);
  1391.                     bOK = false;
  1392.                     break;
  1393.                 };
  1394.             };
  1395.         };
  1396.     } while (!bOK);
  1397.  
  1398.       if (fnRenameFolderToBase(goCurrentFolderUIN, sNewName) != ctfFailure) {
  1399.           fnGetTreeHolder().all.FoldersTree.RenameNode(goCurrentFolderUIN, sNewName);
  1400.         /*
  1401.         var oSelect = ctlTree.all.tags("SELECT")[0];
  1402.         if (oSelect) {
  1403.             oSelect.options(oSelect.selectedIndex).innerText =
  1404.                         sNewName;
  1405.             // has been put here to cause listbox redraw.
  1406.             OnFolderChanged();
  1407.         };
  1408.                 */
  1409.       };
  1410.  
  1411. };
  1412.  
  1413. function fnDeleteFolderFromBase(someUIN) {
  1414.     
  1415.     var ctfResult = fnPrepareToChangeDatabase();
  1416.  
  1417.     if (ctfResult != ctfFailure) {
  1418.         var ctNODE = goBase.selectSingleNode(
  1419.             "//*[@UIN='" + someUIN.toString() +"']");
  1420.           if (ctNODE == null) {
  1421.               alert(L_Folder_Not_Found);
  1422.  
  1423.             fnGetHelperObject().UnlockFile(gsCurrentPath);
  1424.  
  1425.  
  1426.  
  1427.                         return ctfFailure;
  1428.           };
  1429.  
  1430.           if (ctNODE.tagName == "CogTracker:ctDATABASE") {
  1431.               alert(L_Dont_Delete_Root);
  1432.  
  1433.             fnGetHelperObject().UnlockFile(gsCurrentPath);
  1434.  
  1435.               return ctfFailure;
  1436.           };
  1437.           
  1438.                 
  1439.           if (ctNODE.getAttribute(cxbiAttUnsorted) == 1) {
  1440.               alert(L_Dont_Delete_Unsorted);
  1441.  
  1442.             fnGetHelperObject().UnlockFile(gsCurrentPath);
  1443.  
  1444.               return ctfFailure;
  1445.           };
  1446.  
  1447.           var ctParent = ctNODE.parentNode;
  1448.           ctParent.removeChild(ctNODE);
  1449.  
  1450.         fnSaveChangedDatabase();
  1451.     };
  1452.  
  1453.     return ctfResult;
  1454. };
  1455.  
  1456. function fnDeleteFolder() {
  1457.     
  1458.  
  1459.     if ( ! confirm(L_Confirm_Folder_Deletion) ) {
  1460.         return;
  1461.     };
  1462.     
  1463.  
  1464.     if (fnDeleteFolderFromBase(goCurrentFolderUIN) != ctfFailure) {
  1465.         /*
  1466.         var oSelect = ctlTree.all.tags("SELECT")[0];
  1467.         if (oSelect) {
  1468.             var oFolders = oSelect.options;
  1469.             var nSelectedFolder = oSelect.selectedIndex;
  1470.             for (i = 0; i < oFolders.length; i++) {
  1471.                 if ( (oFolders[i].tagName == "OPTION") &&
  1472.                      (oFolders[i].value == goCurrentFolderUIN) )
  1473.                      {
  1474.                     //oFolders.remove(i);
  1475.                                         oFolders[i] = null;
  1476.                     
  1477.                     oSelect.selectedIndex =
  1478.                         ( (nSelectedFolder > 0) ?
  1479.                             (nSelectedFolder-1) :
  1480.                             (0));
  1481.                     
  1482.                     OnFolderChanged();
  1483.                     break;
  1484.                 };
  1485.             };
  1486.         };
  1487.                 */
  1488.                 fnGetTreeHolder().all.FoldersTree.RemoveNode(goCurrentFolderUIN, true);
  1489.     };
  1490.  
  1491.     fnGetCitatesHolder().document.selection.empty();
  1492. };
  1493.  
  1494. function fnMoveFolderInBase(someDestUIN, someSrcUIN) {
  1495.     var ctfResult = fnPrepareToChangeDatabase();
  1496.  
  1497.     if (ctfResult != ctfFailure) {
  1498.         var ctSrcNode = goBase.selectSingleNode(
  1499.             "//CogTracker:ctNODE[@UIN='" +
  1500.                 someSrcUIN.toString() +"']");
  1501.           if (ctSrcNode == null) {
  1502.               alert(L_Folder_Not_Found);
  1503.  
  1504.             fnGetHelperObject().UnlockFile(gsCurrentPath);
  1505.  
  1506.               return ctfFailure;
  1507.           };
  1508.           var ctDestNode = goBase.selectSingleNode(
  1509.             "/root/CogTracker:ctDATABASE[@UIN='" +
  1510.                 someDestUIN.toString() + "'] | " + 
  1511.             "//CogTracker:ctNODE[@UIN='" +
  1512.                 someDestUIN.toString() +"']");
  1513.           if (ctDestNode == null) {
  1514.               alert(L_Folder_Not_Found);
  1515.  
  1516.             fnGetHelperObject().UnlockFile(gsCurrentPath);
  1517.  
  1518.               return ctfFailure;
  1519.           };
  1520.  
  1521.           var ctParent = ctSrcNode.parentNode;
  1522.           ctDestNode.appendChild(ctParent.removeChild(ctSrcNode));
  1523.  
  1524.         fnSaveChangedDatabase();
  1525.  
  1526.     };
  1527.  
  1528.     return ctfResult;
  1529. };
  1530.  
  1531. function fnMoveFolder() {
  1532.  
  1533.         var ctlTree = fnGetTreeHolder();
  1534.  
  1535.     var currentFolder = fnGetTreeHolder().all.FoldersTree.GetCurrentNode();
  1536.     
  1537.     if (currentFolder == null) {
  1538.         alert(L_Folder_Not_Found);
  1539.         return;
  1540.     };
  1541.     
  1542.     currentFolder = currentFolder.parentElement;
  1543.     if (currentFolder.IsDatabase) {
  1544.         alert(L_Database_Cannot_Be_Moved);
  1545.         return;
  1546.     };
  1547.     
  1548.     if (currentFolder.IsUnsortedNode) {
  1549.         alert(L_SystemFolder_Cannot_Be_Moved);
  1550.         return;
  1551.     };
  1552.     
  1553.     var args = new Object();
  1554.     args.XMLbase = goBase;
  1555.     args.TreeHTML = new String(ctlTree.innerHTML);
  1556.     //args.bFragmentMove = false;
  1557.     args.nDialogMode = cmtfFolderMove;
  1558.     args.sourceFolder = ctlTree.all.FoldersTree.GetCurrentNodeUIN();
  1559.  
  1560.     var oResult = showModalDialog("ctMoveToFolder.htm", args,
  1561.         "help:no; resizable:no; status:no;");
  1562.  
  1563.     if (oResult == null || oResult.oFolder == null)
  1564.         return;
  1565.  
  1566.     var destinationFolder = oResult.oFolder;
  1567.  
  1568.  
  1569.     if (fnMoveFolderInBase(destinationFolder, args.sourceFolder) !=
  1570.         ctfFailure) {
  1571.  
  1572.         fnGetCitatesHolder().document.selection.empty();
  1573.         
  1574.         ctlTree.all.FoldersTree.MoveNode(destinationFolder,
  1575.             args.sourceFolder);
  1576.     };
  1577. };
  1578.  
  1579. function fnPrepareToChangeDatabase() {
  1580.  
  1581.     try {
  1582.         fnGetHelperObject().LockFile(gsCurrentPath);
  1583.     }
  1584.     catch (err) {
  1585.         alert(L_Failed_To_Lock_File);
  1586.         return ctfFailure;
  1587.     };
  1588.  
  1589.     var bReloaded = false;
  1590.  
  1591.     { //Check file's stamp
  1592.         var oDiskBase = fnCreateXMLctl();
  1593.         if (oDiskBase == null) {
  1594.             alert(L_Unable_To_Create);
  1595.  
  1596.                         fnGetHelperObject().UnlockFile(gsCurrentPath);
  1597.  
  1598.             return ctfFailure;
  1599.         };
  1600.  
  1601.         if (oDiskBase.load(gsCurrentPath)){
  1602.  
  1603.             if ( ! fnCheckTimeStampsEqual(goBase, oDiskBase) ) {
  1604.                 alert(L_Outside_Modification);
  1605.  
  1606.                                 bReloaded = true;
  1607.  
  1608.                 fnLoadFile(gsCurrentPath);
  1609.             };
  1610.         };
  1611.     };
  1612.  
  1613.     if (bReloaded) {
  1614.         return ctfReloaded;
  1615.     };
  1616.  
  1617.     return ctfSuccess;
  1618. };
  1619.  
  1620. function fnSaveChangedDatabase() {
  1621.  
  1622.     try {
  1623.         if (gsCurrentPath) {
  1624.             if (goCurrentFolderUIN != -1 &&
  1625.                 goBase.selectSingleNode("//*[@UIN='" + goCurrentFolderUIN + "']") ) {
  1626.                 
  1627.                 var ctDATABASE = goBase.selectSingleNode("/root/CogTracker:ctDATABASE");
  1628.                 if (ctDATABASE != null)  {
  1629.                     ctDATABASE.setAttribute(cxbiAttCurrentNode, goCurrentFolderUIN);
  1630.                 };
  1631.             };
  1632.             
  1633.             fnIncrementTimeStamp(goBase);
  1634.  
  1635.             goBase.save(gsCurrentPath);
  1636.  
  1637.             fnGetHelperObject().DoSendChangeNotification(gsCurrentPath, -1);
  1638.         }
  1639.         else {
  1640.                     
  1641.         };
  1642.     }
  1643.     catch(err) {
  1644.     }
  1645.     finally {
  1646.         fnGetHelperObject().UnlockFile(gsCurrentPath);
  1647.     }
  1648. };
  1649.  
  1650. function fnDeleteFragmentFromBase(someArrFragmentUINs /*someUIN*/) {
  1651.     var ctfResult = fnPrepareToChangeDatabase();
  1652.  
  1653.     if (ctfResult == ctfFailure) {
  1654.         return ctfFailure;
  1655.     };
  1656.  
  1657.     for (var i = 0; i < someArrFragmentUINs.length; i ++) {
  1658.         var someUIN = someArrFragmentUINs[i];
  1659.         
  1660.         var ctFragment = goBase.selectSingleNode(
  1661.             "//CogTracker:ctFRAGMENT[@UIN='" +
  1662.                 someUIN.toString() +"']");
  1663.           if (ctFragment == null) {
  1664.               alert(L_Fragment_Not_Found);
  1665.  
  1666.             fnGetHelperObject().UnlockFile(gsCurrentPath);
  1667.  
  1668.               return ctfFailure;
  1669.           };
  1670.  
  1671.           var ctParent = ctFragment.parentNode;
  1672.           ctParent.removeChild(ctFragment);
  1673.     };
  1674.  
  1675.         fnSaveChangedDatabase();
  1676.  
  1677.     return ctfResult;
  1678. };
  1679.  
  1680. function fnDeleteFragments(someParam) {
  1681.  
  1682.     var arrFragmentUINs = null;
  1683.  
  1684.     if (someParam == null) {
  1685.         var oResult = fnBuildSelectedTablesArray(true);
  1686.  
  1687.         if ( ! oResult ) {
  1688.             return;
  1689.         };
  1690.  
  1691.         var arrTables = oResult.arrTables;
  1692.         // var oRange = oResult.oRange;
  1693.  
  1694.                 arrFragmentUINs = new Array();
  1695.         for (var i = 0; i < arrTables.length; i ++) {
  1696.             arrFragmentUINs[i] = arrTables[i].UIN;
  1697.         };
  1698.             //
  1699.     }
  1700.     else {
  1701.         arrFragmentUINs = someParam;
  1702.     };
  1703.  
  1704.     var sPrompt = "";
  1705.     if (arrFragmentUINs.length > 1) {
  1706.         sPrompt = L_Confirm_Multiple_Fragments_Deletion;
  1707.     }
  1708.     else {
  1709.         sPrompt = L_Confirm_Fragment_Deletion;
  1710.     };
  1711.  
  1712.  
  1713.         var ctlCitates = fnGetCitatesHolder();
  1714.  
  1715.     if (confirm(sPrompt)) {
  1716.  
  1717.         if (fnDeleteFragmentFromBase(arrFragmentUINs) != ctfFailure) {
  1718.             for (var i = 0; i < arrFragmentUINs.length; i ++) {
  1719.                 //Database, maybe, has been reloaded...
  1720.                 oFragment = fnGetCitatesHolder().document.all(
  1721.                     "id" + arrFragmentUINs[i].toString());
  1722.  
  1723.                 if (oFragment) {
  1724.                     var oSibling = oFragment.nextSibling; // HR
  1725.                     var oParent = oFragment.parentNode;
  1726.                     oParent.removeChild(oFragment);
  1727.                     if (oSibling.tagName == "HR") {
  1728.                         oParent.removeChild(oSibling);
  1729.                     }
  1730.                 };
  1731.             };
  1732.         };
  1733.  
  1734.         fnGetCitatesHolder().document.selection.empty();
  1735.  
  1736.         if (ctlCitates.innerHTML == "") {
  1737.             ctlCitates.innerHTML = L_NO_FRAGMENTS_HTML;
  1738.         };
  1739.     };
  1740.     
  1741. };
  1742.  
  1743. function fnFragmentDelete(someNode) {
  1744.     var oFragment = someNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  1745.     var UIN = oFragment.UIN;
  1746.  
  1747.     var arrFragmentUINs = new Array();
  1748.         arrFragmentUINs[0] = UIN;
  1749.  
  1750.         fnDeleteFragments(arrFragmentUINs);
  1751. /*
  1752.         var ctlCitates = fnGetCitatesHolder();
  1753.  
  1754.     if (confirm(L_Confirm_Fragment_Deletion)) {
  1755.         var oFragment = someNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  1756.         var UIN = oFragment.UIN;
  1757.         
  1758.         if (fnDeleteFragmentFromBase(UIN) != ctfFailure) {
  1759.             //Database, maybe, has been reloaded...
  1760.             oFragment = fnGetCitatesHolder().document.all("id" + UIN.toString());
  1761.  
  1762.             if (oFragment) {
  1763.                 var oSibling = oFragment.nextSibling; // HR
  1764.                 var oParent = oFragment.parentNode;
  1765.                 oParent.removeChild(oFragment);
  1766.                 if (oSibling.tagName == "HR") {
  1767.                     oParent.removeChild(oSibling);
  1768.                 }
  1769.             };
  1770.         };
  1771.  
  1772.         fnGetCitatesHolder().document.selection.empty();
  1773.  
  1774.         if (ctlCitates.innerHTML == "") {
  1775.             ctlCitates.innerHTML = L_NO_FRAGMENTS_HTML;
  1776.         };
  1777.     };
  1778. */
  1779. };
  1780.  
  1781. var arSortFields = new Array(    "Sort by &Title", "Sort by &Date", "Sort by Te&xt",
  1782.                 "Sort by &Comment", "Sort by &URL");
  1783. var arSortDirections = new Array("Sort &Ascending", "Sort D&escending");
  1784.  
  1785. function fnSortModeSelect() {
  1786.  
  1787.     if (gnSortBy == -1)
  1788.         gnSortBy = 1;
  1789.     if (gnSortDirection == -1)
  1790.         gnSortDirection = 0;
  1791.  
  1792.     var Helper = fnGetHelperObject();
  1793.     Helper.PopupMenuCreate();
  1794.  
  1795.     for (var i = 0; i < arSortFields.length; i++) {
  1796.  
  1797.         Helper.PopupMenuAppendItem(arSortFields[i],
  1798.             i + 1, true, (gnSortBy == i) );
  1799.     };
  1800.     Helper.PopupMenuAppendSeparator();
  1801.  
  1802.     for  (var j = 0; j < arSortDirections.length; i++, j++) {
  1803.         Helper.PopupMenuAppendItem(arSortDirections[j],
  1804.              i + 1, true, (gnSortDirection == j) );
  1805.     };
  1806.  
  1807.     var MenuButton = fnGetRightToolbar().all.ctsSortModes;
  1808.  
  1809.     var nLeft = 0; var nTop = 0;
  1810.  
  1811.     nLeft += MenuButton.offsetLeft +  0 +
  1812.         MenuButton.document.body.offsetLeft +
  1813.         MenuButton.document.parentWindow.screenLeft;
  1814.  
  1815.     nTop += MenuButton.offsetTop +  MenuButton.offsetHeight +
  1816.         MenuButton.document.body.offsetTop +
  1817.         MenuButton.document.parentWindow.screenTop;
  1818.  
  1819.  
  1820.     var res = Helper.PopupMenuTrack(nLeft, nTop, top.oHTA.applicationName);
  1821.  
  1822.     Helper.PopupMenuDestroy();
  1823.  
  1824.     MenuButton.ct_unstick();
  1825.  
  1826.     res --;
  1827.     
  1828.     if (res < 0) {
  1829.         return;
  1830.     };
  1831.     if (res < arSortFields.length) {
  1832.         fnSortBy(res, -1, true);
  1833.     }
  1834.     else {
  1835.         res -= arSortFields.length;
  1836.  
  1837.         if (res < arSortDirections.length) {
  1838.             fnSortBy(-1, res, true);
  1839.         };
  1840.     };
  1841. };
  1842.  
  1843. function fnSortBy(someSort, someDirection, somePerformRefresh) {
  1844.  
  1845.     if (gnSortBy == -1)
  1846.         gnSortBy = 1;
  1847.     if (gnSortDirection == -1)
  1848.         gnSortDirection = 0;
  1849.  
  1850.     
  1851.     /*
  1852.     if (someSort == null || someSort == "") {
  1853.         someSort = -1;
  1854.     };
  1855.  
  1856.     if (someDirection == null || someDirection == "") {
  1857.         someDirection = -1;
  1858.     };
  1859.     */
  1860.     
  1861.     var nSortBy = gnSortBy;
  1862.     var nSortDirection = gnSortDirection;
  1863.  
  1864.     if (someSort >= 0 && someSort < arAttributeNames.length) {
  1865.         nSortBy = someSort;
  1866.     };
  1867.     if (someDirection >= 0 && someDirection < arAttributeNames.length) {
  1868.         nSortDirection = someDirection;
  1869.     };
  1870. /*
  1871.     var RightToolbar = fnGetRightToolbar();
  1872.  
  1873.     var nSortBy = -1;
  1874.     var nSortDirection = -1;
  1875.     if (someSort != null && someSort != "") {
  1876.         for( i = 0; i < arButtonSortNames.length; i++) {
  1877.             //RightToolbar.all[arButtonSortNames[i]].ct_disabled = 0;
  1878.             if (arButtonSortNames[i] == someSort) {
  1879.                 RightToolbar.all[arButtonSortNames[i]].ct_state = 1;
  1880.                 nSortBy = i;
  1881.             }
  1882.             else {
  1883.                 RightToolbar.all[arButtonSortNames[i]].ct_state = 0;
  1884.             };
  1885.         };
  1886.     }
  1887.     else {
  1888.         for( i = 0; i < arButtonSortNames.length; i++) {
  1889.             if (RightToolbar.all[arButtonSortNames[i]].ct_state == 1) {
  1890.                 nSortBy = i;
  1891.             };
  1892.         };
  1893.     };
  1894.     
  1895.     if (someDirection != -1) {
  1896.         for( i = 0; i < arButtonDirNames.length; i++) {
  1897.             //RightToolbar.all[arButtonDirNames[i]].ct_disabled = 0;
  1898.             if ( i == someDirection) {
  1899.                 RightToolbar.all[arButtonDirNames[i]].ct_state = 1;
  1900.                                 nSortDirection = i;
  1901.             }
  1902.             else {
  1903.                 RightToolbar.all[arButtonDirNames[i]].ct_state = 0;
  1904.             };
  1905.         };
  1906.     }
  1907.     else {
  1908.         for( i = 0; i < arButtonDirNames.length; i++) {
  1909.             if ( RightToolbar.all[arButtonDirNames[i]].ct_state == 1 ) {
  1910.                                 nSortDirection = i;
  1911.             };
  1912.         };
  1913.     };
  1914. */
  1915.     if ( (nSortBy == -1) || (nSortDirection == -1) ) {
  1916.         alert(L_Undetermined_Sort);
  1917.         return;
  1918.     };
  1919.  
  1920.     gnSortBy = nSortBy;
  1921.     gnSortDirection = nSortDirection;
  1922.  
  1923.     fnSetSetting(ccsSortBy, gnSortBy + 1, true);
  1924.     fnSetSetting(ccsSortDirection, gnSortDirection + 1, true);
  1925.  
  1926.  
  1927.     if (somePerformRefresh == null)
  1928.         somePerformRefresh = true;
  1929.     
  1930.     if (somePerformRefresh)
  1931.         OnFolderChanged();
  1932. };
  1933.  
  1934. function fnToggleFolderFilter() {
  1935.     gbFilterByFolder = (!gbFilterByFolder);
  1936.  
  1937.     fnGetLeftToolbar().all.ctsFolderFilter.ct_state = (!gbFilterByFolder);
  1938.  
  1939.     OnFolderChanged();
  1940. };
  1941.  
  1942. function fnOnTreeSelectionChange() {
  1943.     var oTree = fnGetTreeHolder().all.FoldersTree;
  1944.     var oCurNode = oTree.GetCurrentNodeUIN();
  1945.  
  1946.            gbFilterByFolder = true;
  1947.     fnGetLeftToolbar().all.ctsFolderFilter.ct_state = (!gbFilterByFolder);
  1948.  
  1949.  
  1950.     OnFolderChanged();
  1951. };
  1952.  
  1953. function fnMoveFragmentInBase(someDestUIN, someSrcUIN, someArrFragmentUINs, //someFragmentUIN, 
  1954.                 someMakeCopy) {
  1955.     var ctfResult = fnPrepareToChangeDatabase();
  1956.  
  1957.     if (ctfResult == ctfFailure) {
  1958.         return ctfFailure;
  1959.     };
  1960.  
  1961.  
  1962.     for (var i = 0; i < someArrFragmentUINs.length; i ++) {
  1963.  
  1964.                 var someFragmentUIN = someArrFragmentUINs[i];
  1965.  
  1966.         var ctFragment = goBase.selectSingleNode(
  1967.             "//CogTracker:ctFRAGMENT[@UIN='" +
  1968.                 someFragmentUIN.toString() +"']");
  1969.           if (ctFragment == null) {
  1970.               alert(L_Fragment_Not_Found);
  1971.  
  1972.             fnGetHelperObject().UnlockFile(gsCurrentPath);
  1973.  
  1974.               return ctfFailure;
  1975.           };
  1976.           var ctDestNode = goBase.selectSingleNode(
  1977.             "/root/CogTracker:ctDATABASE[@UIN='" +
  1978.                 someDestUIN.toString() + "'] | " + 
  1979.             "//CogTracker:ctNODE[@UIN='" +
  1980.                 someDestUIN.toString() +"']");
  1981.           if (ctDestNode == null) {
  1982.               alert(L_Folder_Not_Found);
  1983.  
  1984.             fnGetHelperObject().UnlockFile(gsCurrentPath);
  1985.  
  1986.               return ctfFailure;
  1987.           };
  1988.  
  1989.           var ctParent = ctFragment.parentNode;
  1990.           if (someMakeCopy) {
  1991.               var ctNewFragment = ctFragment.cloneNode(false);
  1992.             ctNewFragment.setAttribute(cxbiAttUIN,
  1993.                     fnCreateNewUIN(goBase));
  1994.  
  1995.               ctDestNode.appendChild(ctNewFragment);
  1996.           }
  1997.           else {
  1998.  
  1999.               ctDestNode.appendChild(ctParent.removeChild(ctFragment));
  2000.         };
  2001.  
  2002.     };
  2003.  
  2004.     fnSaveChangedDatabase();
  2005.  
  2006.     return ctfResult;
  2007. };
  2008.  
  2009. function fnMoveFragments( someParam ) {
  2010.  
  2011.     var arrFragmentUINs = null;
  2012.  
  2013.     if (someParam == null) {
  2014.         var oResult = fnBuildSelectedTablesArray(true);
  2015.  
  2016.         if ( ! oResult ) {
  2017.             return;
  2018.         };
  2019.  
  2020.         var arrTables = oResult.arrTables;
  2021.         // var oRange = oResult.oRange;
  2022.  
  2023.                 arrFragmentUINs = new Array();
  2024.         for (var i = 0; i < arrTables.length; i ++) {
  2025.             arrFragmentUINs[i] = arrTables[i].UIN;
  2026.         };
  2027.             //
  2028.     }
  2029.     else {
  2030.         arrFragmentUINs = someParam;
  2031.     };
  2032.  
  2033.  
  2034.         // Ask user...
  2035.         var ctlTree = fnGetTreeHolder();
  2036.         var ctlCitates = fnGetCitatesHolder();
  2037.  
  2038.     var args = new Object();
  2039.     args.XMLbase = goBase;
  2040.     args.TreeHTML = new String(ctlTree.innerHTML);
  2041.     //args.bFragmentMove = true;
  2042.            args.nDialogMode = cmtfFragmentMove;
  2043.  
  2044.     args.sourceFolder = ctlTree.all.FoldersTree.GetCurrentNodeUIN();
  2045.  
  2046.     var oResult = showModalDialog("ctMoveToFolder.htm", args,
  2047.         "help:no; resizable:no; status:no;");
  2048.     
  2049.     if (oResult == null || oResult.oFolder == null)
  2050.         return;
  2051.  
  2052.     var destinationFolder = oResult.oFolder;
  2053.     var bMakeCopy = oResult.bMakeCopy;
  2054.  
  2055.     if (fnMoveFragmentInBase(destinationFolder, args.sourceFolder,
  2056.         arrFragmentUINs, //UIN,
  2057.         bMakeCopy) != ctfFailure) {
  2058.  
  2059.         if ( ! bMakeCopy ) {
  2060.  
  2061.             for (var i = 0; i < arrFragmentUINs.length; i ++) {
  2062.  
  2063.                 //Database, maybe, has been reloaded...
  2064.                 oFragment = fnGetCitatesHolder().document.all("id" +
  2065.                     arrFragmentUINs[i].toString());
  2066.  
  2067.                 if (oFragment) {
  2068.                     var oSibling = oFragment.nextSibling; // HR
  2069.                     var oParent = oFragment.parentNode;
  2070.                     oParent.removeChild(oFragment);
  2071.                     if (oSibling.tagName == "HR") {
  2072.                         oParent.removeChild(oSibling);
  2073.                     }
  2074.                 };
  2075.             };
  2076.  
  2077.         };
  2078.  
  2079.         fnGetCitatesHolder().document.selection.empty();
  2080.  
  2081.         if (ctlCitates.innerHTML == "") {
  2082.             ctlCitates.innerHTML = L_NO_FRAGMENTS_HTML;
  2083.         };
  2084.                 // A node has been duplicated to this folder
  2085.         if ( (bMakeCopy && destinationFolder == args.sourceFolder) ||
  2086.             ( ! gbFilterByFolder) ) {
  2087.             OnFolderChanged();
  2088.         };
  2089.     };
  2090.  
  2091.  
  2092. };
  2093.  
  2094. function fnFragmentMove(someNode) {
  2095.     
  2096.     var oFragment = someNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  2097.     var UIN = oFragment.UIN;
  2098.  
  2099.     var arrFragmentUINs = new Array();
  2100.         arrFragmentUINs[0] = UIN;
  2101.  
  2102.     fnMoveFragments(arrFragmentUINs);
  2103.  
  2104. /*
  2105.         var ctlTree = fnGetTreeHolder();
  2106.         var ctlCitates = fnGetCitatesHolder();
  2107.  
  2108.     var args = new Object();
  2109.     args.XMLbase = goBase;
  2110.     args.TreeHTML = new String(ctlTree.innerHTML);
  2111.     args.bFragmentMove = true;
  2112.     args.sourceFolder = ctlTree.all.FoldersTree.GetCurrentNodeUIN();
  2113.  
  2114.     var oResult = showModalDialog("ctMoveToFolder.htm", args,
  2115.         "help:no; resizable:no; status:no;");
  2116.     
  2117.     if (oResult == null || oResult.oFolder == null)
  2118.         return;
  2119.  
  2120.     var destinationFolder = oResult.oFolder;
  2121.     var bMakeCopy = oResult.bMakeCopy;
  2122.  
  2123.  
  2124.     var oFragment = someNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  2125.     var UIN = oFragment.UIN;
  2126.  
  2127.     var arrFragmentUINs = new Array();
  2128.         arrFragmentUINs[0] = UIN;
  2129.  
  2130.     if (fnMoveFragmentInBase(destinationFolder, args.sourceFolder,
  2131.         arrFragmentUINs, //UIN,
  2132.         bMakeCopy) != ctfFailure) {
  2133.  
  2134.         if ( ! bMakeCopy ) {
  2135.             //Database, maybe, has been reloaded...
  2136.             oFragment = fnGetCitatesHolder().document.all("id" +
  2137.                     UIN.toString());
  2138.  
  2139.             if (oFragment) {
  2140.                 var oSibling = oFragment.nextSibling; // HR
  2141.                 var oParent = oFragment.parentNode;
  2142.                 oParent.removeChild(oFragment);
  2143.                 if (oSibling.tagName == "HR") {
  2144.                     oParent.removeChild(oSibling);
  2145.                 }
  2146.             };
  2147.         };
  2148.  
  2149.         fnGetCitatesHolder().document.selection.empty();
  2150.  
  2151.         if (ctlCitates.innerHTML == "") {
  2152.             ctlCitates.innerHTML = L_NO_FRAGMENTS_HTML;
  2153.         };
  2154.  
  2155.                 // A node has been duplicated to this folder
  2156.         if (bMakeCopy && destinationFolder == args.sourceFolder) {
  2157.             OnFolderChanged();
  2158.         };
  2159.     };
  2160. */
  2161. };
  2162.  
  2163. function fnChangeVisibilityOptions() {
  2164.  
  2165.     goVisibilityOptions.nMode = cvoDB;
  2166.  
  2167.     var result = showModalDialog("ctVisibilityOptions.htm",
  2168.         goVisibilityOptions,
  2169.         "help:no; resizable:no; status:no;");
  2170.  
  2171.     if ( ! result ) {
  2172.         return;
  2173.     };
  2174.  
  2175.     fnSetSetting(ccsVHideFieldNames , ! goVisibilityOptions.bShowFieldNames, true);
  2176.     fnSetSetting(ccsVShowTitle ,    goVisibilityOptions.bShowTitle, true);
  2177.     fnSetSetting(ccsVShowDate ,    goVisibilityOptions.bShowDate, true);
  2178.     fnSetSetting(ccsVShowText ,    goVisibilityOptions.bShowText, true);
  2179.     fnSetSetting(ccsVShowComment ,    goVisibilityOptions.bShowComment, true);
  2180.     fnSetSetting(ccsVShowURL ,    goVisibilityOptions.bShowURL, true);
  2181.  
  2182.     OnFolderChanged();
  2183. };
  2184.  
  2185.  
  2186. function fnPrint() {
  2187.     var ctlCitates = fnGetCitatesHolder();
  2188.     ctlCitates.document.parentWindow.focus();
  2189.     ctlCitates.document.parentWindow.print();
  2190. };
  2191.  
  2192.  
  2193. function fnFind() {
  2194.     window.setTimeout(    "document.frames.ctRightFrame.focus();" +
  2195.                 "fnGetHelperObject().DoCauseFind();" , 500);
  2196.  
  2197. /*
  2198.     var ctlCitates = fnGetCitatesHolder();
  2199.         document.frames.ctToolBars.blur();
  2200.         document.frames.ctRightFrame.focus();
  2201.     //ctlCitates.document.parentWindow.focus();
  2202.  
  2203.     fnGetHelperObject().DoCauseFind();
  2204. */
  2205. /*
  2206.     var WM_KEYDOWN = 0x0100;
  2207.     var WM_KEYUP   = 0x0101;
  2208.         var WM_COMMAND = 0x0111;
  2209.     var VK_CONTROL = 0x11;
  2210.     var VK_F       = 0x46;
  2211.  
  2212.     var ctlCitates = fnGetCitatesHolder();
  2213.     ctlCitates.document.parentWindow.focus();
  2214.  
  2215.     var Helper = fnGetHelperObject();
  2216.     
  2217. */
  2218. /*
  2219.     alert(document.frames.ctRightFrame.document.parentWindow);
  2220.     Helper.DoIt(document.frames.ctRightFrame.document.parentWindow);
  2221. */
  2222. /*
  2223.     Helper.DoPostMessage(WM_COMMAND,
  2224.                 0x443,
  2225.                 //0x10043,
  2226.                 //0x1091,
  2227.                 0,//(VK_CONTROL << 16) | 1,
  2228.                 top.oHTA.applicationName);
  2229. */
  2230.  
  2231. /*
  2232.     Helper.DoPostMessage(0xE124,
  2233.                 0,
  2234.                 0,//(VK_CONTROL << 16) | 1,
  2235.                 top.oHTA.applicationName);
  2236. */
  2237. /*
  2238.     Helper.DoPostMessage(WM_KEYDOWN,
  2239.                 VK_CONTROL,
  2240.                 0x01D0001,//(VK_CONTROL << 16) | 1,
  2241.                 top.oHTA.applicationName);
  2242.     Helper.DoPostMessage(WM_KEYDOWN,
  2243.                 VK_F,
  2244.                 0x0210001,//(VK_F << 16)  | 1,
  2245.                 top.oHTA.applicationName);
  2246. */
  2247.  
  2248. /*
  2249.     Helper.DoPostMessage(WM_KEYUP,
  2250.                 VK_F,
  2251.                 0xC0210001,//(VK_F << 16) | 0xC000000  | 1,
  2252.                 top.oHTA.applicationName);
  2253.     Helper.DoPostMessage(WM_KEYUP,
  2254.                 VK_CONTROL,
  2255.                 0xC01D0001,//(VK_CONTROL << 16)  | 0xC000000 | 1,
  2256.                 top.oHTA.applicationName);
  2257. */
  2258.     //alert("Not ready yet.");
  2259.     //ctlCitates.document.parentWindow.fireEvent();
  2260.         //ctlCitates.document.execCommand("Find", true, "a");
  2261. };
  2262.  
  2263. function fnOnFileChange() {
  2264.  
  2265.     var sChangedFilePath = fnGetHelperObject().FileChangeFilePath;
  2266.     var nChangedFolderID = fnGetHelperObject().FileChangeFolderID;
  2267.  
  2268.     if (gsCurrentPath.toUpperCase() == sChangedFilePath.toUpperCase()) {
  2269.         fnLoadFile(gsCurrentPath);
  2270.     };
  2271. };
  2272.  
  2273. var cixImport = 1;
  2274. var cixExport = 2;
  2275. var cixSendByMail = 3;
  2276.  
  2277. function fnImport() {
  2278.     fnPerformImportExport(cixImport);
  2279. };
  2280.  
  2281. function fnExport() {
  2282.     fnPerformImportExport(cixExport);
  2283. };
  2284.  
  2285. function fnPerformImportExport( nMode, someFilePath) {
  2286.  
  2287.     var bExternalLocked = false;
  2288.     var ctlBrowser = fnGetBrowserObject();
  2289.     var oldBase = null;
  2290.     var tmpBase = null;
  2291.         
  2292.     switch (nMode) {
  2293.         case cixImport:
  2294.     
  2295.             if ( ! fnBrowseForFile(gsCurrentPath, L_Import_Dialog_Title,
  2296.                 L_CITATES_EXT, L_CITATES_FILTER, false, true, true) ) {
  2297.                     
  2298.                 return false;
  2299.             }
  2300.             break;
  2301.             
  2302.         case cixExport:
  2303.     
  2304.             if ( ! fnBrowseForFile(gsCurrentPath, L_Export_Dialog_Title) ) {
  2305.                     
  2306.                 return false;
  2307.             }
  2308.             break;
  2309.         case cixSendByMail: 
  2310.             ctlBrowser.FileName = someFilePath;
  2311.             break;
  2312.  
  2313.         default:
  2314.             alert("Invalid mode selected.");
  2315.             return false;
  2316.             break;
  2317.     };            
  2318.  
  2319.     var externalBase = fnCreateXMLctl();
  2320.     if (externalBase == null) {
  2321.         alert(L_Unable_To_Create);
  2322.         return false;
  2323.     };
  2324.     externalBase.loadXML("");
  2325.  
  2326.  
  2327.     var bExternalIsInternal = (ctlBrowser.FileName.toUpperCase() == 
  2328.                                     gsCurrentPath.toUpperCase());
  2329.     var sExternalPath = ctlBrowser.FileName;
  2330.     
  2331.  
  2332.     if (bExternalIsInternal) {
  2333.         goBase.save(externalBase);
  2334.     }
  2335.     else {
  2336.         try {
  2337.             fnGetHelperObject().LockFile(ctlBrowser.FileName);
  2338.         }
  2339.         catch (err) {
  2340.  
  2341.             alert(L_Failed_To_Lock_File);
  2342.         
  2343.             return false;
  2344.         };
  2345.  
  2346.         
  2347.         try {
  2348.             switch (nMode) {
  2349.                 case cixImport:
  2350.                     //No Checked initialize, 'coz we do not need this file to work for us.
  2351.                     if (    ( ! externalBase.load(sExternalPath) ) ||
  2352.                         ( ! externalBase.selectSingleNode(cxbiRoot) ) ||
  2353.                         ( ! externalBase.selectSingleNode(cxbiRoot + "/" + cxbiDatabase) ) ) {
  2354.  
  2355.                         throw(L_Failed_To_Load_File);
  2356.                     };
  2357.                     break;
  2358.                 
  2359.                 case cixExport:
  2360.                 case cixSendByMail:
  2361.                     if ( ! fnCheckedInitializeFile(externalBase, sExternalPath)  ) {
  2362.  
  2363.                         throw(L_Failed_To_Load_File);
  2364.                     };
  2365.                     break;
  2366.             };
  2367.         }
  2368.         catch(err) {
  2369.             fnGetHelperObject().UnlockFile(ctlBrowser.FileName);
  2370.             
  2371.             if (err != null && err != "") {
  2372.                 if (err.description != null) {
  2373.                     alert(L_OP_FAILED + err.description);
  2374.                 }
  2375.                 else {
  2376.                     alert(err);
  2377.                 };
  2378.             };
  2379.  
  2380.             return false;
  2381.         };
  2382.         
  2383.         fnGetHelperObject().UnlockFile(ctlBrowser.FileName);
  2384.     };
  2385.     
  2386.     /**/
  2387.     if ( ! fnCheckVersion(externalBase) ) {
  2388.         if ( ! fnConfirmConversion(externalBase) ) {
  2389.             return false;
  2390.         }
  2391.         else {
  2392.             if ( ! fnPerformConversion(externalBase) ) {
  2393.                 return false;
  2394.             };
  2395.         };
  2396.     };
  2397.  
  2398.     //Ensure that all CogTracker:ctNODE have their UINs
  2399.     var oNodesList = externalBase.selectNodes(
  2400.                         "/root/CogTracker:ctDATABASE|//CogTracker:ctNODE|" + 
  2401.                         "//CogTracker:ctFRAGMENT");
  2402.                 
  2403.     for (var i = 0; i < oNodesList.length; i++) {
  2404.         fnGetElementUIN(externalBase, oNodesList.item(i));
  2405.     };
  2406.  
  2407. //Send By Mail does not present a dialog.
  2408.  
  2409. var sourceFolder = null;
  2410. var ctlTree = fnGetTreeHolder();
  2411.  
  2412. if (nMode != cixSendByMail) {
  2413.  
  2414.     if (goTreeXSL == null) {
  2415.         goTreeXSL = fnCreateXMLctl();
  2416.         if (goTreeXSL == null) {
  2417.             alert(L_Unable_To_Create);
  2418.             return false;
  2419.         };
  2420.  
  2421.         //goTreeXSL.load("ctTree.xsl");
  2422.         goTreeXSL.load(top.document.frames.ctToolBars.document.all.ctTree.XMLDocument);
  2423.  
  2424.  
  2425.     }
  2426.  
  2427.  
  2428.     var ctDATABASE = 
  2429.             externalBase.selectSingleNode("/root/CogTracker:ctDATABASE");
  2430.  
  2431.     var oCurrentFolderUIN = parseInt(ctDATABASE.getAttribute(cxbiAttCurrentNode));
  2432.     if (isNaN(oCurrentFolderUIN)) {
  2433.         oCurrentFolderUIN = ctDATABASE.getAttribute(cxbiAttUIN);
  2434.         ctDATABASE.setAttribute(cxbiAttCurrentNode, oCurrentFolderUIN);
  2435.     };
  2436.  
  2437.     var ctCurFolder = 
  2438.             externalBase.selectSingleNode("//*[@UIN='" + oCurrentFolderUIN + "']");
  2439.     if (ctCurFolder == null) {
  2440.         oCurrentFolderUIN = ctDATABASE.getAttribute(cxbiAttUIN);
  2441.         ctDATABASE.setAttribute(cxbiAttCurrentNode, oCurrentFolderUIN);
  2442.     };
  2443.     
  2444.     
  2445.     var szHTML = externalBase.transformNode(goTreeXSL);
  2446.     if (szHTML == null || szHTML == "") {
  2447.         alert(L_Transform_Failed);
  2448.         return false;
  2449.     };
  2450.  
  2451.     var args = new Object();
  2452.     args.XMLbase = goBase;
  2453.     args.TreeHTML = new String(szHTML);
  2454.         
  2455.     switch (nMode) {
  2456.         case cixImport:
  2457.             args.nDialogMode = cmtfFolderImport;
  2458.             break;
  2459.             
  2460.         case cixExport:
  2461.             args.nDialogMode = cmtfFolderExport;
  2462.             break;
  2463.     };            
  2464.         
  2465.     ctlTree = fnGetTreeHolder();
  2466.  
  2467.     args.sourceFolder = null;
  2468.     args.internalDB = goBase;
  2469.     args.externalDB = externalBase;
  2470.     args.internalFolder = ctlTree.all.FoldersTree.GetCurrentNodeUIN();
  2471.  
  2472.     var oResult = showModalDialog("ctMoveToFolder.htm", args,
  2473.         "help:no; resizable:no; status:no;");
  2474.  
  2475.     if (oResult == null || oResult.oFolder == null)
  2476.         return false;
  2477.  
  2478.     sourceFolder = oResult.oFolder;
  2479.     
  2480.     /**/
  2481. }
  2482. else {
  2483.     ctlTree = fnGetTreeHolder();
  2484.     var ctDATABASE = 
  2485.         externalBase.selectSingleNode("/root/CogTracker:ctDATABASE");
  2486.  
  2487.     sourceFolder = fnGetElementUIN(goBase, ctDATABASE);
  2488.     
  2489.     //Remove Unsorted Node
  2490.     var ctUNSORTED = 
  2491.         externalBase.selectSingleNode("/root/CogTracker:ctDATABASE/CogTracker:ctNODE[@IsUnsortedNode]");
  2492.     if (ctUNSORTED != null){
  2493.         ctUNSORTED.parentNode.removeChild(ctUNSORTED);
  2494.     };
  2495. };
  2496.  
  2497.  
  2498.     
  2499.     var ctfResult = fnPrepareToChangeDatabase();
  2500.     if (ctfResult == ctfFailure) {
  2501.         return false;
  2502.     };
  2503.  
  2504.     if ( ! bExternalIsInternal) {
  2505.  
  2506.         try {
  2507.             fnGetHelperObject().LockFile(ctlBrowser.FileName);
  2508.         }
  2509.         catch (err) {
  2510.             fnGetHelperObject().UnlockFile(gsCurrentPath);
  2511.  
  2512.             alert(L_Failed_To_Lock_File);
  2513.         
  2514.             return false;
  2515.         };
  2516.         bExternalLocked = true;
  2517.     };
  2518.  
  2519.     var bError = false;
  2520.  
  2521.     try {
  2522.         tmpBase = fnCreateXMLctl();
  2523.         if (tmpBase == null) {
  2524.             throw(L_Unable_To_Create);
  2525.         };
  2526.         goBase.save(tmpBase);
  2527.     
  2528.         
  2529.         //Just to be sure...
  2530.         ctlTree = fnGetTreeHolder();
  2531.         var destinationFolder = ctlTree.all.FoldersTree.GetCurrentNodeUIN();
  2532.         
  2533.         var sourceNode = externalBase.selectSingleNode(
  2534.                 "/root/CogTracker:ctDATABASE[@UIN='" + 
  2535.                         sourceFolder + "']|//CogTracker:ctNODE[@UIN='" + 
  2536.                         sourceFolder + "']");
  2537.         if (sourceNode == null) {
  2538.             throw(L_Folder_Not_Found);
  2539.         };
  2540.         
  2541.         var destinationNode = tmpBase.selectSingleNode(
  2542.                 "/root/CogTracker:ctDATABASE[@UIN='" + 
  2543.                         destinationFolder + "']|//CogTracker:ctNODE[@UIN='" + 
  2544.                         destinationFolder + "']");
  2545.         if (destinationNode == null) {
  2546.             throw(L_Folder_Not_Found);
  2547.         };
  2548.         
  2549.         switch (nMode) {
  2550.             case cixImport:
  2551.                     if (fnAddNodeData(tmpBase, destinationNode, 
  2552.                                     externalBase, sourceNode, true)) {
  2553.                         oldBase = goBase;
  2554.                         goBase = tmpBase;
  2555.         
  2556.                         fnSaveChangedDatabase();
  2557.  
  2558.                         if (bExternalLocked)
  2559.                             fnGetHelperObject().UnlockFile(sExternalPath);
  2560.                         
  2561.                         fnLoadFile(gsCurrentPath);
  2562.                     }
  2563.                     else {
  2564.         
  2565.                         throw(L_FAILED_TO_ADD_NODE);
  2566.                     };
  2567.                 break;
  2568.             
  2569.             case cixExport:
  2570.             case cixSendByMail:
  2571.             
  2572.                     if (fnAddNodeData(externalBase, sourceNode, 
  2573.                                     tmpBase, destinationNode, true)) {
  2574.         
  2575.                         if (nMode == cixSendByMail) {
  2576.                             //Mark added folder as Unsorted Node
  2577.                             var ctUNSORTED = 
  2578.                                 externalBase.selectSingleNode("/root/CogTracker:ctDATABASE/CogTracker:ctNODE");
  2579.                             if (ctUNSORTED != null){
  2580.                                 ctUNSORTED.setAttribute(cxbiAttUnsorted, "1");
  2581.                             };
  2582.                         };
  2583.                         
  2584.                         fnIncrementTimeStamp(externalBase);
  2585.  
  2586.                         externalBase.save(sExternalPath);
  2587.  
  2588.                         fnGetHelperObject().DoSendChangeNotification(
  2589.                                     sExternalPath, -1);
  2590.  
  2591.                         if (bExternalLocked) {
  2592.                             fnGetHelperObject().UnlockFile(sExternalPath);
  2593.                         }
  2594.                         fnGetHelperObject().UnlockFile(gsCurrentPath);
  2595.                         
  2596.                         if (bExternalIsInternal) {
  2597.                             fnLoadFile(gsCurrentPath);
  2598.                         };                
  2599.                     }
  2600.                     else {
  2601.                         throw(L_FAILED_TO_ADD_NODE);
  2602.                     };
  2603.                 break;
  2604.         };            
  2605.  
  2606.         //TEMP:
  2607.         //fnGetHelperObject().UnlockFile(gsCurrentPath);
  2608.     }
  2609.     catch(err) {
  2610.         if (oldBase != null) {
  2611.             goBase = oldBase;
  2612.         };
  2613.         
  2614.         fnGetHelperObject().UnlockFile(gsCurrentPath);
  2615.  
  2616.         if (bExternalLocked)
  2617.             fnGetHelperObject().UnlockFile(sExternalPath);
  2618.  
  2619.         if (err != null && err != "") {
  2620.             if (err.description != null) {
  2621.                 alert(L_OP_FAILED + err.description);
  2622.             }
  2623.             else {
  2624.                 alert(err);
  2625.             };
  2626.         };
  2627.  
  2628.         bError = true;
  2629.  
  2630.     };
  2631.     //NOTE: this code gets executed even when error occurs. Beware!
  2632.     
  2633.     
  2634.     tmpBase = oldBase = null;
  2635.  
  2636.     return (!bError);
  2637. };
  2638.  
  2639.  
  2640. function fnAddNodeData(someDestBase, someDestNode, someSrcBase, someSrcNode, 
  2641.                         bRecursive)
  2642. {
  2643.     var ctNewNode = someDestBase.createElement(cxbiNODE);
  2644.     
  2645.     var NewUIN = fnCreateNewUIN(someDestBase);
  2646.     ctNewNode.setAttribute(cxbiAttUIN, NewUIN);
  2647.     ctNewNode.setAttribute(cxbiAttName, someSrcNode.getAttribute(cxbiAttName));
  2648.     ctNewNode.text = "\n\t";
  2649.  
  2650.     someDestNode.appendChild(ctNewNode);
  2651.     
  2652.     var oFragmentsList = someSrcNode.selectNodes("./CogTracker:ctFRAGMENT");
  2653.     for (var i = 0; i < oFragmentsList.length; i++) {
  2654.         var ctNewFragment = someDestBase.createElement(cxbiFRAGMENT);
  2655.     
  2656.         var NewUIN = fnCreateNewUIN(someDestBase);
  2657.         ctNewFragment.setAttribute(cxbiAttUIN, NewUIN);
  2658.         
  2659.         ctNewFragment.setAttribute(cxbiAttName,        
  2660.                             oFragmentsList.item(i).getAttribute(cxbiAttName));
  2661.         ctNewFragment.setAttribute(cxbiAttComment,    
  2662.                             oFragmentsList.item(i).getAttribute(cxbiAttComment));
  2663.         ctNewFragment.setAttribute(cxbiAttText,
  2664.                             oFragmentsList.item(i).getAttribute(cxbiAttText));
  2665.         ctNewFragment.setAttribute(cxbiAttURL,
  2666.                             oFragmentsList.item(i).getAttribute(cxbiAttURL));
  2667.         
  2668.         var strDate = oFragmentsList.item(i).getAttribute(cxbiAttDate);
  2669.         if (strDate != null)
  2670.             ctNewFragment.setAttribute(cxbiAttDate, strDate);
  2671.  
  2672.         ctNewNode.appendChild(ctNewFragment);
  2673.     }
  2674.     oFragmentsList = null;
  2675.     
  2676.     var oNodesList = someSrcNode.selectNodes("./CogTracker:ctNODE");
  2677.     
  2678.     if (bRecursive) {
  2679.         for (var i = 0; i < oNodesList.length; i++) {
  2680.             if ( ! fnAddNodeData(someDestBase, ctNewNode, someSrcBase, oNodesList.item(i), 
  2681.                         bRecursive) ) {
  2682.                         
  2683.                 return false;
  2684.             };
  2685.         };
  2686.     };
  2687.     
  2688.     return true;
  2689. };
  2690.  
  2691.  
  2692. function fnHTMLExport() {
  2693.  
  2694.     var nCurFolderUIN = fnGetTreeHolder().all.FoldersTree.GetCurrentNodeUIN();
  2695.  
  2696.     var ctFOLDER = goBase.selectSingleNode(
  2697.         "/root/CogTracker:ctDATABASE[@UIN='" + nCurFolderUIN + "']|"+
  2698.         "//CogTracker:ctNODE[@UIN='" + nCurFolderUIN + "']");
  2699.     if ( ctFOLDER == null) {
  2700.         alert(L_Folder_Not_Found);
  2701.         return;
  2702.     };
  2703.  
  2704.     var ctFragment = ctFOLDER.selectSingleNode(".//CogTracker:ctFRAGMENT");
  2705.     if (ctFragment == null) {
  2706.         alert(L_NOTHING_TO_EXPORT_TO_HTML);
  2707.         return;
  2708.     };
  2709.     if ( ! fnBrowseForFile(gsCurrentPath, L_Export_Dialog_Title, L_HTML_EXT, L_HTML_FILTER, true) ) {
  2710.                     
  2711.         return false;
  2712.     };
  2713.  
  2714.     var ctlBrowser = fnGetBrowserObject();
  2715.  
  2716.     var sFilePath = ctlBrowser.FileName;
  2717.  
  2718.     var oXMLtoHTML = fnCreateXMLctl();
  2719.     if (oXMLtoHTML == null) {
  2720.         alert(L_Unable_To_Create);
  2721.         return;
  2722.     };
  2723.  
  2724.     //oXMLtoHTML.load("ctHTML.xsl");
  2725.     oXMLtoHTML.load(top.document.frames.ctToolBars.document.all.ctHTML.XMLDocument);
  2726.  
  2727.  
  2728.     var oSorts = oXMLtoHTML.selectNodes("//xsl:apply-templates[@select='./CogTracker:ctFRAGMENT']/@order-by");
  2729.     for (i = 0; i < oSorts.length; i++) {
  2730.         oSorts[i].nodeValue = arDirectionSigns[gnSortDirection].toString() +
  2731.                     arAttributeNames[gnSortBy].toString();
  2732.     };
  2733.  
  2734.     var ssnFieldsParent = 
  2735.             oXMLtoHTML.selectSingleNode("//TABLE[@CLASS='Fragment']/TBODY");
  2736.     var ssnTitleAndDate = 
  2737.             oXMLtoHTML.selectSingleNode("//TR[@CLASS='TitleAndDate']");
  2738.     
  2739.     var ssnText = oXMLtoHTML.selectSingleNode("//TR[@CLASS='Text']");
  2740.     var ssnComment = oXMLtoHTML.selectSingleNode("//TR[@CLASS='Comment']");
  2741.     var ssnBaseURL = oXMLtoHTML.selectSingleNode("//xsl:if[@expr='fnIsURLEmpty(this)']");
  2742.     
  2743.     var oVisibilityOptions = new Object();
  2744.     oVisibilityOptions.nMode = cvoHTMLExport;
  2745.  
  2746.     oVisibilityOptions.bShowContents    = !fnGetSetting(ccsHTMLVHideContents , 0, true);
  2747.     oVisibilityOptions.bShowFieldNames    = !fnGetSetting(ccsHTMLVHideFieldNames , 0, true);
  2748.     oVisibilityOptions.bShowTitle        = !fnGetSetting(ccsHTMLVHideTitle , 0, true);
  2749.     oVisibilityOptions.bShowText        = !fnGetSetting(ccsHTMLVHideText , 0, true);
  2750.     oVisibilityOptions.bShowComment        = !fnGetSetting(ccsHTMLVHideComment , 0, true);
  2751.     oVisibilityOptions.bShowURL        = !fnGetSetting(ccsHTMLVHideURL , 0, true);
  2752.  
  2753.     if (     ( ! oVisibilityOptions.bShowTitle ) &&
  2754.         ( ! oVisibilityOptions.bShowText ) &&
  2755.         ( ! oVisibilityOptions.bShowComment )    ) {
  2756.         
  2757.         oVisibilityOptions.bShowContents = 
  2758.         oVisibilityOptions.bShowFieldNames = 
  2759.             oVisibilityOptions.bShowTitle = 
  2760.         oVisibilityOptions.bShowText = 
  2761.         oVisibilityOptions.bShowComment = 
  2762.         oVisibilityOptions.bShowURL =  true;
  2763.     };
  2764.  
  2765.  
  2766.     var result = showModalDialog("ctVisibilityOptions.htm",
  2767.         oVisibilityOptions,
  2768.         "help:no; resizable:no; status:no;");
  2769.  
  2770.     if ( ! result ) {
  2771.         return;
  2772.     };
  2773.  
  2774.     if ( ( ! oVisibilityOptions.bShowTitle) &&
  2775.          ( ! oVisibilityOptions.bShowText) && 
  2776.          ( ! oVisibilityOptions.bShowComment ) ) {
  2777.          
  2778.          alert(L_NOTHING_TO_EXPORT);
  2779.          return;
  2780.     };
  2781.  
  2782.     fnSetSetting(ccsHTMLVHideContents,    !oVisibilityOptions.bShowContents, true);
  2783.     fnSetSetting(ccsHTMLVHideFieldNames,    !oVisibilityOptions.bShowFieldNames, true);
  2784.     fnSetSetting(ccsHTMLVHideTitle,        !oVisibilityOptions.bShowTitle, true);
  2785.     fnSetSetting(ccsHTMLVHideText,        !oVisibilityOptions.bShowText, true);
  2786.     fnSetSetting(ccsHTMLVHideComment,     !oVisibilityOptions.bShowComment, true);
  2787.     fnSetSetting(ccsHTMLVHideURL,         !oVisibilityOptions.bShowURL, true);
  2788.          
  2789.     if ( ! oVisibilityOptions.bShowTitle ) {
  2790.         if (oVisibilityOptions.bShowURL) {
  2791.  
  2792.             var ssnBaseURLHolder = null;            
  2793.             if ( oVisibilityOptions.bShowText) {
  2794.                 ssnBaseURLHolder = ssnText;
  2795.             }
  2796.             else if (oVisibilityOptions.bShowComment) {
  2797.                 ssnBaseURLHolder = ssnComment;
  2798.             };
  2799.  
  2800.             if (ssnBaseURLHolder) {
  2801.                 var ssnFieldData =
  2802.                     ssnBaseURLHolder.selectSingleNode(".//TD[@CLASS='FieldData']");
  2803.                 ssnFieldData.insertBefore(
  2804.                     ssnBaseURL.parentNode.removeChild(ssnBaseURL),
  2805.                     ssnFieldData.firstChild);
  2806.             };
  2807.         };
  2808.     
  2809.         ssnFieldsParent.removeChild(ssnTitleAndDate);
  2810.     }
  2811.     else if ( ! oVisibilityOptions.bShowURL) {
  2812.         ssnBaseURL.parentNode.removeChild(ssnBaseURL);
  2813.     };
  2814.  
  2815.     if ( ! oVisibilityOptions.bShowText ) {
  2816.         ssnFieldsParent.removeChild(ssnText);
  2817.     };
  2818.     
  2819.     if ( ! oVisibilityOptions.bShowComment ) {
  2820.         ssnFieldsParent.removeChild(ssnComment);
  2821.     };
  2822.  
  2823.         if ( ! oVisibilityOptions.bShowFieldNames ) {
  2824.         ssnFieldsParent.parentNode.setAttribute("COLS", 1);
  2825.  
  2826.                 var allFieldTitles = ssnFieldsParent.selectNodes(
  2827.                     "//TD[@CLASS='FieldTitle']");
  2828.         for (var i = 0; i < allFieldTitles.length; i ++) {
  2829.             allFieldTitles[i].parentNode.removeChild(allFieldTitles[i]);
  2830.         };
  2831.  
  2832.                 var allFieldDatas = ssnFieldsParent.selectNodes(
  2833.                     "//TD[@CLASS='FieldData']");
  2834.         for (var i = 0; i < allFieldDatas.length; i ++) {
  2835.             allFieldDatas[i].setAttribute("WIDTH", "99%");
  2836.         };
  2837.  
  2838.         };
  2839.  
  2840.     if ( ! oVisibilityOptions.bShowContents ) {
  2841.         var ssnContentsSection = oXMLtoHTML.selectSingleNode(
  2842.                 "//xsl:if[@test='./CogTracker:ctNODE//CogTracker:ctFRAGMENT']");
  2843.         if (ssnContentsSection) {
  2844.             ssnContentsSection.parentNode.removeChild(ssnContentsSection);
  2845.         };
  2846.     };
  2847.     
  2848.     var ssnFilterPoint = 
  2849.         oXMLtoHTML.selectSingleNode("//xsl:template[@match='root']/xsl:apply-templates/@select");
  2850.     
  2851.     ssnFilterPoint.nodeValue = "/root/CogTracker:ctDATABASE[@UIN='"
  2852.         + goCurrentFolderUIN + "']|//CogTracker:ctNODE[@UIN='"
  2853.         + goCurrentFolderUIN + "']";
  2854.  
  2855.     var ctNode = goBase.selectSingleNode("/root/CogTracker:ctDATABASE[@UIN='"
  2856.         + goCurrentFolderUIN + "']|//CogTracker:ctNODE[@UIN='"
  2857.         + goCurrentFolderUIN + "']");
  2858.     
  2859.     
  2860.     var sHTML = goBase.transformNode(oXMLtoHTML);
  2861.     if (sHTML == null || sHTML == "") {
  2862.  
  2863.         alert(L_Transform_Failed);
  2864.         return;
  2865.     };
  2866.  
  2867.     sHTML = sHTML.replace(/!BR\/!/g, "<BR/>");
  2868.     sHTML = fnSpecialRemoveWhiteSpaces(sHTML);
  2869.     
  2870.     var bUnicode = true;
  2871.     try {
  2872.         var fso = new ActiveXObject("Scripting.FileSystemObject");
  2873.         var ts = fso.CreateTextFile(ctlBrowser.FileName, true, bUnicode);
  2874.         ts.Write(sHTML);
  2875.         ts.Close();
  2876.         
  2877.     }
  2878.     catch (err) {
  2879.         alert(L_Unable_To_Save_A_File + ctlBrowser.FileName + 
  2880.             L_HTML_FAIL_DIAG);
  2881.         return;
  2882.     };
  2883. };
  2884.  
  2885. /*SendByMail-related return codes*/
  2886. var smcmOK = 0;
  2887. var smcmCancel = 1;
  2888. var smcmNoClients = 2;
  2889. var smcmNoDefaultClient = 3;
  2890. var smcmNoDLL = 4;
  2891. var smcmNoInterface = 5;
  2892. var smcmMAPI_E_ATTACHMENT_OPEN_FAILURE = 6;
  2893. var smcmMAPI_E_ATTACHMENT_WRITE_FAILURE = 7;
  2894. var smcmMAPI_E_FAILURE = 8;
  2895. var smcmMAPI_E_INSUFFICIENT_MEMORY = 9;
  2896. var smcmMAPI_E_LOGIN_FAILURE = 10;
  2897. var smcmMAPI_E_USER_ABORT = 11;
  2898. var smcmMAPI_E_UNKNOWN = 12;
  2899. var smcmMAPI_E_ATTACHMENT_NOT_FOUND = 14;
  2900.  
  2901. var sbmDefault = 1;
  2902. var sbmSelected = 2;
  2903.  
  2904. function fnSendByMail() {
  2905.  
  2906.     fnPerformSendByMail(sbmDefault);
  2907. };
  2908.  
  2909. function fnSelectClientAndSendByMail() {
  2910.  
  2911.     fnPerformSendByMail(sbmSelected);
  2912. };
  2913.  
  2914. var L_UnknownMailClient = "Mail client\n";
  2915. var L_MailClient = " mail client\n";
  2916. var L_ReportedThat = "reported that there was\n\n";
  2917. var L_WhileSending = "\n\nwhile attaching file to a message.";
  2918. var L_NoMailClients = "There are no compatible mail clients found.";
  2919. var L_NoDefaultClient = "There are no default mail client selected.";
  2920.  
  2921. var L_NoDLL = "does not define appropriate library\nfor sending files."; 
  2922. var L_NoInterface = "does not define appropriate interface\nfor sending files."; 
  2923.  
  2924. var L_GeneralError = "a general error";
  2925. var L_AttOpenFail = "attachment open failure";
  2926. var L_AttWriteFail = "attachment write failure";
  2927. var L_InsuffisientMem = "insuffisient memory";
  2928. var L_LoginFailure = "login failure";
  2929. var L_UserAbort = "user abort";
  2930. var L_AttNotFound = "attachment not found";
  2931.  
  2932.  
  2933. function ReportSendByMailError(someCode) {
  2934.     var oHelper = fnGetHelperObject();
  2935.  
  2936.     var sClientName = oHelper.MailClientName;
  2937.  
  2938.     var sMessage = "";
  2939.  
  2940.     if (someCode == smcmNoClients) {
  2941.         alert(L_NoMailClients);
  2942.         return;
  2943.     }
  2944.     else if (someCode == smcmNoDefaultClient) {
  2945.         alert(L_NoDefaultClient);
  2946.         return;
  2947.     };
  2948.  
  2949.  
  2950.  
  2951.     if ( sClientName != "" && sClientName != null) {
  2952.         sMessage = sClientName + L_MailClient;
  2953.     }
  2954.     else {
  2955.         sMessage = L_UnknownMailClient;
  2956.     };
  2957.  
  2958.         switch(someCode) {
  2959.         case smcmNoDLL:
  2960.             sMessage += L_NoDLL;
  2961.             break;
  2962.  
  2963.         case smcmNoInterface:
  2964.             sMessage += L_NoInterface;
  2965.             break;
  2966.                         
  2967.  
  2968.             case smcmCancel:
  2969.             case smcmMAPI_E_FAILURE:
  2970.                 sMessage += L_ReportedThat + L_GeneralError + L_WhileSending;
  2971.                 break;
  2972.         
  2973.             case smcmMAPI_E_ATTACHMENT_OPEN_FAILURE:
  2974.                 sMessage += L_ReportedThat + L_AttOpenFail + L_WhileSending;
  2975.                 break;
  2976.  
  2977.             case smcmMAPI_E_ATTACHMENT_WRITE_FAILURE:
  2978.                 sMessage += L_ReportedThat + L_AttWriteFail + L_WhileSending;
  2979.                 break;
  2980.  
  2981.         case smcmMAPI_E_ATTACHMENT_NOT_FOUND:
  2982.                 sMessage += L_ReportedThat + L_AttNotFound + L_WhileSending;
  2983.             break;
  2984.         case smcmMAPI_E_FAILURE:
  2985.                 sMessage += L_ReportedThat +  L_GeneralError + L_WhileSending;
  2986.                 break;
  2987.  
  2988.         case smcmMAPI_E_INSUFFICIENT_MEMORY:
  2989.                 sMessage += L_ReportedThat + L_InsuffisientMem + L_WhileSending;
  2990.                 break;
  2991.  
  2992.         case smcmMAPI_E_LOGIN_FAILURE:
  2993.                 sMessage += L_ReportedThat + L_LoginFailure + L_WhileSending;
  2994.                 break;
  2995.  
  2996.         case smcmMAPI_E_USER_ABORT:
  2997.                 sMessage += L_ReportedThat + L_UserAbort + L_WhileSending;
  2998.                 break;
  2999.  
  3000.         case smcmMAPI_E_UNKNOWN:
  3001.                 sMessage += L_ReportedThat + L_GeneralError + L_WhileSending;
  3002.                 break;
  3003.         default:
  3004.                 sMessage += L_ReportedThat + L_GeneralError + L_WhileSending;
  3005.                 break;
  3006.         };
  3007.  
  3008.         alert(sMessage);
  3009. };
  3010.  
  3011. function fnPerformSendByMail(someMode) {
  3012.  
  3013.     var oHelper = fnGetHelperObject();
  3014.  
  3015.         var nResult = 0;
  3016.     switch(someMode) {
  3017.         case sbmDefault:
  3018.             top.fnGetMainToolbar().all.SendByMailButton.ct_unstick();
  3019.  
  3020.             nResult = oHelper.SetupDefaultMailClient();
  3021.  
  3022.             if (nResult != smcmOK) {
  3023.                 ReportSendByMailError(nResult);
  3024.                 return;
  3025.             };
  3026.             break;
  3027.  
  3028.         case sbmSelected:
  3029.  
  3030.             var MenuButton = fnGetMainToolbar().all.SendByMailButton;
  3031.  
  3032.  
  3033.             var nLeft = 0; var nTop = 0;
  3034.  
  3035.             nLeft += MenuButton.offsetLeft +  0 +
  3036.                 MenuButton.document.body.offsetLeft +
  3037.                 MenuButton.document.parentWindow.screenLeft;
  3038.  
  3039.             nTop += MenuButton.offsetTop +  MenuButton.offsetHeight +
  3040.                 MenuButton.document.body.offsetTop +
  3041.                 MenuButton.document.parentWindow.screenTop;
  3042.  
  3043.             nResult = oHelper.ShowMailClientsMenu(nLeft, nTop, "");
  3044.  
  3045.             top.fnGetMainToolbar().all.ShowMailClientsButton.ct_unstick();
  3046.  
  3047.             if (nResult != smcmOK && nResult != smcmCancel) {
  3048.                 ReportSendByMailError(nResult);
  3049.                 return;
  3050.             };
  3051.             if (nResult == smcmCancel) {
  3052.                 return;
  3053.             };
  3054.             break;
  3055.  
  3056.         default:
  3057.             return;
  3058.     };
  3059.  
  3060.  
  3061.  
  3062.     var sPath = gsCurrentPath;
  3063.  
  3064. //    sPath = "\\sad.qqq\\ewrwer";
  3065. //    sPath = "\\";
  3066. //    sPath = "\\.qq";
  3067.  
  3068.     var nFileNameStart = sPath.lastIndexOf("\\");
  3069.     if (nFileNameStart == -1) {
  3070.         nFileNameStart = 0;
  3071.     }
  3072.     else {
  3073.         nFileNameStart++;
  3074.     };
  3075.     var nFileNameEnd = sPath.lastIndexOf(".");
  3076.     if ( ( nFileNameEnd == -1 ) || ( nFileNameEnd <  nFileNameStart) ) {
  3077.         nFileNameEnd = sPath.length;// - nFileNameStart + 1;
  3078.     }
  3079.     else {
  3080.     };
  3081.  
  3082.     var sFileName = sPath.slice(nFileNameStart, nFileNameEnd);
  3083.     var sFileExt  = sPath.slice(nFileNameEnd + 1);
  3084.  
  3085.  
  3086.  
  3087.     var sTempPath = oHelper.GetTempFilePath(sFileName, sFileExt);
  3088.     if (sTempPath == null || sTempPath == "" ) {
  3089.  
  3090.         alert(L_FailedToGenerateTempFile);
  3091.         return;
  3092.     };
  3093.  
  3094.  
  3095. //Turned off, because Outlook Express, per ex, does not return until closed.
  3096. //    fnShowWaitCursor();
  3097.  
  3098.     if (fnPerformImportExport(cixSendByMail, sTempPath)) {
  3099.  
  3100.         nResult = oHelper.SendFileToMailClient(sTempPath, oHelper.MailClientName,
  3101.                         oHelper.MailClientDLLPath);
  3102. //        fnHideWaitCursor();
  3103.  
  3104.         if (nResult != smcmOK && nResult != smcmMAPI_E_USER_ABORT) {
  3105.             ReportSendByMailError(nResult);
  3106.  
  3107.             return;
  3108.         };
  3109.     }
  3110.     else {
  3111. //        fnHideWaitCursor();
  3112.     };
  3113.  
  3114. };
  3115.  
  3116. function fnOnBusy() {
  3117.     var sFilePath = fnGetHelperObject().FileOpenFilePath;
  3118.     if ( (gsCurrentPath.toUpperCase() != sFilePath.toUpperCase()) &&
  3119.          (sFilePath != "") )
  3120.         alert(L_BUSY);
  3121. };
  3122.  
  3123. function fnOnFileOpenRequest() {
  3124.  
  3125.     var sFilePath = fnGetHelperObject().FileOpenFilePath;
  3126.         
  3127.     if ( sFilePath != "" && 
  3128.          gsCurrentPath.toUpperCase() != sFilePath.toUpperCase()) {
  3129.  
  3130.         var ctfResult = fnPrepareToChangeDatabase();
  3131.         if (ctfResult != ctfFailure) {
  3132.             fnSaveChangedDatabase();
  3133.         };
  3134.  
  3135.         goCurrentFolderUIN = -1;
  3136.         if ( (sFilePath.charAt(0) == '"')  && (sFilePath.charAt(sFilePath.length - 1) == '"')) {
  3137.             sFilePath = sFilePath.substr(1, sFilePath.length - 2);
  3138.         }
  3139.         fnLoadFile(sFilePath);
  3140.     }
  3141.  
  3142. };
  3143.  
  3144. function fnShowAbout() {
  3145.  
  3146.     var NewDialogHeight = "386px";
  3147.     var NewDialogWidth = "500px";
  3148. /*    var xPos =  document.body.clientLeft +
  3149.             document.body.clientWidth/2;
  3150.     var yPos =  document.body.clientTop +
  3151.             document.body.clientHeight/2;
  3152.  
  3153.     xPos -= parseInt(NewDialogWidth.slice(0,NewDialogWidth.length-2), 10)/2;
  3154.     yPos -= parseInt(NewDialogHeight.slice(0,NewDialogHeight.length-2), 10)/2;
  3155. */
  3156.     showModalDialog("ctAbout.htm", top.oHTA.version,
  3157. /*            "help:no; resizable:no; status:no; center:no;" +
  3158.             " dialogLeft:"    + xPos.toString() + "px;" +
  3159.             "dialogTop:"    + yPos.toString() + "px;" +
  3160. */            "help:no; resizable:no; status:no; center:yes; " + 
  3161.             "dialogHeight:" +  NewDialogHeight + ";" +
  3162.             "dialogWidth:"  +  NewDialogWidth + ";");
  3163. };
  3164.  
  3165. function fnShowHelp() {
  3166.     
  3167.     fnShowTheHelp();
  3168.  
  3169. };