<?xml version="1.0" encoding="utf-8"?>
  <finScript version="1.00" exportedUtcDate="2023-08-18T00:53:12.0000000">
    <CreatedUserId>ADMIN</CreatedUserId>
    <CreatedUtcDate>2023-07-31T23:21:05.7370000</CreatedUtcDate>
    <UpdatedUserId>ADMIN</UpdatedUserId>
    <UpdatedUtcDate>2023-08-18T00:52:44.4500000</UpdatedUtcDate>
    <ScriptId>STE</ScriptId>
    <Description>Security Type Edit</Description>
    <ScriptType>HtmlWidget</ScriptType>
    <Active>true</Active>
    <AllowUI>false</AllowUI>
    <Bookmarks />
    <Category />
    <Code>' HtmlWidget_SecurityTypeEdit
Option Explicit On
Option Strict On

' #################################################################
' Security Type Edit form HTML Widget
'
' Version: 1.00 (18/08/2023)
'
' Usage: System-supplied HTML Widget
' #################################################################
' Version        Date  User     Job       Description
' -------  ----------  -------  --------  -------------------------
'    1.00  18/08/2023  ISS      J029715   Created
' #################################################################

' Constants
Private Const FORM_KEY As String = "SecurityTypes"

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

' Standard Parameters
Private mSecurityTypeId 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
    mSecurityTypeId = .GetString("SecurityTypeId") ' Always use Startup Parameters since the Security Type 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 Security Type.
