# Serendib Field ID for the Form ctrls
DECLARE CONSTANT FLD_EnteredBy		AS QUANTITY	2182
DECLARE CONSTANT FLD_InstrumentType		AS QUANTITY	1
DECLARE CONSTANT FLD_Instrument		AS QUANTITY	2711
DECLARE CONSTANT FLD_Side	 			AS QUANTITY 2053
DECLARE CONSTANT FLD_Executed_Price	 			AS QUANTITY 2546
DECLARE CONSTANT FLD_Executed_Size	 			AS QUANTITY 2185

# Data pool IDS
DECLARE CONSTANT Datapool_Instrument				AS QUANTITY 1
DECLARE CONSTANT Datapool_FirmUsers					AS QUANTITY 16
DECLARE CONSTANT iFLD_SYMBOL 	AS QUANTITY 0
DECLARE CONSTANT iFLD_TYPE 		AS QUANTITY 8

DECLARE VARIABLE s_SelectedInstType		AS TEXT 	100
DECLARE CONSTANT DATA_POOL_EQT_INST 	AS QUANTITY 19

PROCEDURE OnInitForm DO
{

	# Set field values of the spin controls
	SetFieldValue1(FLD_Executed_Price, "");
	SetFieldValue1(FLD_Executed_Size, "");
	
	# Load All Firm users to the Entered By Combo Box
	
  	DECLARE VARIABLE nCount AS QUANTITY
	DECLARE VARIABLE nIndex AS QUANTITY
	DECLARE VARIABLE sFirmUser 			AS TEXT		100 

	RemoveListEntry2(FLD_EnteredBy, "");
	[nCount] := GetObjPoolItemCount(Datapool_FirmUsers);	
	[nIndex] := 0;
	[sFirmUser] := "";
	
	WHILE ( [nIndex] < [nCount] ) DO
	{		
		
		[sFirmUser] := GetObjPoolItemKey( Datapool_FirmUsers, [nIndex] );
		AddListEntry1(FLD_EnteredBy, [sFirmUser],"");
				
		[nIndex] := ( [nIndex] + 1 );	
	}
	
	# Load Side combo box
	
	SetControlPool(FLD_Side, FLD_Side);
	AddListEntry1(FLD_Side,"All","");		

	[s_SelectedInstType] := ""; 	

}


PROCEDURE OnChangeCombo
        DECLARE PARAMETER sGroupName as TEXT
        DECLARE PARAMETER sFieldName as TEXT
        DECLARE PARAMETER sVal as TEXT
        DECLARE PARAMETER nCurSel as QUANTITY
        DECLARE PARAMETER nControlID as QUANTITY DO
{

  IF ([nControlID] = FLD_InstrumentType) DO
  	{  		
  		Call LoadSymbolsOfDefinition [sVal];	
  	}

}

###############################################################################
PROCEDURE LoadSymbolsOfDefinition
	DECLARE PARAMETER sDefID AS TEXT	DO
{
	RemoveListEntry2(FLD_Instrument,"");
	[s_SelectedInstType] := [sDefID] ;
	
	IF ([sDefID] = "Equity") DO
	{			  
		SetControlPool(FLD_Instrument, DATA_POOL_EQT_INST);
		RETURN
	} 
	
	DECLARE VARIABLE nCount AS QUANTITY
	DECLARE VARIABLE nIndex AS QUANTITY
	DECLARE VARIABLE sKey AS TEXT 100
	DECLARE VARIABLE sFieldVal AS TEXT 100
	
	RemoveListEntry2(FLD_Instrument,"");
						
	[nCount] := GetObjPoolItemCount(Datapool_Instrument);
	[nIndex] := 0;
	[sKey] := "";
	[sFieldVal] := "";	
		
	WHILE ([nIndex] < [nCount]) DO
	{		
		[sKey] := GetObjPoolItemKey(Datapool_Instrument,[nIndex]);
		[sFieldVal] := GetObjPoolItemVal(Datapool_Instrument,[sKey],iFLD_TYPE);
		IF ([sFieldVal] = [sDefID]) DO
		{			  
			[sFieldVal] := GetObjPoolItemVal(Datapool_Instrument,[sKey],iFLD_SYMBOL);
			AddListEntry3(FLD_Instrument,[sFieldVal]);		
		}
	
		[nIndex] := ([nIndex] + 1);
	}	
}

PROCEDURE PopulateInstrumentListOnInstChange
       DECLARE PARAMETER sSelectedInstType as TEXT DO
{
	DECLARE VARIABLE sInst AS TEXT 100
	[sInst] := GetFieldValue1(FLD_Instrument);
	
	IF ( [sSelectedInstType] != [s_SelectedInstType] ) DO
	{
		CALL LoadSymbolsOfDefinition [sSelectedInstType];
		
		SetFieldValue1(FLD_Instrument,[sInst]);
		SetFieldValue1(FLD_InstrumentType,[sSelectedInstType]);
	}
}