
# Serendib field IDs
DECLARE CONSTANT FLD_InstrumentID 	AS QUANTITY 2051
DECLARE CONSTANT FLD_BookDefID		AS QUANTITY 2099
DECLARE CONSTANT FLD_TraderID		AS QUANTITY	2182
DECLARE CONSTANT FLD_BrokerID		AS QUANTITY	2011
DECLARE CONSTANT FLD_OwnerID		AS QUANTITY	2015

DECLARE CONSTANT FLD_Side	 			AS QUANTITY 2053
DECLARE CONSTANT FLD_Value 				AS QUANTITY 2485
DECLARE CONSTANT FLD_OrderQty 			AS QUANTITY 2709
DECLARE CONSTANT FLD_VisibleQty			AS QUANTITY 2190

#FLD_AllwZeroVS uses the filed Quantifier in New Order Message
DECLARE CONSTANT FLD_AllwZeroVS			AS QUANTITY	2183

DECLARE CONSTANT FLD_ExpiryDate			AS QUANTITY 2542
DECLARE CONSTANT FLD_ExpiryTime			AS QUANTITY 2503
DECLARE CONSTANT FLD_TIF 				AS QUANTITY 2331
DECLARE CONSTANT FLD_OrderType 			AS QUANTITY 2189
DECLARE CONSTANT FLD_AccountType 		AS QUANTITY 40505
DECLARE CONSTANT FLD_StopPrice	 		AS QUANTITY 2425
DECLARE CONSTANT FLD_Capacity			AS QUANTITY	2233
DECLARE CONSTANT FLD_ClearingMnemonic	AS QUANTITY	3129
DECLARE CONSTANT FLD_MinimumSize		AS QUANTITY	2386
DECLARE CONSTANT FLD_ClientID			AS QUANTITY 2230

DECLARE CONSTANT FLD_TotalQty				AS QUANTITY 2224
DECLARE CONSTANT FLD_OrderID				AS QUANTITY 2147
DECLARE CONSTANT FLD_OriginalClientOrderID	AS QUANTITY 2554
DECLARE CONSTANT FLD_ClientOrderID			AS QUANTITY 2055
DECLARE CONSTANT FLD_ContingentCondition	AS QUANTITY 2422
DECLARE CONSTANT FLD_OrderSubType 			AS QUANTITY 2642
DECLARE CONSTANT FLD_Protection 			AS QUANTITY 2163
DECLARE CONSTANT FLD_SideQualifier			AS QUANTITY	2313
DECLARE CONSTANT FLD_NamedOrder				AS QUANTITY	2729

DECLARE CONSTANT FLD_Submit	 		AS QUANTITY 80000
DECLARE CONSTANT FLD_Clear	 		AS QUANTITY 80001

DECLARE CONSTANT CTRL_EXP_DATE_TIME			AS QUANTITY 30003 

# Other field IDs in the form
DECLARE CONSTANT FLD_Time			AS QUANTITY	30001
DECLARE CONSTANT FLD_Date			AS QUANTITY	30002
DECLARE CONSTANT FLD_DateTime		AS QUANTITY	30003

DECLARE CONSTANT FLD_Orders			AS QUANTITY	30005
DECLARE CONSTANT FLD_Quotes			AS QUANTITY	30006

DECLARE CONSTANT FLD_TimeLabel		AS QUANTITY	124

DECLARE CONSTANT FLD_AllwZeroAskVS	AS QUANTITY	109
DECLARE CONSTANT FLD_AllwZeroBidVS	AS QUANTITY	110
DECLARE CONSTANT FLD_Named			AS QUANTITY	141

#129836
DECLARE CONSTANT FLD_LABLE_PRICE		AS QUANTITY	4087
DECLARE CONSTANT FLD_LABLE_YIELD		AS QUANTITY	4088

#EXP Order Entry Additional Fields
DECLARE CONSTANT FLD_CalculatedVal	AS QUANTITY 11
DECLARE CONSTANT FLD_EXPTraderID	AS QUANTITY 3076
DECLARE CONSTANT FLD_Contra			AS QUANTITY 3075
DECLARE CONSTANT FLD_Remarks		AS QUANTITY 3071

DECLARE CONSTANT FLD_Debt_Fee				AS QUANTITY 6070
#<<168597
DECLARE VARIABLE s_ResetFieldSide 			AS TEXT 100
DECLARE CONSTANT FLD_SourceID 			AS QUANTITY 2666
#>>168597
DECLARE CONSTANT FLD_Debt_Commissions		AS QUANTITY 3166	
DECLARE CONSTANT FLD_Debt_Effective_Yield	AS QUANTITY 3175
DECLARE CONSTANT FLD_Debt_Total_Value		AS QUANTITY 6073
DECLARE CONSTANT FLD_Debt_Yield				AS QUANTITY 3168
DECLARE CONSTANT CHK_Debt_Price				AS QUANTITY 6065
DECLARE CONSTANT CHK_Debt_Yield				AS QUANTITY 6066
#DECLARE CONSTANT FLD_Days_To_Expire			AS QUANTITY 6080	
DECLARE CONSTANT n_BtnMore			  	AS  QUANTITY	60000

# Order etry mode
DECLARE CONSTANT MODE_New				AS QUANTITY 0
DECLARE CONSTANT MODE_Amend				AS QUANTITY 1
#CR09 - 162588
DECLARE CONSTANT MODE_Amend_OFFLINE		AS QUANTITY 2

# Order or Ordre
DECLARE CONSTANT TYPE_Order	AS QUANTITY 0
DECLARE CONSTANT TYPE_Quote	AS QUANTITY 3

# Message box icons
DECLARE CONSTANT MSG_BOX_ICON_Critical	AS QUANTITY 0
DECLARE CONSTANT MSG_BOX_ICON_Question	AS QUANTITY 1
DECLARE CONSTANT MSG_BOX_ICON_Exclaim	AS QUANTITY 2
DECLARE CONSTANT MSG_BOX_ICON_Info		AS QUANTITY 3

# Message box types
DECLARE CONSTANT MSG_BOX_TYPE_AbortRetryIgnore		AS QUANTITY 0
DECLARE CONSTANT MSG_BOX_TYPE_Ok		AS QUANTITY 1
DECLARE CONSTANT MSG_BOX_TYPE_OkCancel	AS QUANTITY 2
DECLARE CONSTANT MSG_BOX_TYPE_RetryCancel	AS QUANTITY 3
DECLARE CONSTANT MSG_BOX_TYPE_YesNo		AS QUANTITY 4

# Message box reponse values
DECLARE CONSTANT MSG_BOX_RES_Yes	AS QUANTITY 6
DECLARE CONSTANT MSG_BOX_RES_No		AS QUANTITY 7

#Trader Parameter Object Pool positions  
DECLARE CONSTANT ENABLE_QUOTES			AS QUANTITY 0
DECLARE CONSTANT ENABLE_MARKET_ORDERS	AS QUANTITY 1
DECLARE CONSTANT ENABLE_STOP_ORDERS		AS QUANTITY 2
DECLARE CONSTANT ENABLE_ICEBERG			AS QUANTITY 3
DECLARE CONSTANT ENABLE_RESERVE			AS QUANTITY 4
DECLARE CONSTANT ENABLE_MIN_FILL		AS QUANTITY 5
DECLARE CONSTANT ENABLE_GTD				AS QUANTITY 6
DECLARE CONSTANT ENABLE_GTC				AS QUANTITY 7
DECLARE CONSTANT ENABLE_GTT				AS QUANTITY 8
DECLARE CONSTANT ENABLE_FOK				AS QUANTITY 9
DECLARE CONSTANT ENABLE_OPG				AS QUANTITY 10
DECLARE CONSTANT ENABLE_ATC				AS QUANTITY 11
DECLARE CONSTANT ENABLE_SHORT_SALES 	AS QUANTITY 12
DECLARE CONSTANT TICK_FORMAT_STRING		AS QUANTITY 13
DECLARE CONSTANT ENABLE_GFA				AS QUANTITY 14
#126873
DECLARE CONSTANT MAX_ORDER_DURATION		AS QUANTITY 15
DECLARE CONSTANT NAMED_ORDER_INDICATOR	AS QUANTITY 16
#129836
DECLARE CONSTANT TRADE_METHOD					AS QUANTITY 17
DECLARE CONSTANT TRADE_METHOD_ON_PRICE			AS QUANTITY 1
DECLARE CONSTANT TRADE_METHOD_ON_YIELD			AS QUANTITY 2
DECLARE CONSTANT TRADE_METHOD_ON_RATE			AS QUANTITY 3
DECLARE CONSTANT TRADE_METHOD_ON_DISCOUNT_RATE	AS QUANTITY 4


# Market data type
DECLARE CONSTANT MARKET_TYPE_Limit 	AS QUANTITY 2
DECLARE CONSTANT MARKET_TYPE_Market	AS QUANTITY 1

# The mode  New/Amend
DECLARE VARIABLE g_nEntityMode AS QUANTITY

#side values
DECLARE CONSTANT SIDE_Buy		AS QUANTITY 	1
DECLARE CONSTANT SIDE_Sell		AS QUANTITY 	2

#side qualifier values
DECLARE CONSTANT SideQualifier_None			AS QUANTITY 	0
DECLARE CONSTANT SideQualifier_Sell_Short	AS QUANTITY 	5

#data pool objects
DECLARE CONSTANT Datapool_Instrument				AS QUANTITY 1
DECLARE CONSTANT Datapool_DefaultVals				AS QUANTITY 3
DECLARE CONSTANT Datapool_FirmUsers					AS QUANTITY 16
DECLARE CONSTANT Datapool_TradingPara				AS QUANTITY 15

#Instrument Datapool Items
DECLARE CONSTANT DatapoolItem_Inst_InternalInstType	AS QUANTITY 1
DECLARE CONSTANT DatapoolItem_Inst_MarketFee		AS QUANTITY 7
DECLARE CONSTANT DatapoolItem_Inst_Multiplier		AS QUANTITY 5
DECLARE CONSTANT DatapoolItem_Inst_TickIncrement	AS QUANTITY 9
DECLARE CONSTANT DatapoolItem_Inst_SpinMultipleTick	AS QUANTITY 4
DECLARE CONSTANT DatapoolItem_Inst_ParValue			AS QUANTITY 11

DECLARE CONSTANT LOCK_CONTROL						AS QUANTITY 1
DECLARE CONSTANT UNLOCK_CONTROL						AS QUANTITY 0
DECLARE CONSTANT SHOW_PIC_FALSE						AS QUANTITY 0
DECLARE CONSTANT SHOW_PIC_TRUE						AS QUANTITY 1

DECLARE VARIABLE s_CurrentInstrument				AS TEXT 	100
DECLARE VARIABLE s_CurrentBookDefID				AS TEXT 	100

DECLARE VARIABLE s_Trader							AS TEXT 	100
DECLARE VARIABLE i_MsgID					AS QUANTITY

DECLARE CONSTANT EnumID_OrderType			AS QUANTITY 3
DECLARE CONSTANT EnumID_Side				AS QUANTITY 14
DECLARE CONSTANT EnumID_Capacity			AS QUANTITY 90
DECLARE CONSTANT EnumID_Validity			AS QUANTITY 13

DECLARE VARIABLE n_FormExpanded			AS 	QUANTITY
DECLARE VARIABLE n_ConfirmSubmit 		AS  QUANTITY

DECLARE VARIABLE f_Yield 				AS PRICE	

#CR 122830
DECLARE VARIABLE s_ActiveSide						AS TEXT 	100

# <<< CR 124565
DECLARE VARIABLE f_TotalSize			AS 	PRICE

DECLARE VARIABLE n_QuickLotIncerementField	AS  QUANTITY

#129836
DECLARE VARIABLE n_TradeMethod 	AS QUANTITY 

##CR 150542
DECLARE VARIABLE s_Message			AS TEXT 	600

#166039
DECLARE VARIABLE n_IsFullyVisible		AS  QUANTITY
#CR09 - 162588
DECLARE CONSTANT CHK_Offline_Order	AS QUANTITY 7502

PROCEDURE SetTotalSize 
	DECLARE PARAMETER sTotalSize		AS TEXT DO
{
	SLogLine("SetTotalSize");
	DECLARE VARIABLE 	fFee 		 	AS PRICE
	DECLARE VARIABLE 	fCommissions  	AS PRICE
	DECLARE VARIABLE 	fEffectiveYield	AS PRICE
	
	[f_TotalSize] := StringToFloat([sTotalSize]);
}

#  CR 124565 >>>

# <<< 126873
PROCEDURE SetMaxOrderDurationForAmend
	DECLARE PARAMETER sMaxOrderDuration		AS TEXT DO
{
	SLogLine("SetMaxOrderDurationForAmend");
	DECLARE VARIABLE 	nMaxOrderDuration 	AS QUANTITY
	
	[nMaxOrderDuration] := StringToInt([sMaxOrderDuration]);
	# MSE IF ([nMaxOrderDuration] > 0 ) DO
	# MSE{
	# MSE	SetBuddyMax(FLD_Days_To_Expire, [nMaxOrderDuration]);
	# MSE }
	
}
#  CR 124565 >>>

# <<< 126873
# MSE PROCEDURE SetNumberOfDaysToExpire
# MSE	DECLARE PARAMETER sNumberOfDays		AS TEXT DO
# MSE{
# MSE	SetFieldValue1(FLD_Days_To_Expire, [sNumberOfDays]);
# MSE}
#  CR 124565 >>>


PROCEDURE HandleSpecialCaseBeforeSending DO
{
	SLogLine("HandleSpecialCaseBeforeSending");
	DECLARE VARIABLE sCapacity			AS TEXT 50
	DECLARE VARIABLE sAccountType		AS TEXT 50

	DECLARE VARIABLE 	fValue 	AS PRICE

	[sCapacity] := GetFieldValue1(FLD_Capacity);
	[sAccountType] := GetFieldValue1(FLD_AccountType);

	IF ( ([sCapacity] = " ") OR ([sCapacity] = NULL ) ) DO
	{	
		ResetFieldInCarrierMsg(FLD_Capacity);	  
	}

        IF ([sCapacity] = "") DO
		{
		ResetFieldInCarrierMsg(FLD_Capacity);	  
	}
			
	IF ( ([sAccountType] = " ") OR ([sAccountType] = NULL ) ) DO
	{	
		ResetFieldInCarrierMsg(FLD_AccountType);
	}
			
	IF ([sAccountType] = "") DO
	{			
		ResetFieldInCarrierMsg(FLD_AccountType);
	}
}

PROCEDURE DoCommissionCalcualation DO 
{
	DECLARE VARIABLE 	fFee 		 	AS PRICE
	DECLARE VARIABLE 	fCommissions  	AS PRICE
	DECLARE VARIABLE 	fEffectiveYield	AS PRICE
	
	[fFee] := StringToFloat(GetFieldValue1(FLD_Debt_Fee));
	[fCommissions] := StringToFloat(GetFieldValue1(FLD_Debt_Commissions));
	
	DECLARE VARIABLE sSide AS TEXT 20
	[sSide] := GetFieldValue1(FLD_Side);
		
	IF ( ([sSide] = "SELL SHORT") OR ([sSide] = "SELL") ) THEN
	{
		[fEffectiveYield] := ([f_Yield] + ([fFee] + [fCommissions]));
	} ELSE
	{
		[fEffectiveYield] := ([f_Yield] - ([fFee] + [fCommissions]));
	}
#>>201043
	DECLARE VARIABLE sTradingParameterID            AS TEXT 100
        [sTradingParameterID] := GetObjPoolItemVal(Datapool_Instrument, [s_CurrentInstrument], 10);
        SLogLine("[DoCommissionCalcualation]iNoOfDecimals");
        SLogLine([sTradingParameterID]);
        DECLARE VARIABLE iNoOfDecimals AS QUANTITY
        [iNoOfDecimals] := StringToInt([sTradingParameterID]);

#<<201043
	
	DECLARE VARIABLE	sEffectiveYield 	AS TEXT		100
	[sEffectiveYield] 	:= FloatToString([fEffectiveYield],[iNoOfDecimals]);
	
        SLogLine([sEffectiveYield]);
	SetFieldValue1(FLD_Debt_Effective_Yield, [sEffectiveYield]);
	NotifyControl(FLD_Debt_Effective_Yield,[sEffectiveYield]);
}

