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