''' &lt;/summary&gt;
Private Function GetSecurityType(ByRef securityType As finSecurityType) As Boolean

  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Validate

  ' Create and Load Security Type
  If Success Then
    ' Create Security Type
    securityType = finBL.CreateSecurityType()

    ' Load Security Type
    If Len(mDuplicateRecordId) &lt;&gt; 0 Then
      ' New record (by duplicating existing)
      Success = securityType.Load(mDuplicateRecordId)
      If Success Then securityType.Duplicate()
    ElseIf Len(mSecurityTypeId) = 0 Then
      ' New record
    Else
      Success = securityType.Load(mSecurityTypeId)
    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 FormInitialisationInfo As FormInitialisationInfo
  Dim List As ISList
  Dim SecurityCollateralClass As finSecurityCollateralClass
  Dim SecurityType As finSecurityType
  Dim strTemp As String
  Dim Success As Boolean

  ' Assume Success
  Success = True
  
  ' Validate

  ' Get Security Type
  If Success Then
    Success = GetSecurityType(SecurityType)
  End If

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

      ' Record
      .Pk = SecurityType.Pk
      .Timestamp = SecurityType.Timestamp

      ' Page Permissions (defined here since they are used below)
      .AllowPageGeneral = True
      .AllowPageOther = True
      .AllowPageUserDefined = finBL.Settings.HasSecurityTypeUser

      ' General
      .SecurityTypeId = SecurityType.SecurityTypeId ' Always need to return Security Type Id
      If .AllowPageGeneral Then
        .Active = SecurityType.Active
        .Description = SecurityType.Description
        
        .BaseType = SecurityType.BaseTypeText
        .Class = finBL.SecurityCollateralClasses.ItemByPk(CInt(SecurityType.CollateralClass)).Description        
        .ClassDescription = SecurityType.CollateralClassDescription
        .Category = SecurityType.Category
        
        .DescriptionShort = SecurityType.DescriptionShort
        .Icon = SecurityType.Icon
        
        .AllowTradeIns = SecurityType.AllowTradeIns
        .PhysicalAsset = SecurityType.PhysicalAsset
        .VinMandatoryPPSR = SecurityType.VinMandatoryPPSR
        .UserFlagA = SecurityType.UserFlagA
        .UserFlagB = SecurityType.UserFlagB
        
        .DefaultPPSRPMSIApplies = SecurityType.DefaultPPSRPMSIApplies
        .DefaultPPSRAssetSubjectToControl = SecurityType.DefaultPPSRAssetSubjectToControl
        .DefaultPPSRProceedsToBeClaimed = SecurityType.DefaultPPSRProceedsToBeClaimed
        .DefaultPPSRProceedsToBeClaimedDescription = SecurityType.DefaultPPSRProceedsToBeClaimedDescription
        .DefaultSecurityStmtItemDebtorStatus = SecurityType.DefaultSecurityStmtItemDebtorStatusText
      End If

      ' Other
      If .AllowPageOther Then
        .ValuationPercentUse = SecurityType.ValuationPercentUse
        
        .UseResidualValue = SecurityType.UseResidualValue
        .AllowResidualValueAny = SecurityType.AllowResidualValueAny
        .ResidualValuePercent = SecurityType.ResidualValuePercent  
        
        .UserDefinedParameterSetId = SecurityType.UserDefinedParameterSetId
        
        .DescriptionInformationListId = SecurityType.DescriptionInformationListId        
        .ColourInformationListId = SecurityType.ColourInformationListId
        .CountryOfOriginInformationListId = SecurityType.CountryOfOriginInformationListId        
        .EngineMakeInformationListId = SecurityType.EngineMakeInformationListId
        .MakeModelInformationListId = SecurityType.MakeModelInformationListId
        .TypeStyleInformationListId = SecurityType.TypeStyleInformationListId
        .CodeInformationListId = SecurityType.CodeInformationListId
      End If
      
      ' User Defined
      If .AllowPageUserDefined Then
        .UserDefinedParameters = finBL.CreateWsParameters(finBL.SecurityTypes.CreateUserDefinedParameters())
        .UserDataJson = SecurityType.UserData.ToSimpleJsonString()
      End If
      
      ' Other

      ' Permissions

      ' Lists
      .IconList = finBL.Utilities.GetIconListByPrefix("SecurityType_").ToCsvString()
      
      For Each SecurityCollateralClass In finBL.SecurityCollateralClasses
        .CollateralClasses.Add(New CollateralClass(SecurityCollateralClass))
      Next 
      
      List = finBL.Runtime.CreateList()
      For Each strTemp In finBL.Enums.isefinSecurityBaseType_GetList()
        .SecurityBaseTypes.Add(New SecurityBaseType(finBL.Enums.isefinSecurityBaseType_FromString(strTemp)))
      Next               

      List.Clear()
      List.Add(finBL.Enums.isefinSecurityStmtItemDebtorStatus_ToString(isefinSecurityStmtItemDebtorStatus.Required))
      List.Add(finBL.Enums.isefinSecurityStmtItemDebtorStatus_ToString(isefinSecurityStmtItemDebtorStatus.Waived))
      .DefaultSecurityStmtItemDebtorStatusList = List.ToCsvString()
      
      ' Configuration
      .CountryCode = finBL.CountryCode
      .DebtorStatusTextNotApplicable = finBL.Enums.isefinSecurityStmtItemDebtorStatus_ToString(isefinSecurityStmtItemDebtorStatus.NotApplicable)
      .DebtorStatusTextWaived = finBL.Enums.isefinSecurityStmtItemDebtorStatus_ToString(isefinSecurityStmtItemDebtorStatus.Waived)
      .DebtorStatusTextRequired = finBL.Enums.isefinSecurityStmtItemDebtorStatus_ToString(isefinSecurityStmtItemDebtorStatus.Required)
      .HideOtherPages = mCombinedParameters.GetBoolean("HideOtherPages", False)
      .PromptOnSave = finBL.CloudConnectFunctions.CloudConnectSettings.PromptOnSave
      .UserFlagACaption = finBL.Settings.SecurityTypeFlagAResolved
      .UserFlagBCaption = finBL.Settings.SecurityTypeFlagBResolved
    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 Security Type.
''' &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 SecurityType As finSecurityType
  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 Security Type
  If Success Then
    Success = GetSecurityType(SecurityType)
  End If
  
  ' Validate
  If Success Then
    If Record.Timestamp &lt;&gt; SecurityType.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 Security Type
      With SecurityType
        ' General        
        If Record.AllowPageGeneral Then
          .SecurityTypeId = Record.SecurityTypeId
          .Active = Record.Active
          .Description = Record.Description
          
          .BaseTypeText = Record.BaseType          
          If finBL.SecurityCollateralClasses.ItemByDescription(Record.Class) Is Nothing Then
            .CollateralClass = iseSecurityCollateralClassBase.NotApplicable
          Else
            .CollateralClass = finBL.SecurityCollateralClasses.ItemByDescription(Record.Class).CollateralClassBase
          End If
          .CollateralClassDescription = Record.ClassDescription
          .Category = Record.Category
          
          .DescriptionShort = Record.DescriptionShort
          .Icon = Record.Icon
          
          .AllowTradeIns = Record.AllowTradeIns
          .PhysicalAsset = Record.PhysicalAsset
          .VinMandatoryPPSR = Record.VinMandatoryPPSR
          .UserFlagA = Record.UserFlagA
          .UserFlagB = Record.UserFlagB
          
          .DefaultPPSRPMSIApplies = Record.DefaultPPSRPMSIApplies
          .DefaultPPSRAssetSubjectToControl = Record.DefaultPPSRAssetSubjectToControl
          .DefaultPPSRProceedsToBeClaimed = Record.DefaultPPSRProceedsToBeClaimed
          .DefaultPPSRProceedsToBeClaimedDescription = Record.DefaultPPSRProceedsToBeClaimedDescription
          .DefaultSecurityStmtItemDebtorStatusText = Record.DefaultSecurityStmtItemDebtorStatus
        End If
        
        ' Other
        If Record.AllowPageOther Then
          .ValuationPercentUse = Record.ValuationPercentUse
          
          .UseResidualValue = Record.UseResidualValue
          .AllowResidualValueAny = Record.AllowResidualValueAny
          .ResidualValuePercent = Record.ResidualValuePercent  
          
          .UserDefinedParameterSetId = Record.UserDefinedParameterSetId
          
          .DescriptionInformationListId = Record.DescriptionInformationListId        
          .ColourInformationListId = Record.ColourInformationListId
          .CountryOfOriginInformationListId = Record.CountryOfOriginInformationListId        
          .EngineMakeInformationListId = Record.EngineMakeInformationListId
          .MakeModelInformationListId = Record.MakeModelInformationListId
          .TypeStyleInformationListId = Record.TypeStyleInformationListId
          .CodeInformationListId = Record.CodeInformationListId
        End If
        
        ' User Defined
        If Success Then
          If Record.AllowPageUserDefined AndAlso finBL.Settings.HasSecurityTypeUser Then
            .UserData.FromHtmlWidgetParametersJsonString(Record.UserDataJson)
          End If
        End If
      End With

      ' Save
      If Success Then
        Success = SecurityType.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;
