function OSField(input_el, lang_select_el, result_el) {
	var that = this;
	this.inputElement = input_el;
	this.langElement = lang_select_el;
	this.resultElement = result_el;
	this.timer = null;
	this.inputElement.addEventListener('focus', function() {
	    //document.getElementById('mainSearchFieldReset').style.display = "none";
		that.timer = setInterval(checkForUpdate, 300);
	}, false);
	this.inputElement.addEventListener('blur', function() {
	    //document.getElementById('mainSearchFieldReset').style.display = "";
		clearInterval(that.timer);
	}, false);
	this.langElement.addEventListener('change', function() {
		updateResults();
	}, false);
	this.checkForUpdate = checkForUpdate;
	var last_value = '';
	function updateResults() {
		var req = new Ajax.Request('opensearch.php', {
			method: 'POST',
			parameters: {l: that.langElement.value, q: (that.inputElement.value)},
			onSuccess: function(transport) {
				var response = transport.responseText || '';
				var result = response.evalJSON();
				var suggestions = result[1] || [];
				var html = [];
				var lang = document.getElementById('mainSearchLang').value;
				for (var i=0; i < suggestions.length; i++) {
					html.push(['<a href="ipodia.php?l=', lang, '&q=', encodeURIComponent(unescape(suggestions[i])),'"><li>', unescape(suggestions[i]), '</li>'].join(''));
				}
				that.resultElement.innerHTML = html.join('');
			},
			onFailure: function() {
				console.log('opensearch request error');
			}
		});
	};
	function checkForUpdate() {
	    if (that.inputElement.value === '') {
	        that.resultElement.style.display = 'none';
	    } else if (last_value !== that.inputElement.value) {
			last_value = that.inputElement.value;
			updateResults();
			that.resultElement.style.display = 'block';
		}
	}
};
