<?xml version="1.0" encoding="utf-8"?>
  <finScript version="1.00" exportedUtcDate="2021-12-21T23:47:43.0000000">
    <CreatedUserId>Admin</CreatedUserId>
    <CreatedUtcDate>2021-11-29T03:13:46.3340000</CreatedUtcDate>
    <UpdatedUserId>Admin</UpdatedUserId>
    <UpdatedUtcDate>2021-12-21T23:46:18.1440000</UpdatedUtcDate>
    <ScriptId>CME</ScriptId>
    <Description>Contact Method Edit</Description>
    <ScriptType>HtmlWidget</ScriptType>
    <Active>true</Active>
    <AllowUI>false</AllowUI>
    <Category />
    <Code>' HtmlWidget_ContactMethodEdit
Option Explicit On
Option Strict On

' #################################################################
' Contact Method Edit form HTML Widget
'
' Version: 1.00 (22/12/2021)
'
' Usage: System-supplied HTML Widget
' #################################################################
' Version        Date  User     Job       Description
' -------  ----------  -------  --------  -------------------------
'    1.00  22/12/2021  ISS      J027906   Created
' #################################################################

' Constants
Private Const FORM_KEY As String = "ContactMethods"

' Objects
Private mCombinedParameters As ISKeyValueList
Private mParameters As ISKeyValueList
Private mStartupParameters As ISKeyValueList

' Standard Parameters
Private mContactMethodId As String
Private mDuplicateRecordId As String
Private mPage As String
Private mReadOnly As Boolean

Public Function Main(eventId As String,
                     parametersJson As String,
                     startUpParametersJson As String,
                     hostingContext As isefinHtmlWidgetHostingContext,
                     requestInfo As finScriptRequestInfo,
                     ByRef returnValue As String) As Boolean

  ' Assume Success
  Main = True

  ' Get Parameters
  mParameters = finBL.CreateKeyValueList()
  mParameters.FromSimpleJsonString(parametersJson)
  mStartupParameters = finBL.CreateKeyValueList()
  mStartupParameters.FromSimpleJsonString(startUpParametersJson)

  ' Get Combined Parameters (Startup Parameters updated with event Parameters)
  mCombinedParameters = mStartupParameters.Clone()
  mCombinedParameters.UpdateFromKeyValueList(mParameters, True)

  ' Get Standard Parameters
  With mStartupParameters
    mContactMethodId = .GetString("ContactMethodId") ' Always use Startup Parameters since the ContactMethod Id may be updated
  End With
  With mCombinedParameters
    mDuplicateRecordId = .GetString("DuplicateRecordId")
    mPage = .GetString("Page")
    mReadOnly = .GetBoolean("ReadOnly")
  End With

  ' Validate
  Main = finBL.HtmlWidgetUtilities.HasPermissionToViewFormKey(FORM_KEY)

  ' Handle Events
  If Main Then
    Select Case eventId
      Case ""
        ' Main event, i.e., return initial HTML content (excluding html and body tags)
        returnValue = ScriptInfo.TemplateText

      Case "Finish"
        ' Finish wizard
        Main = Finish(parametersJson, requestInfo, returnValue)

     Case "GetInitialisationInfo"
        ' Get Initialisation Information required for this wizard
        Main = GetInitialisationInfo(returnValue)

      Case Else
        Main = False
        finBL.Error.ErrorBeginFormat("Unhandled event '{0}'", eventId)
    End Select
  End If

End Function

