/************************************
	<id>M-DVD:TopicsFilter</id>
	<name>Topics Filter</name>
	<version>3.1</version>
	<type>modification</type>
*************************************/

function LettersPreload(sLetAll)
{
	return new Array (sLetAll, '#', '0-9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
}

function TopicsFilter(oOptions)
{
	this.opt = oOptions;
}

function TopicsFilterSelect(select_var)
{
	if (!select_var)
		return '';
	style = ('pages' == select_var[0]) ? ' style="float: left; margin: 2px 0" ' : ' style="margin: 2px 0" ';
	string = '						<select name="filter_' + select_var[0] + '"' + style + 'onchange="oTopicsFilter.go(this)">\n';
	string += '							<option value="" disabled="disabled"' + (select_var[1] == '0' ? ' selected="selected" style="font-weight: bold"' : '') + '>' + select_var[2] + '</option>\n';
	for (x in select_var[3])
		{
		string += '							<option value="' + x + '"' + (x == select_var[1] && x != '0' ? ' selected="selected"' : '') + (x == select_var[1] ? ' style="font-weight: bold"' : '') + '>' + select_var[3][x] + '</option>\n';
		}
	string += '						</select>\n';
	return string;
}

function TopicsSortbySelect(select_var)
{
	if (!select_var)
		return '';
	string = '						<select name="sort" style="float: left; margin: 2px 4px 2px 0" onchange="oTopicsFilter.go(this)">\n';
	string += '							<option value="" disabled="disabled" selected="selected" style="font-weight: bold">' + select_var[2] + '</option>\n';
	values = new Array('first_post', 'last_post', 'starter', 'last_poster', 'subject', 'replies', 'views');
	for (x in select_var[3])
		{
		string += '							<option value="' + values[x] + (values[x] + ';desc' == select_var[1] ? '' : ';desc') + '">' + select_var[3][x] + (values[x] + ';desc' == select_var[1] ? ' ↑' : ' ↓') + '</option>\n';
		}
	string += '						</select>\n';
	return string;
}

TopicsFilter.prototype.go = function (element)
{
	filterType = element.name;
	filterValue = filterType == "filter_reset" ? element.value : element.options[element.selectedIndex].value;
	sortValue =  filterType == "sort" || '' == this.opt.sSortby ? '' : this.opt.sSortby + ';';
	if (filterValue != "")
		location = smf_scripturl + '?board=' + this.opt.iBoardId + '.0;' + sortValue + filterType + '=' + filterValue;
}

TopicsFilter.prototype.load = function ()
{
	filterXHTML = '\n'
//         + '               <form id="TopicsFilter" name="TopicsFilter" action="" method="post">\n'
			+ TopicsSortbySelect(this.opt.aSortTopicsBy)
			+ TopicsFilterSelect(this.opt.aFilterPages)
			+ TopicsFilterSelect(this.opt.aFilterLetter)
			+ TopicsFilterSelect(this.opt.aFilterIcon)
			+ TopicsFilterSelect(this.opt.aFilterDate0)
			+ TopicsFilterSelect(this.opt.aFilterDate1)
			+ TopicsFilterSelect(this.opt.aFilterReplies)
			+ '						<input type="button" name="filter_reset" value="' + this.opt.sReset + '" onclick="oTopicsFilter.go(this);" />\n'
//         + '               </form>\n'
			+ '					';

	document.getElementById('filterTopics').innerHTML = filterXHTML;
	return false;
}