home *** CD-ROM | disk | FTP | other *** search
/ ftp.tcs3.com / ftp.tcs3.com.tar / ftp.tcs3.com / DRIVERS / Audio / Office2010 / ProPlus.WW / ProPsWW.cab / SUBMIT.JS5 < prev    next >
Text File  |  2009-09-29  |  86KB  |  2,619 lines

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