''' &lt;summary&gt;
'''  Load ContactMethod.
''' &lt;/summary&gt;
Private Function GetContactMethod(ByRef contactMethod As finContactMethod) As Boolean

  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Validate

  ' Create and Load ContactMethod
  If Success Then
    ' Create Contact Method
    contactMethod = finBL.CreateContactMethod()

    ' Load ContactMethod
    If Len(mDuplicateRecordId) &lt;&gt; 0 Then
      ' New record (by duplicating existing)
      Success = contactMethod.Load(mDuplicateRecordId)
      If Success Then contactMethod.Duplicate()
    ElseIf Len(mContactMethodId) = 0 Then
      ' New record
    Else
      Success = contactMethod.Load(mContactMethodId)
    End If
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Get Initialisation Information required for this wizard.
''' &lt;/summary&gt;
Public Function GetInitialisationInfo(ByRef response As String) As Boolean

  Dim ContactMethod As finContactMethod
  Dim FormInitialisationInfo As FormInitialisationInfo
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Validate

  ' Get ContactMethod
  If Success Then
    Success = GetContactMethod(ContactMethod)
  End If

  ' Get Initialisation Info
  If Success Then
    FormInitialisationInfo = New FormInitialisationInfo()
    With FormInitialisationInfo
      ' Form
      .PageId = mPage
      If finBL.Database.IsReadOnly OrElse mReadOnly OrElse Not finBL.CurrentUser.Permissions.Allow("Admin.ContactMethods") Then
        .ReadOnly = True
      Else
        .ReadOnly = False
      End If

      ' Record
      .Pk = ContactMethod.Pk
      .Timestamp = ContactMethod.Timestamp

      ' Page Permissions (defined here since they are used below)
      .AllowPageGeneral = True
      .AllowPageOptions = True

      ' General
      .ContactMethodId = ContactMethod.ContactMethodId ' Always need to return Contact Method Id
      If .AllowPageGeneral Then
        .Active = ContactMethod.Active
        .Description = ContactMethod.Description

        .ContactTypeText = ContactMethod.ContactTypeText
        .ContactHome = ContactMethod.ContactHome
        .ContactWork = ContactMethod.ContactWork
        .ContactMobile = ContactMethod.ContactMobile
        .Category = ContactMethod.Category
        .OwnedByClient = ContactMethod.OwnedByClient

        .SubTypeInformationListId = ContactMethod.SubTypeInformationListId
        .TooltipText = ContactMethod.TooltipText

        .DescriptionShort = ContactMethod.DescriptionShort
        .Icon = ContactMethod.Icon
      End If

      ' Options
      If .AllowPageOptions Then
        .LaunchUrl = ContactMethod.LaunchUrl

        .FormatPhoneNumbers = ContactMethod.FormatPhoneNumbers
        .AllowPhoneExtensionEntry = ContactMethod.AllowPhoneExtensionEntry

        .EmailHTML = ContactMethod.EmailHTML
        .PhoneVoice = ContactMethod.PhoneVoice
        .PhoneFacsimile = ContactMethod.PhoneFacsimile
        .PhoneSms = ContactMethod.PhoneSms
        .PhoneMms = ContactMethod.PhoneMms
        .AddressPhysical = ContactMethod.AddressPhysical
        .AddressPostal = ContactMethod.AddressPostal
        .DetailsInformationListId = ContactMethod.DetailsInformationListId
        .AllowLinkedClient = ContactMethod.AllowLinkedClient
        .LinkedClientGroups = ContactMethod.LinkedClientGroups

        .ShowInSummary = ContactMethod.ShowInSummary
        .UserFlagA = ContactMethod.UserFlagA
        .UserFlagB = ContactMethod.UserFlagB
      End If

      ' Other

      ' Permissions

      ' Lists
      .ContactTypeList = finBL.Enums.isefinContactType_ToCodeDescriptionList().ToJsonObject()
      .ListIcons = finBL.Utilities.GetIconListByPrefix("ContactMethod_").ToCsvString()

      ' Configuration
      .HideOtherPages = mCombinedParameters.GetBoolean("HideOtherPages", False)
      .PromptOnSave = finBL.CloudConnectFunctions.CloudConnectSettings.PromptOnSave
    End With
  End If

  ' Response
  If Success Then
    Success = finBL.Runtime.WebUtilities.SerialiseObjectToJsonString(FormInitialisationInfo, response)
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Finish, i.e., Save ContactMethod.
''' &lt;/summary&gt;
''' &lt;param name="parametersJson"&gt;
'''  A JSON formatted record (FormInitialisationInfo) object.
''' &lt;/param&gt;
Private Function Finish(parametersJson As String,
                        requestInfo As finScriptRequestInfo,
                        ByRef returnValue As String) As Boolean

  Dim ContactMethod As finContactMethod
  Dim obj As Object
  Dim Record As FormInitialisationInfo
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Parse Parameters
  If finBL.Runtime.WebUtilities.DeserialiseJsonStringToObject(parametersJson, GetType(FormInitialisationInfo), obj) Then
    Record = DirectCast(obj, FormInitialisationInfo)
  Else
    Success = False
  End If

  ' Get ContactMethod
  If Success Then
    Success = GetContactMethod(ContactMethod)
  End If

  ' Validate
  If Success Then
    If Record.Timestamp &lt;&gt; ContactMethod.Timestamp Then
      Success = False
      finBL.Error.ErrorBegin("This record has been updated by another User.")
    End If
  End If

  ' Update and Save
  ' NOTE: Recheck Permissions in addition to the 'AllowPage' properties before updating to prevent spoofing
  If Success Then
    ' Begin Transaction
    If finBL.Database.TransactionBegin() Then
      ' Update ContactMethod
      With ContactMethod
        ' General
        If Record.AllowPageGeneral Then
          .ContactMethodId = Record.ContactMethodId
          .Active = Record.Active
          .Description = Record.Description

          .ContactTypeText = Record.ContactTypeText
          .ContactHome = Record.ContactHome
          .ContactWork = Record.ContactWork
          .ContactMobile = Record.ContactMobile
          .Category = Record.Category
          .OwnedByClient = Record.OwnedByClient

          .SubTypeInformationListId = Record.SubTypeInformationListId
          .TooltipText = Record.TooltipText

          .DescriptionShort = Record.DescriptionShort
          .Icon = Record.Icon
        End If

        ' Options
        If Record.AllowPageOptions Then
          .LaunchUrl = Record.LaunchUrl

          .FormatPhoneNumbers = Record.FormatPhoneNumbers
          .AllowPhoneExtensionEntry = Record.AllowPhoneExtensionEntry

          .EmailHTML = Record.EmailHTML
          .PhoneVoice = Record.PhoneVoice
          .PhoneFacsimile = Record.PhoneFacsimile
          .PhoneSms = Record.PhoneSms
          .PhoneMms = Record.PhoneMms
          .AddressPhysical = Record.AddressPhysical
          .AddressPostal = Record.AddressPostal
          .DetailsInformationListId = Record.DetailsInformationListId
          .AllowLinkedClient = Record.AllowLinkedClient
          .LinkedClientGroups = Record.LinkedClientGroups

          .ShowInSummary = Record.ShowInSummary
          .UserFlagA = Record.UserFlagA
          .UserFlagB = Record.UserFlagB
        End If
      End With

      ' Save
      If Success Then
        Success = ContactMethod.Save()
      End If

      ' Commit/ Rollback Transaction
      If Success Then
        finBL.Database.TransactionCommit()
      Else
        finBL.Database.TransactionRollback()
      End If
    Else
      Success = False
    End If
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Validate a Wizard page.
''' &lt;/summary&gt;
''' &lt;param name="returnValue"&gt;
'''  A JSON object; "true" if validation passed, otherwise, information as to why validation failed.
''' &lt;/param&gt;
Private Function WizardValidate(parametersJson As String,
                                ByRef returnValue As String) As Boolean

  Dim Data As Object
  Dim FailedControlId As String
  Dim FailedMessage As String
  Dim PageId As String
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Get Parameters
  ' NOTE: Use the module mCombinedParameters since this contains Startup and event Parameters in a single Key/Value List
  With mCombinedParameters
    PageId = .GetString("PageId")
  End With

  ' Validate Page
  Select Case PageId
    Case "General"
      ' General
  End Select

  ' Finalise
  If Success Then
    Success = finBL.Runtime.WebUtilities.SerialiseObjectToJsonString(New WizardValidateResponse(Data, FailedMessage, FailedControlId), returnValue)
  End If

  Return Success

End Function


