function over(x){
//	alert(app_img_path+x.name+"_.gif");
	document.images[x.name].src=app_img_path+x.name+"_.gif";
}
function out(x){
	document.images[x.name].src=app_img_path+x.name+".gif";
}
function over_app(x){
	document.images[x.name].src=app_img_path+x.name+"_.gif";
}
function out_app(x){
	document.images[x.name].src="i/p.gif";
}

function menu_over(x){
	document.images[x].src=app_img_path+"li_.gif";
}
function menu_out(x){
	document.images[x].src=app_img_path+"li.gif";
}
function from_array(x){
	x_out=0;
	for(k=0;k<empty_event[key_app][key_month].length;k++)
		if(empty_event[key_app][key_month][k]==x) {x_out=k; break}
	return x_out;
}

function closed_day(x){
	x_out=0;
	for(l=0;l<empty_event[key_app][key_month].length;l++)
		if(x<empty_event[key_app][key_month][l]) {x_out=l; break}
	return x_out;
}

// Выводит на экран меню выбора месяца римскими цифрами
function select_month(){
	if(key_app==1) suffix='_I';
	if(key_app==2) suffix='_II';
	name_of_month=new Array;
	name_of_month=["","january","february","march","april","may","june","july","august","september","october","november","december"];
	rus_month=new Array;
	rus_month=["","январь","февраль","март","апрель","май","июнь","июль","август","сентябрь","октябрь","ноябрь","декабрь"];
	set_event=" onMouseOver=\"over_app(this)\" onMouseOut=\"out_app(this)\"";
	space="<img border=0 alt=\"\" src=\"i/p.gif\" width=1 height=1><br>";
	
	document.write("<table border=0 cellPadding=0 cellSpacing=0 height=516 width=26 background=\""+app_img_path+"pic1_2.gif\"><tr height=516 valign=top><td width=26>");
	for(i=1;i<13;i++)
		if(name_of_month[i]==key_month)
			document.write(space+"<img border=0 alt=\"\" src=\""+app_img_path+i+"r_.gif\" width=26 height=42>");
		else
			document.write(space+"<a href=\""+name_of_month[i]+suffix+".html\"><img border=0 alt=\""+rus_month[i]+"\" src=\"i/p.gif\" width=26 height=42 "+set_event+" name="+i+"r></a>");

	document.write("</td></tr></table>");
}

//Последовательная смена месяцев
function change_month(){
	if(key_app==1) suffix='_I';
	if(key_app==2) suffix='_II';
	document.write("<img border=0 alt=\"\" src=\"i/p.gif\" width=1 height=11><br>");
	set_event=" onMouseOver=\"over(this)\" onMouseOut=\"out(this)\"";
	document.write("<a href=\""+months[key_month][1]+suffix+".html\"><img border=0 alt=\"\" src=\""+app_img_path+"m_left.gif\" name=\"m_left\" width=15 height=15"+set_event+"></a>");
	document.write("<img border=0 alt=\"\" src=\""+app_img_path+months[key_month][0]+".gif\" width=134 height=15>");
	document.write("<a href=\""+months[key_month][2]+suffix+".html\"><img border=0 alt=\"\" src=\""+app_img_path+"m_right.gif\" name=\"m_right\" width=15 height=15"+set_event+"></a>");
}

