<?xml version="1.0" encoding="utf-8"?>
  <finScript version="1.00" exportedUtcDate="2023-10-29T20:36:43.0000000">
    <CreatedUserId>ADMIN</CreatedUserId>
    <CreatedUtcDate>2021-12-13T03:35:42.0600000</CreatedUtcDate>
    <UpdatedUserId>ADMIN</UpdatedUserId>
    <UpdatedUtcDate>2023-10-29T20:36:15.0130000</UpdatedUtcDate>
    <ScriptId>EE</ScriptId>
    <Description>Element Edit</Description>
    <ScriptType>HtmlWidget</ScriptType>
    <Active>true</Active>
    <AllowUI>false</AllowUI>
    <Bookmarks />
    <Category />
    <Code>' HtmlWidget_ElementEdit
Option Explicit On
Option Strict On

' #################################################################
' Element Edit form HTML Widget
'
' Version: 1.03 (30/10/2023)
'
' Usage: System-supplied HTML Widget
' #################################################################
' Version        Date  User     Job       Description
' -------  ----------  -------  --------  -------------------------
'    1.00  15/12/2021  ISS      J027933   Created
'          06/04/2022  ISS      J028041   Additional pre-release changes
'          26/04/2022  ISS      J027933   Additional pre-release changes
'    1.01  28/02/2023  ISS      J027933   Various fixes
'    1.02  24/05/2023  ISS      J031134   Add AmlRevenue checkbox
'    1.03  30/10/2023  ISS      J031275   'Include as income' and 'Consolidate Disbursements' tidied up for Disbursement type Elements
' #################################################################

' Constants
Private Const FORM_KEY As String = "Elements"

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

' Standard Parameters
Private mElementId 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
    mElementId = .GetString("ElementId") ' Always use Startup Parameters since the Element 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 Element.
''' &lt;/summary&gt;
Private Function GetElement(ByRef element As finElement) As Boolean

  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Validate

  ' Create and Load Element
  If Success Then
    ' Create Element
    element = finBL.CreateElement()

    ' Load Element
    If Len(mDuplicateRecordId) &lt;&gt; 0 Then
      ' New record (by duplicating existing)
      Success = element.Load(mDuplicateRecordId)
      If Success Then element.Duplicate()
    ElseIf Len(mElementId) = 0 Then
      ' New record
    Else
      Success = element.Load(mElementId)
    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 Element As finElement
  Dim FormInitialisationInfo As FormInitialisationInfo
  Dim s As String
  Dim sqb As ISSelectQueryBuilder
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Validate

  ' Get Element
  If Success Then
    Success = GetElement(Element)
  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 = Element.Pk
      .Timestamp = Element.Timestamp

      ' Page Permissions (defined here since they are used below)
      .AllowPageGeneral = True
      .AllowPageOptions = True
      .AllowPageDefaults = True
      .AllowPageDisbursements = finBL.Settings.AddOns.Disbursements
      .AllowPageCredit = True
      .AllowPageGlAccounts = True
      .AllowPageAuthorisation = True

      ' General
      .ElementId = Element.ElementId ' Always need to return Element Id
      If .AllowPageGeneral Then
        .Active = Element.Active
        .Description = Element.Description

        .ElementTypeText = Element.ElementTypeText
        .IsDefaultFee = Element.IsDefaultFee
        .Category = Element.Category

        .AllocationTypeText = Element.AllocationTypeText
        .IsIncome = Element.IsIncome
        .AmlRevenue = Element.AmlRevenue
        .DueImmediately = Element.DueImmediately
        .DueImmediatelyDirectDebit = Element.DueImmediatelyDirectDebit
        .UserFlagA = Element.UserFlagA
        .UserFlagB = Element.UserFlagB

        .ComparisonRateCapitalise = Element.ComparisonRateCapitalise
        .ComparisonRateRegions = Element.ComparisonRateRegions
      End If

      ' Options
      If .AllowPageOptions Then
       .ColourBackground = Element.ColourBackground
       .ColourForeground = Element.ColourForeground
       .GstCode = Element.GstCode
       .GstRate = Element.GstRate
      End If

      ' Defaults
      If .AllowPageDefaults Then
        .TransactionReference = Element.TransactionReference
        .TransactionValue = Element.TransactionValue
        .TransactionNotes = Element.TransactionNotes
        .DateAdjustBasisText = Element.DateAdjustBasisText
        .StandardTransactionProcessScriptId = Element.StandardTransactionProcessScriptId
        .PermissionKeyAllowChange = Element.PermissionKeyAllowChange
      End If

      ' Disbursements
      If .AllowPageDisbursements Then
        .DisbursementTypeText = Element.DisbursementTypeText
        .DisbursementElementId = Element.DisbursementElementId
        .DisbursementKey = Element.DisbursementKey

        .DisbursementPayeeTypeText = Element.DisbursementPayeeTypeText
        .DisbursementPayeeExternalPartyId = Element.DisbursementPayeeExternalPartyId
        .DisbursementPayeeAllowUpdates = Element.DisbursementPayeeAllowUpdates
        .DisbursementConsolidate = Element.DisbursementConsolidate

        .DisbursementPayeeExternalPartyCategories = Element.DisbursementPayeeExternalPartyCategories

        .DisbursementBasisText = Element.DisbursementBasisText
        .DisbursementRateCurrency = Element.DisbursementRateCurrency
        .DisbursementRatePercent = Element.DisbursementRatePercent

        .CommissionElementId = Element.CommissionElementId
      End If

      ' Credit
      If .AllowPageCredit Then
        .CreditAllow = Element.CreditAllow
        .CreditCalculationMethodText = Element.CreditCalculationMethodText
        .CreditCalculationLess = Element.CreditCalculationLess
        .CreditCalculationBasisStartText = Element.CreditCalculationBasisStartText
        .CreditCalculationBasisEndText = Element.CreditCalculationBasisEndText
        .CreditRefinanceOptionText = Element.CreditRefinanceOptionText
        .CreditRefinanceCalculationMethodText = Element.CreditRefinanceCalculationMethodText
        .CreditRefinanceCalculationLess = Element.CreditRefinanceCalculationLess
        .CreditRefinanceCalculationBasisStartText = Element.CreditRefinanceCalculationBasisStartText
        .CreditRefinanceCalculationBasisEndText = Element.CreditRefinanceCalculationBasisEndText
        .CreditElementId = Element.CreditElementId
      End If

      ' GL Accounts
      If .AllowPageGlAccounts Then
        .GlAccountId = Element.GlAccountId
        .WTaxGlAccountId = Element.WTaxGlAccountId
        .ImpCreditsGlAccountId = Element.ImpCreditsGlAccountId

        .GlSummaryTypeText = Element.GlSummaryTypeText

        .AccountingLedgerTypeText = Element.AccountingLedgerTypeText
        .AccountingLedgerMethodText = Element.AccountingLedgerMethodText
        .AccountingLedgerLess = Element.AccountingLedgerLess
        .AccountingLedgerGlEomSplit = Element.AccountingLedgerGlEomSplit
        .AccountingLedgerIncludeOpeningInReports = Element.AccountingLedgerIncludeOpeningInReports

        .UnearnedGlAccountId = Element.UnearnedGlAccountId
      End If

      ' Authorisation
      If .AllowPageAuthorisation Then
        .AuthoriseTransactions = Element.AuthoriseTransactions
        .PermissionKeyAuthorise = Element.PermissionKeyAuthorise
      End If

      ' Other
      sqb = finBL.Database.CreateSelectQueryBuilder()
      With sqb
        .Table = "Account"
        .DistinctType = iseSelectQueryDistinctType.Distinct
        .Fields.AddList("Region")
        .OrderByFields.Add("Region")
      End With
      .AccountRegionsFilter = finBL.HtmlWidgetUtilities.EncryptSql(sqb.GetSql())
      .CreditElementFilter = finBL.HtmlWidgetUtilities.EncryptSql("[ElementType]=" &amp; CStr(isefinElementType.Journal)) ' For records without an Element Type yet specified
      .DisbursementElementFilter = finBL.HtmlWidgetUtilities.EncryptSql("[ElementType]=" &amp; CStr(isefinElementType.Disbursement))
      .StandardTransactionProcessScriptFilter = finBL.HtmlWidgetUtilities.EncryptSql(finBL.Scripts.GetDataViewFilter(True, isefinScriptType.ObjectEvents, True, "Account"))

      ' Permissions

      ' Lists
      .AccountingLedgerMethodList = finBL.Enums.isefinAccountingLedgerMethod_ToCodeDescriptionList().ToJsonObject()
      .AccountingLedgerTypeList = finBL.Enums.isefinAccountingLedgerType_ToCodeDescriptionList().ToJsonObject()
      .CreditCalculationMethodList = finBL.Enums.isefinElementCreditCalculationMethod_ToCodeDescriptionList().ToJsonObject()
      .CreditRefinanceOptionList =  finBL.Enums.isefinElementCreditRefinanceOption_ToCodeDescriptionList().ToJsonObject()
      .DisbursementTypeList = finBL.Enums.isefinDisbursementType_ToCodeDescriptionList(True, True, False).ToJsonObject()
      .DisbursementPayeeTypeAllList = finBL.Enums.isefinDisbursementPayeeType_ToCodeDescriptionList(True, True, True).ToJsonObject()
      .DisbursementPayeeTypeNoBulkFunderList = finBL.Enums.isefinDisbursementPayeeType_ToCodeDescriptionList(True, True, False).ToJsonObject()
      .DisbursementValueBasisList = finBL.Enums.isefinDisbursementBasis_ToCodeDescriptionList().ToJsonObject()
      For Each s In finBL.Enums.isefinElementType_GetList()
        .ElementTypeList.Add(New ElementTypeInfo(finBL.Enums.isefinElementType_FromString(s)))
      Next
      .ListGlInterfaceSummaryType = finBL.enums.isefinElementGlInterfaceSummaryType_GetList().ToCsvString()
      .ListAllocationTypeAll = finBL.enums.isefinElementAllocationType_GetList().ToCsvString()
      .ListAllocationTypeExcludeInterest = finBL.enums.isefinElementAllocationType_GetList(False).ToCsvString()
      .ListCreditCalculationBasisEnd = finBL.Enums.isefinElementCreditCalculationBasisEnd_GetList().ToCsvString()
      .ListCreditCalculationBasisStart = finBL.Enums.isefinElementCreditCalculationBasisStart_GetList().ToCsvString()
      .ListDateAdjustBasis = finBL.Enums.isefinElementDateAdjustBasis_GetList().ToCsvString()

      ' Configuration
      .AddOnAccountingLedgers = finBL.Settings.AddOns.AccountingLedgers
      .AddOnBankingAdvanced = finBL.Settings.AddOns.BankingAdvanced
      .AddOnCurrentAccount = finBL.Settings.AddOns.CurrentAccount
      .AddOnDepositAccount = finBL.Settings.AddOns.DepositAccount
      .AddOnLoansAny = finBL.Settings.AddOns.LoansAny
      .GstName = finBL.CurrentCountry.Terminology(isefinCountryTerminology.GSTName, False)
      .GstNameShort = finBL.CurrentCountry.Terminology(isefinCountryTerminology.GSTName, True)
      .HideOtherPages = mCombinedParameters.GetBoolean("HideOtherPages", False)
      .PromptOnSave = finBL.CloudConnectFunctions.CloudConnectSettings.PromptOnSave
      .UseGst = finBL.Settings.UseGst
      .UserFlagACaption = finBL.Settings.ElementFlagAResolved
      .UserFlagBCaption = finBL.Settings.ElementFlagBResolved
    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 Element.
''' &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 Element As finElement
  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 Element
  If Success Then
    Success = GetElement(Element)
  End If

  ' Validate
  If Success Then
    If Record.Timestamp &lt;&gt; Element.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 Element
      With Element
        ' General
        If Record.AllowPageGeneral Then
          .ElementId = Record.ElementId
          .Active = Record.Active
          .Description = Record.Description

          .ElementTypeText = Record.ElementTypeText
          .IsDefaultFee = Record.IsDefaultFee
          .Category = Record.Category

          .AllocationTypeText = Record.AllocationTypeText
          .IsIncome = Record.IsIncome
          .AmlRevenue = Record.AmlRevenue
          .DueImmediately = Record.DueImmediately
          .DueImmediatelyDirectDebit = Record.DueImmediatelyDirectDebit
          .UserFlagA = Record.UserFlagA
          .UserFlagB = Record.UserFlagB

          .ComparisonRateCapitalise = Record.ComparisonRateCapitalise
          .ComparisonRateRegions = Record.ComparisonRateRegions
        End If

        ' Options
        If Record.AllowPageOptions Then
         .ColourBackground = Record.ColourBackground
         .ColourForeground = Record.ColourForeground
         .GstCode = Record.GstCode
         .GstRate = Record.GstRate
        End If

        ' Defaults
        If Record.AllowPageDefaults Then
          .TransactionReference = Record.TransactionReference
          .TransactionValue = Record.TransactionValue
          .TransactionNotes = Record.TransactionNotes
          .DateAdjustBasisText = Record.DateAdjustBasisText
          .StandardTransactionProcessScriptId = Record.StandardTransactionProcessScriptId
          .PermissionKeyAllowChange = Record.PermissionKeyAllowChange
        End If

        ' Disbursements
        If Record.AllowPageDisbursements Then
          .DisbursementTypeText = Record.DisbursementTypeText
          .DisbursementElementId = Record.DisbursementElementId
          .DisbursementKey = Record.DisbursementKey

          .DisbursementPayeeTypeText = Record.DisbursementPayeeTypeText
          .DisbursementPayeeExternalPartyId = Record.DisbursementPayeeExternalPartyId
          .DisbursementPayeeAllowUpdates = Record.DisbursementPayeeAllowUpdates
          .DisbursementConsolidate = Record.DisbursementConsolidate

          .DisbursementPayeeExternalPartyCategories = Record.DisbursementPayeeExternalPartyCategories

          .DisbursementBasisText = Record.DisbursementBasisText
          .DisbursementRateCurrency = Record.DisbursementRateCurrency
          .DisbursementRatePercent = Record.DisbursementRatePercent

          .CommissionElementId = Record.CommissionElementId
        End If

        ' Credit
        If Record.AllowPageCredit Then
          .CreditAllow = Record.CreditAllow
          .CreditCalculationMethodText = Record.CreditCalculationMethodText
          .CreditCalculationLess = Record.CreditCalculationLess
          .CreditCalculationBasisStartText = Record.CreditCalculationBasisStartText
          .CreditCalculationBasisEndText = Record.CreditCalculationBasisEndText
          .CreditRefinanceOptionText = Record.CreditRefinanceOptionText
          .CreditRefinanceCalculationMethodText = Record.CreditRefinanceCalculationMethodText
          .CreditRefinanceCalculationLess = Record.CreditRefinanceCalculationLess
          .CreditRefinanceCalculationBasisStartText = Record.CreditRefinanceCalculationBasisStartText
          .CreditRefinanceCalculationBasisEndText = Record.CreditRefinanceCalculationBasisEndText
          .CreditElementId = Record.CreditElementId
        End If

        ' GL Accounts
        If Record.AllowPageGlAccounts Then
          .GlAccountId = Record.GlAccountId
          .WTaxGlAccountId = Record.WTaxGlAccountId
          .ImpCreditsGlAccountId = Record.ImpCreditsGlAccountId

          .GlSummaryTypeText = Record.GlSummaryTypeText

          .AccountingLedgerTypeText = Record.AccountingLedgerTypeText
          .AccountingLedgerMethodText = Record.AccountingLedgerMethodText
          .AccountingLedgerLess = Record.AccountingLedgerLess
          .AccountingLedgerGlEomSplit = Record.AccountingLedgerGlEomSplit
          .AccountingLedgerIncludeOpeningInReports = Record.AccountingLedgerIncludeOpeningInReports

          .UnearnedGlAccountId = Record.UnearnedGlAccountId
        End If

        ' Authorisation
        If Record.AllowPageAuthorisation Then
          .AuthoriseTransactions = Record.AuthoriseTransactions
          .PermissionKeyAuthorise = Record.PermissionKeyAuthorise
        End If
      End With

      ' Save
      If Success Then
        Success = Element.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 ElementId As String
  Public Active As Boolean
  Public Description As String

  Public ElementTypeText As String
  Public IsDefaultFee As Boolean
  Public Category As String

  Public AllocationTypeText As String
  Public IsIncome As Boolean
  Public AmlRevenue As Boolean
  Public DueImmediately As Boolean
  Public DueImmediatelyDirectDebit As Boolean
  Public UserFlagA As Boolean
  Public UserFlagB As Boolean

  Public ComparisonRateCapitalise As Boolean
  Public ComparisonRateRegions As String

  ' Options
  Public ColourBackground As String
  Public ColourForeground As String

  Public GstCode As String
  Public GstRate As Decimal

  ' Defaults
  Public TransactionReference As String
  Public TransactionValue As Decimal
  Public TransactionNotes As String

  Public DateAdjustBasisText As String
  Public StandardTransactionProcessScriptId As String
  Public PermissionKeyAllowChange As String

  ' Disbursements
  Public DisbursementTypeText As String
  Public DisbursementElementId As String
  Public DisbursementKey As String

  Public DisbursementPayeeTypeText As String
  Public DisbursementPayeeExternalPartyId As String
  Public DisbursementPayeeAllowUpdates As Boolean
  Public DisbursementConsolidate As Boolean

  Public DisbursementPayeeExternalPartyCategories As String

  Public DisbursementBasisText As String
  Public DisbursementRateCurrency As Decimal
  Public DisbursementRatePercent As Double

  Public CommissionElementId As String

  ' Credit
  Public CreditAllow As Boolean
  Public CreditCalculationMethodText As String
  Public CreditCalculationLess As Double
  Public CreditCalculationBasisStartText As String
  Public CreditCalculationBasisEndText As String

  Public CreditRefinanceOptionText As String
  Public CreditRefinanceCalculationMethodText As String
  Public CreditRefinanceCalculationLess As Double
  Public CreditRefinanceCalculationBasisStartText As String
  Public CreditRefinanceCalculationBasisEndText As String

  Public CreditElementId As String

  ' GL Accounts
  Public GlAccountId As String
  Public WTaxGlAccountId As String
  Public ImpCreditsGlAccountId As String

  Public GlSummaryTypeText As String

  Public AccountingLedgerTypeText As String
  Public AccountingLedgerMethodText As String
  Public AccountingLedgerLess As Double
  Public AccountingLedgerGlEomSplit As Boolean
  Public AccountingLedgerIncludeOpeningInReports As Boolean

  Public UnearnedGlAccountId As String

  ' Authorisation
  Public AuthoriseTransactions As Boolean
  Public PermissionKeyAuthorise As String

  ' Other
  Public AccountRegionsFilter As String
  Public CreditElementFilter As String
  Public DisbursementElementFilter As String
  Public StandardTransactionProcessScriptFilter As String

  ' Permissions
  Public AllowPageGeneral As Boolean
  Public AllowPageOptions As Boolean
  Public AllowPageDefaults As Boolean
  Public AllowPageDisbursements As Boolean
  Public AllowPageCredit As Boolean
  Public AllowPageGlAccounts As Boolean
  Public AllowPageAuthorisation As Boolean

  ' Lists
  Public AccountingLedgerMethodList As Object
  Public AccountingLedgerTypeList As Object
  Public CreditCalculationMethodList As Object
  Public CreditRefinanceOptionList As Object
  Public DisbursementPayeeTypeAllList As Object
  Public DisbursementPayeeTypeNoBulkFunderList As Object
  Public DisbursementTypeList As Object
  Public DisbursementValueBasisList As Object
  Public ElementTypeList As New List(Of ElementTypeInfo)
  Public ListGlInterfaceSummaryType As String
  Public ListAllocationTypeAll As String
  Public ListAllocationTypeExcludeInterest As String
  Public ListCreditCalculationBasisEnd As String
  Public ListCreditCalculationBasisStart As String
  Public ListDateAdjustBasis As String

  ' Configuration
  Public AddOnAccountingLedgers As Boolean
  Public AddOnBankingAdvanced As Boolean
  Public AddOnCurrentAccount As Boolean
  Public AddOnDepositAccount As Boolean
  Public AddOnLoansAny As Boolean
  Public GstName As String
  Public GstNameShort As String
  Public HideOtherPages As Boolean
  Public PromptOnSave As Boolean
  Public UseGst As Boolean
  Public UserFlagACaption As String
  Public UserFlagBCaption As String

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