Public Class FormInitialisationInfo

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

  ' Record
  Public Pk As Integer
  Public Timestamp As Integer

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

  Public BaseType As String
  Public [Class] As String
  Public ClassDescription As String
  Public Category As String
  
  Public DescriptionShort As String
  Public Icon As String
  
  Public AllowTradeIns As Boolean
  Public PhysicalAsset As Boolean
  Public VinMandatoryPPSR As Boolean
  Public UserFlagA As Boolean
  Public UserFlagB As Boolean
  
  Public DefaultPPSRPMSIApplies As Boolean
  Public DefaultPPSRAssetSubjectToControl As Boolean
  Public DefaultPPSRProceedsToBeClaimed As Boolean
  Public DefaultPPSRProceedsToBeClaimedDescription As String
  Public DefaultSecurityStmtItemDebtorStatus As String
  
  ' Other
  Public ValuationPercentUse As Double
  
  Public UseResidualValue As Boolean
  Public AllowResidualValueAny As Boolean
  Public ResidualValuePercent As Double
  
  Public UserDefinedParameterSetId As String
  
  Public DescriptionInformationListId As String
  Public ColourInformationListId As String
  Public CountryOfOriginInformationListId As String
  Public EngineMakeInformationListId As String
  Public MakeModelInformationListId As String
  Public TypeStyleInformationListId As String
  Public CodeInformationListId As String
  
  ' User Defined
  Public UserDefinedParameters As ISWsParameters
  Public UserDataJson As String
  
  ' Permissions
  Public AllowPageGeneral As Boolean
  Public AllowPageOther As Boolean
  Public AllowPageUserDefined As Boolean

  ' Lists
  Public IconList As String
  Public CollateralClasses As New List(Of CollateralClass)
  Public SecurityBaseTypes As New List(Of SecurityBaseType)
  Public DefaultSecurityStmtItemDebtorStatusList As String
  
  ' Configuration
  Public CountryCode As String
  Public DebtorStatusTextNotApplicable As String
  Public DebtorStatusTextWaived As String
  Public DebtorStatusTextRequired As String
  Public HideOtherPages As Boolean
  Public PromptOnSave As Boolean
  Public UserFlagACaption As String
  Public UserFlagBCaption As String

End Class



''' &lt;summary&gt;
'''  Collateral Class.
''' &lt;/summary&gt;
Public Class CollateralClass
  
  Public CollateralClassBase As String
  Public CollateralClassBaseDescription As String
  
  Public AllowPurchaseMoneySecurityInterest As Boolean
  Public AllowAssetSubjectToControl As Boolean
  Public AllowProceedsClaimed As Boolean
  Public Commerical As Boolean
  Public IsCollateralItemCommercial As Boolean
  Public IsGrantorRequired As Boolean
  
  Public Sub New(securityCollateralClass As finSecurityCollateralClass)
    
    With securityCollateralClass
      Me.CollateralClassBase = .CollateralClassBase.ToString()
      Me.CollateralClassBaseDescription = .Description
      
      ' Override 'Not Applicable'
      If .CollateralClassBase = iseSecurityCollateralClassBase.NotApplicable OrElse finBLShared.CountryCode &lt;&gt; "AU" Then
        Me.AllowPurchaseMoneySecurityInterest = False
        Me.AllowAssetSubjectToControl = False
        Me.AllowProceedsClaimed = False
        Me.Commerical = False
        Me.IsCollateralItemCommercial = False
        Me.IsGrantorRequired = False
      Else 
        ' These properties will automatically adjust based upon country and Collateral Class
        Me.AllowPurchaseMoneySecurityInterest = .AllowPurchaseMoneySecurityInterest
        Me.AllowAssetSubjectToControl = .AllowAssetSubjectToControl
        Me.AllowProceedsClaimed = .AllowProceedsClaimed
        Me.Commerical = .Commerical
        Me.IsCollateralItemCommercial = .IsCollateralItemCommercial()
        Me.IsGrantorRequired = .IsGrantorRequired
      End If      
    End With
    
  End Sub
  
End Class



''' &lt;summary&gt;
'''  Security Base Type.
''' &lt;/summary&gt;
Public Class SecurityBaseType
  
  Public BaseType As String
  Public BaseTypeText As String
  Public CollateralClassList As String
  Public ShowUseResidualValue As Boolean
  
  Public Sub New(baseType As isefinSecurityBaseType)
    
    Dim CollateralClass As finSecurityCollateralClass
    Dim List As ISList
    
    ' Initialise
    List = finBLShared.Runtime.CreateList()    
    
    ' Compatible Collateral Classes
    For Each CollateralClass In finBLShared.SecurityCollateralClasses
      If CollateralClass.CompatibleBaseTypes.Contains(baseType) Then
        List.Add(CollateralClass.Description)
      End If
    Next
    List.Sort()
    
    ' Set Properties
    Me.BaseType = baseType.ToString()
    Me.BaseTypeText = finBLShared.Enums.isefinSecurityBaseType_ToString(baseType)
    Me.CollateralClassList = List.ToCsvString()
    
    Select Case baseType
      Case isefinSecurityBaseType.Insurance, isefinSecurityBaseType.Investment: Me.ShowUseResidualValue = False        
      Case Else : Me.ShowUseResidualValue = True
    End Select
    
  End Sub
  
