
DECLARE CONSTANT ID_CHK_CUSTODIAN 			AS QUANTITY 5000
DECLARE CONSTANT ID_TXT_BROKER_ID 			AS QUANTITY 5001
DECLARE CONSTANT ID_TXT_BROKER_TYPE			AS QUANTITY 5002
DECLARE CONSTANT ID_TXT_CLIENT_ID 			AS QUANTITY 5003
DECLARE CONSTANT ID_TXT_CLIENT_TYPE 		AS QUANTITY 5004
DECLARE CONSTANT ID_TXT_JOINT_ACC_NO 		AS QUANTITY 5005

DECLARE CONSTANT ID_NOTIFY_CLIENT_ID 		AS QUANTITY 6000
DECLARE CONSTANT ID_NOTIFY_REG_ID 			AS QUANTITY 6001

#123316
DECLARE VARIABLE n_CLIENT_NAME_WND		 	AS QUANTITY
DECLARE CONSTANT Datapool_DefaultVals				AS QUANTITY 3
PROCEDURE OnInitForm DO
{
	StopKillFocusNotification();
	StopChangeNotification();
	
#123316
	[n_CLIENT_NAME_WND] := 0 ; 
}


PROCEDURE EnableCustodian 
	DECLARE PARAMETER sBrokeID as TEXT 
	DECLARE PARAMETER sBrokeType as TEXT DO
{
#	MessageBox([sBrokeID],"",1,1);
		
	SetFieldValue1( ID_TXT_BROKER_ID, [sBrokeID] );
	SetFieldValue1( ID_TXT_BROKER_TYPE, [sBrokeType] );
	SetFieldValue1( ID_TXT_CLIENT_TYPE, "" );
	SetFieldValue1( ID_TXT_JOINT_ACC_NO, "" );
	SetFieldValue1( ID_TXT_CLIENT_ID, "" );


	CALL PopulateClientName;
}

#123316
PROCEDURE RunClientNameWindowMode DO
{
	StopKillFocusNotification();
	StopChangeNotification();
	
	ShowHideCtrl(ID_TXT_BROKER_ID,0);
	ShowHideCtrl(8000,0);
	ShowHideCtrl(ID_TXT_BROKER_TYPE,0);
	ShowHideCtrl(3800,0);
	ShowHideCtrl(3802,0);
	ShowHideCtrl(ID_TXT_JOINT_ACC_NO,0);
	
	MoveCtrlEx(ID_TXT_CLIENT_ID,0,0,20,106);
	MoveCtrlEx(3801,106,0,20,14);
	MoveCtrlEx(ID_TXT_CLIENT_TYPE,120,0,20,31);
	[n_CLIENT_NAME_WND] := 1 ;  
}