PROCEDURE UpdateTotalValue
	DECLARE PARAMETER sTotalValue		AS TEXT DO 
{

	DECLARE VARIABLE 	fPrice 	AS PRICE
	DECLARE VARIABLE 	fQuantity 	AS PRICE
	DECLARE VARIABLE 	fTotal 	AS PRICE
	DECLARE VARIABLE	sTotal 	AS TEXT		100
	
	[fQuantity] := StringToFloat(GetFieldValue1(FLD_OrderQty));
	[fPrice] := StringToFloat([sTotalValue]);
	
	[fTotal] := ( [fQuantity] * [fPrice] ) ;
	IF ( [fTotal] = 0.0 ) THEN
	{
		[sTotal] := "0.0";
	} ELSE
	{
		[sTotal] 	:= FloatToString([fTotal],4);
	}
	SetFieldValue1(FLD_Debt_Total_Value, [sTotal]);
	
}

PROCEDURE InitializeDebtRelatedFields DO 
{
	SetLock (FLD_Debt_Fee,1, 0);
	SetLock (FLD_Debt_Effective_Yield, 1, 0);
	SetLock (FLD_Debt_Total_Value,1, 0);
	
	ChangeControlTextColor(FLD_Debt_Fee, 200,200,200);
	ChangeControlTextColor(FLD_Debt_Effective_Yield, 200,200,200);
	ChangeControlTextColor(FLD_Debt_Total_Value, 200,200,200);
	
	SetLock (FLD_Debt_Commissions,0, 0);
	
	[f_Yield] := 0.0 ; 
	
	SetFieldValue1(FLD_Debt_Fee, "0.02");
	SetFieldValue1(FLD_Debt_Effective_Yield, "0.00");
	SetFieldValue1(FLD_Debt_Total_Value, "0.00");
	
	CALL OnCheck CHK_Debt_Yield, "", 0 ; 
}

PROCEDURE UpdatePriceYield
	DECLARE PARAMETER sCtrlID	AS TEXT
	DECLARE PARAMETER sVal		AS TEXT DO 
{
	DECLARE VARIABLE nCtrlID	AS QUANTITY

	[nCtrlID] := StringToInt([sCtrlID]);
	
	SetFieldValue1([nCtrlID], [sVal]);
	IF ([nCtrlID] = FLD_Debt_Yield ) DO
	{
		DECLARE VARIABLE nVal		AS PRICE
		[nVal] := StringToFloat([sVal]);
	
		[f_Yield] := [nVal]  ;
		CALL DoCommissionCalcualation ;
	}
	
}


PROCEDURE CalculateValue DO
{
	SLogLine("CalculateValue");
	DECLARE VARIABLE 	fPrice 		AS PRICE
	DECLARE VARIABLE 	fQuantity 	AS PRICE
	DECLARE VARIABLE 	fMultiplier	AS PRICE
	DECLARE VARIABLE	sCtrlValue 	AS TEXT		100
	DECLARE VARIABLE	sTempVal 	AS TEXT		100
	DECLARE VARIABLE	sParValue 	AS TEXT		100
	DECLARE VARIABLE 	nParValue 	AS QUANTITY
	
	[sTempVal] := GetObjPoolItemVal(Datapool_Instrument, [s_CurrentInstrument], DatapoolItem_Inst_Multiplier);
	[fMultiplier] := StringToFloat([sTempVal]);
	
	[fQuantity] := StringToFloat(GetFieldValue1(FLD_OrderQty));
	[fPrice] := StringToFloat(GetFieldValue1(FLD_Value));
	
	[sParValue] := GetObjPoolItemVal(Datapool_Instrument, [s_CurrentInstrument], DatapoolItem_Inst_ParValue);
	[nParValue] := StringToInt([sParValue]);
	
	[sCtrlValue] := FloatToString( (  ([fQuantity] * [fPrice] * [fMultiplier] ) / [nParValue]  ), 2 );				
	
	DECLARE VARIABLE	sOrderTypeText	 AS TEXT		30
	[sOrderTypeText] := GetFieldValue1(FLD_OrderType);
	IF ( ([sOrderTypeText] = "MARKET") OR ([sOrderTypeText] = "STOP") OR ([sOrderTypeText] = "STOP_LIMIT") ) THEN
	{
		SetFieldValue1(FLD_CalculatedVal, "0.0");
	} ELSE
	{
	SetFieldValue1(FLD_CalculatedVal, [sCtrlValue]);
}
}


###############################################################################
PROCEDURE SetLocksOnOrderType  
		DECLARE PARAMETER sOrderTypeText	AS TEXT DO
{
	SLogLine("SetLocksOnOrderType");
	IF ( [sOrderTypeText] = "STOP") THEN
	{
		SetLock (FLD_Value, 			1, 0);
		SetLock (FLD_StopPrice, 		0, 0);
		
		ChangeControlTextColor(FLD_Value, 200,200,200);
		ChangeControlTextColor(FLD_StopPrice, 0,0,0);
		
	}
	ELSE IF ( [sOrderTypeText] = "STOP_LIMIT") THEN
	{
		SetLock (FLD_Value, 			0, 0);
		SetLock (FLD_StopPrice, 		0, 0);
		
		ChangeControlTextColor(FLD_Value, 0,0,0);
		ChangeControlTextColor(FLD_StopPrice, 0,0,0);
	}
	ELSE IF ( [sOrderTypeText] = "LIMIT") THEN
	{
#//166566
		SetFieldValue1(FLD_StopPrice, "0.0");
		SetLock (FLD_Value, 			0, 0);
		SetLock (FLD_StopPrice, 		1, 0);
		
		ChangeControlTextColor(FLD_Value, 0,0,0);
		ChangeControlTextColor(FLD_StopPrice, 200,200,200);
	}
	ELSE IF ( [sOrderTypeText] = "MARKET") THEN
	{
#//166566
		SetFieldValue1(FLD_StopPrice, "0.0");
		SetLock (FLD_Value, 			1, 0);
		SetLock (FLD_StopPrice, 		1, 0);
		
		ChangeControlTextColor(FLD_Value, 200,200,200);
		ChangeControlTextColor(FLD_StopPrice, 200,200,200);
	}
	ELSE
	{
#//166566
		SetFieldValue1(FLD_StopPrice, "0.0");
		SetLock (FLD_Value, 			0, 0);
		SetLock (FLD_StopPrice, 		0, 0);
		
		ChangeControlTextColor(FLD_Value, 0,0,0);
		ChangeControlTextColor(FLD_StopPrice, 0,0,0);
	}
	
	#129836
	IF ( ([n_TradeMethod] != TRADE_METHOD_ON_PRICE) AND ([n_TradeMethod] != -1)  ) DO
	{
		ChangeControlTextColor(FLD_Value, 255,255,255); 
		SetLock (FLD_Value, LOCK_CONTROL ,0);
	}
}
# Lock time and date fields depending on the TIF as the TIF combo changes
# =================================================================================
PROCEDURE SetLocksOnTIF 
		DECLARE PARAMETER sTIFText	AS TEXT DO
{
	SLogLine("SetLocksOnTIF");
	IF ( [sTIFText] = "GTD" ) THEN
	{	
		# MSE SetLock(FLD_Days_To_Expire, 0, 0);
		# MSE ChangeControlTextColor(FLD_Days_To_Expire, 0,0,0);
		
		# MSE ChangeControlName(FLD_TimeLabel, "Days to Expiry");
		
		#ShowHideCtrl(FLD_DateTime,1);
		# MSE ShowHideCtrl(FLD_DateTime,0);
		
		SetLock(FLD_DateTime, 0, 0);
		SetFormat1(FLD_DateTime, "yyyy/MM/dd");
		
		ChangeControlName(FLD_TimeLabel, "Expire Date");
		ChangeControlTextColor(FLD_DateTime, 0,0,0);
	}
	ELSE IF ( [sTIFText] = "GTT" ) THEN 
	{
		SetLock(FLD_DateTime, 0, 0);
		SetFormat1(FLD_DateTime, "HH:mm:ss");
		
		ChangeControlName(FLD_TimeLabel, "Expire Time");
		ChangeControlTextColor(FLD_DateTime, 0,0,0);
		
		# MSE ShowHideCtrl(FLD_Days_To_Expire,0);
		# MSE ShowHideCtrl(CTRL_EXP_DATE_TIME,1);
		
	}
	ELSE
	{
		# MSE ChangeControlName(FLD_TimeLabel, "Days to Expiry");
		
		# MSE SetLock(FLD_DateTime, 1, 0);
		# MSE SetLock(FLD_Days_To_Expire, 1, 0);
		
		# MSE ChangeControlTextColor(FLD_Days_To_Expire, 200,200,200);
		# MSE ChangeControlTextColor(FLD_DateTime, 200,200,200);
		
		# MSE ShowHideCtrl(FLD_Days_To_Expire,1);
		# MSE ShowHideCtrl(CTRL_EXP_DATE_TIME,0);

		#ShowHideCtrl(FLD_DateTime,1);
		SetLock(FLD_DateTime, 1, 0);
		ChangeControlTextColor(FLD_DateTime, 200,200,200);
	}
}

# Lock time and date fields depending on the TIF as the TIF combo changes
# =================================================================================
PROCEDURE SetGetExpiry
	DECLARE PARAMETER nDoSet	AS QUANTITY DO
{
	SLogLine("SetGetExpiry");
	DECLARE VARIABLE sTIFText AS TEXT 20
	DECLARE VARIABLE sExpiryDateTime AS TEXT 20
	
	[sTIFText] := GetFieldValue1(FLD_TIF);
	
	IF ( ([sTIFText] = "GTD") OR ( [sTIFText] = "GTT" )) THEN
	{	
		IF ( [nDoSet] = 1 ) THEN
		{	
			[sExpiryDateTime] := GetFieldValue1(CTRL_EXP_DATE_TIME);
			SetFieldValueInCarrierMsg(FLD_ExpiryTime,[sExpiryDateTime] );
		}
		ELSE 
		{
			SetFieldValue1(CTRL_EXP_DATE_TIME, GetStringFieldValueFromUnpackMsg(FLD_ExpiryTime, 0));
		}
		
		}
		ELSE 
		{
		IF ( [nDoSet] = 1 ) DO
		{	
			ResetFieldInCarrierMsg(FLD_ExpiryTime);
		}
	}	
}

###############################################################################
PROCEDURE LockAllFileds 
		DECLARE PARAMETER nMode	AS QUANTITY DO
{
	SLogLine("LockAllFileds");
	SetLock (FLD_Value, 	[nMode], 0);
	SetLock (FLD_OrderType, [nMode], 0);
	SetLock (FLD_AccountType, [nMode], 0);
	SetLock (FLD_Protection, 	[nMode], 0);
	SetLock (FLD_StopPrice, 	[nMode], 0);
	SetLock (FLD_Side,		[nMode], 0);
	SetLock (FLD_OrderQty, 	[nMode], 0);
	SetLock (FLD_TIF,		[nMode], 0);
	SetLock (FLD_VisibleQty,	[nMode], 0);
	SetLock (FLD_Submit,	[nMode], 0);
	SetLock (FLD_Capacity,	[nMode], 0);
	SetLock (FLD_ClearingMnemonic,	[nMode], 0);
	SetLock (FLD_Named,[nMode],0);
	SetLock (FLD_MinimumSize,[nMode],0);
	SetLock (FLD_AllwZeroVS,[nMode],0);
	
	SetLock (FLD_Debt_Commissions,	[nMode], 0);
		
	SetLock (FLD_EXPTraderID, [nMode], 0);
	SetLock (FLD_Contra,[nMode],0);
	SetLock (FLD_Remarks,[nMode],0);
	
	# MSE SetLock (FLD_Days_To_Expire,[nMode],0);
	SetLock (FLD_OwnerID,[nMode],0);
	
	DECLARE VARIABLE nEnableOnBehalfOfSubmission	AS QUANTITY
	
	IF ( [nMode] = 0 ) THEN
	{
		[nEnableOnBehalfOfSubmission] := GetInitialValueInt("ENABLE_ON_BEHALF_SUBMISSION");
		
		IF ( [nEnableOnBehalfOfSubmission] = 1 ) THEN
		{
			SetLock (FLD_OwnerID,[nMode],0);
		} ELSE
		{
			SetLock (FLD_OwnerID,1,0);
		#	ChangeControlTextColor(FLD_OwnerID, 200,200,200);
		}
		
		}
        ELSE
	{
		SetLock (FLD_OwnerID,[nMode],0);
	}
	DECLARE VARIABLE sSide AS TEXT 20
	DECLARE VARIABLE sHardSide AS TEXT 20
	
	IF ( [nMode] = 1) THEN
		ChangeControlTextColor(FLD_Submit,0,0,0);
	ELSE
	{
		[sSide] := GetFieldValue1(FLD_TIF);
		[sHardSide] := GetFieldValue1(FLD_TIF);
		
		IF ( [sSide] = [sHardSide] ) THEN
		{
			ChangeControlTextColor(FLD_Submit,50,50,200);
		}
		ELSE
		{
			ChangeControlTextColor(FLD_Submit,200,50,50);
		}
	}
}

#CR 08 : Disabling Un-used order Types
PROCEDURE LockForSpecialCases DO
{
	SLogLine("LockForSpecialCases");
	#Called when Instruments are changed 
	#-- Get Trading Parameter related values
	IF ( [s_CurrentInstrument] != " " ) DO
	{	
		DECLARE VARIABLE sTradingParameterID		AS TEXT 100
		DECLARE VARIABLE sDefVal					AS TEXT 100
		[sTradingParameterID] := GetObjPoolItemVal(Datapool_Instrument, [s_CurrentInstrument], 2);
		
		#3.1.4.1 Disabling Unused Order Types 
				
		#3.1.4.2 : Disabling Disclosed Size when Iceberg orders are disabled 
		[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], ENABLE_ICEBERG);
		IF ([sDefVal] = "0") THEN
		{
			SetLock (FLD_VisibleQty,LOCK_CONTROL,0);
		} ELSE
		{
			SetLock (FLD_VisibleQty,UNLOCK_CONTROL,0);
		}
		
		#3.1.4.3 : Disabling Trigger Price when Stop orders are disabled 
		[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], ENABLE_STOP_ORDERS);
		IF ([sDefVal] = "0") THEN
		{
			SetLock (FLD_StopPrice,LOCK_CONTROL,0);
		} ELSE
		{
			#166566
			IF ( (GetFieldValue1(FLD_OrderType) = "STOP") OR (GetFieldValue1(FLD_OrderType) = "STOP_LIMIT") ) DO
			{
				SetLock (FLD_StopPrice,UNLOCK_CONTROL,0);
			}
		}
		
		#Disabling Minimum Quantity when MIN Fill is disabled 
		[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], ENABLE_MIN_FILL);
		IF (([sDefVal] = "0") OR ([g_nEntityMode] = MODE_Amend) ) THEN
		{
			SetLock (FLD_MinimumSize,LOCK_CONTROL,0);
		}ELSE
		{
			SetLock (FLD_MinimumSize,UNLOCK_CONTROL,0);
		}

		#Visible Size Tick Box if resere orders are disabled 
		[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], ENABLE_RESERVE);
		IF ([sDefVal] = "0") THEN
		{
			
			SetLock (FLD_AllwZeroVS,LOCK_CONTROL,0);
		} ELSE
		{
			
			SetLock (FLD_AllwZeroVS,UNLOCK_CONTROL,0);
		}

		#Disabling Named Orders if Named order indicater is 0
		[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], NAMED_ORDER_INDICATOR);
		IF (([sDefVal] = "0") OR ([g_nEntityMode] = MODE_Amend) ) THEN
		{
			SetLock (FLD_Named,LOCK_CONTROL,0);
		}ELSE
		{
			SetLock (FLD_Named,UNLOCK_CONTROL,0);
		}
		
		
		#3.1.4.7 : Removing Riskless Capacity if it is Disabled 
		#RemoveListEntry2(FLD_Capacity, "ALL_CAPACITIES");

	}
		
}

