Compile function REACT_MODE_CHG_NG_EVENTS(CtrlEntId, Event, @PARAMS)

/***********************************************************************************************************************

    This program is proprietary and is not to be used by or disclosed to others, nor is it to be copied without written
    permission from Infineon.

    Name        :   React_Mode_Chg_NG_Events

    Description :   This function acts as a commuter module for all events related to this window.

    Notes       :   Commuter Modules are automatically called from the Promoted_Events function which is called by the
                    application-specific promoted event handler. This makes it possible to add QuickEvents that need to
                    execute Basic+ logic without having use the Form Designer to make the association, although this is
                    limited to the events which are currently promoted.

                    If the form needs to call the commuter module directly then the QuickEvent parameters should be
                    formatted like this:

                        '@SELF','@EVENT',['@PARAM1','@PARAMx']

    Parameters  :
        CtrlEntId   [in] -- The fully qualified name of the control calling the promoted event
        Event       [in] -- The event being executed. See the Notes section regarding "PRE" events
        Param1-15   [in] -- Additional event parameter holders
        EventFlow  [out] -- Set to 1 or 0 so the calling event knows whether or not to chain forward. See comments in
                            EVENT_SETUP insert

    History     :   (Date, Initials, Notes)
        04/17/24    djs     Replaced BACKCOLOR Set_Property calls with ENABLED -1 calls (disabled hard) in order to
                            work around an OI 10 migration bug.

***********************************************************************************************************************/
#pragma precomp SRP_PreCompiler
#window REACT_MODE_CHG_NG

$Insert EVENT_SETUP
$Insert APP_INSERTS
$Insert REACT_MODE_EQUATES
$Insert REACT_MODE_NG_EQUATES
$Insert REACTOR_MODES_EQUATES
$Insert REACT_MODE_EQU			;* THESE ARE NOT THE SAME jch, Update 9/15/21. These are the equates for the CONFIG records
$Insert MSG_EQUATES
$Insert RLIST_EQUATES
$Insert REACT_PROB_CAT_EQUATES
$Insert REACTOR_LOG_EQU
$Insert REACT_UTIL_EQU
$Insert WO_LOG_EQU
$Insert REACTOR_CHILD_KEY_IDS_EQUATES
$Insert REACTOR_EQUATES
$Insert POPUP_EQUATES
$insert Message_Box_Equates

Declare function   center_window, msg, Memberof, Get_Property, NextKey, next_key, rowexists, Get_Status
Declare function   SRP_Array, start_window, Dialog_Box, Reactor_Log_Services, Reactor_Modes_Services, GetTickCount
Declare function   Reactor_Services, Error_Services, Logging_Services, Environment_Services, Database_Services
Declare function   SRP_List, Nica_Orders_Services
Declare subroutine RList, Set_Property, Set_List_Box_Data, end_dialog, record_lock, obj_React_Mode, ErrMsg
Declare subroutine Mona_Services, Reactor_Services, Error_Services, obj_React_Status, Logging_Services
Declare subroutine Database_Services, Override_Log_Services, SRP_List, Message_Box, Reactor_Log_Services
Declare subroutine Nica_Orders_Services

GoToEvent Event for CtrlEntId else
    // Event not implemented
end

Return EventFlow or 1

//-----------------------------------------------------------------------------
// EVENT HANDLERS
//-----------------------------------------------------------------------------