End Class



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

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

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

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

  End Sub

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

  &lt;!-- Form Header --&gt;
  &lt;header&gt;
    &lt;!-- Tabs --&gt;
    &lt;div id="tabDetails" class="is-tabs"&gt;
      &lt;ul&gt;
        &lt;li tabId="General"&gt;General&lt;/li&gt;
        &lt;li tabId="Other"&gt;Other&lt;/li&gt;
        &lt;li tabId="UserDefined"&gt;User Defined&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:10em" /&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="txtSecurityTypeId"&gt;Code:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtSecurityTypeId"/&gt; &lt;input id="chkActive" type="checkbox"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtDescription"&gt;Description:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtDescription"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblSecurityType"&gt;Security Type&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboBaseSecurityType"&gt;Base Type:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboBaseSecurityType"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboCollateralClass"&gt;Class:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboCollateralClass"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtCollateralClassDescription"&gt;Class Description:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtCollateralClassDescription"/&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 id="lblShortDescription"&gt;Short Description and Icon (for displaying in grids)&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtDescriptionShort"&gt;Short Description:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtDescriptionShort"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboIcon"&gt;Icon:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboIcon"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblOtherOptions"&gt;Other options&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkAllowTradeIns" type="checkbox" /&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkPhysicalAsset" type="checkbox" /&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkVINMandatoryPPSR" 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="lblPPSRDefaults"&gt;PPSR Defaults&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkPPSRPMSIApplies" type="checkbox" /&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkPPSRAssetSubjectToControl" type="checkbox" /&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkPPSRProceedsToBeClaimed" type="checkbox" /&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2" class="indent1"&gt;&lt;input id="txtPPSRProceedsToBeClaimed" /&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboDefaultSecurityStmtItemDebtorStatus"&gt;Grantor Status:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboDefaultSecurityStmtItemDebtorStatus"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;


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

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblSecurityPercent"&gt;Percentage of Security to use in Valuations&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="numValuationPercentUse"&gt;Default Percent:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="numValuationPercentUse"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblResidualPercent"&gt;Percentage of Residual Value to use&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkUseResidualValue" type="checkbox" /&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkAllowResidualValueAny" type="checkbox" /&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="numResidualValuePercent"&gt;Default Percent:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="numResidualValuePercent"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblParameterSet"&gt;Parameter Set to enter User Defined details&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboParameterSetUserDefined"&gt;Parameter Set:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboParameterSetUserDefined"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblInformationLists"&gt;Information Lists&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboInformationListDescription"&gt;Description:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboInformationListDescription"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboInformationListColour"&gt;Colour:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboInformationListColour"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboInformationListCountryOfOrigin"&gt;Country of Origin:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboInformationListCountryOfOrigin"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboInformationListEngineMake"&gt;Engine Make:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboInformationListEngineMake"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboInformationListMakeModel"&gt;Make:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboInformationListMakeModel"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboInformationListTypeStyle"&gt;Type:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboInformationListTypeStyle"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboInformationListCode"&gt;Code:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboInformationListCode"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;

    
    &lt;!-- User Defined --&gt;
    &lt;div id="pageUserDefined"&gt;
      &lt;div id="phUserDefined" style="display:block"&gt;&lt;/div&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,
  txtSecurityTypeId: null,
  txtDescription: null,
  
  lblSecurityType: null,
  cboBaseSecurityType: null,
  cboCollateralClass: null,
  txtCollateralClassDescription: null,
  cboCategory: null,
  
  lblShortDescription: null,
  txtDescriptionShort: null,
  cboIcon: null,
  
  lblOtherOptions: null,
  chkAllowTradeIns: null,
  chkPhysicalAsset: null,
  chkVINMandatoryPPSR: null,
  chkUserFlagA: null,
  chkUserFlagB: null,
  
  lblPPSRDefaults: null,
  chkPPSRPMSIApplies: null,
  chkPPSRAssetSubjectToControl: null,
  chkPPSRProceedsToBeClaimed: null,
  txtPPSRProceedsToBeClaimed: null,
  cboDefaultSecurityStmtItemDebtorStatus: null,
  
  //   Other
  lblSecurityPercent: null,
  numValuationPercentUse: null,
  
  lblResidualPercent: null,
  chkUseResidualValue: null,
  chkAllowResidualValueAny: null,
  numResidualValuePercent: null,
  
  lblParameterSet: null,
  cboParameterSetUserDefined: null,
  
  lblInformationLists: null,
  cboInformationListDescription: null,
  cboInformationListColour: null,
  cboInformationListCountryOfOrigin: null,
  cboInformationListEngineMake: null,
  cboInformationListMakeModel: null,
  cboInformationListTypeStyle: null,
  cboInformationListCode: null,
  
  //   User Defined
  phUserDefined: null,
}

// Form
var frmMain;
var tabDetails;

// Buttons
var cmdCancel;
var cmdFinish;

