Compile function PROVE_IN_OVERRIDE_EVENTS(CtrlEntId, Event, @PARAMS)
#pragma precomp SRP_PreCompiler
#window PROVE_IN_OVERRIDE

$Insert APP_INSERTS
$insert Message_Box_Equates

Declare subroutine Placedialog, Message_Box
Declare function   Nica_Orders_Services, Reactor_Services

GoToEvent Event for CtrlEntId else
    // Event not implemented
end

Return EventFlow or 1

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

Event WINDOW.CREATE(CreateParam)
	
	ReactNo = CreateParam
	
    Placedialog(-2, -2)
    
    ActiveProveInOrders = Reactor_Services('GetActiveProveInOrderIds', ReactNo)
    If ActiveProveInOrders NE '' then
    	OrderTypes = Xlate('NICA_ORDERS', ActiveProveInOrders, 'ORDER_TYPE', 'X')
		For each OrderType in OrderTypes using @VM
			Begin Case
				Case OrderType _EQC 'CHANGEOVER'
					Set_Property(@Window:'.CHB_CHANGEOVER', 'ENABLED', True$)
				Case OrderType _EQC 'INITIATE_IDLE'
					Set_Property(@Window:'.CHB_IDLE_SHUTDOWN', 'ENABLED', True$)
				Case OrderType _EQC 'IDLE'
					Set_Property(@Window:'.CHB_IDLE_STARTUP', 'ENABLED', True$)
				Case Otherwise$
					Null
			End Case
		Next OrderType
    end else
    	ErrorMsg = 'No active prove in NICA orders found for reactor ':ReactNo:'.'
    	Msg(@Window, '', 'OK', '', 'Error':@FM:ErrorMsg)
    end
    
End Event


Event PUB_SUBMIT.CLICK()
	
	OverrideData = ''
	
	SelectedTypes = ''
	If Get_Property(@Window:'.CHB_CHANGEOVER', 'CHECK') then
		SelectedTypes = "CHANGEOVER"
	end		
	If Get_Property(@Window:'.CHB_IDLE_SHUTDOWN', 'CHECK') then
		If SelectedTypes NE '' then
			SelectedTypes := @VM
		end
		SelectedTypes := 'INITIATE_IDLE'
	end	
	If Get_Property(@Window:'.CHB_IDLE_STARTUP', 'CHECK') then
		If SelectedTypes NE '' then
			SelectedTypes := @VM
		end
		SelectedTypes := 'IDLE'
	end		
	If Get_Property(@Window:'.CHB_INTRUSIVE_MAINT', 'CHECK') then
		If SelectedTypes NE '' then
			SelectedTypes := @VM
		end
		SelectedTypes := 'INTRUSIVE_MAINT'
	end
	
	If SelectedTypes EQ '' then
		Message_Box(@Window, "You must select at least one prove in type!", "Error", MSG_ICON_EXCLAM$)
		return
	end else
		OverrideData<1, 1> = SelectedTypes
	end
	
	OverrideData<2, 1> = Get_Property(@Window:'.EDB_COMMENT', 'TEXT')
	
	If OverrideData<2, 1> EQ '' or Len(OverrideData<2, 1>) LT 4 then
		Message_Box(@Window, "Your comment must be at least 4 characters!", "Error", MSG_ICON_EXCLAM$)
		return
	end	
	
	End_Dialog(@Window, OverrideData)
	
end event


Event PUB_CANCEL.CLICK()
	
	End_Dialog(@Window, '')
	
end event

