var SEARCH_ACC_GROUP_ID_CMB = null;
var SEARCH_ACC_ACCOUNT_ID_CMB = null;

var SEARCH_CMD = null;
var LIST_CMD = null;
var GENERATE_CMD = null;
var EXPORT_BBI = null;

var POS_SALE_LIST_DGV = null;
var HTTP_STOCKFLOW_JSON = null;
var PROCESSING_DGV_INDEX = -1;

function FORM_INITIALIZE()
{
	// Initialize Search Elements
	// ...........................................
	if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_GROUP_ID_CMB"))
	{
		SEARCH_ACC_GROUP_ID_CMB = JSOC_ELEMENT.VAR_GET("SEARCH_ACC_GROUP_ID_CMB");
	}
	if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_ID_CMB"))
	{
		SEARCH_ACC_ACCOUNT_ID_CMB = JSOC_ELEMENT.VAR_GET("SEARCH_ACC_ACCOUNT_ID_CMB");
	}
	
	if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_DATE_FROM_DTP"))
	{
		JSOC_ELEMENT.VAR_VALUE("SEARCH_DATE_FROM_DTP", JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_NOW(), "YYYY-MM-DD") + "T00:00");
	}

	// Initialize: Ribbon Buttons [Add Search]
	// ...........................................
	if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_CMD"))
	{
		SEARCH_CMD = JSOC_ELEMENT.VAR_GET("SEARCH_CMD");
		SEARCH_CMD.onclick = function()
		{
			var DGV_COUNT = POS_SALE_LIST_DGV.ROW.COUNT();
			var DGV_INDEX = 0;
			while(DGV_COUNT > DGV_INDEX)
			{
				if(POS_SALE_LIST_DGV.CELL.VALUE("CAT_PRODUCT_CHK", DGV_INDEX) == true)
				{
					break;
				}
				else if(DGV_COUNT - 1 <= DGV_INDEX)
				{
					JSOC_DIALOG.VAR_MESSAGE_BOX
					(
						'Nothing to generate', 
						'Generate hourly stock', 
						JSOC_DIALOG.MSGBOX_TYPE_OK_ONLY,
						JSOC_DIALOG.MSGBOX_ICON_WARNING,
						function(){}
					);	
					return;
				}
				DGV_INDEX ++;
			}	
			
			HTTP_SEARCH_SALES_BEGIN();
		};
	}

	// Initialize: Ribbon Buttons [Add Search]
	// ...........................................
	if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("LIST_CMD"))
	{
		LIST_CMD = JSOC_ELEMENT.VAR_GET("LIST_CMD");
		LIST_CMD.onclick = function()
		{
			HTTP_SEARCH_PRODUCTS();
		};
	}
			
	// Initialize: Ribbon Buttons [Add Search]
	// ...........................................
	if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("EXPORT_BBI"))
	{
		EXPORT_BBI = JSOC_ELEMENT.VAR_GET("EXPORT_BBI");
		EXPORT_BBI.onclick = function()
		{
			JSRC_EXCEL.REF_EXPORT('POS_SALE_LIST_DGV');
		};
	}	
}