<?xml version="1.0" encoding="utf-8"?><finScript version="1.00" exportedUtcDate="2021-04-12T23:44:29.0000000"><CreatedUserId>ADMIN</CreatedUserId><CreatedUtcDate>2020-06-04T00:45:30.4330000</CreatedUtcDate><UpdatedUserId>ADMIN</UpdatedUserId><UpdatedUtcDate>2021-04-12T23:42:44.5170000</UpdatedUtcDate><ScriptId>ACCOUNTAPPEDIT</ScriptId><Description>Account Application Edit</Description><ScriptType>HtmlWidget</ScriptType><Active>true</Active><AllowUI>false</AllowUI><Category /><Code>' HtmlWidget_AccountAppEdit
Option Explicit On
Option Strict On

' #################################################################
' Account Application Edit form HTML Widget
'
' Version: 1.05 (13/04/2021)
'
' Usage: System-supplied HTML Widget
' #################################################################

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

' Standard Parameters
Private mAccountAppAppId As String
Private mPage As String
Private mReadOnly As Boolean

' Other
Private mAccountApp As finAccountApp

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
    mAccountAppAppId = .GetString("AccountAppId") ' Always use Startup Parameters since the Account Id may be updated
  End With
  With mCombinedParameters
    mPage = .GetString("Page")
    mReadOnly = .GetBoolean("ReadOnly")
  End With

  ' Handle Events
  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 "GetImageData"
      ' Get Image Data
      Main = GetImageData(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 Function

''' &lt;summary&gt;
'''  Load Account Application.
''' &lt;/summary&gt;
Private Function GetAccountApp() As Boolean

  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Shortcut
  If mAccountApp IsNot Nothing Then
    Return Success
  End If

  ' Validate
  If Len(mAccountAppAppId) = 0 Then
    Success = False
    finBL.Error.ErrorBegin("Account App Id not specified.")
  ElseIf Not finBL.CurrentUser.Permissions.Allow("Account.Update") Then
    Success = False
    finBL.Error.ErrorBegin("You do not have permission to update Accounts.")
  End If

  ' Create and Load Account
  If Success Then
    ' Create Account
    mAccountApp = finBL.CreateAccountApp()

    ' Load Account
    If mAccountApp.Load(mAccountAppAppId) Then
      ' Validate
      If mAccountApp.IsNew Then
        Success = False
        finBL.Error.ErrorBeginFormat("Account '{0}' not found.", mAccountAppAppId)
      End If
    Else
      Success = False
    End If
  End If

  ' Clear Account if failed
  If Not Success Then
    mAccountApp = Nothing
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Retrieves Image data for a specific Resource Id
''' &lt;/summary&gt;
Public Function GetImageData(ByRef returnValue As String) As Boolean

  Dim DataUri As String
  Dim obj As Object
  Dim ResourceId As String
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Parameters
  With mCombinedParameters
    ResourceId = .GetString("ResourceId")
  End With

  ' Validate
  If Len(ResourceId) = 0 Then
    ' No Parameter value
  ElseIf Not finBL.Resources.Exists(ResourceId) Then
    ' Resource does not exist
  ElseIf Not finBL.Resources(ResourceId).IsImage Then
    ' Resource is not an Image
  Else
    DataUri = finBL.Resources(ResourceId).GetImageDataUri(200)
  End If

  ' Create response object
  obj = New With {
    .DataUri = DataUri
  }

  ' Serialise
  Success = finBL.Runtime.WebUtilities.SerialiseObjectToJsonString(obj, returnValue)

  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 FormInitialisationInfo As FormInitialisationInfo
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Validate

  ' Get Account Application
  If Success Then
    Success = GetAccountApp()
  End If

  ' Get Initialisation Info
  If Success Then
    FormInitialisationInfo = New FormInitialisationInfo()
    With FormInitialisationInfo
      ' Form
      .PageId = mPage
      If finBL.Database.IsReadOnly OrElse mReadOnly Then
        .ReadOnly = True
      Else
        .ReadOnly = False
      End If

      ' Record
      .Pk = mAccountApp.Pk
      .Timestamp = mAccountApp.Timestamp

      ' Page Permissions (defined here since they are used below)
      .AllowPageGeneral = finBL.CurrentUser.Permissions.Allow("AccountApp.Form.Page.General")
      .AllowPageDetails = finBL.CurrentUser.Permissions.Allow("AccountApp.Form.Page.Details")
      .AllowPageWeb = finBL.CurrentUser.Permissions.Allow("AccountApp.Form.Page.Web") AndAlso finBL.Settings.AddOns.WebAutomation

      ' General
      .AccountAppId = mAccountApp.AccountAppId ' Always need to return Account Id
      If .AllowPageGeneral Then
        .Name = mAccountApp.Name
        .Description = mAccountApp.Description
        .ExternalId = mAccountApp.ExternalId

        .AccountAppTypeId = mAccountApp.AccountAppTypeId
        .AccountAppTypeDescription = mAccountApp.AccountAppType.Description
        .Status = mAccountApp.Status
        .StatusText = mAccountApp.StatusText
        .StatusSub = mAccountApp.StatusSub
        .FlagColour = mAccountApp.FlagColour
        .FlagNotes = mAccountApp.FlagNotes

        .DateQuoted = finBL.HtmlWidgetUtilities.GetNullableJsonUtcDateFromDatabaseDate(mAccountApp.DateQuoted)

        .AccountManagerUserId = mAccountApp.AccountManagerUserId
        .DateReview = finBL.HtmlWidgetUtilities.GetNullableJsonUtcDateFromDatabaseDate(mAccountApp.DateReview)

        .Notes = mAccountApp.Notes
      End If

      ' Details
      If .AllowPageDetails Then
        .BranchId = mAccountApp.BranchId
        .DepartmentId = mAccountApp.DepartmentId

        .BdmUserId = mAccountApp.BdmUserIdResolved
        If mAccountApp.BdmUserPkResolved &lt;&gt; 0 Then .BdmUserName = finBL.Users(mAccountApp.BdmUserIdResolved).Name
        '.BdmCommissionUserId = mAccountApp.BdmCommissionUserId

        .DealerExternalPartyId = mAccountApp.DealerExternalPartyId
        .DealerExternalPartyEmployeeClientEmploymentId = mAccountApp.DealerExternalPartyEmployeeClientEmploymentId
        .DealerEmployeeWarning = "TODO:"

        .BrokerExternalPartyId = mAccountApp.BrokerExternalPartyId
        .BrokerExternalPartyEmployeeClientEmploymentId = mAccountApp.BrokerExternalPartyEmployeeClientEmploymentId
        .BrokerEmployeeWarning = "TODO:"

        .BulkFunderExternalPartyId = mAccountApp.BulkFunderExternalPartyId
        If mAccountApp.BulkFunderExternalPartyPk &lt;&gt; 0 Then .BulkFunderName = finBL.ExternalParties(mAccountApp.BulkFunderExternalPartyId).DescriptionResolved

        .InsuranceInsurerExternalPartyId = mAccountApp.InsuranceInsurerExternalPartyId
        .InsurancePolicyType = mAccountApp.InsurancePolicyType
        .InsurancePolicyNumber = mAccountApp.InsurancePolicyNumber
      End If

      ' Web
      If .AllowPageWeb Then
        .WebFriendlyName = mAccountApp.WebFriendlyName
        .WebResourceImageId = mAccountApp.WebResourceImageId
      End If

      ' Other
      .IsClosed = mAccountApp.IsClosed

      ' Permissions
      If .ReadOnly Then
        .CanUpdateCode = False
        .CanUpdateManager = False
      Else
        .CanUpdateCode = finBL.CurrentUser.Permissions.Allow("AccountApp.UpdateCode")
        .CanUpdateManager = finBL.CurrentUser.Permissions.Allow("Account.ManagerUpdate")
      End If

      ' Lists
      .FlagColourList = finWorkflowFunctions.CommonColourFlagsList

      ' Configuration
      .AccountShowExternalId = finBL.SettingsUser.AccountShowExternalId
      .AddOnBranch = finBL.Settings.AddOns.Branch
      .AddOnExternalParty = finBL.Settings.AddOns.ExternalParty
      .AddOnExternalPartyAdvancedBdms = finBL.Settings.AddOns.ExternalPartyAdvancedBdms
      .AddOnExternalPartyBrokers = finBL.Settings.AddOns.ExternalPartyBrokers
      .AddOnExternalPartyDealers = finBL.Settings.AddOns.ExternalPartyDealers
      .AddOnExternalPartyInsurers = finBL.Settings.AddOns.ExternalPartyInsurers

      .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 Account Application.
''' &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 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 Account
  If Success Then
    Success = GetAccountApp()
  End If

  ' Validate
  If Success Then
    If Record.Timestamp &lt;&gt; mAccountApp.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 Client
      With mAccountApp
        ' General
        If Record.AllowPageGeneral AndAlso finBL.CurrentUser.Permissions.Allow("AccountApp.Form.Page.General") Then
          .AccountAppId = Record.AccountAppId

          .Name = Record.Name
          .Description = Record.Description
          .ExternalId = Record.ExternalId

          .FlagColour = Record.FlagColour
          .FlagNotes = Record.FlagNotes

          .DateQuoted = finBL.HtmlWidgetUtilities.GetDatabaseDateFromJsonUtcDate(Record.DateQuoted)

          .AccountManagerUserId = Record.AccountManagerUserId
          .DateReview = finBL.HtmlWidgetUtilities.GetDatabaseDateFromJsonUtcDate(Record.DateReview)

          .Notes = Record.Notes
        End If

        ' Details
        If Record.AllowPageDetails AndAlso finBL.CurrentUser.Permissions.Allow("AccountApp.Form.Page.Details") Then
          .BranchId = Record.BranchId
          .DepartmentId = Record.DepartmentId

          '.BdmCommissionUserId = Record.BdmCommissionUserId

          .DealerExternalPartyId = Record.DealerExternalPartyId
          .DealerExternalPartyEmployeeClientEmploymentId = Record.DealerExternalPartyEmployeeClientEmploymentId

          .BrokerExternalPartyId = Record.BrokerExternalPartyId
          .BrokerExternalPartyEmployeeClientEmploymentId = Record.BrokerExternalPartyEmployeeClientEmploymentId

          .InsuranceInsurerExternalPartyId = Record.InsuranceInsurerExternalPartyId
          .InsurancePolicyType = Record.InsurancePolicyType
          .InsurancePolicyNumber = Record.InsurancePolicyNumber
        End If

        ' Web
        If Record.AllowPageWeb AndAlso finBL.CurrentUser.Permissions.Allow("AccountApp.Form.Page.Web") AndAlso finBL.Settings.AddOns.WebAutomation Then
          .WebFriendlyName = Record.WebFriendlyName
          .WebResourceImageId = Record.WebResourceImageId
        End If
      End With

      ' Save
      If Success Then
        Success = mAccountApp.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 AccountAppId As String

  Public Name As String
  Public Description As String
  Public ExternalId As String

  Public AccountAppTypeId As String
  Public AccountAppTypeDescription As String
  Public Status As isefinAccountAppStatus
  Public StatusText As String
  Public StatusSub As String
  Public FlagColour As String
  Public FlagNotes As String

  Public DateQuoted As Date?

  Public AccountManagerUserId As String
  Public DateReview As Date?

  Public Notes As String

  ' Details
  Public BranchId As String
  Public DepartmentId As String

  Public BdmUserId As String
  Public BdmUserName As String
  Public BdmCommissionUserId As String

  Public DealerExternalPartyId As String
  Public DealerExternalPartyEmployeeClientEmploymentId As String
  Public DealerEmployeeWarning As String

  Public BrokerExternalPartyId As String
  Public BrokerExternalPartyEmployeeClientEmploymentId As String
  Public BrokerEmployeeWarning As String

  Public BulkFunderExternalPartyId As String
  Public BulkFunderName As String

  Public InsuranceInsurerExternalPartyId As String
  Public InsurancePolicyType As String
  Public InsurancePolicyNumber As String

  Public PoolId As String
  Public PoolDescription As String

  ' User Defined
  Public UserDefinedParameters As ISWsParameters
  Public UserDataJson As String

  ' Web
  Public WebFriendlyName As String
  Public WebResourceImageId As String

  ' Other
  Public IsClosed As Boolean

  ' Permissions
  Public AllowPageGeneral As Boolean
  Public AllowPageDetails As Boolean
  Public AllowPageUserDefined As Boolean
  Public AllowPageWeb As Boolean

   Public CanUpdateCode As Boolean
   Public CanUpdateManager As Boolean

  ' Lists
  Public FlagColourList As String
  Public PurposeInformationListId As String
  Public SourceInformationListId As String

  ' Configuration
  Public AccountShowExternalId As Boolean
  Public AddOnBranch As Boolean
  Public AddOnExternalParty As Boolean
  Public AddOnExternalPartyAdvancedBdms As Boolean
  Public AddOnExternalPartyBrokers As Boolean
  Public AddOnExternalPartyDealers As Boolean
  Public AddOnExternalPartyInsurers As Boolean

  Public HideOtherPages As Boolean
  Public PromptOnSave As Boolean

  ' Other

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 an Account Application.</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="Details"&gt;Details&lt;/li&gt;
        &lt;li tabId="Web"&gt;Web&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, Name and Description&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtAccountAppId"&gt;Code:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtAccountAppId"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtName"&gt;Name:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtName"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtExternalId"&gt;External Id:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtExternalId"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;th colspan="2"&gt;&lt;label id="lblAccountAppType"&gt;Application Type and Status&lt;/label&gt;&lt;/th&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboAccountAppType"&gt;Type:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboAccountAppType"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboStatus"&gt;Status:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboStatus"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboFlagColour"&gt;Flag Colour:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboFlagColour"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtFlagNotes"&gt;Flag Notes:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtFlagNotes"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;th colspan="2"&gt;&lt;label id="lblDates"&gt;Dates&lt;/label&gt;&lt;/th&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="dateDateQuoted"&gt;Quoted:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="dateDateQuoted"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;th colspan="2"&gt;&lt;label id="lblAccountManager"&gt;Account Manager&lt;/label&gt;&lt;/th&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboAccountManagerUser"&gt;Manager:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboAccountManagerUser"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="dateDateReview"&gt;Review Date:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="dateDateReview"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;th colspan="2"&gt;&lt;label id="lblNotes"&gt;Notes&lt;/label&gt;&lt;/th&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="txtNotes" /&gt;&lt;/th&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;



    &lt;!-- Details --&gt;
    &lt;div id="pageDetails"&gt;
      &lt;table class="is-form"&gt;
        &lt;colgroup&gt;
          &lt;col style="width:10em" /&gt;
          &lt;col /&gt;
        &lt;/colgroup&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblBranch"&gt;Branch and Department&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboBranch"&gt;Branch:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboBranch"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboDepartment"&gt;Department:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboDepartment"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblBdm"&gt;Business Development Manager&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboBdmUser"&gt;BDM:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboBdmUser"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboBdmCommissionUser"&gt;Commissions:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboBdmCommissionUser"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblDealer"&gt;Dealer and Employee&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboDealer"&gt;Dealer:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboDealer"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboDealerEmployee"&gt;Employee:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboDealerEmployee"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblBroker"&gt;Broker and Employee&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboBroker"&gt;Broker:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboBroker"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboBrokerEmployee"&gt;Employee:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboBrokerEmployee"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblInsurance"&gt;Insurance details&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboInsInsurer"&gt;Insurer:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboInsInsurer"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboInsPolicyType"&gt;Policy Type:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboInsPolicyType"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtInsPolicyNumber"&gt;Policy&amp;nbsp;Number:&amp;nbsp;&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtInsPolicyNumber"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;



    &lt;!-- Web --&gt;
    &lt;div id="pageWeb"&gt;
      &lt;table class="is-form"&gt;
        &lt;colgroup&gt;
          &lt;col style="width:6em" /&gt;
          &lt;col /&gt;
        &lt;/colgroup&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblWeb"&gt;Friendly Name (Nickname) and Image&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtWebFriendlyName"&gt;Name:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtWebFriendlyName"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboWebResourceImageId"&gt;Image:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboWebResourceImageId"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr id="trResourceImagePreview"&gt;
          &lt;th&gt;&lt;/th&gt;
          &lt;td&gt;&lt;img id="imgResourceImagePreview" style="margin-top:8px;" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;
  &lt;/div&gt;


  &lt;!-- Form Footer --&gt;
  &lt;footer&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,
  txtAccountAppId: null,
  txtName: null,
  txtExternalId: null,

  lblAccountAppType: null,
  cboAccountAppType: null,
  cboStatus: null,
  cboFlagColour: null,
  txtFlagNotes: null,

  lblDates: null,
  dateDateQuoted: null,

  lblAccountManager: null,
  cboAccountManagerUser: null,
  dateDateReview: null,

  lblNotes: null,
  txtNotes: null,

  //   Details
  lblBranch: null,
  cboBranch: null,
  cboDepartment: null,

  lblBdm: null,
  cboBdmUser: null,
  cboBdmCommissionUser: null,

  lblDealer: null,
  cboDealer: null,
  cboDealerEmployee: null,

  lblBroker: null,
  cboBroker: null,
  cboBrokerEmployee: null,

  lblInsurance: null,
  cboInsInsurer: null,
  cboInsPolicyType: null,
  txtInsPolicyNumber: null,

  //   Web
  lblWeb: null,
  txtWebFriendlyName: null,
  cboWebResourceImageId: null,
  trResourceImagePreview: null,
  imgResourceImagePreview: null,
}

// Form
var frmMain;
var tabDetails;

// Buttons
var cmdCancel;
var cmdFinish;

// Other

// ==========
// Initialise
// ==========
$(function () {
  // Mobile optimisations
  $(window).resize(Form_Resize);

  // --------
  // Controls
  // --------
  //   General
  C.lblCodeAndName = widget.UI.Label("lblCodeAndName", {});
  C.txtAccountAppId = widget.UI.TextBox("txtAccountAppId", {
    allowBlank: false,
    maxLength: 10,
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });
  C.txtName = widget.UI.TextBox("txtName", {
    allowBlank: false,
    maxLength: 100,
  });
  C.txtExternalId = widget.UI.TextBox("txtExternalId", {
    maxLength: 40,
  });

  C.lblAccountAppType = widget.UI.Label("lblAccountAppType", {});
  C.cboAccountAppType = widget.UI.DBCombo("cboAccountAppType", {
    autoReadOnly: true,
    readOnly: true,
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });
  C.cboStatus = widget.UI.DBCombo("cboStatus", {
    autoReadOnly: true,
    readOnly: true,
    showDropdown: false,
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });
  C.cboFlagColour = widget.UI.IconComboBox("cboFlagColour", {
    iconPrefix: "Flag[",
    iconSuffix: "]",
    limitToList: true,
    width: "12em",
  });
  C.txtFlagNotes = widget.UI.TextBox("txtFlagNotes", {
    maxLength: 255,
    multiLine: true,
    rows: 2,
  });

  C.lblDates = widget.UI.Label("lblDates", {});
  C.dateDateQuoted = widget.UI.DateBox("dateDateQuoted", {
    allowBlank: false,
  });

  C.lblAccountManager = widget.UI.Label("lblAccountManager", {});
  C.cboAccountManagerUser = widget.UI.DBCombo("cboAccountManagerUser", {
    allowBlank: true,
    width: widget.UI.FIELD_WIDTH_CODE_20,
  });
  C.dateDateReview = widget.UI.DateBox("dateDateReview", {});

  C.lblNotes = widget.UI.Label("lblNotes", {});
  C.txtNotes = widget.UI.TextBox("txtNotes", {
    maxLength: 32767,
    multiLine: true,
    rows: 8,
  });

  //   Details
  C.lblBranch = widget.UI.Label("lblBranch", {});
  C.cboBranch = widget.UI.DBCombo("cboBranch", {
    allowBlank: true,
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });
  C.cboDepartment = widget.UI.DBCombo("cboDepartment", {
    allowBlank: true,
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });

  C.lblBdm = widget.UI.Label("lblBdm", {});
  C.cboBdmUser = widget.UI.DBCombo("cboBdmUser", {
    autoReadOnly: false,
    readOnly: true,
    width: widget.UI.FIELD_WIDTH_CODE_20,
  });
  C.cboBdmCommissionUser = widget.UI.DBCombo("cboBdmCommissionUser", {
    allowBlank: true,
    width: widget.UI.FIELD_WIDTH_CODE_20,
  });

  C.lblDealer = widget.UI.Label("lblDealer", {});
  C.cboDealer = widget.UI.DBCombo("cboDealer", {
    allowBlank: true,
    width: widget.UI.FIELD_WIDTH_CODE_10,
    onChange: cboDealer_Change,
  });
  C.cboDealerEmployee = widget.UI.DBCombo("cboDealerEmployee", {
    allowBlank: true,
    width: widget.UI.FIELD_WIDTH_CODE_20,
  });

  C.lblBroker = widget.UI.Label("lblBroker", {});
  C.cboBroker = widget.UI.DBCombo("cboBroker", {
    allowBlank: true,
    width: widget.UI.FIELD_WIDTH_CODE_10,
    onChange: cboBroker_Change,
  });
  C.cboBrokerEmployee = widget.UI.DBCombo("cboBrokerEmployee", {
    allowBlank: true,
    width: widget.UI.FIELD_WIDTH_CODE_20,
  });

  C.lblInsurance = widget.UI.Label("lblInsurance", {});
  C.cboInsInsurer = widget.UI.DBCombo("cboInsInsurer", {
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });
  C.cboInsPolicyType = widget.UI.InformationListComboBox("cboInsPolicyType", {
    maxLength: 50,
  });
  C.txtInsPolicyNumber = widget.UI.TextBox("txtInsPolicyNumber", {
    maxLength: 20,
  });

  //   Web
  C.lblWeb = widget.UI.Label("lblWeb", {});
  C.txtWebFriendlyName = widget.UI.TextBox("txtWebFriendlyName", {
    maxLength: 50
  });
  C.cboWebResourceImageId = widget.UI.DBCombo("cboWebResourceImageId", {
    limitToList: true,
    width: widget.UI.FIELD_WIDTH_CODE_20,

    onChange: cboWebResourceImageId_Change
  });
  C.trResourceImagePreview = $("#trResourceImagePreview");
  C.imgResourceImagePreview = $("#imgResourceImagePreview");

  // Create Widget form
  // NOTE: Hide by default for a cleaner startup
  frmMain = new widget.UI.Form("frmMain", { captionWidth: "9em", textboxWidth: "20em", 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);

  // 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) {
    if (!mRecord.AllowPageGeneral) tabDetails.TabVisible("General", false);
    if (!mRecord.AllowPageDetails) tabDetails.TabVisible("Details", false);
    if (!mRecord.AllowPageWeb) tabDetails.TabVisible("Web", false);
  }

  // Load Fields
  Fields_Load();

  // Save Fields (so Dates etc. are in the correct format for mOriginalJson)
  Fields_Save();

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

// ===========
// Load Fields
// ===========
function Fields_Load() {
  if (mRecord) {
    // General
    if (mRecord.AllowPageGeneral) {
      C.txtAccountAppId.Text(mRecord.AccountAppId);
      C.txtName.Text(mRecord.Name);
      C.txtExternalId.Text(mRecord.ExternalId);

      C.cboAccountAppType.RefreshUnbound(mRecord.AccountAppTypeId, mRecord.AccountAppTypeDescription);
      C.cboStatus.RefreshUnbound(mRecord.StatusText, mRecord.StatusSub);
      C.cboFlagColour.Text(mRecord.FlagColour);
      C.txtFlagNotes.Text(mRecord.FlagNotes);

      C.dateDateQuoted.Value(mRecord.DateQuoted);

      C.cboAccountManagerUser.Text(mRecord.AccountManagerUserId);
      C.dateDateReview.Value(mRecord.DateReview);

      C.txtNotes.Text(mRecord.Notes);
    }

    // Details
    if (mRecord.AllowPageDetails) {
      C.cboBranch.Text(mRecord.BranchId);
      C.cboDepartment.Text(mRecord.DepartmentId);

      C.cboBdmUser.RefreshUnbound(mRecord.BdmUserId, mRecord.BdmUserName);
      C.cboBdmCommissionUser.Text(mRecord.BdmCommissionUserId);

      C.cboDealer.Text(mRecord.DealerExternalPartyId);
      C.cboDealerEmployee.Text(mRecord.DealerExternalPartyEmployeeClientEmploymentId);

      C.cboBroker.Text(mRecord.BrokerExternalPartyId);
      C.cboBrokerEmployee.Text(mRecord.BrokerExternalPartyEmployeeClientEmploymentId);

      C.cboInsInsurer.Text(mRecord.InsuranceInsurerExternalPartyId);
      C.cboInsPolicyType.Text(mRecord.InsurancePolicyType);
      C.txtInsPolicyNumber.Text(mRecord.InsurancePolicyNumber);
    }

    // Web
    if (mRecord.AllowPageWeb) {
      C.txtWebFriendlyName.Text(mRecord.WebFriendlyName);
      C.cboWebResourceImageId.Text(mRecord.WebResourceImageId);
    }
  }

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

  // Update Controls

  // Update fields
  Fields_Update();

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

// ===========
// Save Fields
// ===========
function Fields_Save() {
  // General
  if (mRecord.AllowPageGeneral) {
    mRecord.AccountAppId = C.txtAccountAppId.Text();
    mRecord.Name = C.txtName.Text();
    mRecord.ExternalId = C.txtExternalId.Text();

    mRecord.FlagColour = C.cboFlagColour.Text();
    mRecord.FlagNotes = C.txtFlagNotes.Text();

    mRecord.DateQuoted = C.dateDateQuoted.Value();

    mRecord.AccountManagerUserId = C.cboAccountManagerUser.Text();
    mRecord.DateReview = C.dateDateReview.Value();

    mRecord.Notes = C.txtNotes.Text();
  }

  // Details
  if (mRecord.AllowPageDetails) {
    mRecord.BranchId = C.cboBranch.Text();
    mRecord.DepartmentId = C.cboDepartment.Text();

    mRecord.BdmCommissionUserId = C.cboBdmCommissionUser.Text();

    mRecord.DealerExternalPartyId = C.cboDealer.Text();
    mRecord.DealerExternalPartyEmployeeClientEmploymentId = C.cboDealerEmployee.Text();

    mRecord.BrokerExternalPartyId = C.cboBroker.Text();
    mRecord.BrokerExternalPartyEmployeeClientEmploymentId = C.cboBrokerEmployee.Text();

    mRecord.InsuranceInsurerExternalPartyId = C.cboInsInsurer.Text();
    mRecord.InsurancePolicyType = C.cboInsPolicyType.Text();
    mRecord.InsurancePolicyNumber = C.txtInsPolicyNumber.Text();
  }

  // Web
  if (mRecord.AllowPageWeb) {
    mRecord.WebFriendlyName = C.txtWebFriendlyName.Text();
    mRecord.WebResourceImageId = C.cboWebResourceImageId.Text();
  }
}

// =============
// Update Fields
// =============
function Fields_Update() {
  // Heading
  if (mRecord) {
    widget.SetHeading("Account Application (" + mRecord.AccountAppId + ")");
  }

  // Information Lists
  if (mRecord) {
    if (mRecord.AddOnExternalPartyInsurers) C.cboInsPolicyType.SetComboFromInformationList("InsurancePolicyTypes");
 }

  // Lists
  if (mRecord) {
    // General
    if (mRecord.AllowPageGeneral) {
      C.cboFlagColour.ListFromCsvString(mRecord.FlagColourList);

      C.cboAccountManagerUser.RefreshFromStandardRange("AccountManagers");
    }

    // Details
    if (mRecord.AllowPageDetails) {
      if (mRecord.AddOnBranch) C.cboBranch.RefreshFromStandardRange("Branches");
      C.cboDepartment.RefreshFromStandardRange("Departments");
      C.cboBdmCommissionUser.RefreshFromStandardRange("Bdms");

      if (mRecord.AddOnExternalPartyDealers) C.cboDealer.RefreshFromStandardRange("ExternalPartiesDealers");
      if (mRecord.AddOnExternalPartyBrokers) C.cboBroker.RefreshFromStandardRange("ExternalPartiesBrokers");
      if (mRecord.AddOnExternalPartyInsurers) C.cboInsInsurer.RefreshFromStandardRange("ExternalPartiesInsurers");
    }

    // Web
    if (mRecord.AllowPageWeb) {
      C.cboWebResourceImageId.RefreshFromStandardRange("ResourcesAccountImages");
    }
  }

  // Controls
  if (mRecord) {
    // General
    if (mRecord.AllowPageGeneral) {
      C.txtAccountAppId.ReadOnly(!mRecord.CanUpdateCode);
      C.cboAccountManagerUser.ReadOnly(!mRecord.CanUpdateManager);
    }

    // Details
    if (mRecord.AllowPageDetails) {
      C.lblBdm.TooltipText(mRecord.BdmTooltip);

      if (mRecord.AddOnExternalPartyDealers) {
        cboDealer_Change();
      }

      if (mRecord.AddOnExternalPartyBrokers) {
        cboBroker_Change();
      }
    }
  }

  // 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"
    if (mRecord.AllowPageGeneral) pageGeneral_Refresh();
    if (mRecord.AllowPageDetails) pageDetails_Refresh();
    if (mRecord.AllowPageWeb) pageWeb_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.txtName.WidthResizeFromParent();
      C.txtExternalId.WidthResizeFromParent();

      C.cboAccountAppType.WidthResizeFromParent();

      C.cboAccountManagerUser.WidthResizeFromParent();

      C.txtNotes.WidthResizeFromParent();
      break;

    case "Details":
      // Details
      C.txtInsPolicyNumber.WidthResizeFromParent();
      break;

    case "Web":
      // Web
      C.txtWebFriendlyName.WidthResizeFromParent();
      C.cboWebResourceImageId.WidthResizeFromParent();
  }
}

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

    case "Details":
      pageDetails_Refresh();
      break;

    case "Web":
      pageWeb_Refresh();
      break;

    default:
      break;
  }

  // Resize
  tabDetails_Resize();

  // 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 Account Id just in case this has changed
      widget.RefreshParent(C.txtAccountAppId.Text());
    },

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

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

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

  // Controls
  C.txtExternalId.VisibleRow(mRecord.AccountShowExternalId);
  if (mRecord.IsClosed || mRecord.Status == "Complete") {
    C.dateDateQuoted.ReadOnly(true);
    C.cboAccountManagerUser.ReadOnly(true);
  }
}

// ===========
// pageDetails
// ===========
function pageDetails_Refresh() {
  if (!mRecord) return;

  // Controls
  if (!mRecord.AddOnBranch) {
    C.cboBranch.VisibleRow(false);
    C.lblBranch.Text("Department");
  }

  if (!mRecord.AddOnExternalPartyDealers) {
    C.lblDealer.VisibleRow(false);
    C.cboDealer.VisibleRow(false);
    C.cboDealerEmployee.VisibleRow(false);
  }

  if (!mRecord.AddOnExternalPartyBrokers) {
    C.lblBroker.VisibleRow(false);
    C.cboBroker.VisibleRow(false);
    C.cboBrokerEmployee.VisibleRow(false);
  }

  if(!mRecord.AddOnExternalPartyInsurers) {
    C.cboInsInsurer.VisibleRow(false);
  }

  if (mRecord.IsClosed || mRecord.Status == "Complete") {
    C.cboBranch.ReadOnly(true);
    C.cboDepartment.ReadOnly(true);
    C.cboBdmUser.ReadOnly(true);
    C.cboBdmCommissionUser.ReadOnly(true);
    C.cboDealer.ReadOnly(true);
    C.cboDealerEmployee.ReadOnly(true);
    C.cboBroker.ReadOnly(true);
    C.cboBrokerEmployee.ReadOnly(true);
    C.cboInsInsurer.ReadOnly(true);
    C.cboInsPolicyType.ReadOnly(true);
    C.txtInsPolicyNumber.ReadOnly(true);
  }

  // Not yet implemented
  C.cboBdmCommissionUser.VisibleRow(false);
}

// =======
// pageWeb
// =======
function pageWeb_Refresh() {
  // Controls
  cboWebResourceImageId_Change();
}

// =========
// cboDealer
// =========
function cboDealer_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

  // Update Employees
  if (C.cboDealer.Text()) {
    C.cboDealerEmployee.RefreshFromStandardRange("ExternalPartiesDealerEmployees", "ExternalPartyId='" + C.cboDealer.Text() + "'");
  }

  // Refresh BDM
  if (e) cboBdm_Refresh();
}

// =========
// cboBroker
// =========
function cboBroker_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

  // Update Employees
  if (C.cboBroker.Text()) {
    C.cboBrokerEmployee.RefreshFromStandardRange("ExternalPartiesBrokerEmployees", "ExternalPartyId='" + C.cboBroker.Text() + "'");
  }

  // Refresh BDM
  if (e) cboBdm_Refresh();
}

// =====================
// cboWebResourceImageId
// =====================
function cboWebResourceImageId_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

  // Clear to prevent an old image taking a while to disappear
  C.trResourceImagePreview.hide();
  C.imgResourceImagePreview.attr("src", "");

  // Get Image Data
  if (C.cboWebResourceImageId.Text()) {
    widget.GetString("GetImageData", { resourceId: C.cboWebResourceImageId.Text() }, cboWebResourceImageId_Change_Done, function(errorMessage) {
      widget.UI.MsgBoxAlert(errorMessage);
    });
  }
}

function cboWebResourceImageId_Change_Done(data) {
  var o = JSON.parse(data);

  // Set Image from Data URI
  C.imgResourceImagePreview.attr("src", o.DataUri);
  C.trResourceImagePreview.show();
}

// ======
// cboBdm
// ======
function cboBdm_Refresh() {
  //TODO: Refresh read-only BDM
}

// ====================
// 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>VugbPYEGc0eNJ1COgYcg5Q</UniqueId><AllowRefresh>true</AllowRefresh><Caption>Account Application</Caption><HtmlWidgetMaxHeight>1024</HtmlWidgetMaxHeight><HtmlWidgetMaxWidth>800</HtmlWidgetMaxWidth><HtmlWidgetNeverApplyStyling>false</HtmlWidgetNeverApplyStyling><HtmlWidgetResourceCssSummaryPage2>false</HtmlWidgetResourceCssSummaryPage2><HtmlWidgetResourceCssWidget>true</HtmlWidgetResourceCssWidget><HtmlWidgetResourceJQuery>true</HtmlWidgetResourceJQuery><HtmlWidgetResourceJQueryVersion /><Icon /><JavaScriptDebugger>None</JavaScriptDebugger><RestrictedOriginsListEnabled>false</RestrictedOriginsListEnabled><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="AccountAppId" 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.AccountApps</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,Details,UserDefined,Web</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>