function sendStateCalendarRequest(year, month) {
	var catid = document.getElementById('mod-calendar-catid').value;
	var url = 'http://' + document.location.host + '/ru/modules/mod_calendar/calendar_table.php?catid='+catid+'&year='+year+'&month='+month+'&r='+Math.random();
	sendRequest(setStateCalendar, url, null, null, 'text/html; charset=utf-8');
}

function setStateCalendar() {
	document.getElementById('calendar-table').innerHTML = http_request.responseText;
}

function initCalendar(k) {
	var year = document.getElementById('calendar-year');
	var y = parseInt(year.options[year.selectedIndex].value);
	var y_max = parseInt(year.options[0].value);
	var y_min = parseInt(year.options[year.options.length-1].value);
	
	var month = document.getElementById('calendar-month');
	var m = parseInt(month.options[month.selectedIndex].value);
	
	if(k) {
		m+=parseInt(k);
		if(m < 1) {m = 12; y--;}
		if(m > 12) {m = 1; y++;}
		
		if(y<y_min || y>y_max) {
			return;
		}
		
		month.selectedIndex = m-1;
		for(var i=0; i<year.options.length; i++) {
			if(parseInt(year.options[i].value) == y) {
				year.options.selectedIndex = i;
			}
		}
	}
	sendStateCalendarRequest(y,m);
}