// Other
var mBaseType;
var mCollateralClass;

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

  // --------
  // Controls
  // --------
  //   General
  C.lblCodeAndName = widget.UI.Label("lblCodeAndName", {});
  C.txtSecurityTypeId = widget.UI.TextBox("txtSecurityTypeId", {
    allowBlank: false,
    maxLength: 10,
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });
  C.chkActive = widget.UI.CheckBox("chkActive", {
    caption: "Active?",
  });
  C.txtDescription = widget.UI.TextBox("txtDescription", {
    allowBlank: false,
    maxLength: 50,
  });

  C.lblSecurityType = widget.UI.Label("lblSecurityType", {});
  C.cboBaseSecurityType = widget.UI.ComboBox("cboBaseSecurityType", {
    allowBlank: false,
    limitToList: true,
    
    onChange: cboBaseSecurityType_Change,
  });
  C.cboCollateralClass = widget.UI.ComboBox("cboCollateralClass", {
    allowBlank: false,
    limitToList: true,
    
    onChange: cboCollateralClass_Change,
  });
  C.txtCollateralClassDescription = widget.UI.TextBox("txtCollateralClassDescription", {
    maxLength: 50,
  });
  C.cboCategory = widget.UI.InformationListComboBox("cboCategory", {
    maxLength: 50,
  });
  
  C.lblShortDescription = widget.UI.Label("lblShortDescription", {});
  C.txtDescriptionShort = widget.UI.TextBox("txtDescriptionShort", {
    maxLength: 20,
  });
  C.cboIcon = widget.UI.IconComboBox("cboIcon", {
    iconPrefix: "SecurityType_",
    limitToList: true,
    width: "14em",
  });
  
  C.lblOtherOptions = widget.UI.Label("lblOtherOptions", {});
  C.chkAllowTradeIns = widget.UI.CheckBox("chkAllowTradeIns", {
    caption: "Trade-Ins allowed?",
    captionWrap: true,
  });
  C.chkPhysicalAsset = widget.UI.CheckBox("chkPhysicalAsset", {
    caption: "Physical Asset (Item can be repossessed)?",
    captionWrap: true,
  });
  C.chkVINMandatoryPPSR = widget.UI.CheckBox("chkVINMandatoryPPSR", {
    caption: "Is the VIN mandatory for a PPSR Registration?",
    captionWrap: true,
  });
  C.chkUserFlagA = widget.UI.CheckBox("chkUserFlagA", {
    caption: "User Flag A",
    captionWrap: true,
  });
  C.chkUserFlagB = widget.UI.CheckBox("chkUserFlagB", {
    caption: "User Flag B",
    captionWrap: true,
  });
  
  C.lblPPSRDefaults = widget.UI.Label("lblPPSRDefaults", {});
  C.chkPPSRPMSIApplies = widget.UI.CheckBox("chkPPSRPMSIApplies", {
    caption: "Purchase money security interest applies?",
    captionWrap: true,
  });
  C.chkPPSRAssetSubjectToControl = widget.UI.CheckBox("chkPPSRAssetSubjectToControl", {
    caption: "Collateral is an asset subject to control?",
    captionWrap: true,
  });
  C.chkPPSRProceedsToBeClaimed = widget.UI.CheckBox("chkPPSRProceedsToBeClaimed", {
    caption: "Proceeds to be claimed?",
    captionWrap: true,
  });
  C.txtPPSRProceedsToBeClaimed = widget.UI.TextBox("txtPPSRProceedsToBeClaimed", {
    maxLength: 500,
    multiLine: true,
    rows: 2,
  });
  C.cboDefaultSecurityStmtItemDebtorStatus = widget.UI.ComboBox("cboDefaultSecurityStmtItemDebtorStatus", {
    allowBlank: false,
    limitToList: true,
    width: "10em",
  });

  //   Other
  C.lblSecurityPercent = widget.UI.Label("lblSecurityPercent", {});
  C.numValuationPercentUse = widget.UI.NumberBox("numValuationPercentUse", {
    minValue: 0,
    maxValue: 100,
    percentage: true,
  });
  
  C.lblResidualPercent = widget.UI.Label("lblResidualPercent", {});
  C.chkUseResidualValue = widget.UI.CheckBox("chkUseResidualValue", {
    caption: "Use Residual Value?",
    captionWrap: true,
    
    onChange: chkUseResidualValue_Change,
  });
  C.chkAllowResidualValueAny = widget.UI.CheckBox("chkAllowResidualValueAny", {
    caption: "Allow Residual Value greater than 100%?",
    captionWrap: true,
    
    onChange: chkAllowResidualValueAny_Change,
  });
  C.numResidualValuePercent = widget.UI.NumberBox("numResidualValuePercent", {
    minValue: 0,
    maxValue: 100,
    percentage: true,
  });
  
  C.lblParameterSet = widget.UI.Label("lblParameterSet", {});
  C.cboParameterSetUserDefined = widget.UI.DBCombo("cboParameterSetUserDefined", {
    limitToList: true,
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });
  
  C.lblInformationLists = widget.UI.Label("lblInformationLists", {});
  C.cboInformationListDescription = widget.UI.DBCombo("cboInformationListDescription", {
    limitToList: true,
    width: widget.UI.FIELD_WIDTH_CODE_25,
  });
  C.cboInformationListColour = widget.UI.DBCombo("cboInformationListColour", {
    limitToList: true,
    width: widget.UI.FIELD_WIDTH_CODE_25,
  });
  C.cboInformationListCountryOfOrigin = widget.UI.DBCombo("cboInformationListCountryOfOrigin", {
    limitToList: true,
    width: widget.UI.FIELD_WIDTH_CODE_25,
  });
  C.cboInformationListEngineMake = widget.UI.DBCombo("cboInformationListEngineMake", {
    limitToList: true,
    width: widget.UI.FIELD_WIDTH_CODE_25,
  });
  C.cboInformationListMakeModel = widget.UI.DBCombo("cboInformationListMakeModel", {
    limitToList: true,
    width: widget.UI.FIELD_WIDTH_CODE_25,
  });
  C.cboInformationListTypeStyle = widget.UI.DBCombo("cboInformationListTypeStyle", {
    limitToList: true,
    width: widget.UI.FIELD_WIDTH_CODE_25,
  });
  C.cboInformationListCode = widget.UI.DBCombo("cboInformationListCode", {
    limitToList: true,
    width: widget.UI.FIELD_WIDTH_CODE_25,
  });

  //   User Defined
  C.phUserDefined = widget.UI.ParametersHost("phUserDefined", {});

  // 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;
  mBaseType = null;
  mCollateralClass = 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");
  }

  // Give Collections ability to lookup by code
  widget.ArrayAllowLookupById(mRecord.CollateralClasses, "CollateralClassBaseDescription");
  widget.ArrayAllowLookupById(mRecord.SecurityBaseTypes, "BaseTypeText");

  // Page Permissions
  if (!mRecord.AllowPageGeneral) tabDetails.TabVisible("General", false);
  if (!mRecord.AllowPageOther) tabDetails.TabVisible("Other", false);
  if (!mRecord.AllowPageUserDefined) tabDetails.TabVisible("UserDefined", 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.txtSecurityTypeId.Text(mRecord.SecurityTypeId);
    C.chkActive.Value(mRecord.Active);
    C.txtDescription.Text(mRecord.Description);
    
    C.cboBaseSecurityType.Text(mRecord.BaseType);
    C.cboCollateralClass.Text(mRecord.Class);
    C.txtCollateralClassDescription.Text(mRecord.ClassDescription);
    C.cboCategory.Text(mRecord.Category);
    
    C.txtDescriptionShort.Text(mRecord.DescriptionShort);
    C.cboIcon.Text(mRecord.Icon);
    
    C.chkAllowTradeIns.Value(mRecord.AllowTradeIns);
    C.chkPhysicalAsset.Value(mRecord.PhysicalAsset);
    C.chkVINMandatoryPPSR.Value(mRecord.VinMandatoryPPSR);
    C.chkUserFlagA.Value(mRecord.UserFlagA);
    C.chkUserFlagB.Value(mRecord.UserFlagB);
    
    C.chkPPSRPMSIApplies.Value(mRecord.DefaultPPSRPMSIApplies);
    C.chkPPSRAssetSubjectToControl.Value(mRecord.DefaultPPSRAssetSubjectToControl);
    C.chkPPSRProceedsToBeClaimed.Value(mRecord.DefaultPPSRProceedsToBeClaimed);
    C.txtPPSRProceedsToBeClaimed.Text(mRecord.DefaultPPSRProceedsToBeClaimedDescription);
    C.cboDefaultSecurityStmtItemDebtorStatus.Text(mRecord.DefaultSecurityStmtItemDebtorStatus);
    
    //   Other
    C.numValuationPercentUse.Value(mRecord.ValuationPercentUse);
    
    C.chkUseResidualValue.Value(mRecord.UseResidualValue);
    C.chkAllowResidualValueAny.Value(mRecord.AllowResidualValueAny);
    C.numResidualValuePercent.Value(mRecord.ResidualValuePercent);
    
    C.cboParameterSetUserDefined.Text(mRecord.UserDefinedParameterSetId);
    
    C.cboInformationListDescription.Text(mRecord.DescriptionInformationListId);
    C.cboInformationListColour.Text(mRecord.ColourInformationListId);
    C.cboInformationListCountryOfOrigin.Text(mRecord.CountryOfOriginInformationListId);
    C.cboInformationListEngineMake.Text(mRecord.EngineMakeInformationListId);
    C.cboInformationListMakeModel.Text(mRecord.MakeModelInformationListId);
    C.cboInformationListTypeStyle.Text(mRecord.TypeStyleInformationListId);
    C.cboInformationListCode.Text(mRecord.CodeInformationListId);
    
    //   User Defined
    if (mRecord.AllowPageUserDefined) {      
      C.phUserDefined.Initialise(mRecord.UserDefinedParameters);
      C.phUserDefined.UpdateParameterValues(JSON.parse(mRecord.UserDataJson));
    }
  }

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

  // Update Controls
  cboBaseSecurityType_Change();

  // Update fields
  Fields_Update();

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