''' &lt;summary&gt;
'''  Wizard Initialisation Information.
''' &lt;/summary&gt;
''' &lt;remarks&gt;
'''  This object is also used to save the Employment.
''' &lt;/remarks&gt;
Public Class FormInitialisationInfo

  ' Form
  Public PageId As String
  Public [ReadOnly] As Boolean

  ' Record
  Public Pk As Integer
  Public Timestamp As Integer

  ' General
  Public ContactMethodId As String
  Public Active As Boolean
  Public Description As String

  Public ContactTypeText As String
  Public ContactHome As Boolean
  Public ContactWork As Boolean
  Public ContactMobile As Boolean
  Public Category As String
  Public OwnedByClient As Boolean

  Public SubTypeInformationListId As String
  Public TooltipText As String

  Public DescriptionShort As String
  Public Icon As String

  ' Options
  Public LaunchUrl As String

  Public FormatPhoneNumbers As Boolean
  Public AllowPhoneExtensionEntry As Boolean

  Public EmailHtml As Boolean
  Public PhoneVoice As Boolean
  Public PhoneFacsimile As Boolean
  Public PhoneSms As Boolean
  Public PhoneMms As Boolean
  Public AddressPhysical As Boolean
  Public AddressPostal As Boolean
  Public DetailsInformationListId As String
  Public AllowLinkedClient As Boolean
  Public LinkedClientGroups As String

  Public ShowInSummary As Boolean
  Public UserFlagA As Boolean
  Public UserFlagB As Boolean

  ' Permissions
  Public AllowPageGeneral As Boolean
  Public AllowPageOptions As Boolean

  ' Lists
  Public ContactTypeList As Object
  Public ListIcons As String

  ' Configuration
  Public HideOtherPages As Boolean
  Public PromptOnSave As Boolean

End Class