#135055
PROCEDURE SetPriceNullOnOrderType  
		DECLARE PARAMETER sOrderTypeText	AS TEXT DO
{
	SLogLine("SetPriceNullOnOrderType");
	IF (( [sOrderTypeText] = "STOP") OR ( [sOrderTypeText] = "MARKET")) DO
	{
		SetFieldValue1(FLD_Value, "0.00");
		SetFieldValue1(FLD_CalculatedVal, "0.00");
	}
}
	
	
###############################################################################
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
{
	SLogLine("OnChangeCombo");
	IF ([nControlID] = FLD_OrderType) THEN
	{	
		CALL SetLocksOnOrderType [sVal];
				#135055
		CALL SetPriceNullOnOrderType [sVal];
	}
	ELSE IF ([nControlID] = FLD_TIF) THEN
	{
		CALL SetLocksOnTIF [sVal];
		
	}
	ELSE IF ([nControlID] = FLD_Side) DO
	{
		DECLARE VARIABLE sHardSide AS TEXT 20
		[sHardSide] := "BUY";
	
		IF ([sVal] = [sHardSide]) THEN
		{
			ChangeControlTextColor(FLD_Submit,50,50,200);
		}
		ELSE
		{
			ChangeControlTextColor(FLD_Submit,200,50,50);
		}
		
		IF (([sVal] = "SELL SHORT") OR ([sVal] = "0") ) THEN
		{
			ChangeControlName(FLD_Submit, "SELL");
		}
		ELSE
		{
			ChangeControlName(FLD_Submit, [sVal]);
		}

		#Changing the color of the form according to the selected side
		#CR 117474
		DECLARE VARIABLE sWndID		AS TEXT 20	
		DECLARE VARIABLE sCtrlID	AS TEXT 20
					
		[sWndID] := IntToString(GetWndID());		
		
		DECLARE VARIABLE	sRed	 		AS TEXT		30
		DECLARE VARIABLE	sGreen 			AS TEXT		30
		DECLARE VARIABLE	sBlue 			AS TEXT		30
											
		IF ( ([sVal] = "SELL") OR ([sVal] = "SELL SHORT") ) THEN
		{	
			[sRed]   := "255";
			[sGreen] := "154";
			[sBlue]  := "156";
			
			SetBackColor( StringToInt([sRed]), StringToInt([sGreen]), StringToInt([sBlue]), 1 );
			
			[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_AdvancedOptions") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);
			
			[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_RecentTransactions") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);
			
			[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_QuoteEntry") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);		
			
			[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_Header") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);

			[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_ExtendedHeader") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);
			
			[sCtrlID] := IntToString( GetCtrlIDByName("DEBT_Reg_Entry") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);
		}
		ELSE IF ( [sVal] = "BUY" ) THEN
		{
			[sRed]   := "206";
			[sGreen] := "203";
			[sBlue]  := "255";
			
			SetBackColor( StringToInt([sRed]), StringToInt([sGreen]), StringToInt([sBlue]), 1 );
			
			[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_AdvancedOptions") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);
			
			[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_RecentTransactions") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);
			
			[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_QuoteEntry") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);		
			
			[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_Header") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);

			[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_ExtendedHeader") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);
			
			[sCtrlID] := IntToString( GetCtrlIDByName("DEBT_Reg_Entry") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);
		}
		ELSE
		{			
			SetBackColor(236, 233, 216, 1);
					
			[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_AdvancedOptions") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], "236", "233", "216");
			
			[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_RecentTransactions") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], "236", "233", "216");
			
			[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_QuoteEntry") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], "236", "233", "216");		
			
			[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_Header") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], "236", "233", "216");

			[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_ExtendedHeader") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], "236", "233", "216");
			
			[sCtrlID] := IntToString( GetCtrlIDByName("DEBT_Reg_Entry") );
			ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], "236", "233", "216");
		}

		CALL DoCommissionCalcualation ;
		
	}
}

###############################################################################
PROCEDURE AddDispayEnum 
		 DECLARE PARAMETER nFieldID AS QUANTITY DO
{
	SLogLine("AddDispayEnum");
	DECLARE VARIABLE nValue		AS QUANTITY
	DECLARE VARIABLE sValue		AS TEXT 	50
	
	RemoveListEntry2([nFieldID],"");
		
	[nValue] := GetIntFieldValueFromUnpackMsg([nFieldID]);
	[sValue] := GetStringFieldValueFromUnpackMsg([nFieldID], [nValue]);
		
	AddListEntry1([nFieldID],[sValue], "");
	SetFieldValue1([nFieldID], [sValue]);
	SetLock([nFieldID],0,1);
}

###############################################################################
PROCEDURE InitMsgForNewOrder DO
{	
	SLogLine("InitMsgForNewOrder");
	[g_nEntityMode] := MODE_New;
	
	CALL SetIncrements;
	
	# Do inital lockings as defined in SetLocksOnOrderType
	CALL SetLocksOnOrderType GetFieldValue1(FLD_OrderType);
	CALL SetLocksOnTIF GetFieldValue1(FLD_TIF);
	
	# The submit button might've been disabled intially to block the user from interacting with the
		# form, until a reponse for a submitted order returns.
	SetLock(FLD_Submit,0,0);
	SetCheck(FLD_AllwZeroVS, 0);
	ChangeControlName(FLD_Submit, GetFieldValue1(FLD_Side));
	
	CALL AddOtherSideValues;
}

###############################################################################
PROCEDURE SetIncrements DO
{
	SLogLine("SetIncrements");
	MessageBox("THIS FUNCTION IS TO BE DELTED","", 1,1);
	DECLARE VARIABLE sTickString	AS TEXT 300
	DECLARE VARIABLE nLotSize		AS QUANTITY
	
	# Set the increment value of the Control and rount up to the matching tick size.
	[sTickString] := GetInitialValueString("TICK_FORMAT");
	SetValueOnTick(FLD_Value, [sTickString], GetFieldValue1(FLD_Value), 0);
	SetValueOnTick(FLD_StopPrice, [sTickString], GetFieldValue1(FLD_StopPrice), 0);
	
	# Set the increment to lot size
	[nLotSize] := GetInitialValueInt("LOT_SIZE");
	
	IF ([nLotSize] < 1) DO
	{
		[nLotSize] := 100;
	}
	
	SetBuddyIntInc(FLD_OrderQty, [nLotSize]);
	SetBuddyIntInc(FLD_VisibleQty, [nLotSize]);
	SetBuddyIntInc(FLD_MinimumSize, [nLotSize]);
}

###############################################################################
PROCEDURE EXPSetIncrements 
		DECLARE PARAMETER sTickString	AS TEXT
        DECLARE PARAMETER sLotSize		AS TEXT DO
{
	SLogLine("EXPSetIncrements");
	DECLARE VARIABLE nLotSize		AS QUANTITY
	
	
	#SetValueOnTick(FLD_Value, [sTickString], GetFieldValue1(FLD_Value), 0);
	#SetValueOnTick(FLD_StopPrice, [sTickString], GetFieldValue1(FLD_StopPrice), 0);
	#Set the increment to lot size
	[nLotSize] := StringToInt([sLotSize]);
	
	IF ([nLotSize] < 1) DO
	{
		[nLotSize] := 100;
	}
		
	SetBuddyIntInc(FLD_OrderQty, [nLotSize] );
	SetBuddyIntInc(FLD_VisibleQty, [nLotSize] );
	SetBuddyIntInc(FLD_MinimumSize, 3);

	
}


###############################################################################
PROCEDURE LockFieldsForAmend DO
{
	SLogLine("LockFieldsForAmend");
	SetLock(FLD_OrderType,1,0);
	SetLock(FLD_AccountType,1,0);
	SetLock(FLD_Side,1,0);
	SetLock(FLD_OwnerID,1,0);
	SetLock(FLD_MinimumSize,1,0);
	SetLock(FLD_Named,1,0);
}

###############################################################################
PROCEDURE IsInLotSize RETURNS QUANTITY 
		DECLARE PARAMETER fPrice	AS PRICE
		DECLARE PARAMETER nLotSize	AS QUANTITY DO
{
	SLogLine("IsInLotSize");
	DECLARE VARIABLE fDevided	AS PRICE
	DECLARE VARIABLE fNumber	AS PRICE
	DECLARE VARIABLE fDevisor	AS PRICE
	DECLARE VARIABLE fMultiplied	AS PRICE
	
	# Void zero devision
	IF ([nLotSize] < 1) DO
		RETURN 1;
	
	# This is done because the division is the script only accept float values.
	[fDevisor] := StringToFloat(IntToString([nLotSize]));
	
	# There is no direct modulus operator or function for float values
	# Below calculation do similar work. i.e Check wh
	#  FloatToString([fDevided],0)  will discard the decimal places in fDevided will 
	[fDevided] := ([fPrice] / [fDevisor]);
	[fMultiplied] := ( StringToFloat(FloatToString([fDevided],0)) *  [fDevisor]);

	IF ( [fPrice] = [fMultiplied] ) THEN
		RETURN 1;
	ELSE
		RETURN 0;
	
	RETURN 0;
}

###############################################################################
PROCEDURE DoInputValidations RETURNS QUANTITY  DO
{	
	SLogLine("DoInputValidations");
	DECLARE VARIABLE sOrderType		AS TEXT 	50
	DECLARE VARIABLE fStopPrice 	AS PRICE
	[sOrderType] := GetFieldValue1(FLD_OrderType);
	
	IF ( ([sOrderType] = "STOP_LIMIT") OR ([sOrderType] = "STOP") ) DO
{	
		[fStopPrice] := StringToFloat(GetFieldValue1(FLD_StopPrice));
		IF ( [fStopPrice] <= 0.0 ) DO
		{
			MessageBox("Invalid Stop Price","Reject", 1, 1);			
			SetFocusDelayed(FLD_StopPrice);
			RETURN 0;
		}		
	}	
	
	RETURN 1;
}


# =================================================================================
PROCEDURE PackMessage RETURNS QUANTITY DO
{
	SLogLine("PackMessage");
	
	#Unset Temp Variables
	ResetFieldInCarrierMsg(FLD_AllwZeroVS);
	
	DECLARE VARIABLE sOrderType		AS TEXT 50
	DECLARE VARIABLE fStopPrice 	AS PRICE
	DECLARE VARIABLE fPrice 		AS PRICE
	DECLARE VARIABLE fQuantity 		AS PRICE
	DECLARE VARIABLE fVisibleQuantity 		AS PRICE 
	DECLARE VARIABLE fOriginalQuantity 		AS PRICE
	DECLARE VARIABLE fOriginalRemaining 	AS PRICE
	DECLARE VARIABLE fFinalQty 	AS PRICE
	DECLARE VARIABLE nValidations			AS QUANTITY
	DECLARE VARIABLE sInstrumentID	AS TEXT		50
	DECLARE VARIABLE sBookID		AS TEXT		50
	DECLARE VARIABLE sUserID		AS TEXT		50
	DECLARE VARIABLE sSide			AS TEXT		50
	
	IF ( [s_CurrentInstrument] = "" ) DO
	{
		RETURN 0 ; 
	}
	
	IF ([s_CurrentBookDefID] = "") DO
	{
		RETURN 0;
	}
	
	IF ( [g_nEntityMode] = MODE_New ) DO
	{
	GetCarrierMsgFromPool([s_CurrentInstrument]);
	}
	
	# Populate values necessary for validatioin
	[fStopPrice] := StringToFloat(GetFieldValue1(FLD_StopPrice));
	[fPrice] := StringToFloat(GetFieldValue1(FLD_Value));
	[fVisibleQuantity] := StringToFloat(GetFieldValue1(FLD_VisibleQty));
	[fQuantity] := StringToFloat(GetFieldValue1(FLD_OrderQty));
	[sOrderType] := GetFieldValue1(FLD_OrderType);

	#Do input validations
	[nValidations] := DoInputValidations();
	IF ( [nValidations] = 0 ) DO
	{
		RETURN 0;
	}
	
	#<<< Code Inplace of ValidatePackSizes Method Call in Exchange 
	SetFieldValueInCarrierMsg(FLD_Side, GetFieldValue1(FLD_Side));
	IF (GetCheck(FLD_AllwZeroVS) = 1) THEN
	{
		SetFieldValueInCarrierMsg(FLD_VisibleQty, "0.0");
	}
	ELSE
	{
		IF ([fVisibleQuantity] <= 0.0) THEN
		{
			ResetFieldInCarrierMsg(FLD_VisibleQty);
		}
		ELSE
		{
			SetFieldValueInCarrierMsg(FLD_VisibleQty, GetFieldValue1(FLD_VisibleQty));
		}
	}
	
	#ISSUE - 136501
	IF ( [g_nEntityMode] = MODE_Amend ) DO
	{
		IF ([fVisibleQuantity] > [fQuantity]) DO
		{
			MessageBox("Invalid display size (> order size)","Reject", 1, 1);	
			RETURN 0;
		}
	}
	
		SetFieldValueInCarrierMsg(FLD_OrderQty, GetFieldValue1(FLD_OrderQty));
	#>>> Code Inplace of ValidatePackSizes Method Call in Exchange 
	
	[sInstrumentID] := [s_CurrentInstrument] ;
	[sBookID] := [s_CurrentBookDefID] ; 
	[sUserID] := [s_Trader];
	
	# Pack the price, visible size, stop price, side, TIF, Capacity
	SetFieldValueInCarrierMsg(FLD_OrderType, GetFieldValue1(FLD_OrderType));
	SetFieldValueInCarrierMsg(FLD_AccountType, GetFieldValue1(FLD_AccountType));
	SetFieldValueInCarrierMsg(FLD_StopPrice, GetFieldValue1(FLD_StopPrice));
	
	#<< 129836
	IF ( ([n_TradeMethod] = TRADE_METHOD_ON_PRICE) OR ([n_TradeMethod] = -1)  ) THEN
	{
		SetFieldValueInCarrierMsg(FLD_Value, GetFieldValue1(FLD_Value));
	} ELSE
	{
		SetFieldValueInCarrierMsg(FLD_Value, GetFieldValue1(FLD_Debt_Yield));
	}
	# 129836 >>
	
	SetFieldValueInCarrierMsg(FLD_TIF, GetFieldValue1(FLD_TIF));
	SetFieldValueInCarrierMsg(FLD_Capacity, GetFieldValue1(FLD_Capacity));
	SetFieldValueInCarrierMsg(FLD_OwnerID,[s_Trader]);
	#SetFieldValueInCarrierMsg(FLD_ClearingMnemonic,GetFieldValue1(FLD_ClearingMnemonic));
	SetFieldValueInCarrierMsg(FLD_MinimumSize,GetFieldValue1(FLD_MinimumSize));
	SetFieldValueInCarrierMsg(FLD_InstrumentID,[sInstrumentID]);
	
	IF ( [g_nEntityMode] = MODE_New ) DO
	{
	SetFieldValueInCarrierMsg(FLD_BookDefID,[sBookID]);
	}
	
	SetFieldValueInCarrierMsg(FLD_BrokerID,[sUserID]);
	SetFieldValueInCarrierMsg(FLD_TraderID,[sUserID]);
	SetFieldValueInCarrierMsg(FLD_ClientID,GetFieldValue1(FLD_ClientID));
	SetFieldValueInCarrierMsg(FLD_EXPTraderID,GetFieldValue1(FLD_EXPTraderID));
	SetFieldValueInCarrierMsg(FLD_Contra,GetFieldValue1(FLD_Contra));
	SetFieldValueInCarrierMsg(FLD_Remarks,GetFieldValue1(FLD_Remarks));
	
	#Set Debt Fields 
	SetFieldValueInCarrierMsg(FLD_Debt_Commissions, GetFieldValue1(FLD_Debt_Commissions));
	SetFieldValueInCarrierMsg(FLD_Debt_Yield, GetFieldValue1(FLD_Debt_Yield));
	SetFieldValueInCarrierMsg(FLD_Debt_Effective_Yield, GetFieldValue1(FLD_Debt_Effective_Yield));
	
	IF ( GetCheck(FLD_Named) = 1 ) THEN
	{
		SetFieldValueInCarrierMsg(FLD_NamedOrder,"1");
	}
	ELSE
	{
		SetFieldValueInCarrierMsg(FLD_NamedOrder,"0");
	}
	
	#side mapping and set
	#'Side=2' and 'Side Qualifier = 0' for regular sells | and 'Side=2' and 'Side Qualifier=3' for sell shorts
	[sSide] := GetFieldValue1(FLD_Side);
	IF ( [sSide] = "SELL SHORT" ) THEN
	{
		SetFieldValueInCarrierMsg(FLD_Side, "SELL");
		SetFieldValueInCarrierMsg(FLD_SideQualifier , "5");
	}
	ELSE
	{
		#regular buy and sell
		SetFieldValueInCarrierMsg(FLD_Side, GetFieldValue1(FLD_Side));
		IF ( [sSide] = "BUY") THEN
		{
			SetFieldValueInCarrierMsg(FLD_SideQualifier , "1");
		}
		ELSE
		{
			SetFieldValueInCarrierMsg(FLD_SideQualifier , "2");
		}
	}	
	
	#Reset values according to the order type
	IF ( [sOrderType] = "STOP" ) THEN 
	{		
		ResetFieldInCarrierMsg(FLD_Value);	
	}
	ELSE IF ( [sOrderType] = "STOP_LIMIT" ) THEN
	{
	}
	ELSE IF ( [sOrderType] = "LIMIT" ) THEN
	{	
		ResetFieldInCarrierMsg(FLD_StopPrice);	  
	}
	ELSE IF ( [sOrderType] = "MARKET" ) DO
	{
		ResetFieldInCarrierMsg(FLD_Value);
		ResetFieldInCarrierMsg(FLD_StopPrice);
	}
	
	#expiry date/time
	CALL SetGetExpiry 1 ;
	
	SetFieldValueInCarrierMsg(FLD_OrderSubType, "ORDER");
	CALL HandleSpecialCaseBeforeSending ;
	
	IF ( [g_nEntityMode] = MODE_New ) DO
	{
	CopyCarrierMsgToPool([s_CurrentInstrument]);
	}
	
	# << 124565
	IF ( [g_nEntityMode] = MODE_Amend ) DO
	{
		# Please refer to the above comment where OrderEntry field 
		# is filled with the Unpack Message
		#----------------------------------
	
		[fOriginalQuantity] := GetFloatFieldValueFromUnpackMsg(FLD_OrderQty);
		[fOriginalRemaining] := [f_TotalSize];

		[fFinalQty] := ([fOriginalQuantity] + [fQuantity]);
		[fFinalQty] := ([fFinalQty] - [fOriginalRemaining]);

		SetFieldValueInCarrierMsg(FLD_OrderQty, FloatToString([fFinalQty],0));

		# This kind of back-end responsiblity. If sending message is an amend order
		# (not a new order) the client-order-id from the unpack message should be filled
		# in the original-client-order-id of the amend message
		#----------------------------------------------------------------------------------
		#SetFieldValueInCarrierMsg(FLD_OriginalClientOrderID,GetStringFieldValueFromUnpackMsg(FLD_ClientOrderID,0)); 
		#SetFieldValueInCarrierMsg(FLD_OwnerID,GetStringFieldValueFromUnpackMsg(FLD_OwnerID,0));
		#SetFieldValueInCarrierMsg(FLD_TraderID,GetStringFieldValueFromUnpackMsg(FLD_TraderID,0));
		#SetIntFieldValueInCarrierMsg(FLD_OrderSubType,GetIntFieldValueFromUnpackMsg(FLD_OrderSubType));
	}
	# 124565 >> 
	# << CR09 - 162588
	IF (GetCheck(CHK_Offline_Order) = 1) THEN
	{
		SetFieldValueInCarrierMsg(FLD_SourceID, "1");
	} ELSE
	{
		SetFieldValueInCarrierMsg(FLD_SourceID, "0");
	}
#CR09 - 162588 >>
	RETURN 1;
	
	# BookDefID, ClientOrderID, TraderID, UserID and BroderID  will be set from the Back-End.
}

###############################################################################
PROCEDURE OnReturnPage
        DECLARE PARAMETER nControlID	AS QUANTITY
        DECLARE PARAMETER sListName		AS TEXT DO
{
	SLogLine("OnReturnPage");
	CALL OnPress FLD_Submit, "";
}

# =================================================================================
PROCEDURE ClearOnSuccess DO
{
	SLogLine("ClearOnSuccess");
	SetFieldValue1(FLD_OrderQty, "0.0");
	SetFieldValue1(FLD_Value, "0.0");
	SetFieldValue1(FLD_StopPrice, "0.0");
	SetFieldValue1(FLD_VisibleQty, "0.0");	
	SetFieldValue1(FLD_MinimumSize, "0.0");	
	
	SetFieldValue1(FLD_Debt_Commissions, "0.0");
	SetFieldValue1(FLD_Debt_Yield, "0.0");
	SetFieldValue1(FLD_Debt_Effective_Yield, "0.0");
	
	SetFieldValue1(FLD_MinimumSize, "0.0");	
	SetFieldValue1(FLD_Remarks, "");
	SetFieldValue1(FLD_Contra, "");
	SetFieldValue1(FLD_EXPTraderID, "");

	
	CALL OnSpin FLD_Value, "", 0 ;
	CALL ClearExtra;	
}

# =================================================================================
PROCEDURE ClearExtra DO
{
	
	DECLARE VARIABLE sWndID		AS TEXT 20	
	DECLARE VARIABLE sCtrlID	AS TEXT 20
	
	DECLARE VARIABLE	sDefVal 	AS TEXT		100
	DECLARE VARIABLE	sObjKeyDefVal 	AS TEXT		30	
	DECLARE VARIABLE	sFirmVal 	AS TEXT		30	
	DECLARE VARIABLE	sBrokeTypeVal 	AS TEXT		30	


	
	[sWndID] := IntToString(GetWndID());		
	IF ( [g_nEntityMode] != MODE_Amend ) DO 
	{
		SetFieldValue1(FLD_OrderType, "LIMIT");
		CALL OnChangeCombo "", "", "LIMIT", 0, FLD_OrderType;
		SetFieldValue1(FLD_TIF, "DAY");
		CALL OnChangeCombo "", "", "DAY", 0, FLD_TIF;
		
		SetFieldValue1(FLD_AccountType, "");
		SetLock (FLD_OwnerID,	0, 0);
		SetFieldValue1(FLD_OwnerID, [s_Trader]);	
		[sObjKeyDefVal] := GetObjPoolItemKey(Datapool_DefaultVals, 0);
		[sFirmVal] := GetObjPoolItemVal(Datapool_DefaultVals, [sObjKeyDefVal], 12);
		[sObjKeyDefVal] := GetObjPoolItemKey(Datapool_DefaultVals, 0);
		[sBrokeTypeVal] := GetObjPoolItemVal(Datapool_DefaultVals, [sObjKeyDefVal], 13);

		[sCtrlID] := IntToString( GetCtrlIDByName("DEBT_Reg_Entry") );
		ExecExtSrciptProc( "EnableCustodian", [sWndID],[sCtrlID],[sFirmVal],[sBrokeTypeVal]);

		SetCheck(7500,0);	
		SetCheck(FLD_Named,0);	
	#	SetFieldValue1(FLD_OwnerID, "");
		SetFieldValue1(FLD_Capacity, "");
	
	}
	#	[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_AdvancedOptions") );
	#	ExecExtSrciptProc("RemoveSingleClick", [sWndID], [sCtrlID]);

	IF ( [s_CurrentInstrument] != " " ) DO
	{

		DECLARE VARIABLE sTradingParameterID            AS TEXT 100
		DECLARE VARIABLE	sDefVal2 	AS TEXT		100

                [sTradingParameterID] := GetObjPoolItemVal(Datapool_Instrument, [s_CurrentInstrument], 2);
                #SLogLine([sTradingParameterID]);
                #[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], 16);
                [sDefVal2] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], 17);
                #SLogLine("ClearExtraS");
                SLogLine([sDefVal2]);
                IF ([sDefVal2] = "2") THEN
                {
			#if the value is 2 it is on yield otherwise it is on price
                        SetCheck(CHK_Debt_Price, 0);
                        SetCheck(CHK_Debt_Yield, 1);

                }
                ELSE
                {
                        SetCheck(CHK_Debt_Price, 1);
                        SetCheck(CHK_Debt_Yield, 0);

                }

	} 

}



# =================================================================================
PROCEDURE ClearSizeOnSuccess DO
{
	SLogLine("ClearSizeOnSuccess");
	SetFieldValue1(FLD_OrderQty, "0.0");
	SetFieldValue1(FLD_VisibleQty, "0.0");
	SetLock (FLD_OwnerID,	0, 0);
	#141906
	SetFieldValue1(FLD_MinimumSize, "0.0");
	CALL OnSpin FLD_OrderQty, "", 0 ;
}


###############################################################################
PROCEDURE ClearInitially DO
{
# << 135450
	SLogLine("##############ClearInitially");
	#  135450 >>

	SetFieldValue1(FLD_OrderQty, "0.0");
	SetFieldValue1(FLD_Value, "0.0");
	SetFieldValue1(FLD_StopPrice, "0.0");
	SetFieldValue1(FLD_VisibleQty, "0.0");	
	
	SetLock (FLD_Named,LOCK_CONTROL,0);
	SetLock (FLD_AllwZeroVS,LOCK_CONTROL,0);

	[s_CurrentInstrument] := "";
	[s_CurrentBookDefID] := "";
	[s_ActiveSide] := "BUY";
	[s_Trader] := "" ;
}

###############################################################################
PROCEDURE ReleaseOnResponse DO
{
	SLogLine("ReleaseOnResponse");
	CALL LockAllFileds 0;
	CALL SetLocksOnOrderType GetFieldValue1(FLD_OrderType);
	CALL SetLocksOnTIF GetFieldValue1(FLD_TIF);
	
	IF ( GetCheck(FLD_AllwZeroVS) = 1 ) DO
	{
		SetLock(FLD_VisibleQty, 1, 0);
	}
	CALL LockForSpecialCases;
	CALL OnCheck CHK_Debt_Yield, "", 0 ; 
	SetLock (FLD_OwnerID,	0, 0);
}

###############################################################################
PROCEDURE OnSpin
        DECLARE PARAMETER nControlID	AS QUANTITY
        DECLARE PARAMETER sBuddyValue	AS TEXT
        DECLARE PARAMETER nType			AS QUANTITY DO
{
#	SLogLine("OnSpin");
	DECLARE VARIABLE sCurValue AS TEXT 30
	# nType 0 - UpTick, 1 - DownTick-
	
	# The TICK_FORMAT will be sent as initial string vlue from the back-end
	# The formant is    "min1|tick1|max1|min2|tick2|max2|...minN|tickN|maxN|"
	#
	# where,
	#		N is number of tick entries,
	#		A is integer from one to N
	#
	#		minA, tickA , and maxA  are floaing values and in the order defines 
	#			minimum value, tick size, and maximun value of a tick entry  
	
	DECLARE VARIABLE 	sTickString AS TEXT 300
	
	IF ( ([nControlID] = FLD_Value) OR 
		 ([nControlID] = FLD_StopPrice) ) DO
	{
		
		IF ( (([nType] = 0) OR ([nType] = 1)) ) DO
		{
			[sTickString] := GetObjPoolItemVal(Datapool_Instrument, [s_CurrentInstrument], DatapoolItem_Inst_SpinMultipleTick);
			SetValueOnTick([nControlID], [sTickString], [sBuddyValue], [nType]);
		}
	}

	CALL DoPostSpinCalculations [nControlID] ; 
	
	#166039
	IF ( [g_nEntityMode] = MODE_Amend ) DO
	{
		IF ( [nControlID] = FLD_OrderQty ) DO
		{
			IF ( [n_IsFullyVisible] = 1 ) DO
			{
				SetFieldValue1(FLD_VisibleQty, GetFieldValue1(FLD_OrderQty));
			} 
		}
	}
}

###############################################################################
PROCEDURE DoPostSpinCalculations
        DECLARE PARAMETER nControlID	AS QUANTITY DO
{
	IF ( ([nControlID] = FLD_Value) OR ( [nControlID] = FLD_OrderQty )  OR ( [nControlID] = FLD_Debt_Yield )) DO
	{
		CALL CalculateValue ;
	}
	
	IF ( ([nControlID] = FLD_Debt_Commissions) OR ( [nControlID] = FLD_OrderQty )) DO
	{
		CALL DoCommissionCalcualation ;
	}
	
	IF ([nControlID] = FLD_Debt_Yield) DO
	{
		[f_Yield] := StringToFloat(GetFieldValue1(FLD_Debt_Yield));
		CALL DoCommissionCalcualation ;
	}
	
	#important, if Calculations are done for FLD_Value alone in the procedure, Call this function with FLD_Value from UpdateAfterRoundUp Procedure 
}

#CR 150542
###############################################################################
PROCEDURE OrderConfirmMessage DO
{
	#DECLARE VARIABLE sOrderType  AS TEXT 100
	#DECLARE VARIABLE sSymbol  AS TEXT 100
	#DECLARE VARIABLE sQuantity  AS TEXT 100
	#DECLARE VARIABLE sPrice  AS TEXT 100
	#DECLARE VARIABLE sStopPrice  AS TEXT 100
	[s_Message] := "Send the Order : ";
	[s_Message] :=  StrCat([s_Message],GetFieldValue1(FLD_Side));
	[s_Message] := StrCat([s_Message]," ");
	[s_Message] :=  StrCat([s_Message],GetFieldValue1(FLD_OrderType));
	[s_Message] := StrCat([s_Message]," ");
	[s_Message] :=  StrCat([s_Message],GetObjPoolItemVal(Datapool_Instrument, [s_CurrentInstrument], 0));
	[s_Message] := StrCat([s_Message]," ");
	[s_Message] :=  StrCat([s_Message],GetFieldValue1(FLD_OrderQty));
	
	IF ((GetFieldValue1(FLD_OrderType) = "LIMIT") OR (GetFieldValue1(FLD_OrderType) = "STOP_LIMIT")) DO
	{
		[s_Message] := StrCat([s_Message]," @ ");
		[s_Message] :=  StrCat([s_Message],GetFieldValue1(FLD_Value));
	} 
	
	IF ((GetFieldValue1(FLD_OrderType) = "STOP") OR (GetFieldValue1(FLD_OrderType) = "STOP_LIMIT")) DO
	{
		[s_Message] := StrCat([s_Message]," [Stop Price : ");
		[s_Message] :=  StrCat([s_Message],GetFieldValue1(FLD_StopPrice));
		[s_Message] := StrCat([s_Message]," ]");
	} 
	
	[s_Message] := StrCat([s_Message]," ?");
	#CALL AddToMsg GetFieldValue1(FLD_OrderQty);
	#CALL AddToMsg GetFieldValue1(FLD_Value) ;

	#[sMessage] ; 
	
}

# When price or stop price spinner is pressed.
# =================================================================================
PROCEDURE OnPress
        DECLARE PARAMETER nButtonID as QUANTITY
        DECLARE PARAMETER sButtonName as TEXT DO
{
	SLogLine("OnPress");
		DECLARE VARIABLE nSuccess	AS QUANTITY
		DECLARE VARIABLE nResponse	AS QUANTITY


	IF ([nButtonID] = FLD_Submit) THEN
	{	
# << 135450
		SLogLine("Onpress************");
		SLogLine([s_CurrentInstrument]);
		SLogLine([s_CurrentBookDefID]);
			# 135450 >>
		[nSuccess] := PackMessage();
		
		IF ( [nSuccess] = 1 ) DO
		{
			
			IF ( [n_ConfirmSubmit] = 1) THEN
			{
				#CR 150542
				CALL OrderConfirmMessage ;
				[nResponse] := MessageBox([s_Message],"Confirm",MSG_BOX_TYPE_YesNo,MSG_BOX_ICON_Question);
				
				IF ( [nResponse] = MSG_BOX_RES_Yes) DO
				{
					SendMsg();
					CALL LockAllFileds 1;
				}
			}
			ELSE
			{
				SendMsg();
				CALL LockAllFileds 1;
			}
		}
	}
	ELSE IF ( [nButtonID] = n_BtnMore ) THEN 
	{
		IF ( [n_FormExpanded] = 0 ) THEN
		{
			[n_FormExpanded] := 1;
			ChangeControlName(n_BtnMore, "<<");
		}
		ELSE
		{
			[n_FormExpanded] := 0;
			ChangeControlName(n_BtnMore, ">>");
		}
		
		DECLARE VARIABLE nID 				AS QUANTITY
		DECLARE VARIABLE sWndID				AS TEXT 20
		DECLARE VARIABLE sLayoutCtrlID		AS TEXT 20				
		DECLARE VARIABLE sBtnID				AS TEXT 20
		DECLARE VARIABLE sExpandState		AS TEXT 20
		
		[nID] 			:= GetWndID();
		[sBtnID]		:= IntToString( n_BtnMore );		
		[sWndID] 		:= IntToString( [nID] );
		[sLayoutCtrlID] := IntToString( GetCtrlIDByName("OrderEntry") );
		[sExpandState]  := IntToString( [n_FormExpanded] );
		
		ExecExtSrciptProc("OnExpandButtonClicked", [sWndID], [sLayoutCtrlID], [sBtnID], [sExpandState]);	
	}
	ELSE IF ( [nButtonID] = FLD_Clear ) DO
	{
		CALL ClearOnSuccess; 
	}
}


###############################################################################
PROCEDURE ToggleOrder DO
{
	SLogLine("ToggleOrder");
	#SetLock(FLD_Capacity, 0, 0 );
	DECLARE VARIABLE sSide			AS TEXT		50
	[sSide] := GetFieldValue1(FLD_Side);
	
	IF ( [sSide] = "SELL SHORT" ) THEN
	{
		ChangeControlName(FLD_Submit, "SELL");	
	}
	ELSE
	{
		ChangeControlName(FLD_Submit, GetFieldValue1(FLD_Side));
	}
}

###############################################################################
PROCEDURE OnCheck
        DECLARE PARAMETER nControlID as QUANTITY
        DECLARE PARAMETER sName as TEXT
        DECLARE PARAMETER nValue as QUANTITY DO
{
	SLogLine("OnCheck");
	IF ([nControlID] = FLD_AllwZeroVS) DO
	{
		IF ([nValue] = 1) THEN
		{
			SetFieldValue1(FLD_VisibleQty, "");
			SetLock(FLD_VisibleQty, 1, 0);
		}
		ELSE
		{
			SetFieldValue1(FLD_VisibleQty, "");
			SetLock(FLD_VisibleQty, 0, 0);
		}
	}

	DECLARE VARIABLE nPriceEnable	AS QUANTITY

	[nPriceEnable] := -1 ; 
	
	IF ((([nControlID] = CHK_Debt_Yield) AND ([nValue] = 1)) OR (([nControlID] = CHK_Debt_Price) AND ([nValue] = 0))) THEN
	{
		[nPriceEnable] := 0 ; 
	} ELSE IF ((([nControlID] = CHK_Debt_Yield) AND ([nValue] = 0)) OR (([nControlID] = CHK_Debt_Price) AND ([nValue] = 1))) DO
	{
		[nPriceEnable] := 1 ; 
	}
	
	IF ([nPriceEnable] = -1) DO
	{
		RETURN
	}
	
	IF ( ([nPriceEnable] = 1) AND ([n_TradeMethod] != TRADE_METHOD_ON_PRICE) ) DO
	{	
		[nPriceEnable] := 0 ;
	}

	IF ([nPriceEnable] = 0 ) THEN 
	{
		SetCheck(CHK_Debt_Price, 0);
		SetCheck(CHK_Debt_Yield, 1);
		
		SetLock(FLD_Value, LOCK_CONTROL, 0);

		#129836
		IF ( [n_TradeMethod] = TRADE_METHOD_ON_PRICE ) THEN
		{
			ChangeControlTextColor(FLD_Value, 200,200,200);
		} ELSE
		{
			ChangeControlTextColor(FLD_Value , 255,255,255);
		}
		
		SetLock(FLD_Debt_Yield , UNLOCK_CONTROL, 0);
		ChangeControlTextColor(FLD_Debt_Yield , 0,0,0);
	} ELSE 	
	{
		SetCheck(CHK_Debt_Yield, 0);
		SetCheck(CHK_Debt_Price, 1);
		
		SetLock(FLD_Value, UNLOCK_CONTROL, 0);
		ChangeControlTextColor(FLD_Value, 0,0,0);
		
		SetLock(FLD_Debt_Yield , LOCK_CONTROL, 0);
		ChangeControlTextColor(FLD_Debt_Yield , 200,200,200);
	}

			
}

###############################################################################
PROCEDURE AddOtherSideValues DO
{
	SLogLine("AddOtherSideValues");
	AddListEntry1(FLD_Side,"SELL SHORT", "");
}

###############################################################################
PROCEDURE InitializeOrderEntry DO
{
	SLogLine("InitializeOrderEntry");
	#SetLock(FLD_OwnerID, UNLOCK_CONTROL, SHOW_PIC_FALSE);
	
	ChangeControlTextColor(FLD_CalculatedVal, 200,200,200);
	SetLock(FLD_CalculatedVal, 1, 0 );
		
	CALL SetFirmUsers ;
	
	CALL InitializeDebtRelatedFields ; 
}

###############################################################################
PROCEDURE OnInitForm DO
{	
	SLogLine("OnInitForm");
	#publish datapool values for enum dropdowns
	
	SetControlPool(FLD_Side, FLD_Side);
	SetControlPool(FLD_TIF, FLD_TIF);
	SetControlPool(FLD_OrderType, FLD_OrderType);
	SetControlPool(FLD_Capacity, FLD_Capacity);
	SetControlPool(FLD_AccountType, FLD_AccountType);	
		
	AddListEntry1(FLD_Capacity, " ", "");
	RemoveListEntry2(FLD_Capacity, "ALL_CAPACITIES");

	AddListEntry1(FLD_AccountType, " ", "");
	
	[s_CurrentInstrument] := "";
	[s_CurrentBookDefID] := "";
	[s_Trader] := "";
	
	[n_FormExpanded] := 0;
	[n_ConfirmSubmit] := 0 ;
	
	#129836
	[n_TradeMethod] := -1 ; 
	
# << 135450
	[s_ActiveSide] := "";
# 135450 >>

CALL SetQuickLotUpdateField FLD_OrderQty ; 

	#166039
	[n_IsFullyVisible] := 0;
}

PROCEDURE SetOrderConfirmation
	DECLARE PARAMETER sSetConfirmation AS TEXT	DO
{
	SLogLine("SetOrderConfirmation");
	[n_ConfirmSubmit] := StringToInt([sSetConfirmation]);
}

###############################################################################
PROCEDURE ResetToInitialState DO
{	
	SLogLine("ResetToInitialState");
	#do locking		
	CALL ClearInitially;	
	[s_CurrentInstrument] := "";
	[s_CurrentBookDefID] := "";
	[s_Trader] := "" ; 
	ResetMsgPool();
	
	#CR 122830
	[s_ActiveSide] := "BUY";
	
	CALL SetDefaults ; 
}

###############################################################################
PROCEDURE InitNewOrder
	DECLARE PARAMETER sMsgID AS TEXT	DO
{
	SLogLine("InitNewOrder");
	[i_MsgID] := StringToInt([sMsgID]);
	
	AddEnumField(FLD_OrderType, EnumID_OrderType);
	AddEnumField(FLD_Side, EnumID_Side);
	AddEnumField(FLD_Capacity, EnumID_Capacity);
	AddEnumField(FLD_TIF, EnumID_Validity);
	
}

#################################################################################
PROCEDURE SetFirmUsers	DO
{
	SLogLine("SetFirmUsers");
	DECLARE VARIABLE nCount AS QUANTITY
	DECLARE VARIABLE nIndex AS QUANTITY
	DECLARE VARIABLE sFirmUser 			AS TEXT		100 

	RemoveListEntry2(FLD_OwnerID, "");
	[nCount] := GetObjPoolItemCount(Datapool_FirmUsers);	
	[nIndex] := 0;
	[sFirmUser] := "";
	
	WHILE ( [nIndex] < [nCount] ) DO
	{		
		
		[sFirmUser] := GetObjPoolItemKey( Datapool_FirmUsers, [nIndex] );
		AddListEntry1(FLD_OwnerID, [sFirmUser],"");
				
		[nIndex] := ( [nIndex] + 1 );	
	}		
}


###############################################################################
PROCEDURE OnNotifySelectInstrument 
	DECLARE PARAMETER sInstrument AS TEXT
	DECLARE PARAMETER sBookDefID  AS TEXT DO
{		
# << 135450
	DECLARE VARIABLE sOldBookDef		AS TEXT		50
	SLogLine("OnNotifySelectInstrument#############");
	SLogLine([sInstrument]);
	SLogLine([sBookDefID]);
	# 135450 >>		
	#129836
	IF ([s_CurrentInstrument] != [sInstrument]) DO
	{
		DECLARE VARIABLE sTradingParameterID		AS TEXT 100
		DECLARE VARIABLE sVal	 					AS TEXT	100
		[sTradingParameterID] := GetObjPoolItemVal(Datapool_Instrument, [sInstrument], 2);

		[sVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], TRADE_METHOD);
		[n_TradeMethod] := StringToInt([sVal]);
		
	}
	
	IF ( [g_nEntityMode] = MODE_Amend ) DO
	{
		SLogLine("RETURN_DUE_TO_MODE_AMEND");
		[s_CurrentInstrument] := [sInstrument];
		
		CALL OnCheck CHK_Debt_Yield, "", 0 ;
		STOP
	}

	[sOldBookDef] := [s_CurrentBookDefID];		
	[s_CurrentBookDefID] := [sBookDefID];

	#[Msg 1] [Msg 2] [Msg 3] [Msg 4] ... [Msg n]
	
	#1) Save the user input vaues to the old tabs message
	IF ( [s_CurrentInstrument] != "" ) DO
	{
		IF ([s_CurrentInstrument] = [sInstrument]) DO
		{
			#if current bnook equals comming from anouther form
			IF ([sOldBookDef] = [sBookDefID]) THEN
			{
				#CALL SetValuesforAONNoTIF ; 
				CALL SetValuesforAON [sInstrument], 0; 
			}	
			ELSE
			{
				CALL SetValuesforAON [sInstrument], 1; 
			}
			
			RETURN
		}
		
		GetCarrierMsgFromPool([s_CurrentInstrument]);
		
		SetFieldValueInCarrierMsg(FLD_OrderType, GetFieldValue1(FLD_OrderType));
		SetFieldValueInCarrierMsg(FLD_AccountType, GetFieldValue1(FLD_AccountType));
		SetFieldValueInCarrierMsg(FLD_Side, GetFieldValue1(FLD_Side));
		SetFieldValueInCarrierMsg(FLD_Value, GetFieldValue1(FLD_Value));
		SetFieldValueInCarrierMsg(FLD_OrderQty, GetFieldValue1(FLD_OrderQty));
		SetFieldValueInCarrierMsg(FLD_VisibleQty, GetFieldValue1(FLD_VisibleQty));
		SetFieldValueInCarrierMsg(FLD_MinimumSize, GetFieldValue1(FLD_MinimumSize));
	#>>168597	
		IF ( [s_ResetFieldSide] = "0" ) THEN 
		{
			
			SLogLine("setting s field in carrier message");
			SetFieldValueInCarrierMsg(FLD_SourceID , "1");
		}
		ELSE
		{
		
			#SetFieldValueInCarrierMsg( 2666 , "0");
			ResetFieldInCarrierMsg(FLD_SourceID);
		}

#			SetFieldValueInCarrierMsg( 2666 , "0");
#>>168597
		# To Do : Handle All Capacity Issue 
		SetFieldValueInCarrierMsg(FLD_Capacity, GetFieldValue1(FLD_Capacity));


		SetFieldValueInCarrierMsg(FLD_StopPrice, GetFieldValue1(FLD_StopPrice));
		SetFieldValueInCarrierMsg(FLD_EXPTraderID, GetFieldValue1(FLD_EXPTraderID));
		SetFieldValueInCarrierMsg(FLD_Contra, GetFieldValue1(FLD_Contra));
		SetFieldValueInCarrierMsg(FLD_Remarks, GetFieldValue1(FLD_Remarks));
		
		#Set Debt Fields 
		SetFieldValueInCarrierMsg(FLD_Debt_Commissions, GetFieldValue1(FLD_Debt_Commissions));
		SetFieldValueInCarrierMsg(FLD_Debt_Yield, GetFieldValue1(FLD_Debt_Yield));
		SetFieldValueInCarrierMsg(FLD_Debt_Effective_Yield, GetFieldValue1(FLD_Debt_Effective_Yield));
		
		SetFieldValueInCarrierMsg(FLD_TraderID, GetFieldValue1(FLD_TraderID));
		SetFieldValueInCarrierMsg(FLD_OwnerID, GetFieldValue1(FLD_OwnerID));
		SetFieldValueInCarrierMsg(FLD_TIF, GetFieldValue1(FLD_TIF));
		
		IF ( GetCheck(FLD_Named) = 1 ) THEN
		{
			SetFieldValueInCarrierMsg(FLD_NamedOrder,"1");
		}
		ELSE
		{
			SetFieldValueInCarrierMsg(FLD_NamedOrder,"0");
		}
	
		IF (GetCheck(FLD_AllwZeroVS) = 1) THEN
		{	
			SetFieldValueInCarrierMsg(FLD_AllwZeroVS,"1");
		} ELSE
		{
			SetFieldValueInCarrierMsg(FLD_AllwZeroVS,"0");
		}
		#expiry date / time
		CALL SetGetExpiry 1 ; 
				
		CopyCarrierMsgToPool([s_CurrentInstrument]);

	}
	

		
	CALL ClearBeforeNewOrder ; 
	CALL InitializeDebtRelatedFields ; 
	#2) get the created message relavant to this tab and populate values to the fields from it
	
	DECLARE VARIABLE nIsNewMessage AS QUANTITY
	[nIsNewMessage] := CreateMsgInPool([sInstrument], [i_MsgID]);
	
	IF ( [nIsNewMessage] = 0 ) THEN
	{
		#message already exist
		GetUnpackMsgFromPool([sInstrument]);
		CALL SetAccordingToTradingParameter [sInstrument] ;
		
		SetFieldValue1(FLD_OrderType, GetStringFieldValueFromUnpackMsg(FLD_OrderType, GetIntFieldValueFromUnpackMsg(FLD_OrderType)));
		
		#-- << START >> Sell Short is not defined as an entity in Exman, therefore a value of 0 will be returned and it has to be handled 
		DECLARE VARIABLE	sSide 		AS TEXT		20
		[sSide] := GetStringFieldValueFromUnpackMsg(FLD_Side, 0);
		IF ( [sSide] = "0" ) DO
		{
			[sSide] := "SELL SHORT";
		}
		#-- << END >> 
		
		SetFieldValue1(FLD_Side, [sSide]);
	#>>168597	
			
		DECLARE VARIABLE nCurWorkingSide AS TEXT  10
			
		DECLARE VARIABLE nCurValReset AS QUANTITY;
		[nCurValReset] := GetIntFieldValueFromUnpackMsg( FLD_SourceID);
		IF ( [nCurValReset] = 1 ) THEN 
		{
			
			SLogLine("resetting to active side");
			SetFieldValue1(FLD_Side, [s_ActiveSide]);
			
			SLogLine([s_ActiveSide]);

			SLogLine(GetStringFieldValueFromUnpackMsg(FLD_Side, GetIntFieldValueFromUnpackMsg(FLD_Side))  );
		#	ResetFieldInCarrierMsg(FLD_Side);
		#	SetFieldValueInCarrierMsg(FLD_Side, [s_ActiveSide]);
			#CopyCarrierMsgToPool([sInstrument]);
			SLogLine(GetStringFieldValueFromUnpackMsg(FLD_Side, GetIntFieldValueFromUnpackMsg(FLD_Side))  );
			[sSide]	:= [s_ActiveSide];

			[nCurWorkingSide] := [s_ActiveSide];

			ResetFieldInCarrierMsg(FLD_SourceID);
		}
		ELSE
		{
			[nCurWorkingSide] := GetStringFieldValueFromUnpackMsg(FLD_Side, GetIntFieldValueFromUnpackMsg(FLD_Side)); 
		}
	#>>168597	
		SetFieldValue1(FLD_Value, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_Value), 4));
		SetFieldValue1(FLD_OrderQty, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_OrderQty), 4));
		SetFieldValue1(FLD_VisibleQty, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_VisibleQty), 4));
		SetFieldValue1(FLD_MinimumSize, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_MinimumSize), 4));
		SetFieldValue1(FLD_Capacity,GetStringFieldValueFromUnpackMsg(FLD_Capacity, GetIntFieldValueFromUnpackMsg(FLD_Capacity)));
		SetFieldValue1(FLD_AccountType,GetStringFieldValueFromUnpackMsg(FLD_AccountType, GetIntFieldValueFromUnpackMsg(FLD_AccountType)));
		
		DECLARE VARIABLE sCapacity		AS TEXT 50

		[sCapacity] := GetFieldValue1(FLD_Capacity);
		IF ( ([sCapacity] = "ALL_CAPACITIES") ) DO
		{			
			SetFieldValue1(FLD_Capacity,"AGENCY");
		}
		
		SetFieldValue1(FLD_StopPrice, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_StopPrice), 4));
		SetFieldValue1(FLD_EXPTraderID, GetStringFieldValueFromUnpackMsg(FLD_EXPTraderID, 0));
		SetFieldValue1(FLD_Contra, GetStringFieldValueFromUnpackMsg(FLD_Contra, 0));
		SetFieldValue1(FLD_Remarks, GetStringFieldValueFromUnpackMsg(FLD_Remarks, 0));
		SetFieldValue1(FLD_TraderID, GetStringFieldValueFromUnpackMsg(FLD_TraderID, 0));
		SetFieldValue1(FLD_OwnerID, GetStringFieldValueFromUnpackMsg(FLD_OwnerID, 0));
		
		#Set Debt Fields 
		SetFieldValue1(FLD_Debt_Commissions, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_Debt_Commissions), 4));
		SetFieldValue1(FLD_Debt_Yield, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_Debt_Yield), 4));
		SetFieldValue1(FLD_Debt_Effective_Yield, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_Debt_Effective_Yield), 4));
		
		
		SetFieldValue1(FLD_TIF,GetStringFieldValueFromUnpackMsg(FLD_TIF, GetIntFieldValueFromUnpackMsg(FLD_TIF)));
		
				IF ( GetIntFieldValueFromUnpackMsg(FLD_NamedOrder) = 1 ) THEN
		{
			SetCheck(FLD_Named,1);
		}
		ELSE
		{
			SetCheck(FLD_Named,0);
		}
		
		IF ( GetIntFieldValueFromUnpackMsg(FLD_AllwZeroVS) = 1 ) THEN
		{
			SetCheck(FLD_AllwZeroVS,1);
		}
		ELSE
		{
			SetCheck(FLD_AllwZeroVS,0);
		}
		
		#expiry date / time
		CALL SetGetExpiry 0 ; 
		#enable disable and color changes of dependent ctrls
		#do required changes related to some fields
