/** * Скрипт для фильтра топиков */
var Day;var Month;var MinYear = 2005;var curYear;
var Year;var DaysArr = new Array(	31,28,31,30,31,30,31,31,30,31,30,31);
var Filter_sort = 'p';var Filter_rating = 'all';var Filter_type = 'all';
function getCurDay() {	var lsToday = new Date();	this.curYear = lsToday.getFullYear();
	if(this.setFilterDay !== undefined) {		this.Day = this.setFilterDay;	} else {		this.Day = lsToday.getDate();	}	if(this.setFilterMonth !== undefined) {		this.Month = this.setFilterMonth - 1;	} else {		this.Month = lsToday.getMonth();	}	if(this.setFilterYear !== undefined) {		this.Year = this.setFilterYear;	} else {		this.Year = this.curYear;	}	if(this.setFilterSort !== undefined) {		$('filter_sort_value').value = this.setFilterSort;		this.Filter_sort = this.setFilterSort;	}	if(this.setFilterRating !== undefined) {		$('filter_rating_value').value = this.setFilterRating;		this.Filter_rating = this.setFilterRating;	}	if(this.setFilterType !== undefined) {		$('filter_type_value').value = this.setFilterType;		this.Filter_type = this.setFilterType;	}
	this.setDate();
	$('filter_month_prev').addEvent('click', function(event){		changeDate('m','-1');
	});
	$('filter_month_next').addEvent('click', function(event){		changeDate('m','1');
	});
	$('filter_year_prev').addEvent('click', function(event){		changeDate('y','-1');	});
	$('filter_year_next').addEvent('click', function(event){		changeDate('y','1');	});
	$('filter_sort_value').addEvent('change', function(event){		changeSort();	});
	$('filter_rating_value').addEvent('change', function(event){		changeRating();	});
	$('filter_type_value').addEvent('change', function(event){		changeType();	});

}
function buttonClick() {	document.location = DIR_WEB_ROOT + '/filter/' + this.Year + '-' + (this.Month+1) +(this.setFilterDay !== undefined ? '-' + this.Day : '') + '/' + this.Filter_sort + '/' + this.Filter_rating + '/' + this.Filter_type;
}

/** * Установка дней в феврале в зависимости от високосности года */function setFebDays() {	if(this.Year % 4 == 0) {		this.DaysArr[1] = 29;	} else {		this.DaysArr[1] = 28;	}}
function setDate() {	month_value = '<a href="' + DIR_WEB_ROOT + '/filter/' + this.Year + '-' + (this.Month+1) + '/' + this.Filter_sort + '/' + this.Filter_rating + '/' + this.Filter_type + '">' + this.MonthArr[this.Month] + '</a>';	$('filter_month_value').innerHTML = month_value;	$('filter_year_value').innerHTML = this.Year;	this.setFebDays();	this.setDays();}
function setDays() {	DaysNum = this.DaysArr[this.Month] + 1;	result = '';	for (var i=1;i<DaysNum; i++) {		result += '<a href="' + DIR_WEB_ROOT + '/filter/' + this.Year + '-' + (this.Month+1) + '-' + i + '/' + this.Filter_sort + '/' + this.Filter_rating + '/' + this.Filter_type + '"' + ((this.setFilterDay !== undefined && i == this.Day) ? ' class="active"' : '') +'>' + i + '</a>';	}	$('filter_days').innerHTML = result;}
function changeDate(type,value) {	switch (type) {		case 'y':			if(value < 0 && this.Year > this.MinYear) {				this.Year--;			} else if (value > 0 && this.Year < this.curYear) {				this.Year++;			}			break;		case 'm':			if(value < 0) {				this.Month--;				if(this.Month < 0) {					this.Month = 11;				}			} else {				this.Month++;				if(this.Month > 11) {					this.Month = 0;				}			}			break;	}	this.setDate();	if (this.Year == this.curYear) {		$('filter_year_next').removeClass('active');		$('filter_year_next').addClass('default');	} else {		$('filter_year_next').removeClass('default');		$('filter_year_next').addClass('active');	}	if (this.Year == this.MinYear) {		$('filter_year_prev').removeClass('active');		$('filter_year_prev').addClass('default');	} else {		$('filter_year_prev').removeClass('default');		$('filter_year_prev').addClass('active');	}}

function changeSort() {	this.Filter_sort = $('filter_sort_value').value;	this.setDate();}
function changeRating() {	this.Filter_rating = $('filter_rating_value').value;	this.setDate();}
function changeType() {	this.Filter_type = $('filter_type_value').value;	this.setDate();}
getCurDay();
