function cal_selectDay(calid, td){
	var cal = $(calid);
	if(!cal) return;
	var tds = cal.getElementsByTagName('td');
	var day = td.getAttribute('day');
	if(day == '') return;
	for(var i in tds){
		if(tds[i].className){
			 tds[i].className = tds[i].className.replace('selected', '');
		}
	}
	td.className = td.className + ' selected';
	if(day < 10) day = '0'+day;
	cal.setAttribute('day', day);
	var hdn = $(calid+'_date');
	if(hdn){
		hdn.value = cal.getAttribute('day')+'.'+cal.getAttribute('month')+'.'+cal.getAttribute('year');
	}
	cal_onDaySelect(calid, day);
	cal_onChange(calid);
}
function cal_selectMonth(calid, td){
	var cal = $(calid);
	if(!cal) return;
	var month = td.getAttribute('month');
	if(month<10) month = '0'+month;
	cal.setAttribute('monthname', td.getAttribute('monthname'));
	cal.setAttribute('month', month);
	var hdn = $(calid+'_date');
	if(hdn){
		hdn.value = cal.getAttribute('day')+'.'+cal.getAttribute('month')+'.'+cal.getAttribute('year');
	}
	var month = {
		monthname: td.getAttribute('monthname'),
		monthshort: td.getAttribute('monthshort'),
		month: td.getAttribute('month')
	}
	cal_onMonthSelect(calid, month);
	cal_onChange(calid);
}
function cal_selectYear(calid, td){
	var cal = $(calid);
	if(!cal) return;
	
	var year = td.getAttribute('year');
	cal.setAttribute('year', year);
	var hdn = $(calid+'_date');
	if(hdn){
		hdn.value = cal.getAttribute('day')+'.'+cal.getAttribute('month')+'.'+cal.getAttribute('year');
	}
	cal_onYearSelect(calid, year);
	cal_onChange(calid);
}
function cal_show(calid, what){
	var cal = $(calid);
	if(!cal) return;
	if(!what) what = 'days';
	$(calid+'_days_sheet').style.display = 'none';
	$(calid+'_months_sheet').style.display = 'none';
	$(calid+'_years_sheet').style.display = 'none';
	$(calid+'_'+what+'_sheet').style.display = 'block';
}
