# 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_OrderType 		AS QUANTITY 2189
DECLARE CONSTANT FLD_StopPrice 		AS QUANTITY 2425
DECLARE CONSTANT FLD_Side	 		AS QUANTITY 2053
DECLARE CONSTANT FLD_TIF 			AS QUANTITY 2331
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_Capacity		AS QUANTITY	2233
DECLARE CONSTANT FLD_OrderSubType 	AS QUANTITY 2642
DECLARE CONSTANT FLD_ClearingMnemonic		AS QUANTITY	3129
DECLARE CONSTANT FLD_RFQID			AS QUANTITY 2638

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

DECLARE CONSTANT FLD_AskValue 		AS QUANTITY 10050
DECLARE CONSTANT FLD_AskOrderQty 	AS QUANTITY 10051


DECLARE CONSTANT FLD_BidValue 		AS QUANTITY 10048
DECLARE CONSTANT FLD_BidOrderQty	AS QUANTITY 10049

DECLARE CONSTANT FLD_Submit	 		AS QUANTITY 80000

# 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_AllwZeroVS		AS QUANTITY	131

DECLARE CONSTANT FLD_QuickLot_0		AS QUANTITY	40020
DECLARE CONSTANT FLD_QuickLot_1		AS QUANTITY	40021
DECLARE CONSTANT FLD_QuickLot_2		AS QUANTITY	40022
DECLARE CONSTANT FLD_QuickLot_3		AS QUANTITY	40023
DECLARE CONSTANT FLD_QuickLot_4		AS QUANTITY	40024
DECLARE CONSTANT FLD_QuickLot_5		AS QUANTITY	40025

# Order etry mode
DECLARE CONSTANT MODE_New			AS QUANTITY 0
DECLARE CONSTANT MODE_Amend			AS QUANTITY 1

# 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

# Tif values
DECLARE CONSTANT TIF_Def_DAY	AS QUANTITY 0
DECLARE CONSTANT TIF_Def_GTC	AS QUANTITY 1
DECLARE CONSTANT TIF_Def_IOC	AS QUANTITY 3
DECLARE CONSTANT TIF_Def_FOK	AS QUANTITY 4
DECLARE CONSTANT TIF_Def_OPEN	AS QUANTITY 5
DECLARE CONSTANT TIF_Def_GTD	AS QUANTITY 6
DECLARE CONSTANT TIF_Def_OPG	AS QUANTITY 7
DECLARE CONSTANT TIF_Def_GTT	AS QUANTITY 8
DECLARE CONSTANT TIF_Def_GTS	AS QUANTITY 9
DECLARE CONSTANT TIF_Def_CLOSE	AS QUANTITY 10

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

# The mode  New/Amend
DECLARE VARIABLE g_nEntityMode AS QUANTITY
DECLARE VARIABLE g_nOrderQuote AS QUANTITY

#Field to Hold Clearing Menomnic, upon deletion of Clearing Menemonic Field for ExPlus CR12, 3.1.2.1
DECLARE VARIABLE s_ClearingMnemonic	AS TEXT 100

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
# REMARKS:
# =================================================================================
# Initially the combo boxes and the default values of the fields are loaded from 
# the back-end as defined in the ExMan. Additional parameters are loaded as 
# 'initial values' which are necessary for subsequent actions. 
#			
#	"TICK_FORMAT"		In what scale spinner of price fields should increment in 
#						certain value ranges.
#	"LOT_SIZE"			Unit size of order quantity.
#	"MINIMUM_LOT_SIZE"	Minimum size of order quantity.
#	"MAXIMUM_LOT_SIZE"	Maximum size of order quantity.
#	"CONFIRM_SUBMIT"	Whether to confirm before sending the order to backend.
#
# Then one of 'InitMsgForNewOrder' or 'InitMsgForAmendOrder' procedures will be 
# called from the back-end on the need. upon calling those methods user defined 
# defaults values and any addtional combo entries are added.
#
# ToggleOrder and ToggleQuote methods are called when the backend selects the 
# relavant mode on preferences and when user clickes the combo. This do nothing
# that updating labels, since two scripts(because of 2 forms) exists (this being 
# a one)and those two handle order entry mode specific functionality seperately.
# 
# Upon clicking the button which is needed as submit button or upon entering on 
# form (OnReturnPage) the field values are validated. Upon successfull validation, 
# confirm if necessary and send the messaege to back-end. Hence all the field are 
# locked (LockAllFields) to void user from sending any more orders until user get 
# a reponse.Back-End, after recieving the order will set BookDefID, ClientOrderID, 
# TraderID, UserID and BroderID and call ReleaseOnResponse which will unlock the 
# previously locked fields. Back-End will call ClearOnSuccesss to clear any already 
# entered fileds, if it's necessary on successful submission of order.


