// NOTE: [This JS must loaded as last item]


	// ===============================================================
	// Initialize Form
	// ===============================================================
	function FORM_LOAD()
	{
		// Initialize
		// _______________________________________________________________________	
		var DGV_ELEMENT_CHILD = null;
		var DGV_ELEMENT_CHILD_INDEX = 0;
		
		
		// Load DataGridVuew
		// _______________________________________________________________________	
		JSTOOL_CUSTOMIZE.DGVREORDER.APPLY("PSCHEDULE_DGV");
		PSCHEDULE_DGV = DataGridView("PSCHEDULE_DGV");
		//PSCHEDULE_DGV.SETTING_ALLOW_USER_TO_ADD_ROWS = true;
		//PSCHEDULE_DGV.SETTING_EDITABLE = true;
	

		// Auto Compute
		// _______________________________________________________________________	
		var AUTO_CALC = JSTOOL_CUSTOMIZE.DGVCALC.APPLY(PSCHEDULE_DGV);
		var AUTO_COMPUTE_BLOCKS = AUTO_CALC[0];
			
		/*
			// Sample Code
			AUTO_COMPUTE_BLOCKS.push
			(
				[
					'COLUMN_A', 					// Target Column
					'`COLUMN_1` + `COLUMN_2`',		// Math
					true							// Apply CFormat
				]
			);
		*/
		
		AUTO_COMPUTE_BLOCKS.push
		(
			[
				'REC_PSCHEDULE_QTY_TOTAL', 					
				'`REC_PSCHEDULE_QTY_D01` + `REC_PSCHEDULE_QTY_D02` + `REC_PSCHEDULE_QTY_D03` + `REC_PSCHEDULE_QTY_D04` + `REC_PSCHEDULE_QTY_D05` + `REC_PSCHEDULE_QTY_D06` + `REC_PSCHEDULE_QTY_D07` + ' +
				'`REC_PSCHEDULE_QTY_D08` + `REC_PSCHEDULE_QTY_D09` + `REC_PSCHEDULE_QTY_D10` + `REC_PSCHEDULE_QTY_D11` + `REC_PSCHEDULE_QTY_D12` + `REC_PSCHEDULE_QTY_D13` + `REC_PSCHEDULE_QTY_D14` + ' +
				'`REC_PSCHEDULE_QTY_D15` + `REC_PSCHEDULE_QTY_D16` + `REC_PSCHEDULE_QTY_D17` + `REC_PSCHEDULE_QTY_D18` + `REC_PSCHEDULE_QTY_D19` + `REC_PSCHEDULE_QTY_D20` + `REC_PSCHEDULE_QTY_D21` + ' +
				'`REC_PSCHEDULE_QTY_D22` + `REC_PSCHEDULE_QTY_D23` + `REC_PSCHEDULE_QTY_D24` + `REC_PSCHEDULE_QTY_D25` + `REC_PSCHEDULE_QTY_D26` + `REC_PSCHEDULE_QTY_D27` + `REC_PSCHEDULE_QTY_D28` + ' +
				'`REC_PSCHEDULE_QTY_D29` + `REC_PSCHEDULE_QTY_D30` + `REC_PSCHEDULE_QTY_D31`',
				true					
			]
		);
		AUTO_COMPUTE_BLOCKS.push
		(
			[
				'AMOUNT', 					
				'`REC_PSCHEDULE_QTY_TOTAL` * `REC_PSCHEDULE_AMOUNT_PRICE`',
				true					
			]
		);
		AUTO_COMPUTE_BLOCKS.push
		(
			[
				'COST', 					
				'`REC_PSCHEDULE_QTY_TOTAL` * `REC_PSCHEDULE_AMOUNT_COST`',
				true					
			]
		);
		AUTO_COMPUTE_BLOCKS.push
		(
			[
				'GM', '`AMOUNT` - `COST`', true					
			]
		);
		PSCHEDULE_DGV.COLUMN.AUTO_COMPUTE_CREATE(AUTO_COMPUTE_BLOCKS);
		
		
		// Auto Total
		// _______________________________________________________________________	
		var AUTO_TOTAL_COLUMNS = AUTO_CALC[1];
		var AUTO_TOTAL_COPY_TO_ELEMENT = AUTO_CALC[2];
		
		/*
			AUTO_TOTAL_COLUMNS.push('COLUMN_A');					// Column to Auto Total
			AUTO_TOTAL_COPY_TO_ELEMENT.push(["COL_ID", "ELEM_ID"]);	// Source Column, Element ID where total is copied to
			
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_AMOUNT_PRICE');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_AMOUNT_COST');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D01');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D02');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D03');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D04');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D05');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D06');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D07');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D08');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D09');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D10');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D11');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D12');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D13');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D14');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D15');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D16');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D17');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D18');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D19');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D20');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D21');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D22');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D23');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D24');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D25');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D26');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D27');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D28');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D29');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D30');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_D31');
			AUTO_TOTAL_COLUMNS.push('REC_PSCHEDULE_QTY_TOTAL');
		*/
		/*
		PSCHEDULE_DGV.COLUMN.TOTAL_CREATE
		(
			AUTO_TOTAL_COLUMNS,
			'REC_PSCHEDULE_ID',									// Column, where you want to display the caption `Total:`.
			AUTO_TOTAL_COPY_TO_ELEMENT
		);		
		*/
		
		
		PSCHEDULE_DGV.ON_CLICK
		(			
			function(COL_INDEX, ROW_INDEX)
			{
				// Delete Button
				// ...........................................
				if(PSCHEDULE_DGV.COLUMN.NAME(COL_INDEX) == "DELETE_CMD")
				{
					// Delete Unsaved Item
					if
					(
						PSCHEDULE_DGV.COLUMN.IS_EXISTS("REC_PSCHEDULE_ID") &&
						JSVC_NUM.VAR_NVALL(PSCHEDULE_DGV.CELL.VALUE("REC_PSCHEDULE_ID", ROW_INDEX)) <= 0
					)
					{
						PSCHEDULE_DGV.ROW.REMOVE_AT(ROW_INDEX);
					}
					
					// Delete Saved Item
					else
					{
						HTTP_DELETE
						(
							function(IS_SUCCESS)
							{
								console.log('Record Deleted.');
							}, 
							ROW_INDEX
						);				
					}
				}			

				// Void Button
				// ...........................................
				else if(PSCHEDULE_DGV.COLUMN.NAME(COL_INDEX) == "VOID_CMD")
				{
					// Delete Unsaved Item
					if
					(
						PSCHEDULE_DGV.COLUMN.IS_EXISTS("REC_PSCHEDULE_ID") &&
						JSVC_NUM.VAR_NVALL(PSCHEDULE_DGV.CELL.VALUE("REC_PSCHEDULE_ID", ROW_INDEX)) <= 0
					)
					{
						PSCHEDULE_DGV.ROW.REMOVE_AT(ROW_INDEX);
					}
					
					// Void Saved Item
					else
					{

					}
				}	

				// Highlight the value in an input text
				// ...........................................
				else
				{
					var ADDED_COUNT = "0";
					for(var ROW_COUNT = 1; ROW_COUNT <= 31; ROW_COUNT++)
					{
						if(ROW_COUNT.toString().length < 2)
							ADDED_COUNT = "0" + ROW_COUNT.toString();
						else
							ADDED_COUNT = ROW_COUNT.toString();

						if(PSCHEDULE_DGV.COLUMN.NAME(COL_INDEX) == "REC_PSCHEDULE_QTY_D"+ADDED_COUNT)
						{
							var REC_PSCHEDULE_QTY_D = PSCHEDULE_DGV.CELL.ELEMENT("REC_PSCHEDULE_QTY_D"+ADDED_COUNT, ROW_INDEX);
							REC_PSCHEDULE_QTY_D.select();

							break;
						}
					}

					return;
				}
				
				// Link to Child Table
				// ...........................................
				/*
				// Sample Child Code
				else if(PSCHEDULE_DGV.COLUMN.NAME(COL_INDEX) == "CHILD_CMD")
				{
					// 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', 
						PSCHEDULE_DGV.CELL.VALUE('REC_PSCHEDULE_ID', ROW_INDEX), 
						5, 
						CURRENT_ROOT_PATH
					);
					JSVC_COOKIE.VAR_ADD
					(
						'PROPERTY_PARENT_DESCRIPTION', 
						PSCHEDULE_DGV.CELL.VALUE('REC_PSCHEDULE_ID', ROW_INDEX), 
						5, 
						CURRENT_ROOT_PATH
					);
					
					// Open EditPage
					window.location = JSCUS_CACHE.SERVER_URL + '/p/record/pschedule.html';	
					return;
				}
				*/
						
	
				// If dialog supported
				// ...........................................
				/*
				else if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PSCHEDULE_MODAL") == true)
				{
					// Clear Modal
					if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
					{
						JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);
					}
						
					// Display Modal
					PROPERTY_REC_PSCHEDULE_ID = PSCHEDULE_DGV.CELL.VALUE('REC_PSCHEDULE_ID', ROW_INDEX);
					PROPERTY_EDIT_ROW_INDEX = ROW_INDEX;
					
					EDIT_HANDLER.REF_IS_MODIFIED = false;
					JSOC_DIALOG.VAR_MODAL("PSCHEDULE_MODAL", true);
					HTTP_LOAD();
					return;
				}
				*/
				
				// Open View / Edit Page
				// ...........................................
				/*
				else if(PSCHEDULE_DGV.SETTING_EDITABLE == false)
				{
					// 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', 
						PSCHEDULE_DGV.CELL.VALUE('REC_PSCHEDULE_ID', ROW_INDEX), 
						5, 
						CURRENT_ROOT_PATH
					);
					JSVC_COOKIE.VAR_ADD
					(
						'PROPERTY_PARENT_DESCRIPTION', 
						PSCHEDULE_DGV.CELL.VALUE('REC_PSCHEDULE_ID', ROW_INDEX), 
						5, 
						CURRENT_ROOT_PATH
					);
					
					// Open EditPage
					window.location = 'pschedule_info.html';				
				}
				*/

			}
		);   

		PSCHEDULE_DGV.ON_CHANGE
		(			
			function(COL_INDEX, ROW_INDEX)
			{
				// Update Change Status
				// ...........................................
				EDIT_HANDLER.REF_IS_MODIFIED = true;
				
				// Initialize
				// ...........................................
				var COLUMN_NAME = PSCHEDULE_DGV.COLUMN.NAME(COL_INDEX);
				
				// Abort if not qty changes
				// ...........................................
				if(JSVC_STR.VAR_CONTAINS_LEFT(COLUMN_NAME, "REC_PSCHEDULE_QTY_D") == false)
				{
					return;
				}				
				
				// Update Values
				// ...........................................
				PSCHEDULE_DGV.COLUMN.AUTO_COMPUTE_EXECUTE(ROW_INDEX);
				
				if(PSCHEDULE_DGV.COLUMN.TOTAL_IS_READY())
				{
					PSCHEDULE_DGV.COLUMN.TOTAL_REFRESH();
				}
			}
		);
					
		// Show Progress
		// _______________________________________________________________________	
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		
		
		// Requires Authentication
		// _______________________________________________________________________	
		PAGE_AUTH_REQUIRES_LOGIN(HTTP_POPULATE_RESULT);			


		
		
		// Foreign Key [Fixed]
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_PSCHEDULE_ACC_GROUP_ID_CMB") == true)
		{
			// Set Default Item, if used in DataGridView
			JSOC_CMB.VAR_ADD("REC_PSCHEDULE_ACC_GROUP_ID_CMB", FLAG_BIGINT_NULL.toString(), "-");
			
			// To use custom populate
			var GET_MAP_ARRAY = JSCUS_SQL._ACCOUNT._GROUP.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ACC_GROUP_STATUS', JSCUS_SQL._SYSTEM._STATUS.STATUS_ACTIVE);	
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ACC_GROUP_SYSTEM_GENERATED', JSCUS_SQL._SYSTEM._STATUS.STATUS_INACTIVE);	
			
			JSCUS_SQL._ACCOUNT._GROUP.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function(IS_SUCCESS, RESPONSE_STRING)
				{
					// Set Default index
					JSOC_CMB.VAR_SELECTED_INDEX("REC_PSCHEDULE_ACC_GROUP_ID_CMB", 0);
					
					// Clone to DGV Cell if ComboBox Exists
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PSCHEDULE_DGV_ROW_REC_PSCHEDULE_ACC_GROUP_ID") == true)
					{
						DGV_ELEMENT_CHILD = JSOC_ELEMENT.VAR_SUB_ELEMENTS("PSCHEDULE_DGV_ROW_REC_PSCHEDULE_ACC_GROUP_ID");
						DGV_ELEMENT_CHILD_INDEX = 0;
						while(DGV_ELEMENT_CHILD.length > DGV_ELEMENT_CHILD_INDEX)
						{
							if
							(
								DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX].tagName == "SELECT" &&
								JSVC_STR.VAR_IS_BLANK(DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX].id.toString())
							)
							{
								JSOC_ELEMENT.VAR_INNER_HTML
								(
									DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX], 
									JSOC_ELEMENT.VAR_INNER_HTML("REC_PSCHEDULE_ACC_GROUP_ID_CMB")
								);
							}	
							DGV_ELEMENT_CHILD_INDEX ++;
						}
					}
					
					// Check if user has override access to psschedule 
					if(JSCUS_SQL._ACCOUNT._LOGIN.CUS_ME_HAS_PERMISSION("record_pschedule", 5) == false)
					{
						JSOC_ELEMENT.VAR_ENABLED('REC_PSCHEDULE_ACC_GROUP_ID_CMB', false);
					}
					
					// Copy items to edit control
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_REC_PSCHEDULE_ACC_GROUP_ID_CMB") == true)
					{
						JSOC_CMB.VAR_CLEAR("SEARCH_REC_PSCHEDULE_ACC_GROUP_ID_CMB");
						JSOC_ELEMENT.VAR_INNER_HTML("SEARCH_REC_PSCHEDULE_ACC_GROUP_ID_CMB", JSOC_ELEMENT.VAR_INNER_HTML("REC_PSCHEDULE_ACC_GROUP_ID_CMB"), true);
						JSOC_CMB.VAR_SELECTED_VALUE("SEARCH_REC_PSCHEDULE_ACC_GROUP_ID_CMB", JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_ACC_GROUP_ID.toString());
						$('.BSSP_SEARCH_REC_PSCHEDULE_ACC_GROUP_ID_CMB').selectpicker('refresh');
						
						// Check if user has override access to psschedule 
						if(JSCUS_SQL._ACCOUNT._LOGIN.CUS_ME_HAS_PERMISSION("record_pschedule", 5) == false)
						{
							JSOC_ELEMENT.VAR_ENABLED('REC_PSCHEDULE_ACC_GROUP_ID_CMB', false);
						}
					}				
					
					// Update Modal Settings
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PSCHEDULE_MODAL") == true)
					{
						INPUT_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("PSCHEDULE_MODAL");
					}
					
					// Forward populate complete event.
					$('.BSSP_REC_PSCHEDULE_ACC_GROUP_ID_CMB').selectpicker('refresh');
					
					

			
					HTTP_POPULATE_RESULT();		
				},
				"REC_PSCHEDULE_ACC_GROUP_ID_CMB",
				true, 2, GET_MAP_ARRAY 
			);
		}
		if
		(
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_REC_PSCHEDULE_ACC_GROUP_ID_CMB") == true &&
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_PSCHEDULE_ACC_GROUP_ID_CMB") == false
		)
		{
			JSOC_CMB.VAR_CLEAR("SEARCH_REC_PSCHEDULE_ACC_GROUP_ID_CMB");
			
			// To use custom populate
			var GET_MAP_ARRAY = JSCUS_SQL._ACCOUNT._GROUP.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_', JSCUS_SQL._SYSTEM._STATUS.STATUS_ACTIVE);	
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ACC_GROUP_SYSTEM_GENERATED', JSCUS_SQL._SYSTEM._STATUS.STATUS_INACTIVE);	
							
			JSCUS_SQL._ACCOUNT._GROUP.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function(IS_SUCCESS, RESPONSE_STRING)
				{
					// Set Default index
					JSOC_CMB.VAR_SELECTED_INDEX("SEARCH_REC_PSCHEDULE_ACC_GROUP_ID_CMB", 0);
					
					// Forward populate complete event.		
					$('.BSSP_SEARCH_REC_PSCHEDULE_ACC_GROUP_ID_CMB').selectpicker('refresh');
					HTTP_POPULATE_RESULT();
					
					// Check if user has override access to psschedule 
					if(JSCUS_SQL._ACCOUNT._LOGIN.CUS_ME_HAS_PERMISSION("record_pschedule", 5) == false)
					{
						JSOC_ELEMENT.VAR_ENABLED('REC_PSCHEDULE_ACC_GROUP_ID_CMB', false);
					}
				},		
				"SEARCH_REC_PSCHEDULE_ACC_GROUP_ID_CMB",
				true, 2, GET_MAP_ARRAY 
			);
		}
		
		// Foreign Key [Fixed]
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_PSCHEDULE_CAT_PRODUCT_ID_CMB") == true)
		{
			// Set Default Item, if used in DataGridView
			JSOC_CMB.VAR_ADD("REC_PSCHEDULE_CAT_PRODUCT_ID_CMB", FLAG_BIGINT_NULL.toString(), "-");
			// To use custom populate
			// var GET_MAP_ARRAY = JSCUS_SQL._CATEGORY._PRODUCT.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			// JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_', JSCUS_SQL._SYSTEM._STATUS.STATUS_ACTIVE);	
			JSCUS_SQL._CATEGORY._PRODUCT.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function(IS_SUCCESS, RESPONSE_STRING)
				{
					// Set Default index
					JSOC_CMB.VAR_SELECTED_INDEX("REC_PSCHEDULE_CAT_PRODUCT_ID_CMB", 0);
					
					// Clone to DGV Cell if ComboBox Exists
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PSCHEDULE_DGV_ROW_REC_PSCHEDULE_CAT_PRODUCT_ID") == true)
					{
						DGV_ELEMENT_CHILD = JSOC_ELEMENT.VAR_SUB_ELEMENTS("PSCHEDULE_DGV_ROW_REC_PSCHEDULE_CAT_PRODUCT_ID");
						DGV_ELEMENT_CHILD_INDEX = 0;
						while(DGV_ELEMENT_CHILD.length > DGV_ELEMENT_CHILD_INDEX)
						{
							if
							(
								DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX].tagName == "SELECT" &&
								JSVC_STR.VAR_IS_BLANK(DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX].id.toString())
							)
							{
								JSOC_ELEMENT.VAR_INNER_HTML
								(
									DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX], 
									JSOC_ELEMENT.VAR_INNER_HTML("REC_PSCHEDULE_CAT_PRODUCT_ID_CMB")
								);
							}	
							DGV_ELEMENT_CHILD_INDEX ++;
						}
					}
					
					// Copy items to edit control
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_REC_PSCHEDULE_CAT_PRODUCT_ID_CMB") == true)
					{
						JSOC_CMB.VAR_CLEAR("SEARCH_REC_PSCHEDULE_CAT_PRODUCT_ID_CMB");
						JSOC_CMB.VAR_ADD("SEARCH_REC_PSCHEDULE_CAT_PRODUCT_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Product");
						JSOC_ELEMENT.VAR_INNER_HTML("SEARCH_REC_PSCHEDULE_CAT_PRODUCT_ID_CMB", JSOC_ELEMENT.VAR_INNER_HTML("REC_PSCHEDULE_CAT_PRODUCT_ID_CMB"), true);
						JSOC_CMB.VAR_SELECTED_INDEX("SEARCH_REC_PSCHEDULE_CAT_PRODUCT_ID_CMB", 0);
						$('.BSSP_SEARCH_REC_PSCHEDULE_CAT_PRODUCT_ID_CMB').selectpicker('refresh');
					}				
					
					// Update Modal Settings
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PSCHEDULE_MODAL") == true)
					{
						INPUT_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("PSCHEDULE_MODAL");
					}
					
					// Forward populate complete event.
					$('.BSSP_REC_PSCHEDULE_CAT_PRODUCT_ID_CMB').selectpicker('refresh');
					HTTP_POPULATE_RESULT();		
				},
				"REC_PSCHEDULE_CAT_PRODUCT_ID_CMB",
				true, 2
				// , GET_MAP_ARRAY 
			);
		}
		if
		(
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_REC_PSCHEDULE_CAT_PRODUCT_ID_CMB") == true &&
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_PSCHEDULE_CAT_PRODUCT_ID_CMB") == false
		)
		{
			JSOC_CMB.VAR_CLEAR("SEARCH_REC_PSCHEDULE_CAT_PRODUCT_ID_CMB");
			JSOC_CMB.VAR_ADD("SEARCH_REC_PSCHEDULE_CAT_PRODUCT_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Product");
			// To use custom populate
			// var GET_MAP_ARRAY = JSCUS_SQL._CATEGORY._PRODUCT.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			// JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_', JSCUS_SQL._SYSTEM._STATUS.STATUS_ACTIVE);	
			JSCUS_SQL._CATEGORY._PRODUCT.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function(IS_SUCCESS, RESPONSE_STRING)
				{
					// Set Default index
					JSOC_CMB.VAR_SELECTED_INDEX("SEARCH_REC_PSCHEDULE_CAT_PRODUCT_ID_CMB", 0);
					
					// Forward populate complete event.		
					$('.BSSP_SEARCH_REC_PSCHEDULE_CAT_PRODUCT_ID_CMB').selectpicker('refresh');
					HTTP_POPULATE_RESULT();
				},		
				"SEARCH_REC_PSCHEDULE_CAT_PRODUCT_ID_CMB",
				true, 2
				// , GET_MAP_ARRAY 
			);
		}
		
		// Status		
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_REC_PSCHEDULE_STATUS_CMB") == true)
		{
			JSOC_CMB.VAR_CLEAR("SEARCH_REC_PSCHEDULE_STATUS_CMB");
			JSOC_CMB.VAR_ADD("SEARCH_REC_PSCHEDULE_STATUS_CMB", "0","Any Status");
			JSOC_CMB.VAR_ADD("SEARCH_REC_PSCHEDULE_STATUS_CMB", "1","Inactive");
			JSOC_CMB.VAR_ADD("SEARCH_REC_PSCHEDULE_STATUS_CMB", "2","Active");
			// JSOC_CMB.VAR_ADD("SEARCH_REC_PSCHEDULE_STATUS_CMB", "3","Closed");
			// JSOC_CMB.VAR_ADD("SEARCH_REC_PSCHEDULE_STATUS_CMB", "4","Completed");
			JSOC_CMB.VAR_SELECTED_VALUE("SEARCH_REC_PSCHEDULE_STATUS_CMB", "2");
		}			
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_PSCHEDULE_STATUS_CMB") == true)
		{
			JSOC_CMB.VAR_CLEAR("REC_PSCHEDULE_STATUS_CMB");
			JSOC_CMB.VAR_ADD("REC_PSCHEDULE_STATUS_CMB", "1","Inactive");
			JSOC_CMB.VAR_ADD("REC_PSCHEDULE_STATUS_CMB", "2","Active");
			// JSOC_CMB.VAR_ADD("REC_PSCHEDULE_STATUS_CMB", "3","Closed");
			// JSOC_CMB.VAR_ADD("REC_PSCHEDULE_STATUS_CMB", "4","Completed");
			JSOC_CMB.VAR_SELECTED_VALUE("REC_PSCHEDULE_STATUS_CMB", "2");
		}
		
		
		
		// Get Modal Instance (Add Modal Adjustment before this line)
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PSCHEDULE_MODAL") == true)
		{
			INPUT_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("PSCHEDULE_MODAL");
		}
		
		// Add Search Events for the SEARCH_DESCRIPTION_TXT - TextInput
		// _______________________________________________________________________		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_REC_PSCHEDULE_ID_TXT"))
		{
			var SEARCH_REC_PSCHEDULE_ID_TXT = JSOC_ELEMENT.VAR_GET("SEARCH_REC_PSCHEDULE_ID_TXT");
			SEARCH_REC_PSCHEDULE_ID_TXT.onkeydown = 
				function() 
				{ 
					return function(e) 
					{
						if
						(
							(
								e.which == 13 || 
								e.keyCode == 13 || 
								e.key === "Enter"
							) &&
							JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_CMD")
						)
						{
							HTTP_SEARCH();
						}
					};
				}();
		}
		
		
		// Load Parent Data (if Exists)
		// _______________________________________________________________________	
		HTTP_PARENT_LOAD();
		
		
		// Pre-Load Items (uncomment if no foreign key pre-fetch)
		// _______________________________________________________________________	
		if(CUS_SEND_REQUEST_HAS_QUEUE() == false)
		{
			//HTTP_SEARCH();
		}
		
		
		// Disable Dialogs
		// _______________________________________________________________________	
		CUS_SEND_DIALOG_TRY_DISMISS();
	};
	
	
	// ===============================================================
	// Populate Foreign Keys
	// ===============================================================
	function HTTP_POPULATE_RESULT(IS_SUCCESS, HTTP_RESPONSE)
	{
		// Disable Dialogs
		CUS_SEND_DIALOG_TRY_DISMISS();
			
		// Handle Error
		if(IS_SUCCESS === false)
		{
			alert("Unable to populate lists.");
		}
		else
		{
			// Disable Dialogs
			if(CUS_SEND_REQUEST_HAS_QUEUE() == false)
			{
				//HTTP_SEARCH();
			}
		}
	};

	
	// ===============================================================
	// Request Search - PART.A
	// ===============================================================
	function HTTP_SEARCH(NEW_ITEM_ID, EDITED_ROW_INDEX)
	{
		// Optional Value
		// _______________________________________________________________________
		NEW_ITEM_ID = JSVC_VAR.VAR_OPTIONAL(NEW_ITEM_ID, -1);
		EDITED_ROW_INDEX = JSVC_VAR.VAR_OPTIONAL(EDITED_ROW_INDEX, -1);
		
		// Parameter Validate
		// _______________________________________________________________________
		JSVC_AV.VAR_VALIDATE_ARGUMENT_TYPE(NEW_ITEM_ID, 'NEW_ITEM_ID', 'NUMERIC');
		JSVC_AV.VAR_VALIDATE_ARGUMENT_TYPE(EDITED_ROW_INDEX, 'EDITED_ROW_INDEX', 'NUMERIC');
		
		
		// Actual Function
		// _______________________________________________________________________
		GET_MAP_ARRAY = JSCUS_SQL._RECORD._PSCHEDULE.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();	
		// if(JSVC_VAR.VAR_ISSET("PROPERTY_PARENT_ID"))
		// {
		//	JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_PARENT_ID', PROPERTY_PARENT_ID);
		// }  // Parent ID Sample
		
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_ACC_GROUP_ID_CMB', 'PARAM_REC_PSCHEDULE_ACC_GROUP_ID'
		);
		
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_CAT_PRODUCT_ID_CMB', 'PARAM_REC_PSCHEDULE_CAT_PRODUCT_ID'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_AMOUNT_PRICE_FROM_TXT', 'PARAM_REC_PSCHEDULE_AMOUNT_PRICE_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_AMOUNT_PRICE_TO_TXT', 'PARAM_REC_PSCHEDULE_AMOUNT_PRICE_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_AMOUNT_COST_FROM_TXT', 'PARAM_REC_PSCHEDULE_AMOUNT_COST_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_AMOUNT_COST_TO_TXT', 'PARAM_REC_PSCHEDULE_AMOUNT_COST_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D01_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D01_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D01_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D01_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D02_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D02_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D02_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D02_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D03_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D03_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D03_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D03_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D04_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D04_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D04_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D04_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D05_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D05_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D05_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D05_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D06_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D06_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D06_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D06_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D07_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D07_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D07_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D07_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D08_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D08_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D08_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D08_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D09_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D09_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D09_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D09_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D10_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D10_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D10_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D10_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D11_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D11_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D11_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D11_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D12_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D12_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D12_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D12_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D13_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D13_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D13_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D13_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D14_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D14_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D14_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D14_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D15_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D15_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D15_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D15_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D16_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D16_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D16_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D16_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D17_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D17_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D17_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D17_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D18_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D18_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D18_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D18_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D19_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D19_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D19_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D19_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D20_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D20_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D20_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D20_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D21_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D21_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D21_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D21_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D22_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D22_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D22_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D22_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D23_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D23_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D23_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D23_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D24_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D24_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D24_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D24_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D25_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D25_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D25_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D25_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D26_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D26_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D26_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D26_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D27_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D27_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D27_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D27_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D28_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D28_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D28_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D28_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D29_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D29_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D29_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D29_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D30_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D30_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D30_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D30_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D31_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_D31_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_D31_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_D31_TO'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_TOTAL_FROM_TXT', 'PARAM_REC_PSCHEDULE_QTY_TOTAL_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_QTY_TOTAL_TO_TXT', 'PARAM_REC_PSCHEDULE_QTY_TOTAL_TO'
		);
		
		
		JSVC_MAP_ARRAY.VAR_SET
		(
			GET_MAP_ARRAY, 'PARAM_REC_PSCHEDULE_DATE_FROM', 
			JSVC_DATE.VAR_FORMAT
			(
				JSVC_DATE.VAR_BEGIN_OF_MONTH(JSOC_ELEMENT.VAR_VALUE('SEARCH_REC_PSCHEDULE_DATE_FROM_DTP')),
				"YYYY-MM-DD HH:mm:ss" 
			) + ".000000"
		);		
		JSVC_MAP_ARRAY.VAR_SET
		(
			GET_MAP_ARRAY, 'PARAM_REC_PSCHEDULE_DATE_TO', 
			JSVC_DATE.VAR_FORMAT
			(
				JSVC_DATE.VAR_BEGIN_OF_MONTH(JSOC_ELEMENT.VAR_VALUE('SEARCH_REC_PSCHEDULE_DATE_FROM_DTP')),
				"YYYY-MM-DD HH:mm:ss" 
			) + ".000000"
		);		
		

		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_REMARKS_TXT', 'PARAM_REC_PSCHEDULE_REMARKS'
		);	
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_PSCHEDULE_STATUS_CMB', 'PARAM_REC_PSCHEDULE_STATUS'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_ORDER_BY_CMB', 'PARAM_ORDER_FIELD'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_LIMIT_CMB', 'PARAM_LIMIT'
		);		
		
		var SELECTED_SEARCH_MODE = 0;
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_MODE_CMB") == true)
		{
			SELECTED_SEARCH_MODE = JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE("SEARCH_MODE_CMB"));		
		}						
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		
		
		// Search Inserted / Saved Record
		// _______________________________________________________________________
		if(NEW_ITEM_ID >= 0)
		{
			GET_MAP_ARRAY = JSCUS_SQL._RECORD._PSCHEDULE.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();	
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_PSCHEDULE_ID', NEW_ITEM_ID);
			
			JSCUS_SQL._RECORD._PSCHEDULE.CUS_GET
			(
				GET_MAP_ARRAY,
				function(IS_SUCCESS, RESPONSE_STRING)
				{
					// Update Existing Row
					if(EDITED_ROW_INDEX >= 0)
					{
						HTTP_SEARCH_LIMITED_ROWS_CALLBACK(IS_SUCCESS, RESPONSE_STRING, EDITED_ROW_INDEX);
					}
					
					// Add new item
					else
					{
						HTTP_SEARCH_LIMITED_ROWS_CALLBACK(IS_SUCCESS, RESPONSE_STRING, 0);
					}
				},
				true
			); 			
		}
			
			
		// REGULAR Search Mode
		// _______________________________________________________________________
		else if(SELECTED_SEARCH_MODE == 0)
		{			
			JSCUS_SQL._RECORD._PSCHEDULE.CUS_GET
			(
				GET_MAP_ARRAY,
				HTTP_SEARCH_CALLBACK,
				true
			); 			
       	}
		
		
		// LITE Search Mode
		// _______________________________________________________________________
		else if(SELECTED_SEARCH_MODE == 1)
		{
			JSCUS_SQL._RECORD._PSCHEDULE.CUS_GET_LITE
			(
				GET_MAP_ARRAY,
				HTTP_SEARCH_CALLBACK,
				true
			); 				
		}
		
		
		// ALL Search Mode
		// _______________________________________________________________________
		else if(SELECTED_SEARCH_MODE == 2)
		{
			JSCUS_SQL._RECORD._PSCHEDULE.CUS_GET_ALL
			(
				GET_MAP_ARRAY,
				HTTP_SEARCH_CALLBACK,
				true
			); 							
		}
	};
	
	
	// ===============================================================
	// Request Search - PART.B
	// ===============================================================
	function HTTP_SEARCH_CALLBACK(IS_SUCCESS, RESPONSE_STRING)
	{
		// Disable Dialogs
		// _______________________________________________________________________
		CUS_SEND_DIALOG_TRY_DISMISS();
		
		// Validate
		// _______________________________________________________________________
		if(IS_SUCCESS === false)
		{
			console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
			return;
		}
		
		// Validate JSON Response
		// _______________________________________________________________________
		var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
		if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
		{
			console.error("REQUEST ERROR: \n" + RESPONSE_STRING);
			return;
		}
		
		// Back to DGV Top
		// _______________________________________________________________________	
		if(LOAD_PAGING_IGNORE_NEXT_REQUEST == true)
		{
			JSOC_ELEMENT.VAR_GET("PSCHEDULE_DGV").scrollIntoView
			(
				{
			  		behavior: 'auto', 
			  		block: 'start'
				}
			);		
		}
		
		
		// JSON Empty (Clears the DataGrodView)
		// _______________________________________________________________________
		if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
		{
			PSCHEDULE_DGV.ROW.CLEAR();
			NEW_SCHEDULE_PREPARE_DGV_COLS_CLEAR();
			return;
		}
		
		
		// Populate DGV
		// _______________________________________________________________________
		HTTP_LOAD(JSON_OBJECT);
		
		
		// Color Coding (Uncomment to use)
		// _______________________________________________________________________	
		//PSCHEDULE_DGV.CELL.ELEMENT("COLUMN_NAME", ROW_INDEX).style.color = "#1cc88a"; // Safe
		//PSCHEDULE_DGV.CELL.ELEMENT("COLUMN_NAME", ROW_INDEX).style.color = "#5a5c69"; // Neutral
		//PSCHEDULE_DGV.CELL.ELEMENT("COLUMN_NAME", ROW_INDEX).style.color = "#f6c23e"; // Caution
		//PSCHEDULE_DGV.CELL.ELEMENT("COLUMN_NAME", ROW_INDEX).style.color = "#e74a3b"; // Warning
	};
	
	
	// ===============================================================
	// Request Search - PART.C
	// ===============================================================
	function HTTP_SEARCH_LIMITED_ROWS_CALLBACK(IS_SUCCESS, RESPONSE_STRING, ROW_INDEX)
	{
		// Disable Dialogs
		// _______________________________________________________________________
		CUS_SEND_DIALOG_TRY_DISMISS();
		
		// Validate
		// _______________________________________________________________________
		if(IS_SUCCESS === false)
		{
			console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
			return;
		}
		
		// Validate JSON Response
		// _______________________________________________________________________
		var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
		if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
		{
			console.error("REQUEST ERROR: \n" + RESPONSE_STRING);
			return;
		}
		
		// JSON Empty (Clears the DataGrodView)
		// _______________________________________________________________________
		if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
		{
			PSCHEDULE_DGV.ROW.CLEAR();
			return;
		}

		// Validate Row Count
		// _______________________________________________________________________	
		if(PSCHEDULE_DGV.ROW.COUNT() <= 0)
		{
			console.error("DataGridView has no rows to fill.");
			return;
		}
		JSVC_AV.VAR_VALIDATE_RANGE(ROW_INDEX, "ROW_INDEX", 0, PSCHEDULE_DGV.ROW.COUNT() - 1);
		
		// Populate DGV
		// _______________________________________________________________________
		PSCHEDULE_DGV.POPULATE_FROM_QUERY
		(
				JSON_OBJECT, 
				'',
				false,
				false,
				1,
				[2, 1],
				ROW_INDEX
		);
		
		
		// For Applying CFormat
		// _______________________________________________________________________	
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_AMOUNT_PRICE");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_AMOUNT_COST");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D01");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D02");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D03");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D04");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D05");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D06");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D07");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D08");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D09");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D10");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D11");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D12");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D13");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D14");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D15");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D16");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D17");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D18");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D19");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D20");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D21");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D22");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D23");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D24");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D25");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D26");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D27");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D28");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D29");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D30");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_D31");
		PSCHEDULE_DGV.COLUMN.CFORMAT("REC_PSCHEDULE_QTY_TOTAL");
		
	
		// For Applying DateTime Format
		// _______________________________________________________________________	
		if(PSCHEDULE_DGV.COLUMN.IS_EXISTS("REC_PSCHEDULE_DATE"))
		{
			PSCHEDULE_DGV.COLUMN.DATE_FORMAT("REC_PSCHEDULE_DATE", "MMM DD, YYYY");
		}


		// Auto-total tool
		// _______________________________________________________________________	
		if(PSCHEDULE_DGV.COLUMN.TOTAL_IS_READY())
		{
			PSCHEDULE_DGV.COLUMN.TOTAL_REFRESH();
		}
		
		
		// Color Coding (Uncomment to use)
		// _______________________________________________________________________	
		//PSCHEDULE_DGV.CELL.ELEMENT("COLUMN_NAME", ROW_INDEX).style.color = "#1cc88a"; // Safe
		//PSCHEDULE_DGV.CELL.ELEMENT("COLUMN_NAME", ROW_INDEX).style.color = "#5a5c69"; // Neutral
		//PSCHEDULE_DGV.CELL.ELEMENT("COLUMN_NAME", ROW_INDEX).style.color = "#f6c23e"; // Caution
		//PSCHEDULE_DGV.CELL.ELEMENT("COLUMN_NAME", ROW_INDEX).style.color = "#e74a3b"; // Warning
		//PSCHEDULE_DGV.CELL.ELEMENT("COLUMN_NAME", ROW_INDEX).style.color = "#dc3545"; // Danger
		//PSCHEDULE_DGV.CELL.ELEMENT("COLUMN_NAME", ROW_INDEX).style.color = "#17a2b8"; // Info
	};
	
				
	// ===============================================================
	// Begin Processing the Page
	// ===============================================================
	FORM_INITIALIZE();
	FORM_LOAD();