// ===========
// Save Fields
// ===========
function Fields_Save() {
  // General
  mRecord.SecurityTypeId = C.txtSecurityTypeId.Text();
  mRecord.Active = C.chkActive.Value();
  mRecord.Description = C.txtDescription.Text();
  
  mRecord.BaseType = C.cboBaseSecurityType.Text();
  mRecord.Class = C.cboCollateralClass.Text();
  mRecord.ClassDescription = C.txtCollateralClassDescription.Text();
  mRecord.Category = C.cboCategory.Text();
  
  mRecord.DescriptionShort = C.txtDescriptionShort.Text();
  mRecord.Icon = C.cboIcon.Text();
  
  mRecord.AllowTradeIns = C.chkAllowTradeIns.Value();
  mRecord.PhysicalAsset = C.chkPhysicalAsset.Value();
  mRecord.VinMandatoryPPSR = C.chkVINMandatoryPPSR.Value();
  mRecord.UserFlagA = C.chkUserFlagA.Value();
  mRecord.UserFlagB = C.chkUserFlagB.Value();
  
  mRecord.DefaultPPSRPMSIApplies = C.chkPPSRPMSIApplies.Value();
  mRecord.DefaultPPSRAssetSubjectToControl = C.chkPPSRAssetSubjectToControl.Value();
  mRecord.DefaultPPSRProceedsToBeClaimed = C.chkPPSRProceedsToBeClaimed.Value();
  mRecord.DefaultPPSRProceedsToBeClaimedDescription = C.txtPPSRProceedsToBeClaimed.Text();
  mRecord.DefaultSecurityStmtItemDebtorStatus = C.cboDefaultSecurityStmtItemDebtorStatus.Text();
  
  //   Other
  mRecord.ValuationPercentUse = C.numValuationPercentUse.Value();
  
  mRecord.UseResidualValue = C.chkUseResidualValue.Value();
  mRecord.AllowResidualValueAny = C.chkAllowResidualValueAny.Value();
  mRecord.ResidualValuePercent = C.numResidualValuePercent.Value();
  
  mRecord.UserDefinedParameterSetId = C.cboParameterSetUserDefined.Text();
  
  mRecord.DescriptionInformationListId = C.cboInformationListDescription.Text();
  mRecord.ColourInformationListId = C.cboInformationListColour.Text();
  mRecord.CountryOfOriginInformationListId = C.cboInformationListCountryOfOrigin.Text();
  mRecord.EngineMakeInformationListId = C.cboInformationListEngineMake.Text();
  mRecord.MakeModelInformationListId = C.cboInformationListMakeModel.Text();
  mRecord.TypeStyleInformationListId = C.cboInformationListTypeStyle.Text();
  mRecord.CodeInformationListId = C.cboInformationListCode.Text();
  
  //   User Defined
  if (mRecord.AllowPageUserDefined) {
    mRecord.UserDataJson = JSON.stringify(C.phUserDefined.GetParameterValuesWithTypes());
  }
}

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

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

  // Lists
  if (mRecord) {
    // General    
    C.cboBaseSecurityType.ListFromCollection(mRecord.SecurityBaseTypes, "BaseTypeText");
    C.cboIcon.ListFromCsvString(mRecord.IconList);
    C.cboDefaultSecurityStmtItemDebtorStatus.ListFromCsvString(mRecord.DefaultSecurityStmtItemDebtorStatusList);
    
    // Other
    C.cboParameterSetUserDefined.RefreshFromStandardRange("ParameterSets");
    C.cboInformationListDescription.RefreshFromStandardRange("InformationLists", "", false, mRecord.DescriptionInformationListId);
    C.cboInformationListColour.RefreshFromStandardRange("InformationLists", "", false, mRecord.ColourInformationListId);
    C.cboInformationListCountryOfOrigin.RefreshFromStandardRange("InformationLists", "", false, mRecord.CountryOfOriginInformationListId);
    C.cboInformationListEngineMake.RefreshFromStandardRange("InformationLists", "", false, mRecord.EngineMakeInformationListId);
    C.cboInformationListMakeModel.RefreshFromStandardRange("InformationLists", "", false, mRecord.MakeModelInformationListId);
    C.cboInformationListTypeStyle.RefreshFromStandardRange("InformationLists", "", false, mRecord.TypeStyleInformationListId);
    C.cboInformationListCode.RefreshFromStandardRange("InformationLists", "", false, mRecord.CodeInformationListId);
  }

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

  // 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();
    pageOther_Refresh();
  }

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

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

  // Resize Tab
  tabDetails_Resize();
}

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

  // General

  // Tab
  tabDetails_Resize();
}

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

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

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

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

