Liferay.JournalStructureValuesSelector = new Liferay.Class(
	{
		/**
		 * OPTIONS
		 *
		 * Required
		 * instanceVar {string}: The instance variable for this class.
		 * hiddenInput {string}: The hidden input used to pass in the current tag entries.
		 * textInput {string}: The text input for users to add tag entries.
		 */

		initialize: function(options) {
			var instance = this;

			instance.options = options;

			var textInput = jQuery('#' + options.textInput);

			textInput.autocomplete(
				{
					source: instance._getStructureValues,
					width: textInput.width() + 20,
					formatItem: function(row, i, max, term) {
						return row;
					},
					dataType: 'json',
					delay: 0,
					multiple: false,
					minChars: 1,
					hide: function(event, ui) {
						jQuery(this).removeClass('showing-list');
					},
					show: function(event, ui) {
						jQuery(this).addClass('showing-list');
						this._LFR_listShowing = true;
					},
					result: function(event, ui) {
						var caretPos = this.value.length;

						if (this.createTextRange) {
							var textRange = this.createTextRange();

							textRange.moveStart('character', caretPos);
							textRange.select();
						}
						else if (this.selectionStart) {
							this.selectionStart = caretPos;
							this.selectionEnd = caretPos;
						}
					}
				}
			);

			if (options.focus) {
				textInput.focus();
			}

			Liferay.Util.actsAsAspect(window);
		},

		_getStructureValues: function(term) {
			var instance = this;

			var beginning = 0;
			var end = 30;

			hiddenInput = 'kutya-kepesiteset-igazolo-tanusitvany-szama';
			
			var data = Liferay.Service.Journal.JournalArticle.searchST(
				{
					companyId: themeDisplay.getCompanyId(),
					groupId: themeDisplay.getScopeGroupId(),
					locale: themeDisplay.getLanguageId(),
					name: hiddenInput,
					value: term,
					begin: beginning,
					end: end
				}
			);

			return jQuery.map(
				data,
				function(row) {
					return {
						data: row.text,
						value: row.value,
						result: row.text
					}
				}
			);
		},
	}
);