Event WINDOW.CREATE(CreateParam)
    
    Reactor				= CreateParam[1,'*']
    Wo					= CreateParam[COL2()+1,'*']
    ForceModeChange 	= CreateParam[COL2()+1,'*']
    FourthParm			= CreateParam[COL2()+1,'*']
    LeakLampAutoFlag	= (FourthParm = 1 )
    
    IF INDEX(CreateParam,'CENTER',1 ) THEN
        void = center_window( @WINDOW )
    END ELSE
        Void = Set_Property( @WINDOW, 'VISIBLE', 1 )
    END 
    
    EventFlow = 1
    
    // Get List of Reactor Modes
    CurrentMode = Reactor_Services('GetReactCurrModeName', Reactor)
    ModeList = Reactor_Modes_Services('AvailableModes', CurrentMode, @User4, Reactor)
    Set_Property(@Window : '.MODE', 'LIST', ModeList)
    // End of Get list of Reactor Modes
    
    // Find the current REACT_MODE OR REACT_MODE_NG record.
    OldGenReactModeKey = XLATE('REACTOR_CHILD_KEY_IDS', Reactor, REACTOR_CHILD_KEY_IDS_REACT_MODE_KEY_IDS$, 'X')
    NewGenReactModeKey = XLATE('REACTOR_CHILD_KEY_IDS_NG', Reactor, REACTOR_CHILD_KEY_IDS_REACT_MODE_KEY_IDS$, 'X')
    OldGenReactModeDTM = Field(OldGenReactModeKey, '*', 2)
    NewGenReactModeDTM = Field(NewGenReactModeKey, '*', 2)
    
    ReactModeKeyToUse = ''
    If OldGenReactModeDTM GT NewGenReactModeDTM then
        ReactModeKeyToUse = OldGenReactModeKey
        GoSub TranslateOldCodes
    end
    If NewGenReactModeDTM GT OldGenReactModeDTM then
        ReactModeKeyToUse = NewGenReactModeKey
    end
    // End find the current REACT_MODE OR REACT_MODE_NG record.
    
    Set_List_Box_Data( @WINDOW )
    // Check for Groups allowed to change
    IF memberof( @USER4, 'DATA_ENTRY' ) OR memberof( @USER4, 'SUPERVISOR' ) OR memberof( @USER4, 'MAINTENANCE' ) OR @USER4 EQ 'JONATHAN_O' THEN
        IF Reactor NE '' THEN
            * called from status window and createparam is the reactor number
            * so simply READ and lock
            OPEN 'CONFIG' TO ConfigTable ELSE
                Void = msg( '', 'Unable to open CONFIG table...' )
                RETURN 0
            END
            LOCK ConfigTable, 'REACT_MODE':Reactor THEN
                
                IF ForceModeChange THEN
                    Set_Property(@Window : '.CANCEL', 'ENABLED', 0)
                    Set_Property(@Window : '.APPLY', 'ENABLED', 1)
                END
            END ELSE
                Set_Property(@Window : '.MODE', 'ENABLED', 0)
                Set_Property(@Window : '.REACTMODESVC', 'ENABLED', 0)
                Set_Property(@Window : '.CANCEL', 'TEXT', 'OK')
                MsgInfo = ''
                MsgInfo<mtext$> = 'Reactor ':Reactor:' is currently being set to another mode...'
                MsgInfo<micon$> = '!'
                NotSignedRL = 1
                Void = msg( '', MsgInfo )
            END
            GOSUB DoRead
            unlock ConfigTable, 'REACT_MODE':Reactor else NULL
        END ELSE
            * let them enter the reactor number and get a lock on the onchange event
            Set_Property(@Window : '.reactor_no', 'ENABLED', 1)
        END	;* End of check for Non-Null Reactor No 
    END ELSE
        Set_Property(@Window : '.MODE', 'ENABLED', 0)
        Set_Property(@Window : '.REACTMODESVC', 'ENABLED', 0)
        Set_Property(@Window : '.CANCEL', 'TEXT', 'OK')
        GOSUB DoRead
    END	;* End of check for Groups allowed to change
    
    OriginalCommentSize = Get_Property(@Window:'.EDB_COMMENT', 'SIZE')
    Set_Property(@Window, '@EDB_COMMENT_ORIG_SIZE', OriginalCommentSize)
    
End Event


Event MODE.CHANGED()
    
	Set_Property(@Window:'.EDB_COMMENT', 'TEXT', '')
    
    OrigMode = Get_Property(@Window: '.CURRENT_MODE', 'TEXT')
    NewMode = Get_Property(@Window : '.MODE', 'TEXT')
    
    IF OrigMode NE NewMode then
        Set_Property(@Window : '.APPLY', 'ENABLED', 1)
        Set_Property(@Window : '.REACTMODESVC', 'TEXT', '')
    end else
        Set_Property(@Window : '.APPLY', 'ENABLED', 1)
    end
    
    CatDesc = Xlate('REACTOR_MODES', NewMode, REACTOR_MODES_SERVICE_CATEGORIES$, 'X')
    Swap @VM with @FM in CatDesc
    
    Set_Property(@Window : '.REACTMODESVC', 'VISIBLE', 1)
    Set_Property(@Window : '.REACTMODESVC', 'ENABLED', 1)
    Set_Property(@Window : '.REACTMODESVC', 'LIST', CatDesc)
    Set_Property(@Window : '.SERV_LABEL', 'VISIBLE', 1)
    
    IF NewMode EQ 'CHANGEOVER_SCHEDULED' then
        //GoSub ChangeOverAutoSet
    end
    
    If (NewMode _NEC 'WAITING_FOR_MAINTENANCE_UNSCHEDULED') and (NewMode _NEC 'WAITING_FOR_ENGTECH_UNSCHEDULED') then
    	GoSub HideDropDownComments
    end
    