#>>168597 changing to nCurWorking side from GetingStringField
		CALL OnChangeCombo "", "", [nCurWorkingSide], 0, FLD_Side;
		CALL OnChangeCombo "", "", GetStringFieldValueFromUnpackMsg(FLD_TIF, GetIntFieldValueFromUnpackMsg(FLD_TIF)), 0, FLD_TIF;
		CALL OnChangeCombo "", "", GetStringFieldValueFromUnpackMsg(FLD_Capacity, GetIntFieldValueFromUnpackMsg(FLD_Capacity)), 0, FLD_Capacity;
		CALL OnChangeCombo "", "", GetStringFieldValueFromUnpackMsg(FLD_OrderType, GetIntFieldValueFromUnpackMsg(FLD_OrderType)), 0, FLD_OrderType;
		
		#CALL SetValuesforAONNoTIF;
		CALL SetValuesforAON [sInstrument], 0; 
		
	}
	ELSE
	{
		CALL InitWithDefaults [sInstrument];
		CALL SetValuesforAON [sInstrument], 1; 
	}
	
	[s_CurrentInstrument] := [sInstrument];
	[s_CurrentBookDefID] := [sBookDefID];
	
	#lot size increment should be set----------------------------------
	DECLARE VARIABLE	sMarketFee 		AS TEXT		100
	[sMarketFee] := GetObjPoolItemVal(Datapool_Instrument, [s_CurrentInstrument], DatapoolItem_Inst_MarketFee);
	SetFieldValue1(FLD_Debt_Fee, [sMarketFee]);
		
	SetFieldValue1(FLD_OwnerID, [s_Trader]);
        CALL LockForSpecialCases;
	CALL SetSpinIncrements ;

	#SetFieldValue1(2053, "BUY");