# Lock certain fileds depending on the selection in order type combo.
# =================================================================================
PROCEDURE SetLocksOnOrderType  
		DECLARE PARAMETER sOrderTypeText	AS TEXT DO
{
	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
	{
		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
	{
		SetLock (FLD_Value, 			1, 0);
		SetLock (FLD_StopPrice, 		1, 0);
		
		ChangeControlTextColor(FLD_Value, 200,200,200);
		ChangeControlTextColor(FLD_StopPrice, 200,200,200);
	}
	ELSE
	{
		SetLock (FLD_Value, 			0, 0);
		SetLock (FLD_StopPrice, 		0, 0);
		
		ChangeControlTextColor(FLD_Value, 0,0,0);
		ChangeControlTextColor(FLD_StopPrice, 0,0,0);
	}
}

# Lock time and date fields depending on the TIF as the TIF combo changes
# =================================================================================
PROCEDURE SetLocksOnTIF 
		DECLARE PARAMETER sTIFText	AS TEXT DO
{
	IF ( [sTIFText] = "GTD" ) THEN
	{
		SetLock(FLD_DateTime, 0, 0);
		SetFormat1(FLD_DateTime, "yyyy/MM/dd");
		
		ChangeControlTextColor(FLD_DateTime, 0,0,0);
	}
	ELSE IF ( [sTIFText] = "GTT" ) THEN 
	{
		SetLock(FLD_DateTime, 0, 0);
		SetFormat1(FLD_DateTime, "HH:mm:ss");
		
		ChangeControlTextColor(FLD_DateTime, 0,0,0);
	}
	ELSE
	{
		SetLock(FLD_DateTime, 1, 0);
		ChangeControlTextColor(FLD_DateTime, 200,200,200);
	}
}
		

PROCEDURE LockAllFileds 
		DECLARE PARAMETER nMode	AS QUANTITY DO
{
	SetLock (FLD_Value, 	[nMode], 0);
	SetLock (FLD_OrderType, [nMode], 0);
	SetLock (FLD_StopPrice, 	[nMode], 0);
	SetLock (FLD_Side,		[nMode], 0);
	SetLock (FLD_OrderQty, 	[nMode], 0);
	SetLock (FLD_Value,		[nMode], 0);
	SetLock (FLD_TIF,		[nMode], 0);
	SetLock (FLD_VisibleQty,	[nMode], 0);
	SetLock (FLD_Submit,	[nMode], 0);

	SetLock (FLD_AskValue,	[nMode], 0);
	SetLock (FLD_AskOrderQty,	[nMode], 0);
	SetLock (FLD_BidValue,	[nMode], 0);
	SetLock (FLD_BidOrderQty,	[nMode], 0);
	
	IF ( [nMode] = 1) THEN
		ChangeControlTextColor(FLD_Submit,0,0,0);
	ELSE
		ChangeControlTextColor(FLD_Submit,0,0,150);
}

# =================================================================================
PROCEDURE OnChangeCombo
        DECLARE PARAMETER sGroupName	AS TEXT
        DECLARE PARAMETER sFieldName	AS TEXT
        DECLARE PARAMETER sVal			AS TEXT
        DECLARE PARAMETER nCurSel		AS QUANTITY
        DECLARE PARAMETER nControlID	AS QUANTITY DO
{
	IF ([nControlID] = FLD_OrderType) THEN
	{	
		CALL SetLocksOnOrderType [sVal];
	}
	ELSE IF ([nControlID] = FLD_TIF) THEN
	{
		CALL SetLocksOnTIF [sVal];
	}
	ELSE IF ([nControlID] = FLD_Side) DO
	{
		#ChangeControlName(FLD_Submit, [sVal]);
	}
}

# Add enum filed which is not supposed to be edited.
# =================================================================================
PROCEDURE AddDispayEnum 
		 DECLARE PARAMETER nFieldID AS QUANTITY DO
{
	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
{	
	[g_nEntityMode] := MODE_New;
	
	SetFieldValue1(FLD_AskValue, "0.0");
	SetFieldValue1(FLD_BidValue, "0.0");

	CALL SetIncrements;
	
	RemoveListEntry2(FLD_TIF,"");
	
	# The whole enumeration  is only used for the order-entry. For quote entry all are not there
	AddListEntry1(FLD_TIF,"DAY","");
	AddListEntry1(FLD_TIF,"OPEN","");
	AddListEntry1(FLD_TIF,"GTT","");
	SetFieldValue1(FLD_TIF, "DAY");
	
	
	SetFieldValue1(FLD_Submit, "SUBMIT");
	
	# Do inital lockings as defined in SetLocksOnOrderType
	#RAVI SetFieldValue1(FLD_AskValue, "0.0");
	#RAVI SetFieldValue1(FLD_BidValue, "0.0");


	
	# 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);
	#ChangeControlName(FLD_Submit, GetFieldValue1(FLD_Side));
}


# =================================================================================
PROCEDURE InitMsgForAmendOrder DO
{
	DECLARE VARIABLE fAskVisibleQty AS PRICE
	DECLARE VARIABLE fBidVisibleQty AS PRICE
	
	[g_nEntityMode] := MODE_Amend;
	
	CALL SetIncrements;
	
	SetFieldValue1(FLD_TIF,GetStringFieldValueFromUnpackMsg(FLD_TIF, GetIntFieldValueFromUnpackMsg(FLD_TIF)));
	
	#ExPlus CR12, 3.1.2.1
	#SetFieldValue1(FLD_ClearingMnemonic,GetStringFieldValueFromUnpackMsg(FLD_ClearingMnemonic, 0));
	[s_ClearingMnemonic] := GetStringFieldValueFromUnpackMsg(FLD_ClearingMnemonic, 0) ; 			
	
	# Do inital lockings as defined in SetLocksOnOrderType
	# CALL SetLocksOnOrderType GetFieldValue1(FLD_OrderType);
	
	# Load Price, Visible size and Stop price from unpack message
	#--orderfileds-- SetFieldValue1(FLD_Value,FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_Value),2));
	#--orderfileds-- SetFieldValue1(FLD_VisibleQty,FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_VisibleQty),0));
	#--orderfileds-- SetFieldValue1(FLD_StopPrice,FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_StopPrice),4));
	
	# Load Price, Visible size and Stop price from unpack message
	
	SetFieldValue1(FLD_AskValue,GetInitialValueString("ASK_PRICE"));
	SetFieldValue1(FLD_AskOrderQty,GetInitialValueString("ASK_TOTAL_SIZE"));
		
	SetFieldValue1(FLD_BidValue,GetInitialValueString("BID_PRICE"));
	SetFieldValue1(FLD_BidOrderQty,GetInitialValueString("BID_TOTAL_SIZE"));
	
	[fAskVisibleQty] := StringToFloat(GetInitialValueString("ASK_VISIBLE_SIZE"));
	[fBidVisibleQty] := StringToFloat(GetInitialValueString("BID_VISIBLE_SIZE"));
	
	# Load Quantity from UnpackMessage
	# What should be filled in the OrderEntry actually is the remaining size. Either
	# order is filled or P-filled the 'OrderQty' contains the original order quantity,
	# where the 'TotalSize' contains the remaining size. Then when submitting the change that
	# user has done anyway has to be added to the 'OrderQty'.
	#SetFieldValue1(FLD_OrderQty,FloatToString(GetFloatFieldValueFromUnpackMsg(FLD_TotalQty),0));
	
	# Get the OrderID from from UnpackMessage and set it in the new
	SetFieldValueInCarrierMsg(FLD_OrderID,GetStringFieldValueFromUnpackMsg(FLD_OrderID,0));
	
	# Users should not be allowed to change any field.
	# Lock the fields the users are not supposed to change.
	CALL LockFieldsForAmmend;
	
	# 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);
	ChangeControlName(FLD_Submit, "AMEND");
	
	ChangeControlTextColor(FLD_Submit,50,50,200);
	ChangeControlTextColor(FLD_Submit,0,0,150);
}


# =================================================================================
PROCEDURE SetIncrements DO
{
	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_BidValue, [sTickString], GetFieldValue1(FLD_BidValue), 0);
	SetValueOnTick(FLD_AskValue, [sTickString], GetFieldValue1(FLD_AskValue), 0);

	# Set the increment to LotSize
	[nLotSize] := GetInitialValueInt("LOT_SIZE");
	
	IF ([nLotSize] < 1) DO
	{
		[nLotSize] := 100;
	}
	
	SetBuddyIntInc(FLD_VisibleQty, [nLotSize]);
	SetBuddyIntInc(FLD_AskOrderQty, [nLotSize]);
	SetBuddyIntInc(FLD_BidOrderQty, [nLotSize]);

}

# Lock the fields that should not be allowed to ammend
# =================================================================================
PROCEDURE LockFieldsForAmmend DO
{
	SetLock(FLD_Side,1,0);
	SetLock(FLD_TIF,1,0);
	#SetLock(FLD_OwnerID,1,0);
}

PROCEDURE IsInLotSize RETURNS QUANTITY 
		DECLARE PARAMETER fPrice	AS PRICE
		DECLARE PARAMETER nLotSize	AS QUANTITY DO
{
	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 in 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 ValidatePackSizes RETURNS QUANTITY 
			DECLARE PARAMETER nfldSize	AS QUANTITY
			DECLARE PARAMETER nfldVisibleSize	AS QUANTITY  
			DECLARE PARAMETER nfldAllowZero   AS QUANTITY DO
{

	DECLARE VARIABLE fVisibleQuantity 		AS PRICE 
	DECLARE VARIABLE fQuantity 		AS PRICE
	DECLARE VARIABLE nMinimumLotSize	AS QUANTITY
	DECLARE VARIABLE nMaximumLotSize	AS QUANTITY
	DECLARE VARIABLE nQuantityInLots	AS QUANTITY
	DECLARE VARIABLE nQuantity	AS QUANTITY
	DECLARE VARIABLE nLotSize	AS QUANTITY
	DECLARE VARIABLE nAllowZeroVisibleSize	AS QUANTITY

	[fVisibleQuantity] := StringToFloat(GetFieldValue1([nfldVisibleSize]));
	[fQuantity] := StringToFloat(GetFieldValue1([nfldSize]));
	[nAllowZeroVisibleSize] := GetCheck([nfldAllowZero]);
	
	# The value of the stop value filed are set to 0 when necessary upon change in
	# OrderType combo.
	
	#IF ( [fQuantity] <= 0.0) DO
	#{
	#	MessageBox("Should have a valid quantity", "", MSG_BOX_TYPE_Ok,MSG_BOX_ICON_Exclaim);
	#	SetCtrlFocus([nfldSize]);
	#	RETURN 0;
	#}
	
	# Visible sizes is the size shown to the public in the orderbook,
	# to avoid the impact on maket of showing the exact size of 
	# orders having large order quantity.
	# This should ceratinly be less that or equaly to the real quantity.
	
	#IF ([fVisibleQuantity] > [fQuantity]) DO
	#{
	#	MessageBox("Visible Quantity should not be greater than Order Quantity.", "", MSG_BOX_TYPE_Ok,MSG_BOX_ICON_Exclaim);
	#	SetCtrlFocus([nfldVisibleSize]);
	#	SetFieldValueInCarrierMsg([nfldVisibleSize],"0.0");
	#	RETURN 0;
	#}
	
	# Validate for a minimum of Minimum lot size
	
	[nMinimumLotSize] := GetInitialValueInt("MINIMUM_LOT_SIZE");
	[nMaximumLotSize] := GetInitialValueInt("MAXIMUM_LOT_SIZE");
	
	[nQuantity] := StringToInt(FloatToString([fQuantity],0));
	
	#IF ( [nQuantity] < [nMinimumLotSize] ) DO
	#{
	#	MessageBox("Quantity is below Minimum Lot Size.", "", MSG_BOX_TYPE_Ok, MSG_BOX_ICON_Exclaim);
	#	SetCtrlFocus([nfldSize]);
	#	RETURN 0;
	#}
	
	#IF ( [nQuantity] > [nMaximumLotSize] ) DO
	#{
	#	MessageBox("Quantity is over Maximum Lot Size.", "", MSG_BOX_TYPE_Ok, MSG_BOX_ICON_Exclaim);
	#	SetCtrlFocus([nfldSize]);
	#	RETURN 0;
	#}
	
	# Check the lot size of the order. Lot size is send to Front-End in the
	# Business data message (APIFED functionality) as "LOT_SIZE" in an 
	# configtree ref. Back-End MFormCtrl.
	[nLotSize] := GetInitialValueInt("LOT_SIZE");
	[nQuantityInLots] := IsInLotSize([fQuantity], [nLotSize]);
	
	#IF ([nQuantityInLots] = 0) DO
	#{
	#	MessageBox("Quantity is not a multiple of Lot Size.", "", MSG_BOX_TYPE_Ok, MSG_BOX_ICON_Exclaim);
	#	SetCtrlFocus([nfldSize]);
	#	RETURN 0;
	##}
	
	#commented by ishara for issue 3129
	# Remove the main else part from the below code later and add filled value resetting code to the commented block.
	#IF ([fVisibleQuantity] <= 0.0) THEN
	#{
	#	IF ([nAllowZeroVisibleSize] = 1) THEN
	#	{
	#		SetFieldValueInCarrierMsg([nfldVisibleSize], "0.0");
	#	}
	#	ELSE
	#	{
	#		# Do nothing. When this field is set null then the Matching Engine will set it
	#		# with the same value as Size.
	#		ResetFieldInCarrierMsg([nfldVisibleSize]);
	#	}
	#}
	#ELSE  	
	#{
	#	SetFieldValueInCarrierMsg([nfldVisibleSize], GetFieldValue1([nfldVisibleSize]));
	#}
	
	IF ([nAllowZeroVisibleSize] = 1) THEN
	{
		SetFieldValueInCarrierMsg([nfldVisibleSize], "0.0");
	}
	ELSE
	{
		IF ([fVisibleQuantity] <= 0.0) THEN
		{
			ResetFieldInCarrierMsg([nfldVisibleSize]);
		}
		ELSE
		{
			SetFieldValueInCarrierMsg([nfldVisibleSize], GetFieldValue1([nfldVisibleSize]));
		}
	}	
	
	SetFieldValueInCarrierMsg([nfldSize], GetFieldValue1([nfldSize]));
	
	RETURN 1;
} 


# =================================================================================
PROCEDURE PackMessage RETURNS QUANTITY DO
{
	DECLARE VARIABLE fAskPrice 		AS PRICE
	DECLARE VARIABLE fBidPrice 		AS PRICE
	DECLARE VARIABLE nSizeValidationAsk	AS QUANTITY		# For quotes
	DECLARE VARIABLE nSizeValidationBid	AS QUANTITY		# For quotes
	DECLARE VARIABLE sInstrumentID	AS TEXT		50
	DECLARE VARIABLE sBookID		AS TEXT		50
	DECLARE VARIABLE sUserID		AS TEXT		50
		
	# Populate values necessary for validation
	[fAskPrice] := StringToFloat(GetFieldValue1(FLD_AskValue));
	[fBidPrice] := StringToFloat(GetFieldValue1(FLD_BidValue));


	IF (IsValidDisplayFormat(FLD_AskValue) = 0) DO
	{
		MessageBox("Price value entered does not match the display format.", "", MSG_BOX_TYPE_Ok, MSG_BOX_ICON_Exclaim);
		RETURN 0;
	}
	
	IF (IsValidDisplayFormat(FLD_BidValue) = 0) DO
	{
		MessageBox("Price value entered does not match the display format.", "", MSG_BOX_TYPE_Ok, MSG_BOX_ICON_Exclaim);
		RETURN 0;
	}


	# Validations for quotes
	#[nSizeValidationAsk] := ValidatePackSizes(FLD_AskOrderQty , FLD_AskVisibleQty, FLD_AllwZeroAskVS) Dilukat changed to below
	[nSizeValidationAsk] := ValidatePackSizes(FLD_AskOrderQty , 0, 0);
	IF ( [nSizeValidationAsk] = 0 ) DO
	{
		RETURN 0;
	}

	#[nSizeValidationBid] := ValidatePackSizes(FLD_BidOrderQty , FLD_BidVisibleQty, FLD_AllwZeroBidVS); changed to below as FLD_AllwZeroBidVS is not there anymore
	[nSizeValidationBid] := ValidatePackSizes(FLD_BidOrderQty , 0, 0);
	
	IF ( [nSizeValidationBid] = 0 ) DO
	{
		RETURN 0;
	}

	#IF ( [fAskPrice] <= 0.0 ) DO
	#{
	#	MessageBox("Need a valid Ask Price.","",MSG_BOX_TYPE_Ok, MSG_BOX_ICON_Exclaim);
	#	SetCtrlFocus(FLD_AskValue);
	#	RETURN 0;
	#}

	#IF ( [fBidPrice] <= 0.0 ) DO
	#{
	#	MessageBox("Need a valid Bid Price.","",MSG_BOX_TYPE_Ok, MSG_BOX_ICON_Exclaim);
	#	SetCtrlFocus(FLD_BidValue);
	#	RETURN 0;
	#}
	
	
	[sInstrumentID] := GetInitialValueString("INSTRUMENT_ID");
	[sBookID] := GetInitialValueString("BOOK_ID");
	[sUserID] := GetInitialValueString("USER_ID");
	
	SetFieldValueInCarrierMsg(FLD_AskValue, GetFieldValue1(FLD_AskValue));
	SetFieldValueInCarrierMsg(FLD_BidValue, GetFieldValue1(FLD_BidValue));
	SetFieldValueInCarrierMsg(FLD_TIF, GetFieldValue1(FLD_TIF));
	SetFieldValueInCarrierMsg(FLD_OwnerID,[sUserID]);
	
	#ExPlus CR12, 3.1.2.1
	#SetFieldValueInCarrierMsg(FLD_ClearingMnemonic,GetFieldValue1(FLD_ClearingMnemonic));
	SetFieldValueInCarrierMsg(FLD_ClearingMnemonic,[s_ClearingMnemonic]);
	
	SetFieldValueInCarrierMsg(FLD_InstrumentID,[sInstrumentID]);
	SetFieldValueInCarrierMsg(FLD_BookDefID,[sBookID]);
	SetFieldValueInCarrierMsg(FLD_TraderID,[sUserID]);
	SetFieldValueInCarrierMsg(FLD_BrokerID,[sUserID]);
	SetFieldValueInCarrierMsg(FLD_RFQID,GetFieldValue1(FLD_RFQID));
	
	
	# Values hard coded for quotes
	SetFieldValueInCarrierMsg(FLD_Capacity, "PRINCIPAL");
	SetFieldValueInCarrierMsg(FLD_OrderSubType, "MANUAL_QUOTE");
	SetFieldValueInCarrierMsg(FLD_Side,"SELL");
	SetFieldValueInCarrierMsg(FLD_OrderType,"LIMIT");
	
	IF ( [g_nEntityMode] = MODE_Amend ) DO
	{
		# No speciality for ammending. Just another quote send.	
	}
	
	RETURN 1;
	
	# BookDefID, ClientOrderID, TraderID, UserID and BroderID  will be set from 
	# the Back-End.
}


# On return presss on the order entry
# =================================================================================
PROCEDURE OnReturnPage
        DECLARE PARAMETER nControlID	AS QUANTITY
        DECLARE PARAMETER sListName		AS TEXT DO
{
	CALL OnPress FLD_Submit, "";
}

# Upon reception of Execution-Report for successful order this will be called if 
# user prefer a resetting of fileds. Reset the necessary fileds here.
# =================================================================================
PROCEDURE ClearOnSuccesss DO
{
	CALL ClearInitially;
}


# =================================================================================
PROCEDURE ClearInitially DO
{
	SetFieldValue1(FLD_OrderQty, "0.0");
	SetFieldValue1(FLD_Value, "0.0");
	SetFieldValue1(FLD_StopPrice, "0.0");
	SetFieldValue1(FLD_VisibleQty, "0.0");	
	
	#ExPlus CR12, 3.1.2.1
	[s_ClearingMnemonic] := "" ; 			
}


# =================================================================================
PROCEDURE ReleaseOnResponse DO
{
	CALL LockAllFileds 0;
	CALL SetLocksOnOrderType GetFieldValue1(FLD_OrderType);
	CALL SetLocksOnTIF GetFieldValue1(FLD_TIF);
	
}

# When price or stop price spinner is pressed.
# =================================================================================
PROCEDURE OnSpin
        DECLARE PARAMETER nControlID	AS QUANTITY
        DECLARE PARAMETER sBuddyValue	AS TEXT
        DECLARE PARAMETER nType			AS QUANTITY DO
{
	# 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) OR
		 ([nControlID] = FLD_BidValue) OR 
		 ([nControlID] = FLD_AskValue)) DO
	{
		IF ( (([nType] = 0) OR ([nType] = 1)) ) DO
		{
			[sTickString] := GetInitialValueString("TICK_FORMAT");
			SetValueOnTick([nControlID], [sTickString], [sBuddyValue], [nType]);
		}
	}
}


# =================================================================================
PROCEDURE OnPress
        DECLARE PARAMETER nButtonID as QUANTITY
        DECLARE PARAMETER sButtonName as TEXT DO
{
		DECLARE VARIABLE nSuccess	AS QUANTITY
		DECLARE VARIABLE nConfirm	AS QUANTITY
		DECLARE VARIABLE nResponse	AS QUANTITY


	IF ([nButtonID] = FLD_Submit) DO
	{	
		[nSuccess] := PackMessage();
		
		IF ( [nSuccess] = 1 ) DO
		{
			[nConfirm] := GetInitialValueInt("CONFIRM_SUBMIT");
			
			IF ( [nConfirm] = 1) THEN
			{
				[nResponse] := MessageBox("Send the Order?","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;
			}
		}
	}
}


# =================================================================================
PROCEDURE ToggleOrder DO
{
	#ChangeControlName(FLD_Submit, GetFieldValue1(FLD_Side));
}

# =================================================================================
PROCEDURE ToggleQuote DO
{
	ChangeControlName(FLD_Submit, "SUBMIT");
}


# =================================================================================
PROCEDURE OnInitForm DO
{
	SetFieldValue1(FLD_AskValue, "0.0");
	SetFieldValue1(FLD_BidValue, "0.0");
}

# =================================================================================
PROCEDURE OnCheck
        DECLARE PARAMETER nControlID as QUANTITY
        DECLARE PARAMETER sName as TEXT
        DECLARE PARAMETER nValue as QUANTITY DO
{	


}
