function lmOver(id){
	if(document.getElementById('lm_ul_'+id).style.display!='block')
		document.getElementById('lm_li_'+id).className='act';
}
function lmOut(id){
	if(document.getElementById('lm_ul_'+id).style.display!='block')
		document.getElementById('lm_li_'+id).className='el';
}
function lmClick(id){
	if(document.getElementById('lm_ul_'+id).style.display!='block'){
		var str=document.getElementById('lm_ul_'+id).innerHTML;
		str=str.replace(/^\s*(\S.*$|$)/,"$1");
		str=str.replace(/(^|^.*\S)\s*$/,"$1");
		if(str){
			document.getElementById('lm_li_'+id).className='act';
			document.getElementById('lm_img_'+id).src='sait/images/icon_minus.gif';
			document.getElementById('lm_ul_'+id).style.display='block';
		}
	}else{
		document.getElementById('lm_li_'+id).className='el';
		document.getElementById('lm_img_'+id).src='sait/images/icon_plus.gif';
		document.getElementById('lm_ul_'+id).style.display='none';
	}
}
function getSchedule(){
	var c=document.getElementById('online_cabinet').value;
	var d=document.getElementById('online_date').value;
	window.frames['online_frame'].location.href='index.php?m_code=st_block&online=1&cabinet='+c+'&date='+d;
}
function setSchedule(s){
	document.getElementById('online_schedule').innerHTML=s;
}
function ajaxMessage(code,num,img,hash){
	for(var i=0; i<document.getElementById(code+'_hide').childNodes.length; i++)
		if(document.getElementById(code+'_hide').childNodes[i].nodeName=='DIV')
			document.getElementById(code+'_hide').childNodes[i].style.display='none';
	if(num){
		document.getElementById(code+'_message_'+num).style.display='block';
		document.getElementById(code+'_hide').style.display='block';
		if(num==1)
		document.forms[code+'_form'].reset();
	}
	if(img&&hash){
		document.getElementById(code+'_code_img').src=img;
		document.getElementById(code+'_hash').value=hash;
	}
}
// показать объект в определенной позиции
function cmShow(name,l,t){
	name=name.toString();
	if(document.getElementById(name)&&document.getElementById(name).style){
		if(!document.getElementById(name).style.left)
			document.getElementById(name).style.left=l;
		if(!document.getElementById(name).style.top)
			document.getElementById(name).style.top=t;
		document.getElementById(name).style.display="block";
	}
}
// спрятать объект
function cmHide(name){
	if(document.getElementById(name)&&document.getElementById(name).style)
		document.getElementById(name).style.display="none";
}
// окно выбора даты/времени
function frmOpenDatePopup(code,y,m,d){
	var _date,curdate;
	if((y%4==3)&&m==2&&d==29) d=28; // 29 февраля заменяем на 28 если надо
	if(!y&&!m&&!d&&document.getElementById(code).value){
		_date=document.getElementById(code).value.split(".");
		y=_date[0],m=_date[1],d=_date[2];
	}
	if(y||m||d) curdate=new Date(y,m-1,d);
	else curdate=new Date();

	y=curdate.getFullYear();
	m=curdate.getMonth();
	d=curdate.getDate();
	var curmonth=new Date(y,m,1);
	var wd=curmonth.getDay(); if(!wd) wd=7;
	var dayCount;
	if(m==0||m==2||m==4||m==6||m==7||m==9||m==11) dayCount=31;
	else if(m==1&&(y%4==3)) dayCount=28;
	else if(m==1) dayCount=29;
	else dayCount=30;
	var lastY=y,lastM=m-1;
	var nextY=y,nextM=m+1;
	if(m==0){ lastY=y-1; lastM=11; }
	if(m==11){ nextY=y+1; nextM=0; }
	var content="";
	var i=0,k=1;

	content+="<table border='0' onselectstart=\"return false;\"><tr>";
	content+="<td colspan='3'><table border='0'>";
	// заголовок
	content+="<tr>";
	content+="<th onclick=\"frmDateChange('"+code+"','"+(y-1)+"','"+(m+1)+"','"+d+"');\">&laquo;</th>";
	content+="<th onclick=\"frmDateChange('"+code+"','"+lastY+"','"+(lastM+1)+"','"+d+"');\">&larr;</th>";
	content+="<th colspan='3'>"+frmMonths[m]+"<br>"+y+"</th>";
	content+="<th onclick=\"frmDateChange('"+code+"','"+nextY+"','"+(nextM+1)+"','"+d+"');\">&rarr;</th>";
	content+="<th onclick=\"frmDateChange('"+code+"','"+(y+1)+"','"+(m+1)+"','"+d+"');\">&raquo;</th>";
	content+="</tr>";
	// дни недели &larr; mes
	content+="<tr><th>Пн</th><th>Вт</th><th>Ср</th><th>Чт</th><th>Пт</th><th>Сб</th><th>Вс</th></tr>";
	// контент
	content+="<tr>";
	while(k<=dayCount||(i%7)!=0){
		if(i&&(i%7)==0&&k<=dayCount)
		content+="</tr><tr>";
		if((i+1)>=wd&&k<=dayCount){
			if(k==d) content+="<th onclick=\"frmSetDate('"+y+"."+(m+1)+"."+k+"','"+code+"'); frmCloseDatePopup('"+code+"');\">"+k+"</th>";
			else content+="<td onclick=\"frmSetDate('"+y+"."+(m+1)+"."+k+"','"+code+"'); frmCloseDatePopup('"+code+"');\">"+k+"</td>";
			k++;
		}else{
			content+="<td>&nbsp;</td>";
		}
		i++;
	}
	// закрыть
	content+="</tr></table></td>";
	content+="</tr><tr>";
	content+="<th width='50%' align='right' onclick=\"frmSetDate('"+y+"."+(m+1)+"."+d+"','"+code+"'); frmCloseDatePopup('"+code+"');\">Установить&nbsp;</th>";
	content+="<th>|</th>";
	content+="<th width='50%' align='left' onclick=\"frmCloseDatePopup('"+code+"');\">&nbsp;Закрыть</th>";
	content+="</tr></table>";
	// вывод
	var dateName="date_"+code;
	cmShow(dateName,'0px','25px');
	document.getElementById(dateName).innerHTML=content;
	event.returnValue=false;
}
// закрытие окна выбора даты
function frmCloseDatePopup(code){
	var dateName="date_"+code;
	cmHide(dateName);
}
// месяцы
var frmMonths=new Array("Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь","Декабрь");
// установка даты/времени
function frmSetDate(d,code){
	document.getElementById(code).value=d;
	getSchedule();
}
// изменение даты
function frmDateChange(code,y,m,d){
	frmOpenDatePopup(code,y,m,d);
}