//Меню "домой" "печать" "закрыть"
function sys_menu(){
	set_event="onMouseOver=\"over(this)\" onMouseOut=\"out(this)\"";
	img_home="<a href=\"calendar.html\" alt=\"\"><img border=0 alt=\"в начало\" src=\""+app_img_path+"home.gif\" width=31 height=31 hspace=5 vspace=10 "+set_event+" name=home align=top></a>";
	img_print="<a href=\"\" alt=\"\"><img border=0 alt=\"печатать\" src=\""+app_img_path+"print.gif\" width=31 height=31 hspace=5 vspace=10 "+set_event+" name=print align=top></a>";
	img_close="<a href=\"javascript:window.close()\" alt=\"\"><img border=0 alt=\"закрыть\" src=\""+app_img_path+"close.gif\" width=31 height=31 hspace=5 vspace=10 "+set_event+" name=close align=top></a>";
	document.write(img_home+img_print+img_close+"<img border=0 alt=\"\" src=\"i/p.gif\" width=2 height=1>");
}
//Главное меню для перехода в основные приложения
function main_menu(){
	if(key_app==1) x_class='menu_mos';
	if(key_app==2) x_class='menu_jub';
	quad1="<td width=26><img border=0 alt=\"\" src=\""+app_img_path+"li.gif\" width=14 height=13 hspace=6 vspace=8 name=li1></td>";
	quad2="<td width=26><img border=0 alt=\"\" src=\""+app_img_path+"li.gif\" width=14 height=13 hspace=6 vspace=8 name=li2></td>";
	quad3="<td width=26><img border=0 alt=\"\" src=\""+app_img_path+"li.gif\" width=14 height=13 hspace=6 vspace=8 name=li3></td>";
	quad4="<td width=26><img border=0 alt=\"\" src=\""+app_img_path+"li.gif\" width=14 height=13 hspace=6 vspace=8 name=li4></td>";

	head_menu="<table border=0 align=center cellPadding=0 cellSpacing=0 height=29 width=578><tr height=29 valign=middle>";

	punkt1="<td width=95><a class="+x_class+" href=\""+key_month+".html\" alt=\"\" onMouseOver=\"menu_over('li1')\" onMouseOut=\"menu_out('li1')\">КАЛЕНДАРЬ</a></td>";

	if(key_app==1){
		quad2="<td width=26><img border=0 alt=\"\" src=\""+app_img_path+"li_.gif\" width=14 height=13 hspace=6 vspace=8 name=li2></td>";
		punkt2="<td width=316><span class="+x_class+">ПАМЯТНЫЕ ДАТЫ И ЮБИЛЯРЫ МОСКВЫ</span></td>";
	}else
		punkt2="<td width=208><a class="+x_class+" href=\""+key_month+"_I.html\" alt=\"\" onMouseOver=\"menu_over('li2')\" onMouseOut=\"menu_out('li2')\">ПАМЯТНЫЕ ДАТЫ МОСКВЫ</a></td>";
	if(key_app==2){
		quad3="<td width=26><img border=0 alt=\"\" src=\""+app_img_path+"li_.gif\" width=14 height=13 hspace=6 vspace=8 name=li3></td>";
		punkt3="<td width=84><span class="+x_class+">ЮБИЛЯРЫ</span></td>";
	}
	else
		punkt3="<td width=84><a class="+x_class+" href=\""+key_month+"_II.html\" alt=\"\" onMouseOver=\"menu_over('li3')\" onMouseOut=\"menu_out('li3')\">ЮБИЛЯРЫ</a></td>";

	punkt4="<td width=89><a class="+x_class+" href=\"ukaz.html\" alt=\"\" onMouseOver=\"menu_over('li4')\" onMouseOut=\"menu_out('li4')\">УКАЗАТЕЛИ</a></td>";

	foot_menu="</tr></table>";

	document.write(head_menu+quad1+punkt1+quad2+punkt2+quad4+punkt4+foot_menu);

}

//Формирует и выводит на экран календарь на заданный месяц
function show_calendar(x){
	td="";
	for(i=0;i<7;i++)
		td=td+"<td width=22><img border=0 src=\""+app_img_path+days[i]+".gif\" width=22 height=27></td>"
	tr="<tr height=27>"+td+"</tr>";

	set_event="onMouseOver=\"over(this)\" onMouseOut=\"out(this)\"";

	if(!from_array(x)) x=empty_event[key_app][key_month][closed_day(x)];
	for(i=0;i<42;i=i+7){
		td="";
		for(j=0;j<7;j++){
			if(full_months[i+j]=="")
				td+="<td width=22><img border=0 src=\"i/p.gif\" width=1 height=1></td>"
			else
				if(full_months[i+j]==x)
					td+="<td width=22><img border=0 src=\""+app_img_path+"day"+full_months[i+j]+"_.gif\" width=22 height=21></td>";
				else
					if(from_array(full_months[i+j]))
						td+="<td width=22><a href=\"javascript:goto_day("+full_months[i+j]+")\"><img border=0 src=\""+app_img_path+"day"+full_months[i+j]+".gif\" "+set_event+" name=\"day"+full_months[i+j]+"\" width=22 height=21></a></td>";
					else
						td+="<td width=22><img border=0 src=\""+app_img_path+"day"+full_months[i+j]+"e.gif\" width=22 height=21></td>"
		}
		tr+="<tr height=21>"+td+"</tr>";
	}
	ins_txt="<table border=0 align=center cellPadding=0 cellSpacing=0 height=153 width=154>"+tr+"</table>";

	document.all['calend'].innerHTML=ins_txt;
}

