home *** CD-ROM | disk | FTP | other *** search
/ ftp.tcs3.com / ftp.tcs3.com.tar / ftp.tcs3.com / DRIVERS / Audio / Office2010 / ProPlus.WW / ProPsWW.cab / SUBMIT.JS4 < prev    next >
Text File  |  2007-02-04  |  83KB  |  2,532 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. // These variables defined in PublicFunctions.js.
  13. var g_IsNew = false;
  14. var g_IsSearch = false;
  15. var g_IsPreviewPane = false;
  16. var g_IsReadOnly = false;
  17. var g_IsResponse = false;
  18. var g_IsVersioned = false;
  19. var g_RecordID = -1;
  20. var g_FormID = -1;
  21. var g_SelectedID = -1;
  22. var g_IsFormPreview = false;
  23.  
  24. var g_IsFocusSet = false;
  25. var g_IsCreateAnother = false;
  26. var g_IsInitializing = false;
  27. var g_IsInitializingTextView = false;
  28. var g_IsInitializingDocumentShare = false;
  29.  
  30. var g_IsPreviewPaneRefresh = false;
  31. var g_IsViewSource = false;
  32. var g_IsPrinting = false;
  33. var g_HasDesignChanged = false;
  34. var g_BypassEventCallouts = false;
  35.  
  36. var g_NewRecord;
  37. var g_SearchType;
  38. var g_RichTextObjects = new Array();
  39. var g_DataListObjects = new Array();
  40. var g_ContactFields = new Array();
  41. var g_RegisteredContactFields = new Array();
  42. var g_AttachmentsObject;
  43. var g_AttachmentsElement;
  44.  
  45. var g_EnableTextViewCount = 0;
  46. var g_EnableDocumentShareCount = 0;
  47. var g_EnableDataListCount = 0;
  48.  
  49. var g_IsDirty = false;
  50. var g_SaveAsMain = false;
  51.  
  52.  
  53. // =====================================================
  54. // ===            Document Event Handlers            ===
  55. // =====================================================
  56.  
  57. document.onkeydown = keyDownEvent;
  58. document.oncontextmenu = contextMenuEvent;
  59.  
  60. function keyDownEvent()
  61. {
  62.     var objElement = event.srcElement;
  63.  
  64.     // Only allow 'Backspace' key in writable text type fields.
  65.     if (event.keyCode == 8 && ((objElement.type != "text" && objElement.type != "textarea" && objElement.type != "password") || objElement.readOnly))
  66.             event.returnValue = false;
  67. }
  68.  
  69. function contextMenuEvent()
  70. {
  71.     // Only allow context menu if the 'Ctrl' key is held down.
  72.     if (!event.ctrlKey)
  73.         event.returnValue = false;
  74. }
  75.  
  76. // =====================================================
  77. // ===              Form Initialization              ===
  78. // =====================================================
  79.  
  80. function initFormPage(i_RecordID)
  81. {
  82.     if (g_IsViewSource)
  83.         return;
  84.  
  85.     if (!g_IsSearch && !g_IsPreviewPane && !g_IsFormPreview && !g_IsPrinting)
  86.         getScriptHostQI("IGrooveFormsToolUIDelegate").ClearStatusBarMessage();
  87.  
  88.     if (!g_IsFormPreview && typeof OnBeforeInitialize != "undefined" && !processCallout(OnBeforeInitialize))
  89.         return true;
  90.  
  91.     // Let the UIDelegate know there are no validation errors.
  92.     getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").HasValidationErrors = false;
  93.  
  94.     // Set the dirty bit for the current form.
  95.     g_IsInitializing = false;
  96.     int_setIsDirty(false);
  97.     g_IsInitializing = true;
  98.     // We need to reset this array otherwise we'll gradually be adding more objects to it every time you
  99.     // select another document and this will cause a major CPU spike
  100.     g_RichTextObjects = new Array();
  101.     g_DataListObjects = new Array();
  102.     g_ContactFields = new Array();
  103.     g_RegisteredContactFields = new Array();
  104.  
  105.     // If a record ID is passed in then use it.
  106.     if (typeof i_RecordID != "undefined")
  107.     {
  108.         g_IsPreviewPaneRefresh = true;
  109.         g_RecordID = i_RecordID;
  110.     }
  111.  
  112.     var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction();
  113.     try
  114.     {
  115.         var FormRecord;
  116.  
  117.         if (!g_IsSearch && !g_IsPreviewPane && !g_IsPrinting && !g_IsFormPreview && getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").NeedToAutoCreateRecord())
  118.         {
  119.             if (getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").LimitOneRecordPerMember)
  120.             {
  121.                 FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateOrOpenMemberRecord();
  122.                 getScriptHostQI("IGrooveFormsToolUIDelegateViewPrivate").SetFocusRecordID(FormRecord.ID);
  123.             }
  124.             else
  125.                 FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateRecord("");
  126.             
  127.             if (!getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(FormRecord.ID))
  128.             {
  129.                 g_IsNew = true;
  130.                 g_NewRecord = FormRecord;
  131.                 g_RecordID = FormRecord.ID;
  132.             }
  133.             else
  134.                 g_RecordID = FormRecord.ID;
  135.         }
  136.         else
  137.         {
  138.             if (g_IsSearch || g_IsFormPreview || g_IsPrinting)
  139.             {
  140.                 if (g_IsSearch)
  141.                     FormRecord = getScriptHostQI("IGrooveFormsToolSearchDialogDelegatePrivate").CreateSearchRecord(RecordType);
  142.                 else if (g_IsFormPreview)
  143.                     FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateSandboxedRecord();
  144.                 else if (g_IsPrinting && g_RecordID != null && g_RecordID != -1)
  145.                     FormRecord = getScriptHostQI("IGrooveFormsToolPrintDialogDelegatePrivate").OpenFormRecord();
  146.  
  147.  
  148.                 if (g_IsSearch || g_IsFormPreview)
  149.                     g_IsNew = true;
  150.                 else
  151.                     g_IsNew = false;
  152.  
  153.                 g_NewRecord = FormRecord;
  154.                 g_RecordID = FormRecord.ID;
  155.             }
  156.             else
  157.             {
  158.                 // Open the record if there is a record ID, otherwise create a new record.
  159.                 if (g_RecordID != null && g_RecordID != -1 && getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(g_RecordID))
  160.                 {
  161.                     if (!g_IsPreviewPane)
  162.                         getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").MarkRecordRead(g_RecordID);
  163.                     FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").OpenRecord(g_RecordID);
  164.                     // Set the focus record ID as the current record ID.
  165.                     getScriptHostQI("IGrooveFormsToolUIDelegateViewPrivate").SetFocusRecordID(g_RecordID);
  166.                 }
  167.                 else
  168.                 {
  169.                     if (getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").LimitOneRecordPerMember)
  170.                         FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateOrOpenMemberRecord();
  171.                     else
  172.                         FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateRecord("");
  173.  
  174.                     if (!getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(FormRecord.ID))
  175.                     {
  176.                         g_IsNew = true;
  177.                         g_NewRecord = FormRecord;
  178.                         g_RecordID = FormRecord.ID;
  179.                     }
  180.                     else
  181.                         g_RecordID = FormRecord.ID;
  182.                 }
  183.             }
  184.         }
  185.  
  186.         // Iterate through the form fields to properly set them up.
  187.         initSystemFields(FormRecord);
  188.         initFormElements(FormRecord);
  189.  
  190.         // If the record is new and is a response, then set the _ParentID so that HasParentID property works 
  191.         if (g_IsNew && g_IsResponse && g_SelectedID != -1)
  192.             FormRecord.SetField("_ParentID", g_SelectedID);
  193.  
  194.         // Create an IGrooveFormsToolRecord global variable for scripters to use.
  195.         g_FormRecord = FormRecord;
  196.  
  197.         Transaction.Commit();
  198.     }
  199.     catch (error)
  200.     {
  201.         //alert("Transaction aborted in initFormPage [" + error.description + "]");
  202.         Transaction.Abort();
  203.     }
  204.  
  205.     // Make sure that the document is a valid response.
  206.     if (g_IsNew && g_IsResponse && !getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").IsValidRecord(g_SelectedID))
  207.     {
  208.         getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox("The selected parent record has been deleted or is invalid. You will now be returned to the view.", "Invalid Selection");
  209.         window.setTimeout("getScriptHostQI('IGrooveFormsToolUIDelegatePrivate').SwitchWebState(FormsUIState_HomePage, -1)", 50);
  210.         return;
  211.     }
  212.  
  213.     // Update any lookups included in the form.
  214.     if (!g_IsFormPreview)
  215.         int_updateLookups(true, "");
  216.  
  217.     // Add the document to HTMLComponentBridge.
  218.     addDocument();
  219.  
  220.     // Inherit attachments field values if they should be.
  221.     if (g_AttachmentsObject != null)
  222.         inheritFieldValue(g_AttachmentsObject);
  223.  
  224.     // Enable rich text fields and inherit field values.
  225.     for (var i = 0; i < g_RichTextObjects.length; i++)
  226.     {
  227.         inheritFieldValue(g_RichTextObjects[i]);
  228.         window.setTimeout("enableTextView(" + i + ")", 10);
  229.     }
  230.  
  231.     // Enable embedded view fields.
  232.     for (var i = 0; i < g_DataListObjects.length; i++)
  233.     {
  234.         window.setTimeout("enableDataList(" + i + ")", 10);
  235.     }
  236.  
  237.     // Enable attachments fields.
  238.     window.setTimeout("enableDocumentShare()", 10);
  239.  
  240.     if (!g_IsSearch && !g_IsFormPreview && !g_IsPrinting)
  241.         getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").SetCurrentFormDocument(document);
  242.  
  243.     // Enable all contact fields.
  244.     for (var i = 0; i < g_ContactFields.length; i++)
  245.     {
  246.         inheritFieldValue(g_ContactFields[i]);
  247.     }
  248.  
  249.     enableContactFields();
  250.     registerContactFields();
  251.  
  252.     // Tell the UIDelegate we are in the DocumentDisplay state.
  253.     if (!g_IsSearch && !g_IsPreviewPane && !g_IsFormPreview && !g_IsPrinting)
  254.         getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").SwitchWebState(FormsUIState_DocumentDisplay, g_RecordID, g_IsNew);
  255.  
  256.     g_IsPreviewPaneRefresh = false;
  257.     g_IsInitializing = false;
  258.     
  259.     if (g_IsPreviewPane)
  260.         getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").OnPreviewPaneLoadingComplete();
  261.  
  262.     if (!g_IsFormPreview && typeof OnAfterInitialize != "undefined" && !processCallout(OnAfterInitialize))
  263.         return true;
  264.  
  265.     // Print the form if we should be doing it.
  266.     if (g_IsPrinting)
  267.     {
  268.         // Display the contents of all tabs when printing.
  269.         var arrDivs = document.getElementsByTagName("DIV");
  270.         for (var i = 0; i < arrDivs.length; i++)
  271.         {
  272.             var strObjectType = arrDivs[i].getAttribute("OBJECTTYPE");
  273.             if (strObjectType == "TabContents" && arrDivs[i].style.display == "none")
  274.             {
  275.                 arrDivs[i].insertAdjacentHTML("beforeBegin", "<HR ID=\"" + arrDivs[i].id + "_line\" SIZE=\"1\" COLOR=\"#000000\">");
  276.                 arrDivs[i].style.display = "";
  277.             }
  278.         }
  279.  
  280.         printThroughForm();
  281.     }
  282. }
  283.  
  284. function CheckValidResponseRecord()
  285. {
  286.     var ResponseError = false;
  287.  
  288.     try
  289.     {
  290.         // Check to see if this is a response record, and if it is valid to create.
  291.         if (g_IsResponse && !g_IsPreviewPane)
  292.         {
  293.             if (g_SelectedID == -1 || !getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").IsValidRecord(g_SelectedID))
  294.                 ResponseError = true;
  295.                 
  296.  
  297.             // MWATodo: update UI to add option for not allowing responses to a response.
  298.             /*
  299.             if (g_SelectedID != -1)
  300.             {
  301.                 var SelectedFormURL = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DataDelegate.IGrooveFormsToolUserDataPrivate.OpenFormURLByRecordID(g_SelectedID);
  302.  
  303.                 var ThisFormURL = String(window.location.href);
  304.                 if (ThisFormURL.indexOf("?") >= 0)
  305.                     ThisFormURL = ThisFormURL.substring(0, ThisFormURL.indexOf("?"));
  306.  
  307.                 // Normalize the URLs by converting to lower case for comparison.
  308.                 if (SelectedFormURL.toLowerCase() == ThisFormURL.toLowerCase())
  309.                     ResponseErrorMessage = "You must select a valid parent document in order to create a response. You have a response selected.";
  310.             }
  311.             */
  312.         }
  313.     }
  314.     catch (error)
  315.     {
  316.         //alert("ERROR: " + error.description);
  317.     }
  318.  
  319.     return ResponseError;
  320. }
  321.  
  322. function initSystemFields(i_Record)
  323. {
  324.     // There must be a valid record, unless it is new or a search.
  325.     if (!g_IsNew && (typeof i_Record == "undefined" || i_Record == null))
  326.         return;
  327.  
  328.     var divCreatedBy = document.getElementById("_CreatedBy");
  329.     var divCreated = document.getElementById("_Created");
  330.     var divModifiedBy = document.getElementById("_ModifiedBy");
  331.     var divModified = document.getElementById("_Modified");
  332.     var divEditors = document.getElementById("_Editors");
  333.     var divReaders = document.getElementById("_Readers");
  334.  
  335.     if (divCreatedBy)
  336.     {
  337.         if (g_IsSearch)
  338.             divCreatedBy.innerHTML = "<INPUT TYPE=\"text\" CLASS=\"text\" NAME=\"_CreatedBy\">";
  339.         else if (g_IsNew)
  340.             divCreatedBy.innerText = getCurrentAuthorName();
  341.         else
  342.             divCreatedBy.innerText = i_Record.OpenField("_CreatedBy");
  343.     }
  344.  
  345.     if (divCreated)
  346.     {
  347.         if (g_IsSearch)
  348.             divCreated.innerHTML = "<INPUT TYPE=\"text\" CLASS=\"text\" ID=\"_Created\" NAME=\"_Created\" DATATYPE=\"Date\" FORMAT=\"3\"> <BUTTON CLASS=\"dateButton\" ONCLICK=\"doCalendar('_Created');\"><IMG SRC=\"calendar.gif\" WIDTH=15 HEIGHT=13 STYLE=\"nargin 2px 2px 0px 2px;\"></BUTTON>";
  349.         else if (g_IsNew)
  350.             divCreated.innerText = getScriptHostQI("IGrooveFormsToolUIDelegate").FormatDateTime(new Date().valueOf(), 3, 3);
  351.         else
  352.             divCreated.innerText = getScriptHostQI("IGrooveFormsToolUIDelegate").FormatDateTime(i_Record.OpenField("_Created"), 3, 3);
  353.     }
  354.  
  355.     if (divModifiedBy)
  356.     {
  357.         if (g_IsSearch)
  358.             divModifiedBy.innerHTML = "<INPUT TYPE=\"text\" CLASS=\"text\" NAME=\"_ModifiedBy\">";
  359.         else if (g_IsNew)
  360.             divModifiedBy.innerText = getCurrentAuthorName();
  361.         else
  362.             divModifiedBy.innerText = i_Record.OpenField("_ModifiedBy");
  363.     }
  364.  
  365.     if (divModified)
  366.     {
  367.         if (g_IsSearch)
  368.             divModified.innerHTML = "<INPUT TYPE=\"text\" CLASS=\"text\" ID=\"_Modified\" NAME=\"_Modified\" DATATYPE=\"Date\" FORMAT=\"3\"> <BUTTON CLASS=\"dateButton\" ONCLICK=\"doCalendar('_Modified');\"><IMG SRC=\"calendar.gif\" WIDTH=15 HEIGHT=13 STYLE=\"nargin 2px 2px 0px 2px;\"></BUTTON>";
  369.         else if (g_IsNew)
  370.             divModified.innerText = getScriptHostQI("IGrooveFormsToolUIDelegate").FormatDateTime(new Date().valueOf(), 3, 3);
  371.         else
  372.             divModified.innerText = getScriptHostQI("IGrooveFormsToolUIDelegate").FormatDateTime(i_Record.OpenField("_Modified"), 3, 3);
  373.     }
  374.  
  375.     if (divEditors || divReaders)
  376.     {
  377.         var objMemberNameURLEnum = getScriptHostQI("IGrooveFormsToolUIDelegate").CreateMemberNameURLEnum();
  378.         if (divEditors)
  379.         {
  380.             var strEditors = "";
  381.             if (!g_IsNew && !g_IsSearch)
  382.                 strEditors = i_Record.OpenField("_Editors");
  383.  
  384.             divEditors.innerHTML = createMemberNameURLOptions("_Editors", strEditors, objMemberNameURLEnum);
  385.         }
  386.  
  387.         objMemberNameURLEnum.Reset();
  388.         if (divReaders)
  389.         {
  390.             var strReaders = "";
  391.             if (!g_IsNew && !g_IsSearch)
  392.                 strReaders = i_Record.OpenField("_Readers");
  393.  
  394.             divReaders.innerHTML = createMemberNameURLOptions("_Readers", strReaders, objMemberNameURLEnum);
  395.         }
  396.     }
  397. }
  398.  
  399. function getCurrentAuthorName()
  400. {
  401.     if (g_IsFormPreview)
  402.         return getScriptHostQI("IGrooveFormsToolUIDelegate").GetCurrentAuthorName();
  403.     else
  404.         return getScriptHostQI("IGrooveFormsToolUIDelegate").CurrentAuthorName;
  405. }
  406.  
  407. function getTelespaceDisplayName()
  408. {
  409.     if (g_IsFormPreview)
  410.         return getScriptHostQI("IGrooveFormsToolUIDelegate").GetTelespaceDisplayName();
  411.     else
  412.         return getScriptHostQI("IGrooveFormsToolUIDelegate").TelespaceDisplayName;
  413. }
  414.  
  415. function getToolDisplayName()
  416. {
  417.     if (g_IsFormPreview)
  418.         return getScriptHostQI("IGrooveFormsToolUIDelegate").GetToolDisplayName();
  419.     else
  420.         return getScriptHostQI("IGrooveFormsToolUIDelegate").ToolDisplayName;
  421. }
  422.  
  423. function createMemberNameURLOptions(i_strName, i_strURLs, i_objMemberNameURLEnum)
  424. {
  425.     var StyleAttribute = "";
  426.     if (g_IsPreviewPane)
  427.         StyleAttribute = " STYLE=\"display:none;\"";
  428.  
  429.     var strOptions = "<SELECT NAME=\"" + i_strName + "\" SIZE=\"4\" MULTIPLE" + StyleAttribute + ">";
  430.  
  431.     while (i_objMemberNameURLEnum.HasMore())
  432.     {
  433.         var objMemberNameURLPair = i_objMemberNameURLEnum.OpenNextPair();
  434.         var strMemberName = objMemberNameURLPair.First;
  435.         var strMemberURL = objMemberNameURLPair.Second;
  436.         var strSelected = "";
  437.         if (i_strURLs.indexOf(strMemberURL) >= 0)
  438.             strSelected = " SELECTED";
  439.         strOptions += "<OPTION VALUE=\"" + strMemberURL + "\"" + strSelected + "\">" + strMemberName;
  440.     }
  441.  
  442.     strOptions += "</SELECT>";
  443.     strOptions += "<SPAN CLASS=\"selectPreview\" ID=\"" + i_strName + "_preview\"></SPAN>";
  444.     return strOptions;
  445. }
  446.  
  447. function initFormElements(i_Record)
  448. {
  449.     // Iterate through elements in the form.
  450.     var DocumentForm = document.GrooveFormBase;
  451.     for (var i = 0; i < DocumentForm.elements.length; i++)
  452.     {
  453.         var DocumentElement = DocumentForm.elements[i];
  454.         if (DocumentElement.tagName == "OBJECT")
  455.         {
  456.             initFormObject(DocumentElement);
  457.         }
  458.         else
  459.         {
  460.             if (!g_IsNew)
  461.                 clearFormElement(DocumentElement);
  462.             initFormElement(i_Record, DocumentElement);
  463.         }
  464.  
  465.         if (!g_IsReadOnly && !g_IsFormPreview && !g_IsFocusSet && DocumentElement.getAttribute("ISREADONLY") == null && DocumentElement.getAttribute("ISHIDDEN") == null)
  466.         {
  467.             try
  468.             {
  469.                 DocumentElement.focus();
  470.                 g_IsFocusSet = true;
  471.             }
  472.             catch (error)
  473.             {
  474.                 g_IsFocusSet = false;
  475.             }
  476.         }
  477.     }
  478.  
  479.     var DocumentSpans = document.getElementsByTagName("SPAN");
  480.     for (var i = 0; i < DocumentSpans.length; i++)
  481.     {
  482.         if (DocumentSpans[i].getAttribute("DATATYPE") == "Contact")
  483.             initFormObject(DocumentSpans[i]);
  484.     }
  485. }
  486.  
  487. function clearFormElement(i_Element)
  488. {
  489.     var ElementName = i_Element.id;
  490.     if (ElementName == "")
  491.         ElementName = i_Element.name;
  492.     var ElementType = i_Element.type;
  493.     var ElementDataType = i_Element.getAttribute("DATATYPE");
  494.     if (ElementType == "text" || ElementType == "textarea" || ElementType == "password")
  495.     {
  496.         if (ElementName.indexOf("_Time") < 0)
  497.             i_Element.value = "";
  498.     }
  499.     else if (ElementType == "checkbox" || ElementType == "radio")
  500.     {
  501.         if (!g_IsNew)
  502.             i_Element.checked = false;
  503.     }
  504.     else if (ElementType.indexOf("select") == 0)
  505.     {
  506.         for (var i = 0; i < i_Element.options.length; i++)
  507.         {
  508.             i_Element.options[i].selected = false;
  509.         }
  510.     }
  511. }
  512.  
  513. function initFormElement(i_Record, i_Element)
  514. {
  515.     var ElementName = i_Element.id;
  516.     if (ElementName == "")
  517.         ElementName = i_Element.name;
  518.     var ElementType = i_Element.type;
  519.     var ElementDataType = i_Element.getAttribute("DATATYPE");
  520.     var ElementPreview = null;
  521.  
  522.     if (g_IsReadOnly && !g_IsFormPreview)
  523.     {
  524.         ElementPreview = document.getElementById(ElementName + "_preview");
  525.         if (ElementPreview == null && (ElementType == "text" || ElementType == "textarea" || ElementType == "password"))
  526.             return;
  527.     }
  528.  
  529.     if (!g_IsPreviewPaneRefresh && ElementType.indexOf("select") == 0)
  530.     {
  531.         // Add members list to drop-down list and list box fields.
  532.         var MembersAttribute = i_Element.getAttribute("MEMBERS");
  533.         if (MembersAttribute != null)
  534.         {
  535.             var MemberNameEnum = getScriptHostQI("IGrooveFormsToolUIDelegate").CreateMemberNameEnum();
  536.             while (MemberNameEnum.HasMore())
  537.             {
  538.                 var MemberName = MemberNameEnum.OpenNext();
  539.                 insertNewOption(i_Element, MemberName, MemberName, false);
  540.             }
  541.         }
  542.  
  543.         if (g_IsSearch)
  544.             i_Element.options.value = "";
  545.     }
  546.  
  547.     if (!g_IsSearch && typeof i_Record != "undefined" && i_Record != null)
  548.     {
  549.         // Check to see if the field exists in the record.
  550.         if (i_Record.HasField(ElementName))
  551.         {
  552.             var ElementValue = i_Record.OpenField(ElementName);
  553.             if (g_IsNew)
  554.             {
  555.                 // Check to see if there is a special initial value.
  556.                 var InitialValueTypeAttribute = i_Element.getAttribute("INITIALVALUETYPE");
  557.  
  558.                 var FieldTypeAttribute = i_Element.getAttribute("FIELDTYPE");
  559.                 if (FieldTypeAttribute == FormObjectType_Text)
  560.                 {
  561.                     if (InitialValueTypeAttribute == GrooveFormsToolTextFieldInitialValueType_Unique)
  562.                         ElementValue = int_getUniqueID();
  563.                     else if (InitialValueTypeAttribute == GrooveFormsToolTextFieldInitialValueType_UserDisplayName)
  564.                         ElementValue = getCurrentAuthorName();
  565.                     else if (InitialValueTypeAttribute == GrooveFormsToolTextFieldInitialValueType_TelespaceDisplayName)
  566.                         ElementValue = getTelespaceDisplayName();
  567.                     else if (InitialValueTypeAttribute == GrooveFormsToolTextFieldInitialValueType_ToolDisplayName)
  568.                         ElementValue = getToolDisplayName();
  569.                 }
  570.                 else if (FieldTypeAttribute == FormObjectType_Date)
  571.                 {
  572.                     // Get the current date and set the time to noon.
  573.                     var CurrentDate = new Date();
  574.                     CurrentDate.setHours(12);
  575.                     CurrentDate.setMinutes(0);
  576.                     CurrentDate.setSeconds(0);
  577.                     if (InitialValueTypeAttribute == GrooveFormsToolDateFieldInitialValueType_Today)
  578.                         ElementValue = CurrentDate.valueOf();
  579.                     else if (InitialValueTypeAttribute == GrooveFormsToolDateFieldInitialValueType_Tomorrow)
  580.                     {
  581.                         // Add one day to the current date.
  582.                         CurrentDate.setMinutes(60 * 24);
  583.                         ElementValue = CurrentDate.valueOf();
  584.                     }
  585.                 }
  586.                 else if (FieldTypeAttribute == FormObjectType_DateTime)
  587.                 {
  588.                     if (InitialValueTypeAttribute == GrooveFormsToolDateTimeFieldInitialValueType_Now)
  589.                         ElementValue = new Date().valueOf();
  590.                 }
  591.  
  592.                 // Get the return value from a function.
  593.                 if ((FieldTypeAttribute == FormObjectType_Text && InitialValueTypeAttribute == GrooveFormsToolTextFieldInitialValueType_Function) ||
  594.                     (FieldTypeAttribute == FormObjectType_Date && InitialValueTypeAttribute == GrooveFormsToolDateFieldInitialValueType_Function) ||
  595.                     (FieldTypeAttribute == FormObjectType_DateTime && InitialValueTypeAttribute == GrooveFormsToolDateTimeFieldInitialValueType_Function))
  596.                 {
  597.                     var InitialValueFunctionAttribute = i_Element.getAttribute("INITIALVALUEFUNCTION");
  598.                     if (InitialValueFunctionAttribute != null && InitialValueFunctionAttribute != "")
  599.                     {
  600.                         try
  601.                         {
  602.                             ElementValue = eval(InitialValueFunctionAttribute);
  603.                         }
  604.                         catch (error) { }
  605.                     }
  606.                 }
  607.             }
  608.  
  609.             var IsValueInherited = false;
  610.             // Check to see if the field value should be inherited.
  611.             if (g_IsNew && g_SelectedID != -1)
  612.             {
  613.                 var InheritAttribute = i_Element.getAttribute("INHERIT");
  614.                 if (InheritAttribute != null && InheritAttribute != "")
  615.                 {
  616.                     if (getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").IsValidRecord(g_SelectedID))
  617.                     {
  618.                         var ParentRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").OpenRecord(g_SelectedID);
  619.  
  620.                         if (InheritAttribute == "FormsInheritSelf")
  621.                             InheritAttribute = ElementName;
  622.  
  623.                         if (ParentRecord.HasField(InheritAttribute))
  624.                         {
  625.                             ElementValue = ParentRecord.OpenField(InheritAttribute);
  626.                             IsValueInherited = true;
  627.                             // Set the inherited attribute to be used by lookup later on.
  628.                             i_Element.setAttribute("INHERITEDVALUE", ElementValue);
  629.                         }
  630.                     }
  631.                     else
  632.                     {
  633.                         displayStatusBar("The selected item in the view is not a valid record. Inheriting field values not completed.", GrooveMessageBoxIcon_Error);
  634.                     }
  635.                 }
  636.             }
  637.  
  638.             // Set the value for each field depending on the element type.
  639.             if (ElementType == "text" || ElementType == "textarea" || ElementType == "password")
  640.             {
  641.                 if (ElementDataType == "Date")
  642.                 {
  643.                     // Will be new code for date and time fields.
  644.                     // Commenting out for now so I can check in.
  645.                     var DateValue = "";
  646.                     var TimeValue = "";
  647.                     if (ElementValue != INVALID_DATE)
  648.                     {
  649.                         try
  650.                         {
  651.                             var DateFormat = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").CreateDateFormatStyleFromAttributeValue(i_Element.getAttribute("FORMAT"));
  652.                             var NumberValue = Number(ElementValue);
  653.                             if (!isNaN(NumberValue))
  654.                             {
  655.                                 var FieldTypeAttribute = i_Element.getAttribute("FIELDTYPE");
  656.                                 if (FieldTypeAttribute == FormObjectType_DateTime)
  657.                                 {
  658.                                     var DateTimeEnum = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").FormatDateAndTime(NumberValue, DateFormat, 3);
  659.                                     if (DateTimeEnum.HasMore())
  660.                                         DateValue = DateTimeEnum.OpenNext();
  661.                                     if (DateTimeEnum.HasMore())
  662.                                         TimeValue = DateTimeEnum.OpenNext();
  663.                                 }
  664.                                 else
  665.                                     DateValue = getScriptHostQI("IGrooveFormsToolUIDelegate").FormatDate(NumberValue, DateFormat);
  666.                             }
  667.                         }
  668.                         catch (error) { }
  669.                     }
  670.  
  671.                     if (g_IsReadOnly && !g_IsFormPreview)
  672.                     {
  673.                         ElementPreview.innerText = DateValue;
  674.                         if (FieldTypeAttribute == FormObjectType_DateTime)
  675.                             ElementPreview.innerText += " " + TimeValue;
  676.                     }
  677.  
  678.                     i_Element.value = DateValue;
  679.                     if (FieldTypeAttribute == FormObjectType_DateTime)
  680.                     {
  681.                         var TimeElement = document.getElementById(ElementName + "_Time");
  682.                         if (TimeElement != null)
  683.                             TimeElement.value = TimeValue;
  684.                     }
  685.                 }
  686.                 else if (ElementDataType == "Numeric")
  687.                 {
  688.                     if (ElementValue == 0)
  689.                         ElementValue = "";
  690.  
  691.                     if (ElementValue != "")
  692.                     {
  693.                         var FieldTypeAttribute = i_Element.getAttribute("FIELDTYPE");
  694.                         if (FieldTypeAttribute == FormObjectType_Number)
  695.                             ElementValue = formatNumericValue(i_Element, ElementValue);
  696.                         else if (FieldTypeAttribute == FormObjectType_Currency)
  697.                             ElementValue = formatCurrencyValue(i_Element, ElementValue);
  698.                     }
  699.  
  700.                     if (g_IsReadOnly && !g_IsFormPreview)
  701.                         ElementPreview.innerText = ElementValue;
  702.  
  703.                     i_Element.value = ElementValue;
  704.                 }
  705.                 else
  706.                 {
  707.                     if (g_IsReadOnly && !g_IsFormPreview)
  708.                     {
  709.                         if (ElementType == "password")
  710.                         {
  711.                             var ElementValueLength = ElementValue.length;
  712.                             ElementValue = "";
  713.                             for (var i = 0; i < ElementValueLength; i++)
  714.                             {
  715.                                 ElementValue += "*";
  716.                             }
  717.                         }
  718.                         ElementPreview.innerText = ElementValue;
  719.                     }
  720.  
  721.                     // Check to see if the field contains a lookup.
  722.                     var FieldHasLookup = false;
  723.                     var LookupAttribute = i_Element.getAttribute("LOOKUP");
  724.                     if (LookupAttribute != null)
  725.                         FieldHasLookup = true;
  726.  
  727.                     if (!g_IsNew || (g_IsNew && !FieldHasLookup))
  728.                         i_Element.value = ElementValue;
  729.                 }
  730.             }
  731.             else if (ElementType == "checkbox")
  732.             {
  733.                 if (!g_IsNew || IsValueInherited)
  734.                 {
  735.                     if (ElementValue != "")
  736.                         i_Element.checked = true;
  737.                     else
  738.                         i_Element.checked = false;
  739.                 }
  740.             }
  741.             else if (ElementType == "radio")
  742.             {
  743.                 if (!g_IsNew || IsValueInherited)
  744.                 {
  745.                     if (i_Element.value == ElementValue)
  746.                         i_Element.checked = true;
  747.                     else
  748.                         i_Element.checked = false;
  749.                 }
  750.             }
  751.             else if (ElementType == "select-one")
  752.             {
  753.                 if (g_IsReadOnly && !g_IsFormPreview)
  754.                 {
  755.                     OptionValue = "";
  756.                     for (var i = 0; i < i_Element.options.length; i++)
  757.                     {
  758.                         if (i_Element.options[i].value == ElementValue)
  759.                         {
  760.                             OptionValue = i_Element.options[i].text;
  761.                             break;
  762.                         }
  763.                     }
  764.  
  765.                     if (OptionValue == "")
  766.                         OptionValue = ElementValue;
  767.  
  768.                     ElementPreview.innerText = OptionValue;
  769.                 }
  770.  
  771.                 if (!g_IsNew || IsValueInherited)
  772.                 {
  773.                     var IsValueFound = false;
  774.                     for (var i = 0; i < i_Element.options.length; i++)
  775.                     {
  776.                         if (i_Element.options[i].value == ElementValue)
  777.                         {
  778.                             i_Element.options[i].selected = true;
  779.                             IsValueFound = true;
  780.                             break;
  781.                         }
  782.                     }
  783.  
  784.                     var CustomAttribute = i_Element.getAttribute("CUSTOM");
  785.                     if (!IsValueFound && CustomAttribute != null && ElementValue != "")
  786.                         insertNewOption(i_Element, ElementValue, ElementValue, true);
  787.                 }
  788.             }
  789.             else if (ElementType == "select-multiple")
  790.             {
  791.                 // Editors and Readers fields are separated with a semi-colon.
  792.                 var ElementValueSeparator = "\n";
  793.                 if (ElementName == "_Editors" || ElementName == "_Readers")
  794.                     ElementValueSeparator = ";";
  795.  
  796.                 if (g_IsReadOnly && !g_IsFormPreview)
  797.                 {
  798.                     var ElementValueArray = ElementValue.split(ElementValueSeparator);
  799.                     var OptionValueArray = new Array(ElementValueArray.length);
  800.                     for (var i = 0; i < ElementValueArray.length; i++)
  801.                     {
  802.                         var ValueFound = false;
  803.                         for (var j = 0; j < i_Element.options.length; j++)
  804.                         {
  805.                             if (i_Element.options[j].value == ElementValueArray[i])
  806.                             {
  807.                                 OptionValueArray[i] = i_Element.options[j].text;
  808.                                 ValueFound = true;
  809.                                 break;
  810.                             }
  811.                         }
  812.  
  813.                         if (!ValueFound)
  814.                             OptionValueArray[i] = ElementValueArray[i];
  815.                     }
  816.  
  817.                     for (var i = 0; i < OptionValueArray.length; i++)
  818.                     {
  819.                         if (OptionValueArray[i] == "")
  820.                             OptionValueArray[i] = ElementValueArray[i];
  821.                     }
  822.  
  823.                     ElementPreview.innerText = OptionValueArray.join(", ");
  824.                 }
  825.  
  826.                 if (!g_IsNew || IsValueInherited)
  827.                 {
  828.                     var ElementValueArray = ElementValue.split(ElementValueSeparator);
  829.                     for (var i = 0; i < ElementValueArray.length; i++)
  830.                     {
  831.                         for (var j = 0; j < i_Element.options.length; j++)
  832.                         {
  833.                             if (i_Element.options[j].value == ElementValueArray[i])
  834.                             {
  835.                                 i_Element.options[j].selected = true;
  836.                                 break;
  837.                             }
  838.                         }
  839.                     }
  840.                 }
  841.             }
  842.         }
  843.     }
  844.     else
  845.     {
  846.         if (g_IsPreviewPane)
  847.         {
  848.             getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox("The record you have selected to preview has been deleted.", "Record Deleted");
  849.             location.replace("FormsBlankPage.html");
  850.         }
  851.         else if (!g_IsNew && !g_IsSearch && !g_IsFormPreview && !g_IsPrinting)
  852.         {
  853.             getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox("The record you have selected to edit has been deleted. You will be returned to the view.", "Record Deleted");
  854.             window.setTimeout("getScriptHostQI('IGrooveFormsToolUIDelegatePrivate').SwitchWebState(FormsUIState_HomePage, -1)", 50);
  855.         }
  856.     }
  857.  
  858.     if (!g_IsSearch && !g_IsPrinting)
  859.     {
  860.         // Add event handlers to each element in the form for script developers.
  861.         i_Element.attachEvent("onblur", onBlurHandler);
  862.         i_Element.attachEvent("onfocus", onFocusHandler);
  863.         i_Element.attachEvent("onclick", onClickHandler);
  864.         // OnChange is only supported by text INPUT, TEXTAREA, and SELECT.
  865.         if (ElementType == "text" || ElementType == "textarea" || ElementType.indexOf("select") == 0)
  866.             i_Element.attachEvent("onchange", onChangeHandler);
  867.  
  868.         // Set the disabled flag for the element.
  869.         var ReadOnlyAttribute = i_Element.getAttribute("ISREADONLY");
  870.         if (ReadOnlyAttribute != null || g_IsReadOnly)
  871.         {
  872.             if (ElementType == "select-one")
  873.             {
  874.                 var objCustomButton = document.getElementById(ElementName + "Button");
  875.                 if (objCustomButton != null)
  876.                     objCustomButton.style.display = "none";
  877.             }
  878.  
  879.             if (ElementDataType == "Date")
  880.             {
  881.                 var objDateButton = document.getElementById(ElementName + "Button");
  882.                 if (objDateButton != null)
  883.                     objDateButton.disabled = true;
  884.             }
  885.  
  886.             if (ElementType == "text" || ElementType == "textarea" || ElementType == "password")
  887.                 i_Element.readOnly = true;
  888.             else
  889.                 i_Element.disabled = true;
  890.         }
  891.     }
  892. }
  893.  
  894. function initFormObject(i_Object)
  895. {
  896.     // Save the attachments elements in a global variable.
  897.     var ObjectDataType = i_Object.getAttribute("DATATYPE");
  898.     if (ObjectDataType == "RichText")
  899.         g_RichTextObjects.push(i_Object);
  900.     else if (ObjectDataType == "Attachments")
  901.         g_AttachmentsObject = i_Object;
  902.     else if (ObjectDataType == "Contact")
  903.         g_ContactFields.push(i_Object);
  904.     else if (ObjectDataType == "View")
  905.         g_DataListObjects.push(i_Object);
  906. }
  907.  
  908. // =====================================================
  909. // ===               Form Termination                ===
  910. // =====================================================
  911.  
  912. function terminateFormPage()
  913. {
  914.     if (g_IsViewSource)
  915.         return;
  916.  
  917.     if (!g_IsFormPreview && typeof OnBeforeTerminate != "undefined" && !processCallout(OnBeforeTerminate))
  918.         return true;
  919.  
  920.     if (!g_IsSearch && !g_IsPreviewPane && !g_IsFormPreview && !g_IsPrinting)
  921.         getScriptHostQI("IGrooveFormsToolUIDelegate").ClearStatusBarMessage();
  922.  
  923.     // Remove the document from HTMLComponentBridge.
  924.     removeDocument();
  925.  
  926.     if (!g_IsFormPreview && typeof OnAfterTerminate != "undefined" && !processCallout(OnAfterTerminate))
  927.         return true;
  928. }
  929.  
  930. function reinitAttachments()
  931. {
  932.     var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction();
  933.     try
  934.     {
  935.         var FormRecord = openCurrentRecord();
  936.         if (FormRecord != null)
  937.         {
  938.             g_AttachmentsElement = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").ReinitializeAttachments(document, FormRecord);
  939.             if (g_AttachmentsObject != null)
  940.                 g_AttachmentsObject.Commands2.Refresh();    
  941.         }
  942.  
  943.         Transaction.Commit();
  944.     }
  945.     catch (error)
  946.     {
  947.         //alert("Transaction aborted in reinitAttachments [" + error.description + "]");
  948.         Transaction.Abort();
  949.     }
  950. }
  951.  
  952. // =====================================================
  953. // ===              Add/Remove Document              ===
  954. // =====================================================
  955.  
  956. function addDocument()
  957. {
  958.     if (!g_IsFormPreview)
  959.     {
  960.         var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction();
  961.         try
  962.         {
  963.             var FormRecord = openCurrentRecord();
  964.             if (FormRecord != null)
  965.             {
  966.                 // Get the enum of data list names that need to be added.
  967.                 var ViewNameArray = new Array();
  968.                 for (var i = 0; i < g_DataListObjects.length; i++)
  969.                     ViewNameArray.push(g_DataListObjects[i].id);
  970.  
  971.                 g_AttachmentsElement = getScriptHostQI("IGrooveFormsToolUIDelegateHTMLDocumentPrivate").AddHTMLDocumentForForm(document, FormRecord, int_CreateBSTREnumFromArray(ViewNameArray));
  972.             }
  973.  
  974.             Transaction.Commit();
  975.         }
  976.         catch (error)
  977.         {
  978.             //alert("Transaction aborted in addDocument [" + error.description + "]");
  979.             Transaction.Abort();
  980.         }
  981.     }
  982. }
  983.  
  984. function removeDocument()
  985. {
  986.     // Unregister all registered contacts.
  987.     for (var FieldName in g_RegisteredContactFields)
  988.     {
  989.         unregisterContact(g_RegisteredContactFields[FieldName], FieldName);
  990.     }
  991.  
  992.     if (!g_IsFormPreview)
  993.         getScriptHostQI("IGrooveFormsToolUIDelegateHTMLDocumentPrivate").RemoveHTMLDocument(document);
  994. }
  995.  
  996. // =====================================================
  997. // ===            Printing Event Handlers            ===
  998. // =====================================================
  999.  
  1000. function beforePrint()
  1001. {
  1002.     if (!g_IsFormPreview && typeof OnBeforePrint != "undefined" && !processCallout(OnBeforePrint))
  1003.         return true;
  1004.  
  1005.     if (!g_IsPrinting)
  1006.         subInDivs();
  1007. }
  1008.  
  1009. function afterPrint()
  1010. {
  1011.     if (!g_IsFormPreview && typeof OnAfterPrint != "undefined" && !processCallout(OnAfterPrint))
  1012.         return true;
  1013.  
  1014.     if (!g_IsPrinting)
  1015.         putBackTextAreas();
  1016.     else
  1017.         getScriptHostQI("IGrooveFormsToolPrintDialogDelegatePrivate").PrintingComplete();
  1018. }
  1019.  
  1020. // =====================================================
  1021. // ===              Dirty Bit Handling               ===
  1022. // =====================================================
  1023.  
  1024. function setIsDirty()
  1025. {
  1026.     // No need to check if it is already marked as dirty.
  1027.     if (g_IsDirty)
  1028.         return;
  1029.  
  1030.     // Rich text control does not send an event, so verify that it is valid.
  1031.     if (window.event != null)
  1032.     {
  1033.         var KeyCode = window.event.keyCode;
  1034.         var bShift = window.event.shiftKey;
  1035.         if ((KeyCode >= 112 && KeyCode <= 123) || (KeyCode >= 33 && KeyCode <= 40) || (KeyCode >= 16 && KeyCode <= 20) ||
  1036.             (KeyCode == 45 && !bShift) || KeyCode == 145 || KeyCode == 27 || KeyCode == 9)
  1037.             return;
  1038.     }
  1039.  
  1040.     // Set the dirty bit to true.
  1041.     int_setIsDirty(true);
  1042. }
  1043.  
  1044. function int_setIsDirty(i_IsDirty)
  1045. {
  1046.     if (g_IsSearch || g_IsPreviewPane || g_IsFormPreview || g_IsReadOnly || g_IsPrinting)
  1047.         return;
  1048.  
  1049.     if (i_IsDirty && (g_IsInitializing || g_IsInitializingTextView || g_IsInitializingDocumentShare))
  1050.         return;
  1051.  
  1052.     if (!i_IsDirty || (i_IsDirty && g_IsDirty != i_IsDirty))
  1053.     {
  1054.         getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").SetFormRecordIsDirty(i_IsDirty);
  1055.         g_IsDirty = i_IsDirty;
  1056.     }
  1057. }
  1058.  
  1059. // =====================================================
  1060. // ===             Object Initialization             ===
  1061. // =====================================================
  1062.  
  1063. function enableTextView(i_Index)
  1064. {
  1065.     g_IsInitializingTextView = true;
  1066.  
  1067.     var RichTextObject = g_RichTextObjects[i_Index];
  1068.     var RichTextName = RichTextObject.id;
  1069.  
  1070.     // Make sure the object is marked as unitialized.
  1071.     RichTextObject.removeAttribute("ISINITIALIZED");
  1072.  
  1073.     // Disable all command bar buttons.
  1074.     if (g_IsSearch || g_IsFormPreview || g_IsReadOnly || g_IsPrinting)
  1075.     {
  1076.         setCommandDisabledState(RichTextName + "Bold", true);
  1077.         setCommandDisabledState(RichTextName + "Italic", true);
  1078.         setCommandDisabledState(RichTextName + "Underline", true);
  1079.         setCommandDisabledState(RichTextName + "ChooseFont", true);
  1080.         setCommandDisabledState(RichTextName + "ChooseColor", true);
  1081.         setCommandDisabledState(RichTextName + "Bold", true);
  1082.         setCommandDisabledState(RichTextName + "AlignLeft", true);
  1083.         setCommandDisabledState(RichTextName + "Center", true);
  1084.         setCommandDisabledState(RichTextName + "AlignRight", true);
  1085.         setCommandDisabledState(RichTextName + "Justify", true);
  1086.         setCommandDisabledState(RichTextName + "Bullets", true);
  1087.         setCommandDisabledState(RichTextName + "IncreaseIndent", true);
  1088.         setCommandDisabledState(RichTextName + "DecreaseIndent", true);
  1089.         setCommandDisabledState(RichTextName + "SpellCheck", true);
  1090.         setCommandDisabledState(RichTextName + "Hyperlink", true);
  1091.     }
  1092.  
  1093.     if (!g_IsFormPreview)
  1094.     {
  1095.         var RichTextObjectName = null;
  1096.         try
  1097.         {
  1098.             RichTextObjectName = RichTextObject.IGrooveComponent.OpenName();
  1099.         }
  1100.         catch (error) { }
  1101.         
  1102.         if (RichTextObjectName != null && RichTextObjectName != "")
  1103.         {
  1104.             // Make sure the object is marked as initialized.
  1105.             RichTextObject.setAttribute("ISINITIALIZED", "true");
  1106.  
  1107.             var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction();
  1108.             try
  1109.             {
  1110.                 var FormRecord = openCurrentRecord();
  1111.                 if (FormRecord != null && FormRecord.HasField(RichTextName))
  1112.                 {
  1113.                     var RTFElement = FormRecord.OpenField(RichTextName);
  1114.                     RichTextObject.CellContent.ReadContentFromElement(RTFElement);
  1115.                 }
  1116.  
  1117.                 Transaction.Commit();
  1118.             }
  1119.             catch (error)
  1120.             {
  1121.                 //alert("Transaction aborted in enableTextView(" + i_Index + ") [" + error.description + "]");
  1122.                 Transaction.Abort();
  1123.             }
  1124.  
  1125.             if (g_IsFormPreview || !g_IsReadOnly || (g_IsReadOnly && !g_IsPreviewPane && !g_IsPrinting))
  1126.             {
  1127.                 // Don't allow objects to be dropped in a search dialog.
  1128.                 if (g_IsSearch)
  1129.                     RichTextObject.IGrooveTextImportControl.AcceptObjects = false;
  1130.  
  1131.                 // Set the ReadOnly, BorderHidden, and BackColor properties.
  1132.                 var IsReadOnly = false;
  1133.                 var ReadOnlyAttribute = RichTextObject.getAttribute("ISREADONLY");
  1134.                 var DisabledAttribute = RichTextObject.getAttribute("ISDISABLEDBYSCRIPT");
  1135.                 var IsSearchableAttribute = RichTextObject.getAttribute("ISSEARCHABLE");
  1136.                 if (ReadOnlyAttribute != null || DisabledAttribute != null || g_IsReadOnly || (g_IsSearch && IsSearchableAttribute == null))
  1137.                     IsReadOnly = true;
  1138.  
  1139.                 int_DisableRichTextField(RichTextObject, IsReadOnly);
  1140.                 setCommandDisabledState(RichTextObjectName + "Spellcheck", !RichTextObject.CanCheckSpelling);
  1141.  
  1142.                 var BorderHiddenAttribute = RichTextObject.getAttribute("ISBORDERHIDDEN");
  1143.                 if (BorderHiddenAttribute != null)
  1144.                     RichTextObject.BorderVisible = false;
  1145.  
  1146.                 var BackgroundColorAttribute = RichTextObject.getAttribute("BACKGROUNDCOLOR");
  1147.                 if (BackgroundColorAttribute != null && BackgroundColorAttribute != "")
  1148.                 {
  1149.                     if (BackgroundColorAttribute == "Transparent")
  1150.                     {
  1151.                         RichTextObject.BackStyle = 1;
  1152.                     }
  1153.                     else if (BackgroundColorAttribute.indexOf("#") == 0 && BackgroundColorAttribute.length == 7)
  1154.                     {
  1155.                         // Reverse red and blue as text view needs BGR, not RGB.
  1156.                         var Red = BackgroundColorAttribute.substring(1, 3);
  1157.                         var Green = BackgroundColorAttribute.substring(3, 5);
  1158.                         var Blue = BackgroundColorAttribute.substring(5, 7);
  1159.                         // Convert the HTML color into a long for the text view control.
  1160.                         var BackgroundColor = "0x" + Blue + Green + Red;
  1161.                         RichTextObject.BackColor = parseInt(BackgroundColor);
  1162.                     }
  1163.                 }
  1164.             }
  1165.             else
  1166.             {
  1167.                 var RichTextPreview = document.getElementById(RichTextName + "_preview");
  1168.                 if (RichTextPreview != null)
  1169.                 {
  1170.                     var RTFContent = getScriptHostQI("IGrooveFormsToolUIDelegatePrintFormPrivate").OpenRTFContent(RichTextObject);
  1171.                     if (RTFContent != null)
  1172.                         RichTextPreview.innerHTML = RTFContent;
  1173.                     else
  1174.                         RichTextPreview.innerText = "";
  1175.                 }
  1176.             }
  1177.         }
  1178.         else
  1179.         {
  1180.             if (g_EnableTextViewCount < 10)
  1181.             {
  1182.                 g_EnableTextViewCount++;
  1183.                 window.setTimeout("enableTextView(" + i_Index + ")", 250);
  1184.             }
  1185.         }
  1186.     }
  1187.  
  1188.     g_IsInitializingTextView = false;
  1189. }
  1190.  
  1191. function enableContactFields()
  1192. {
  1193.     for (var i = 0; i < g_ContactFields.length; i++)
  1194.     {
  1195.         var ContactField = g_ContactFields[i];
  1196.         var ContactFieldName = ContactField.id;
  1197.  
  1198.         var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction();
  1199.         try
  1200.         {
  1201.             var FormRecord = GetFormRecord();
  1202.             if (FormRecord != null && FormRecord.HasField(ContactFieldName))
  1203.             {
  1204.                 var Contact = FormRecord.OpenField(ContactFieldName);
  1205.                 displayContactInfo(Contact, ContactFieldName, false);
  1206.             }
  1207.  
  1208.             Transaction.Commit();
  1209.         }
  1210.         catch (error)
  1211.         {
  1212.             //alert("Transaction aborted in enableContactFields(" + i + ") [" + error.description + "]");
  1213.             Transaction.Abort();
  1214.         }
  1215.     }
  1216. }
  1217.  
  1218. function registerContactFields()
  1219. {
  1220.     for (var i = 0; i < g_ContactFields.length; i++)
  1221.     {
  1222.         var ContactField = g_ContactFields[i];
  1223.         if (ContactField != null)
  1224.         {
  1225.             var ContactFieldName = ContactField.id;
  1226.             var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction();
  1227.             try
  1228.             {
  1229.                 var FormRecord = GetFormRecord();
  1230.                 if (FormRecord != null && FormRecord.HasField(ContactFieldName))
  1231.                 {
  1232.                     var Contact = FormRecord.OpenField(ContactFieldName);
  1233.                     if (Contact != null)
  1234.                         registerContact(Contact, ContactFieldName);
  1235.                 }
  1236.  
  1237.                 Transaction.Commit();
  1238.             }
  1239.             catch (error)
  1240.             {
  1241.                 //alert("Transaction aborted in registerContactFields(" + i + ") [" + error.description + "]");
  1242.                 Transaction.Abort();
  1243.             }
  1244.         }
  1245.     }
  1246. }
  1247.  
  1248. function enableDocumentShare()
  1249. {
  1250.     if (g_AttachmentsObject == null)
  1251.         return;
  1252.  
  1253.     if (g_IsSearch || g_IsFormPreview || g_IsPrinting)
  1254.     {
  1255.         setCommandDisabledState(g_AttachmentsObject.id + "Add", true);
  1256.         setCommandDisabledState(g_AttachmentsObject.id + "Launch", true);
  1257.         setCommandDisabledState(g_AttachmentsObject.id + "Save", true);
  1258.         setCommandDisabledState(g_AttachmentsObject.id + "Delete", true);
  1259.     }
  1260.  
  1261.     g_IsInitializingDocumentShare = true;
  1262.  
  1263.     if (!g_IsFormPreview)
  1264.     {
  1265.         try
  1266.         {
  1267.             if (g_AttachmentsObject.Properties2.Initialized)
  1268.             {
  1269.                 var IsReadOnly = false;
  1270.                 var ReadOnlyAttribute = g_AttachmentsObject.getAttribute("ISREADONLY");
  1271.                 var DisabledAttribute = g_AttachmentsObject.getAttribute("ISDISABLEDBYSCRIPT");
  1272.                 if (ReadOnlyAttribute != null || DisabledAttribute != null || g_IsReadOnly || g_IsSearch)
  1273.                     IsReadOnly = true;
  1274.  
  1275.                 int_DisableAttachmentsField(g_AttachmentsObject, IsReadOnly);
  1276.  
  1277.                 var IsHiddenAttribute = g_AttachmentsObject.getAttribute("ISHIDDEN");
  1278.                 if (IsHiddenAttribute == null)
  1279.                 {
  1280.                     // Hide the attachments field if it is read-only, or
  1281.                     // in the preview pane, and there are no attachments.
  1282.                     var AttachmentCount = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").GetAttachmentCount(g_AttachmentsElement);
  1283.                     var DisplayStyle = ""
  1284.                     if (!g_IsNew && g_IsReadOnly && AttachmentCount == 0)
  1285.                         DisplayStyle = "none";
  1286.  
  1287.                     var objAttachmentLabel = document.getElementById(g_AttachmentsObject.id + "_label");
  1288.                     if (objAttachmentLabel != null)
  1289.                         objAttachmentLabel.style.display = DisplayStyle;
  1290.                     var objAttachmentField = document.getElementById(g_AttachmentsObject.id + "_field");
  1291.                     if (objAttachmentField != null)
  1292.                         objAttachmentField.style.display = DisplayStyle;
  1293.                 }
  1294.  
  1295.                 if (!g_IsPrinting && !g_IsSearch)
  1296.                     getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").SetCurrentDocumentShareView(g_AttachmentsObject.object, g_AttachmentsObject.id);
  1297.             }
  1298.             else
  1299.             {
  1300.                 if (g_EnableDocumentShareCount < 10)
  1301.                 {
  1302.                     g_EnableDocumentShareCount++;
  1303.                     window.setTimeout("enableDocumentShare()", 250);
  1304.                 }
  1305.             }
  1306.         }
  1307.         catch (error)
  1308.         {
  1309.             if (g_EnableDocumentShareCount < 10)
  1310.             {
  1311.                 g_EnableDocumentShareCount++;
  1312.                 window.setTimeout("enableDocumentShare()", 250);
  1313.             }
  1314.         }
  1315.     }
  1316.  
  1317.     g_IsInitializingDocumentShare = false;
  1318. }
  1319.  
  1320. function enableDataList(i_Index)
  1321. {
  1322.     if (!g_IsFormPreview)
  1323.     {
  1324.         try
  1325.         {
  1326.             var DataListObject = g_DataListObjects[i];
  1327.             if (DataListObject.IGrooveDataListDisplay.Initialized)
  1328.                 getScriptHostQI("IGrooveFormsToolUIDelegateViewPrivate").EnableDataList(document, DataListObject);
  1329.             else
  1330.             {
  1331.                 if (g_EnableDataListCount < 10)
  1332.                 {
  1333.                     g_EnableDataListCount++;
  1334.                     setTimeout("enableDataList(" + i_Index + ")", 250);
  1335.                 }
  1336.             }
  1337.         }
  1338.         catch (error)
  1339.         {
  1340.             if (g_EnableDataListCount < 10)
  1341.             {
  1342.                 g_EnableDataListCount++;
  1343.                 window.setTimeout("enableDataList(" + i_Index + ")", 250);
  1344.             }
  1345.         }
  1346.     }
  1347. }
  1348.  
  1349. function setCommandDisabledState(i_Name, i_IsReadOnly)
  1350. {
  1351.     var objCommand = document.getElementById(i_Name);
  1352.     var objCommandButton = document.getElementById(i_Name + "Button");
  1353.     if (objCommand && objCommandButton)
  1354.     {
  1355.         objCommand.setAttribute("COMMANDDISABLED", i_IsReadOnly);
  1356.         if (i_IsReadOnly)
  1357.             objCommandButton.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=50);";
  1358.         else
  1359.             objCommandButton.style.filter = "";
  1360.     }
  1361. }
  1362.  
  1363. function setCommandPressedState(i_Name, i_IsPressed)
  1364. {
  1365.     var objCommand = document.getElementById(i_Name);
  1366.     if (objCommand != null)
  1367.     {
  1368.         if (i_IsPressed && !objCommand.getAttribute("COMMANDPRESSED"))
  1369.         {
  1370.             with (objCommand.style)
  1371.             {
  1372.                 backgroundImage = "url(rtf_pressed.gif)";
  1373.                 borderTopColor = "buttonshadow";
  1374.                 borderRightColor = "buttonhighlight";
  1375.                 borderBottomColor = "buttonhighlight";
  1376.                 borderLeftColor = "buttonshadow";
  1377.             }
  1378.         }
  1379.         else if (!i_IsPressed && objCommand.getAttribute("COMMANDPRESSED"))
  1380.         {
  1381.             with (objCommand.style)
  1382.             {
  1383.                 backgroundImage = "";
  1384.                 border = "1px solid buttonface";
  1385.             }
  1386.         }
  1387.         objCommand.setAttribute("COMMANDPRESSED", i_IsPressed);
  1388.     }
  1389. }
  1390.  
  1391. function commandMouseOver(i_Command)
  1392. {
  1393.     if (!i_Command.getAttribute("COMMANDDISABLED") && !i_Command.getAttribute("COMMANDPRESSED"))
  1394.         i_Command.className = "commandHover";
  1395. }
  1396.  
  1397. function commandMouseOut(i_Command)
  1398. {
  1399.     if (!i_Command.getAttribute("COMMANDDISABLED") && !i_Command.getAttribute("COMMANDPRESSED"))
  1400.         i_Command.className = "command";
  1401. }
  1402.  
  1403. function commandMouseDown(i_Command)
  1404. {
  1405.     if (!i_Command.getAttribute("COMMANDDISABLED") && !i_Command.getAttribute("COMMANDPRESSED"))
  1406.         i_Command.className = "commandDown";
  1407. }
  1408.  
  1409. function commandMouseUp(i_Command)
  1410. {
  1411.     if (!i_Command.getAttribute("COMMANDDISABLED") && !i_Command.getAttribute("COMMANDPRESSED"))
  1412.         i_Command.className = "commandHover";
  1413. }
  1414.  
  1415. // =====================================================
  1416. // ===                Inherit Utility                ===
  1417. // =====================================================
  1418.  
  1419. function inheritFieldValue(i_Object)
  1420. {
  1421.     if (i_Object != null & !g_IsSearch && !g_IsFormPreview && !g_IsPrinting && g_IsNew && getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").IsValidRecord(g_SelectedID))
  1422.     {
  1423.         var InheritAttribute = i_Object.getAttribute("INHERIT");
  1424.         if (InheritAttribute != null && InheritAttribute != "")
  1425.         {
  1426.             var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction();
  1427.             try
  1428.             {
  1429.                 var ObjectName = i_Object.id;
  1430.                 if (InheritAttribute == "FormsInheritSelf")
  1431.                     InheritAttribute = ObjectName;
  1432.  
  1433.                 var ParentRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").OpenRecord(g_SelectedID);
  1434.                 if (ParentRecord.HasField(InheritAttribute))
  1435.                 {
  1436.                     var FormRecord = openCurrentRecord();
  1437.                     if (FormRecord != null)
  1438.                     {
  1439.                         var FieldTypeAttribute = i_Object.getAttribute("FIELDTYPE");
  1440.                         if (FieldTypeAttribute == FormObjectType_Attachments || FieldTypeAttribute == FormObjectType_RichText)
  1441.                             FormRecord.SetField(ObjectName, ParentRecord.OpenField(InheritAttribute));
  1442.                         else if (FieldTypeAttribute == FormObjectType_Contact)
  1443.                             FormRecord.SetField(ObjectName, ParentRecord.OpenField(InheritAttribute));
  1444.                     }
  1445.                 }
  1446.  
  1447.                 Transaction.Commit();
  1448.             }
  1449.             catch (error)
  1450.             {
  1451.                 //alert("Transaction aborted in inheritFieldValue [" + error.description + "]");
  1452.                 Transaction.Abort();
  1453.             }
  1454.         }
  1455.     }
  1456. }
  1457.  
  1458. // =====================================================
  1459. // ===                Option Utility                 ===
  1460. // =====================================================
  1461.  
  1462. function addNewOption(i_Name)
  1463. {
  1464.     try
  1465.     {
  1466.         var DocumentElement = document.getElementById(i_Name);
  1467.         if (DocumentElement != null)
  1468.         {
  1469.             var AddOptionResult = getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayTextInputDialog("Enter text:", "Add Custom Entry");
  1470.             if (AddOptionResult.Result == GrooveDialogBoxResultCode_OK)
  1471.             {
  1472.                 insertNewOption(DocumentElement, AddOptionResult.Data, AddOptionResult.Data, true);
  1473.                 DocumentElement.fireEvent("onchange");
  1474.             }
  1475.         }
  1476.     }
  1477.     catch (error)
  1478.     {
  1479.         var OptionError = "There was an error adding the custom option to the drop-down list, most likely caused by the form reloading in response to a design change. Please try adding the custom option again.";
  1480.         getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayError(OptionError);
  1481.     }
  1482. }
  1483.  
  1484. function insertNewOption(i_Element, i_Value, i_Text, i_IsSelected)
  1485. {
  1486.     var NewOption = document.createElement("OPTION");
  1487.     NewOption.value = i_Value;
  1488.     NewOption.text = i_Text;
  1489.  
  1490.     i_Element.options.add(NewOption);
  1491.  
  1492.     if (i_IsSelected)
  1493.         i_Element.value = i_Value;
  1494. }
  1495.  
  1496. function insertNewOptionUnique(i_Element, i_Value, i_Text, i_IsSelected)
  1497. {
  1498.     // Check the list to see if the option already exists.
  1499.     for (var i = 0; i < i_Element.options.length; i++)
  1500.     {
  1501.         if (i_Element.options[i].value == i_Value)
  1502.             return;
  1503.     }
  1504.  
  1505.     insertNewOption(i_Element, i_Value, i_Text, i_IsSelected);
  1506. }
  1507.  
  1508. // =====================================================
  1509. // ===                Data Submission                ===
  1510. // =====================================================
  1511.  
  1512. function submitData()
  1513. {
  1514.     if (!g_IsFormPreview && typeof OnBeforeSubmitData != "undefined" && !processCallout(OnBeforeSubmitData))
  1515.         return true;
  1516.  
  1517.     // Only continue if data saved with no errors.
  1518.     if (submitDataNoNavigate())
  1519.     {
  1520.         if (!g_IsFormPreview && typeof OnAfterSubmitData != "undefined" && !processCallout(OnAfterSubmitData))
  1521.             return true;
  1522.  
  1523.         // MWATodo: we have to do these timeouts to avoid a deadlock for now.
  1524.         if (g_IsCreateAnother)
  1525.         {
  1526.             var strHref = window.location.href;
  1527.             strHref = strHref.replace(/(.*)\?.*$/, "$1");
  1528.  
  1529.             
  1530.             var strQuery = "";
  1531.             if (g_SelectedID != -1 && getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").IsValidRecord(g_SelectedID))
  1532.             {
  1533.                 var strSelectedID = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").ConvertDesignObjectIDToString(g_SelectedID);
  1534.                 strQuery = "?SelectedID=" + strSelectedID;
  1535.             }
  1536.             else if (g_IsResponse)
  1537.             {
  1538.                 var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction();
  1539.                 try
  1540.                 {
  1541.                     // If it is a response, get the parent id and pass it along.
  1542.                     var FormRecord = openCurrentRecord();
  1543.                     if (FormRecord != null && FormRecord.HasField("_ParentID"))
  1544.                         strQuery = "?SelectedID=" + FormRecord.OpenField("_ParentID");
  1545.  
  1546.                     Transaction.Commit();
  1547.                 }
  1548.                 catch (error)
  1549.                 {
  1550.                     //alert("Transaction aborted in submitData [" + error.description + "]");
  1551.                     Transaction.Abort();
  1552.                 }
  1553.             }
  1554.  
  1555.             var strFormID = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").ConvertDesignObjectIDToString(g_FormID);
  1556.             if (strQuery != "")
  1557.                 strQuery += "&FormID=" + strFormID;
  1558.             else
  1559.                 strQuery = "?FormID=" + strFormID;
  1560.  
  1561.             window.setTimeout("window.location.href = '" + strHref + strQuery + "'", 50);
  1562.         }
  1563.         else if (g_IsSearch)
  1564.         {
  1565.             var UIDelegate = getScriptHostQI("IGrooveFormsToolSearchDialogDelegatePrivate").GetUIDelegate();
  1566.             UIDelegate.IGrooveFormsToolUIDelegatePrivate.DoSearch();
  1567.             return true;
  1568.         }
  1569.         else
  1570.         {
  1571.             window.setTimeout("getScriptHostQI('IGrooveFormsToolUIDelegatePrivate').SwitchWebState(FormsUIState_HomePage, -1)", 50);
  1572.         }
  1573.     }
  1574. }
  1575.  
  1576. function submitDataNoNavigate()
  1577. {
  1578.     g_BypassEventCallouts = true;
  1579.  
  1580.     // Fire the onblur event for all elements in the form.
  1581.     var DocumentForm = document.GrooveFormBase;
  1582.     for (var i = 0; i < DocumentForm.elements.length; i++)
  1583.     {
  1584.         var DocumentElement = DocumentForm.elements[i];
  1585.         if (DocumentElement.getAttribute("DATATYPE") == "RichText")
  1586.             validateRequired(DocumentElement);
  1587.         else
  1588.             DocumentElement.fireEvent("onblur");
  1589.     }
  1590.  
  1591.     // Validate that all required contact fields have a contact.
  1592.     var DocumentSpans = document.getElementsByTagName("SPAN");
  1593.     for (var i = 0; i < DocumentSpans.length; i++)
  1594.     {
  1595.         if (DocumentSpans[i].getAttribute("DATATYPE") == "Contact")
  1596.             validateRequired(DocumentSpans[i]);
  1597.     }
  1598.  
  1599.     g_BypassEventCallouts = false;
  1600.  
  1601.     // Check error array to see if there are still uncorrected errors.
  1602.     for (var i = 0; i < g_arrErrors.length; i++)
  1603.     {
  1604.         if (typeof g_arrErrors[i] != "undefined")
  1605.         {
  1606.             getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox("The form values you have entered are not valid. Please correct the error(s) as displayed in the form.", "Invalid Form Values");
  1607.             getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").HasValidationErrors = true;
  1608.             g_IsCreateAnother = false;
  1609.             return false;
  1610.         }
  1611.     }
  1612.     getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").HasValidationErrors = false;
  1613.  
  1614.     var ParentIDHasBeenReset = false;
  1615.     if (g_IsNew && g_IsResponse && !g_SaveAsMain && !getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").IsValidRecord(g_SelectedID))
  1616.     {
  1617.         getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox("You cannot save this record because it is a response to a record that has been deleted. If you want to save data from this record, you can copy and paste it (for example, to Notepad) before closing the record.", "Invalid Selection");
  1618.         return;
  1619.     }
  1620.  
  1621.     var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction();
  1622.  
  1623.     try
  1624.     {
  1625.         var FormRecord;
  1626.         if (!g_IsSearch)
  1627.         {
  1628.             FormRecord = openCurrentRecord();
  1629.             if (FormRecord != null)
  1630.             {
  1631.                 // If the record is versioned, save a copy as a child.
  1632.                 if (!g_IsNew && g_IsVersioned)
  1633.                     getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").CreateVersionedRecord(FormRecord, g_RecordID);
  1634.  
  1635.                 // Save the parent ID if this is a response record.
  1636.                 if (g_IsNew && g_IsResponse && !ParentIDHasBeenReset)
  1637.                 {
  1638.                     var ParentID = -1;
  1639.                     if (FormRecord.HasField("_ParentID"))
  1640.                         ParentID = FormRecord.OpenField("_ParentID");
  1641.  
  1642.                     if (!getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").IsValidRecord(ParentID))
  1643.                         FormRecord.SetField("_ParentID", g_SelectedID);
  1644.                 }
  1645.  
  1646.                 // Save the form ID, for later use.
  1647.                 var FormID = FormRecord.OpenField("Forms_Tool_grooveFormID");
  1648.                 if (FormID != g_FormID)
  1649.                     FormRecord.SetField("Forms_Tool_grooveFormID", g_FormID);
  1650.  
  1651.                 // Save the record ID for script use.
  1652.                 g_RecordID = FormRecord.ID;
  1653.             }
  1654.         }
  1655.         else
  1656.         {
  1657.             // Start the search query on the UI delegate.
  1658.             var UIDelegate = getScriptHostQI("IGrooveFormsToolSearchDialogDelegatePrivate").GetUIDelegate();
  1659.             UIDelegate.IGrooveFormsToolUIDelegatePrivate.StartSearchQuery(g_SearchType);
  1660.         }
  1661.  
  1662.         var PropagateUpdatesArray = new Array();
  1663.  
  1664.         // Iterate through form elements to set values in the record.
  1665.         var DocumentForm = document.GrooveFormBase;
  1666.         for (var i = 0; i < DocumentForm.elements.length; i++)
  1667.         {
  1668.             var DocumentElement = DocumentForm.elements[i];
  1669.             setFormElementValue(DocumentElement, FormRecord);
  1670.  
  1671.             var PropagateUpdatesAttribute = DocumentElement.getAttribute("PROPAGATEUPDATES");
  1672.             if (PropagateUpdatesAttribute != null)
  1673.             {
  1674.                 var DocumentElementName = DocumentElement.id;
  1675.                 if (DocumentElementName == "")
  1676.                     DocumentElementName = DocumentElement.name;
  1677.                 PropagateUpdatesArray.push(DocumentElementName);
  1678.             }
  1679.         }
  1680.  
  1681.         // Iterate through contact fields to set values in the record.
  1682.         var DocumentSpans = document.getElementsByTagName("SPAN");
  1683.         for (var i = 0; i < DocumentSpans.length; i++)
  1684.         {
  1685.             if (DocumentSpans[i].getAttribute("DATATYPE") == "Contact")
  1686.             {
  1687.                 var DocumentElement = DocumentSpans[i];
  1688.                 setFormElementValue(DocumentElement, FormRecord);
  1689.  
  1690.                 var PropagateUpdatesAttribute = DocumentElement.getAttribute("PROPAGATEUPDATES");
  1691.                 if (PropagateUpdatesAttribute != null)
  1692.                 {
  1693.                     var DocumentElementName = DocumentElement.id;
  1694.                     if (DocumentElementName == "")
  1695.                         DocumentElementName = DocumentElement.name;
  1696.                     PropagateUpdatesArray.push(DocumentElementName);
  1697.                 }
  1698.             }
  1699.         }
  1700.  
  1701.         // Add the record to the database if it is new.
  1702.         if (g_IsNew && !g_IsSearch)
  1703.         {
  1704.             if (FormRecord != null)
  1705.             {
  1706.                 getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").AddRecord(FormRecord);
  1707.                 getScriptHostQI("IGrooveFormsToolUIDelegateViewPrivate").SetFocusRecordID(FormRecord.ID);
  1708.             }
  1709.  
  1710.             // Make sure the UIDelegate knows that the auto-create record has been created.
  1711.             if (getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").NeedToAutoCreateRecord())
  1712.                 getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").AutoCreateRecordCreated();
  1713.         }
  1714.  
  1715.         // Propagate updates to the children of this record.
  1716.         propagateUpdates(PropagateUpdatesArray, FormRecord);
  1717.  
  1718.         // Set the dirty bit to false.
  1719.         int_setIsDirty(false);
  1720.  
  1721.         Transaction.Commit();
  1722.  
  1723.         return true;
  1724.     }
  1725.     catch (error)
  1726.     {
  1727.         alert("Transaction aborted in submitDataNoNavigate [" + error.description + "]");
  1728.         Transaction.Abort();
  1729.  
  1730.         return false;
  1731.     }
  1732. }
  1733.  
  1734. function setFormElementValue(i_Element, i_Record)
  1735. {
  1736.     var ElementName = i_Element.id;
  1737.     if (ElementName == "")
  1738.         ElementName = i_Element.name;
  1739.     var ElementType = i_Element.type;
  1740.     var ElementDataType = i_Element.getAttribute("DATATYPE");
  1741.  
  1742.     if (g_IsSearch || (typeof i_Record != "undefined" && i_Record != null))
  1743.     {
  1744.         // Check to see if the field exists in the record.
  1745.         if (g_IsSearch || i_Record.HasField(ElementName))
  1746.         {
  1747.             // Set the value for each field depending on the element type.
  1748.             if (ElementType == "text" || ElementType == "textarea" || ElementType == "password")
  1749.             {
  1750.                 var ElementValue = i_Element.value;
  1751.  
  1752.                 if (ElementDataType == "Numeric")
  1753.                 {
  1754.                     if (typeof ElementValue != "undefined" && ElementValue != null && ElementValue != "")
  1755.                     {
  1756.                         ElementValue = getValidNumber(i_Element);
  1757.                         if (g_IsSearch)
  1758.                             addToCurrentSearch(ElementName, ElementValue.toString());
  1759.                     }
  1760.                     else
  1761.                         ElementValue = 0;
  1762.  
  1763.                     if (!g_IsSearch)
  1764.                     {
  1765.                         var RecordValue = i_Record.OpenField(ElementName);
  1766.                         if (RecordValue != ElementValue)
  1767.                             i_Record.SetField(ElementName, ElementValue);
  1768.                     }
  1769.                 }
  1770.                 else if (ElementDataType == "Date")
  1771.                 {
  1772.                     if (ElementValue != "")
  1773.                     {
  1774.                         var DateFormat = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").CreateDateFormatStyleFromAttributeValue(i_Element.getAttribute("FORMAT"));
  1775.                         ElementValue = getValidDateMillis(ElementValue, DateFormat, i_Element);
  1776.                     }
  1777.                     else
  1778.                         ElementValue = INVALID_DATE;
  1779.  
  1780.                     // If this is a search add the field to the query.
  1781.                     if (g_IsSearch)
  1782.                     {
  1783.                         if (ElementValue != INVALID_DATE)
  1784.                             addToCurrentSearch(ElementName, ElementValue.toString());
  1785.                     }
  1786.                     else
  1787.                     {
  1788.                         var RecordValue = i_Record.OpenField(ElementName);
  1789.                         if (RecordValue != ElementValue)
  1790.                             i_Record.SetField(ElementName, ElementValue);
  1791.                     }
  1792.                 }
  1793.                 else if (ElementDataType != "Time")
  1794.                 {
  1795.                     // If this is a search add the field to the query.
  1796.                     if (g_IsSearch)
  1797.                         addToCurrentSearch(ElementName, ElementValue);
  1798.                     else
  1799.                     {
  1800.                         var RecordValue = i_Record.OpenField(ElementName);
  1801.                         if (RecordValue != ElementValue)
  1802.                             i_Record.SetField(ElementName, ElementValue);
  1803.                     }
  1804.                 }
  1805.             }
  1806.             else if (ElementType == "checkbox")
  1807.             {
  1808.                 var ElementValue = "";
  1809.  
  1810.                 if (i_Element.checked)
  1811.                 {
  1812.                     ElementValue = i_Element.value;
  1813.                     if (ElementValue == "on" || ElementValue == "")
  1814.                         ElementValue = "true";
  1815.                 }
  1816.  
  1817.                 // If this is a search add the field to the query.
  1818.                 if (g_IsSearch)
  1819.                     addToCurrentSearch(ElementName, ElementValue);
  1820.                 else
  1821.                 {
  1822.                     var RecordValue = i_Record.OpenField(ElementName);
  1823.                     if (RecordValue != ElementValue)
  1824.                         i_Record.SetField(ElementName, ElementValue);
  1825.                 }
  1826.             }
  1827.             else if (ElementType == "radio")
  1828.             {
  1829.                 if (i_Element.checked)
  1830.                 {
  1831.                     var ElementValue = i_Element.value;
  1832.                     // If this is a search add the field to the query.
  1833.                     if (g_IsSearch)
  1834.                         addToCurrentSearch(ElementName, ElementValue);
  1835.                     else
  1836.                     {
  1837.                         var RecordValue = i_Record.OpenField(ElementName);
  1838.                         if (RecordValue != ElementValue)
  1839.                             i_Record.SetField(ElementName, ElementValue);
  1840.                     }
  1841.                 }
  1842.             }
  1843.             if (ElementType == "select-one")
  1844.             {
  1845.                 var ElementValue = "";
  1846.  
  1847.                 var SelectedIndex = i_Element.selectedIndex;
  1848.                 if (SelectedIndex >= 0)
  1849.                     ElementValue = i_Element.options[SelectedIndex].value;
  1850.  
  1851.                 // If this is a search add the field to the query.
  1852.                 if (g_IsSearch)
  1853.                     addToCurrentSearch(ElementName, ElementValue);
  1854.                 else
  1855.                 {
  1856.                     var RecordValue = i_Record.OpenField(ElementName);
  1857.                     if (RecordValue != ElementValue)
  1858.                         i_Record.SetField(ElementName, ElementValue);
  1859.                 }
  1860.             }
  1861.             else if (ElementType == "select-multiple")
  1862.             {
  1863.                 var ElementValue = "";
  1864.  
  1865.                 // Editors and Readers fields are separated with a semi-colon.
  1866.                 var ElementValueSeparator = "\n";
  1867.                 if (ElementName == "_Editors" || ElementName == "_Readers")
  1868.                     ElementValueSeparator = ";";
  1869.  
  1870.                 for (var i = 0; i < i_Element.options.length; i++)
  1871.                 {
  1872.                     if (i_Element.options[i].selected)
  1873.                     {
  1874.                         var TempValue = i_Element.options[i].value;
  1875.                         if (TempValue == "")
  1876.                             TempValue = i_Element.options[i].text;
  1877.  
  1878.                         if (ElementValue != "")
  1879.                             ElementValue += ElementValueSeparator + TempValue;
  1880.                         else
  1881.                             ElementValue += TempValue;
  1882.                     }
  1883.                 }
  1884.  
  1885.                 // If this is a search add the field to the query.
  1886.                 if (g_IsSearch)
  1887.                     addToCurrentSearch(ElementName, ElementValue);
  1888.                 else
  1889.                 {
  1890.                     var RecordValue = i_Record.OpenField(ElementName);
  1891.                     if (RecordValue != ElementValue)
  1892.                         i_Record.SetField(ElementName, ElementValue);
  1893.                 }
  1894.             }
  1895.             else if (ElementDataType == "RichText")
  1896.             {
  1897.                 if (g_IsSearch)
  1898.                 {
  1899.                     // Get the plain text out of the rich text object.
  1900.                     var PlainText = getPlainText(i_Element);
  1901.                     if (PlainText != "")
  1902.                         addToCurrentSearch(ElementName, PlainText.replace(/^[\n\r]*/, "").replace(/[\n\r]*$/, ""));
  1903.                 }
  1904.                 else
  1905.                 {
  1906.                     var RichTextElement = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").CreateRichTextElement();
  1907.                     i_Element.CellContent.WriteContentToElement(RichTextElement);
  1908.  
  1909.                     var RecordElement = i_Record.OpenField(ElementName);
  1910.                     if (!RecordElement.Equals(RichTextElement))
  1911.                     {
  1912.                         if (!i_Element.TextContent.IsEmpty())
  1913.                             i_Record.SetField(ElementName, RichTextElement);
  1914.                         else
  1915.                         {
  1916.                             // Set the field back to it's default element if they are the same.
  1917.                             var DefaultElement = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").GetDefaultValueAsElement(i_Record, ElementName);
  1918.                             if (DefaultElement.Equals(RichTextElement))
  1919.                                 i_Record.SetField(ElementName, DefaultElement);
  1920.                             else
  1921.                                 i_Record.SetField(ElementName, RichTextElement);
  1922.                         }                        
  1923.                     }
  1924.                 }
  1925.             }
  1926.             else if (ElementDataType == "Attachments")
  1927.             {
  1928.                 if (!g_IsSearch)
  1929.                 {
  1930.                     var AttachmentCount = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").GetAttachmentCount(g_AttachmentsElement);
  1931.                     // Set the file icon field if there is at least one attachment.
  1932.                     i_Record.SetField("FileIcon", AttachmentCount > 0 ? 1 : 0);
  1933.                     // Set the attachment element if it has changed.
  1934.                     var RecordElement = i_Record.OpenField(ElementName);
  1935.                     if (!RecordElement.Equals(g_AttachmentsElement))
  1936.                     {
  1937.                         if (AttachmentCount > 0)
  1938.                             i_Record.SetField(ElementName, g_AttachmentsElement);
  1939.                         else
  1940.                         {
  1941.                             // Set the field back to it's default element
  1942.                             var DefaultElement = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").GetDefaultValueAsElement(i_Record, ElementName);
  1943.                             i_Record.SetField(ElementName, DefaultElement);
  1944.                         }
  1945.                     }
  1946.                 }
  1947.             }
  1948.             else if (ElementDataType == "Contact")
  1949.             {
  1950.                 if (!g_IsSearch)
  1951.                 {
  1952.                     var ContactURL = i_Element.getAttribute("CONTACTURL");
  1953.                     if (!g_IsNew || (g_IsNew && ContactURL != null && ContactURL != ""))
  1954.                     {
  1955.                         var Contact = g_RegisteredContactFields[ElementName];
  1956.  
  1957.                         var FormRecord = GetFormRecord();
  1958.                         var RecordValue = FormRecord.OpenField(ElementName);
  1959.                         // Set the contact if it has changed.
  1960.                         if (RecordValue != Contact)
  1961.                         {
  1962.                             // If the contact was removed, set it to a null pointer.
  1963.                             var ContactType = i_Element.getAttribute("CONTACTTYPE");
  1964.                             if (ContactType == "removed")
  1965.                                 i_Record.SetField(ElementName, getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").CreateNullPointer());
  1966.                             else
  1967.                                 FormRecord.SetField(ElementName, Contact);
  1968.                         }
  1969.                     }
  1970.                 }
  1971.             }
  1972.         }
  1973.     }
  1974. }
  1975.  
  1976. function addToCurrentSearch(i_Name, i_Value)
  1977. {
  1978.     if (typeof i_Value != "undefined" && i_Value != null && i_Value.toString() != "")
  1979.         getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").AddToSearchQuery(i_Name, i_Value);
  1980. }
  1981.  
  1982. function propagateUpdates(i_FieldNameArray, i_Record)
  1983. {
  1984.     if (!g_IsNew && !g_IsSearch && i_Record != null && i_FieldNameArray.length > 0)
  1985.     {
  1986.         if (!g_IsFormPreview && typeof OnBeforePropagateUpdates != "undefined" && !processCallout(OnBeforePropagateUpdates))
  1987.             return true;
  1988.  
  1989.         var bSuccess = true;
  1990.         if (!getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").UpdateAllFieldsInChildRecords(int_CreateBSTREnumFromArray(i_FieldNameArray), i_Record))
  1991.         {
  1992.             displayStatusBar("Value propagation to children did not complete successfully. Verify record permissions.", GrooveMessageBoxIcon_Error);
  1993.             bSuccess = false;
  1994.         }
  1995.  
  1996.         if (!g_IsFormPreview && typeof OnAfterPropagateUpdates != "undefined" && !processCalloutWithParameter(OnAfterPropagateUpdates, bSuccess))
  1997.             return true;
  1998.     }
  1999. }
  2000.  
  2001. // =====================================================
  2002. // ===             Button Event Handlers             ===
  2003. // =====================================================
  2004.  
  2005. function saveAndCreateAnother()
  2006. {
  2007.     g_IsCreateAnother = true;
  2008.     submitData();
  2009. }
  2010.  
  2011. function resetData()
  2012. {
  2013.     if (!g_IsSearch)
  2014.         window.location.reload(true);
  2015. }
  2016.  
  2017. function cancelEdit()
  2018. {
  2019.     if (!g_IsSearch)
  2020.     {
  2021.         getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").HasValidationErrors = false;
  2022.         window.setTimeout("getScriptHostQI('IGrooveFormsToolUIDelegatePrivate').SwitchWebState(FormsUIState_HomePage, -1)", 50);
  2023.     }
  2024. }
  2025.  
  2026. function printForm()
  2027. {
  2028.     try
  2029.     {
  2030.         // Have to call directly to the script dispatch when in the dialog.
  2031.         if (!g_IsPrinting)
  2032.             getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").PrintForm();
  2033.         else
  2034.             getScriptHostQI("IGrooveFormsToolPrintDialogDelegatePrivate").PrintForm();
  2035.     }
  2036.     catch (error) { }
  2037. }
  2038.  
  2039. function printThroughForm()
  2040. {
  2041.     var blnContinue = true;
  2042.  
  2043.     for (var i = 0; i < g_RichTextObjects.length; i++)
  2044.     {
  2045.         var InitializedAttribute = g_RichTextObjects[i].getAttribute("ISINITIALIZED");
  2046.         if (InitializedAttribute == null)
  2047.         {
  2048.             blnContinue = false;
  2049.             break;
  2050.         }
  2051.     }
  2052.  
  2053.     if (!blnContinue)
  2054.     {
  2055.         window.setTimeout("printThroughForm()", 250);
  2056.         return;
  2057.     }
  2058.  
  2059.     // If all objects are done initializing then we should print.
  2060.     printForm();
  2061. }
  2062.  
  2063. function updateLookups()
  2064. {
  2065.     var SourceElement = window.event.srcElement;
  2066.     var SourceElementName = SourceElement.id;
  2067.     if (SourceElementName == "")
  2068.         SourceElementName = SourceElement.name;
  2069.     int_updateLookups(false, SourceElementName);
  2070. }
  2071.  
  2072. function int_updateLookups(i_IsInitial, i_SourceElementName)
  2073. {
  2074.     // Iterate through elements in the form to perform lookups.
  2075.     var DocumentForm = document.GrooveFormBase;
  2076.     if (DocumentForm != null && DocumentForm.elements != null)
  2077.     {
  2078.         for (var i = 0; i < DocumentForm.elements.length; i++)
  2079.         {
  2080.             var DocumentElement = DocumentForm.elements[i];
  2081.             var DocumentElementName = DocumentElement.id;
  2082.             if (DocumentElementName == "")
  2083.                 DocumentElementName = DocumentElement.name;
  2084.             if (DocumentElementName != i_SourceElementName)
  2085.             {
  2086.                 var LookupAttribute = DocumentElement.getAttribute("LOOKUP");
  2087.                 if (LookupAttribute != null)
  2088.                     updateLookup(DocumentElement, i_IsInitial, i_SourceElementName);
  2089.             }
  2090.         }
  2091.     }
  2092.  
  2093.     // Iterate through DIV tags to perform lookups on static text fields.
  2094.     var DivArray = document.getElementsByTagName("DIV");
  2095.     for (var i = 0; i < DivArray.length; i++)
  2096.     {
  2097.         var DocumentDiv = DivArray[i];
  2098.         var LookupAttribute = DocumentDiv.getAttribute("LOOKUP");
  2099.         if (LookupAttribute != null)
  2100.             updateLookup(DocumentDiv, i_IsInitial, i_SourceElementName);
  2101.     }
  2102. }
  2103.  
  2104. function doSearch(i_Type)
  2105. {
  2106.     g_IsSearch = true;
  2107.     g_SearchType = i_Type;
  2108.     return submitData();
  2109. }
  2110.  
  2111. // =====================================================
  2112. // ===              Field Value Lookup               ===
  2113. // =====================================================
  2114.  
  2115. function updateLookup(i_Element, i_IsInitial, i_SourceElementName)
  2116. {
  2117.     // Don't redo any lookups with just switching records.
  2118.     if (g_IsPreviewPaneRefresh && i_Element.tagName == "SELECT")
  2119.         return;
  2120.  
  2121.     var FieldName = i_Element.id;
  2122.     if (FieldName == "")
  2123.         FieldName = i_Element.name;
  2124.     var LookupString = int_GetLookupStringForObject(FieldName);
  2125.  
  2126.     if (LookupString != null && LookupString != "")
  2127.     {
  2128.         // Get all of the values from the lookup string.
  2129.         var TelespaceDisplayName = convertFromXMLName(getValueFromQueryString("TelespaceName", LookupString));
  2130.         var TelespaceURL = convertFromXMLName(getValueFromQueryString("TelespaceURL", LookupString));
  2131.         var ToolDisplayName = convertFromXMLName(getValueFromQueryString("ToolDisplayName", LookupString));
  2132.         var ToolName = convertFromXMLName(getValueFromQueryString("ToolName", LookupString));
  2133.         var ViewName = convertFromXMLName(getValueFromQueryString("ViewName", LookupString));
  2134.         var ViewID = convertFromXMLName(getValueFromQueryString("ViewID", LookupString));
  2135.         var KeyColumn = convertFromXMLName(getValueFromQueryString("KeyColumn", LookupString));
  2136.         var KeyValue = convertFromXMLName(getValueFromQueryString("KeyValue", LookupString));
  2137.         var LookupColumn = convertFromXMLName(getValueFromQueryString("LookupColumn", LookupString));
  2138.         var ReturnUnique = getValueFromQueryString("ReturnUnique", LookupString);
  2139.         var NoCache = getValueFromQueryString("NoCache", LookupString);
  2140.         var KeyValueIsFieldName = getValueFromQueryString("KeyValueIsFieldName", LookupString);
  2141.  
  2142.         // Convert the boolean values from strings.
  2143.         var bReturnUnique = false;
  2144.         if (ReturnUnique == "true")
  2145.             bReturnUnique = true;
  2146.  
  2147.         var bNoCache = false;
  2148.         if (NoCache == "true")
  2149.             bNoCache = true;
  2150.  
  2151.         // Get the true key value from a field if it is a field name.
  2152.         if (KeyValueIsFieldName == "true")
  2153.         {
  2154.             var KeyValueElement = document.getElementById(KeyValue);
  2155.             if (KeyValueElement != null)
  2156.             {
  2157.                 var KeyValueElementType = KeyValueElement.type;
  2158.                 if (KeyValueElementType == "text" || KeyValueElementType == "textarea")
  2159.                     KeyValue = KeyValueElement.value;
  2160.                 else if (KeyValueElementType.indexOf("select") == 0 && KeyValueElement.selectedIndex >= 0)
  2161.                     KeyValue = KeyValueElement.options[KeyValueElement.selectedIndex].value;
  2162.                 else
  2163.                     KeyValue = "";
  2164.  
  2165.                 if (i_IsInitial)
  2166.                 {
  2167.                     if (KeyValueElementType == "text" || KeyValueElementType == "textarea" || KeyValueElementType.indexOf("select") == 0)
  2168.                         KeyValueElement.attachEvent("onchange", updateLookups);
  2169.                     else if (KeyValueElementType == "password")
  2170.                         KeyValueElement.attachEvent("onblur", updateLookups);
  2171.                     else if (KeyValueElementType == "checkbox" || KeyValueElementType == "radio")
  2172.                         KeyValueElement.attachEvent("onclick", updateLookups);
  2173.                 }
  2174.             }
  2175.             else
  2176.             {
  2177.                 displayStatusBar("The field '" + KeyValue + "' does not exist on the form, so the lookup for the field '" + FieldName + "' was not performed.", GrooveMessageBoxIcon_Error);
  2178.                 return;
  2179.             }
  2180.         }
  2181.         else if (typeof i_SourceElementName != "undefined" && i_SourceElementName != null && i_SourceElementName != "")
  2182.             return;
  2183.  
  2184.         var ElementType = i_Element.type;
  2185.         var ElementTagName = i_Element.tagName.toUpperCase();
  2186.         if (ElementTagName == "DIV")
  2187.             ElementType = "static";
  2188.  
  2189.         // Reset the value of the field.
  2190.         var PreviousDropDownValue = "";
  2191.         var PreviousListBoxArray = new Array();
  2192.         if (!i_IsInitial)
  2193.         {
  2194.             if (ElementTagName == "SELECT")
  2195.             {
  2196.                 var ElementOptionsLength = i_Element.options.length;
  2197.                 if (ElementType == "select-one")
  2198.                     PreviousDropDownValue = i_Element.value;
  2199.                 else if (ElementType == "select-multiple")
  2200.                 {
  2201.                     for (var i = 0; i < ElementOptionsLength; i++)
  2202.                     {
  2203.                         if (i_Element.options[i].selected)
  2204.                             PreviousListBoxArray.push(i_Element.options[i].value);
  2205.                     }
  2206.                 }
  2207.  
  2208.                 // Remove any non-original values from the control.
  2209.                 var RemoveCount = 0;
  2210.                 for (var i = 0; i < ElementOptionsLength; i++)
  2211.                 {
  2212.                     var OriginalAttribute = i_Element.options[RemoveCount].getAttribute("ORIGINAL");
  2213.                     if (OriginalAttribute != null)
  2214.                         RemoveCount++;
  2215.                     else
  2216.                         i_Element.options.remove(RemoveCount);
  2217.                 }
  2218.  
  2219.                 // Put the member names back if they should be there.
  2220.                 var MembersAttribute = i_Element.getAttribute("MEMBERS");
  2221.                 if (MembersAttribute != null)
  2222.                 {
  2223.                     var MemberNameEnum = getScriptHostQI("IGrooveFormsToolUIDelegate").CreateMemberNameEnum();
  2224.                     while (MemberNameEnum.HasMore())
  2225.                     {
  2226.                         var MemberName = MemberNameEnum.OpenNext();
  2227.                         insertNewOption(i_Element, MemberName, MemberName, false);
  2228.                     }
  2229.                 }
  2230.             }
  2231.             else if (ElementTagName == "DIV")
  2232.                 i_Element.innerText = "";
  2233.             else
  2234.                 i_Element.value = "";
  2235.         }
  2236.  
  2237.         // Put the value returned from the lookup into the element.
  2238.         var strValueText = "";
  2239.         // Specify the string separator to use for text fields.
  2240.         var strValueSep = ", ";
  2241.         if (ElementType == "textarea")
  2242.             strValueSep = "\n";
  2243.         var ValueEnum = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").LookupValues(TelespaceURL, ToolName, Number(ViewID), KeyColumn, KeyValue, LookupColumn, bReturnUnique, bNoCache);
  2244.         while (ValueEnum != null && ValueEnum.HasMore())
  2245.         {
  2246.             var strValue = ValueEnum.OpenNext();
  2247.             if (ElementType.indexOf("select") == 0)
  2248.             {
  2249.                 // If the lookup is unique don't add duplicate options.
  2250.                 if (bReturnUnique)
  2251.                     insertNewOptionUnique(i_Element, strValue, strValue, false);
  2252.                 else
  2253.                     insertNewOption(i_Element, strValue, strValue, false);
  2254.             }
  2255.             else if (strValueText != "")
  2256.                 strValueText += strValueSep + strValue;
  2257.             else
  2258.                 strValueText += strValue;
  2259.         }
  2260.  
  2261.         // Set the value if it is a text based field.
  2262.         if (!g_IsSearch)
  2263.         {
  2264.             if (ElementTagName == "DIV")
  2265.                 i_Element.innerText = strValueText;
  2266.             else if (ElementType == "text" || ElementType == "textarea")
  2267.                 i_Element.value = strValueText;
  2268.         }
  2269.  
  2270.         // If this is the initial lookup, insert the record value.
  2271.         if (i_IsInitial)
  2272.         {
  2273.             var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction();
  2274.             try
  2275.             {
  2276.                 var FormRecord = openCurrentRecord();
  2277.                 if (FormRecord != null && FormRecord.HasField(FieldName))
  2278.                 {
  2279.                     if (ElementType == "select-one")
  2280.                         PreviousDropDownValue = FormRecord.OpenField(FieldName);
  2281.                     else if (ElementType == "select-multiple")
  2282.                     {
  2283.                         var FieldValue = FormRecord.OpenField(FieldName);
  2284.                         PreviousListBoxArray = FieldValue.split("\n");
  2285.                     }
  2286.                 }
  2287.                 Transaction.Commit();
  2288.             }
  2289.             catch (error)
  2290.             {
  2291.                 //alert("Transaction aborted in updateLookup [" + error.description + "]");
  2292.                 Transaction.Abort();
  2293.             }
  2294.         }
  2295.  
  2296.         // If the value should be inherited, set it.
  2297.         var InheritedValue = i_Element.getAttribute("INHERITEDVALUE");
  2298.         if (i_IsInitial && InheritedValue != null && InheritedValue != "")
  2299.         {
  2300.             if (ElementType == "select-one")
  2301.                 PreviousDropDownValue = InheritedValue;
  2302.             else if (ElementType == "select-multiple")
  2303.                 PreviousListBoxArray = InheritedValue.split("\n");
  2304.         }
  2305.  
  2306.         // Make sure the value that was previously selected is still selected.
  2307.         if (ElementType == "select-one" && PreviousDropDownValue != "")
  2308.         {
  2309.             var IsValueFound = false;
  2310.             for (var i = 0; i < i_Element.options.length; i++)
  2311.             {
  2312.                 if (i_Element.options[i].value == PreviousDropDownValue)
  2313.                 {
  2314.                     i_Element.options[i].selected = true;
  2315.                     IsValueFound = true;
  2316.                     break;
  2317.                 }
  2318.             }
  2319.  
  2320.             var CustomAttribute = i_Element.getAttribute("CUSTOM");
  2321.             if (CustomAttribute != null && !IsValueFound)
  2322.                 insertNewOption(i_Element, PreviousDropDownValue, PreviousDropDownValue, true);
  2323.         }
  2324.  
  2325.         // List boxes can have multiple items selected so check the previous array.
  2326.         if (ElementType == "select-multiple" && PreviousListBoxArray.length > 0)
  2327.         {
  2328.             for (var i = 0; i < PreviousListBoxArray.length; i++)
  2329.             {
  2330.                 for (var j = 0; j < i_Element.options.length; j++)
  2331.                 {
  2332.                     if (i_Element.options[j].value == PreviousListBoxArray[i])
  2333.                     {
  2334.                         i_Element.options[j].selected = true;
  2335.                         break;
  2336.                     }
  2337.                 }
  2338.             }
  2339.         }
  2340.     }
  2341. }
  2342.  
  2343. function convertFromXMLName(i_XMLName)
  2344. {
  2345.     var Value = i_XMLName;
  2346.  
  2347.     if (i_XMLName != "")
  2348.         Value = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").ConvertFromXMLName(i_XMLName);
  2349.  
  2350.     return Value;
  2351. }
  2352.  
  2353. // =====================================================
  2354. // ===          Design/Role Event Handlers           ===
  2355. // =====================================================
  2356.  
  2357. function designChanged()
  2358. {
  2359.     // We only need to call this method once.
  2360.     if (!g_HasDesignChanged)
  2361.     {
  2362.         // Disable the attachments buttons if they are present
  2363.         if (g_AttachmentsObject != null)
  2364.         {
  2365.             removeDocument();
  2366.  
  2367.             setCommandDisabledState(g_AttachmentsObject.id + "Add", true);
  2368.             setCommandDisabledState(g_AttachmentsObject.id + "Delete", true);
  2369.  
  2370.             addDocument();
  2371.  
  2372.             if (g_AttachmentsObject.Properties2.Initialized)
  2373.                 g_AttachmentsObject.Properties2.SetReadOnlyMode(true);
  2374.         }
  2375.  
  2376.         // Since the document can no longer be saved, it is not dirty.
  2377.         int_setIsDirty(false);
  2378.  
  2379.         g_HasDesignChanged = true;
  2380.     }
  2381. }
  2382.  
  2383. function roleChanged()
  2384. {
  2385.     
  2386.     var EnableButtons = false;
  2387.     if (g_IsNew)
  2388.         EnableButtons = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CanCreateRecords();
  2389.     else
  2390.         EnableButtons = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CanEditRecord(g_RecordID);
  2391.  
  2392.     // Disable the attachments buttons if they are present
  2393.     if (g_AttachmentsObject != null && EnableButtons == false)
  2394.     {
  2395.         removeDocument();
  2396.  
  2397.         setCommandDisabledState(g_AttachmentsObject.id + "Add", !EnableButtons);
  2398.         setCommandDisabledState(g_AttachmentsObject.id + "Delete", !EnableButtons);
  2399.  
  2400.         addDocument();
  2401.  
  2402.         if (g_AttachmentsObject.Properties2.Initialized)
  2403.             g_AttachmentsObject.Properties2.SetReadOnlyMode(!EnableButtons);
  2404.     }
  2405. }
  2406.  
  2407. // =====================================================
  2408. // ===               Rich Text Utility               ===
  2409. // =====================================================
  2410.  
  2411. function getPlainText(i_TextView)
  2412. {
  2413.     // Prepare text view for direct TOM access.
  2414.     i_TextView.Freeze(true);
  2415.     i_TextView.HideDecorations(true);
  2416.  
  2417.     // Retrieve TOM document from text view.
  2418.     var TextCache = i_TextView.TextCache;
  2419.     var TCDocument = TextCache.Document;
  2420.  
  2421.     // Retrieve plain text from the document (see "tom" typelib for tomForward).
  2422.     var Range = TCDocument.Range(0, 1073741823);
  2423.     var PlainText = Range.Text;
  2424.  
  2425.     // We're done accessing the TOM directly.
  2426.     i_TextView.HideDecorations(false);
  2427.     TextCache.Synchronize(1);
  2428.     i_TextView.Freeze(false);
  2429.     
  2430.     return PlainText;
  2431. }
  2432.  
  2433. // =====================================================
  2434. // ===              QueryString Utility              ===
  2435. // =====================================================
  2436.  
  2437. function getQueryStringVariables()
  2438. {
  2439.     var strSearch = String(window.location.search).substring(1);
  2440.     var arrSearch = strSearch.split("&");
  2441.     for (var i = 0; i < arrSearch.length; i++)
  2442.     {
  2443.         // Set up global variables depending on querystring values.
  2444.         var arrSubSearch = arrSearch[i].split("=");
  2445.         switch (arrSubSearch[0])
  2446.         {
  2447.             case "Search":
  2448.                 g_IsSearch = true;
  2449.                 break;
  2450.             case "PreviewPane":
  2451.                 g_IsPreviewPane = true;
  2452.                 break;
  2453.             case "FormPreview":
  2454.                 g_IsFormPreview = true;
  2455.                 break;
  2456.             case "ViewSource":
  2457.                 g_IsViewSource = true;
  2458.                 break;
  2459.             case "Printing":
  2460.                 g_IsPrinting = true;
  2461.                 g_IsReadOnly = true;
  2462.                 break;
  2463.             case "RecordID":
  2464.                 g_RecordID = Number(arrSubSearch[1]);
  2465.                 break;
  2466.             case "SelectedID":
  2467.                 g_SelectedID = Number(arrSubSearch[1]);
  2468.                 break;
  2469.             case "FormID":
  2470.                 g_FormID = Number(arrSubSearch[1]);
  2471.                 break;
  2472.         }
  2473.     }
  2474.  
  2475.     if (!isNaN(g_FormID) && g_FormID != -1)
  2476.     {
  2477.         if (!g_IsSearch)
  2478.         {
  2479.             if (!g_IsFormPreview && !g_IsPrinting)
  2480.             {
  2481.                 // If there is a valid FormID, check if records should be versioned
  2482.                 g_IsVersioned = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").GetFormRecordsAreVersioned(g_FormID);
  2483.                 // If there is a valid FormID, check if it is a response form.
  2484.                 g_IsResponse = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").GetFormIsResponse(g_FormID);
  2485.  
  2486.                 if (g_RecordID != -1 && !getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(g_RecordID))
  2487.                     g_RecordID = -1;
  2488.  
  2489.                 if (g_SelectedID != -1 && !getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(g_SelectedID))
  2490.                     g_SelectedID = -1;
  2491.  
  2492.                 // Check to see if the record should be read-only.
  2493.                 if (getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(g_RecordID))
  2494.                     g_IsReadOnly = !getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CanEditRecord(g_RecordID);
  2495.             }
  2496.  
  2497.             // The record should always be read-only in the preview pane or form preview.
  2498.             if (g_IsPreviewPane || g_IsFormPreview)
  2499.                 g_IsReadOnly = true;
  2500.         }
  2501.     }
  2502.     else
  2503.     {
  2504.         if (!g_IsSearch)
  2505.             window.setTimeout("getScriptHostQI('IGrooveFormsToolUIDelegatePrivate').SwitchWebState(FormsUIState_HomePage, -1)", 50);
  2506.     }
  2507. }
  2508.  
  2509. // =====================================================
  2510. // ===                 Record Utility                ===
  2511. // =====================================================
  2512.  
  2513. function openCurrentRecord()
  2514. {
  2515.     if (g_IsNew)
  2516.         return g_NewRecord;
  2517.     else
  2518.     {
  2519.         if (g_IsPrinting)
  2520.         {
  2521.             return getScriptHostQI("IGrooveFormsToolPrintDialogDelegatePrivate").OpenFormRecord();
  2522.         }
  2523.         else
  2524.         {
  2525.             if (getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(g_RecordID))
  2526.                 return getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").OpenRecord(g_RecordID);
  2527.             else
  2528.                 return null;
  2529.         }
  2530.     }
  2531. }
  2532.