''' &lt;summary&gt;
'''  Validation details.
''' &lt;/summary&gt;
Public Class WizardValidateResponse

  Public Data As Object
  Public FailedMessage As String
  Public FailedControlId As String

  Public Sub New(data As Object,
                 failedMessage As String,
                 failedControlId As String)

    Me.Data = data
    Me.FailedMessage = failedMessage
    Me.FailedControlId = failedControlId

  End Sub

End Class</Code>
    <Language>VisualBasic</Language>
    <Notes>System-supplied HTML Widget to edit a Contact Method.</Notes>
    <PermissionKeyExecute />
    <RunWithoutPrompts>false</RunWithoutPrompts>
    <TemplateText>&lt;div id="frmMain" class="is-widget-content" style="visibility:hidden"&gt;

  &lt;!-- Form Header --&gt;
  &lt;header&gt;
    &lt;!-- Tabs --&gt;
    &lt;div id="tabDetails" class="is-tabs"&gt;
      &lt;ul&gt;
        &lt;li tabId="General"&gt;General&lt;/li&gt;
        &lt;li tabId="Options"&gt;Options&lt;/li&gt;
      &lt;ul&gt;
    &lt;/div&gt;
  &lt;/header&gt;


  &lt;!-- Pages --&gt;
  &lt;div class="is-widget-form-body"&gt;
    &lt;!-- General --&gt;
    &lt;div id="pageGeneral"&gt;
      &lt;table class="is-form"&gt;
        &lt;colgroup&gt;
          &lt;col style="width:8em" /&gt;
          &lt;col /&gt;
        &lt;/colgroup&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblCodeAndName"&gt;Code and Description&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtContactMethodId"&gt;Code:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtContactMethodId"/&gt; &lt;input id="chkActive" type="checkbox"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtDescription"&gt;Description:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtDescription"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblTypeAndCategory"&gt;Contact Type and Category&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboContactType"&gt;Contact Type:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboContactType"/&gt;&amp;nbsp;&amp;nbsp; &lt;input id="chkContactHome" type="checkbox"/&gt; &lt;input id="chkContactWork" type="checkbox"/&gt; &lt;input id="chkContactMobile" type="checkbox"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboCategory"&gt;Category:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboCategory"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkOwnedByClient" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblSubTypeAndTooltip"&gt;Optional Sub-Type and Tooltip&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboSubTypeInformationList"&gt;Sub-Type List:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboSubTypeInformationList"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtTooltipText"&gt;Tooltip:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtTooltipText"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblShortDescription"&gt;Short Description and Icon&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtDescriptionShort"&gt;Short&amp;nbsp;Description:&amp;nbsp;&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtDescriptionShort"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboIcon"&gt;Icon:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboIcon"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;



    &lt;!-- Options --&gt;
    &lt;div id="pageOptions"&gt;
      &lt;table class="is-form"&gt;
        &lt;colgroup&gt;
          &lt;col style="width:8em" /&gt;
          &lt;col /&gt;
        &lt;/colgroup&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblLaunchUrl"&gt;Launch URL&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboLaunchUrl"&gt;Launch URL:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboLaunchUrl"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblPhoneExtension"&gt;Phone Number entry and formatting&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkFormatPhoneNumbers" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkPhoneExtension" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblDefaults"&gt;Defaults for new records&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkEmailHtml" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkPhoneVoice" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr class="advanced"&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkPhoneFacsimile" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkPhoneSms" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr class="advanced"&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkPhoneMms" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkAddressPostal" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkAddressPhysical" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboDetailsInformationList"&gt;Details List:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboDetailsInformationList"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkAllowLinkedClient" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th class="indent1"&gt;&lt;label for="txtLinkedClientGroups"&gt;Client&amp;nbsp;Groups:&amp;nbsp;&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtLinkedClientGroups" /&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblOtherFlags"&gt;Other flags&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkShowInSummary" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkUserFlagA" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkUserFlagB" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;

  &lt;/div&gt;


  &lt;!-- Form Footer --&gt;
  &lt;footer&gt;
    &lt;button id="cmdAdvanced" class="is-button" style="float:left" title="Show/hide advanced options"&gt;Advanced&lt;/button&gt;
    &lt;button id="cmdCancel" class="is-button"&gt;Cancel&lt;/button&gt;
    &lt;button id="cmdFinish" class="is-button ok"&gt;Save&lt;/button&gt;
  &lt;/footer&gt;

&lt;/div&gt;


&lt;script&gt;
// Properties
var mRecord;

var mOriginalJson;

// Controls
var C = {
  //   General
  lblCodeAndName: null,
  chkActive: null,
  txtContactMethodId: null,
  txtDescription: null,

  lblTypeAndCategory: null,
  cboContactType: null,
  chkContactHome: null,
  chkContactWork: null,
  chkContactMobile: null,
  cboCategory: null,
  chkOwnedByClient: null,

  lblSubTypeAndTooltip: null,
  cboSubTypeInformationList: null,
  txtTooltipText: null,

  lblShortDescription: null,
  txtDescriptionShort: null,
  cboIcon: null,

  //   Options
  lblLaunchUrl: null,
  cboLaunchUrl: null,

  lblPhoneExtension: null,
  chkFormatPhoneNumbers: null,
  chkPhoneExtension: null,

  lblDefaults: null,
  chkEmailHtml: null,
  chkPhoneVoice: null,
  chkPhoneFacsimile: null,
  chkPhoneSms: null,
  chkPhoneMms: null,
  chkAddressPostal: null,
  chkAddressPhysical: null,
  cboDetailsInformationList: null,
  chkAllowLinkedClient: null,
  txtLinkedClientGroups: null,

  lblOtherFlags: null,
  chkShowInSummary: null,
  chkUserFlagA: null,
  chkUserFlagB: null,
}

// Form
var frmMain;
var tabDetails;

// Buttons
var cmdCancel;
var cmdFinish;

var cmdAdvanced;

// Other
var mAdvancedVisible = false;
var mHasAdvanced_Options = false;

// ==========
// Initialise
// ==========
$(function () {
  // --------
  // Controls
  // --------
  //   General
  C.lblCodeAndName = widget.UI.Label("lblCodeAndName", {});
  C.txtContactMethodId = widget.UI.TextBox("txtContactMethodId", {
    allowBlank: false,
    maxLength: 5,
    width: widget.UI.FIELD_WIDTH_CODE_5,
  });
  C.chkActive = widget.UI.CheckBox("chkActive", {
    caption: "Active?",
  });
  C.txtDescription = widget.UI.TextBox("txtDescription", {
    allowBlank: false,
    maxLength: 50,
  });

  C.lblTypeAndCategory = widget.UI.Label("lblTypeAndCategory", {
    tooltipText: "Type defines the underlying type of Contact Method, whereas the Category groups Contacts (within Addresses verses Non-Addresses).\n\nFlagging Phone and Email contact methods as 'Home', 'Mobile' and 'Work' allows them to be identified more accurately if required.\n\n'Owned by Client' indicates whether this Contact Method is owned by the Client. Uncheck to exclude the Contact Method from their own Contacts, e.g., if it is the phone number of an Advisor or Next of Kin.",
  });
  C.cboContactType = widget.UI.ComboBox("cboContactType", {
    allowBlank: false,
    limitToList: true,
    width: "12em",

    onChange: cboContactType_Change,
  });
  C.chkContactHome = widget.UI.RadioButton("chkContactHome", {
    caption: "Home",

    onChange: chkContact_Change,
  });
  C.chkContactWork = widget.UI.RadioButton("chkContactWork", {
    caption: "Work",

    onChange: chkContact_Change,
  });
  C.chkContactMobile = widget.UI.RadioButton("chkContactMobile", {
    caption: "Mobile",

    onChange: chkContact_Change,
  });
  C.cboCategory = widget.UI.InformationListComboBox("cboCategory", {
    maxLength: 50,
  });
  C.chkOwnedByClient = widget.UI.CheckBox("chkOwnedByClient", {
    caption: "Owned by Client?",
  });

  C.lblSubTypeAndTooltip = widget.UI.Label("lblSubTypeAndTooltip", {
    tooltipText: "The optional Sub-Type allows you to define a Sub-Type Information List against a Contact Method, e.g., Next of Kin relationship type such as Spouse or Father. Leave blank to not show a Sub-Type.\n\nThe Tooltip can be used to instruct the User what details to enter or how to enter them.",
  });
  C.cboSubTypeInformationList = widget.UI.DBCombo("cboSubTypeInformationList", {
    limitToList: true,
    width: widget.UI.FIELD_WIDTH_CODE_20,
  });
  C.txtTooltipText = widget.UI.TextBox("txtTooltipText", {
    multiLine: true,
    rows: 3,
  });

  C.lblShortDescription = widget.UI.Label("lblShortDescription", {
   tooltipText: "Icon and Short Description are used when displaying Contact Methods in grids.",
  });
  C.txtDescriptionShort = widget.UI.TextBox("txtDescriptionShort", {
    maxLength: 20,
  });
  C.cboIcon = widget.UI.IconComboBox("cboIcon", {
    iconPrefix: "ContactMethod_",
    limitToList: true,
    width: "12em",
  });

  //   Options
  C.lblLaunchUrl = widget.UI.Label("lblLaunchUrl", {
    tooltipText: "Use '[value]' to substitute the Contact Detail in the Launch URL.",
  });
  C.cboLaunchUrl = widget.UI.ComboBox("cboLaunchUrl", {
    limitToList: false,
    maxLength: 255,
  });

  C.lblPhoneExtension = widget.UI.Label("lblPhoneExtension", {});
  C.chkFormatPhoneNumbers = widget.UI.CheckBox("chkFormatPhoneNumbers", {
    caption: "Format Phone Numbers upon entry?",
  });
  C.chkPhoneExtension = widget.UI.CheckBox("chkPhoneExtension", {
    caption: "Allow entry of a Phone Extension?",
  });

  C.lblDefaults = widget.UI.Label("lblDefaults", {});
  C.chkEmailHtml = widget.UI.CheckBox("chkEmailHtml", {
    caption: "HTML format supported",
  });
  C.chkPhoneVoice = widget.UI.CheckBox("chkPhoneVoice", {
    caption: "Supports voice calls",
  });
  C.chkPhoneFacsimile = widget.UI.CheckBox("chkPhoneFacsimile", {
    caption: "Can receive faxes",
  });
  C.chkPhoneSms = widget.UI.CheckBox("chkPhoneSms", {
    caption: "Supports SMS",
  });
  C.chkPhoneMms = widget.UI.CheckBox("chkPhoneMms", {
    caption: "Show 'Supports MMS (Multimedia Message Service)' option?",
  });
  C.chkAddressPostal = widget.UI.CheckBox("chkAddressPostal", {
    caption: "Postal Address",
  });
  C.chkAddressPhysical = widget.UI.CheckBox("chkAddressPhysical", {
    caption: "Physical Address",
  });
  C.cboDetailsInformationList = widget.UI.DBCombo("cboDetailsInformationList", {});
  C.chkAllowLinkedClient = widget.UI.CheckBox("chkAllowLinkedClient", {
    caption: "Allow linked Client?",

    onChange: chkAllowLinkedClient_Change,
  });
  C.txtLinkedClientGroups = widget.UI.TextBox("txtLinkedClientGroups", {
    onButtonClick: txtLinkedClientGroups_ButtonClick,
  });
  C.txtLinkedClientGroups.ButtonsDefine([{ id: "Lookup", icon: "Find", tooltipText: "Lookup Client Groups" }]);

  C.lblOtherFlags = widget.UI.Label("lblOtherFlags", {});
  C.chkShowInSummary = widget.UI.CheckBox("chkShowInSummary", {
    caption: "Show in Summary Pages?",
  });
  C.chkUserFlagA = widget.UI.CheckBox("chkUserFlagA", {
    caption: "User Flag A",
  });
  C.chkUserFlagB = widget.UI.CheckBox("chkUserFlagB", {
    caption: "User Flag B",
  });

  // Grids

  // Create Widget form
  // NOTE: Hide by default for a cleaner startup
  frmMain = new widget.UI.Form("frmMain", { visible: false });

  // Create Tabs
  tabDetails = new widget.UI.Tabs("tabDetails", {
    style: "normal",
    onSelectedTabChanged: tabDetails_Refresh,
  });

  // Handle resize
  $(window).resize(Form_Resize);

  // Disable Close Button (this causes the 'FormClose' notification action to be invoked instead)
  widget.DisableCloseButton();
  widget.ActionNotificationHandle(Widget_NotificationHandler)

  // Handle Wizard Buttons
  cmdCancel = $("#cmdCancel");
  cmdFinish = $("#cmdFinish");
  cmdCancel.click(tabDetails_Cancel);
  cmdFinish.click(Form_ExecuteAction_Finish);

  cmdAdvanced = $("#cmdAdvanced");
  cmdAdvanced.click(function () {
    // Toggle Advanced
    mAdvancedVisible = !mAdvancedVisible;
    if (mAdvancedVisible) {
      // Showing
      $("body").addClass("advanced-visible");
      cmdAdvanced.attr("showing", true);
    }
    else {
      // Not showing
      $("body").removeClass("advanced-visible");
      cmdAdvanced.attr("showing", false);
    }
    Form_Resize();
  });

  // Reset
  Form_Reset();
});

// ==========
// Reset Form
// ==========
function Form_Reset() {
  // Resize
  Form_Resize();

  // Load Record (i.e., initialise wizard)
  Record_Load();
}

// ===========
// Load Record
// ===========
function Record_Load() {
  // Initialise
  mRecord = null;

  // Hide content
  frmMain.Visible(false);

  // Block UI
  widget.UI.Block("Initialising, please wait...");

  // Load Initialisation details
  widget.GetString("GetInitialisationInfo", {},
    // Success
    Record_Load_Done,

    // Fail
    function (message) {
      widget.UI.MsgBoxAlert("fail: " + message);
      Fields_Load();
    }
  );
}

function Record_Load_Done(data) {
  // Initialise
  mRecord = JSON.parse(data);

  // Set Tab
  if (mRecord &amp;&amp; mRecord.PageId) {
    tabDetails.SelectedTabId(mRecord.PageId);

    // Hide other Pages
    if (mRecord.HideOtherPages) {
      tabDetails.ShowSingleTab(mRecord.PageId);
    }
  }
  else {
    tabDetails.SelectedTabId("General");
  }

  // Page Permissions
  if (!mRecord.AllowPageGeneral) tabDetails.TabVisible("General", false);
  if (!mRecord.AllowPageOptions) tabDetails.TabVisible("Options", false);

  // Load Fields
  Fields_Load();

  // Save Fields (so UserData is in correct format for mOriginalJson)
  Fields_Save();

  // Save original JSON for Form_IsDirty
  mOriginalJson = JSON.stringify(mRecord);
}

// ===========
// Load Fields
// ===========
function Fields_Load() {
  if (mRecord) {
    // General
    C.txtContactMethodId.Text(mRecord.ContactMethodId);
    C.chkActive.Value(mRecord.Active);
    C.txtDescription.Text(mRecord.Description);

    C.cboContactType.Text(mRecord.ContactTypeText);
    C.chkContactHome.Value(mRecord.ContactHome);
    C.chkContactWork.Value(mRecord.ContactWork);
    C.chkContactMobile.Value(mRecord.ContactMobile);
    C.cboCategory.Text(mRecord.Category);
    C.chkOwnedByClient.Value(mRecord.OwnedByClient);

    C.cboSubTypeInformationList.Text(mRecord.SubTypeInformationListId);
    C.txtTooltipText.Text(mRecord.TooltipText);

    C.txtDescriptionShort.Text(mRecord.DescriptionShort);
    C.cboIcon.Text(mRecord.Icon);

    // Options
    C.cboLaunchUrl.Text(mRecord.LaunchUrl);

    C.chkFormatPhoneNumbers.Value(mRecord.FormatPhoneNumbers);
    C.chkPhoneExtension.Value(mRecord.AllowPhoneExtensionEntry);

    C.chkEmailHtml.Value(mRecord.EmailHtml);
    C.chkPhoneVoice.Value(mRecord.PhoneVoice);
    C.chkPhoneFacsimile.Value(mRecord.PhoneFacsimile);
    C.chkPhoneSms.Value(mRecord.PhoneSms);
    C.chkPhoneMms.Value(mRecord.PhoneMms);
    C.chkAddressPostal.Value(mRecord.AddressPostal);
    C.chkAddressPhysical.Value(mRecord.AddressPhysical);
    C.cboDetailsInformationList.Text(mRecord.DetailsInformationListId);
    C.chkAllowLinkedClient.Value(mRecord.AllowLinkedClient);
    C.txtLinkedClientGroups.Text(mRecord.LinkedClientGroups);

    C.chkShowInSummary.Value(mRecord.ShowInSummary);
    C.chkUserFlagA.Value(mRecord.UserFlagA);
    C.chkUserFlagB.Value(mRecord.UserFlagB);
  }

  // Unblock UI
  widget.UI.Unblock();

  // Update Controls

  // Update fields
  Fields_Update();

  // Refresh Tab
  tabDetails_Refresh();
  tabDetails_Resize();
}

// ===========
// Save Fields
// ===========
function Fields_Save() {
  // General
  mRecord.ContactMethodId = C.txtContactMethodId.Text();
  mRecord.Active = C.chkActive.Value();
  mRecord.Description = C.txtDescription.Text();

  mRecord.ContactTypeText = C.cboContactType.Text();
  mRecord.ContactHome = C.chkContactHome.Value();
  mRecord.ContactWork = C.chkContactWork.Value();
  mRecord.ContactMobile = C.chkContactMobile.Value();
  mRecord.Category = C.cboCategory.Text();
  mRecord.OwnedByClient = C.chkOwnedByClient.Value();

  mRecord.SubTypeInformationListId = C.cboSubTypeInformationList.Text();
  mRecord.TooltipText = C.txtTooltipText.Text();

  mRecord.DescriptionShort = C.txtDescriptionShort.Text();
  mRecord.Icon = C.cboIcon.Text();

  // Options
  mRecord.LaunchUrl = C.cboLaunchUrl.Text();

  mRecord.FormatPhoneNumbers = C.chkFormatPhoneNumbers.Value();
  mRecord.AllowPhoneExtensionEntry = C.chkPhoneExtension.Value();

  mRecord.EmailHtml = C.chkEmailHtml.Value();
  mRecord.PhoneVoice = C.chkPhoneVoice.Value();
  mRecord.PhoneFacsimile = C.chkPhoneFacsimile.Value();
  mRecord.PhoneSms = C.chkPhoneSms.Value();
  mRecord.PhoneMms = C.chkPhoneMms.Value();
  mRecord.AddressPostal = C.chkAddressPostal.Value();
  mRecord.AddressPhysical = C.chkAddressPhysical.Value();
  mRecord.DetailsInformationListId = C.cboDetailsInformationList.Text();
  mRecord.AllowLinkedClient = C.chkAllowLinkedClient.Value();
  mRecord.LinkedClientGroups = C.txtLinkedClientGroups.Text();

  mRecord.ShowInSummary = C.chkShowInSummary.Value();
  mRecord.UserFlagA = C.chkUserFlagA.Value();
  mRecord.UserFlagB = C.chkUserFlagB.Value();
}

// =============
// Update Fields
// =============
function Fields_Update() {
  // Heading
  if (mRecord) {
    if (mRecord.ContactMethodId) {
      widget.SetHeading("Contact Method (" + mRecord.ContactMethodId + ")");
    }
    else {
      widget.SetHeading("New Contact Method");
    }
  }

  // Information Lists
  if (mRecord) {
    C.cboCategory.SetComboFromInformationList("ContactMethodCat");
  }

  // Lists
  if (mRecord) {
    // General
    C.cboContactType.ListFromCollection(mRecord.ContactTypeList, "Description");
    C.cboSubTypeInformationList.RefreshFromStandardRange("InformationLists");
    C.cboIcon.ListFromCsvString(mRecord.ListIcons);
    C.cboDetailsInformationList.RefreshFromStandardRange("InformationLists");
  }

  // Controls
  if (mRecord) {
  }

  // Pages
  if (mRecord) {
    // NOTE: Even though many pages are updated in tabDetails_Refresh, we must update them here to ensure controls are hidden since this is not a wizard and all pages are validated on "Finish"
    pageGeneral_Refresh();
    pageOptions_Refresh();
  }

  // Read-Only?
  if (mRecord &amp;&amp; mRecord.ReadOnly) {
    cmdFinish.prop("disabled", true);
    frmMain.FormReadOnly(C, true);
  }

  // Show content
  frmMain.Visible(mRecord != null);

  // Resize Tab
  tabDetails_Resize();
}

// ===========
// Resize Form
// ===========
function Form_Resize() {
  // Mobile Optimisations
  var el = $(".mobile-indent th.indent1, .mobile-indent th.no-indent1");
  if (window.innerWidth &lt; 500) {
    el.addClass("no-indent1").removeClass("indent1");
  }
  else {
    el.addClass("indent1").removeClass("no-indent1");
  }

  // General

  // Tab
  tabDetails_Resize();
}

// ========
// Is Dirty
// ========
function Form_IsDirty() {
  if (mRecord) {
    // Save Fields
    Fields_Save();

    // Is Dirty?
    return mOriginalJson != JSON.stringify(mRecord);
  }
  else {
    return false;
  }
}

// ==============
// Wizard Buttons
// ==============
function tabDetails_Cancel() {
  if (Form_IsDirty()) {
    // Confirm
    widget.UI.MsgBoxConfirm("Are you sure you want to close this form without saving your changes?", { heading: "Close Form" }, tabDetails_Cancel_Finalise);
  }
  else {
    // Cancel immediately
    tabDetails_Cancel_Finalise();
  }
}

function tabDetails_Cancel_Finalise() {
  if (widget.CanClose()) {
    widget.Close();
  }
  else {
    widget.Reset();
  }
}

// ==========
// Resize Tab
// ==========
function tabDetails_Resize() {
  switch (tabDetails.SelectedTabId()) {
    case "General":
      // General
      C.txtDescription.WidthResizeFromParent();
      C.txtDescriptionShort.WidthResizeFromParent();
      break;

    case "Options":
      // Options
      break;
  }
}

function tabDetails_UpdateButtons() {
  // Only show Advanced button on relevant pages
  switch (tabDetails.SelectedTabId()) {
    case "Options":
      if (mHasAdvanced_Options) {
        cmdAdvanced.show();
      }
      else {
        cmdAdvanced.hide();
      }
      break;

    default:
      cmdAdvanced.hide();
      break;
  }
}

// ===========
// Refresh Tab
// ===========
function tabDetails_Refresh() {
   // Load details
  switch (tabDetails.SelectedTabId()) {
    case "General":
      pageGeneral_Refresh();
      break;

    case "Options":
      pageOptions_Refresh();
      break;

    default:
      break;
  }

  // Resize
  tabDetails_Resize();

  // Update Buttons
  tabDetails_UpdateButtons();

  // Focus
  switch (tabDetails.SelectedTabId()) {
    default:
      tabDetails.FocusFirst();
      break;
  }
}

// =================
// Execute an Action
// =================
function Form_ExecuteAction(actionId, data) {
  switch(actionId) {
    default:
      window.alert("Unhandled action '" + actionId + "'");
  }
}

// =============
// Finish Action
// =============
function Form_ExecuteAction_Finish() {
  // Assume Success
  var Ok = true;

  // Validate
  Ok = tabDetails.Validate();

  // Prompt
  if (Ok) {
    if (mRecord.PromptOnSave) {
      // Confirm
      widget.UI.MsgBoxConfirm("Are you sure you want to save this record?",
                              { heading: "Save" },
                              Form_ExecuteAction_FinishPost);

    }
    else {
      // Save without prompting
      Form_ExecuteAction_FinishPost();
    }
  }
}

function Form_ExecuteAction_FinishPost() {
  // Disable Form
  widget.UI.Block("Saving, please wait...");

  // Create Parameters
  // NOTE: We will simply update mRecord, clone this and send back (less some information)
  Fields_Save();
  var params = JSON.parse(JSON.stringify(mRecord));
  //params.GendersList = null;

  // Finish
  widget.GetString("Finish", params,
    function (data) {
      // Close Form
      widget.Close();

      // Refresh Parent (to show updated details)
      // NOTE: Pass in Record Id just in case this has changed
      widget.RefreshParent(C.txtContactMethodId.Text());
    },

    function (data) {
      // Show Error
      widget.UI.MsgBoxAlert(data);

      // Enable Form
      widget.UI.Unblock();
    }
  );
}

// ===========
// pageGeneral
// ===========
function pageGeneral_Refresh() {
  if (!mRecord) return;

  // Get Contact Type
  var ContactType = "Other";
  if (C.cboContactType.ListIndex() != -1) ContactType = mRecord.ContactTypeList[C.cboContactType.ListIndex()].Code;

  // Home, Work, Mobile indicators
  switch(ContactType) {
    case "Email":
      C.chkContactHome.Visible(true);
      C.chkContactWork.Visible(true);
      C.chkContactMobile.Visible(false);
      break;

    case "Phone":
      C.chkContactHome.Visible(true);
      C.chkContactWork.Visible(true);
      C.chkContactMobile.Visible(true);
      break;

    default:
      C.chkContactHome.Visible(false);
      C.chkContactWork.Visible(false);
      C.chkContactMobile.Visible(false);
      break;
  }

  // Controls
}

// ===========
// pageOptions
// ===========
function pageOptions_Refresh() {
  if (!mRecord) return;

  // Initialise
  mHasAdvanced_Options = false;

  // Get Contact Type
  var ContactType = "Other";
  if (C.cboContactType.ListIndex() != -1) ContactType = mRecord.ContactTypeList[C.cboContactType.ListIndex()].Code;

  // Launch URL
  switch(ContactType) {
    case "Address":
      C.lblLaunchUrl.VisibleRow(false);
      C.cboLaunchUrl.VisibleRow(false);
      break;

    default:
      C.lblLaunchUrl.VisibleRow(true);
      C.cboLaunchUrl.VisibleRow(true);
      break;
  }

  // Phone formatting and extension
  switch(ContactType) {
    case "Pager":
      C.lblPhoneExtension.VisibleRow(true);
      C.chkFormatPhoneNumbers.VisibleRow(true);
      C.chkPhoneExtension.VisibleRow(false);
      break;

    case "Phone":
      C.lblPhoneExtension.VisibleRow(true);
      C.chkFormatPhoneNumbers.VisibleRow(true);
      C.chkPhoneExtension.VisibleRow(true);
      break;

    default:
      C.lblPhoneExtension.VisibleRow(false);
      C.chkFormatPhoneNumbers.VisibleRow(false);
      C.chkPhoneExtension.VisibleRow(false);
      break;
  }

  // Other contact-type dependent options
  switch(ContactType) {
    case "Address":
      // Address
      C.lblDefaults.Text("Defaults for new records");
      C.lblDefaults.TooltipText("");
      C.lblDefaults.VisibleRow(true);
      C.chkEmailHtml.VisibleRow(false);
      C.chkPhoneVoice.VisibleRow(false);
      C.chkPhoneFacsimile.VisibleRow(false);
      C.chkPhoneSms.VisibleRow(false);
      C.chkPhoneMms.VisibleRow(false);
      C.chkAddressPhysical.VisibleRow(true);
      C.chkAddressPostal.VisibleRow(true);
      C.cboDetailsInformationList.VisibleRow(false);
      C.chkAllowLinkedClient.VisibleRow(false);
      C.txtLinkedClientGroups.VisibleRow(false);
      break;

    case "Email":
      // Email
      C.lblDefaults.Text("Defaults for new records");
      C.lblDefaults.TooltipText("");
      C.lblDefaults.VisibleRow(true);
      C.chkEmailHtml.VisibleRow(true);
      C.chkPhoneVoice.VisibleRow(false);
      C.chkPhoneFacsimile.VisibleRow(false);
      C.chkPhoneSms.VisibleRow(false);
      C.chkPhoneMms.VisibleRow(false);
      C.chkAddressPhysical.VisibleRow(false);
      C.chkAddressPostal.VisibleRow(false);
      C.cboDetailsInformationList.VisibleRow(false);
      C.chkAllowLinkedClient.VisibleRow(false);
      C.txtLinkedClientGroups.VisibleRow(false);
      break;

    case "InstantMessaging":
      // Instant Messaging
      C.lblDefaults.Text("Defaults for new records");
      C.lblDefaults.TooltipText("");
      C.lblDefaults.VisibleRow(true);
      C.chkEmailHtml.VisibleRow(false);
      C.chkPhoneVoice.VisibleRow(true);
      C.chkPhoneFacsimile.VisibleRow(false);
      C.chkPhoneSms.VisibleRow(false);
      C.chkPhoneMms.VisibleRow(false);
      C.chkAddressPhysical.VisibleRow(false);
      C.chkAddressPostal.VisibleRow(false);
      C.cboDetailsInformationList.VisibleRow(false);
      C.chkAllowLinkedClient.VisibleRow(false);
      C.txtLinkedClientGroups.VisibleRow(false);
      break;

    case "Phone":
      // Phone
      C.lblDefaults.Text("Defaults for new records");
      C.lblDefaults.TooltipText("");
      C.lblDefaults.VisibleRow(true);
      C.chkEmailHtml.VisibleRow(false);
      C.chkPhoneVoice.VisibleRow(true);
      C.chkPhoneFacsimile.VisibleRow(true);
      C.chkPhoneSms.VisibleRow(true);
      C.chkPhoneMms.VisibleRow(true);
      C.chkAddressPhysical.VisibleRow(false);
      C.chkAddressPostal.VisibleRow(false);
      C.cboDetailsInformationList.VisibleRow(false);
      C.chkAllowLinkedClient.VisibleRow(false);
      C.txtLinkedClientGroups.VisibleRow(false);

      mHasAdvanced_Options = true;
      break;

    case "Other":
      // Other
      C.lblDefaults.Text("Contact Details and linked Client");
      C.lblDefaults.TooltipText("Optionally enter an Information List to use for Details.\n\nLinked Clients allow another Client to be linked to a Contact.");
      C.lblDefaults.VisibleRow(true);
      C.chkEmailHtml.VisibleRow(false);
      C.chkPhoneVoice.VisibleRow(false);
      C.chkPhoneFacsimile.VisibleRow(false);
      C.chkPhoneSms.VisibleRow(false);
      C.chkPhoneMms.VisibleRow(false);
      C.chkAddressPhysical.VisibleRow(false);
      C.chkAddressPostal.VisibleRow(false);
      C.cboDetailsInformationList.VisibleRow(true);
      C.chkAllowLinkedClient.VisibleRow(true);
      C.txtLinkedClientGroups.VisibleRow(true);
      chkAllowLinkedClient_Change();
      break;

    default:
      // Not applicable
      C.lblDefaults.VisibleRow(false);
      C.chkEmailHtml.VisibleRow(false);
      C.chkPhoneVoice.VisibleRow(false);
      C.chkPhoneFacsimile.VisibleRow(false);
      C.chkPhoneSms.VisibleRow(false);
      C.chkPhoneMms.VisibleRow(false);
      C.chkAddressPhysical.VisibleRow(false);
      C.chkAddressPostal.VisibleRow(false);
      C.cboDetailsInformationList.VisibleRow(false);
      C.chkAllowLinkedClient.VisibleRow(false);
      C.txtLinkedClientGroups.VisibleRow(false);
      break;
  }
}

// ==============
// cboContactType
// ==============
function cboContactType_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

  // Refresh pages
  pageGeneral_Refresh();
  pageOptions_Refresh();
}

// ==========
// chkContact
// ==========
function chkContact_Change(sender, e) {
  // NOTE: Different to normal since we allow none of the options to be a valid choice
  if (sender !== C.chkContactHome) C.chkContactHome.Value(false);
  if (sender !== C.chkContactWork) C.chkContactWork.Value(false);
  if (sender !== C.chkContactMobile) C.chkContactMobile.Value(false);
}

// ====================
// chkAllowLinkedClient
// ====================
function chkAllowLinkedClient_Change(sender, e) {
  C.txtLinkedClientGroups.VisibleRow(C.chkAllowLinkedClient.Value());
}

function txtLinkedClientGroups_ButtonClick(sender, e) {
  widget.UI.Forms.ShowRangeLookupFromStandardRange("ClientGroups", sender.Text(), { caption: "Lookup Client Groups" },
     function (newRange) {
       sender.Text(newRange);
       sender.Focus();
     });
}

// ====================
// Notification Handler
// ====================
function Widget_NotificationHandler(actionId, data) {
   switch(actionId) {
     case "FormClose":
      // Form Close button is disabled so act as if 'Cancel' has been clicked
      tabDetails_Cancel();
      break;
   }
}
&lt;/script&gt;</TemplateText>
    <TemplateTextBookmarks />
    <TimeoutSeconds>60</TimeoutSeconds>
    <UniqueId>HsJExSeyK0OmlZF--nkGDQ</UniqueId>
    <AllowRefresh>true</AllowRefresh>
    <Caption>Contact Method</Caption>
    <HtmlWidgetMaxHeight>800</HtmlWidgetMaxHeight>
    <HtmlWidgetMaxWidth>800</HtmlWidgetMaxWidth>
    <HtmlWidgetNeverApplyStyling>false</HtmlWidgetNeverApplyStyling>
    <HtmlWidgetResourceCssSummaryPage2>false</HtmlWidgetResourceCssSummaryPage2>
    <HtmlWidgetResourceCssWidget>true</HtmlWidgetResourceCssWidget>
    <HtmlWidgetResourceJQuery>true</HtmlWidgetResourceJQuery>
    <HtmlWidgetResourceJQueryVersion />
    <Icon>ContactMethod</Icon>
    <JavaScriptDebugger>None</JavaScriptDebugger>
    <RestrictedOriginsListEnabled>false</RestrictedOriginsListEnabled>
    <RunAsAdministrator>false</RunAsAdministrator>
    <WebServiceName />
    <WebServiceAllowAnonymous>false</WebServiceAllowAnonymous>
    <WebServiceSendDebugInformation>false</WebServiceSendDebugInformation>
    <ShowInMenu>None</ShowInMenu>
    <ParametersType>Custom</ParametersType>
    <Parameters>
      <ISParameterDefs version="1.00">
        <Parameters>
          <Parameter name="" type="SectionStart">
            <BlankTip />
            <Caption>Form options.</Caption>
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <SectionColumns>1</SectionColumns>
            <Visible>true</Visible>
          </Parameter>
          <Parameter name="HideOtherPages" type="Boolean">
            <BlankTip />
            <Caption>Hide pages other than the one being edited?</Caption>
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value>True</Value>
            <Visible>true</Visible>
          </Parameter>
          <Parameter name="" type="SectionStart">
            <BlankTip />
            <Caption>Configuration options.</Caption>
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <SectionColumns>1</SectionColumns>
            <Visible>true</Visible>
          </Parameter>
          <Parameter name="" type="SectionStart">
            <BlankTip />
            <Caption>TESTING</Caption>
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <SectionColumns>1</SectionColumns>
            <Visible>true</Visible>
          </Parameter>
          <Parameter name="ContactMethodId" type="Range">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <Mandatory>false</Mandatory>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value />
            <Visible>true</Visible>
            <LimitToList>false</LimitToList>
            <MaxLength>10</MaxLength>
            <RangeSingle>true</RangeSingle>
            <RangeType>Standard</RangeType>
            <RangeLookupSource>ContactMethods</RangeLookupSource>
            <RangeLookupSqlWhere />
          </Parameter>
          <Parameter name="DuplicateRecordId" type="List">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <Mandatory>false</Mandatory>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value />
            <Visible>true</Visible>
            <List>RANGE.ContactMethods</List>
            <LimitToList>false</LimitToList>
            <MaxLength>0</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="Page" type="List">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <Mandatory>false</Mandatory>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value />
            <Visible>true</Visible>
            <List>General,Filters</List>
            <LimitToList>false</LimitToList>
            <MaxLength>0</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="ReadOnly" type="Boolean">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value>False</Value>
            <Visible>true</Visible>
          </Parameter>
        </Parameters>
      </ISParameterDefs>
    </Parameters>
  </finScript>