# << 135450
	SLogLine("OnNotifySelectInstrument END #############");
	SLogLine([s_CurrentInstrument]);
	SLogLine([s_CurrentBookDefID]);
	
	CALL SetQuickLotUpdateField FLD_OrderQty ;
	SetLock (FLD_OwnerID,	0, 0);
# 135450>>
}

PROCEDURE SetValuesforAON
	DECLARE PARAMETER sInstrument	AS TEXT 
	DECLARE PARAMETER nSetTIF AS QUANTITY DO 
{


	DECLARE VARIABLE	sPoolSetOrderType 		AS TEXT		20

	IF ( [s_CurrentBookDefID] = "AON" ) THEN
	{
                SetFieldValue1(FLD_OrderType,"LIMIT" );
                SetLock (FLD_OrderType, 1 , 0);
                SetFieldValue1(FLD_TIF,"GTC" );
                SetLock (FLD_TIF,1 , 0);
	}ELSE IF ( [s_CurrentBookDefID] = "DEF_AUC" ) THEN
	{
		[sPoolSetOrderType] 	:=  GetFieldValue1(FLD_OrderType);

		RemoveListEntry2(FLD_OrderType, "");
		AddListEntry3(FLD_OrderType, "LIMIT");
		AddListEntry3(FLD_OrderType, "MARKET");
		SetFieldValue1(FLD_TIF,"DAY" );
        SetLock (FLD_TIF,1 , 0);

		IF ([nSetTIF] = 1 ) THEN 
		{
			SetFieldValue1(FLD_OrderType,"LIMIT" );
        } ELSE
	{
			
			SetFieldValue1(FLD_OrderType,[sPoolSetOrderType] );
		}	
                SetLock (FLD_OrderType, 0 , 0);
                

	}ELSE
	{
		SLogLine([s_CurrentInstrument]);

                SetLock (FLD_OrderType, 0 , 0);
                SetLock (FLD_TIF,0 , 0);

		IF ([nSetTIF] = 1 ) THEN 
		{
                SetFieldValue1(FLD_TIF,"DAY" );
			CALL SetOrderTypeAccordingToTradingParameter [sInstrument];
			SetFieldValue1(FLD_OrderType,"LIMIT" );
		}ELSE
		{
		
		}
	}

}


