home *** CD-ROM | disk | FTP | other *** search
/ ftp.tcs3.com / ftp.tcs3.com.tar / ftp.tcs3.com / DRIVERS / Audio / Office2010 / ProPlus.WW / ProPsWW.cab / UTILITYFUNCTIONS.JS4 < prev    next >
Text File  |  2007-02-04  |  52KB  |  1,771 lines

  1. /*********************************************************************
  2.                                  Notice
  3.  
  4. You may not modify, use, copy or distribute this file or its contents. 
  5. Internal interfaces referenced in this file are nonpublic, unsupported 
  6. and subject to change without notice. These interfaces may not be 
  7. utilized in other software applications or components.
  8.  
  9.  
  10. *********************************************************************/
  11.  
  12. var g_FormRecord;
  13. var g_arrTabContents;
  14. var g_arrIntervals = new Array();
  15. var g_AlertShown = false;
  16. var g_ContactContextMenuFieldName = "";
  17. var g_IsMacro = false;
  18.  
  19. // Invalid date.
  20. var INVALID_DATE = -0xFFFFFFFFFFFFF;
  21.  
  22. // This enum is defined in code, but we
  23. // can't access it from here, so just redeclare it.
  24. var FormsUIState_Unknown            = 0;
  25. var FormsUIState_HomePage            = 1;
  26. var FormsUIState_ViewDesign            = 2;
  27. var FormsUIState_FormDesign            = 3;
  28. var FormsUIState_MacroDesign        = 4;
  29. var FormsUIState_SettingsAndOptions    = 5;
  30. var FormsUIState_ViewData            = 6;
  31. var FormsUIState_DocumentDisplay    = 7;
  32.  
  33. // These enums are defined in IDL, but we
  34. // can't access them from here, so just redeclare it.
  35. var GrooveFormsToolFieldSizeType_Characters = 0;
  36. var GrooveFormsToolFieldSizeType_Pixels = 1;
  37. var GrooveFormsToolFieldSizeType_Percent = 2;
  38.  
  39. var GrooveFormsToolTextFieldInitialValueType_Static = 0;
  40. var GrooveFormsToolTextFieldInitialValueType_Unique = 1;
  41. var GrooveFormsToolTextFieldInitialValueType_UserDisplayName = 2;
  42. var GrooveFormsToolTextFieldInitialValueType_TelespaceDisplayName = 3;
  43. var GrooveFormsToolTextFieldInitialValueType_ToolDisplayName = 4;
  44. var GrooveFormsToolTextFieldInitialValueType_Function = 5;
  45.  
  46. var GrooveFormsToolDateFieldInitialValueType_Static = 0;
  47. var GrooveFormsToolDateFieldInitialValueType_Today = 1;
  48. var GrooveFormsToolDateFieldInitialValueType_Tomorrow = 2;
  49. var GrooveFormsToolDateFieldInitialValueType_Function = 3;
  50.  
  51. var GrooveFormsToolDateTimeFieldInitialValueType_Static = 0;
  52. var GrooveFormsToolDateTimeFieldInitialValueType_Now = 1;
  53. var GrooveFormsToolDateTimeFieldInitialValueType_Function = 2;
  54.  
  55. // These enums are defined in IDL, but we can't access them
  56. // from here, so just redeclare them
  57. var    GrooveFormsToolContactOutputInformation_Fingerprint = 0;
  58. var    GrooveFormsToolContactOutputInformation_EmailAddress = 1;
  59. var    GrooveFormsToolContactOutputInformation_Affiliation = 2;
  60. var    GrooveFormsToolContactOutputInformation_FullName = 3;
  61. var    GrooveFormsToolContactOutputInformation_Alias = 4;
  62. var    GrooveFormsToolContactOutputInformation_ExplanatoryURL = 5;
  63. var    GrooveFormsToolContactOutputInformation_Title = 6;
  64. var    GrooveFormsToolContactOutputInformation_Role = 7;
  65. var    GrooveFormsToolContactOutputInformation_GivenName = 8;
  66. var    GrooveFormsToolContactOutputInformation_FamilyName = 9;
  67. var    GrooveFormsToolContactOutputInformation_OrganizationName = 10;
  68. var    GrooveFormsToolContactOutputInformation_OrganizationUnit = 11;
  69. var    GrooveFormsToolContactOutputInformation_AuthenticationColorString = 12;
  70. var    GrooveFormsToolContactOutputInformation_AuthenticationTooltip = 13;
  71. var GrooveFormsToolContactOutputInformation_WorkPhoneNumber = 14;
  72.  
  73. // NOTE: Input types are only used for new contacts.  Once
  74. // the contact has been set in the record it cannot be changed.
  75. // An exception will be generated if SetContactInfo is called
  76. // on a persisted contact.
  77. var    GrooveFormsToolContactInputInformation_FullName = 0;
  78. var    GrooveFormsToolContactInputInformation_EmailAddress = 1;
  79. var    GrooveFormsToolContactInputInformation_WorkPhoneNumber = 2;
  80. var    GrooveFormsToolContactInputInformation_ExplanatoryURL = 3;
  81. var    GrooveFormsToolContactInputInformation_Title = 4;
  82. var    GrooveFormsToolContactInputInformation_Role = 5;
  83. var    GrooveFormsToolContactInputInformation_GivenName = 6;
  84. var    GrooveFormsToolContactInputInformation_FamilyName = 7;
  85. var    GrooveFormsToolContactInputInformation_OrganizationName = 8;
  86. var    GrooveFormsToolContactInputInformation_OrganizationUnit = 9;
  87.  
  88. var GrooveContactOnlineState_Offline = 0;
  89. var GrooveContactOnlineState_OnlineAvailable = 1;
  90. var GrooveContactOnlineState_FreeToChat = 2;
  91. var GrooveContactOnlineState_Away = 3;
  92. var GrooveContactOnlineState_ExtendedAway = 4;
  93. var GrooveContactOnlineState_DoNotDisturb = 5;
  94.  
  95. // Defined in tom.idl.
  96. var tomUndefined = -9999999;
  97.  
  98. var tomFalse = 0;
  99. var tomTrue = -1;
  100.  
  101. var tomListBullet = 1;
  102.  
  103. var tomSingle = 1;
  104.  
  105. var tomAlignLeft = 0;
  106. var tomAlignCenter = 1;
  107. var tomAlignRight = 2;
  108. var tomAlignJustify = 3;
  109.  
  110. var GrooveTextParaFlag_AlignLeft = 0x00000000;
  111. var GrooveTextParaFlag_AlignCenter = 0x00000001;
  112. var GrooveTextParaFlag_AlignRight = 0x00000002;
  113. var GrooveTextParaFlag_AlignJustify = 0x00000003;
  114. var GrooveTextParaFlag_NumberNone = 0x00000000;
  115. var GrooveTextParaFlag_NumberBullet = 0x00000010;
  116. var GrooveTextParaFlag_IndentRelative = 0x00001000;
  117. var GrooveTextParaFlag_UseAlign = 0x01000000;
  118. var GrooveTextParaFlag_UseNumber = 0x02000000;
  119.  
  120.  
  121. function getScriptHostQI(i_Interface)
  122. {
  123.     try
  124.     {
  125.         // If these variables are valid, then you are in a form.
  126.         if (typeof g_IsSearch != "undefined")
  127.         {
  128.             if (!g_IsSearch && !g_IsFormPreview && !g_IsPrinting)
  129.                 return eval("window.external." + i_Interface);
  130.             else if (g_IsSearch)
  131.             {
  132.                 if (i_Interface.indexOf("IGrooveFormsToolUIDelegate") != -1)
  133.                 {
  134.                     var UIDelegate = window.external.IGrooveFormsToolSearchDialogDelegatePrivate.GetUIDelegate();
  135.                     return eval("UIDelegate." + i_Interface);
  136.                 }
  137.                 else
  138.                     return eval("window.external." + i_Interface);
  139.             }
  140.             else if (g_IsPrinting)
  141.             {
  142.                 if (i_Interface.indexOf("IGrooveFormsToolUIDelegate") != -1)
  143.                 {
  144.                     var UIDelegate = window.external.IGrooveFormsToolPrintDialogDelegatePrivate.GetUIDelegate();
  145.                     return eval("UIDelegate." + i_Interface);
  146.                 }
  147.                 else
  148.                     return eval("window.external." + i_Interface);
  149.             }
  150.             else
  151.             {
  152.                 var ScriptDispatch = window.external.GetScriptDispatch();
  153.                 if (ScriptDispatch != null)
  154.                     return eval("ScriptDispatch.GetUIDelegate()." + i_Interface);
  155.             }
  156.         }
  157.         else if (g_IsMacro)
  158.         {
  159.             var ScriptDispatch = window.external.IGrooveFormsToolUIMacroWindowPrivate;
  160.             if (ScriptDispatch != null)
  161.                 return eval("ScriptDispatch.GetUIDelegate()." + i_Interface);
  162.         }
  163.         else
  164.             return eval("window.external." + i_Interface);
  165.     }
  166.     catch (error)
  167.     {
  168.         if (!g_AlertShown)
  169.         {
  170.             alert("This web page should only be opened from within Groove. Please close the window.");
  171.             g_AlertShown = true;
  172.         }
  173.         return null;
  174.     }
  175. }
  176.  
  177. function getImageBindableURLByID(i_ID)
  178. {
  179.     return getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").GetBindableURLByID(i_ID);
  180. }
  181.  
  182. function processCallout(i_Function)
  183. {
  184.     try
  185.     {
  186.         var blnContinue = true;
  187.         if (typeof i_Function == "function" && i_Function() == false)
  188.             blnContinue = false;
  189.     }
  190.     catch (error) { }
  191.     finally
  192.     {
  193.         return blnContinue;
  194.     }
  195. }
  196.  
  197. function processCalloutWithParameter(i_Function, i_Parameter)
  198. {
  199.     try
  200.     {
  201.         var blnContinue = true;
  202.         if (typeof i_Function == "function" && i_Function(i_Parameter) == false)
  203.             blnContinue = false;
  204.     }
  205.     catch (error) { }
  206.     finally
  207.     {
  208.         return blnContinue;
  209.     }
  210. }
  211.  
  212. function getValueFromQueryString(i_Key, i_Querystring, i_Default)
  213. {
  214.     var strReturn = "";
  215.     if (typeof i_Default != "undefined")
  216.         strReturn = i_Default;
  217.  
  218.     var objRegExp = new RegExp(i_Key + "=[^&]*", "");
  219.     if (objRegExp.test(i_Querystring))
  220.     {
  221.         var strPair = objRegExp.exec(i_Querystring);
  222.         var arrPair = strPair[0].split("=");
  223.         if (arrPair.length == 2 && arrPair[0] == i_Key)
  224.             strReturn = unescape(arrPair[1]);
  225.     }
  226.  
  227.     return strReturn;
  228. }
  229.  
  230.  
  231. // === status bar functions ============================
  232. // these functions control the display of the status bar
  233. function displayStatusBar(i_Message, i_Icon)
  234. {
  235.     if (!g_IsSearch && !g_IsPreviewPane && !g_IsPrinting)
  236.         getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayStatusBarMessage(i_Message, i_Icon);
  237. }
  238.  
  239. function clearStatusBar()
  240. {
  241.     if (!g_IsSearch && !g_IsPreviewPane && !g_IsPrinting)
  242.         getScriptHostQI("IGrooveFormsToolUIDelegate").ClearStatusBarMessage();
  243. }
  244.  
  245. // === event handlers ============================
  246. // these functions handle events for form elements
  247. function onBlurHandler()
  248. {
  249.     eventHandler("OnBlur");
  250. }
  251.  
  252. function onFocusHandler()
  253. {
  254.     eventHandler("OnFocus");
  255. }
  256.  
  257. function onClickHandler()
  258. {
  259.     eventHandler("OnClick");
  260. }
  261.  
  262. function onChangeHandler()
  263. {
  264.     eventHandler("OnChange");
  265. }
  266.  
  267. function eventHandler(i_strEvent)
  268. {
  269.     var objElement = event.srcElement;
  270.     eventHandlerById(i_strEvent, objElement.id);
  271. }
  272.  
  273. function eventHandlerById(i_strEvent, i_strId)
  274. {
  275.     try
  276.     {
  277.         if (g_BypassEventCallouts)
  278.             return;
  279.  
  280.         if (i_strId != null && i_strId != "")
  281.         {
  282.             var objElement = document.getElementById(i_strId);
  283.             if (eval("typeof " + i_strId + "_" + i_strEvent) != "undefined")
  284.                 eval(i_strId + "_" + i_strEvent + "(objElement)");
  285.         }
  286.     }
  287.     catch (error) { }
  288. }
  289.  
  290. // === object replacement ==========================================
  291. // these functions are called to replace object tags with empty divs
  292. function subInDivs()
  293. {
  294.     g_arrTabs = new Array();
  295.     g_arrTabContents = new Array();
  296.  
  297.     // Display the contents of all tabs when printing.
  298.     var arrDivs = document.getElementsByTagName("DIV");
  299.     for (var i = 0; i < arrDivs.length; i++)
  300.     {
  301.         var strObjectType = arrDivs[i].getAttribute("OBJECTTYPE");
  302.         if (strObjectType == "TabContents" && arrDivs[i].style.display == "none")
  303.         {
  304.             arrDivs[i].insertAdjacentHTML("beforeBegin", "<HR ID=\"" + arrDivs[i].id + "_line\" SIZE=\"1\" COLOR=\"#000000\">");
  305.             arrDivs[i].style.display = "";
  306.             g_arrTabContents.push(arrDivs[i]);
  307.         }
  308.     }
  309.  
  310.     // Hide all tabs when printing.
  311.     var arrDivs = document.getElementsByTagName("SPAN");
  312.     for (var i = 0; i < arrDivs.length; i++)
  313.     {
  314.         var strObjectType = arrDivs[i].getAttribute("OBJECTTYPE");
  315.         if (strObjectType == "Tab")
  316.         {
  317.             arrDivs[i].style.display = "none";
  318.             g_arrTabs.push(arrDivs[i]);
  319.         }
  320.     }
  321.  
  322.     // Replace all textarea and input boxes.
  323.     var arrInputs = document.getElementsByTagName("INPUT");
  324.     for (var i = 0; i < arrInputs.length; i++)
  325.     {
  326.         if (arrInputs[i].type == "text" || arrInputs[i].type == "password")
  327.             Object2Div(arrInputs[i], null, "inputPreview");
  328.     }
  329.  
  330.     var arrTextAreas = document.getElementsByTagName("TEXTAREA");
  331.     for (var i = 0; i < arrTextAreas.length; i++)
  332.         Object2Div(arrTextAreas[i], null, "textareaPreview");
  333.  
  334.     var arrSelects = document.getElementsByTagName("SELECT");
  335.     for (var i = 0; i < arrSelects.length; i++)
  336.         Object2Div(arrSelects[i], null, "selectPreview");
  337.  
  338.     // Handle rich text and attachments objects.
  339.     var arrObject = document.getElementsByTagName("OBJECT");
  340.     for (var i = 0; i < arrObject.length; i++)
  341.     {
  342.         var strDataType = arrObject[i].getAttribute("DataType");
  343.         var ObjectText = "";
  344.         if (strDataType == "RichText")
  345.         {
  346.             ObjectText = getScriptHostQI("IGrooveFormsToolUIDelegatePrintFormPrivate").OpenRTFContent(arrObject[i]);
  347.         }
  348.         else if (strDataType == "Attachments")
  349.         {
  350.             var AttachmentNameEnum = getScriptHostQI("IGrooveFormsToolUIDelegatePrintFormPrivate").OpenAttachmentNameEnum(g_AttachmentsElement);
  351.             while (AttachmentNameEnum.HasMore())
  352.             {
  353.                 ObjectText += AttacmentNameEnum.OpenNext();
  354.                 ObjectText += "<BR>";
  355.             }
  356.         }
  357.         Object2Div(arrObject[i], ObjectText);
  358.     }
  359.  
  360.     // Hide all buttons on the form.
  361.     var arrButtons = document.getElementsByTagName("BUTTON");
  362.     for (var i = 0; i < arrButtons.length; i++)
  363.     {
  364.         arrButtons[i].style.display = "none";
  365.     }
  366. }
  367.  
  368. function putBackTextAreas()
  369. {
  370.     var arrInputs = document.getElementsByTagName("INPUT");
  371.     for (var i = 0; i < arrInputs.length; i++)
  372.     {
  373.         if (arrInputs[i].type == "text" || arrInputs[i].type == "password")
  374.             DivBackToObject(arrInputs[i]);
  375.     }
  376.  
  377.     var arrTextAreas = document.getElementsByTagName("TEXTAREA");
  378.     for (var i = 0; i < arrTextAreas.length; i++)
  379.         DivBackToObject(arrTextAreas[i]);
  380.  
  381.     var arrSelects = document.getElementsByTagName("SELECT");
  382.     for (var i = 0; i < arrSelects.length; i++)
  383.         DivBackToObject(arrSelects[i]);
  384.  
  385.     // Handle rich text objects.
  386.     var arrObject = document.getElementsByTagName("OBJECT");
  387.     var strDataType;
  388.     for (var i = 0; i < arrObject.length; i++)
  389.     {
  390.         strDataType = arrObject[i].getAttribute("DataType");
  391.         if (strDataType == "RichText")
  392.             DivBackToObject(arrObject[i]);
  393.     }
  394.     
  395.     // Display all buttons on the form.
  396.     var arrButtons = document.getElementsByTagName("BUTTON");
  397.     for (var i = 0; i < arrButtons.length; i++)
  398.     {
  399.         arrButtons[i].style.display = "";
  400.     }
  401.  
  402.     // Display all tabs on a form.
  403.     for (var i = 0; i < g_arrTabs.length; i++)
  404.     {
  405.         g_arrTabs[i].style.display = "";
  406.     }
  407.  
  408.     // Re-hide the contents of all tabs that should be hidden.
  409.     for (var i = 0; i < g_arrTabContents.length; i++)
  410.     {
  411.         var objLine = document.getElementById(g_arrTabContents[i].id + "_line");
  412.         if (objLine != null)
  413.             objLine.removeNode(true);
  414.         g_arrTabContents[i].style.display = "none";
  415.     }
  416. }
  417.  
  418. function Object2Div(i_Object, i_Content, i_ClassName)
  419. {
  420.     var oNewDiv;
  421.  
  422.     oNewDiv = document.createElement("DIV");
  423.     oNewDiv.className = i_ClassName;
  424.     oNewDiv.id = i_Object.uniqueID + "_div";
  425.  
  426.     if (i_Content != null)
  427.     {
  428.         oNewDiv.innerHTML = i_Content;
  429.     }
  430.     else
  431.     {
  432.         var ObjectValue = i_Object.value;
  433.         if (i_Object.type == "password")
  434.         {
  435.             var ObjectValueLength = ObjectValue.length;
  436.             ObjectValue = "";
  437.             for (var i = 0; i < ObjectValueLength; i++)
  438.             {
  439.                 ObjectValue += "*";
  440.             }
  441.         }
  442.         else if (i_Object.type == "select-multiple")
  443.         {
  444.             var OptionValueArray = new Array();
  445.             for (var i = 0; i < i_Object.options.length; i++)
  446.             {
  447.                 if (i_Object.options[i].selected)
  448.                     OptionValueArray.push(i_Object.options[i].text);
  449.             }
  450.  
  451.             ObjectValue = OptionValueArray.join("\n");
  452.         }
  453.         oNewDiv.innerText = ObjectValue;
  454.     }
  455.  
  456.     i_Object.parentNode.insertBefore(oNewDiv, i_Object);
  457.     i_Object.style.display = "none";
  458. }
  459.  
  460. function DivBackToObject(i_Object)
  461. {
  462.     var oDivToRemove = document.all(i_Object.uniqueID + "_div");
  463.     if (oDivToRemove != null)
  464.         oDivToRemove.removeNode(true);
  465.  
  466.     i_Object.style.display = "";
  467. }
  468.  
  469. // === button handlers ============================================
  470. // these functions are called in response to a button being clicked
  471. function doCalendar(i_Name)
  472. {
  473.     try
  474.     {
  475.         // Get the INPUT object that the date value will be put into.
  476.         var objDate = document.getElementById(i_Name);
  477.         if (objDate != null)
  478.         {
  479.             var DateValue = objDate.value;
  480.  
  481.             // Clear any errors that the current date may have.
  482.             clearError(objDate, "Required");
  483.             clearError(objDate, "InvalidDate");
  484.             clearError(objDate, "Date");
  485.  
  486.             var bIsDateTime = false;
  487.             var FieldTypeAttribute = objDate.getAttribute("FIELDTYPE");
  488.             if (FieldTypeAttribute == FormObjectType_DateTime)
  489.                 bIsDateTime = true;
  490.  
  491.             // Get the new date from the choose date sub-form.
  492.             var FormatAttribute = objDate.getAttribute("FORMAT");
  493.             if (FormatAttribute != null)
  494.             {
  495.                 var intDateFormat = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").CreateDateFormatStyleFromAttributeValue(FormatAttribute);
  496.                 var intDate = getValidDateMillis(DateValue, intDateFormat, objDate);
  497.                 if (isNaN(intDate))
  498.                     intDate = new Date().valueOf();
  499.  
  500.                 var DateResult = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DisplayRawDatePickerDialog(intDate, intDateFormat, bIsDateTime);
  501.                 if (DateResult.Result == GrooveDialogBoxResultCode_OK)
  502.                 {
  503.                     var DateValue = DateResult.Data;
  504.  
  505.                     if (bIsDateTime)
  506.                     {
  507.                         var DateAndTimeEnum = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").FormatDateAndTime(DateValue, intDateFormat, 3);
  508.                         if (DateAndTimeEnum.HasMore());
  509.                             objDate.value = DateAndTimeEnum.OpenNext();
  510.                         var objTime = document.getElementById(i_Name + "_Time");
  511.                         if (objTime != null && DateAndTimeEnum.HasMore())
  512.                             objTime.value = DateAndTimeEnum.OpenNext();
  513.                     }
  514.                     else
  515.                     {
  516.                         DateValue = getScriptHostQI("IGrooveFormsToolUIDelegate").FormatDate(DateValue, intDateFormat);
  517.                         objDate.value = DateValue;
  518.                     }
  519.  
  520.                     // Set the dirty bit if it needs to be set.
  521.                     int_setIsDirty(true);
  522.  
  523.                     // Call onblur to validate the date.
  524.                     objDate.fireEvent("onblur");
  525.  
  526.                     // Call onchange for designer scripts to use.
  527.                     objDate.fireEvent("onchange");
  528.                 }
  529.             }
  530.         }
  531.     }
  532.     catch (error)
  533.     {
  534.         var Priv = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate");
  535.         // IDS_FORMS_TOOL_JS_DATE_SAVING_ERROR
  536.         getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayError(Priv.GetResourcedString(IDS_FORMS_TOOL_JS_DATE_SAVING_ERROR) + "\n\n" + error.description);
  537.     }
  538. }
  539.  
  540. // Rich text command bar button handlers.
  541. function doBold(i_Name)
  542. {
  543.     submitControlChar(i_Name, "B");
  544. }
  545.  
  546. function doItalic(i_Name)
  547. {
  548.     submitControlChar(i_Name, "I");
  549. }
  550.  
  551. function doUnderline(i_Name)
  552. {
  553.     submitControlChar(i_Name, "U");
  554. }
  555.  
  556. function submitControlChar(i_Name, i_String)
  557. {
  558.     var objTextView = document.getElementById(i_Name);
  559.     if (objTextView != null)
  560.     {
  561.         var CharCode = i_String.charCodeAt(0) & 0x1F;
  562.         objTextView.SubmitText(String.fromCharCode(CharCode));
  563.         objTextView.focus();
  564.     }
  565. }
  566.  
  567. function doAlignLeft(i_Name)
  568. {
  569.     submitParaChange(i_Name, GrooveTextParaFlag_UseAlign | GrooveTextParaFlag_AlignLeft, tomUndefined);
  570. }
  571.  
  572. function doCenter(i_Name)
  573. {
  574.     submitParaChange(i_Name, GrooveTextParaFlag_UseAlign | GrooveTextParaFlag_AlignCenter, tomUndefined);
  575. }
  576.  
  577. function doAlignRight(i_Name)
  578. {
  579.     submitParaChange(i_Name, GrooveTextParaFlag_UseAlign | GrooveTextParaFlag_AlignRight, tomUndefined);
  580. }
  581.  
  582. function doJustify(i_Name)
  583. {
  584.     submitParaChange(i_Name, GrooveTextParaFlag_UseAlign | GrooveTextParaFlag_AlignJustify, tomUndefined);
  585. }
  586.  
  587. function doBullets(i_Name)
  588. {
  589.     var objTextView = document.getElementById(i_Name);
  590.     if (objTextView != null)
  591.     {
  592.         var Flags = GrooveTextParaFlag_UseNumber;
  593.         var ListType = objTextView.TextCache.Document.Selection.Para.ListType;
  594.         if (ListType == tomUndefined)
  595.             Flags |= GrooveTextParaFlag_NumberBullet;
  596.         else if ((ListType & 0xFFFF) != tomListBullet)
  597.             Flags |= GrooveTextParaFlag_NumberBullet;
  598.         else
  599.             Flags |= GrooveTextParaFlag_NumberNone;
  600.  
  601.         submitParaChange(i_Name, Flags, tomUndefined);
  602.     }
  603. }
  604.  
  605. function doIncreaseIndent(i_Name)
  606. {
  607.     submitParaChange(i_Name, GrooveTextParaFlag_IndentRelative, 18.0);
  608. }
  609.  
  610. function doDecreaseIndent(i_Name)
  611. {
  612.     submitParaChange(i_Name, GrooveTextParaFlag_IndentRelative, -18.0);
  613. }
  614.  
  615. function doChooseFont(i_Name)
  616. {
  617.     var objTextView = document.getElementById(i_Name);
  618.     if (objTextView != null)
  619.     {
  620.         objTextView.ChooseFont();
  621.         objTextView.focus();
  622.     }
  623. }
  624.  
  625. function doChooseColor(i_Name)
  626. {
  627.     var objTextView = document.getElementById(i_Name);
  628.     if (objTextView != null)
  629.     {
  630.         objTextView.ChooseColor();
  631.         objTextView.focus();
  632.     }
  633. }
  634.  
  635. function submitParaChange(i_Name, i_Flags, i_Left)
  636. {
  637.     var objTextView = document.getElementById(i_Name);
  638.     if (objTextView != null)
  639.     {
  640.         var TabPositionEnum = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateDoubleEnum();
  641.         var TabFlagsEnum = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateLongEnum();
  642.  
  643.         objTextView.SubmitParaChange(i_Flags, tomUndefined, tomUndefined, i_Left, tomUndefined, tomUndefined, tomUndefined, TabPositionEnum, TabFlagsEnum);
  644.         objTextView.focus();
  645.     }
  646. }
  647.  
  648. function doSpellCheck(i_Name)
  649. {
  650.     var objTextView = document.getElementById(i_Name);
  651.     if (objTextView != null)
  652.     {
  653.         // GrooveTextKey_F7 = 1007 from GrooveTextTools.idl.
  654.         objTextView.SubmitKeyPress(1007, false, false);
  655.         objTextView.focus();
  656.     }
  657. }
  658.  
  659. function doHyperlink(i_Name)
  660. {
  661.     submitControlChar(i_Name, "H");
  662. }
  663.  
  664. function startInterval(i_Name)
  665. {
  666.     for (var i = 0; i < g_arrIntervals.length; i++)
  667.     {
  668.         if (g_arrIntervals[i].Name == i_Name)
  669.         {
  670.             g_arrIntervals[i].Stop();
  671.             break;
  672.         }
  673.     }
  674.  
  675.     var Interval = new CommandBarInterval();
  676.     Interval.Start(i_Name);
  677.     g_arrIntervals.push(Interval);
  678. }
  679.  
  680. function stopInterval(i_Name)
  681. {
  682.     for (var i = 0; i < g_arrIntervals.length; i++)
  683.     {
  684.         if (g_arrIntervals[i].Name == i_Name)
  685.         {
  686.             g_arrIntervals[i].Stop();
  687.             g_arrIntervals[i] = null;
  688.             g_arrIntervals.splice(i, 1);
  689.         }
  690.     }
  691. }
  692.  
  693. function updateCommandBar(i_Name)
  694. {
  695.     var objTextView = document.getElementById(i_Name);
  696.     if (objTextView != null)
  697.     {
  698.         setCommandPressedState(i_Name + "Bold", objTextView.SelectionFont.Bold == tomTrue);
  699.         setCommandPressedState(i_Name + "Italic", objTextView.SelectionFont.Italic == tomTrue);
  700.         setCommandPressedState(i_Name + "Underline", objTextView.SelectionFont.Underline == tomSingle);
  701.         setCommandPressedState(i_Name + "AlignLeft", objTextView.TextCache.Document.Selection.Para.Alignment == tomAlignLeft);
  702.         setCommandPressedState(i_Name + "Center", objTextView.TextCache.Document.Selection.Para.Alignment == tomAlignCenter);
  703.         setCommandPressedState(i_Name + "AlignRight", objTextView.TextCache.Document.Selection.Para.Alignment == tomAlignRight);
  704.         setCommandPressedState(i_Name + "Justify", objTextView.TextCache.Document.Selection.Para.Alignment == tomAlignJustify);
  705.  
  706.         var ListType = objTextView.TextCache.Document.Selection.Para.ListType;
  707.         if (ListType == tomUndefined || ((ListType & 0xFFFF) != tomListBullet))
  708.             setCommandPressedState(i_Name + "Bullets", false);
  709.         else
  710.             setCommandPressedState(i_Name + "Bullets", true);
  711.  
  712.         setCommandDisabledState(i_Name + "Spellcheck", !objTextView.CanCheckSpelling);
  713.     }
  714. }
  715.  
  716. // Object to store command bar interval data.
  717. function CommandBarInterval()
  718. {
  719.     this.Name;
  720.     this.ID;
  721. }
  722.  
  723. CommandBarInterval.prototype.Start = IntervalStart;
  724. CommandBarInterval.prototype.Stop = IntervalStop;
  725.  
  726. function IntervalStart(i_Name)
  727. {
  728.     this.Name = i_Name;
  729.     this.ID = window.setInterval("updateCommandBar('" + i_Name + "')", 250);
  730. }
  731.  
  732. function IntervalStop()
  733. {
  734.     window.clearInterval(this.ID);
  735. }
  736.  
  737. // Attachment command bar button handlers.
  738. function doAddAttachments()
  739. {
  740.     try
  741.     {
  742.         if (g_AttachmentsObject != null && g_AttachmentsElement != null)
  743.             getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").AddAttachments(g_AttachmentsObject, g_AttachmentsElement);
  744.     }
  745.     catch (error)
  746.     {
  747.         var strError = "There was an error adding the attachment, most likely caused by the form reloading in response to a design change or because the file may be in use by another program. Please try adding the attachment again, after correcting the issue.";
  748.         getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayError(strError);
  749.     }
  750. }
  751.  
  752. function doDeleteSelectedAttachments()
  753. {
  754.     if (g_AttachmentsObject != null)
  755.         getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").DeleteAttachments(g_AttachmentsObject);
  756. }
  757.  
  758. function doLaunchSelectedAttachments()
  759. {
  760.     if (g_AttachmentsObject != null)
  761.         getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").LaunchAttachments(g_AttachmentsObject.object, g_AttachmentsObject.id, g_RecordID);
  762. }
  763.  
  764. function doSaveSelectedAttachments()
  765. {
  766.     if (g_AttachmentsObject != null)
  767.         getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").SaveAttachments(g_AttachmentsObject);
  768. }
  769.  
  770. // Add a trim method to the String object.
  771. String.prototype.trim = function()
  772. {
  773.     // Replace leading and trailing spaces with an empty string.
  774.     return this.replace(/(^\s*)|(\s*$)/g, "");
  775. }
  776.  
  777. // A utility function to get the top or left position of a given object.
  778. function getOffset(i_objPos, i_strDir)
  779. {
  780.     var intOffset = 0;
  781.     var objOffset = i_objPos;
  782.     while (objOffset.tagName != "BODY")
  783.     {
  784.         if (i_strDir == "top")
  785.             intOffset += objOffset.offsetTop;
  786.         else if (i_strDir == "left")
  787.             intOffset += objOffset.offsetLeft;
  788.  
  789.         objOffset = objOffset.offsetParent;
  790.     }
  791.     return intOffset;
  792. }
  793.  
  794. function showContactMenu(i_FieldName)
  795. {
  796.     g_ContactContextMenuFieldName = i_FieldName;
  797.  
  798.     window.event.cancelBubble = true;
  799.     window.event.returnValue = false;
  800.  
  801.     var XPos = window.event.screenX;
  802.     var YPos = window.event.screenY;
  803.  
  804.     window.setTimeout(function () { showContactMenuDelayed(i_FieldName, XPos, YPos); }, 100);
  805. }
  806.  
  807. function sendMessage(i_FieldName)
  808. {
  809.     window.event.cancelBubble = true;
  810.  
  811.     window.setTimeout(function () { sendMessageDelayed(i_FieldName); }, 100);
  812. }
  813.  
  814. function showContactMenuDelayed(i_FieldName, i_XPos, i_YPos)
  815. {
  816.     var ContactField = document.getElementById(i_FieldName);
  817.     if (ContactField != null)
  818.     {
  819.         var Contact = g_RegisteredContactFields[i_FieldName];
  820.         if (Contact != null)
  821.             getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").DisplayContactContextMenu(Contact, i_XPos, i_YPos, g_IsReadOnly);
  822.     }
  823. }
  824.  
  825. function executeContactCommand(i_CommandName)
  826. {
  827.     window.setTimeout(function () { executeContactCommandDelayed(i_CommandName); }, 100);
  828. }
  829.  
  830. function executeContactCommandDelayed(i_CommandName)
  831. {
  832.     var ContactField = document.getElementById(g_ContactContextMenuFieldName);
  833.     if (ContactField != null)
  834.     {
  835.         var ContactURL = ContactField.getAttribute("CONTACTURL");
  836.         var ContactURLEnum = CreateBSTREnumFromArray(new Array(ContactURL));
  837.  
  838.         // We have to make sure that the field is in the contact store.
  839.         ensureContactInStore(g_ContactContextMenuFieldName, ContactURL);
  840.  
  841.         var pMessagingServices = getScriptHostQI("IGrooveFormsToolMessagingServices");
  842.         var pContactServices = getScriptHostQI("IGrooveFormsToolContactServices");
  843.  
  844.         switch (i_CommandName)
  845.         {
  846.             case "SendMessage":
  847.                 pMessagingServices.DisplaySendInstantMessageDialog(ContactURLEnum);
  848.                 break;
  849.             case "InviteToWorkspace":
  850.                 pMessagingServices.DisplaySendInvitationDialog(ContactURLEnum);
  851.                 break;
  852.             case "SendAlertToComeHere":
  853.                 pMessagingServices.SendInvitation(ContactURLEnum);
  854.                 break;
  855.             case "Properties":
  856.                 pContactServices.DisplayContactProperties(ContactURL);
  857.                 break;
  858.             case "AddToMyContacts":
  859.             {
  860.                 if (pContactServices.DoesContactExist(ContactURL))
  861.                 {
  862.                     var Contact = pContactServices.OpenContact(ContactURL);
  863.                     pContactServices.AddContactToPersonalContacts(Contact);
  864.                 }
  865.                 break;
  866.             }
  867.             case "Remove":
  868.             {
  869.                 if (getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayYesNoMessageBox("Are you sure you want to remove this contact? This operation cannot be undone.", "Remove Contact"))
  870.                     removeContact(g_ContactContextMenuFieldName);
  871.  
  872.                 break;
  873.             }
  874.         }
  875.     }
  876. }
  877.  
  878. function removeContact(i_FieldName)
  879. {
  880.     var Contact = g_RegisteredContactFields[i_FieldName];
  881.  
  882.     // Unregister the contact.
  883.     unregisterContact(Contact, i_FieldName);
  884.     // Display the contact information for a contact.
  885.     displayContactInfo(null, i_FieldName, true);
  886.     // Set the dirty bit when a contact is removed.
  887.     setIsDirty();
  888.     // Set the attribute on the field so we know that this is empty.
  889.     var ContactField = document.getElementById(i_FieldName);
  890.     if (ContactField != null)
  891.     {
  892.         ContactField.setAttribute("CONTACTTYPE", "removed");
  893.         ContactField.removeAttribute("CONTACTURL");
  894.     }
  895.     // Call the _OnChange event so scripts can work on this.
  896.     contactOnChangeEvent(i_FieldName, null, Contact);
  897. }
  898.  
  899. function ensureContactInStore(i_FieldName, i_ContactURL)
  900. {
  901.     var ContactField = document.getElementById(i_FieldName);
  902.     var Contact = g_RegisteredContactFields[i_FieldName];
  903.     if (ContactField != null && Contact != null)
  904.     {
  905.         var ContactType = ContactField.getAttribute("CONTACTTYPE");
  906.         if (ContactType == "temporary")
  907.             return;
  908.  
  909.         if (g_IsReadOnly || (ContactType != "new" && ContactType != "temporary"))
  910.         {
  911.             var FormRecord = GetFormRecord();
  912.             var FieldNameInline = i_FieldName + "_Inline";
  913.             if (FormRecord.HasField(i_FieldName) && FormRecord.HasField(FieldNameInline))
  914.             {
  915.                 var IsContactInline = FormRecord.OpenField(FieldNameInline);
  916.                 if (IsContactInline)
  917.                 {
  918.                     // Unregister the original contact.
  919.                     unregisterContact(Contact, i_FieldName);
  920.  
  921.                     // Set the contact and inline fields to the record.
  922.                     if (!g_IsReadOnly)
  923.                         FormRecord.SetField(i_FieldName, Contact);
  924.                     FormRecord.SetField(FieldNameInline, false);
  925.  
  926.                     // Display the contact information for the contact.
  927.                     displayContactInfo(Contact, i_FieldName, true);
  928.                 }
  929.             }
  930.         }
  931.         else if (ContactType == "new")
  932.         {
  933.             // Unregister the original contact.
  934.             unregisterContact(Contact, i_FieldName);
  935.  
  936.             // Set the attribute on the field so we know that this is temporary.
  937.             ContactField.setAttribute("CONTACTTYPE", "temporary");
  938.             // Add to the contact store as a temporary contact.
  939.             var NewContact = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").AddTemporaryContactToStore(Contact);
  940.  
  941.             // Display the contact information for the new contact.
  942.             displayContactInfo(NewContact, i_FieldName, true);
  943.         }
  944.     }
  945. }
  946.  
  947. function sendMessageDelayed(i_FieldName)
  948. {
  949.     var ContactField = document.getElementById(i_FieldName);
  950.     if (ContactField != null)
  951.     {
  952.         var ContactURL = ContactField.getAttribute("CONTACTURL");
  953.         if (ContactURL != null && ContactURL != "")
  954.         {
  955.             var Contact = g_RegisteredContactFields[i_FieldName];
  956.             if (Contact != null)
  957.             {
  958.                 if (Contact.IsGroovey)
  959.                 {
  960.                     // We have to make sure that the field is in the contact store.
  961.                     ensureContactInStore(i_FieldName, ContactURL);
  962.  
  963.                     var ContactURLEnum = CreateBSTREnumFromArray(new Array(ContactURL));
  964.                     getScriptHostQI("IGrooveFormsToolMessagingServices").DisplaySendInstantMessageDialog(ContactURLEnum);
  965.                 }
  966.             }
  967.         }
  968.     }
  969. }
  970.  
  971. function selectContact(i_FieldName)
  972. {
  973.     var ContactField = document.getElementById(i_FieldName);
  974.     if (ContactField != null)
  975.     {
  976.         var OriginalContact = g_RegisteredContactFields[i_FieldName];
  977.  
  978.         var Contact = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").DisplayContactSearchDialog();
  979.         if (Contact != null)
  980.         {
  981.             // Unregister the original contact.
  982.             unregisterContact(OriginalContact, i_FieldName);
  983.             // Display the contact information for the new contact.
  984.             displayContactInfo(Contact, i_FieldName, true);
  985.             // Set the dirty bit when a new contact is selected.
  986.             setIsDirty();
  987.             // Set the attribute on the field so we know that this is new.
  988.             ContactField.setAttribute("CONTACTTYPE", "new");
  989.             // Call the _OnChange event so scripts can work on this.
  990.             contactOnChangeEvent(i_FieldName, Contact, OriginalContact);
  991.         }
  992.  
  993.         validateRequired(ContactField);
  994.     }
  995. }
  996.  
  997. function contactOnChangeEvent(i_FieldName, i_Contact, i_OriginalContact)
  998. {
  999.     try
  1000.     {
  1001.         if (eval("typeof " + i_FieldName + "_OnChange") != "undefined")
  1002.             eval(i_FieldName + "_OnChange(i_Contact, i_OriginalContact)");
  1003.     }
  1004.     catch (error) {}
  1005. }
  1006.  
  1007. function setContactName(i_FieldName, i_Name)
  1008. {
  1009.     var ContactSpan = document.getElementById(i_FieldName + "_Name");
  1010.     if (ContactSpan != null)
  1011.         ContactSpan.innerText = i_Name;
  1012. }
  1013.  
  1014. function displayContactInfo(i_Contact, i_FieldName, i_ToBeRegistered)
  1015. {
  1016.     if (i_Contact != null)
  1017.     {
  1018.         var ContactField = document.getElementById(i_FieldName);
  1019.         if (ContactField != null)
  1020.         {
  1021.             ContactField.setAttribute("CONTACTURL", i_Contact.ContactURL);
  1022.  
  1023.             // Set the color of the contact text if we should.
  1024.             if (ContactField.getAttribute("USEAUTHENTICATIONCOLOR") != null)
  1025.                 ContactField.style.color = i_Contact.GetContactInfo(GrooveFormsToolContactOutputInformation_AuthenticationColorString);
  1026.  
  1027.             var ContactName = i_Contact.GetContactInfo(GrooveFormsToolContactOutputInformation_FullName);
  1028.             setContactName(i_FieldName, ContactName);
  1029.  
  1030.             displayAwarenessInfo(i_Contact, GrooveContactOnlineState_Offline, "Offline", 0, ContactField);
  1031.  
  1032.             // Register the contact for awareness updates if the icon is visible.
  1033.             if (i_ToBeRegistered)
  1034.                 registerContact(i_Contact, i_FieldName);
  1035.         }
  1036.     }
  1037.     else
  1038.     {
  1039.         setContactName(i_FieldName, "No contact selected");
  1040.  
  1041.         var ContactField = document.getElementById(i_FieldName);
  1042.         if (ContactField != null)
  1043.         {
  1044.             ContactField.removeAttribute("CONTACTURL");
  1045.  
  1046.             ContactField.title = "";
  1047.             ContactField.style.color = "";
  1048.         }
  1049.  
  1050.         var ContactIcon = document.getElementById(i_FieldName + "_Icon");
  1051.         if (ContactIcon != null)
  1052.             ContactIcon.style.display = "none";
  1053.     }
  1054. }
  1055.  
  1056. function registerContact(i_Contact, i_FieldName)
  1057. {
  1058.     if (i_Contact != null)
  1059.     {
  1060.         // Add the field name to the list of registered contacts.
  1061.         g_RegisteredContactFields[i_FieldName] = i_Contact;
  1062.         // Register the contact in the UIDelegate to receive awareness updates.
  1063.         getScriptHostQI("IGrooveFormsToolAwarenessServicesPrivate").RegisterContact(i_Contact);
  1064.     }
  1065. }
  1066.  
  1067. function unregisterContact(i_Contact, i_FieldName)
  1068. {
  1069.     if (i_Contact != null)
  1070.     {
  1071.         // Remove the contact from the global array.
  1072.         delete g_RegisteredContactFields[i_FieldName];
  1073.         // Unregister the contact if there is not still a reference to it.
  1074.         getScriptHostQI("IGrooveFormsToolAwarenessServicesPrivate").UnregisterContact(i_Contact);
  1075.     }
  1076. }
  1077.  
  1078. function OnlineStateChanged2(i_Contact, i_OnlineState, i_StateText, i_TimeWentIdle)
  1079. {
  1080.     if (i_Contact != null)
  1081.     {
  1082.         for (var i = 0; i < g_ContactFields.length; i++)
  1083.         {
  1084.             displayAwarenessInfo(i_Contact, i_OnlineState, i_StateText, i_TimeWentIdle, g_ContactFields[i]);
  1085.         }
  1086.     }
  1087. }
  1088.  
  1089. function displayAwarenessInfo(i_Contact, i_OnlineState, i_StateText, i_TimeWentIdle, i_ContactField)
  1090. {
  1091.     if (i_Contact != null)
  1092.     {
  1093.         var ContactURL = i_Contact.ContactURL;
  1094.         if (i_ContactField != null && i_ContactField.getAttribute("CONTACTURL") == ContactURL)
  1095.         {
  1096.             if (i_ContactField.getAttribute("ISAWARENESSICONHIDDEN") == null)
  1097.             {
  1098.                 var ContactIcon = document.getElementById(i_ContactField.id + "_Icon");
  1099.                 if (ContactIcon != null)
  1100.                 {
  1101.                     var IconSrc = "../../../ToolIcons/PersonalContact.ico";
  1102.                     if (i_Contact.IsGroovey)
  1103.                     {
  1104.                         switch (i_OnlineState)
  1105.                         {
  1106.                             case GrooveContactOnlineState_OnlineAvailable:
  1107.                             {
  1108.                                 if (i_TimeWentIdle > 0)
  1109.                                     IconSrc = "../../../ToolIcons/OnlineIdle.ico";
  1110.                                 else
  1111.                                     IconSrc = "../../../ToolIcons/OnLine.ico";
  1112.  
  1113.                                 break;
  1114.                             }
  1115.                             case GrooveContactOnlineState_Offline:
  1116.                                 IconSrc = "../../../ToolIcons/Offline.ico";
  1117.                                 break;
  1118.                         }
  1119.                     }
  1120.  
  1121.                     ContactIcon.src = IconSrc;
  1122.                     ContactIcon.style.display = "inline";
  1123.                 }
  1124.  
  1125.                 i_ContactField.setAttribute("TIMEWENTIDLE", i_TimeWentIdle);
  1126.             }
  1127.  
  1128.             updateContactTooltip(i_ContactField, i_Contact, i_TimeWentIdle);
  1129.         }
  1130.     }
  1131. }
  1132.  
  1133. function updateIdleTime(i_FieldName)
  1134. {
  1135.     var ContactField = document.getElementById(i_FieldName);
  1136.     if (ContactField != null)
  1137.     {
  1138.         var TimeWentIdle = ContactField.getAttribute("TIMEWENTIDLE");
  1139.         if (TimeWentIdle > 1)
  1140.         {
  1141.             var ContactURL = ContactField.getAttribute("CONTACTURL");
  1142.             if (ContactURL != "")
  1143.             {
  1144.                 var Contact = g_RegisteredContactFields[i_FieldName];
  1145.                 if (Contact != null)
  1146.                     updateContactTooltip(ContactField, Contact, TimeWentIdle);
  1147.             }
  1148.         }
  1149.     }
  1150. }
  1151.  
  1152. function updateContactTooltip(i_ContactField, i_Contact, i_TimeWentIdle)
  1153. {
  1154.     if (i_ContactField != null && i_Contact != null)
  1155.     {
  1156.         var sFullName = i_Contact.GetContactInfo(GrooveFormsToolContactOutputInformation_FullName);
  1157.         var sAlias    = i_Contact.GetContactInfo(GrooveFormsToolContactOutputInformation_Alias);
  1158.         var sOrg      = i_Contact.GetContactInfo(GrooveFormsToolContactOutputInformation_OrganizationName);
  1159.         var sTip      = i_Contact.GetContactInfo(GrooveFormsToolContactOutputInformation_AuthenticationTooltip);
  1160.  
  1161.         var sToolTip = sFullName;
  1162.         {
  1163.             if (sAlias && sAlias != sFullName)
  1164.                 sToolTip = sAlias + "\n" + sAlias;
  1165.             if (sOrg)
  1166.                 sToolTip = sToolTip + "\n" + sOrg;
  1167.             if (sTip)
  1168.                 sToolTip = sToolTip + "\n" + sTip;
  1169.  
  1170.             if (i_TimeWentIdle > 1)
  1171.             {
  1172.                 var Minutes = Math.floor((new Date().valueOf() - i_TimeWentIdle ) / 60000);
  1173.                 var Hours = Math.floor(Minutes / 60);
  1174.  
  1175.                 var IdleText = "";
  1176.                 if (Hours < 24)
  1177.                 {
  1178.                     Minutes %= 60;
  1179.                     IdleText = "\nIdle for ";
  1180.                     if (Hours == 1)
  1181.                         IdleText += Hours + " hour";
  1182.                     else if (Hours > 1)
  1183.                         IdleText += Hours + " hours";
  1184.                     if (Hours > 0 && Minutes > 0)
  1185.                         IdleText += " and ";
  1186.                     if (Minutes > 0)
  1187.                         IdleText += Minutes + " minutes";
  1188.                 }
  1189.                 else
  1190.                 {
  1191.                     IdleText = "\nIdle since " + GetApp().FormatDateTime(i_TimeWentIdle, GrooveIntlDateFormatStyle_Default, GrooveIntlDateFormatStyle_Default);
  1192.                 }
  1193.                 sToolTip += IdleText;
  1194.             }
  1195.         }
  1196.  
  1197.         i_ContactField.title = sToolTip;
  1198.     }
  1199. }
  1200.  
  1201. // === tab handlers ================
  1202. // these functions handle tab events
  1203.  
  1204. function tabClick(i_objTab, i_objTabGroup)
  1205. {
  1206.     var strOldTabName = i_objTabGroup.ActiveTabName;
  1207.     var strNewTabName = i_objTab.id;
  1208.     if (strNewTabName != strOldTabName)
  1209.     {
  1210.         var objOldTab = document.getElementById(strOldTabName);
  1211.         if (objOldTab != null)
  1212.             objOldTab.className = "inactiveTab";
  1213.         var objOldTabContents = document.getElementById(strOldTabName + "Contents");
  1214.         if (objOldTabContents != null)
  1215.             objOldTabContents.style.display = "none";
  1216.  
  1217.         i_objTab.className = "activeTab";
  1218.         var objNewTabContents = document.getElementById(strNewTabName + "Contents");
  1219.         if (objNewTabContents != null)
  1220.             objNewTabContents.style.display = "block";
  1221.  
  1222.         i_objTabGroup.ActiveTabName = strNewTabName;
  1223.  
  1224.         int_RefreshErrorIcons();
  1225.     }
  1226.  
  1227.     event.cancelBubble = true;
  1228. }
  1229.  
  1230. // Misc functions
  1231. function getUniqueID()
  1232. {
  1233.     return int_getUniqueID();
  1234. }
  1235.  
  1236. function int_getUniqueID()
  1237. {
  1238.     // format is firstpart-second part where first part is:
  1239.     //     First letter of first name+ first two letters of last name + last letter
  1240.     // Last part is:
  1241.     //    Number of ticks- always increasing so entries you create are always ascending
  1242.     //    in sequence.
  1243.     // Example: JOZE-5WWTYC
  1244.  
  1245.     // Extract ticks in milliseconds, converted to base16 uppercase string
  1246.     var d = new Date();
  1247.     var HexMilliseconds = d.getTime().toString(16);
  1248.     HexMilliseconds = HexMilliseconds.toUpperCase();
  1249.  
  1250.     // take the high order characters, e.g. the last nine characters 
  1251.     var HexUnique = HexMilliseconds.slice(-9);
  1252.  
  1253.     // get current user name
  1254.     var UserName = getScriptHostQI("IGrooveFormsToolUIDelegate").CurrentAuthorName;
  1255.  
  1256.     // clean the name.  First replace x.500 OU slashes with spaces
  1257.     var filteredUserName = UserName.replace(/\//,"\x20");
  1258.  
  1259.     // upcase
  1260.     filteredUserName = filteredUserName.toUpperCase();
  1261.  
  1262.     // handle special cases for name for short length
  1263.     var AlphaUnique;
  1264.     if (filteredUserName.length <= 4)
  1265.     {
  1266.         AlphaUnique = filteredUserName;
  1267.     }
  1268.     else
  1269.     {
  1270.         // split the username into it's possible token parts. 
  1271.  
  1272.         // Use the first and second tokens as likely unique first name, last name.
  1273.         // It's possible in the worst case to have first/middle/last/OU/.../, but 
  1274.         // just use first two tokens since we don't have specific structured 
  1275.         // fields in the user name -it's just a string!
  1276.  
  1277.         // split tokens separated by one or more spaces
  1278.         var TokenArray = filteredUserName.split(/\s+/);
  1279.         
  1280.         // first char of 1st token
  1281.         var Prefix1 = TokenArray[0].slice(0,1); 
  1282.  
  1283.         // first 2 chars of 2nd token if there is one, else remainder of 1st token
  1284.         var Prefix2;
  1285.         if (TokenArray.length > 1 && TokenArray[1].length >= 2)
  1286.         {
  1287.             Prefix2 = TokenArray[1].slice(0,2);
  1288.  
  1289.             // last char of 2nd token
  1290.             LastChar = TokenArray[1].slice(-1);
  1291.  
  1292.             Prefix2 = Prefix2+LastChar;
  1293.         }
  1294.         else
  1295.             Prefix2 = TokenArray[0].slice(1,2);
  1296.  
  1297.         AlphaUnique = Prefix1 + Prefix2;
  1298.     }
  1299.  
  1300.     return (AlphaUnique + "-" + HexUnique);
  1301. }
  1302.  
  1303. function grooveNavigate(i_URL)
  1304. {
  1305.     getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").GrooveNavigate(i_URL);
  1306. }
  1307.  
  1308. function int_GetLookupStringForObject(i_ObjectName)
  1309. {
  1310.     var TargetString = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").GetLookupTargetString(i_ObjectName);
  1311.     return TargetString;
  1312. }
  1313.  
  1314. function int_GetLookupStringForObjectFromMacro(i_ObjectName, i_FormsToolUIDelegate)
  1315. {
  1316.     var TargetString = i_FormsToolUIDelegate.IGrooveFormsToolUIDelegatePrivate.GetLookupTargetString(i_ObjectName);
  1317.     return TargetString;
  1318. }
  1319.  
  1320. // Pass through functions called from PublicFunctions.js.
  1321. function int_GetApp()
  1322. {
  1323.     return getScriptHostQI("IGrooveFormsToolUIDelegate");
  1324. }
  1325.  
  1326. function int_CreateBSTREnumFromArray(i_Array)
  1327. {
  1328.     var BSTREnumCreate = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateBSTREnum();
  1329.     
  1330.     for (var i = 0; i < i_Array.length; i++)
  1331.     {
  1332.         BSTREnumCreate.IGrooveBSTREnumCreate.Add(i_Array[i]);
  1333.     }
  1334.     
  1335.     return BSTREnumCreate.IGrooveBSTREnum;
  1336. }
  1337.  
  1338. function int_SetFieldLabel(i_FieldName, i_Label)
  1339. {
  1340.     var objCell = null;
  1341.     var objLabelCell = document.getElementById(i_FieldName + "_label");
  1342.     if (objLabelCell != null)
  1343.         objCell = objLabelCell;
  1344.     else
  1345.     {
  1346.         var objFieldCell = document.getElementById(i_FieldName + "_field");
  1347.         if (objFieldCell != null)
  1348.             objCell = objFieldCell;
  1349.     }
  1350.  
  1351.     if (objCell != null)
  1352.     {
  1353.         // Get the font tag if this is a standard field, otherwise
  1354.         // this is a field in a field group.
  1355.         if (objCell.tagName == "TD")
  1356.         {
  1357.             var arrFont = objCell.getElementsByTagName("FONT");
  1358.             if (arrFont.length > 0)
  1359.                 objCell = arrFont[0];
  1360.         }
  1361.  
  1362.         objCell.innerText = i_Label;
  1363.     }
  1364. }
  1365.  
  1366. function int_HideField(i_FieldName, i_bHide)
  1367. {
  1368.     var objLabel = document.getElementById(i_FieldName + "_label");
  1369.     if (objLabel != null)
  1370.     {
  1371.         if (i_bHide)
  1372.             objLabel.style.display = "none"
  1373.         else
  1374.             objLabel.style.display = "inline";
  1375.     }
  1376.  
  1377.     var objField = document.getElementById(i_FieldName + "_field");
  1378.     if (objField != null)
  1379.     {
  1380.         if (i_bHide)
  1381.             objField.style.display = "none"
  1382.         else
  1383.             objField.style.display = "inline";
  1384.     }
  1385. }
  1386.  
  1387. function int_DisableField(i_FieldName, i_bDisable)
  1388. {
  1389.     var objField = document.getElementById(i_FieldName);
  1390.     if (objField != null && typeof objField.disabled != "undefined")
  1391.     {
  1392.         var intFieldType = objField.getAttribute("FIELDTYPE");
  1393.         if (intFieldType == FormObjectType_RichText)
  1394.             int_DisableRichTextField(objField, i_bDisable);
  1395.         else if (intFieldType == FormObjectType_Attachments)
  1396.             int_DisableAttachmentsField(objField, i_bDisable);
  1397.         else
  1398.             objField.disabled = i_bDisable;
  1399.  
  1400.         // Disable associated button if field has one.
  1401.         if (intFieldType == FormObjectType_DropDownList)
  1402.         {
  1403.             if (objField.getAttribute("CUSTOM") != null)
  1404.             {
  1405.                 var objCustomButton = document.getElementById(i_FieldName + "Button");
  1406.                 if (objCustomButton != null)
  1407.                     objCustomButton.disabled = i_bDisable;
  1408.             }
  1409.         }
  1410.         else if (intFieldType == FormObjectType_Date || intFieldType == FormObjectType_DateTime)
  1411.         {
  1412.             var objCalendarButton = document.getElementById(i_FieldName + "Button");
  1413.             if (objCalendarButton != null)
  1414.                 objCalendarButton.disabled = i_bDisable;
  1415.         }
  1416.     }
  1417. }
  1418.  
  1419. function int_DisableRichTextField(i_Field, i_bDisable)
  1420. {
  1421.     var FieldName = i_Field.id;
  1422.     setCommandDisabledState(FieldName + "Bold", i_bDisable);
  1423.     setCommandDisabledState(FieldName + "Italic", i_bDisable);
  1424.     setCommandDisabledState(FieldName + "Underline", i_bDisable);
  1425.     setCommandDisabledState(FieldName + "ChooseFont", i_bDisable);
  1426.     setCommandDisabledState(FieldName + "ChooseColor", i_bDisable);
  1427.     setCommandDisabledState(FieldName + "AlignLeft", i_bDisable);
  1428.     setCommandDisabledState(FieldName + "Center", i_bDisable);
  1429.     setCommandDisabledState(FieldName + "AlignRight", i_bDisable);
  1430.     setCommandDisabledState(FieldName + "Justify", i_bDisable);
  1431.     setCommandDisabledState(FieldName + "Bullets", i_bDisable);
  1432.     setCommandDisabledState(FieldName + "IncreaseIndent", i_bDisable);
  1433.     setCommandDisabledState(FieldName + "DecreaseIndent", i_bDisable);
  1434.     setCommandDisabledState(FieldName + "SpellCheck", i_bDisable);
  1435.     setCommandDisabledState(FieldName + "Hyperlink", i_bDisable);
  1436.  
  1437.     i_Field.ReadOnly = i_bDisable;
  1438.  
  1439.     if (i_bDisable)
  1440.         i_Field.setAttribute("ISDISABLEDBYSCRIPT", "true");
  1441.     else
  1442.         i_Field.removeAttribute("ISDISABLEDBYSCRIPT");
  1443. }
  1444.  
  1445. function int_DisableAttachmentsField(i_Field, i_bDisable)
  1446. {
  1447.     var FieldName = i_Field.id;
  1448.     setCommandDisabledState(FieldName + "Add", i_bDisable);
  1449.     setCommandDisabledState(FieldName + "Delete", i_bDisable);
  1450.  
  1451.     i_Field.Properties.SetIsDragDropTarget(!i_bDisable);
  1452.     i_Field.Properties2.SetReadOnlyMode(i_bDisable);
  1453.  
  1454.     if (i_bDisable)
  1455.         i_Field.setAttribute("ISDISABLEDBYSCRIPT", "true");
  1456.     else
  1457.         i_Field.removeAttribute("ISDISABLEDBYSCRIPT");
  1458. }
  1459.  
  1460. function int_RefreshErrorIcons()
  1461. {
  1462.     // Blur all fields that have errors to re-validate.
  1463.     var arrFields = new Array();
  1464.     for (var i = 0; i < g_arrErrors.length; i++)
  1465.     {
  1466.         var objError = g_arrErrors[i];
  1467.         var objField = document.getElementById(objError.FieldName);
  1468.         if (objField != null)
  1469.             arrFields.push(objField);
  1470.     }
  1471.  
  1472.     for (var i = 0; i < arrFields.length; i++)
  1473.     {
  1474.         arrFields[i].fireEvent("onblur");
  1475.     }
  1476. }
  1477.  
  1478. function int_RefreshPreviewPane()
  1479. {
  1480.     if (g_IsPreviewPane)
  1481.         initFormPage(g_RecordID);
  1482. }
  1483.  
  1484. function int_GetIsNew() { return g_IsNew; }
  1485. function int_GetIsSearch() { return g_IsSearch; }
  1486. function int_GetIsFormPreview() { return g_IsFormPreview; }
  1487. function int_GetIsPreviewPane() { return g_IsPreviewPane; }
  1488. function int_GetIsReadOnly() { return g_IsReadOnly; }
  1489. function int_GetIsResponse() { return g_IsResponse; }
  1490. function int_GetIsVersioned() { return g_IsVersioned; }
  1491. function int_GetRecordID() { return g_RecordID; }
  1492. function int_GetFormID() { return g_FormID; }
  1493. function int_GetSelectedID() { return g_SelectedID; }
  1494. function int_GetFormRecord() { return g_FormRecord; }
  1495.  
  1496. function int_OpenThisRecord()
  1497. {
  1498.     if (g_IsPreviewPane)
  1499.     {
  1500.         var SelectedID = -1;
  1501.         if (g_FormRecord)
  1502.             SelectedID = g_FormRecord.OpenField("_ParentID");
  1503.  
  1504.         GetApp().NavigateToForm(g_FormID, g_RecordID, SelectedID);
  1505.     }
  1506. }
  1507.  
  1508. function int_GetHTMLFieldValue(i_FieldName)
  1509. {
  1510.     var FieldValue = "";
  1511.  
  1512.     var Field = document.getElementById(i_FieldName);
  1513.     if (Field != null)
  1514.     {
  1515.         var FieldType = Field.type;
  1516.         if (FieldType == "text" || FieldType == "textarea" || FieldType == "password")
  1517.         {
  1518.             FieldValue = Field.value;
  1519.         }
  1520.         else if (FieldType == "checkbox")
  1521.         {
  1522.             if (Field.checked)
  1523.                 FieldValue = Field.value;
  1524.         }
  1525.         else if (FieldType == "select-one")
  1526.         {
  1527.             var SelectedIndex = Field.selectedIndex;
  1528.             if (SelectedIndex >= 0)
  1529.                 FieldValue = Field.options[SelectedIndex].value;
  1530.         }
  1531.         else if (FieldType == "select-multiple")
  1532.         {
  1533.             for (var i = 0; i < Field.options.length; i++)
  1534.             {
  1535.                 if (Field.options[i].selected)
  1536.                 {
  1537.                     var TempValue = Field.options[i].value;
  1538.                     if (TempValue == "")
  1539.                         TempValue = Field.options[i].text;
  1540.  
  1541.                     if (FieldValue != "")
  1542.                         FieldValue += "\n" + TempValue;
  1543.                     else
  1544.                         FieldValue += TempValue;
  1545.                 }
  1546.             }
  1547.         }
  1548.         else if (FieldType == "radio")
  1549.         {
  1550.             var RadioField = document.GrooveFormBase[i_FieldName];
  1551.             if (RadioField != null)
  1552.             {
  1553.                 for (var i = 0; i < RadioField.length; i++)
  1554.                 {
  1555.                     if (RadioField[i].checked)
  1556.                     {
  1557.                         FieldValue = RadioField[i].value;
  1558.                         break;
  1559.                     }
  1560.                 }
  1561.             }
  1562.         }
  1563.     }
  1564.  
  1565.     return FieldValue;
  1566. }
  1567.  
  1568. function int_GetHTMLFieldValueAsNumber(i_FieldName)
  1569. {
  1570.     var FieldValue = 0;
  1571.  
  1572.     var Field = document.getElementById(i_FieldName);
  1573.     if (Field != null)
  1574.     {
  1575.         var FieldType = Field.type;
  1576.         var FieldDataType = Field.getAttribute("DATATYPE");
  1577.  
  1578.         if (FieldType == "text" && FieldDataType == "Numeric")
  1579.         {
  1580.             var TempValue = Field.value;
  1581.             if (typeof TempValue != "undefined" && TempValue != null && TempValue != "")
  1582.                 FieldValue = getValidNumber(Field);
  1583.         }
  1584.     }
  1585.  
  1586.     return FieldValue;
  1587. }
  1588.  
  1589. function int_SetHTMLFieldValue(i_FieldName, i_Value)
  1590. {
  1591.     var Field = document.getElementById(i_FieldName);
  1592.     if (Field != null)
  1593.     {
  1594.         var FieldType = Field.type;
  1595.  
  1596.         if (FieldType == "text" || FieldType == "textarea" || FieldType == "password")
  1597.         {
  1598.             Field.value = i_Value;
  1599.         }
  1600.         else if (FieldType == "checkbox")
  1601.         {
  1602.             if (i_Value != "")
  1603.                 Field.checked = true;
  1604.             else
  1605.                 Field.checked = false;
  1606.         }
  1607.         else if (FieldType == "select-one")
  1608.         {
  1609.             for (var i = 0; i < Field.options.length; i++)
  1610.             {
  1611.                 if (Field.options[i].value == i_Value)
  1612.                 {
  1613.                     Field.options[i].selected = true;
  1614.                     break;
  1615.                 }
  1616.             }
  1617.         }
  1618.         else if (FieldType == "select-multiple")
  1619.         {
  1620.             var ElementValueArray = i_Value.split("\n");
  1621.             for (var i = 0; i < ElementValueArray.length; i++)
  1622.             {
  1623.                 for (var j = 0; j < Field.options.length; j++)
  1624.                 {
  1625.                     if (Field.options[j].value == ElementValueArray[i])
  1626.                     {
  1627.                         Field.options[j].selected = true;
  1628.                         break;
  1629.                     }
  1630.                 }
  1631.             }
  1632.         }
  1633.         else if (FieldType == "radio")
  1634.         {
  1635.             var RadioField = document.GrooveFormBase[i_FieldName];
  1636.             if (RadioField)
  1637.             {
  1638.                 for (var i = 0; i < RadioField.length; i++)
  1639.                 {
  1640.                     if (RadioField[i].value == i_Value)
  1641.                     {
  1642.                         RadioField[i].checked = true;
  1643.                         break;
  1644.                     }
  1645.                 }
  1646.             }
  1647.         }
  1648.     }
  1649. }
  1650.  
  1651. function int_SetHTMLFieldValueAsNumber(i_FieldName, i_Value)
  1652. {
  1653.     var Field = document.getElementById(i_FieldName);
  1654.     if (Field != null)
  1655.     {
  1656.         var FieldName = Field.id;
  1657.         var FieldDataType = Field.getAttribute("DATATYPE");
  1658.  
  1659.         if (FieldDataType == "Numeric")
  1660.         {
  1661.             var FieldValue = "";
  1662.  
  1663.             var FieldTypeAttribute = Field.getAttribute("FIELDTYPE");
  1664.             if (FieldTypeAttribute == FormObjectType_Number)
  1665.                 FieldValue = formatNumericValue(Field, i_Value);
  1666.             else if (FieldTypeAttribute == FormObjectType_Currency)
  1667.                 FieldValue = formatCurrencyValue(Field, i_Value);
  1668.  
  1669.             Field.value = FieldValue;
  1670.         }
  1671.     }
  1672. }
  1673.  
  1674. function int_InsertBSTREnumIntoListField(i_BSTREnum, i_FieldName, i_bAllowDuplicates)
  1675. {
  1676.     var Field = document.getElementById(i_FieldName);
  1677.     if (Field != null)
  1678.     {
  1679.         while (i_BSTREnum.HasMore())
  1680.         {
  1681.             var Value = i_BSTREnum.OpenNext();
  1682.             if (!i_bAllowDuplicates)
  1683.             {
  1684.                 var bDuplicateFound = false;
  1685.                 for (var i = 0; i < Field.options.length; i++)
  1686.                 {
  1687.                     if (Field.options[i].value == Value)
  1688.                     {
  1689.                         bDuplicateFound = true;
  1690.                         break;
  1691.                     }
  1692.                 }
  1693.  
  1694.                 if (bDuplicateFound)
  1695.                     continue;
  1696.             }
  1697.  
  1698.             var NewOption = document.createElement("OPTION");
  1699.             NewOption.text = Value;
  1700.             NewOption.value = Value;
  1701.             Field.options.add(NewOption);
  1702.         }
  1703.     }
  1704. }
  1705.  
  1706. function int_DoesFunctionExist(i_FunctionName)
  1707. {
  1708.     if (eval("typeof " + i_FunctionName) == "function")
  1709.         return true;
  1710.     else
  1711.         return false;
  1712. }
  1713.  
  1714. function int_IsValidDate(i_Value)
  1715. {
  1716.     if (i_Value != INVALID_DATE)
  1717.         return true;
  1718.     else
  1719.         return false;
  1720. }
  1721.  
  1722. function int_HasValidationErrors()
  1723. {
  1724.     if (g_arrErrors.length > 0)
  1725.         return true;
  1726.     else
  1727.         return false;
  1728. }
  1729.  
  1730. function int_SetContactFieldValue(i_FieldName, i_Contact)
  1731. {
  1732.     if (i_Contact != null)
  1733.     {
  1734.         var ContactField = document.getElementById(i_FieldName);
  1735.         if (ContactField != null)
  1736.         {
  1737.             // Unregister the original contact.
  1738.             unregisterContact(g_RegisteredContactFields[i_FieldName], i_FieldName);
  1739.             // Display the contact information for the new contact.
  1740.             displayContactInfo(i_Contact, i_FieldName, true);
  1741.             // Set the dirty bit when a new contact is selected.
  1742.             setIsDirty();
  1743.             // Set the attribute on the field so we know that this is new.
  1744.             ContactField.setAttribute("CONTACTTYPE", "new");
  1745.         }
  1746.     }
  1747.     else
  1748.         removeContact(i_FieldName);
  1749. }
  1750.  
  1751. function int_GetContactFieldValue(i_FieldName)
  1752. {
  1753.     return g_RegisteredContactFields[i_FieldName];
  1754. }
  1755.  
  1756. // These functions used to be in PublicFunctions.js, so a copy is left here for
  1757. // backward compatibility.
  1758. function NavigateToForm(i_FormID, i_RecordID, i_SelectedID)
  1759. {
  1760.     if (typeof i_RecordID == "undefined" || i_RecordID == null)
  1761.         i_RecordID = -1;
  1762.     if (typeof i_SelectedID == "undefined" || i_SelectedID == null)
  1763.         i_SelectedID = -1;
  1764.  
  1765.     getScriptHostQI("IGrooveFormsToolUIDelegate").NavigateToForm(i_FormID, i_RecordID, i_SelectedID);
  1766. }
  1767.  
  1768. function NavigateToView(i_ViewID)
  1769. {
  1770.     getScriptHostQI("IGrooveFormsToolUIDelegate").NavigateToView(i_ViewID);
  1771. }