end event


Event REACTMODESVC.CHANGED()
    
	Set_Property(@Window:'.EDB_COMMENT', 'TEXT', '')
	
	UseDropDownComments = 0
	NewMode             = Get_Property(@Window : '.MODE', 'TEXT')
	SvcCat              = Get_Property(@Window:'.REACTMODESVC', 'TEXT')
	
	If NewMode _EQC 'WAITING_FOR_MAINTENANCE_UNSCHEDULED' then
		AvailableMaintComments = Xlate('APP_INFO', 'REACT_MODE_CHANGE_MAINT_COMMENT_OPTIONS', 1, 'X')
		Swap @VM with @FM in AvailableMaintComments
		Set_Property(@Window:'.COB_COMMENT', 'LIST', AvailableMaintComments)
		UseDropDownComments += 1
	end
	
	If NewMode _EQC 'WAITING_FOR_ENGTECH_UNSCHEDULED' then
		AvailableEngrComments  = Xlate('APP_INFO', 'REACT_MODE_CHANGE_ENGR_COMMENT_OPTIONS', 1, 'X')
		Swap @VM with @FM in AvailableEngrComments
		Set_Property(@Window:'.COB_COMMENT', 'LIST', AvailableEngrComments)
		UseDropDownComments   += 1
	end
    
    If SvcCat _EQC 'WF-PARTICLES' then
    	UseDropDownComments += 1
    end
	
	If UseDropDownComments GT 1 then
		Set_Property(@Window:'.COB_COMMENT', 'ENABLED', True$)
		Set_Property(@Window:'.COB_COMMENT', 'VISIBLE', True$)
		OriginalCommentSize = Get_Property(@Window, '@EDB_COMMENT_ORIG_SIZE')
		CommentSize         = Get_Property(@Window, '@EDB_COMMENT_ORIG_SIZE')
		CommentSize<2>      = CommentSize<2> + 37
		CommentSize<4>      = 65
		Set_Property(@Window:'.EDB_COMMENT', 'SIZE', CommentSize)
		Set_Property(@Window:'.COB_COMMENT', 'TEXT', '')
		Set_Property(@Window:'.EDB_COMMENT', 'ENABLED', -1)
	end else
		GoSub HideDropDownComments
	end
	
end event