PROCEDURE OnChange
        DECLARE PARAMETER sGroupName as TEXT
        DECLARE PARAMETER sFieldName as TEXT
        DECLARE PARAMETER sOldVal as TEXT
        DECLARE PARAMETER nControlID as QUANTITY DO
{
#123316 - Added AND ([n_CLIENT_NAME_WND] = 0) in the following IF Block
#167849 - Added ID_TXT_BROKER_TYPE, and compared the value entered by user with the firm's type
	DECLARE VARIABLE        sDefVal         AS TEXT         100
        DECLARE VARIABLE        sObjKeyDefVal   AS TEXT         30
        DECLARE VARIABLE        sTrader   AS TEXT         30
	IF (( ([nControlID] = ID_TXT_BROKER_TYPE)) AND ([n_CLIENT_NAME_WND] = 0)) DO
	{
		DECLARE VARIABLE 	sBrokeID 		AS TEXT 100
		DECLARE VARIABLE	sBrType			AS TEXT	50
		DECLARE VARIABLE	sUserBrType		AS TEXT	50
		[sBrokeID] := GetFieldValue1(ID_TXT_BROKER_ID);
		#167849
		[sUserBrType] := GetFieldValue1(ID_TXT_BROKER_TYPE);
		
		IF (([sBrokeID] != "") AND ([sUserBrType] != "")) DO
		{
			[sBrType] := GetObjPoolItemVal(21, [sBrokeID], 0);
			
			#167849			
			IF ([sBrType] != [sUserBrType]) DO
			{
				MessageBox("Firm and Broker Type entered is invalid.","Error",1,1);
				STOP
			}
		}
	
	}
#Issue Id: 134543	
	IF ((([nControlID] = ID_TXT_BROKER_ID)  ) AND ([n_CLIENT_NAME_WND] = 0)) DO
	{

		DECLARE VARIABLE 	sBrokeID 		AS TEXT 100
		DECLARE VARIABLE	sBrType			AS TEXT	50
		DECLARE VARIABLE	sUserBrType		AS TEXT	50
		[sBrokeID] := GetFieldValue1(ID_TXT_BROKER_ID);
		#167849
		[sUserBrType] := GetFieldValue1(ID_TXT_BROKER_TYPE);
		
		IF (([sBrokeID] != "") AND ([sUserBrType] != "")) DO
		{
			[sBrType] := GetObjPoolItemVal(21, [sBrokeID], 0);
			IF ( [sBrType] = "") THEN	
			{
				
				MessageBox("Invalid Participant ID.","Error",1,1);
				SetCtrlFocus( ID_TXT_BROKER_ID );
				STOP
			}
			ELSE
			{
				[sObjKeyDefVal] := GetObjPoolItemKey(Datapool_DefaultVals, 0);
				[sTrader] := GetObjPoolItemVal(Datapool_DefaultVals, [sObjKeyDefVal], 12);
			
		#		MessageBox([sTrader],"Error",1,1);
			
				IF ([sTrader] != "") DO
				{
					IF ( ( [sBrType] = "B" )   AND ( [sBrokeID] != [sTrader] ) ) DO 
					{
						MessageBox("Invalid Participant ID .","Error",1,1);
						SetCtrlFocus( ID_TXT_BROKER_ID );
						STOP
					}


				}
				SetFieldValue1( ID_TXT_BROKER_TYPE, [sBrType] );

			} 
			
			#167849			
		}
		

	}
	IF ( ([nControlID] = ID_TXT_CLIENT_ID) OR ([nControlID] = ID_TXT_CLIENT_TYPE) ) DO
	{
		DECLARE VARIABLE sConcatClientID 	AS TEXT 100
		IF ((GetFieldValue1(ID_TXT_CLIENT_ID) != "") AND (GetFieldValue1(ID_TXT_CLIENT_TYPE) != "")) THEN
		{
			[sConcatClientID] := StrCat(GetFieldValue1(ID_TXT_CLIENT_ID), "-");
			[sConcatClientID] := StrCat([sConcatClientID], GetFieldValue1(ID_TXT_CLIENT_TYPE));
			
			NotifyControl(ID_NOTIFY_CLIENT_ID, [sConcatClientID]);	
		}
		ELSE
		{
			NotifyControl(ID_NOTIFY_CLIENT_ID, "");	
		}
	}
	
	IF ( ([nControlID] >= ID_TXT_BROKER_ID) AND ([nControlID] <= ID_TXT_JOINT_ACC_NO) ) DO
	{

		IF ( (GetFieldValue1(ID_TXT_BROKER_ID) != "") AND
		 (GetFieldValue1(ID_TXT_CLIENT_ID) != "") AND
		 (GetFieldValue1(ID_TXT_CLIENT_TYPE) != "") AND
		 (GetFieldValue1(ID_TXT_JOINT_ACC_NO) != "") ) DO
		{
			DECLARE VARIABLE sRegistrationID 	AS TEXT 100
			[sRegistrationID] := StrCat(GetFieldValue1(ID_TXT_BROKER_ID), "-");
			[sRegistrationID] := StrCat([sRegistrationID],GetFieldValue1(5002));
			[sRegistrationID] := StrCat([sRegistrationID], "/");
			[sRegistrationID] := StrCat([sRegistrationID], GetFieldValue1(ID_TXT_CLIENT_ID));
			[sRegistrationID] := StrCat([sRegistrationID], "-");
			[sRegistrationID] := StrCat([sRegistrationID], GetFieldValue1(ID_TXT_CLIENT_TYPE));
			[sRegistrationID] := StrCat([sRegistrationID], "/");
			[sRegistrationID] := StrCat([sRegistrationID], GetFieldValue1(ID_TXT_JOINT_ACC_NO));
			
			NotifyControl(ID_NOTIFY_REG_ID, [sRegistrationID]);
		}
		
		IF ( (GetFieldValue1(ID_TXT_BROKER_ID) = "") OR
			 (GetFieldValue1(ID_TXT_CLIENT_ID) = "") OR
			 (GetFieldValue1(ID_TXT_CLIENT_TYPE) = "") OR
			 (GetFieldValue1(ID_TXT_JOINT_ACC_NO) = "") ) DO
		{
			NotifyControl(ID_NOTIFY_REG_ID, "");
		}

	}
}

PROCEDURE PopulateClientName DO
{
	CALL OnChange "", "", "", ID_TXT_CLIENT_ID;
}


PROCEDURE OnChangeInstrumentType
          DECLARE PARAMETER sInsType as TEXT DO
{
	CALL OnChange "", "", " ", ID_TXT_JOINT_ACC_NO;
}

PROCEDURE OnReturnPage
        DECLARE PARAMETER nControlID as QUANTITY
        DECLARE PARAMETER sListName as TEXT DO
{
	CALL OnChange "", "", "", ID_TXT_CLIENT_ID;
}

##########################################################
PROCEDURE SetBkgColor
		 DECLARE PARAMETER sRVal AS TEXT
		 DECLARE PARAMETER sGVal AS TEXT 
		 DECLARE PARAMETER sBVal AS TEXT DO
{
	DECLARE VARIABLE nRed	AS QUANTITY
	DECLARE VARIABLE nGreen	AS QUANTITY
	DECLARE VARIABLE nBlue	AS QUANTITY
	
	[nRed]   := StringToInt([sRVal]);
	[nGreen] := StringToInt([sGVal]);
	[nBlue]  := StringToInt([sBVal]);
	SetBackColor([nRed], [nGreen], [nBlue], 1);
	#ChangeControlBackColor(3800,[nRed],[nGreen],[nBlue]);
	#ChangeControlBackColor(3801,[nRed],[nGreen],[nBlue]);
	#ChangeControlBackColor(3802,[nRed],[nGreen],[nBlue]);
}

PROCEDURE LockWhenAmend DO
{
	SetLock (ID_TXT_CLIENT_TYPE,1, 0);
	SetLock (ID_TXT_JOINT_ACC_NO, 1, 0);
	SetLock (ID_TXT_CLIENT_ID, 1, 0);
	SetLock (ID_TXT_BROKER_TYPE, 1, 0);
} 