PROCEDURE SetValuesforAONNoTIF DO
{


	IF ( [s_CurrentBookDefID] = "AON" ) THEN
	{
                SetFieldValue1(FLD_OrderType,"LIMIT" );
                SetLock (FLD_OrderType, 1 , 0);
                SetFieldValue1(FLD_TIF,"GTC" );
                SetLock (FLD_TIF,1 , 0);
        } ELSE
	{
                SetLock (FLD_OrderType, 0 , 0);
                SetLock (FLD_TIF,0 , 0);
                #SetFieldValue1(FLD_TIF,"DAY" );
	}

}
#Issue 121726 : [CSE][Trader FE] The spinner of the Price Field should consider Price Tick set for the Instrument
PROCEDURE SetSpinIncrements DO
{
	SLogLine("SetSpinIncrements");
	#lot size increment should be set----------------------------------
	DECLARE VARIABLE	sDefVal 				AS TEXT		100
	DECLARE VARIABLE	sSpinMultipleTick 		AS TEXT		100
	DECLARE VARIABLE 	nLotSize				AS QUANTITY
	DECLARE VARIABLE 	nTickIncriment			AS PRICE
	
	[sDefVal] := GetObjPoolItemVal(Datapool_Instrument, [s_CurrentInstrument], 3);
	[nLotSize] := StringToInt([sDefVal]);
		
	SetBuddyIntInc(FLD_OrderQty, [nLotSize] );
	SetBuddyIntInc(FLD_VisibleQty, [nLotSize] );
	SetBuddyIntInc(FLD_MinimumSize, [nLotSize]);
	
	[sDefVal] := GetObjPoolItemVal(Datapool_Instrument, [s_CurrentInstrument], DatapoolItem_Inst_TickIncrement);
	[nTickIncriment] := StringToFloat([sDefVal]);

	#SetBuddyFloatInc(FLD_Value, [nTickIncriment] );
	#SetBuddyFloatInc(FLD_StopPrice, [nTickIncriment]);
	
	#[sSpinMultipleTick] := GetObjPoolItemVal(Datapool_Instrument, [s_CurrentInstrument], DatapoolItem_Inst_SpinMultipleTick);
	#SetBuddyMultipleTick(FLD_Value,[sSpinMultipleTick]);

}

PROCEDURE SetDefaults DO
{
	SLogLine("SetDefaults");
	#set defaults
	#############
	DECLARE VARIABLE	sDefVal 	AS TEXT		100
	DECLARE VARIABLE	sObjKeyDefVal 	AS TEXT		30	

	[sObjKeyDefVal] := GetObjPoolItemKey(Datapool_DefaultVals, 0);
	[s_Trader] := GetObjPoolItemVal(Datapool_DefaultVals, [sObjKeyDefVal], 0);
	SetFieldValue1(FLD_OwnerID, [s_Trader]);
	
	#def OrdType 
	[sDefVal] := GetObjPoolItemVal(Datapool_DefaultVals, [sObjKeyDefVal], 2);
	SetFieldValue1(FLD_OrderType,[sDefVal]);
	CALL OnChangeCombo "", "", [sDefVal], 0, FLD_OrderType;
	
	#CR 122830 <<<
	#def side
	IF ( [s_ActiveSide] != "" ) THEN
	{
		[sDefVal] := [s_ActiveSide] ;
	} ELSE 
	{
		[sDefVal] := GetObjPoolItemVal(Datapool_DefaultVals, [sObjKeyDefVal], 1);
# << 135450
		[s_ActiveSide] := [sDefVal]; 
# 135450 >>
	}
	#CR 122830 >>>
	SetFieldValue1(FLD_Side, [sDefVal]);
	CALL OnChangeCombo "", "", [sDefVal], 0, FLD_Side;
	
	#def validity
	[sDefVal] := GetObjPoolItemVal(Datapool_DefaultVals, [sObjKeyDefVal], 3);
	SetFieldValue1(FLD_TIF, [sDefVal]);
	CALL OnChangeCombo "", "", [sDefVal], 0, FLD_TIF;
	
	[sDefVal] := GetObjPoolItemVal(Datapool_DefaultVals, [sObjKeyDefVal], 10);
	SetFieldValue1(FLD_AccountType, [sDefVal]);
	
	[sDefVal] := GetObjPoolItemVal(Datapool_DefaultVals, [sObjKeyDefVal], 11);
	SetFieldValue1(FLD_Capacity, [sDefVal]);
	
	SetCheck(FLD_Named,0);
	SetCheck(FLD_AllwZeroVS,0);
}

#CR 122830
PROCEDURE SetSide
	DECLARE PARAMETER sSide		AS TEXT DO
{
	SLogLine("SetSide");
	[s_ActiveSide] := [sSide] ;
	
	#<< 135484
	ChangeControlName(FLD_Submit, [sSide]);	
	#	135484 >>
	
	IF ( [s_CurrentInstrument] != "" ) DO
	{
		SetFieldValue1(FLD_Side, [s_ActiveSide]);
		CALL OnChangeCombo "", "", [s_ActiveSide], 0, FLD_Side;
	}
}


PROCEDURE OnNotifyMsgPoolUpdate
	DECLARE PARAMETER nPoolID	AS QUANTITY 
	DECLARE PARAMETER sKey		AS TEXT DO
{
	SLogLine("OnNotifyMsgPoolUpdate");
	#MessageBox("OnNotifyMsgPoolUpdate","",1,1);
}

###############################################################################
PROCEDURE InitWithDefaults 
	DECLARE PARAMETER sInstrument AS TEXT	DO
{	
	SLogLine("InitWithDefaults");
	CALL LockAllFileds UNLOCK_CONTROL ; 
	
	CALL SetAccordingToTradingParameter [sInstrument] ;
	
	CALL SetDefaults ;
}

PROCEDURE SetOrderTypeAccordingToTradingParameter 
	DECLARE PARAMETER sInstrument AS TEXT	DO
{

	
	SLogLine("SetOrderTypeAccordingToTradingParameter ");
	DECLARE VARIABLE sTradingParameterID		AS TEXT 100
	DECLARE VARIABLE sDefVal 	AS TEXT		100
	[sTradingParameterID] := GetObjPoolItemVal(Datapool_Instrument, [sInstrument], 2);
	#-- Enable Disable Order Typeset n
	RemoveListEntry2(FLD_OrderType, "");
	
	SLogLine([sInstrument]);
	AddListEntry3(FLD_OrderType, "LIMIT");
	
	[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], ENABLE_MARKET_ORDERS);
	IF ([sDefVal] = "1") DO
	{
		AddListEntry3(FLD_OrderType, "MARKET");
	}
		
	[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], ENABLE_STOP_ORDERS);
	IF ([sDefVal] = "1") DO
	{
#////166566
		IF ( GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], ENABLE_MARKET_ORDERS) = "1") DO
		{
			AddListEntry3(FLD_OrderType, "STOP");
		}
		#134345
		AddListEntry3(FLD_OrderType, "STOP_LIMIT");
	}
		
	
	#-- END Enable Disable Order Types 

}