Event APPLY.CLICK()
    
    // Initialize Logging
    LogPath = Environment_Services('GetApplicationRootPath') : '\ReactMode\LogFiles'
    Date            = Oconv(Date(), 'D4/')
    LogFileName     = Date[7, 4] : '-' : Date[1, 2] : '-' : Date[4, 2] : ' ReactMode Log.csv'
    Headers         = 'Logging DTM' : @FM : 'Description'
    ColumnWidths    = 20 : @FM : 250
    objLog          = Logging_Services('NewLog', LogPath, LogFilename, CRLF$, ' ', Headers, ColumnWidths, False$, False$)
    
    ReactNo         = Get_Property(@WINDOW:'.REACTOR_NO','TEXT')
    NewMode         = Get_Property(@Window : '.MODE', 'TEXT')
    NewReactModeSvc = Get_Property(@WINDOW:'.REACTMODESVC','TEXT')	;* .reactmodesvc->text
    
    NewNoteText     = ''
    CobCommentEnabled = Get_Property(@Window:'.COB_COMMENT', 'ENABLED')
    If CobCommentEnabled then
    	SelectedComment = Get_Property(@Window:'.COB_COMMENT', 'TEXT')
		If SelectedComment _EQC 'other' then
			NewNoteText = Get_Property(@Window:'.EDB_COMMENT', 'TEXT')
		end else
			NewNoteText = SelectedComment
		end
    end else
    	NewNoteText = Get_Property(@Window:'.EDB_COMMENT', 'TEXT')
    end
    
    CurrentModeRecord = Reactor_Services('GetReactCurrModeRec', ReactNo)
    CurrentMode = CurrentModeRecord<REACT_MODE_NG_MODE$>
    CurrentServiceDesc = CurrentModeRecord<REACT_MODE_NG_SERVICE_DESC$>
    If (CurrentMode _EQC 'test_scheduled' or CurrentMode _EQC 'test_unscheduled') and CurrentServiceDesc _EQC 'spv test' then
		ReactType = Xlate('REACTOR', ReactNo, REACTOR_REACT_TYPE$, 'X')
		If Len(ReactType) GE 3 and ReactType[1, 3] _EQC 'HTR' then
			Message = 'Remember to load the production recipe. Please find another employee to confirm this has been done.'
			Verification = Dialog_Box('NDW_VERIFY_USER', @WINDOW, '':@FM:'':@FM:'':@FM:Message)
			ValidVerification = Verification<1> and Verification<2> NE @User4
			If ValidVerification EQ True$ then
				ConfirmNote = 'Confirmed production recipe loaded'
				Reactor_Log_Services('AddComment', ReactNo, ConfirmNote, Verification<2>)
			end else
				If Verification<1> NE True$ then
					Message_Box(@Window, 'Invalid signature!', "Error", MSG_ICON_EXCLAM$)
				end else
					Message_Box(@Window, 'You must get another user to confirm the production recipe is loaded!', "Error", MSG_ICON_EXCLAM$)
				end
				Error_Services('Add', 'Post HTR SPV test recipe verification not complete')
			end
		end
    end
	
    If Error_Services('NoError') then
    	
		Def            = ""
		Def<MCAPTION$> = "Changing Reactor Mode..."
		Def<MCOL$>     = -2
		Def<MROW$>     = -2
		Def<MTYPE$>    = "U"
		MsgHandle      = Msg(@Window, Def)
		
    	Reactor_Services('CreateReactModeChange', @User4, ReactNo, NewMode, NewReactModeSvc, NewNoteText)
    	
    	// Take down the message
    	Msg(@Window, MsgHandle)
    	
		If Error_Services('NoError') then
			
			End_Dialog(@Window, NewMode)
			
		end else
			
			Error_Services('DisplayError')
			ReactorRec           = Database_Services('ReadDataRow', 'REACTOR', ReactNo)
			If Error_Services('NoError') then
				ActiveProveInOrder    = ReactorRec<REACTOR_PROVE_IN_ACTIVE$>
				ActiveHgCVOrder       = ReactorRec<REACTOR_HGCV_CHECKLIST_ACTIVE$>
				ActiveIntrMaintOrder  = ReactorRec<REACTOR_INTRUSIVE_MAINT_CHECKLIST_ACTIVE$>
			    ActiveAbortAlarmOrder = ReactorRec<REACTOR_ABORT_ALARM_CHECKLIST_ACTIVE$>
				Begin Case
					
					Case ActiveProveInOrder
						
						OverrideGroups   = 'LEAD':@VM:'SUPERVISOR'
						UserMsg          = "Reactor prove in must be processed in NICA. Override required from a lead or supervisor to bypass NICA."
						UserVerification = Dialog_Box('NDW_VERIFY_USER', @WINDOW, @USER4:@FM:OverrideGroups:@FM:'':@FM:UserMsg)
						Override         = UserVerification<1>
						If Override EQ True$ then
							ProveInOrderIds = Reactor_Services('GetActiveProveInOrderIds', ReactNo)
							If (DCount(ProveInOrderIds, @VM) GT 1) then 
								ProveInTypes         = Xlate('NICA_ORDERS', ProveInOrderIds, 'ORDER_TYPE', 'X')
								OverrideData         = Dialog_Box('PROVE_IN_OVERRIDE', @Window, ReactNo)
								ProveInTypesToCancel = OverrideData<1, 1>
								ResponseComment      = ''
								For each ProveInType in ProveInTypes using @VM setting Idx
									Locate ProveInType in ProveInTypesToCancel using @VM setting Unused then
										ProveInOrderId = ProveInOrderIds<0, Idx>
										Nica_Orders_Services('CancelOrder', ProveInOrderId)
										If ResponseComment NE '' then ResponseComment := ', '
										ResponseComment := ProveInType									
									end
								Next ProveInType
								ResponseComment := ': '
								ResponseComment := OverrideData<2, 1>
								Override_Log_Services('Create', 'REACTOR', ReactNo, UserVerification<2>, ResponseComment, 'REACTOR_PROVE_IN')
								Reactor_Services('CreateReactModeChange', @User4, ReactNo, NewMode, NewReactModeSvc, NewNoteText)
								If Error_Services('NoError') then End_Dialog(@Window, NewMode)						
							end else
								ResponseComment = Dialog_Box('NDW_ADD_COMMENT', @WINDOW)<2>
								If Assigned(ResponseComment) and Len(ResponseComment) GT 4 then
									Nica_Orders_Services('CancelOrder', ProveInOrderIds<0, 1>)
									Override_Log_Services('Create', 'REACTOR', ReactNo, UserVerification<2>, ResponseComment, 'REACTOR_PROVE_IN')
									Reactor_Services('CreateReactModeChange', @User4, ReactNo, NewMode, NewReactModeSvc, NewNoteText)
									If Error_Services('NoError') then End_Dialog(@Window, NewMode)
								end else
									Message_Box(@Window, 'You must enter a comment greater than 4 letters!', 'Error', MSG_ICON_EXCLAM$)
								end
							end
						end					
						
					Case ActiveHgCVOrder

						OverrideGroups   = 'LEAD':@VM:'SUPERVISOR'
						UserMsg          = "HgCV OCAP Checklist must be completed in NICA. Override required from a lead or supervisor to bypass NICA."
						UserVerification = Dialog_Box('NDW_VERIFY_USER', @WINDOW, @USER4:@FM:OverrideGroups:@FM:'':@FM:UserMsg)
						Override         = UserVerification<1>
						If Override then
							
							ResponseComment = Dialog_Box('NDW_ADD_COMMENT', @WINDOW)<2>
							If Assigned(ResponseComment) and Len(ResponseComment) GT 4 then
								ActiveHgCVOrders = Nica_Orders_Services('GetActiveOrders', 'REACTOR', ReactNo, 'IQS_HGCV_ALARM')
								For each ActiveHgCVOrderId in ActiveHgCVOrders using @VM
									Nica_Orders_Services('CancelOrder', ActiveHgCVOrderId)
								Next ActiveHgCVOrderId
								
								Override_Log_Services('Create', 'REACTOR', ReactNo, UserVerification<2>, ResponseComment, 'HGCV_OCAP_CHECKLIST')
							
								Reactor_Services('CreateReactModeChange', @User4, ReactNo, NewMode, NewReactModeSvc, NewNoteText)
								If Error_Services('NoError') then
									End_Dialog(@Window, NewMode)
								end
							end else
								Message_Box(@Window, 'You must enter a comment greater than 4 letters!', 'Error', MSG_ICON_EXCLAM$)
							end
						end
						
					Case ActiveIntrMaintOrder

						OverrideGroups   = 'LEAD':@VM:'SUPERVISOR'
						UserMsg          = "Intrusive Maintenance Checklist must be completed in NICA. Override required from a lead or supervisor to bypass NICA."
						UserVerification = Dialog_Box('NDW_VERIFY_USER', @WINDOW, @USER4:@FM:OverrideGroups:@FM:'':@FM:UserMsg)
						Override         = UserVerification<1>
						If Override then
							
							ResponseComment = Dialog_Box('NDW_ADD_COMMENT', @WINDOW)<2>
							If Assigned(ResponseComment) and Len(ResponseComment) GT 4 then
								ActiveIntrMaintOrders = Nica_Orders_Services('GetActiveOrders', 'REACTOR', ReactNo, 'INTRUSIVE_MAINT')
								For each ActiveIntrMaintOrderId in ActiveIntrMaintOrders using @VM
									Nica_Orders_Services('CancelOrder', ActiveIntrMaintOrderId)
								Next ActiveIntrMaintOrderId
								
								Override_Log_Services('Create', 'REACTOR', ReactNo, UserVerification<2>, ResponseComment, 'INTR_MAINT_CHECKLIST')
							
								Reactor_Services('CreateReactModeChange', @User4, ReactNo, NewMode, NewReactModeSvc, NewNoteText)
								If Error_Services('NoError') then
									End_Dialog(@Window, NewMode)
								end
							end else
								Message_Box(@Window, 'You must enter a comment greater than 4 letters!', 'Error', MSG_ICON_EXCLAM$)
							end
						end
						
					Case ActiveAbortAlarmOrder
					    
						OverrideGroups   = 'LEAD':@VM:'SUPERVISOR'
						UserMsg          = "ABORT/ALARM Checklist must be completed in NICA. Override required from a lead or supervisor to bypass NICA."
						UserVerification = Dialog_Box('NDW_VERIFY_USER', @WINDOW, @USER4:@FM:OverrideGroups:@FM:'':@FM:UserMsg)
						Override         = UserVerification<1>
						If Override then
							
							ResponseComment = Dialog_Box('NDW_ADD_COMMENT', @WINDOW)<2>
							If Assigned(ResponseComment) and Len(ResponseComment) GT 4 then
								ActiveIntrMaintOrders = Nica_Orders_Services('GetActiveOrders', 'REACTOR', ReactNo, 'ABORT_ALARM')
								For each ActiveIntrMaintOrderId in ActiveIntrMaintOrders using @VM
									Nica_Orders_Services('CancelOrder', ActiveIntrMaintOrderId)
								Next ActiveIntrMaintOrderId
								
								Override_Log_Services('Create', 'REACTOR', ReactNo, UserVerification<2>, ResponseComment, 'ABORT_ALARM_CHECKLIST')
							
								Reactor_Services('CreateReactModeChange', @User4, ReactNo, NewMode, NewReactModeSvc, NewNoteText)
								If Error_Services('NoError') then
									End_Dialog(@Window, NewMode)
								end
							end else
								Message_Box(@Window, 'You must enter a comment greater than 4 letters!', 'Error', MSG_ICON_EXCLAM$)
							end
						end					    
						
				End Case
			end else
				Error_Services('DisplayError')
			end
		end
    end
    
    EventFlow = 0   