''' &lt;summary&gt;
'''  Element Type Information.
''' &lt;/summary&gt;
Public Class ElementTypeInfo
  
  Public ElementType As isefinElementType
  Public Description As String
  
  ' Lists
  Public CreditElementFilter As String
  
  Public Sub New(elementType As isefinElementType)
    
    With elementType
      Me.ElementType = elementType 
      Me.Description = finBLShared.Enums.isefinElementType_ToString(elementType)
      
      ' Lists
      Select Case elementType
        Case isefinElementType.Disbursement 
          Me.CreditElementFilter = finBLShared.HtmlWidgetUtilities.EncryptSql("[ElementType]=" &amp; CStr(isefinElementType.Disbursement))

        Case Else
          Me.CreditElementFilter = finBLShared.HtmlWidgetUtilities.EncryptSql("[ElementType]=" &amp; CStr(isefinElementType.Journal) &amp; " OR [ElementType]=" &amp; CStr(elementType))
      End Select
    End With
    
  End Sub
  
  
  
End Class</Code>
    <Language>VisualBasic</Language>
    <Notes>System-supplied HTML Widget to edit an Element.</Notes>
    <PermissionKeyExecute />
    <ReferenceLinq>false</ReferenceLinq>
    <RunWithoutPrompts>false</RunWithoutPrompts>
    <TemplateText>&lt;div id="frmMain" class="is-widget-content" style="visibility:hidden"&gt;

 &lt;style type="text/less"&gt;
   div.colour-preview {
      display:inline-block;
      border:1px solid rgba(0,0,0,0.1);
      height:32px;
      line-height:32px;
      margin:4px 0 0 0;
      padding:0;
      text-align:center;
      width:100px;
   }
 &lt;/style&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;li tabId="Defaults"&gt;Defaults&lt;/li&gt;
        &lt;li tabId="Disbursements"&gt;Disbursements&lt;/li&gt;
        &lt;li tabId="Credit"&gt;Credit/ Rebates&lt;/li&gt;
        &lt;li tabId="GlAccounts"&gt;GL Accounts&lt;/li&gt;
        &lt;li tabId="Authorisation"&gt;Authorisation&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="txtElementId"&gt;Code:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtElementId"/&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&gt;Element Type and Category&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboElementType"&gt;Type:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboElementType"/&gt; &lt;input id="chkIsDefaultFee" 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;label&gt;Other options&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboAllocationType"&gt;Allocation:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboAllocationType"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkIsIncome" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkAmlRevenue" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkDueImmediately" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2" class="indent1"&gt;&lt;input id="chkDueImmediatelyDirectDebit" 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;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblComparisonRateOptions"&gt;Comparison Rate options&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkComparisonRateCapitalise" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtComparisonRateRegions"&gt;Regions:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtComparisonRateRegions"/&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&gt;Colours&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboColourForeground"&gt;Foreground:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboColourForeground"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboColourBackground"&gt;Background:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboColourBackground"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;div id="divPreview" class="colour-preview"&gt;Preview&lt;/div&gt;&lt;/th&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblGst"&gt;GST Code and Rate&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboGstCode"&gt;GST Code:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboGstCode"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="numGstRate"&gt;GST Rate:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="numGstRate"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;



    &lt;!-- Defaults --&gt;
    &lt;div id="pageDefaults"&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&gt;Default Transaction values&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboTransactionReference"&gt;Reference:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboTransactionReference"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="numTransactionValue"&gt;Value:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="numTransactionValue"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtTransactionNotes"&gt;Notes:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtTransactionNotes"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label&gt;Standard Transaction processing&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboDateAdjustBasis"&gt;Date Adjust:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboDateAdjustBasis"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboStandardTransactionProcessScript"&gt;Script:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboStandardTransactionProcessScript"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblAllowChangePermissionKey"&gt;Optional Permission Key to prevent changes whilst a Quote&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboPermissionKeyAllowChange"&gt;Permission&amp;nbsp;Key:&amp;nbsp;&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboPermissionKeyAllowChange"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;



    &lt;!-- Disbursements --&gt;
    &lt;div id="pageDisbursements"&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="lblDisbursementType"&gt;Disbursement Type&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboDisbursementType"&gt;Type:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboDisbursementType"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboDisbursementElement"&gt;Element:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboDisbursementElement"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtDisbursementKey"&gt;Key:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtDisbursementKey"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblDisbursementPayeeDetails"&gt;Disbursement payee defaults&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboDisbursementPayeeType"&gt;Payee Type:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboDisbursementPayeeType"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboDisbursementPayeeExternalParty"&gt;Ext Party:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboDisbursementPayeeExternalParty"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkDisbursementPayeeAllowUpdates" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkDisbursementConsolidate" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblDisbursementExternalPartyCategories"&gt;External Party categories&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtDisbursementPayeeExternalPartyCategories"&gt;Categories:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtDisbursementPayeeExternalPartyCategories"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblDisburseValues"&gt;Disbursement value defaults&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboDisbursementValueBasis"&gt;Basis:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboDisbursementValueBasis"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="numDisbursementValueCurrency"&gt;Value:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="numDisbursementValueCurrency"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="numDisbursementValuePercent"&gt;Percent:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="numDisbursementValuePercent"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblCommission"&gt;Commision Element&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboCommissionElement"&gt;Element:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboCommissionElement"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;



    &lt;!-- Credit --&gt;
    &lt;div id="pageCredit"&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="lblCreditCalculationMethod"&gt;Credit (rebate) calculation for Close&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkCreditAllow" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboCreditCalculationMethod"&gt;Method:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboCreditCalculationMethod"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="numCreditCalculationLess"&gt;Less:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="numCreditCalculationLess"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboCreditCalculationBasisStart"&gt;Start Basis:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboCreditCalculationBasisStart"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboCreditCalculationBasisEnd"&gt;End Basis:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboCreditCalculationBasisEnd"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblCreditRebateRefinance"&gt;Credit (rebate) calculation for Refinances&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboCreditRefinanceOption"&gt;Option:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboCreditRefinanceOption"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboCreditRefinanceCalculationMethod"&gt;Method:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboCreditRefinanceCalculationMethod"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="numCreditRefinanceCalculationLess"&gt;Less:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="numCreditRefinanceCalculationLess"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboCreditRefinanceCalculationBasisStart"&gt;Start Basis:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboCreditRefinanceCalculationBasisStart"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboCreditRefinanceCalculationBasisEnd"&gt;End Basis:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboCreditRefinanceCalculationBasisEnd"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblCreditRebateElement"&gt;Credit (rebate) Element&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboCreditElement"&gt;Element:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboCreditElement"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;



    &lt;!-- GL Accounts --&gt;
    &lt;div id="pageGlAccounts"&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&gt;GL Accounts where transactions are posted&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboGlAccount"&gt;GL Account:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboGlAccount"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboWTaxGlAccount"&gt;W/ Tax:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboWTaxGlAccount"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboImpCreditsGlAccount"&gt;Imp Credits:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboImpCreditsGlAccount"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblGlSummaryType"&gt;Summary transfer option&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboElementGlInterfaceSummaryType"&gt;Summary&amp;nbsp;Type:&amp;nbsp;&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboElementGlInterfaceSummaryType"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblAccountingLedgers"&gt;Accounting Ledger options&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboAccountingLedgerType"&gt;Type:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboAccountingLedgerType"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboAccountingLedgerMethod"&gt;Method:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboAccountingLedgerMethod"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="numAccountingLedgerLess"&gt;Less:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="numAccountingLedgerLess"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkAccountingLedgerGlEomSplit" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkAccountingLedgerIncludeOpeningInReports" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblAccountingLedgerGlAccount"&gt;GL Account where unearned transactions are posted&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboUnearnedGlAccount"&gt;Unearned:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboUnearnedGlAccount"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;



    &lt;!-- Authorisation --&gt;
    &lt;div id="pageAuthorisation"&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&gt;Transaction authorisation&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkAuthoriseTransactions" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblPermissionKeyAuthorise"&gt;Permission Key required to authorise Transactions&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboPermissionKeyAuthorise"&gt;Permission&amp;nbsp;Key:&amp;nbsp;&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboPermissionKeyAuthorise"/&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,
  chkActive: null,
  txtElementId: null,
  txtDescription: null,

  cboElementType: null,
  chkIsDefaultFee: null,
  cboCategory: null,

  cboAllocationType: null,
  chkIsIncome: null,
  chkAmlRevenue: null,
  chkDueImmediately: null,
  chkDueImmediatelyDirectDebit: null,
  chkUserFlagA: null,
  chkUserFlagB: null,

  lblComparisonRateOptions: null,
  chkComparisonRateCapitalise: null,
  txtComparisonRateRegions: null,

  //   Options
  cboColourForeground: null,
  cboColourBackground: null,
  divPreview: null,

  lblGst: null,
  cboGstCode: null,
  numGstRate: null,

  //   Defaults
  cboTransactionReference: null,
  numTransactionValue: null,
  txtTransactionNotes: null,

  cboDateAdjustBasis: null,
  cboStandardTransactionProcessScript: null,

  lblAllowChangePermissionKey: null,
  cboPermissionKeyAllowChange: null,

  //   Disbursements
  lblDisbursementType: null,
  cboDisbursementType: null,
  cboDisbursementElement: null,
  txtDisbursementKey: null,

  lblDisbursementPayeeDetails: null,
  cboDisbursementPayeeType: null,
  cboDisbursementPayeeExternalParty: null,
  chkDisbursementPayeeAllowUpdates: null,
  chkDisbursementConsolidate: null,

  lblDisbursementExternalPartyCategories: null,
  txtDisbursementPayeeExternalPartyCategories: null,

  lblDisburseValues: null,
  cboDisbursementValueBasis: null,
  numDisbursementValueCurrency: null,
  numDisbursementValuePercent: null,

  lblCommission: null,
  cboCommissionElement: null,

  //   Credit
  lblCreditCalculationMethod: null,
  chkCreditAllow: null,
  cboCreditCalculationMethod: null,
  numCreditCalculationLess: null,
  cboCreditCalculationBasisStart: null,
  cboCreditCalculationBasisEnd: null,

  lblCreditRebateRefinance: null,
  cboCreditRefinanceOption: null,
  cboCreditRefinanceCalculationMethod: null,
  numCreditRefinanceCalculationLess: null,
  cboCreditRefinanceCalculationBasisStart: null,
  cboCreditRefinanceCalculationBasisEnd: null,

  lblCreditRebateElement: null,
  cboCreditElement: null,

  //   GL Accounts
  cboGlAccount: null,
  cboWTaxGlAccount: null,
  cboImpCreditsGlAccount: null,

  lblGlSummaryType: null,
  cboElementGlInterfaceSummaryType: null,

  lblAccountingLedgers: null,
  cboAccountingLedgerType: null,
  cboAccountingLedgerMethod: null,
  numAccountingLedgerLess: null,
  chkAccountingLedgerGlEomSplit: null,
  chkAccountingLedgerIncludeOpeningInReports: null,

  lblAccountingLedgerGlAccount: null,
  cboUnearnedGlAccount: null,

  //   Authorisation
  chkAuthoriseTransactions: null,
  lblPermissionKeyAuthorise: null,
  cboPermissionKeyAuthorise: 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.txtElementId = widget.UI.TextBox("txtElementId", {
    allowBlank: false,
    maxLength: 20,
    width: widget.UI.FIELD_WIDTH_CODE_20,
  });
  C.chkActive = widget.UI.CheckBox("chkActive", {
    caption: "Active?",
  });
  C.txtDescription = widget.UI.TextBox("txtDescription", {
    allowBlank: false,
    maxLength: 50,
  });

  C.cboElementType = widget.UI.ComboBox("cboElementType", {
    allowBlank: false,
    limitToList: true,
    width: "14em",

    onChange: cboElementType_Change,
  });
  C.chkIsDefaultFee = widget.UI.CheckBox("chkIsDefaultFee", {
    caption: "Default Fee?",
  });
  C.cboCategory = widget.UI.InformationListComboBox("cboCategory", {
    maxLength: 50,
  });

  C.cboAllocationType = widget.UI.ComboBox("cboAllocationType", {
    allowBlank: false,
    limitToList: true,
    width: "14em",
  });
  C.chkIsIncome = widget.UI.CheckBox("chkIsIncome", {
    caption: "Include as Income?",
  });
  C.chkAmlRevenue = widget.UI.CheckBox("chkAmlRevenue", {
    caption: "Include as revenue for AML Reporting?",
  });
  C.chkDueImmediately = widget.UI.CheckBox("chkDueImmediately", {
    caption: "Is payment due immediately?",

    onChange: chkDueImmediately_Change,
  });
  C.chkDueImmediatelyDirectDebit = widget.UI.CheckBox("chkDueImmediatelyDirectDebit", {
    caption: "Direct Debit immediately?",
  });
  C.chkUserFlagA = widget.UI.CheckBox("chkUserFlagA", {});
  C.chkUserFlagB = widget.UI.CheckBox("chkUserFlagB", {});

  C.lblComparisonRateOptions = widget.UI.Label("lblComparisonRateOptions", {});
  C.chkComparisonRateCapitalise = widget.UI.CheckBox("chkComparisonRateCapitalise", {
    caption: "Capitalise values?",

    onChange: chkComparisonRateCapitalise_Change,
  });
  C.txtComparisonRateRegions = widget.UI.TextBox("txtComparisonRateRegions", {
    maxLength: 100,

    onButtonClick: txtComparisonRateRegions_ButtonClick,
  });
  C.txtComparisonRateRegions.ButtonsDefine([{ id: "Lookup", icon: "Find", tooltipText: "Find" }]);

  //   Options
  C.cboColourForeground = widget.UI.ColourChooserComboBox("cboColourForeground", {
    width: "12em",

    onChange: divPreview_Refresh,
  });
  C.cboColourBackground = widget.UI.ColourChooserComboBox("cboColourBackground", {
    width: "12em",

    onChange: divPreview_Refresh,
  });
  C.divPreview = $("#divPreview");

  C.lblGst = widget.UI.Label("lblGst", {});
  C.cboGstCode = widget.UI.InformationListComboBox("cboGstCode", {
    limitToList: true,
    width: "7em",
  });
  C.numGstRate = widget.UI.NumberBox("numGstRate", {
    decimals: 4,
    maxValue: 100,
    minValue: 0,
    percentage: true,
    width: "7em",
  });

  //   Defaults
  C.cboTransactionReference = widget.UI.ComboBox("cboTransactionReference", {
    maxLength: 20,
  });
  C.numTransactionValue = widget.UI.NumberBox("numTransactionValue", {
    decimals: -1,
    maxValue: 999999999999999,
    minValue: 0,
  });
  C.txtTransactionNotes = widget.UI.TextBox("txtTransactionNotes", {
    maxLength: 255,
    multiLine: true,
    rows: 3,
  });

  C.cboDateAdjustBasis = widget.UI.ComboBox("cboDateAdjustBasis", {
    allowBlank: false,
    limitToList: true,
    width: "15em",
  });
  C.cboStandardTransactionProcessScript = widget.UI.DBCombo("cboStandardTransactionProcessScript", {
    formKeyOpen: "Scripts",
    maxLength: 10,
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });

  C.lblAllowChangePermissionKey = widget.UI.Label("lblAllowChangePermissionKey", {});
  C.cboPermissionKeyAllowChange = widget.UI.PermissionKeyComboBox("cboPermissionKeyAllowChange", {
  });

  //   Disbursements
  C.lblDisbursementType = widget.UI.Label("lblDisbursementType", {});
  C.cboDisbursementType = widget.UI.ComboBox("cboDisbursementType", {
    allowBlank: false,
    limitToList: true,
    width: "15em",

    onChange: cboDisbursementType_Change,
  });
  C.cboDisbursementElement = widget.UI.DBCombo("cboDisbursementElement", {
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });
  C.txtDisbursementKey = widget.UI.TextBox("txtDisbursementKey", {
    maxLength: 10,
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });

  C.lblDisbursementPayeeDetails = widget.UI.Label("lblDisbursementPayeeDetails", {});
  C.cboDisbursementPayeeType = widget.UI.ComboBox("cboDisbursementPayeeType", {
    allowBlank: false,
    limitToList: true,
    width: "15em",

    onChange: cboDisbursementPayeeType_Change,
  });
  C.cboDisbursementPayeeExternalParty = widget.UI.DBCombo("cboDisbursementPayeeExternalParty", {
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });
  C.chkDisbursementPayeeAllowUpdates = widget.UI.CheckBox("chkDisbursementPayeeAllowUpdates", {
    caption: "Allow payee to be overridden?",
  });
  C.chkDisbursementConsolidate = widget.UI.CheckBox("chkDisbursementConsolidate", {
    caption: "Consolidate Disbursements?",
  });

  C.lblDisbursementExternalPartyCategories = widget.UI.Label("lblDisbursementExternalPartyCategories", {});
  C.txtDisbursementPayeeExternalPartyCategories = widget.UI.TextBox("txtDisbursementPayeeExternalPartyCategories", {
    maxLength: 100,
  });

  C.lblDisburseValues = widget.UI.Label("lblDisburseValues", {});
  C.cboDisbursementValueBasis = widget.UI.ComboBox("cboDisbursementValueBasis", {
    allowBlank: false,
    limitToList: true,
    width: "15em",

    onChange: cboDisbursementValueBasis_Change,
  });
  C.numDisbursementValueCurrency = widget.UI.NumberBox("numDisbursementValueCurrency", {
    decimals: -1,
    maxValue: 999999999999999,
    minValue: -999999999999999,
  });
  C.numDisbursementValuePercent = widget.UI.NumberBox("numDisbursementValuePercent", {
    decimals: 4,
    maxValue: 100,
    minValue: 0,
    percentage: true,
    width: "7em",
  });

  C.lblCommission = widget.UI.Label("lblCommission", {});
  C.cboCommissionElement = widget.UI.DBCombo("cboCommissionElement", {
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });

  //   Credit
  C.lblCreditCalculationMethod = widget.UI.Label("lblCreditCalculationMethod", {});
  C.chkCreditAllow = widget.UI.CheckBox("chkCreditAllow", {
    caption: "Allow credit (rebate) when Account closed?",

    onChange: chkCreditAllow_Change,
  });
  C.cboCreditCalculationMethod = widget.UI.ComboBox("cboCreditCalculationMethod", {
    allowBlank: false,
    limitToList: true,
    width: "15em",

    onChange: cboCreditCalculationMethod_Change,
  });
  C.numCreditCalculationLess = widget.UI.NumberBox("numCreditCalculationLess", {
    decimals: 2,
    percentage: true,
    maxValue: 100,
    minValue: 0,
  });
  C.cboCreditCalculationBasisStart = widget.UI.ComboBox("cboCreditCalculationBasisStart", {
    allowBlank: false,
    limitToList: true,
    width: "15em",
  });
  C.cboCreditCalculationBasisEnd = widget.UI.ComboBox("cboCreditCalculationBasisEnd", {
    allowBlank: false,
    limitToList: true,
    width: "15em",
  });

  C.lblCreditRebateRefinance = widget.UI.Label("lblCreditRebateRefinance", {});
  C.cboCreditRefinanceOption = widget.UI.ComboBox("cboCreditRefinanceOption", {
    allowBlank: false,
    limitToList: true,
    width: "15em",

    onChange: cboCreditRefinanceOption_Change,
  });
  C.cboCreditRefinanceCalculationMethod = widget.UI.ComboBox("cboCreditRefinanceCalculationMethod", {
    allowBlank: false,
    limitToList: true,
    width: "15em",

    onChange: cboCreditRefinanceCalculationMethod_Change,
  });
  C.numCreditRefinanceCalculationLess = widget.UI.NumberBox("numCreditRefinanceCalculationLess", {
    decimals: 2,
    percentage: true,
    maxValue: 100,
    minValue: 0,
  });
  C.cboCreditRefinanceCalculationBasisStart = widget.UI.ComboBox("cboCreditRefinanceCalculationBasisStart", {
    allowBlank: false,
    limitToList: true,
    width: "15em",
  });
  C.cboCreditRefinanceCalculationBasisEnd = widget.UI.ComboBox("cboCreditRefinanceCalculationBasisEnd", {
    allowBlank: false,
    limitToList: true,
    width: "15em",
  });

  C.lblCreditRebateElement = widget.UI.Label("lblCreditRebateElement", {});
  C.cboCreditElement = widget.UI.DBCombo("cboCreditElement", {
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });

  //   GL Accounts
  C.cboGlAccount = widget.UI.DBCombo("cboGlAccount", {
    formKeyOpen: "GlAccounts",
    width: widget.UI.FIELD_WIDTH_CODE_20,
  });
  C.cboWTaxGlAccount = widget.UI.DBCombo("cboWTaxGlAccount", {
    formKeyOpen: "GlAccounts",
    width: widget.UI.FIELD_WIDTH_CODE_20,
  });
  C.cboImpCreditsGlAccount = widget.UI.DBCombo("cboImpCreditsGlAccount", {
    formKeyOpen: "GlAccounts",
    width: widget.UI.FIELD_WIDTH_CODE_20,
  });

  C.lblGlSummaryType = widget.UI.Label("lblGlSummaryType", {});
  C.cboElementGlInterfaceSummaryType = widget.UI.ComboBox("cboElementGlInterfaceSummaryType", {
    allowBlank: false,
    limitToList: true,
    width: "15em",
  });

  C.lblAccountingLedgers = widget.UI.Label("lblAccountingLedgers", {});
  C.cboAccountingLedgerType = widget.UI.ComboBox("cboAccountingLedgerType", {
    allowBlank: false,
    limitToList: true,
    width: "15em",

    onChange: cboAccountingLedgerType_Change,
  });
  C.cboAccountingLedgerMethod = widget.UI.ComboBox("cboAccountingLedgerMethod", {
    allowBlank: false,
    limitToList: true,
    width: "15em",

    onChange: cboAccountingLedgerMethod_Change,
  });
  C.numAccountingLedgerLess = widget.UI.NumberBox("numAccountingLedgerLess", {
    decimals: 2,
    percentage: true,
    maxValue: 100,
    minValue: 0,
  });
  C.chkAccountingLedgerGlEomSplit = widget.UI.CheckBox("chkAccountingLedgerGlEomSplit", {
    caption: "Split and apportion Journals at month end?",
  });
  C.chkAccountingLedgerIncludeOpeningInReports = widget.UI.CheckBox("chkAccountingLedgerIncludeOpeningInReports", {
    caption: "Include Opening entries in Income Reports?",
  });

  C.lblAccountingLedgerGlAccount = widget.UI.Label("lblAccountingLedgerGlAccount", {});
  C.cboUnearnedGlAccount = widget.UI.DBCombo("cboUnearnedGlAccount", {
    formKeyOpen: "GlAccounts",
    width: widget.UI.FIELD_WIDTH_CODE_20,
  });

  //   Authorisation
  C.chkAuthoriseTransactions = widget.UI.CheckBox("chkAuthoriseTransactions", {
    caption: "Transactions require authorisation?",

    onChange: chkAuthoriseTransactions_Change,
  });

  C.lblPermissionKeyAuthorise = widget.UI.Label("lblPermissionKeyAuthorise", {});
  C.cboPermissionKeyAuthorise = widget.UI.PermissionKeyComboBox("cboPermissionKeyAuthorise", {
  });

  // 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);

  // 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);
  if (!mRecord.AllowPageDefaults) tabDetails.TabVisible("Defaults", false);
  if (!mRecord.AllowPageDisbursements) tabDetails.TabVisible("Disbursements", false);
  if (!mRecord.AllowPageCredit) tabDetails.TabVisible("Credit", false);
  if (!mRecord.AllowPageGlAccounts) tabDetails.TabVisible("GlAccounts", false);
  if (!mRecord.AllowPageAuthorisation) tabDetails.TabVisible("Authorisation", 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.txtElementId.Text(mRecord.ElementId);
    C.chkActive.Value(mRecord.Active);
    C.txtDescription.Text(mRecord.Description);

    C.cboElementType.Text(mRecord.ElementTypeText);
    C.chkIsDefaultFee.Value(mRecord.IsDefaultFee);
    C.cboCategory.Text(mRecord.Category);

    C.cboAllocationType.Text(mRecord.AllocationTypeText);
    C.chkIsIncome.Value(mRecord.IsIncome);
    C.chkAmlRevenue.Value(mRecord.AmlRevenue);
    C.chkDueImmediately.Value(mRecord.DueImmediately);
    C.chkDueImmediatelyDirectDebit.Value(mRecord.DueImmediatelyDirectDebit);
    C.chkUserFlagA.Value(mRecord.UserFlagA);
    C.chkUserFlagB.Value(mRecord.UserFlagB);

    C.chkComparisonRateCapitalise.Value(mRecord.ComparisonRateCapitalise);
    C.txtComparisonRateRegions.Text(mRecord.ComparisonRateRegions);

    // Options
    C.cboColourBackground.Text(mRecord.ColourBackground);
    C.cboColourForeground.Text(mRecord.ColourForeground);

    C.cboGstCode.Text(mRecord.GstCode);
    C.numGstRate.Value(mRecord.GstRate);

    // Defaults
    C.cboTransactionReference.Text(mRecord.TransactionReference);
    C.numTransactionValue.Value(mRecord.TransactionValue);
    C.txtTransactionNotes.Text(mRecord.TransactionNotes);

    C.cboDateAdjustBasis.Text(mRecord.DateAdjustBasisText);
    C.cboStandardTransactionProcessScript.Text(mRecord.StandardTransactionProcessScriptId);

    C.cboPermissionKeyAllowChange.Text(mRecord.PermissionKeyAllowChange);

    // Disbursements
    C.cboDisbursementType.Text(mRecord.DisbursementTypeText);
    C.cboDisbursementElement.Text(mRecord.DisbursementElementId);
    C.txtDisbursementKey.Text(mRecord.DisbursementKey);

    C.cboDisbursementPayeeType.Text(mRecord.DisbursementPayeeTypeText);
    C.cboDisbursementPayeeExternalParty.Text(mRecord.DisbursementPayeeExternalPartyId);
    C.txtDisbursementPayeeExternalPartyCategories.Text(mRecord.DisbursementPayeeExternalPartyCategories);
    C.chkDisbursementPayeeAllowUpdates.Value(mRecord.DisbursementPayeeAllowUpdates);
    C.chkDisbursementConsolidate.Value(mRecord.DisbursementConsolidate);

    C.cboDisbursementValueBasis.Text(mRecord.DisbursementBasisText);
    C.numDisbursementValueCurrency.Value(mRecord.DisbursementRateCurrency);
    C.numDisbursementValuePercent.Value(mRecord.DisbursementRatePercent);

    C.cboCommissionElement.Text(mRecord.CommissionElementId);

    // Credit
    C.chkCreditAllow.Value(mRecord.CreditAllow);
    C.cboCreditCalculationMethod.Text(mRecord.CreditCalculationMethodText);
    C.numCreditCalculationLess.Value(mRecord.CreditCalculationLess);
    C.cboCreditCalculationBasisStart.Text(mRecord.CreditCalculationBasisStartText);
    C.cboCreditCalculationBasisEnd.Text(mRecord.CreditCalculationBasisEndText);

    C.cboCreditRefinanceOption.Text(mRecord.CreditRefinanceOptionText);
    C.cboCreditRefinanceCalculationMethod.Text(mRecord.CreditRefinanceCalculationMethodText);
    C.numCreditRefinanceCalculationLess.Value(mRecord.CreditRefinanceCalculationLess);
    C.cboCreditRefinanceCalculationBasisStart.Text(mRecord.CreditRefinanceCalculationBasisStartText);
    C.cboCreditRefinanceCalculationBasisEnd.Text(mRecord.CreditRefinanceCalculationBasisEndText);

    C.cboCreditElement.Text(mRecord.CreditElementId);

    // GL Accounts
    C.cboGlAccount.Text(mRecord.GlAccountId);
    C.cboWTaxGlAccount.Text(mRecord.WTaxGlAccountId);
    C.cboImpCreditsGlAccount.Text(mRecord.ImpCreditsGlAccountId);

    C.cboElementGlInterfaceSummaryType.Text(mRecord.GlSummaryTypeText);

    C.cboAccountingLedgerType.Text(mRecord.AccountingLedgerTypeText);
    C.cboAccountingLedgerMethod.Text(mRecord.AccountingLedgerMethodText);
    C.numAccountingLedgerLess.Value(mRecord.AccountingLedgerLess);
    C.chkAccountingLedgerGlEomSplit.Value(mRecord.AccountingLedgerGlEomSplit);
    C.chkAccountingLedgerIncludeOpeningInReports.Value(mRecord.AccountingLedgerIncludeOpeningInReports);

    C.cboUnearnedGlAccount.Text(mRecord.UnearnedGlAccountId);

    // Authorisation
    C.chkAuthoriseTransactions.Value(mRecord.AuthoriseTransactions);
    C.cboPermissionKeyAuthorise.Text(mRecord.PermissionKeyAuthorise);
  }

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

  // Update Controls

  // Update fields
  Fields_Update();

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

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

  mRecord.ElementTypeText = C.cboElementType.Text();
  mRecord.IsDefaultFee = C.chkIsDefaultFee.Value();
  mRecord.Category = C.cboCategory.Text();

  mRecord.AllocationTypeText = C.cboAllocationType.Text();
  mRecord.IsIncome = C.chkIsIncome.Value();
  mRecord.AmlRevenue = C.chkAmlRevenue.Value();
  mRecord.DueImmediately = C.chkDueImmediately.Value();
  mRecord.DueImmediatelyDirectDebit = C.chkDueImmediatelyDirectDebit.Value();
  mRecord.UserFlagA = C.chkUserFlagA.Value();
  mRecord.UserFlagB = C.chkUserFlagB.Value();

  mRecord.ComparisonRateCapitalise = C.chkComparisonRateCapitalise.Value();
  mRecord.ComparisonRateRegions = C.txtComparisonRateRegions.Text();

  // Options
  mRecord.ColourBackground = C.cboColourBackground.Text();
  mRecord.ColourForeground = C.cboColourForeground.Text();

  mRecord.GstCode = C.cboGstCode.Text();
  mRecord.GstRate = C.numGstRate.Value();

  // Defaults
  mRecord.TransactionReference = C.cboTransactionReference.Text();
  mRecord.TransactionValue = C.numTransactionValue.Value();
  mRecord.TransactionNotes = C.txtTransactionNotes.Text();

  mRecord.DateAdjustBasisText = C.cboDateAdjustBasis.Text();
  mRecord.StandardTransactionProcessScriptId = C.cboStandardTransactionProcessScript.Text();

  mRecord.PermissionKeyAllowChange = C.cboPermissionKeyAllowChange.Text();

  // Disbursements
  mRecord.DisbursementTypeText = C.cboDisbursementType.Text();
  mRecord.DisbursementElementId = C.cboDisbursementElement.Text();
  mRecord.DisbursementKey = C.txtDisbursementKey.Text();

  mRecord.DisbursementPayeeTypeText = C.cboDisbursementPayeeType.Text();
  mRecord.DisbursementPayeeExternalPartyId = C.cboDisbursementPayeeExternalParty.Text();
  mRecord.DisbursementPayeeExternalPartyCategories = C.txtDisbursementPayeeExternalPartyCategories.Text();
  mRecord.DisbursementPayeeAllowUpdates = C.chkDisbursementPayeeAllowUpdates.Value();
  mRecord.DisbursementConsolidate = C.chkDisbursementConsolidate.Value();

  mRecord.DisbursementBasisText = C.cboDisbursementValueBasis.Text();
  mRecord.DisbursementRateCurrency = C.numDisbursementValueCurrency.Value();
  mRecord.DisbursementRatePercent = C.numDisbursementValuePercent.Value();

  mRecord.CommissionElementId = C.cboCommissionElement.Text();

  // Credit
  mRecord.CreditAllow = C.chkCreditAllow.Value();
  mRecord.CreditCalculationMethodText = C.cboCreditCalculationMethod.Text();
  mRecord.CreditCalculationLess = C.numCreditCalculationLess.Value();
  mRecord.CreditCalculationBasisStartText = C.cboCreditCalculationBasisStart.Text();
  mRecord.CreditCalculationBasisEndText = C.cboCreditCalculationBasisEnd.Text();

  mRecord.CreditRefinanceOptionText = C.cboCreditRefinanceOption.Text();
  mRecord.CreditRefinanceCalculationMethodText = C.cboCreditRefinanceCalculationMethod.Text();
  mRecord.CreditRefinanceCalculationLess = C.numCreditRefinanceCalculationLess.Value();
  mRecord.CreditRefinanceCalculationBasisStartText = C.cboCreditRefinanceCalculationBasisStart.Text();
  mRecord.CreditRefinanceCalculationBasisEndText = C.cboCreditRefinanceCalculationBasisEnd.Text();

  mRecord.CreditElementId = C.cboCreditElement.Text();

  // GL Accounts
  mRecord.GlAccountId = C.cboGlAccount.Text();
  mRecord.WTaxGlAccountId = C.cboWTaxGlAccount.Text();
  mRecord.ImpCreditsGlAccountId = C.cboImpCreditsGlAccount.Text();

  mRecord.GlSummaryTypeText = C.cboElementGlInterfaceSummaryType.Text();

  mRecord.AccountingLedgerTypeText = C.cboAccountingLedgerType.Text();
  mRecord.AccountingLedgerMethodText = C.cboAccountingLedgerMethod.Text();
  mRecord.AccountingLedgerLess = C.numAccountingLedgerLess.Value();
  mRecord.AccountingLedgerGlEomSplit = C.chkAccountingLedgerGlEomSplit.Value();
  mRecord.AccountingLedgerIncludeOpeningInReports = C.chkAccountingLedgerIncludeOpeningInReports.Value();

  mRecord.UnearnedGlAccountId = C.cboUnearnedGlAccount.Text();

  // Authorisation
  mRecord.AuthoriseTransactions = C.chkAuthoriseTransactions.Value();
  mRecord.PermissionKeyAuthorise = C.cboPermissionKeyAuthorise.Text();
}

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

  // Information Lists
  if (mRecord) {
    C.cboCategory.SetComboFromInformationList("ElementCategories");
    C.cboGstCode.SetComboFromInformationList("GSTCodes");
  }

  // Lists
  if (mRecord) {
    // General
    C.cboElementType.ListFromCollection(mRecord.ElementTypeList, "Description");
    C.cboAllocationType.ListFromCsvString(mRecord.ListAllocationTypeAll); // NOTE: This is updated in cboElementType_Change

    // Defaults
    C.cboTransactionReference.ListFromCsvString("[Seq],[User]");
    C.cboDateAdjustBasis.ListFromCsvString(mRecord.ListDateAdjustBasis);
    C.cboStandardTransactionProcessScript.RefreshFromStandardRange("Scripts", mRecord.StandardTransactionProcessScriptFilter);

    // Disbursements
    // NOTE: Other lists set in pageDisburesement_Refresh
    C.cboDisbursementType.ListFromCollection(mRecord.DisbursementTypeList, "Description");
    C.cboDisbursementElement.RefreshFromStandardRange("Elements", mRecord.DisbursementElementFilter);
    C.cboCommissionElement.RefreshFromStandardRange("Elements", mRecord.DisbursementElementFilter);
    C.cboDisbursementValueBasis.ListFromCollection(mRecord.DisbursementValueBasisList, "Description");

    // Credit
    C.cboCreditCalculationMethod.ListFromCollection(mRecord.CreditCalculationMethodList, "Description");
    C.cboCreditCalculationBasisStart.ListFromCsvString(mRecord.ListCreditCalculationBasisStart);
    C.cboCreditCalculationBasisEnd.ListFromCsvString(mRecord.ListCreditCalculationBasisEnd);
    C.cboCreditRefinanceOption.ListFromCollection(mRecord.CreditRefinanceOptionList, "Description");
    C.cboCreditRefinanceCalculationMethod.ListFromCollection(mRecord.CreditCalculationMethodList, "Description");
    C.cboCreditRefinanceCalculationBasisStart.ListFromCsvString(mRecord.ListCreditCalculationBasisStart);
    C.cboCreditRefinanceCalculationBasisEnd.ListFromCsvString(mRecord.ListCreditCalculationBasisEnd);
    //C.cboCreditElement.RefreshFromStandardRange("Elements", mRecord.CreditElementFilter);

    // GL Accounts
    C.cboGlAccount.RefreshFromStandardRange("GlAccounts");
    C.cboWTaxGlAccount.RefreshFromStandardRange("GlAccounts");
    C.cboImpCreditsGlAccount.RefreshFromStandardRange("GlAccounts");
    C.cboElementGlInterfaceSummaryType.ListFromCsvString(mRecord.ListGlInterfaceSummaryType);
    C.cboAccountingLedgerType.ListFromCollection(mRecord.AccountingLedgerTypeList, "Description");
    C.cboAccountingLedgerMethod.ListFromCollection(mRecord.AccountingLedgerMethodList, "Description");
    C.cboUnearnedGlAccount.RefreshFromStandardRange("GlAccounts");
  }

  // Controls
  if (mRecord) {
    // General
    C.chkUserFlagA.Caption(mRecord.UserFlagACaption);
    C.chkUserFlagB.Caption(mRecord.UserFlagBCaption);

    // Options
    if (mRecord.UseGst) {
      C.lblGst.Text(mRecord.GstName + " Code and Rate");
      C.cboGstCode.Caption(mRecord.GstNameShort + " Code:");
      C.numGstRate.Caption(mRecord.GstNameShort + " Rate:");
    }
    else {
      C.lblGst.VisibleRow(false);
      C.cboGstCode.VisibleRow(false);
      C.numGstRate.VisibleRow(false);
    }

    // Authorisation
    chkAuthoriseTransactions_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"
    pageGeneral_Refresh();
    pageOptions_Refresh();
    pageDefaults_Refresh();
    pageDisbursements_Refresh();
    pageCredit_Refresh();
    pageGlAccounts_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();
      break;

    case "Options":
      // Options
      break;

    case "Defaults":
      // Defaults
      C.cboTransactionReference.WidthResizeFromParent();
      C.numTransactionValue.WidthResizeFromParent();
      C.txtTransactionNotes.WidthResizeFromParent();
      break;
  }
}

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

    case "Options":
      pageOptions_Refresh();
      break;

    case "Defaults":
      pageDefaults_Refresh();
      break;

    case "Disbursements":
      pageDisbursements_Refresh();
      break;

    case "Credit":
      pageCredit_Refresh();
      break;

    case "GlAccounts":
      pageGlAccounts_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 Record Id just in case this has changed
      widget.RefreshParent(C.txtElementId.Text());
    },

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

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

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

  // Get Element Type
  var ElementType = "Journal";
  if (C.cboElementType.ListIndex() != -1) ElementType = mRecord.ElementTypeList[C.cboElementType.ListIndex()].ElementType;

  // Controls
  switch (ElementType) {
    case "Advance":
    case "Deposit":
      // Advance/ Deposit
      C.chkIsDefaultFee.Visible(false);
      C.cboAllocationType.ListFromCsvString(mRecord.ListAllocationTypeExcludeInterest);
      C.cboAllocationType.ReadOnly(false);
      C.cboAllocationType.VisibleRow(true);
      C.chkIsIncome.VisibleRow(false);
      C.chkAmlRevenue.VisibleRow(false);
      C.chkDueImmediately.VisibleRow(false);
      C.chkDueImmediatelyDirectDebit.VisibleRow(false);

      C.lblComparisonRateOptions.VisibleRow(false);
      C.chkComparisonRateCapitalise.VisibleRow(false);
      C.txtComparisonRateRegions.VisibleRow(false);
      break;

    case "Cost":
      // Cost
      C.chkIsDefaultFee.Visible(false);
      C.cboAllocationType.ListFromCsvString(mRecord.ListAllocationTypeExcludeInterest);
      C.cboAllocationType.ReadOnly(false);
      C.cboAllocationType.VisibleRow(true);
      C.chkIsIncome.VisibleRow(true);
      C.chkAmlRevenue.VisibleRow(true);
      C.chkDueImmediately.VisibleRow(false);
      C.chkDueImmediatelyDirectDebit.VisibleRow(false);

      C.lblComparisonRateOptions.VisibleRow(true);
      C.chkComparisonRateCapitalise.VisibleRow(true);
      C.txtComparisonRateRegions.VisibleRow(C.chkComparisonRateCapitalise.Value());
      break;

    case "Disbursement":
      // Disbursement
      C.chkIsDefaultFee.Visible(false);
      C.cboAllocationType.ListFromCsvString(mRecord.ListAllocationTypeExcludeInterest);
      C.cboAllocationType.ReadOnly(false);
      C.cboAllocationType.VisibleRow(true);
      C.chkIsIncome.VisibleRow(true);
      C.chkAmlRevenue.VisibleRow(true);
      C.chkDueImmediately.VisibleRow(false);
      C.chkDueImmediatelyDirectDebit.VisibleRow(false);

      C.lblComparisonRateOptions.VisibleRow(false);
      C.chkComparisonRateCapitalise.VisibleRow(false);
      C.txtComparisonRateRegions.VisibleRow(false);
      break;

    case "Fee":
      // Fee
      C.chkIsDefaultFee.Visible(true);
      C.cboAllocationType.ListFromCsvString(mRecord.ListAllocationTypeExcludeInterest);
      C.cboAllocationType.ReadOnly(false);
      C.cboAllocationType.VisibleRow(true);
      C.chkIsIncome.VisibleRow(true);
      C.chkAmlRevenue.VisibleRow(true);
      C.chkDueImmediately.VisibleRow(true);
      C.chkDueImmediatelyDirectDebit.VisibleRow(C.chkDueImmediately.Value());

      C.lblComparisonRateOptions.VisibleRow(true);
      C.chkComparisonRateCapitalise.VisibleRow(true);
      C.txtComparisonRateRegions.VisibleRow(C.chkComparisonRateCapitalise.Value());
      break;

    case "Interest":
      // Interest
      C.chkIsDefaultFee.Visible(false);
      C.cboAllocationType.ListFromCsvString("Interest");
      C.cboAllocationType.Text("Interest");
      C.cboAllocationType.ReadOnly(true);
      C.cboAllocationType.VisibleRow(true);
      C.chkIsIncome.VisibleRow(false);
      C.chkAmlRevenue.VisibleRow(true);
      C.chkDueImmediately.VisibleRow(false);
      C.chkDueImmediatelyDirectDebit.VisibleRow(false);

      C.lblComparisonRateOptions.VisibleRow(false);
      C.chkComparisonRateCapitalise.VisibleRow(false);
      C.txtComparisonRateRegions.VisibleRow(false);
      break;

    case "InterestDefault":
      // Default Interest
      C.chkIsDefaultFee.Visible(false);
      C.cboAllocationType.ListFromCsvString("Interest");
      C.cboAllocationType.Text("Interest");
      C.cboAllocationType.ReadOnly(true);
      C.cboAllocationType.VisibleRow(true);
      C.chkIsIncome.VisibleRow(false);
      C.chkAmlRevenue.VisibleRow(true);
      C.chkDueImmediately.VisibleRow(true);
      C.chkDueImmediatelyDirectDebit.VisibleRow(C.chkDueImmediately.Value());

      C.lblComparisonRateOptions.VisibleRow(false);
      C.chkComparisonRateCapitalise.VisibleRow(false);
      C.txtComparisonRateRegions.VisibleRow(false);
      break;

    case "InterestPayout":
      // Interest Payout
      C.chkIsDefaultFee.Visible(false);
      C.cboAllocationType.ListFromCsvString("Interest");
      C.cboAllocationType.Text("Interest");
      C.cboAllocationType.ReadOnly(true);
      C.cboAllocationType.VisibleRow(true);
      C.chkIsIncome.VisibleRow(false);
      C.chkAmlRevenue.VisibleRow(false);
      C.chkDueImmediately.VisibleRow(false);
      C.chkDueImmediatelyDirectDebit.VisibleRow(false);

      C.lblComparisonRateOptions.VisibleRow(false);
      C.chkComparisonRateCapitalise.VisibleRow(false);
      C.txtComparisonRateRegions.VisibleRow(false);
      break;

    case "Investment":
    case "InvestmentAdditional":
      // Investment/ Additional Investment
      C.chkIsDefaultFee.Visible(false);
      C.cboAllocationType.ListFromCsvString(mRecord.ListAllocationTypeExcludeInterest);
      C.cboAllocationType.ReadOnly(false);
      C.cboAllocationType.VisibleRow(true);
      C.chkIsIncome.VisibleRow(false);
      C.chkAmlRevenue.VisibleRow(false);
      C.chkDueImmediately.VisibleRow(false);
      C.chkDueImmediatelyDirectDebit.VisibleRow(false);

      C.lblComparisonRateOptions.VisibleRow(false);
      C.chkComparisonRateCapitalise.VisibleRow(false);
      C.txtComparisonRateRegions.VisibleRow(false);
      break;

    case "Journal":
      // Journal
      C.chkIsDefaultFee.Visible(false);
      C.cboAllocationType.ListFromCsvString(mRecord.ListAllocationTypeExcludeInterest);
      C.cboAllocationType.ReadOnly(false);
      C.cboAllocationType.VisibleRow(true);
      C.chkIsIncome.VisibleRow(true);
      C.chkAmlRevenue.VisibleRow(true);
      C.chkDueImmediately.VisibleRow(true);
      C.chkDueImmediatelyDirectDebit.VisibleRow(C.chkDueImmediately.Value());

      C.lblComparisonRateOptions.VisibleRow(true);
      C.chkComparisonRateCapitalise.VisibleRow(true);
      C.txtComparisonRateRegions.VisibleRow(C.chkComparisonRateCapitalise.Value());
      break;

    case "PaymentDue":
      // Payment Due
      C.chkIsDefaultFee.Visible(false);
      C.cboAllocationType.ListFromCsvString(mRecord.ListAllocationTypeExcludeInterest);
      C.cboAllocationType.ReadOnly(true);
      C.cboAllocationType.VisibleRow(false);
      C.chkIsIncome.VisibleRow(false);
      C.chkAmlRevenue.VisibleRow(false);
      C.chkDueImmediately.VisibleRow(false);
      C.chkDueImmediatelyDirectDebit.VisibleRow(false);

      C.lblComparisonRateOptions.VisibleRow(false);
      C.chkComparisonRateCapitalise.VisibleRow(false);
      C.txtComparisonRateRegions.VisibleRow(false);
      break;

    case "PaymentReceived":
      // Payment Received
      C.chkIsDefaultFee.Visible(false);
      C.cboAllocationType.ListFromCsvString(mRecord.ListAllocationTypeExcludeInterest);
      C.cboAllocationType.ReadOnly(true);
      C.cboAllocationType.VisibleRow(false);
      C.chkIsIncome.VisibleRow(false);
      C.chkAmlRevenue.VisibleRow(false);
      C.chkDueImmediately.VisibleRow(false);
      C.chkDueImmediatelyDirectDebit.VisibleRow(false);

      C.lblComparisonRateOptions.VisibleRow(false);
      C.chkComparisonRateCapitalise.VisibleRow(false);
      C.txtComparisonRateRegions.VisibleRow(false);
      break;

    case "Refinance":
      // Refinance
      C.chkIsDefaultFee.Visible(false);
      C.cboAllocationType.ListFromCsvString(mRecord.ListAllocationTypeExcludeInterest);
      C.cboAllocationType.ReadOnly(false);
      C.cboAllocationType.VisibleRow(true);
      C.chkIsIncome.VisibleRow(false);
      C.chkAmlRevenue.VisibleRow(false);
      C.chkDueImmediately.VisibleRow(false);
      C.chkDueImmediatelyDirectDebit.VisibleRow(false);

      C.lblComparisonRateOptions.VisibleRow(false);
      C.chkComparisonRateCapitalise.VisibleRow(false);
      C.txtComparisonRateRegions.VisibleRow(false);
      break;

    case "Refund":
      // Refund
      C.chkIsDefaultFee.Visible(false);
      C.cboAllocationType.ListFromCsvString(mRecord.ListAllocationTypeAll);
      C.cboAllocationType.ReadOnly(false);
      C.cboAllocationType.VisibleRow(true);
      C.chkIsIncome.VisibleRow(false);
      C.chkAmlRevenue.VisibleRow(false);
      C.chkDueImmediately.VisibleRow(true);
      C.chkDueImmediatelyDirectDebit.VisibleRow(C.chkDueImmediately.Value());

      C.lblComparisonRateOptions.VisibleRow(false);
      C.chkComparisonRateCapitalise.VisibleRow(false);
      C.txtComparisonRateRegions.VisibleRow(false);
      break;

    case "Transfer":
      // Transfer
      C.chkIsDefaultFee.Visible(false);
      C.cboAllocationType.ListFromCsvString(mRecord.ListAllocationTypeExcludeInterest);
      C.cboAllocationType.ReadOnly(false);
      C.cboAllocationType.VisibleRow(true);
      C.chkIsIncome.VisibleRow(false);
      C.chkAmlRevenue.VisibleRow(false);
      C.chkDueImmediately.VisibleRow(true);
      C.chkDueImmediatelyDirectDebit.VisibleRow(C.chkDueImmediately.Value());

      C.lblComparisonRateOptions.VisibleRow(false);
      C.chkComparisonRateCapitalise.VisibleRow(false);
      C.txtComparisonRateRegions.VisibleRow(false);
      break;

    case "Withdrawal":
      // Withdrawal
      C.chkIsDefaultFee.Visible(false);
      C.cboAllocationType.ListFromCsvString(mRecord.ListAllocationTypeExcludeInterest);
      C.cboAllocationType.ReadOnly(false);
      C.cboAllocationType.VisibleRow(true);
      C.chkIsIncome.VisibleRow(false);
      C.chkAmlRevenue.VisibleRow(false);
      C.chkDueImmediately.VisibleRow(true);
      C.chkDueImmediatelyDirectDebit.VisibleRow(C.chkDueImmediately.Value());

      C.lblComparisonRateOptions.VisibleRow(false);
      C.chkComparisonRateCapitalise.VisibleRow(false);
      C.txtComparisonRateRegions.VisibleRow(false);
      break;

    default:
      window.alert("Unhandled Element Type '" + ElementType + "'");
      break;
  }
  
  // Clear out invalid values
  if (C.cboAllocationType.Text() &amp;&amp; C.cboAllocationType.ListIndex() == -1) {
    C.cboAllocationType.Text("");
  }

  // Licensing
  if (!mRecord.AddOnBankingAdvanced) {
    C.chkDueImmediatelyDirectDebit.VisibleRow(false);
  }

  divPreview_Refresh();
}

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

// ============
// pageDefaults
// ============
function pageDefaults_Refresh() {
  if (!mRecord) return;

  // Get Element Type
  var ElementType = "Journal";
  if (C.cboElementType.ListIndex() != -1) ElementType = mRecord.ElementTypeList[C.cboElementType.ListIndex()].ElementType;

  // Controls
  switch (ElementType) {
    case "Advance":
    case "Deposit":
      // Advance/ Deposit
      C.cboStandardTransactionProcessScript.VisibleRow(true);
      break;

    case "Cost":
      // Cost
      C.cboStandardTransactionProcessScript.VisibleRow(true);
      break;

    case "Disbursement":
      // Disbursement
      C.cboStandardTransactionProcessScript.VisibleRow(false);
      break;

    case "Fee":
      // Fee
      C.cboStandardTransactionProcessScript.VisibleRow(true);
      break;

    case "Interest":
      // Interest
      C.cboStandardTransactionProcessScript.VisibleRow(false);
      break;

    case "InterestDefault":
      // Default Interest
      C.cboStandardTransactionProcessScript.VisibleRow(false);
      break;

    case "InterestPayout":
      // Interest Payout
      C.cboStandardTransactionProcessScript.VisibleRow(false);
      break;

    case "Investment":
    case "InvestmentAdditional":
      // Investment/ Additional Investment
      C.cboStandardTransactionProcessScript.VisibleRow(true);
      break;

    case "Journal":
      // Journal
      C.cboStandardTransactionProcessScript.VisibleRow(true);
      break;

    case "PaymentDue":
      // Payment Due
      C.cboStandardTransactionProcessScript.VisibleRow(false);
      break;

    case "PaymentReceived":
      // Payment Received
      C.cboStandardTransactionProcessScript.VisibleRow(true);
      break;

    case "Refinance":
      // Refinance
      C.cboStandardTransactionProcessScript.VisibleRow(false);
      break;

    case "Refund":
      // Refund
      C.cboStandardTransactionProcessScript.VisibleRow(false);
      break;

    case "Transfer":
      // Transfer
      C.cboStandardTransactionProcessScript.VisibleRow(true);
      break;

    case "Withdrawal":
      // Withdrawal
      C.cboStandardTransactionProcessScript.VisibleRow(true);
      break;

    default:
      window.alert("Unhandled Element Type '" + ElementType + "'");
      break;
  }
}

// =================
// pageDisbursements
// =================
function pageDisbursements_Refresh() {
  // Get Disbursement Type
  var DisbursementType = "None";
  if (C.cboDisbursementType.ListIndex() != -1) DisbursementType = mRecord.DisbursementTypeList[C.cboDisbursementType.ListIndex()].Code;

  // Get Element Type
  var ElementType = "Journal";
  if (C.cboElementType.ListIndex() != -1) ElementType = mRecord.ElementTypeList[C.cboElementType.ListIndex()].ElementType;

  // Controls
  switch (ElementType) {
    case "Disbursement":
      // Disbursement Element
      C.lblDisbursementType.VisibleRow(false);
      C.cboDisbursementType.VisibleRow(false);
      C.cboDisbursementElement.VisibleRow(false);
      C.txtDisbursementKey.VisibleRow(false);

      C.lblDisbursementPayeeDetails.VisibleRow(true);
      C.cboDisbursementPayeeType.VisibleRow(true);
      C.cboDisbursementPayeeType.ListFromCollection(mRecord.DisbursementPayeeTypeAllList, "Description");
      pageDisbursements_Refresh_PayeeType();

      C.lblDisbursementExternalPartyCategories.VisibleRow(true);
      C.txtDisbursementPayeeExternalPartyCategories.VisibleRow(true);

      C.lblDisburseValues.VisibleRow(false);
      C.cboDisbursementValueBasis.VisibleRow(false);
      C.numDisbursementValueCurrency.VisibleRow(false);
      C.numDisbursementValuePercent.VisibleRow(false);

      C.lblCommission.VisibleRow(false);
      C.cboCommissionElement.VisibleRow(false);
      break;

    default:
      // Non-Disbursement Element
      C.lblDisbursementType.VisibleRow(true);
      C.cboDisbursementType.VisibleRow(true);

      C.lblDisbursementExternalPartyCategories.VisibleRow(false);
      C.txtDisbursementPayeeExternalPartyCategories.VisibleRow(false);

      C.lblCommission.VisibleRow(true);
      C.cboCommissionElement.VisibleRow(true);

      switch (DisbursementType) {
        case "Cost":
        case "Recovery":
          // Cost/ Recovery
          C.cboDisbursementElement.VisibleRow(true);
          C.txtDisbursementKey.VisibleRow(true);

          C.lblDisbursementPayeeDetails.VisibleRow(true);
          C.cboDisbursementPayeeType.VisibleRow(true);
          C.cboDisbursementPayeeType.ListFromCollection(mRecord.DisbursementPayeeTypeAllList, "Description");
          pageDisbursements_Refresh_PayeeType();

          C.lblDisburseValues.VisibleRow(true);
          C.cboDisbursementValueBasis.VisibleRow(true);
          pageDisbursements_Refresh_ValueBasis();
          break;

        case "None":
          // None
          C.cboDisbursementElement.VisibleRow(false);
          C.txtDisbursementKey.VisibleRow(false);

          C.lblDisbursementPayeeDetails.VisibleRow(false);
          C.cboDisbursementPayeeType.VisibleRow(false);
          C.cboDisbursementPayeeExternalParty.VisibleRow(false);
          C.chkDisbursementPayeeAllowUpdates.VisibleRow(false);
          C.chkDisbursementConsolidate.VisibleRow(false);

          C.lblDisburseValues.VisibleRow(false);
          C.cboDisbursementValueBasis.VisibleRow(false);
          C.numDisbursementValueCurrency.VisibleRow(false);
          C.numDisbursementValuePercent.VisibleRow(false);
          break;

        case "Payout":
          // Payout
          C.cboDisbursementElement.VisibleRow(true);
          C.txtDisbursementKey.VisibleRow(true);

          C.lblDisbursementPayeeDetails.VisibleRow(true);
          C.cboDisbursementPayeeType.VisibleRow(true);
          C.cboDisbursementPayeeType.ListFromCollection(mRecord.DisbursementPayeeTypeNoBulkFunderList, "Description");
          pageDisbursements_Refresh_PayeeType();

          C.lblDisburseValues.VisibleRow(true);
          C.cboDisbursementValueBasis.VisibleRow(true);
          pageDisbursements_Refresh_ValueBasis();
          break;

        default:
          window.alert("Unhandled Disbursement Type '" + DisbursementType + "'");
          break;
      }
      break;
  }
}

function pageDisbursements_Refresh_PayeeType() {
  // Get Disbursement Type
  var DisbursementType = "None";
  if (C.cboDisbursementType.ListIndex() != -1) DisbursementType = mRecord.DisbursementTypeList[C.cboDisbursementType.ListIndex()].Code;

  // Get Element Type
  var ElementType = "Journal";
  if (C.cboElementType.ListIndex() != -1) ElementType = mRecord.ElementTypeList[C.cboElementType.ListIndex()].ElementType;

  // Get Payee Type
  // NOTE: More complicated than the usual method since this list varies and therefore the ListIndex will vary too
  var PayeeType = "None";
  if (C.cboDisbursementPayeeType.ListIndex() != -1) {
    if (DisbursementType == "Payout") {
      PayeeType = mRecord.DisbursementPayeeTypeNoBulkFunderList[C.cboDisbursementPayeeType.ListIndex()].Code;
    }
    else {
      PayeeType = mRecord.DisbursementPayeeTypeAllList[C.cboDisbursementPayeeType.ListIndex()].Code;
    }
  }

  // Controls
  if (PayeeType == "None") {
    C.cboDisbursementPayeeExternalParty.VisibleRow(false);
    C.chkDisbursementPayeeAllowUpdates.VisibleRow(false);
    C.chkDisbursementConsolidate.VisibleRow(false);    
  }
  else {
    if (PayeeType == "Account") {
      C.cboDisbursementPayeeExternalParty.VisibleRow(false);
    }
    else {
      C.cboDisbursementPayeeExternalParty.VisibleRow(true);
      C.cboDisbursementPayeeExternalParty.Caption(C.cboDisbursementPayeeType.Text() + ":");

      // Refresh list
      if (C.cboDisbursementPayeeExternalParty.Tag != PayeeType) {
        C.cboDisbursementPayeeExternalParty.Tag = PayeeType;

        var StandardRangeName = "ExternalParties" + PayeeType + "s";
        switch (PayeeType) {
          case "Other":
            StandardRangeName = "ExternalPartiesOther";
            break;
        }

        C.cboDisbursementPayeeExternalParty.RefreshFromStandardRange(StandardRangeName, "[DisbursementAccountPk]&lt;&gt;0");
      }
    }
    C.chkDisbursementPayeeAllowUpdates.VisibleRow(true);

    switch (ElementType) {
      case "Advance":
      case "Cost":
      case "Deposit":
      case "Fee":
      case "Journal":
        C.chkDisbursementConsolidate.VisibleRow(true);
        switch (PayeeType) {
          case "Account":
          case "None":
            C.chkDisbursementPayeeAllowUpdates.VisibleRow(false);
            break;
        }
        break;

      default:
        C.chkDisbursementConsolidate.VisibleRow(false);
        C.chkDisbursementPayeeAllowUpdates.VisibleRow(false);
        break;
    }
  }
}

function pageDisbursements_Refresh_ValueBasis() {
  // Get Value Bais
  var ValueBasis = "None";
  if (C.cboDisbursementValueBasis.ListIndex() != -1) ValueBasis = mRecord.DisbursementValueBasisList[C.cboDisbursementValueBasis.ListIndex()].Code;

  // Controls
  switch (ValueBasis) {
    case "Difference":
    case "SetValue":
      C.numDisbursementValueCurrency.VisibleRow(true);
      C.numDisbursementValuePercent.VisibleRow(false);
      break;

    case "Percentage":
      C.numDisbursementValueCurrency.VisibleRow(false);
      C.numDisbursementValuePercent.VisibleRow(true);
      break;

    default:
      C.numDisbursementValueCurrency.VisibleRow(false);
      C.numDisbursementValuePercent.VisibleRow(false);
      break;
  }
}

// ==========
// pageCredit
// ==========
function pageCredit_Refresh() {
  // Get Element Type Information
  var ElementTypeInfo = null;
  if (C.cboElementType.ListIndex() != -1) ElementTypeInfo = mRecord.ElementTypeList[C.cboElementType.ListIndex()];
  
  // Controls
  if (ElementTypeInfo) {
    C.cboCreditElement.RefreshFromStandardRange("Elements", ElementTypeInfo.CreditElementFilter, false, "", "ElementId,Description,ElementTypeText");
  }
  else {
    C.cboCreditElement.RefreshFromStandardRange("Elements", mRecord.CreditElementFilter, false, "", "ElementId,Description,ElementTypeText");
  }

  // Calculation for Close
  var CalculationMethod = "None";
  if (C.cboCreditCalculationMethod.ListIndex() != -1) CalculationMethod = mRecord.CreditCalculationMethodList[C.cboCreditCalculationMethod.ListIndex()].Code;

  if (C.chkCreditAllow.Value()) {
    C.cboCreditCalculationMethod.VisibleRow(true);
    C.lblCreditRebateElement.VisibleRow(true);
    C.cboCreditElement.VisibleRow(true);

    switch(CalculationMethod) {
      case "ContractualInterest":
        // Contractual Interest
        C.numCreditCalculationLess.VisibleRow(true);
        C.cboCreditCalculationBasisStart.VisibleRow(false);
        C.cboCreditCalculationBasisEnd.VisibleRow(false);
        break;

      case "None":
        // None
        C.numCreditCalculationLess.VisibleRow(false);
        C.cboCreditCalculationBasisStart.VisibleRow(false);
        C.cboCreditCalculationBasisEnd.VisibleRow(false);
        break;

      default:
        C.numCreditCalculationLess.VisibleRow(true);
        C.cboCreditCalculationBasisStart.VisibleRow(true);
        C.cboCreditCalculationBasisEnd.VisibleRow(true);
        break;
    }
  }
  else {
    C.cboCreditCalculationMethod.VisibleRow(false);
    C.numCreditCalculationLess.VisibleRow(false);
    C.cboCreditCalculationBasisStart.VisibleRow(false);
    C.cboCreditCalculationBasisEnd.VisibleRow(false);
    C.lblCreditRebateElement.VisibleRow(false);
    C.cboCreditElement.VisibleRow(false);
  }

  // Calculation for Refinance
  var RefinanceOption = "NotUsed";
  if (C.cboCreditRefinanceOption.ListIndex() != -1) RefinanceOption = mRecord.CreditRefinanceOptionList[C.cboCreditRefinanceOption.ListIndex()].Code;

  var RefinanceCalculationMethod = "None";
  if (C.cboCreditRefinanceCalculationMethod.ListIndex() != -1) RefinanceCalculationMethod = mRecord.CreditCalculationMethodList[C.cboCreditRefinanceCalculationMethod.ListIndex()].Code;

  switch (RefinanceOption) {
    case "AsPerClose":
    case "NotUsed":
      // As per Close/ Not Used
      C.cboCreditRefinanceCalculationMethod.VisibleRow(false);
      C.numCreditRefinanceCalculationLess.VisibleRow(false);
      C.cboCreditRefinanceCalculationBasisStart.VisibleRow(false);
      C.cboCreditRefinanceCalculationBasisEnd.VisibleRow(false);
      break;

    case "Overridden":
      // Overridden
      C.cboCreditRefinanceCalculationMethod.VisibleRow(true);
      C.lblCreditRebateElement.VisibleRow(true);
      C.cboCreditElement.VisibleRow(true);

      switch(RefinanceCalculationMethod) {
        case "ContractualInterest":
          // Contractual Interest
          C.numCreditRefinanceCalculationLess.VisibleRow(true);
          C.cboCreditRefinanceCalculationBasisStart.VisibleRow(false);
          C.cboCreditRefinanceCalculationBasisEnd.VisibleRow(false);
          break;

        case "None":
          // None
          C.numCreditRefinanceCalculationLess.VisibleRow(false);
          C.cboCreditRefinanceCalculationBasisStart.VisibleRow(false);
          C.cboCreditRefinanceCalculationBasisEnd.VisibleRow(false);
          break;

        default:
          C.numCreditRefinanceCalculationLess.VisibleRow(true);
          C.cboCreditRefinanceCalculationBasisStart.VisibleRow(true);
          C.cboCreditRefinanceCalculationBasisEnd.VisibleRow(true);
          break;
      }
      break;
  }

  // Licensing
  if (!mRecord.AddOnLoansAny) {
    C.lblCreditRebateRefinance.VisibleRow(false);
    C.cboCreditRefinanceOption.VisibleRow(false);
    C.cboCreditRefinanceCalculationMethod.VisibleRow(false);
    C.numCreditRefinanceCalculationLess.VisibleRow(false);
    C.cboCreditRefinanceCalculationBasisStart.VisibleRow(false);
    C.cboCreditRefinanceCalculationBasisEnd.VisibleRow(false);
  }
}

// ==============
// pageGlAccounts
// ==============
function pageGlAccounts_Refresh() {
  // Get Element Type
  var ElementType = "Journal";
  if (C.cboElementType.ListIndex() != -1) ElementType = mRecord.ElementTypeList[C.cboElementType.ListIndex()].ElementType;

  // Get Accounting Ledger Type
  var AccountingLedgerType = "None";
  if (C.cboAccountingLedgerType.ListIndex() != -1) AccountingLedgerType = mRecord.AccountingLedgerTypeList[C.cboAccountingLedgerType.ListIndex()].Code;

  // Controls
  switch(ElementType) {
    case "Cost":
    case "Disbursement":
    case "Fee":
    case "Interest":
    case "InterestDefault":
    case "Journal":
      C.lblAccountingLedgers.VisibleRow(true);
      C.cboAccountingLedgerType.VisibleRow(true);
      C.lblAccountingLedgerGlAccount.VisibleRow(true);
      C.cboUnearnedGlAccount.VisibleRow(true);

      switch(AccountingLedgerType) {
        case "AmortisationSchedule":
          C.cboAccountingLedgerMethod.VisibleRow(true);
          C.numAccountingLedgerLess.VisibleRow(true);
          C.chkAccountingLedgerGlEomSplit.VisibleRow(true);
          C.chkAccountingLedgerIncludeOpeningInReports.VisibleRow(true);
          pageGlAccounts_Refresh_Method();
          break;

        case "SimpleJournal":
          C.cboAccountingLedgerMethod.VisibleRow(false);
          C.numAccountingLedgerLess.VisibleRow(false);
          C.chkAccountingLedgerGlEomSplit.VisibleRow(true);
          C.chkAccountingLedgerIncludeOpeningInReports.VisibleRow(false);
          pageGlAccounts_Refresh_Method();
          break;

        default:
          C.cboAccountingLedgerMethod.VisibleRow(false);
          C.numAccountingLedgerLess.VisibleRow(false);
          C.chkAccountingLedgerGlEomSplit.VisibleRow(false);
          C.chkAccountingLedgerIncludeOpeningInReports.VisibleRow(false);
          break;
      }
      break;

    default:
      C.lblAccountingLedgers.VisibleRow(false);
      C.cboAccountingLedgerType.VisibleRow(false);
      C.cboAccountingLedgerMethod.VisibleRow(false);
      C.numAccountingLedgerLess.VisibleRow(false);
      C.chkAccountingLedgerGlEomSplit.VisibleRow(false);
      C.chkAccountingLedgerIncludeOpeningInReports.VisibleRow(false);
      C.lblAccountingLedgerGlAccount.VisibleRow(false);
      C.cboUnearnedGlAccount.VisibleRow(false);
      break;
  }

  // Licensing
  if (!mRecord.AddOnDepositAccount &amp;&amp; !mRecord.AddOnCurrentAccount) {
    C.cboWTaxGlAccount.VisibleRow(false);
  }
  if (!mRecord.AddOnDepositAccount) {
    C.cboImpCreditsGlAccount.VisibleRow(false);
  }
  if (!mRecord.AddOnAccountingLedgers) {
    C.lblAccountingLedgers.VisibleRow(false);
    C.cboAccountingLedgerType.VisibleRow(false);
    C.cboAccountingLedgerMethod.VisibleRow(false);
    C.numAccountingLedgerLess.VisibleRow(false);
    C.chkAccountingLedgerGlEomSplit.VisibleRow(false);
    C.chkAccountingLedgerIncludeOpeningInReports.VisibleRow(false);
    C.lblAccountingLedgerGlAccount.VisibleRow(false);
    C.cboUnearnedGlAccount.VisibleRow(false);
  }
  
  // Finalise
  pageGlAccounts_Refresh_Method();
}

function pageGlAccounts_Refresh_Method() {
    // Get Accounting Ledger Method
  var AccountingLedgerMethod = "None";
  if (C.cboAccountingLedgerMethod.ListIndex() != -1) AccountingLedgerMethod = mRecord.AccountingLedgerMethodList[C.cboAccountingLedgerMethod.ListIndex()].Code;

  switch(AccountingLedgerMethod) {
    case "AtClose":
    case "AtMaturity":
    case "OnDate":
      C.numAccountingLedgerLess.VisibleRow(false);
      C.chkAccountingLedgerGlEomSplit.VisibleRow(false);
      break;

    case "Proportional":
    case "ProportionalDaily":
    case "RuleOf78":
    case "ContractualInterest":
      C.numAccountingLedgerLess.VisibleRow(true);
      C.chkAccountingLedgerGlEomSplit.VisibleRow(true);
      break;

    case "Custom":
      C.numAccountingLedgerLess.VisibleRow(false);
      C.chkAccountingLedgerGlEomSplit.VisibleRow(true);
      break;

    case "None":
      C.numAccountingLedgerLess.VisibleRow(false);
      C.chkAccountingLedgerGlEomSplit.VisibleRow(false);
      break;

    default:
      window.alert("Unahandled Accounting Ledger Method '" + AccountingLedgerMethod + "'.");
      break;
  }
}

// ==========
// divPreview
// ==========
function divPreview_Refresh(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

  C.divPreview.css("color", C.cboColourForeground.Text());
  C.divPreview.css("background-color", C.cboColourBackground.Text());
}

// ==============
// cboElementType
// ==============
function cboElementType_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

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

// =================
// chkDueImmediately
// =================
function chkDueImmediately_Change(sender, e) {
  // Refresh pages
  pageGeneral_Refresh();
}

// ===========================
// chkComparisonRateCapitalise
// ===========================
function chkComparisonRateCapitalise_Change(sender, e) {
  // Refresh pages
  pageGeneral_Refresh();
}

// ===================
// cboDisbursementType
// ===================
function cboDisbursementType_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

  // Refresh pages
  pageDisbursements_Refresh();
}

// ========================
// cboDisbursementPayeeType
// ========================
function cboDisbursementPayeeType_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

  // Refresh pages
  pageDisbursements_Refresh();
}

// =========================
// cboDisbursementValueBasis
// =========================
function cboDisbursementValueBasis_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

  // Refresh pages
  pageDisbursements_Refresh();
}

// ==============
// chkCreditAllow
// ==============
function chkCreditAllow_Change(sender, e) {
  // Refresh pages
  pageCredit_Refresh();
}

// ==========================
// cboCreditCalculationMethod
// ==========================
function cboCreditCalculationMethod_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

  // Refresh pages
  pageCredit_Refresh();
}

// ===================================
// cboCreditRefinanceCalculationMethod
// ===================================
function cboCreditRefinanceCalculationMethod_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

  // Refresh pages
  pageCredit_Refresh();
}

// ========================
// cboCreditRefinanceOption
// ========================
function cboCreditRefinanceOption_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

  // Refresh pages
  pageCredit_Refresh();
}

// =======================
// cboAccountingLedgerType
// =======================
function cboAccountingLedgerType_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

  // Refresh pages
  pageGlAccounts_Refresh();
}

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

  // Refresh pages
  pageGlAccounts_Refresh();
}

// ========================
// chkAuthoriseTransactions
// ========================
function chkAuthoriseTransactions_Change(sender, e) {
  C.lblPermissionKeyAuthorise.VisibleRow(C.chkAuthoriseTransactions.Value());
  C.cboPermissionKeyAuthorise.VisibleRow(C.chkAuthoriseTransactions.Value());
}

// ========================
// txtComparisonRateRegions
// ========================
function txtComparisonRateRegions_ButtonClick(sender, e) {
  switch(e.id) {
    case "Lookup":
      widget.UI.Forms.ShowRangeLookupFromDatabase(sender.Text(), { idField: "Region", rangeLookupSql: mRecord.AccountRegionsFilter },
        function (newValue) {
          sender.Text(newValue);
          sender.Focus();
        }
      );
      break;
  }
}

// ====================
// 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>SC-0HQbfU0uHbxzzY-5PjA</UniqueId>
    <AllowRefresh>true</AllowRefresh>
    <Caption>Element</Caption>
    <HtmlWidgetAllowInitialEventCaching>false</HtmlWidgetAllowInitialEventCaching>
    <HtmlWidgetMaxHeight>800</HtmlWidgetMaxHeight>
    <HtmlWidgetMaxWidth>800</HtmlWidgetMaxWidth>
    <HtmlWidgetNeverApplyStyling>false</HtmlWidgetNeverApplyStyling>
    <HtmlWidgetResourceChartsApex>false</HtmlWidgetResourceChartsApex>
    <HtmlWidgetResourceCssSummaryPage2>false</HtmlWidgetResourceCssSummaryPage2>
    <HtmlWidgetResourceCssWidget>true</HtmlWidgetResourceCssWidget>
    <HtmlWidgetResourceJQuery>true</HtmlWidgetResourceJQuery>
    <HtmlWidgetResourceJQueryVersion />
    <HtmlWidgetSpecialEventGetFolderCount>false</HtmlWidgetSpecialEventGetFolderCount>
    <Icon>Element</Icon>
    <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="ElementId" 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>20</MaxLength>
            <RangeSingle>true</RangeSingle>
            <RangeType>Standard</RangeType>
            <RangeLookupSource>Elements</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.Elements</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,Options,Defaults,Disbursements,Credit,GlAccounts,Authorisation</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>