//Меню для последовательного переключения дней месяца
function insert_day(x,y){
	x1=Math.floor(x/10);	x2=x-x1*10;
	if(y=='b'){
		x_height=b_height;	x1_width=b_0_9[x1];	x2_width=b_0_9[x2];	v_space=0;
	}else{
		x_height=m_height;	x1_width=m_0_9[x1];	x2_width=m_0_9[x2];	v_space=12;
	}
	x_out="";
	if(x1!=0)
		x_out+="<img border=0 alt=\"\" src=\""+app_img_path+x1+y+".gif\" width="+x1_width+" height="+x_height+" vspace="+v_space+"><img border=0 alt=\"\" src=\"i/pw.gif\" width=4 height=10 vspace="+v_space+">";
	x_out+="<img border=0 alt=\"\" src=\""+app_img_path+x2+y+".gif\" width="+x2_width+" height="+x_height+" vspace="+v_space+">";
	return x_out;	
}
function change_day(x){
	set_event="onMouseOver=\"over(this)\" onMouseOut=\"out(this)\"";
	big_white="<img border=0 alt=\"\" src=\"i/pw.gif\" width=14 height=10>";
	xx=from_array(x);
	if(xx==0) xx=closed_day(x);
	if(xx==1){
		day_left="<img border=0 alt=\"\" src=\"i/p.gif\" width=1 height=1>";
		goto_left="<img border=0 alt=\"\" src=\"i/p.gif\" width=1 height=1>";
	}
	else {
		y=empty_event[key_app][key_month][xx-1];
		goto_left="<a href=\"javascript:goto_day("+y+")\" alt=\"\"><img border=0 alt=\"\" src=\""+app_img_path+"d_left.gif\" width=19 height=14 "+set_event+" vspace=12 hspace=15 name=d_left></a>";
		day_left=insert_day(y,'m');
	}
	if(xx==(empty_event[key_app][key_month].length-1)){
		day_right="<img border=0 alt=\"\" src=\"i/p.gif\" width=1 height=1>";
		goto_right="<img border=0 alt=\"\" src=\"i/p.gif\" width=1 height=1>";
	}
	else{
		y=empty_event[key_app][key_month][xx+1];
		goto_right="<a href=\"javascript:goto_day("+y+")\" alt=\"\"><img border=0 alt=\"\" src=\""+app_img_path+"d_right.gif\" width=19 height=14 "+set_event+" vspace=12 hspace=15 name=d_right></a>";
		day_right=insert_day(y,'m');
	}

	ins_txt="<table border=0 align=center cellPadding=0 cellSpacing=0 height=41 width=564><tr height=41 valign=bottom>";
	ins_txt+="<td width=39 align=left>"+day_left+"</td>";
	ins_txt+="<td width=49 align=left>"+goto_left+"</td>";
	ins_txt+="<td width=388 align=center>"+big_white+insert_day(empty_event[key_app][key_month][xx],'b')+big_white+"</td>";
	ins_txt+="<td width=49 align=right>"+goto_right+"</td>";
	ins_txt+="<td width=39 align=right>"+day_right+"</td>";
	ins_txt+="</tr></table>";
	document.all['days'].innerHTML=ins_txt;
}
//Выводит содержимое выбранного дня
function goto_day(x){
	show_calendar(x);
	change_day(x);
	content(x);
}
//Выводит содержимое календаря выбранного дня
function content(x){
	if(!from_array(x)) x=empty_event[key_app][key_month][closed_day(x)];
	ins_txt="<table border=0 align=center cellPadding=0 cellSpacing=0 height=100% width=564 background=\""+app_img_path+"pic10_1.gif\" class=back>";
	ins_txt+="<tr height=20 valign=top><td width=564><img border=0 alt=\"\" src=\"i/p.gif\" width=1 height=20></td></tr>";
	ins_txt+="<tr height=100% valign=top><td width=564>";
	if(key_app==1){
		if(key_month=='january') event_day_I=jan_I;
		if(key_month=='february') event_day_I=feb_I;
		if(key_month=='march') event_day_I=mar_I;
		if(key_month=='april') event_day_I=apr_I;
		if(key_month=='may') event_day_I=may_I;
		if(key_month=='june') event_day_I=jun_I;
		if(key_month=='july') event_day_I=jul_I;
		if(key_month=='august') event_day_I=aug_I;
		if(key_month=='september') event_day_I=sep_I;
		if(key_month=='october') event_day_I=oct_I;
		if(key_month=='november') event_day_I=nov_I;
		if(key_month=='december') event_day_I=dec_I;
		
		if(event_day_I[x][1][1]!=="")
			for(i=1;i<event_day_I[x].length;i++)
				ins_txt+=event_day_I[x][i][0]+event_day_I[x][i][1]+event_day_I[x][i][2]+"<br>";
		else ins_txt+="<img border=0 alt=\"\" src=\"i/p.gif\" width=1 height=26>";
	}
	if(key_app==2){
		if(key_month=='january') event_day_II=jan_II;
		if(key_month=='february') event_day_II=feb_II;
		if(key_month=='march') event_day_II=mar_II;
		if(key_month=='april') event_day_II=apr_II;
		if(key_month=='may') event_day_II=may_II;
		if(key_month=='june') event_day_II=jun_II;
		if(key_month=='july') event_day_II=jul_II;
		if(key_month=='august') event_day_II=aug_II;
		if(key_month=='september') event_day_II=sep_II;
		if(key_month=='october') event_day_II=oct_II;
		if(key_month=='november') event_day_II=nov_II;
		if(key_month=='december') event_day_II=dec_II;
		
		if(event_day_II[x][1][1]!=="")
			for(i=1;i<event_day_II[x].length;i++)
				ins_txt+=event_day_II[x][i][0]+event_day_II[x][i][1]+event_day_II[x][i][2]+"<br>";
		else ins_txt+="<img border=0 alt=\"\" src=\"i/p.gif\" width=1 height=26>";
	}
	ins_txt+="</td></tr></table><br>";

	document.all['text'].innerHTML=ins_txt;
}