end event


Event RL_BUTTON.CLICK()

    If Get_Property('NDW_MAIN', 'VISIBLE') then
        AppMain = 'NDW_MAIN'
    end else
        AppMain = 'LSL_MAIN2'
    end

    ReactorLogID = Get_Property(@Window : '.RLID', 'TEXT')

    //Void = start_window( 'REACTOR_LOG', AppMain, ReactorLogID:'*CENTER', '', '' )
    Void = Dialog_Box('REACTOR_LOG', AppMain, ReactorLogID:'*CENTER')
    void = Set_Property('REACTOR_LOG','@PARENT','REACT_MODE_CHG_NG')

    If Reactor_Log_Services('IsMaint', ReactorLogID) AND Reactor_Log_Services('IsSigned', ReactorLogID) then
        Set_Property(@Window : '.MODE', 'ENABLED', 1)
    end

    EventFlow = 0
    
end event


Event CANCEL.CLICK()
    
    Reactor = Get_Property(@Window : '.REACTOR_NO', 'TEXT')
    CurMode = Get_Property(@Window: '.CURRENT_MODE','TEXT')
    End_Dialog(@Window, CurMode)
    
end event


Event COB_COMMENT.CHANGED()
    
	Set_Property(@Window:'.EDB_COMMENT', 'TEXT', '')
	Comment = Get_Property(@Window:'.COB_COMMENT', 'TEXT')
	If Comment _EQC 'other' then
		Set_Property(@Window:'.EDB_COMMENT', 'ENABLED', True$)
	end else
		Set_Property(@Window:'.EDB_COMMENT', 'ENABLED', -1)
	end
	