PROCEDURE SetAccordingToTradingParameter 
	DECLARE PARAMETER sInstrument AS TEXT	DO
{
	SLogLine("SetAccordingToTradingParameter");
#-- Get Trading Parameter related values
	DECLARE VARIABLE sTradingParameterID		AS TEXT 100
	DECLARE VARIABLE sDefVal 	AS TEXT		100
	[sTradingParameterID] := GetObjPoolItemVal(Datapool_Instrument, [sInstrument], 2);
	
	#-- Enable Disable Order Types 
	RemoveListEntry2(FLD_OrderType, "");
	
	AddListEntry3(FLD_OrderType, "LIMIT");
	
	[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], ENABLE_MARKET_ORDERS);
	IF ([sDefVal] = "1") DO
	{
		AddListEntry3(FLD_OrderType, "MARKET");
	}
		
	[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], ENABLE_STOP_ORDERS);
	IF ([sDefVal] = "1") DO
	{
		AddListEntry3(FLD_OrderType, "STOP");
			#134345
		AddListEntry3(FLD_OrderType, "STOP_LIMIT");
	}

	#-- END Enable Disable Order Types 
	
	#-- Enable Disable Entries in Side Field 
	RemoveListEntry2(FLD_Side, "");
	
	AddListEntry3(FLD_Side, "BUY");
	AddListEntry3(FLD_Side, "SELL");
	
	[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], ENABLE_SHORT_SALES);
	IF ([sDefVal] = "1") DO
	{
		AddListEntry3(FLD_Side, "SELL SHORT");
	}
	#-- END Enable Disable Entries in Side Field 
	
	#-- Change TIFS Depending on the Trading Parameter 
	RemoveListEntry2(FLD_TIF, "");
	
	[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], ENABLE_ATC);
	IF ([sDefVal] = "1") DO
	{
		AddListEntry3(FLD_TIF, "ATC");
	}
	
	AddListEntry3(FLD_TIF, "DAY");
	
	[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], ENABLE_FOK);
	IF ([sDefVal] = "1") DO
	{
		AddListEntry3(FLD_TIF, "FOK");
	}
	
	
	
	[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], ENABLE_GTC);
	IF ([sDefVal] = "1") DO
	{
		AddListEntry3(FLD_TIF, "GTC");
	}
	
	[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], ENABLE_GTD);
	IF ([sDefVal] = "1") DO
	{
		AddListEntry3(FLD_TIF, "GTD");
	}
	
	[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], ENABLE_GTT);
	IF ([sDefVal] = "1") DO
	{
		AddListEntry3(FLD_TIF, "GTT");
	}
	
	AddListEntry3(FLD_TIF, "IOC");
	
	[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], ENABLE_OPG);
	IF ([sDefVal] = "1") DO
	{
		AddListEntry3(FLD_TIF, "OPG");
	}
	
	
	[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], ENABLE_GFA);
	IF ([sDefVal] = "1") DO
	{
		AddListEntry3(FLD_TIF, "GFA");
	}
	
	#126873
	[sDefVal] := GetObjPoolItemVal(Datapool_TradingPara, [sTradingParameterID], MAX_ORDER_DURATION);
	DECLARE VARIABLE nMaxOrderDuration	AS QUANTITY
	[nMaxOrderDuration] := StringToInt([sDefVal]);
	
	IF ( [nMaxOrderDuration] > 0 ) DO
	{
		# MSE SetBuddyMax(FLD_Days_To_Expire, [nMaxOrderDuration]);
	}
	#-- Change TIFS Depending on the Trading Parameter 
}

PROCEDURE ClearBeforeNewOrder DO
{
	SLogLine("ClearBeforeNewOrder");
	#--Enum Fields
	SetFieldValue1(FLD_Side, "");
	SetFieldValue1(FLD_TIF, "");
	SetFieldValue1(FLD_OrderType, "");
	SetFieldValue1(FLD_AccountType, "");
	SetFieldValue1(FLD_Capacity, "");
	
	#--Text Fields
	SetFieldValue1(CTRL_EXP_DATE_TIME, "");
	# MSE SetFieldValue1(FLD_Days_To_Expire, "1");
	# MSE ChangeControlTextColor(FLD_Days_To_Expire, 200,200,200);
	
	SetFieldValue1(FLD_ClearingMnemonic, "");
	SetFieldValue1(FLD_ClientID, "");
	SetFieldValue1(FLD_EXPTraderID, "");
	SetFieldValue1(FLD_Contra, "");
	SetFieldValue1(FLD_Remarks, "");
	
	SetFieldValue1(FLD_OwnerID, "");
	
	#--Float Values
	SetFieldValue1(FLD_Value, "0.0");
	SetFieldValue1(FLD_StopPrice, "0.0");
	
	#--Int Values
	SetFieldValue1(FLD_OrderQty, "0");
	SetFieldValue1(FLD_VisibleQty, "0");
	SetFieldValue1(FLD_MinimumSize, "0");
	
	#Set Debt Fields 
	SetFieldValue1(FLD_Debt_Commissions, "0.0");
	SetFieldValue1(FLD_Debt_Yield, "0.0");
	SetFieldValue1(FLD_Debt_Effective_Yield, "0.0");
	
}
	
	
###############################################################################
PROCEDURE RemoveInstrumentFromOE
	DECLARE PARAMETER sInstrument AS TEXT	DO
{
	SLogLine("RemoveInstrumentFromOE");
	#Instrument Remove Should be handled 
}

###################################################################
PROCEDURE SetSize
		 DECLARE PARAMETER sVal AS TEXT DO
{
	SLogLine("SetSize");
	
	IF (([n_QuickLotIncerementField] != FLD_MinimumSize) AND ([n_QuickLotIncerementField] != FLD_OrderQty) AND ([n_QuickLotIncerementField] != FLD_VisibleQty)) DO
	{
		[n_QuickLotIncerementField] :=  FLD_OrderQty; 
	}
		
	SetFieldValue1([n_QuickLotIncerementField], [sVal]);
	CALL OnSpin [n_QuickLotIncerementField], "", 0 ;
	SetCtrlFocus([n_QuickLotIncerementField]);
}


PROCEDURE SyncDebtAndNormalOEMoreExpansion
		 DECLARE PARAMETER sVal AS TEXT DO
{
	SLogLine("SyncDebtAndNormalOEMoreExpansion");
	DECLARE VARIABLE nExpanded	AS QUANTITY
	[nExpanded] := StringToInt([sVal]);
	
	IF ( [nExpanded] = 0 ) THEN
	{
		[n_FormExpanded] := 0;
		ChangeControlName(n_BtnMore, ">>");
	}
	ELSE
	{
		[n_FormExpanded] := 1;
		ChangeControlName(n_BtnMore, "<<");
	}
}
#CR09 - 162588
#################################################################################
PROCEDURE InitOfflineAmend
	DECLARE PARAMETER sMsgID AS TEXT 
	DECLARE PARAMETER sIsNamed AS TEXT
	DECLARE PARAMETER sHiddenOrder AS TEXT
	DECLARE PARAMETER sCapacity AS TEXT	DO	
{
	SLogLine("Start of Offline InitAmend");
	
	[i_MsgID] := StringToInt([sMsgID]);
	[g_nEntityMode] := MODE_Amend_OFFLINE;
	
	SetCheck(CHK_Offline_Order,0);
	SetLock (CHK_Offline_Order,LOCK_CONTROL,0);
	
	DECLARE VARIABLE sInstrument AS TEXT 	100
	[sInstrument] := GetStringFieldValueFromUnpackMsg(FLD_InstrumentID, 0);
	SLogLine("FLD_InstrumentID");
	SLogLine([sInstrument]);
	
	
	[s_CurrentInstrument] := [sInstrument];
	CALL InitWithDefaults [sInstrument];	
	
	SetFieldValue1(FLD_OrderType, GetStringFieldValueFromUnpackMsg(FLD_OrderType, GetIntFieldValueFromUnpackMsg(FLD_OrderType)));	
	SetFieldValue1(FLD_Side, GetStringFieldValueFromUnpackMsg(FLD_Side, GetIntFieldValueFromUnpackMsg(FLD_Side)));
	
	#<< 129836
	IF ( ([n_TradeMethod] = TRADE_METHOD_ON_PRICE) OR ([n_TradeMethod] = -1)  ) THEN
	{
		SetFieldValue1(FLD_Value, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_Value), 4));	
	} ELSE
	{
		SetFieldValue1(FLD_Debt_Yield, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_Value), 4));	
	}

	SetFieldValue1(FLD_OrderQty,FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_OrderQty), 0));
	SetFieldValueInCarrierMsg(FLD_OrderID,GetStringFieldValueFromUnpackMsg(FLD_OrderID,0));
	SetFieldValueInCarrierMsg(FLD_ClientOrderID,GetStringFieldValueFromUnpackMsg(FLD_ClientOrderID,0));
	
	SetFieldValue1(FLD_VisibleQty, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_VisibleQty), 0));

	IF ( [sCapacity] != "99" ) DO
	{		
		SetFieldValue1(FLD_Capacity, GetStringFieldValueFromUnpackMsg(FLD_Capacity, GetIntFieldValueFromUnpackMsg(FLD_Capacity)));
	}
	SetFieldValue1(FLD_AccountType, GetStringFieldValueFromUnpackMsg(FLD_AccountType, GetIntFieldValueFromUnpackMsg(FLD_AccountType)));
	SetFieldValue1(FLD_StopPrice, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_StopPrice), 2));	
	   	
	SetFieldValue1(FLD_OwnerID, GetStringFieldValueFromUnpackMsg(FLD_OwnerID, 0));
	SetFieldValue1(FLD_TIF,GetStringFieldValueFromUnpackMsg(FLD_TIF, GetIntFieldValueFromUnpackMsg(FLD_TIF)));
	
	#expiry date / time
	SetFieldValue1(FLD_ExpiryDate, GetStringFieldValueFromUnpackMsg(FLD_ExpiryDate, 0));
	SetFieldValue1(FLD_ExpiryTime, GetStringFieldValueFromUnpackMsg(FLD_ExpiryTime, 0));
	
	SetFieldValue1(FLD_MinimumSize, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_MinimumSize), 0));	
	SetFieldValue1(FLD_ClientID, GetStringFieldValueFromUnpackMsg(FLD_ClientID, 0));
	
	SetFieldValue1(FLD_ClearingMnemonic, GetStringFieldValueFromUnpackMsg(FLD_ClearingMnemonic, 0));
	
	SetFieldValue1(FLD_EXPTraderID,GetStringFieldValueFromUnpackMsg(FLD_EXPTraderID,FLD_EXPTraderID));
	SetFieldValue1(FLD_Contra,GetStringFieldValueFromUnpackMsg(FLD_Contra,FLD_Contra));
	SetFieldValue1(FLD_Remarks,GetStringFieldValueFromUnpackMsg(FLD_Remarks,FLD_Remarks));
	
	#do required changes related to some fields
	CALL OnChangeCombo "", "", GetStringFieldValueFromUnpackMsg(FLD_Side, GetIntFieldValueFromUnpackMsg(FLD_Side)), 0, FLD_Side;
	CALL OnChangeCombo "", "", GetStringFieldValueFromUnpackMsg(FLD_TIF, GetIntFieldValueFromUnpackMsg(FLD_TIF)), 0, FLD_TIF;
	#CALL OnChangeCombo "", "", [sCapacity], 0, FLD_OrderType; - Commented this line and replaced with the below for issue 173791
	CALL OnChangeCombo "", "", GetStringFieldValueFromUnpackMsg(FLD_OrderType, GetIntFieldValueFromUnpackMsg(FLD_OrderType)), 0, FLD_OrderType;
	CALL OnChangeCombo "", "", GetStringFieldValueFromUnpackMsg(FLD_Capacity, GetIntFieldValueFromUnpackMsg(FLD_Capacity)), 0, FLD_Capacity;
	
	#Set Debt Fields 
	#SetFieldValue1(FLD_Debt_Yield, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_Debt_Yield), 4));	
	SetFieldValue1(FLD_Debt_Effective_Yield, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_Debt_Effective_Yield), 4));	
	SetFieldValue1(FLD_Debt_Commissions, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_Debt_Commissions), 4));	
	
	IF ( [sIsNamed] = "1" ) THEN
	{
		SetCheck(FLD_Named,1);
	}
	ELSE
	{
		SetCheck(FLD_Named,0);
	}

	IF ( [sHiddenOrder] = "1" ) THEN
	{
		SetCheck(FLD_AllwZeroVS,1);
	}
	ELSE
	{
		SetCheck(FLD_AllwZeroVS,0);
	}
	
	#<< 129836
	IF ( ([n_TradeMethod] = TRADE_METHOD_ON_PRICE) OR ([n_TradeMethod] = -1)  ) THEN
	{
		NotifyControl(FLD_Value,FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_Value), 4));
	} ELSE
	{
		#CALL OnSpin FLD_Debt_Yield, "", -999 ;
		CALL DoPostSpinCalculations  FLD_Debt_Yield;
	}
	# 129836 >>
	
	CALL CalculateValue ;
	CALL DoCommissionCalcualation ; 
	#lock non amendable fields
	CALL SetQuickLotUpdateField FLD_OrderQty ;
	
		
	#CALL LockForSpecialCases; 185488

	
	SetCheck(CHK_Offline_Order,1);
	SetLock (CHK_Offline_Order,LOCK_CONTROL,0);
}

#################################################################################
PROCEDURE InitAmend
	DECLARE PARAMETER sMsgID AS TEXT
	DECLARE PARAMETER sCapacity AS TEXT	
	DECLARE PARAMETER sIsNamed AS TEXT
	DECLARE PARAMETER sAccType AS TEXT	DO
{
	SLogLine("Start of InitAmend");
	[i_MsgID] := StringToInt([sMsgID]);
	[g_nEntityMode] := MODE_Amend;
	
	DECLARE VARIABLE sInstrument AS TEXT 	100
	[sInstrument] := GetStringFieldValueFromUnpackMsg(FLD_InstrumentID, 0);
	SLogLine("FLD_InstrumentID");
	SLogLine([sInstrument]);
	
	
	[s_CurrentInstrument] := [sInstrument];
	CALL InitWithDefaults [sInstrument];	
	
	#CALL LockCtrlByID FLD_Clear, 1, 0;
	#ChangeControlTextColor(FLD_Clear,144,144,144);



	#for non amendable fields, value is set and locked
	SetFieldValue1(FLD_OrderType, GetStringFieldValueFromUnpackMsg(FLD_OrderType, GetIntFieldValueFromUnpackMsg(FLD_OrderType)));	
	SetFieldValue1(FLD_Side, GetStringFieldValueFromUnpackMsg(FLD_Side, GetIntFieldValueFromUnpackMsg(FLD_Side)));
	
	#<< 129836
	IF ( ([n_TradeMethod] = TRADE_METHOD_ON_PRICE) OR ([n_TradeMethod] = -1)  ) THEN
	{
		SetFieldValue1(FLD_Value, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_Value), 4));	
	} ELSE
	{
		SetFieldValue1(FLD_Debt_Yield, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_Value), 4));	
	}
	# 129836 >>
	# Load quantity from unpack message.
	# What should be filled as the quantity is the remaining size. Either
	# order is filled or partially-filled the 'OrderQty' contains the original order quantity,
	# where the 'TotalSize' contains the remaining size. When submitting, the change that
	# user has done anyway has to be added to the 'OrderQty'.
	# 124565 --------------------------------------------------------
	#MessageBox(FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_TotalQty),0),"FLD_TotalQty",1,1);
	SetFieldValue1(FLD_OrderQty,FloatToString([f_TotalSize],0));
				
	# Get the OrderID from from UnpackMessage and set it in the new
	SetFieldValueInCarrierMsg(FLD_OrderID,GetStringFieldValueFromUnpackMsg(FLD_OrderID,0));

	SetFieldValue1(FLD_VisibleQty, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_VisibleQty), 0));
		
	SetFieldValue1(FLD_Capacity, [sCapacity]);
	SetFieldValue1(FLD_AccountType, [sAccType]);
	SetFieldValue1(FLD_StopPrice, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_StopPrice), 2));	
	   	
	SetFieldValue1(FLD_OwnerID, GetStringFieldValueFromUnpackMsg(FLD_OwnerID, 0));
	SetFieldValue1(FLD_TIF,GetStringFieldValueFromUnpackMsg(FLD_TIF, GetIntFieldValueFromUnpackMsg(FLD_TIF)));
	
	#expiry date / time
	SetFieldValue1(FLD_ExpiryDate, GetStringFieldValueFromUnpackMsg(FLD_ExpiryDate, 0));
	SetFieldValue1(FLD_ExpiryTime, GetStringFieldValueFromUnpackMsg(FLD_ExpiryTime, 0));
	
	SetFieldValue1(FLD_MinimumSize, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_MinimumSize), 0));	
	SetFieldValue1(FLD_ClientID, GetStringFieldValueFromUnpackMsg(FLD_ClientID, 0));
	
	SetFieldValue1(FLD_ClearingMnemonic, GetStringFieldValueFromUnpackMsg(FLD_ClearingMnemonic, 0));
	
	SetFieldValue1(FLD_EXPTraderID,GetStringFieldValueFromUnpackMsg(FLD_EXPTraderID,FLD_EXPTraderID));
	SetFieldValue1(FLD_Contra,GetStringFieldValueFromUnpackMsg(FLD_Contra,FLD_Contra));
	SetFieldValue1(FLD_Remarks,GetStringFieldValueFromUnpackMsg(FLD_Remarks,FLD_Remarks));
	
	#do required changes related to some fields
	CALL OnChangeCombo "", "", GetStringFieldValueFromUnpackMsg(FLD_Side, GetIntFieldValueFromUnpackMsg(FLD_Side)), 0, FLD_Side;
	CALL OnChangeCombo "", "", GetStringFieldValueFromUnpackMsg(FLD_TIF, GetIntFieldValueFromUnpackMsg(FLD_TIF)), 0, FLD_TIF;
	#CALL OnChangeCombo "", "", [sCapacity], 0, FLD_OrderType; - Commented this line and replaced with the below for issue 173791
	CALL OnChangeCombo "", "", GetStringFieldValueFromUnpackMsg(FLD_OrderType, GetIntFieldValueFromUnpackMsg(FLD_OrderType)), 0, FLD_OrderType;
	CALL OnChangeCombo "", "", GetStringFieldValueFromUnpackMsg(FLD_Capacity, GetIntFieldValueFromUnpackMsg(FLD_Capacity)), 0, FLD_Capacity;
	
	#Set Debt Fields 
	#SetFieldValue1(FLD_Debt_Yield, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_Debt_Yield), 4));	
	SetFieldValue1(FLD_Debt_Effective_Yield, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_Debt_Effective_Yield), 4));	
	SetFieldValue1(FLD_Debt_Commissions, FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_Debt_Commissions), 4));	
	
	IF ( [sIsNamed] = "1" ) THEN
	{
		SetCheck(FLD_Named,1);
	}
	ELSE
	{
		SetCheck(FLD_Named,0);
	}
	#CALL OnSpin FLD_Value, "", 0 ;
	
	#<< 129836
	IF ( ([n_TradeMethod] = TRADE_METHOD_ON_PRICE) OR ([n_TradeMethod] = -1)  ) THEN
	{
		NotifyControl(FLD_Value,FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_Value), 4));
	} ELSE
	{
		#CALL OnSpin FLD_Debt_Yield, "", -999 ;
		CALL DoPostSpinCalculations  FLD_Debt_Yield;
	}
	# 129836 >>
	
	CALL CalculateValue ;
	CALL DoCommissionCalcualation ; 
	#lock non amendable fields
	CALL SetQuickLotUpdateField FLD_OrderQty ;
	
	
	ChangeControlName(FLD_Submit, "AMEND");
		
	CALL LockForAmend "1" ;
	CALL LockForSpecialCases;
	
	#<<166039
	DECLARE VARIABLE fVisibleSize AS PRICE
	[fVisibleSize] := GetFloatFieldValueFromUnpackMsg(FLD_VisibleQty) ;
		
	IF ( [fVisibleSize] = [f_TotalSize] ) THEN
	{
		[n_IsFullyVisible] := 1 ; 
	}
	ELSE
	{
		[n_IsFullyVisible] := 0 ; 
	}
	#166039 >> 
