JSCUS_SQL = function(){};
JSCUS_SQL._ACCOUNT = function(){};
JSCUS_SQL._ADDON = function(){};
JSCUS_SQL._CATEGORY = function(){};
JSCUS_SQL._MOBILE = function(){};
JSCUS_SQL._RECORD = function(){};
JSCUS_SQL._SYSTEM = function(){};
JSCUS_SQL._SYSTEM._STATUS = function(){};

JSCUS_SQL._SYSTEM._STATUS.STATUS_INACTIVE = 1;
JSCUS_SQL._SYSTEM._STATUS.STATUS_ACTIVE = 2;
JSCUS_SQL._SYSTEM._STATUS.STATUS_CLOSE = 3;
JSCUS_SQL._SYSTEM._STATUS.STATUS_COMPLETE = 4;

JSCUS_SQL._ADD_FROM = function(MAP_ARRAY, ELEMENT_ID, PARAM_NAME)
{
	// Initialize
	// _______________________________________________________________________
	var CURRENT_TAG_NAME = "";
	var CURRENT_INPUT_TYPE = "";
	
	var DATETIME_FORMAT = "YYYY-MM-DD";
	var TIME_FORMAT = "";
	var INPUT_TYPE = 0;
	
	var FLAG_INTYPE_TEXT = 1;
	var FLAG_INTYPE_DATETIME = 2;
	var FLAG_INTYPE_DATETIME_FROM = 3;
	var FLAG_INTYPE_DATETIME_TO = 4;
	var FLAG_INTYPE_DATETIME_LOCAL = 5;
	var FLAG_INTYPE_COMBOBOX = 6;
	var FLAG_INTYPE_ORDER_BY = 999;
	
	// Abort if element does not exists
	// _______________________________________________________________________
	if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(ELEMENT_ID) == false)
	{
		return MAP_ARRAY;
	}
	ELEMENT_ID = JSOC_ELEMENT.VAR_GET(ELEMENT_ID);
			
	// Read Type
	// _______________________________________________________________________
	CURRENT_TAG_NAME = JSVC_STR.VAR_UCASE(ELEMENT_ID.tagName);
	if(CURRENT_TAG_NAME == 'INPUT')
	{
		CURRENT_INPUT_TYPE = JSVC_STR.VAR_UCASE(ELEMENT_ID.type);
	}
	
	// Identify Type
	// _______________________________________________________________________		
	if(PARAM_NAME == 'PARAM_ORDER_FIELD')
	{
		INPUT_TYPE = FLAG_INTYPE_ORDER_BY;
	}
	else if(CURRENT_TAG_NAME == "SELECT")
	{
		INPUT_TYPE = FLAG_INTYPE_COMBOBOX;
	}
	else if
	(
		CURRENT_INPUT_TYPE == "DATE" || 
		CURRENT_INPUT_TYPE == "DATETIME"
	)
	{
		if(JSVC_STR.VAR_CONTAINS(ELEMENT_ID.id, "_FROM_") && JSVC_STR.VAR_CONTAINS_RIGHT(PARAM_NAME, "_FROM"))
		{
			INPUT_TYPE = FLAG_INTYPE_DATETIME_FROM;
		}
		else
		{
			INPUT_TYPE = FLAG_INTYPE_DATETIME_TO;
		}
	}
	else if(CURRENT_INPUT_TYPE == "DATETIME-LOCAL")
	{
		INPUT_TYPE = FLAG_INTYPE_DATETIME_LOCAL;
	}
	else
	{
		INPUT_TYPE = FLAG_INTYPE_TEXT;
	}
			
	// Textbox Input
	// _______________________________________________________________________
	if
	(
		INPUT_TYPE == FLAG_INTYPE_TEXT &&
		JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE(ELEMENT_ID)) == false
	)
	{
		JSVC_MAP_ARRAY.VAR_SET(MAP_ARRAY, PARAM_NAME, JSOC_ELEMENT.VAR_VALUE(ELEMENT_ID));			
	}
	
	// DateTime Input
	// _______________________________________________________________________
	else if
	(
		INPUT_TYPE >= FLAG_INTYPE_DATETIME &&
		INPUT_TYPE <= FLAG_INTYPE_DATETIME_LOCAL &&
		JSOC_STYLE.VAR_IS_VISIBLE(ELEMENT_ID) == true &&
		JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE(ELEMENT_ID)) == false
	)
	{
		// Prepare Time Format
		// ...........................................	
		if(INPUT_TYPE == FLAG_INTYPE_DATETIME_FROM)
		{
			TIME_FORMAT = " 00:00:00.000000";
		}				
		else if(INPUT_TYPE == FLAG_INTYPE_DATETIME || INPUT_TYPE == FLAG_INTYPE_DATETIME_TO)
		{
			TIME_FORMAT = " 23:59:59.999999";
		}					
		else if(INPUT_TYPE == FLAG_INTYPE_DATETIME_LOCAL)
		{
			DATETIME_FORMAT = DATETIME_FORMAT + " HH:mm:ss";
			TIME_FORMAT = ".999999";
		}					
		
		// Apply Format
		// ...........................................	
		JSVC_MAP_ARRAY.VAR_SET
		(
			MAP_ARRAY, PARAM_NAME,
			JSVC_DATE.VAR_FORMAT(JSOC_ELEMENT.VAR_VALUE(ELEMENT_ID), DATETIME_FORMAT) + TIME_FORMAT
		);
	}
			
	// Combobox Input
	// _______________________________________________________________________
	else if(INPUT_TYPE == FLAG_INTYPE_COMBOBOX)
	{
		JSVC_MAP_ARRAY.VAR_SET
		(
			MAP_ARRAY, PARAM_NAME,
			JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(ELEMENT_ID))
		);
	}
	
	// Order By
	// _______________________________________________________________________
	else if(INPUT_TYPE == FLAG_INTYPE_ORDER_BY)
	{
		var SELECTED_VAL = JSOC_CMB.VAR_SELECTED_VALUE(ELEMENT_ID);
		if(JSVC_STR.VAR_CONTAINS_RIGHT(SELECTED_VAL, '_ASC'))
		{
			JSVC_MAP_ARRAY.VAR_SET(MAP_ARRAY, 'PARAM_ORDER_FIELD', JSVC_STR.VAR_DRIGHT(SELECTED_VAL, 4));
			JSVC_MAP_ARRAY.VAR_SET(MAP_ARRAY, 'PARAM_ORDER_TYPE', 'ASC');		
		}
		else
		{
			JSVC_MAP_ARRAY.VAR_SET(MAP_ARRAY, 'PARAM_ORDER_FIELD', SELECTED_VAL);
			JSVC_MAP_ARRAY.VAR_SET(MAP_ARRAY, 'PARAM_ORDER_TYPE', 'DESC');
		}
	}
	
	// Return Result
	// _______________________________________________________________________
	return MAP_ARRAY;	
};


/**
 * Validate value if legin autogen format when assigned by the user
 */
JSCUS_SQL.VAR_VERIFY_AUTO_NUMBER_10L = function(APPLY_CODE)
{
	if(JSVC_VAR.VAR_IS_ELEMENT(APPLY_CODE))
	{
		APPLY_CODE = JSOC_ELEMENT.VAR_VALUE(APPLY_CODE);
	}
	
	// ~~~~~
	
	if(JSVC_STR.VAR_IS_BLANK(APPLY_CODE))
	{
		return true;
	}
	
	// ~~~~~
	
	if(JSVC_NUM.VAR_NVALL(APPLY_CODE).toString().length != 10)
	{
		return false;
	}
	return true;
};