end event

//-----------------------------------------------------------------------------
// INTERNAL GOSUBS
//-----------------------------------------------------------------------------

DoRead:

    // Pull in the full REACT_MODE or REACT_MODE_NG record.
    CurReactModeRec = XLATE('REACT_MODE', ReactModeKeyToUse, '','X')
    If CurReactModeRec EQ '' then
        //If CurReactModeRec is blank then check the NG table for that record.
        CurReactModeRec = XLATE('REACT_MODE_NG', ReactModeKeyToUse, '','X')
    end

    // This basically pulls in redundant information from a config table
    Rec = XLATE( 'CONFIG', 'REACT_MODE_NG':Reactor, '', 'X' )
    If Rec = '' then
        Rec = XLATE( 'CONFIG', 'REACT_MODE':Reactor, '', 'X' )
    end
    Service	= Rec<Service$>
    Note	= Rec<Note$>
    Mode = Rec<Mode$>
    ReactLogID = Rec<ReactorLogID$>
    ReactLogCat = XLATE('REACTOR_LOG', ReactLogID, 6, 'X')

    IF ReactLogID NE '' then
        IF Reactor_Log_Services('IsMaint', ReactLogID)  then
            Set_Property(@Window : '.RL_BUTTON', 'VISIBLE', 1)
            IF NOT(Reactor_Log_Services('IsSigned', ReactLogID)) then
                * DO NOT ALLOW A MODE CHANGE CAUSE THE REACTOR LOG IS STILL OPEN
                MsgInfo = ''
                MsgInfo<mtext$> = 'You are not allowed to change the mode because the maintenance tech has not signed off on the reactor log entry...'
                MsgInfo<micon$> = '!'
                Set_Property(@Window : '.MODE', 'ENABLED', 0);
                NotSignedRL = 1
                Void = msg( '', MsgInfo )
            end
                
        end else
            * ALLOW A MODE CHANGE CAUSE IT HAS BEEN SIGNED BY A MAINTENANCE TECHNICIAN
        end
    end


    Set_Property(@WINDOW:'.REACTOR_NO','TEXT', Reactor)
    Set_Property(@WINDOW:'.USERNAME','TEXT', Rec<Username$>)
    Set_Property(@WINDOW:'.DATE','TEXT', Rec<Date$>)
    Set_Property(@WINDOW:'.TIME','TEXT', Rec<Time$>)
    Set_Property(@WINDOW:'.CURRENT_MODE','TEXT', Mode)
    Set_Property(@WINDOW:'.CURRENT_REACTMODESVC','TEXT', Service)
    Set_Property(@WINDOW:'.RUID','TEXT', Rec<ReactUtilID$>)
    Set_Property(@WINDOW:'.RLID','TEXT', Rec<ReactorLogID$>)
    Set_Property(@WINDOW:'.WO','TEXT', Wo)

    IF Service THEN
        Set_Property(@WINDOW:'.REACTMODESVC','VISIBLE',TRUE$)
        Set_Property(@WINDOW:'.SERV_LABEL','VISIBLE',TRUE$)
        Set_Property(@WINDOW:'.REACTMODESVC','ENABLED', 0)			;* Do not allow them to change the service until they change the mode
    END

    // Get Possible Modes here
    ModeList = ''
    ModeList = Reactor_Modes_Services('AvailableModes', Mode, @User4, Reactor)
    Set_Property(@Window : '.MODE', 'LIST', ModeList)
    
