﻿var nbg__my_bible__website__sidebar_c = function()
{
	this.verse_listener_o = false;
	this.translation_s = '';
};

/**/

nbg__my_bible__website__sidebar_c.prototype.setAjaxListener = function(state_i, status_i, content_s)
{
	if ((state_i == 4) && (status_i == 200))
	{
		var element_o = document.getElementById('sidebar_content');

		if (element_o)
		{
			element_o.innerHTML = content_s;

			if (typeof __ajax_constructor != 'undefined')
				__ajax_constructor();
		}
	}
};

nbg__my_bible__website__sidebar_c.prototype.setFeatureRequest = function(argument_o)
{
	var ajax_o = new ajax_c();

	ajax_o.setPath('/ENGINE/main.php');
	ajax_o.setArgument('object', 'nbg__my_bible__website__sidebar__feature__ajax_c');

	for (key_s in argument_o)
		ajax_o.setArgument(key_s, argument_o[key_s]);

	ajax_o.setType('POST');
	ajax_o.setListener(this, 'setAjaxListener');

	ajax_o.setRequest();
};

nbg__my_bible__website__sidebar_c.prototype.setFeatureSelect = function(feature_s)
{
	var select_o = document.getElementById('feature_select');

	if (select_o)
	{
		for (var i_i = 0; i_i < select_o.options.length; i_i++)
		{
			if (select_o.options[i_i].value == feature_s)
			{
				select_o.selectedIndex = i_i;
				break;
			}
		}
	}
};

/**/

nbg__my_bible__website__sidebar_c.prototype.setVerseListener = function(listener_o)
{
	this.verse_listener_o = (typeof listener_o.setVerse != 'undefined') ? listener_o : this.verse_listener_o;
};

nbg__my_bible__website__sidebar_c.prototype.setTranslation = function(translation_s)
{
	this.translation_s = translation_s;
};

nbg__my_bible__website__sidebar_c.prototype.setVerse = function(osis_id_s)
{
	if (this.verse_listener_o)
		this.verse_listener_o.setVerse(osis_id_s);
};

/**/

nbg__my_bible__website__sidebar_c.prototype.setFeatureBySelect = function(select_o)
{
	var feature_s = select_o.options[select_o.selectedIndex].value;

	this.setFeatureRequest({feature_code: feature_s, action_reset: true});
};

nbg__my_bible__website__sidebar_c.prototype.setFeatureByCode = function(code_s)
{
	this.setFeatureSelect(code_s);
	this.setFeatureRequest({feature_code: code_s, action_reset: true});
};

/**/

nbg__my_bible__website__sidebar_c.prototype.setSearchByForm = function(form_o)
{
	var query_s = form_o.normal_query.value;
		query_s = query_s.replace(/(^\s+)|(\s+$)/g, '');

	if (query_s.length > 3)
	{
		search_o.setSearchBusy();

		var argument_o = new Object();
			argument_o.feature_code = 'search';
			argument_o.action = 'normal';

		for (var i_i = 0; i_i < form_o.elements.length; i_i++)
			argument_o[form_o.elements[i_i].name] = form_o.elements[i_i].value;

		this.setFeatureRequest(argument_o);
	}
	else
	{
		window.alert('Uw zoekopdracht moet minimaal 4 letters bevatten.');
	}

	return false;
};

/**/

nbg__my_bible__website__sidebar_c.prototype.setLogOut = function()
{
	this.setFeatureRequest({feature_code: 'overview', action: 'log_out'});
};