// ==========
// Resize Tab
// ==========
function tabDetails_Resize() {
  switch (tabDetails.SelectedTabId()) {
    case "General":
      // General
      C.txtDescription.WidthResizeFromParent();      
      C.cboCollateralClass.WidthResizeFromParent();
      break;
      
    case "UserDefined":
      // User Defined
      C.phUserDefined.ResizeFromParent();
      break;
  }
}

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

    case "Other":
      pageOther_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.CollateralClasses = null;
  params.SecurityBaseTypes = 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.txtSecurityTypeId.Text());
    },

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

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

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

  // Controls
}

// =========
// pageOther
// =========
function pageOther_Refresh() {
  if (!mRecord) return;

  // Hide Controls
  C.lblSecurityPercent.VisibleRow(false);
  C.numValuationPercentUse.VisibleRow(false);
  C.lblResidualPercent.VisibleRow(false);
  C.chkUseResidualValue.VisibleRow(false);

  C.lblInformationLists.VisibleRow(false);
  C.lblInformationLists.TooltipText("");
  C.cboInformationListDescription.VisibleRow(false);
  C.cboInformationListColour.VisibleRow(false);
  C.cboInformationListCountryOfOrigin.VisibleRow(false);
  C.cboInformationListEngineMake.VisibleRow(false);
  C.cboInformationListMakeModel.VisibleRow(false);
  C.cboInformationListTypeStyle.VisibleRow(false);
  C.cboInformationListCode.VisibleRow(false);
  C.cboInformationListCode.Caption("Code:");

  // Update Controls
  if (mBaseType) {
    switch (mBaseType.BaseType) {
      case "Aircraft":      
        C.lblInformationLists.VisibleRow(true);
        C.lblInformationLists.TooltipText("Aircraft Class: The Aircraft Class Information List to use for this Security Type\n\nMake: The Make|Model Information List to use for this Security Type");  
        
        C.cboInformationListCountryOfOrigin.VisibleRow(true);
        C.cboInformationListMakeModel.VisibleRow(true);
        C.cboInformationListCode.VisibleRow(true);
        C.cboInformationListCode.Caption("Aircraft Class:");
        
        C.lblSecurityPercent.VisibleRow(true);
        C.numValuationPercentUse.VisibleRow(true);
        break;
        
      case "Boat":
        C.lblInformationLists.VisibleRow(true);
        C.lblInformationLists.TooltipText("Make: The Boat Make|Model Information List to use for this Security Type\n\nType: The Boat Type|Hull Information List to use for this Security Type"); 
        
        C.cboInformationListColour.VisibleRow(true);
        C.cboInformationListCountryOfOrigin.VisibleRow(true);
        C.cboInformationListEngineMake.VisibleRow(true);
        C.cboInformationListMakeModel.VisibleRow(true);
        C.cboInformationListTypeStyle.VisibleRow(true);
        
        C.lblSecurityPercent.VisibleRow(true);
        C.numValuationPercentUse.VisibleRow(true);
        break;
        
      case "Insurance":
        C.lblInformationLists.VisibleRow(true);
        C.cboInformationListDescription.VisibleRow(true);
        break;
      
      case "Investment":
        C.lblInformationLists.VisibleRow(true);
        C.lblInformationLists.TooltipText("The Investment Code Information List to use for this Security Type"); 
        
        C.cboInformationListDescription.VisibleRow(true);
        C.cboInformationListCode.VisibleRow(true);
      
        C.lblSecurityPercent.VisibleRow(true);
        C.numValuationPercentUse.VisibleRow(true);
        break;
        
      case "Land":
        C.lblInformationLists.VisibleRow(true);
        
        C.cboInformationListDescription.VisibleRow(true);        
      
        C.lblSecurityPercent.VisibleRow(true);
        C.numValuationPercentUse.VisibleRow(true);
        break;
        
      case "MotorVehicle":
        C.lblInformationLists.VisibleRow(true);
        C.lblInformationLists.TooltipText("Make: The Make|Model|Sub-Model Information List to use for this Security Type\n\nType: The VehicleType|BodyStyle Information List to use for this Security Type"); 
        
        C.cboInformationListColour.VisibleRow(true);
        C.cboInformationListCountryOfOrigin.VisibleRow(true);
        C.cboInformationListMakeModel.VisibleRow(true);
        C.cboInformationListTypeStyle.VisibleRow(true);
        
        C.lblSecurityPercent.VisibleRow(true);
        C.numValuationPercentUse.VisibleRow(true);
        break;
        
      case "SerialNumberedGood":
        C.lblInformationLists.VisibleRow(true);
        C.lblInformationLists.TooltipText("Make: The Make|Model Information List to use for this Security Type"); 
        
        C.cboInformationListDescription.VisibleRow(true);
        C.cboInformationListColour.VisibleRow(true);
        C.cboInformationListCountryOfOrigin.VisibleRow(true);
        C.cboInformationListMakeModel.VisibleRow(true);
        
        C.lblSecurityPercent.VisibleRow(true);
        C.numValuationPercentUse.VisibleRow(true);
        break;
        
      case "Standard":
        C.lblInformationLists.VisibleRow(true);
        
        C.cboInformationListDescription.VisibleRow(true);
        
        C.lblSecurityPercent.VisibleRow(true);
        C.numValuationPercentUse.VisibleRow(true);
        break;
    }
    
    // Uses dedicated property as a similar check is required in the change event for chkUseResidualValue
    if (mBaseType.ShowUseResidualValue) {
      C.lblResidualPercent.VisibleRow(true);
      C.chkUseResidualValue.VisibleRow(true);
    }
  }
  
  // Update Controls
  chkUseResidualValue_Change();
  chkAllowResidualValueAny_Change();
}

