	// ===============================================================
	// Global Var
	// ===============================================================
	
	// Edit Handler
	// _______________________________________________________________________
	var EDIT_HANDLER = function(){};	
	EDIT_HANDLER.REF_IS_MODIFIED = false;
	EDIT_HANDLER.HAS_NEWLY_SAVED_DATA = false;
	var PROPERTY_PARENT_ID = 0;
	var PROPERTY_PARENT_DESCRIPTION = "";
	
	var INPUT_INSTANCE = null;

	// Buttons [Optional]
	// _______________________________________________________________________
	var ADD_BBI = null;
	var SEARCH_BBI = null;
	var PROCEED_BBI = null;
	var SAVE_BBI = null;

	// Dialog Controls
	// _______________________________________________________________________
	var SEARCH_CAT_PRICEMDL_ID_CMB = null;

	// DGV Controls
	// _______________________________________________________________________
	var PRODUCT_BRANCH_DGV = null;
	var PRODUCT_DGV = null;

	var ROW_INDEX = 1;

	function FORM_INITIALIZE()
	{
		// Load Cache Parent Data [Add Redirects if this is a required data.]
		// ...........................................
		if(JSVC_COOKIE.VAR_ISSET("PROPERTY_PARENT_ID_PRODUCT_BRANCH_ADD"))
		{
			PROPERTY_PARENT_ID = JSVC_COOKIE.VAR_READ("PROPERTY_PARENT_ID_PRODUCT_BRANCH_ADD");
		}	
		else
		{
			window.location = JSCUS_CACHE.AUTH_REDIRECT_URL[JSCUS_CACHE.LOGIN_CLASS];
		}
		if(JSVC_COOKIE.VAR_ISSET("PROPERTY_PARENT_DESCRIPTION_PRODUCT_BRANCH_ADD"))
		{
			PROPERTY_PARENT_DESCRIPTION = JSVC_COOKIE.VAR_READ("PROPERTY_PARENT_DESCRIPTION_PRODUCT_BRANCH_ADD");
			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PAGE_PARENT_DESCRIPTION_TXT") == true)
			{
				JSOC_ELEMENT.VAR_VALUE("PAGE_PARENT_DESCRIPTION_TXT", PROPERTY_PARENT_DESCRIPTION);			
			}
		}	
		else
		{
			window.location = JSCUS_CACHE.AUTH_REDIRECT_URL[JSCUS_CACHE.LOGIN_CLASS];	
		}
	
		// Restore Cache on reload
		// ...........................................	
		if
		(
			JSVC_COOKIE.VAR_ISSET("PROPERTY_PARENT_ID_PRODUCT_BRANCH_ADD") || 
			JSVC_COOKIE.VAR_ISSET("PROPERTY_PARENT_DESCRIPTION_PRODUCT_BRANCH_ADD")
		)
		{
			  window.onbeforeunload = function(event)
			  {
					// Get Current Root path
					var CURRENT_ROOT_PATH = JSCUS_CACHE.ROOT_PATH + JSVC_STR.VAR_MID(JSVC_STR.VAR_DLEFT(JSCUS_CACHE.AUTH_REDIRECT_URL[JSCUS_CACHE.LOGIN_CLASS], JSCUS_CACHE.SERVER_URL.length), 1, 1);
				
					// Cache Primary Key
					JSVC_COOKIE.VAR_ADD
					(
						'PROPERTY_PARENT_ID_PO_ORDER_LIST', 
						PROPERTY_PARENT_ID, 
						5, 
						CURRENT_ROOT_PATH
					);
					
					// Cache Description
					JSVC_COOKIE.VAR_ADD
					(
						'PROPERTY_PARENT_DESCRIPTION_PO_ORDER_LIST', 
						PROPERTY_PARENT_DESCRIPTION, 
						5, 
						CURRENT_ROOT_PATH
					);
			  };
		}
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PRODUCT_MODAL") == true)
		{
			// Display Modal
			JSOC_DIALOG.VAR_MODAL("PRODUCT_MODAL", false);
		}
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ADD_BBI"))
		{
    		ADD_BBI = JSOC_ELEMENT.VAR_GET("ADD_BBI");     	
			
			// Add OnClick event [Show Modal]
			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PRODUCT_MODAL"))
			{
				ADD_BBI.onclick = 
					function()
					{		
						// Display Modal
						PROPERTY_CAT_PRODUCT_ID = FLAG_BIGINT_NULL;
						PROPERTY_EDIT_ROW_INDEX = -1;
						
						if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
						{
							JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);
						}
						EDIT_HANDLER.REF_IS_MODIFIED = false;
						JSOC_CMB.VAR_SELECTED_VALUE("CAT_PRODUCT_TYPE_CAT_PRODTYPE_ID_CMB", FLAG_BIGINT_NULL.toString());
						LOAD_MAIN_PRODUCT();
						JSOC_DIALOG.VAR_MODAL("PRODUCT_MODAL", true);

					}
			}
			// Add OnClick event [Show Add/Edit Page]
			else
			{
				
			}
		}
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PROCEED_BBI"))
		{
			PROCEED_BBI = JSOC_ELEMENT.VAR_GET("PROCEED_BBI");     
			if(JSVC_VAR.VAR_ISSET(DGV_ADD_PRODUCT))
			{
				// Prepare Save callback
				var CALLBACK_HANDLER = 
					function(IS_SUCCESS)
					{
						// Abort on failure
						if(IS_SUCCESS == false)
						{
							return;
						}
					
						// Show record saved messageBox
						JSVC_INFO.VAR_RECORD_SAVED('');
					}
				
				// Add OnClick event
				PROCEED_BBI.onclick = 
					function()
					{
						DGV_ADD_PRODUCT(CALLBACK_HANDLER);
					}
			}
		}
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SAVE_BBI"))
		{
			SAVE_BBI = JSOC_ELEMENT.VAR_GET("SAVE_BBI");     
			if(JSVC_VAR.VAR_ISSET(HTTP_SAVE))
			{
				// Prepare Save callback
				var CALLBACK_HANDLER = 
					function(IS_SUCCESS)
					{
						// Abort on failure
						if(IS_SUCCESS == false)
						{
							if(ROW_INDEX < PRODUCT_BRANCH_DGV.ROW.COUNT())
							{
								ROW_INDEX++;
								if(JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_ID', ROW_INDEX - 1)) == 0)
									IF_EXISTS(CALLBACK_HANDLER, ROW_INDEX - 1);
								else
									HTTP_SAVE(CALLBACK_HANDLER, ROW_INDEX - 1, false);
							}
							return;
						}
						else
						{
							if(ROW_INDEX < PRODUCT_BRANCH_DGV.ROW.COUNT())
							{
								ROW_INDEX++;
								if(JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_ID', ROW_INDEX - 1)) == 0)
									IF_EXISTS(CALLBACK_HANDLER, ROW_INDEX - 1);
								else
									HTTP_SAVE(CALLBACK_HANDLER, ROW_INDEX - 1, false);

								return;
							}
						}

						// Show record saved messageBox
						CUS_SEND_DIALOG_TRY_DISMISS();
						JSVC_INFO.VAR_RECORD_SAVED('');
					}

				// Add OnClick event
				SAVE_BBI.onclick = 
					function()
					{
						if(PRODUCT_BRANCH_DGV.ROW.COUNT() <= 0)
						{
							JSOC_DIALOG.VAR_MESSAGE_BOX
							(
								'No data found.', 
								'Information',
								'OK', 'WARNING'
							);
							return;
						}

						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							'Any product does not have default SRP pricing scheme will be created automatically. Are you sure you want to update data of branch product?', 
							'Information',
							'YES NO', 'QUESTION',
							function(MESSAGE_RESPONSE)
							{
								if(MESSAGE_RESPONSE == 2)
								{
									ROW_INDEX = 1
									if(PRODUCT_BRANCH_DGV.ROW.COUNT() >= ROW_INDEX)
									{
										if(JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_ID', ROW_INDEX - 1)) == 0)
											IF_EXISTS(CALLBACK_HANDLER, ROW_INDEX - 1);
										else
											HTTP_SAVE(CALLBACK_HANDLER, ROW_INDEX - 1, false);
									}
								}
							}
						);
					}
			}
		}
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_BBI"))
		{
    		SEARCH_BBI = JSOC_ELEMENT.VAR_GET("SEARCH_BBI");
			SEARCH_BBI.onclick = function(){LOAD_MAIN_PRODUCT()};
		}
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_CAT_PRICEMDL_ID_CMB"))
		{
			SEARCH_CAT_PRICEMDL_ID_CMB = JSOC_ELEMENT.VAR_GET("SEARCH_CAT_PRICEMDL_ID_CMB");      	
			SEARCH_CAT_PRICEMDL_ID_CMB.onchange = 
				function()
				{
					HTTP_SEARCH();
				};
			SEARCH_CAT_PRICEMDL_ID_CMB.onkeypress = function(){SEARCH_CAT_PRICEMDL_ID_CMB.onchange();};
			SEARCH_CAT_PRICEMDL_ID_CMB.onpaste = function(){SEARCH_CAT_PRICEMDL_ID_CMB.onchange();};
			//SEARCH_CAT_PRICEMDL_ID_CMB.oninput = function(){SEARCH_CAT_PRICEMDL_ID_CMB.onchange();};							
		}
	}