#<< 171022
	CALL OnChangeCombo "", "", GetStringFieldValueFromUnpackMsg(FLD_TIF, GetIntFieldValueFromUnpackMsg(FLD_TIF)), 0, FLD_TIF;	
}

###############################################################################
PROCEDURE LockForAmend
		DECLARE PARAMETER sText AS TEXT DO
{
	
	SLogLine("LockForAmend");
	#CALL ReleaseOnResponse;
	
	CALL LockAllFileds 1; 
	SetLock (FLD_Value, 	UNLOCK_CONTROL , 0);
	SetLock (FLD_OrderQty, 	UNLOCK_CONTROL, 0);
	#SetLock (FLD_TIF, 	UNLOCK_CONTROL, 0);				Commented as per 139178
	SetLock (FLD_EXPTraderID, 	UNLOCK_CONTROL, 0);
	SetLock (FLD_Contra, 	UNLOCK_CONTROL, 0);
	#SetLock (FLD_Remarks, 	UNLOCK_CONTROL, 0);
	SetLock (FLD_Submit,	UNLOCK_CONTROL, 0);
	SetLock (FLD_VisibleQty ,UNLOCK_CONTROL,0);
	#SetLock (FLD_Days_To_Expire ,UNLOCK_CONTROL,0);
		# <<<< 120942
	DECLARE VARIABLE sOrderType		AS TEXT 	50
	[sOrderType] := GetFieldValue1(FLD_OrderType);
	
	IF ( ([sOrderType] = "STOP_LIMIT") OR ([sOrderType] = "STOP") ) DO
	{
		IF ( ([sOrderType] = "STOP")) DO
		{
			SetLock (FLD_Value, LOCK_CONTROL, 0);
			ChangeControlTextColor(FLD_Value, 200,200,200);
			SetLock (FLD_Debt_Yield, LOCK_CONTROL, 0);
			ChangeControlTextColor(FLD_Debt_Yield, 200,200,200);
			
			SetLock (CHK_Debt_Yield, LOCK_CONTROL, 0);
			SetLock (CHK_Debt_Price, LOCK_CONTROL, 0);
			
			ChangeControlTextColor(FLD_StopPrice, 0,0,0);
		}
		
		SetLock (FLD_StopPrice, UNLOCK_CONTROL ,0);
	}	
	# 120942 >>>>
	
	IF ( ([n_TradeMethod] != TRADE_METHOD_ON_PRICE) AND ([n_TradeMethod] != -1)  ) DO
	{
		ChangeControlTextColor(FLD_Value, 255,255,255); 
		SetLock (FLD_Value, LOCK_CONTROL ,0);
	}
}

PROCEDURE CreateContraOrder
	DECLARE PARAMETER sCtrlID AS TEXT
	DECLARE PARAMETER sPrice AS TEXT
	DECLARE PARAMETER sSize AS TEXT
	DECLARE PARAMETER sSide AS TEXT	
	DECLARE PARAMETER sAutoCreate AS TEXT DO
{	
	SLogLine("CreateContraOrder");
	DECLARE VARIABLE nCtrlID	AS QUANTITY
	DECLARE VARIABLE nAutoCreate	AS QUANTITY
	
	[nCtrlID] := StringToInt([sCtrlID]);
	[nAutoCreate]   := StringToInt([sAutoCreate]);
	
	IF ( [nAutoCreate] = 0 ) DO
	{
		SetFieldValue1([nCtrlID] , [sPrice]);
	}
	
	SetFieldValue1(FLD_Side, [sSide]);
	SetFieldValue1(FLD_OrderQty, [sSize]);
	
	CALL OnChangeCombo "", "", [sSide], 0, FLD_Side;
	CALL CalculateValue ;
}

##########################################################
PROCEDURE SetBkgColor
		 DECLARE PARAMETER sRVal AS TEXT
		 DECLARE PARAMETER sGVal AS TEXT 
		 DECLARE PARAMETER sBVal AS TEXT DO
{
	SLogLine("SetBkgColor");
	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);
}



##########################################################
PROCEDURE SetModeAsAmend
	DECLARE PARAMETER sText AS TEXT DO
{
	SLogLine("SetModeAsAmend");
	[g_nEntityMode] := MODE_Amend;
	[s_CurrentBookDefID] := [sText];
}

###############################################################################
PROCEDURE OnRemoveAllInstruments  DO
{       	
	SLogLine("OnRemoveAllInstruments");
	ResetMsgPool();
	[s_CurrentInstrument] := "";
	[s_Trader] := "" ;              
	
	SetFieldValue1(FLD_Side,"");
	SetFieldValue1(FLD_Value, "0.0");
	SetFieldValue1(FLD_OrderQty, "0");
	# MSE SetFieldValue1(FLD_Days_To_Expire, "1");
	SetFieldValue1(FLD_TIF,"");
	SetFieldValue1(FLD_OrderType,"");
	SetFieldValue1(FLD_AccountType,"");
	SetFieldValue1(FLD_StopPrice, "0.0");
	SetFieldValue1(FLD_Capacity,"");
	SetFieldValue1(FLD_OwnerID,"");
	SetFieldValue1(FLD_ClientID, "");
	SetFieldValue1(FLD_VisibleQty, "0.0");  
	SetFieldValue1(FLD_MinimumSize, "");
	SetFieldValue1(FLD_EXPTraderID, "");
	SetFieldValue1(FLD_Contra, "");
	SetFieldValue1(FLD_Remarks, "");
#//166566
	SetFieldValue1(FLD_DateTime, "");
	SetFieldValue1(FLD_CalculatedVal, "0.00");
	#Set Debt Fields 
	SetFieldValue1(FLD_Debt_Commissions, "0.0");  
	SetFieldValue1(FLD_Debt_Yield, "0.0");  
	SetFieldValue1(FLD_Debt_Effective_Yield, "0.0");  
	
	CALL OnChangeCombo "", "", "", 0, FLD_Side;

	SetLock(FLD_Side ,1,0);
	SetLock(FLD_Value ,1,0);
	SetLock(FLD_OrderQty ,1,0);
	# MSE SetLock(FLD_Days_To_Expire ,1,0);
	SetLock(FLD_TIF ,1,0);
	SetLock(FLD_OrderType ,1,0);
	SetLock(FLD_AccountType ,1,0);
	SetLock(FLD_StopPrice ,1,0);
	SetLock(FLD_Capacity ,1,0);
	SetLock(FLD_OwnerID ,1,0);
	SetLock(FLD_ClientID ,1,0);
	SetLock(FLD_VisibleQty ,1,0);
	SetLock(FLD_MinimumSize ,1,0);
	SetLock(FLD_EXPTraderID ,1,0);
	SetLock(FLD_Contra ,1,0);
	SetLock(FLD_Remarks ,1,0);

	
	SetLock(FLD_Submit ,1,0);
	ChangeControlTextColor(FLD_Submit, 200,200,200);
	
	IF ( ([s_ActiveSide] = "SELL") OR ([s_ActiveSide] = "SELL SHORT") ) THEN
	{
		SetFieldValue1(FLD_Submit,"SELL");
		CALL SetSellColour;
	}
	ELSE IF ( [s_ActiveSide] = "BUY" ) DO
	{
		SetFieldValue1(FLD_Submit,"BUY");
		CALL SetBuyColour;
	}
}

##########################################################
PROCEDURE ChangeInsMode
	DECLARE PARAMETER sText AS TEXT DO
{
	SLogLine("ChangeInsMode");
	CALL OnChangeCombo "", "", GetFieldValue1(FLD_Side), 0, FLD_Side;
}

###############################################################################
PROCEDURE ShowErrorMessage  
		DECLARE PARAMETER sErrorMessage	AS TEXT
		DECLARE PARAMETER sHeader	AS TEXT DO
{
	SLogLine("ShowErrorMessage");
	MessageBox([sErrorMessage],[sHeader],1,1);
}

PROCEDURE SetForSync DO
{
	CALL OnCheck CHK_Debt_Yield, "", 0 ; 
}


###############################################################################
PROCEDURE SetBuyColour  DO
{
	SLogLine("Debt - SetBuyColour");
	DECLARE VARIABLE sWndID		AS TEXT 20	
	DECLARE VARIABLE sCtrlID	AS TEXT 20

	[sWndID] := IntToString(GetWndID());		
	
	DECLARE VARIABLE	sRed	 		AS TEXT		30
	DECLARE VARIABLE	sGreen 			AS TEXT		30
	DECLARE VARIABLE	sBlue 			AS TEXT		30
										
	[sRed]   := "206";
	[sGreen] := "203";
	[sBlue]  := "255";
	
	SetBackColor( StringToInt([sRed]), StringToInt([sGreen]), StringToInt([sBlue]), 1 );
	
	[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_AdvancedOptions") );
	ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);

	[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_RecentTransactions") );
	ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);

	[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_QuoteEntry") );
	ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);		
	
	[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_Header") );
	ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);

	[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_ExtendedHeader") );
	ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);
	
	[sCtrlID] := IntToString( GetCtrlIDByName("EQT_Reg_Entry") );
	ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);
}

###############################################################################
PROCEDURE SetSellColour  DO
{
	SLogLine("Debt - SetSellColour");
	DECLARE VARIABLE sWndID		AS TEXT 20	
	DECLARE VARIABLE sCtrlID	AS TEXT 20
				
	[sWndID] := IntToString(GetWndID());		
	
	DECLARE VARIABLE	sRed	 		AS TEXT		30
	DECLARE VARIABLE	sGreen 			AS TEXT		30
	DECLARE VARIABLE	sBlue 			AS TEXT		30
		
	[sRed]   := "255";
	[sGreen] := "154";
	[sBlue]  := "156";
	
	SetBackColor( StringToInt([sRed]), StringToInt([sGreen]), StringToInt([sBlue]), 1 );
	
	[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_AdvancedOptions") );
	ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);
	
	[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_RecentTransactions") );
	ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);

	[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_QuoteEntry") );
	ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);		
	
	[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_Header") );
	ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);

	[sCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_ExtendedHeader") );
	ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);
	
	[sCtrlID] := IntToString( GetCtrlIDByName("EQT_Reg_Entry") );
	ExecExtSrciptProc("SetBkgColor", [sWndID], [sCtrlID], [sRed], [sGreen], [sBlue]);	
}


PROCEDURE UpdateAccordingToOrderType DO
{
	SLogLine("UpdateAccordingToOrderType");
	DECLARE VARIABLE	sOrderTypeText	 AS TEXT		30
	[sOrderTypeText] := GetFieldValue1(FLD_OrderType);
	
	IF ( [sOrderTypeText] = "STOP") THEN
	{
		SetFieldValue1(FLD_Value,"0.0");
		SetLock (FLD_Value, 			1, 0);
		SetLock (FLD_StopPrice, 		0, 0);
		
		ChangeControlTextColor(FLD_Value, 200,200,200);
		ChangeControlTextColor(FLD_StopPrice, 0,0,0);
		
	}
	ELSE IF ( [sOrderTypeText] = "STOP_LIMIT") THEN
	{
		SetFieldValue1(FLD_Value,"0.0");
		SetLock (FLD_Value, 			0, 0);
		SetLock (FLD_StopPrice, 		0, 0);
		
		ChangeControlTextColor(FLD_Value, 0,0,0);
		ChangeControlTextColor(FLD_StopPrice, 0,0,0);
	}
	ELSE IF ( [sOrderTypeText] = "MARKET") DO
	{
		SetFieldValue1(FLD_Value,"0.0");
		SetLock (FLD_Value, 			1, 0);
		SetLock (FLD_StopPrice, 		1, 0);

		ChangeControlTextColor(FLD_Value, 200,200,200);
		ChangeControlTextColor(FLD_StopPrice, 200,200,200);
	}
	
	IF ( ([n_TradeMethod] != TRADE_METHOD_ON_PRICE) AND ([n_TradeMethod] != -1)  ) DO
	{
		ChangeControlTextColor(FLD_Value, 255,255,255); 
		SetLock (FLD_Value, LOCK_CONTROL ,0);
	}
	
	
}

PROCEDURE OnFocusChange
        DECLARE PARAMETER nControlID as QUANTITY
        DECLARE PARAMETER sName as TEXT
        DECLARE PARAMETER nFocus as QUANTITY DO
{
	IF ([nFocus] = 1) DO
	{
		IF (([nControlID] = FLD_MinimumSize) OR ([nControlID] = FLD_OrderQty) OR ([nControlID] = FLD_VisibleQty)) DO
		{
			CALL SetQuickLotUpdateField [nControlID] ; 
		}
	}
}

PROCEDURE SetQuickLotUpdateField
	DECLARE PARAMETER nControlID as QUANTITY DO
{
	DECLARE VARIABLE nCtrlState    AS QUANTITY   
	[nCtrlState] := GetControlState([nControlID]);

	IF ( [nCtrlState] = 1 ) DO
	{
		[n_QuickLotIncerementField] := [nControlID];
	}		

}

#129836
###############################################################################
PROCEDURE UpdateAfterRoundUp
        DECLARE PARAMETER sPrice	AS TEXT
        DECLARE PARAMETER sYield	AS TEXT DO
{
	SLogLine("UpdateAfterRoundUp");
	SetFieldValue1(FLD_Value,[sPrice]);
	SetFieldValue1(FLD_Debt_Yield,[sYield]);
	
	CALL DoPostSpinCalculations  FLD_Debt_Yield;
}
#<<168597
PROCEDURE SetGlobalReset 
	DECLARE PARAMETER nState as TEXT DO
{
	
	SLogLine("SetGlobalReset2");
	[s_ResetFieldSide] := [nState]; 			
}