// ===================
// cboBaseSecurityType
// ===================
function cboBaseSecurityType_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;
  
  // Reset  
  C.cboCollateralClass.ListFromCsvString("");
  C.chkVINMandatoryPPSR.VisibleRow(false);
  
  // Get Selected Base Type
  mBaseType = mRecord.SecurityBaseTypes.GetItem(C.cboBaseSecurityType.Text());
  
  // Update Controls
  if (mBaseType) {
    C.cboCollateralClass.ListFromCsvString(mBaseType.CollateralClassList);
    
    // Clear Collateral Class if value is no longer in the list
    if (e &amp;&amp; C.cboCollateralClass.ListIndex() == -1) {
      C.cboCollateralClass.Text("");
    }
    
    switch (mBaseType.BaseType) {
      case "MotorVehicle":
        C.chkVINMandatoryPPSR.VisibleRow(true);
        break;
    }
  }
  else {
    if (e) C.cboCollateralClass.Text("");
  }
  
  // Update Other Controls
  cboCollateralClass_Change();
}

// ==================
// cboCollateralClass
// ==================
function cboCollateralClass_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;
  
  // Hide controls
  C.lblPPSRDefaults.VisibleRow(false);
  C.chkPPSRPMSIApplies.VisibleRow(false);
  C.chkPPSRAssetSubjectToControl.VisibleRow(false);
  C.chkPPSRProceedsToBeClaimed.VisibleRow(false);
  C.txtPPSRProceedsToBeClaimed.VisibleRow(false);
  C.cboDefaultSecurityStmtItemDebtorStatus.VisibleRow(false);
  
  // Reset
  if (mRecord.CountryCode == "AU" &amp;&amp; e) {
    C.cboDefaultSecurityStmtItemDebtorStatus.Text(mRecord.DebtorStatusTextNotApplicable);
  }
  
  // Get Selected Collateral Class
  mCollateralClass = mRecord.CollateralClasses.GetItem(C.cboCollateralClass.Text());
  
  // Update Controls
  if (mCollateralClass) {
    if (mCollateralClass.AllowPurchaseMoneySecurityInterest || mCollateralClass.AllowAssetSubjectToControl || mCollateralClass.AllowProceedsClaimed || mCollateralClass.Commerical) {
      C.lblPPSRDefaults.VisibleRow(true);
    }
  
    C.chkPPSRPMSIApplies.VisibleRow(mCollateralClass.AllowPurchaseMoneySecurityInterest);
    C.chkPPSRAssetSubjectToControl.VisibleRow(mCollateralClass.AllowAssetSubjectToControl);
    C.chkPPSRProceedsToBeClaimed.VisibleRow(mCollateralClass.AllowProceedsClaimed);
    C.txtPPSRProceedsToBeClaimed.VisibleRow(mCollateralClass.AllowProceedsClaimed);
    
    C.cboDefaultSecurityStmtItemDebtorStatus.VisibleRow(mCollateralClass.Commerical);
    
    // Debtor Status
    if (mRecord.CountryCode == "AU" &amp;&amp; e) {
      if (mCollateralClass.CollateralClassBase == "NotApplicable") {
        // Do nothing
      }
      if (mCollateralClass.IsCollateralItemCommercial) {
        C.cboDefaultSecurityStmtItemDebtorStatus.Text(mRecord.DebtorStatusTextWaived);
      }
      else if (mCollateralClass.IsGrantorRequired) {
        C.cboDefaultSecurityStmtItemDebtorStatus.Text(mRecord.DebtorStatusTextRequired);
      }
    }
  }
}

// ===================
// chkUseResidualValue
// ===================
function chkUseResidualValue_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;
  
  // Hide fields
  C.chkAllowResidualValueAny.VisibleRow(false);
  C.numResidualValuePercent.VisibleRow(false);
  
  // Update
  if (mBaseType) {
    if (mBaseType.ShowUseResidualValue &amp;&amp; C.chkUseResidualValue.Value()) {
      C.chkAllowResidualValueAny.VisibleRow(true);
      C.numResidualValuePercent.VisibleRow(true);
    }
  }
}

// ========================
// chkAllowResidualValueAny
// ========================
function chkAllowResidualValueAny_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;
  
  // Update Controls
  if (C.chkAllowResidualValueAny.Value()) {
    C.numResidualValuePercent.MaxValue(9999);
  }
  else {
    C.numResidualValuePercent.MaxValue(100);
  }
}

// ====================
// 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>wXWVkwHOKE+eh-Ti2GgelQ</UniqueId>
    <AllowRefresh>true</AllowRefresh>
    <Caption>Security Type</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>SecurityType</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="SecurityTypeId" type="Range">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <Mandatory>false</Mandatory>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value />
            <Visible>true</Visible>
            <LimitToList>false</LimitToList>
            <MaxLength>10</MaxLength>
            <RangeSingle>true</RangeSingle>
            <RangeType>Standard</RangeType>
            <RangeLookupSource>SecurityTypes</RangeLookupSource>
            <RangeLookupSqlWhere />
          </Parameter>
          <Parameter name="DuplicateRecordId" 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>
            <List>RANGE.SecurityTypes</List>
            <LimitToList>false</LimitToList>
            <MaxLength>10</MaxLength>
            <RangeSingle>true</RangeSingle>
            <RangeType>Standard</RangeType>
            <RangeLookupSource>SecurityTypes</RangeLookupSource>
            <RangeLookupSqlWhere />
          </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,Other,User Defined</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>