DECLARE CONSTANT Datapool_Markets				AS QUANTITY 17
DECLARE CONSTANT Datapool_Sectors				AS QUANTITY 103

DECLARE CONSTANT CMB_StatisticTypes				AS QUANTITY 2023
DECLARE CONSTANT CMB_EntityID					AS QUANTITY 2024

DECLARE CONSTANT iFLD_SYMBOL 	AS QUANTITY 0
DECLARE CONSTANT iFLD_TYPE 		AS QUANTITY 8

DECLARE CONSTANT LBL_InsType				AS QUANTITY 6000
DECLARE CONSTANT CMB_InsType				AS QUANTITY 6001
DECLARE CONSTANT LBL_InstrumentID			AS QUANTITY 6002
DECLARE CONSTANT CMB_Instrument				AS QUANTITY 6003
DECLARE CONSTANT LBL_MarketID				AS QUANTITY 6004
DECLARE CONSTANT CMB_Market					AS QUANTITY 6005
DECLARE CONSTANT LBL_SectorID				AS QUANTITY 6006
DECLARE CONSTANT CMB_Sector					AS QUANTITY 6007
DECLARE VARIABLE s_SelectedInstType		AS TEXT 	100

DECLARE CONSTANT DATA_POOL_EQT_INST 	AS QUANTITY 19

PROCEDURE OnInitForm DO
{
	[s_SelectedInstType] := ""; 
}


###############################################################################
PROCEDURE InitializeFilterCtrl DO
{
	CALL UpdateFromPool Datapool_Markets, CMB_Market; 
	CALL UpdateFromPool Datapool_Sectors, CMB_Sector; 
}

PROCEDURE OnTypeTabChange
        DECLARE PARAMETER sVal as TEXT DO
{
	IF ([sVal] = "Instrument") THEN
	{
		ShowHideCtrl(LBL_InsType,1);
		ShowHideCtrl(CMB_InsType,1);
		ShowHideCtrl(LBL_InstrumentID,1);
		ShowHideCtrl(CMB_Instrument,1);
		ShowHideCtrl(LBL_MarketID,0);
		ShowHideCtrl(CMB_Market,0);
		ShowHideCtrl(LBL_SectorID,0);
		ShowHideCtrl(CMB_Sector,0);	
		
		MoveCtrlEx(LBL_InsType,6,35,20,100);
		MoveCtrlEx(CMB_InsType,107,35,20,80);
		MoveCtrlEx(LBL_InstrumentID,195,35,20,69);
		MoveCtrlEx(CMB_Instrument,265,35,20,90);
	}
	ELSE IF ([sVal] = "Sector") THEN
	{
		ShowHideCtrl(LBL_InsType,0);
		ShowHideCtrl(CMB_InsType,0);
		ShowHideCtrl(LBL_InstrumentID,0);
		ShowHideCtrl(CMB_Instrument,0);
		ShowHideCtrl(LBL_MarketID,0);
		ShowHideCtrl(CMB_Market,0);
		ShowHideCtrl(LBL_SectorID,1);
		ShowHideCtrl(CMB_Sector,1);	
		
		MoveCtrlEx(LBL_SectorID,6,35,20,57);
		MoveCtrlEx(CMB_Sector,65,35,20,80);
	}
	ELSE IF ([sVal] = "Market") DO
	{
		ShowHideCtrl(LBL_InsType,0);
		ShowHideCtrl(CMB_InsType,0);
		ShowHideCtrl(LBL_InstrumentID,0);
		ShowHideCtrl(CMB_Instrument,0);
		ShowHideCtrl(LBL_MarketID,1);
		ShowHideCtrl(CMB_Market,1);
		ShowHideCtrl(LBL_SectorID,0);
		ShowHideCtrl(CMB_Sector,0);	
		
		MoveCtrlEx(LBL_MarketID,6,35,20,60);
		MoveCtrlEx(CMB_Market,68,35,20,110);
	}
}
       
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] = CMB_InsType) DO
  	{  		
  		CALL PopulateInstrumentList [sVal];
  	}
}

PROCEDURE PopulateInstrumentList
        DECLARE PARAMETER sSelectedInstType as TEXT DO
{
	RemoveListEntry2(CMB_Instrument,"");
	[s_SelectedInstType] := [sSelectedInstType] ;
	
	IF ([sSelectedInstType] = "Equity") DO
	{			  
		SetControlPool(CMB_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
					
	[nCount] := GetObjPoolItemCount(1);
	[nIndex] := 0;
	[sKey] := "";
	[sFieldVal] := "";	
	
	WHILE ([nIndex] < [nCount]) DO
	{		
		[sKey] := GetObjPoolItemKey(1,[nIndex]);
		[sFieldVal] := GetObjPoolItemVal(1,[sKey],iFLD_TYPE);
		IF ([sFieldVal] = [sSelectedInstType]) DO
		{			  
			[sFieldVal] := GetObjPoolItemVal(1,[sKey],iFLD_SYMBOL);
			AddListEntry3(CMB_Instrument,[sFieldVal]);		
		}
		
		[nIndex] := ([nIndex] + 1);
	}	
}


PROCEDURE UpdateFromPool 
	DECLARE PARAMETER nPoolID as QUANTITY
	DECLARE PARAMETER nCtrlId as QUANTITY DO
{

	DECLARE VARIABLE nCount AS QUANTITY
	DECLARE VARIABLE nIndex AS QUANTITY
	DECLARE VARIABLE sInstVal 			AS TEXT		100 
	
	RemoveListEntry2([nCtrlId], "");
	[nCount] := GetObjPoolItemCount([nPoolID]);	
	[nIndex] := 0;
	[sInstVal] := "";
	
	WHILE ( [nIndex] < [nCount] ) DO
	{		
		[sInstVal] := GetObjPoolItemKey( [nPoolID], [nIndex] );
		AddListEntry1([nCtrlId], [sInstVal],"");
				
		IF ( [nIndex] = 0) DO
		{
			SetFieldValue1([nCtrlId], [sInstVal]);	
		}
		
		[nIndex] := ( [nIndex] + 1 );	
	}	

}

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