function cal(){
	n='calendar';
	c=xGetElementById(n);
	c.style.display='block';
	xLeft(n, xPageX('cbutton')+30);
	xTop(n, xPageY('cbutton')-xHeight(n)-40);
	xGetElementById('cform').dd.value='';
	c.innerHTML=createCal();
	xGetElementById('cform').dd.style.textAlign='left';
	return false;
	}

function createCal(y,m,d){
	str='';
	monthnames=new Array("Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь","Декабрь");
	monthnames1=new Array("января","февраля","марта","апреля","мая","июня","июля","авгуса","сентября","октября","ноября","декабря");
	linkdays=new Array();
	monthdays=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	if (y){
		todayDate=new Date(y,m,d);
		}else{
		todayDate=new Date();
		}
	thisday=todayDate.getDay();
	thismonth=todayDate.getMonth();
	thisdate=todayDate.getDate();
	thisyear=todayDate.getYear();
	thisyear=thisyear%100;
	thisyear=((thisyear<50)?(2000+thisyear):(1900+thisyear));
	if (((thisyear%4==0)&&!(thisyear%100==0))||(thisyear%400==0))monthdays[1]++;
	startspaces=thisdate;
	while (startspaces>7) startspaces-=7;
	startspaces=thisday-startspaces;
	if (startspaces<0) startspaces+=7;
	//alert(startspaces);
	str+="<table>";
	str+="<tr><td colspan=7 align=center>";
	if (y){
		str+="<a href=\"#\" onClick=\"c.innerHTML=createCal()\">&lt;</a>";
		}
	str+="&nbsp;&nbsp;<b>"+monthnames[thismonth]+" "+thisyear+"</b>&nbsp;&nbsp;";
	if (!y){
		str+="<a href=\"#\" onClick=\"c.innerHTML=createCal(thisyear,thismonth+1,1)\">&gt;</a>";
		}
	str+="</td></tr>";
	str+="<tr><td>Пн</td><td>Вт</td><td>Ср</td><td>Чт</td><td>Пт</td><td>Сб</td><td>Вс</td></tr>";
	str+="<tr>";
	for (s=0; s<startspaces; s++){
		str+="<td> </td>";
		}
	count=1;
	while (count<=monthdays[thismonth]){
		for (b=startspaces; b<7; b++){
			linktrue=false;
			str+="<td>";
			if (count>thisdate||y){
				str+="<a href=# onClick=\"xGetElementById('cform').dd.value='"+count+" "+monthnames1[thismonth]+"'; c.style.display='none'; return false;\">";
				}
			if (count==thisdate&&!y){
				str+="<font color='FF0000'><b>";
				}
			if (count<=monthdays[thismonth]){
				str+=count;
				}else{
				str+=" ";
				}
			if (count==thisdate&&!y){
				str+="</b></font>";
				}
			if (count>thisdate||y){
				str+="</a>";
				}
	str+="</td>";
	count++;
	}
	str+="</tr>";
	str+="<tr>";
	startspaces=0;
	}
	str+="</table>";
	return str;
	}