return


TranslateOldCodes:

    ReactorModeList  = Xlate('SYSREPOSPOPUPS', @APPID<1>:'**':'REACTOR_MODE', PDISPLAY$, 'X')
    ReactorModeArray = ReactorModeList<8>
    Convert @VM to @FM in ReactorModeArray
    Convert @SVM to @VM in ReactorModeArray

    CurReactModeCode = XLATE('REACT_MODE', ReactModeKeyToUse, REACT_MODE_MODE$, 'X')

    Locate CurReactModeCode in ReactorModeArray using @FM setting CodePos then
        NewMode = ReactorModeArray<CodePos, 2>
    end
    
return


CheckReactorLogStatus:
    
return


ChangeOverAutoSet:

    LastWO = ''
    NextWO = ''
    
return


HideDropDownComments:
    
	Set_Property(@Window:'.COB_COMMENT', 'ENABLED', False$)
	Set_Property(@Window:'.COB_COMMENT', 'VISIBLE', False$)
	Set_Property(@Window:'.EDB_COMMENT', 'ENABLED', True$)
	Set_Property(@Window:'.EDB_COMMENT', 'VISIBLE', True$)
	OriginalCommentSize = Get_Property(@Window, '@EDB_COMMENT_ORIG_SIZE')
	Set_Property(@Window:'.EDB_COMMENT', 'SIZE', OriginalCommentSize)
	Set_Property(@Window:'.COB_COMMENT', 'TEXT', '')
	
return

