Event.observe(window, 'load', function() {
	var suggestionRefTitleSearch = new SuggestionRefTitleSearch(
								'searchRefTitle',
								'referenceSearchForm',
								'refTitleSuggestion',
								'h3',
								'RefTitle Search Keyword Suggestion Result',
								'referenceSearchForm',
								'../images/suggestionLoading.gif',
								'../images/suggestionPrev.gif',
								'../images/suggestionNext.gif',
								'refTitleSearchSuggestionAction.do',
								'post');
});

var SuggestionRefTitleSearch = Class.create();
Object.extend(SuggestionRefTitleSearch.prototype, Suggestion.prototype);
Object.extend(SuggestionRefTitleSearch.prototype, {
	// パラメーターを作成します。 (オーバーライド)
	createParameter: function(inputString) {
		var param = new String;
		param += "&name=" + encodeURIComponent(inputString);

		var publicPrivate = $RF('referenceSearchForm', 'publicPrivate');
		if (publicPrivate) {
			param += "&publicPrivate=" + encodeURIComponent(publicPrivate);
		}
		var pmid = $F('searchPmid');
		param += "&pmid=" + encodeURIComponent(pmid);

		var author = $F('searchAuthor');
		param += "&author=" + encodeURIComponent(author);

		var journal = $F('searchJournal');
		param += "&journal=" + encodeURIComponent(journal);

		param += "&refTitle=" + encodeURIComponent(inputString);

		var yearPublished = $F('searchYearPublished');
		param += "&yearPublished=" + encodeURIComponent(yearPublished);

		var speciesId = $('searchSpeciesId');
		if (speciesId) {
			param += "&speciesId=" + encodeURIComponent($F(speciesId));
		}
		var resourceNames = $F('searchResourceNames');
		param += "&resourceNames=" + encodeURIComponent(resourceNames);

		return param;
	},

	// 候補キーワードリストの位置をブラウザごとに微調整を行います。 (オーバーライド)
	adjustSuggestion: function(left, top, width) {
		if (this.client.isWinOS && this.client.isIE) {
			left += 0; top -= 1; width -= 0;

		} else if (this.client.isWinOS && this.client.isFirefox) {
			left += 1; top -= 1; width -= 3;

		} else if (this.client.isWinOS && this.client.isSafari) {
			left += 4; top -= 0; width -= 3;

		} else if (this.client.isWinOS && this.client.isOpera) {
			left += 0; top -= 1; width -= 3;

		}  else if (this.client.isMacOS && this.client.isFirefox) {
			left += 1; top += 0; width -= 3;

		} else if (this.client.isMacOS && this.client.isSafari) {
			left += 4; top += 1; width -= 3;

		} else if (this.client.isLinuxOS && this.client.isFirefox) {
			left += 0; top -= 1; width -= 3;
		}

		return '{left: ' + left + ', top: ' + top + ', width: '+ width +'}';
	}
});

/**
* Returns the value of the selected radio button in the radio group, null if
* none are selected, and false if the button group doesn't exist
*
* @param {radio Object} or {radio id} el
* OR
* @param {form Object} or {form id} el
* @param {radio group name} radioGroup
*
* 例:
* var value = $RF('radio_btn_id');
* var value = $RF('form_id', 'radio_grp_name');
*/
// ラジオボタンの値を取得します。
function $RF(el, radioGroup) {
	if($(el).type && $(el).type.toLowerCase() == 'radio') {
		var radioGroup = $(el).name;
		var el = $(el).form;
	} else if ($(el).tagName.toLowerCase() != 'form') {
		return false;
	}

	var checked = $(el).getInputs('radio', radioGroup).find(
		function(re) {return re.checked;}
	);
	return (checked) ? $F(checked) : null;
}