
<div id="calendar_block_screen" class="calendar_block_screen" onclick="calendar_close();calendar_update_click()"></div>
<div id="menu_global_filter_block_screen" class="calendar_block_screen" onclick="menu_update_global_filters()"></div>
<div id="menu_bar" >
<!-------------------------------------- Календарь ------------------------------------------------>
	<%
	# Описание API календаря
	#
	# Для включения календаря необходимо в локальных перменных calendar_use изменить на 1 
	#
	# Для получения текущих выбранных дат:
	# Начало периода или единичный день - calendar_from_date (формат дата)
	# Конец периода - calendar_to_date (формат дата)
	#
	# Задать дату:
	# calendar_select_day(начало периода,конец периода) - формат js дата, если единичный день то начало периода = концу периода
	#
	# Действие при смене даты:
	# При добавлении в локальных перменных изменить calendar_action равное 0
	# И в окна добавить функцию calendar_update() внутри которой выполнять необходимые действия
	#
	#
	# Для первоначальной загрузки дат
	# В JS используйти массив calendar_user_date{"from" : начало периода, "to" : конец периода}, который необходимо добавить до загрузки календаря
	# В Ruby в локальных переменных добаить calendar_from_date и calendar_to_date формате "new Date(год,месяц(с 0),день)"
		
			@month_name_array=[{:id =>1, :name =>t(:calendar_jan), :shortname =>t(:calendar_jan_s), :form =>t(:calendar_jan_f)},
								{:id =>2, :name =>t(:calendar_feb), :shortname =>t(:calendar_feb_s), :form =>t(:calendar_feb_f)},
								{:id =>3, :name =>t(:calendar_mar), :shortname =>t(:calendar_mar_s), :form =>t(:calendar_mar_f)},
								{:id =>4, :name =>t(:calendar_apr), :shortname =>t(:calendar_apr_s), :form =>t(:calendar_apr_f)},
								{:id =>5, :name =>t(:calendar_may), :shortname =>t(:calendar_may_s), :form =>t(:calendar_may_f)},
								{:id =>6, :name =>t(:calendar_jun), :shortname =>t(:calendar_jun_s), :form =>t(:calendar_jun_f)},
								{:id =>7, :name =>t(:calendar_jul), :shortname =>t(:calendar_jul_s), :form =>t(:calendar_jul_f)},
								{:id =>8, :name =>t(:calendar_aug), :shortname =>t(:calendar_aug_s), :form =>t(:calendar_aug_f)},
								{:id =>9, :name =>t(:calendar_sep), :shortname =>t(:calendar_sep_s), :form =>t(:calendar_sep_f)},
								{:id =>10, :name =>t(:calendar_oct), :shortname =>t(:calendar_oct_s), :form =>t(:calendar_oct_f)},
								{:id =>11, :name =>t(:calendar_nov), :shortname =>t(:calendar_nov_s), :form =>t(:calendar_nov_f)},
								{:id =>12, :name =>t(:calendar_dec), :shortname =>t(:calendar_dec_s), :form =>t(:calendar_dec_f)}]	
	%>
<script>var calendar_month_names=<%= raw @month_name_array.to_json %> </script>
<% if calendar_use == 1 && defined?(@calendar_view_disable) == nil %>
	<div id="calendar_head" onclick="calendar_open()">
		<div id="calendar_head_container" >
			<div id="calendar_selected_date_full">
				<div id="calendar_head_from_date"></div>
				<div id="calendar_head_to_date" ></div>
			</div> 
			<div id="calendar_selected_date_short">
				<div id="calendar_head_from_date_short"></div>
				<div id="calendar_head_to_date_short" ></div>
			</div>
		</div>
		<%= image_tag( "shared/calendar.png", id: "calendar_head_image") %>
	</div>
	<div id="calendar_container">
		<div id="calendar_left_menu">
			<div id="calendar_today_button">
				<%= image_tag( "shared/today.png", id: "calendar_today_image", onclick: "calendar_back_for_today()") %>
				<div><%= t(:calendar_today) %></div>
			</div>
			<% if @calendar_select_interval == 2 %>
			<div class="calendar_predefined_periods" onclick="calendar_select_predefind_period(6)" style="top:80px"><%= t(:calendar_week) %></div>
			<div class="calendar_predefined_periods" onclick="calendar_select_predefind_period(13)" style="top:105px">2 <%= t(:calendar_week) %></div>
			<div class="calendar_predefined_periods" onclick="calendar_select_predefind_period(30)" style="top:130px"><%= t(:calendar_month) %></div>
			<div class="calendar_predefined_periods" onclick="calendar_select_predefind_period(90)" style="top:155px">3 <%= t(:calendar_month_s) %></div>
			<div class="calendar_predefined_periods" onclick="calendar_select_predefind_period(180)" style="top:180px">6 <%= t(:calendar_month_s) %></div>
			<div class="calendar_predefined_periods" onclick="calendar_select_predefind_period(365)" style="top:205px"><%= t(:calendar_year) %></div>
			<% end %>
			<% if calendar_action == 1 %>
			<div id="calendar_refresh_button">
				<%= image_tag( "shared/refresh_calendar.png", id: "calendar_refresh_image", onclick: "calendar_update();calendar_close()") %>
				<div><%= t(:update) %></div>
			</div>
			<% end %>
		</div>
		<div id="calendar_day_of_week_container">
						<div class="calendar_name_of_days" style="left:0px"><%= t(:calendar_mon) %></div>
						<div class="calendar_name_of_days" style="left:25px"><%= t(:calendar_tue) %></div>
						<div class="calendar_name_of_days" style="left:50px"><%= t(:calendar_wen) %></div>
						<div class="calendar_name_of_days" style="left:75px"><%= t(:calendar_thu) %></div>
						<div class="calendar_name_of_days" style="left:100px"><%= t(:calendar_fri) %></div>
						<div class="calendar_name_of_days" style="left:125px"><%= t(:calendar_sat) %></div>
						<div class="calendar_name_of_days" style="left:150px"><%= t(:calendar_sun) %></div>
		</div>
		<div onscroll="calendar_check_scroll()"  id="caledar_body_container"></div>
		<div id="caledar_body_container_scroll_separator"></div>
		<div id="calendar_period_body">
			<% date_pickers=[{:name => 'from', :bottom => '40', :ru => t(:calendar_from)},{:name => 'to', :bottom => '5', :ru => t(:calendar_to)}]%>
			<% date_pickers.each do |picker|%>
			<div style="width:220px;height:30px;position:absolute;left:15px;bottom:<%= picker[:bottom] %>px">
				<div class="text_m" style="width:40px;line-height:30px" align="right"><%= picker[:ru] %>:</div>
				<select id="calendar_picker_<%= picker[:name] %>_day" onchange="calendar_update_period_from_pickers()" size="1" style="position:absolute;left:40px;width:40px;top:3px;height:24px;font-size:14px" >
					<option class="calendar_picker_<%= picker[:name] %>_day_row_remove" value="1">1</option>
				</select>
				<select id="calendar_picker_<%= picker[:name] %>_month" onchange="calendar_<%= picker[:name] %>_picker_day_calc();calendar_update_period_from_pickers()" size="1" style="position:absolute;left:80px;width:80px;top:3px;height:24px;font-size:14px" >
					<% 	@month_name_array.each do |item| %>
							<option value="<%= item[:id] %>"><%= item[:name] %></option>
					<% 	end %>
				</select>
				<select id="calendar_picker_<%= picker[:name] %>_year" onchange="calendar_<%= picker[:name] %>_picker_day_calc();calendar_update_period_from_pickers()" size="1" style="position:absolute;left:160px;width:60px;top:3px;height:24px;font-size:14px" >
					<% 	year = 2015
						while year < DateTime.now.year+2  do %>
							<option value="<%= year %>"><%= year %> г.</option>
					<% 	year +=1
						end %>
				</select>
			</div>
			<% end %>
		</div>	
	</div>
	
	<script>
	
	function update_date(from_date,to_date){
		$.post('/sessions/update_user_dates', { from_date:from_date, to_date:to_date, user_id:<%=if session[:user_id] == nil;0;else;session[:user_id];end%>}, function() {
			console.log('Даты обновлены')
		})
	}
	
	
	var calendar_set_date=new Date()
	var calendar_top_month=''
	var calendar_bottom_month=''
	var calendar_check_click=1
	var calendar_first_date=''
	var calendar_second_date=''
	var calendar_from_date=''
	var calendar_to_date=''
	var calendar_open_check=0
	var calendar_date_chech=0
	$(document).ready(
		function() { 
			//$(body).niceScroll(scroll_settings);
			calendar_initial_setup()
			$("#caledar_body_container").niceScroll(scroll_settings);
			$(".settings_common_table_container").niceScroll(scroll_settings);
		}
	);
	function calendar_build_month_container(month,year){
		number_of_days=new Date(year,month+1,0).getDate();
		start_day=new Date(year,month,1).getDay();
		if (start_day == 0){start_day=7}
		bonus_height=''
		if ( (number_of_days == 30 && start_day == 7) || (number_of_days == 31 && start_day > 5) ){
			bonus_height="height:175px"
		}
		day_array='<div style="width:'+25*(start_day-1)+'px;height:25px;float:left"></div>'
		for (i=1;i<=number_of_days;i++){
			day_array+='<div id="calendar_day_id_'+i+'_'+month+'_'+year+'" onclick="calendar_day_click('+i+','+month+','+year+')" class="calendar_month_day" >'+i+'</div>'
		}
		month_name_container='<div class="calendar_month_name_container">'+
										'<div class="calendar_month_name_month" >'+calendar_month_names[month].name+'</div>'+
										'<div class="calendar_month_name_year">'+year+'</div>'+
									'</div>'
		month_day_container='<div class="calendar_month_day_container" >'+day_array+'</div>'
		month_container='<div id="calendar_month_id_'+month+'_'+year+'" class="calendar_month_container" style="'+bonus_height+'"  >'+month_name_container+month_day_container+'</div>'
		
		return month_container
	}
	function calendar_build_selected_month(from,to){
		from_month=parseInt(from.split('/')[0])
		from_year=parseInt(from.split('/')[1])
		to_month=parseInt(to.split('/')[0])
		to_year=parseInt(to.split('/')[1])
		if (new Date(from_year,from_month,1) > new Date(to_year,to_month,1)){
			to_month=parseInt(from.split('/')[0])
			to_year=parseInt(from.split('/')[1])
			from_month=parseInt(to.split('/')[0])
			from_year=parseInt(to.split('/')[1])
		}
		
		
		if (new Date(from_year,from_month,1) > new Date())
			{
				from_month=new Date().getMonth();
				from_year=new Date().getFullYear()
			}
		if (new Date(to_year,to_month,1) < new Date())
			{
				to_month=new Date().getMonth();
				to_year=new Date().getFullYear()
			}
		console.log(from_month,from_year,'sds',to_month,to_year)
		if (from == false){
			
			$(calendar_build_month_container(from_month,from_year)).appendTo('#caledar_body_container')
			calendar_append_month(from_month,from_year)
			calendar_prepend_month(from_month,from_year)
			
		}else{
			check=0
			build_month=from_month
			build_year=from_year
			while (check == 0){
				if (build_month+'/'+build_year ==  to_month+'/'+to_year ){
					check=1
				}
				$(calendar_build_month_container(build_month,build_year)).appendTo('#caledar_body_container')
				build_year= build_month+1 == 12 ? build_year+1 : build_year
				build_month= build_month+1 == 12 ? 0 : build_month+1
			}
			calendar_append_month(to_month,to_year)
			calendar_prepend_month(from_month,from_year)
		}
		document.getElementById('caledar_body_container').scrollTop=125
	}
	function calendar_prepend_month(month,year){
		year = (month - 1) < 0 ? (year - 1) : year
		month = (month - 1) < 0 ? 11 : (month - 1)
		$(calendar_build_month_container(month,year)).prependTo('#caledar_body_container')
		calendar_top_month=month+'/'+year
	}
	function calendar_append_month(month,year){
		year = (month + 1) > 11 ? (year + 1) : year
		month = (month + 1) > 11 ? 0 : (month + 1)
		$(calendar_build_month_container(month,year)).appendTo('#caledar_body_container')
		calendar_bottom_month=month+'/'+year
	}
	function calendar_check_scroll(){
		calendar_scroll_body=document.getElementById('caledar_body_container')
		
		if (calendar_scroll_body.scrollTop < 50){
			month=parseInt(calendar_top_month.split('/')[0])
			year=parseInt(calendar_top_month.split('/')[1])
			calendar_prepend_month(month,year)
			calendar_scroll_body.scrollTop=calendar_scroll_body.scrollTop+150
		}
		if ( ($('#caledar_body_container')[0].scrollHeight - calendar_scroll_body.scrollTop - 275) < 50){
			month=parseInt(calendar_bottom_month.split('/')[0])
			year=parseInt(calendar_bottom_month.split('/')[1])
			calendar_append_month(month,year)
		}
	}
	function calendar_unselect_all_days(){
		days=document.getElementsByClassName('calendar_month_day')
		for(i=0;i<days.length;i++){
			days[i].style.background=''
			days[i].style.color=''
			days[i].style.opacity=''
		}
	}
	function calendar_day_click(day,month,year){
		if (calendar_check_click == 1){
			calendar_select_first_day(day,month,year)
		}else{
			calendar_select_second_day(day,month,year)
		}
		<%
		 if defined?(@calendar_select_interval) == nil ; @calendar_select_interval = 1 ; end
		%>
		calendar_check_click=calendar_check_click == 1 ? <%= @calendar_select_interval %> : 1
		console.log('from - '+calendar_from_date+' | to - '+calendar_to_date)
		calendar_head_build_full_name()
		update_date(calendar_from_date,calendar_to_date)
	}
	function calendar_select_first_day(day,month,year){
		calendar_container=document.getElementById('calendar_container')
		calendar_first_date=day+'/'+month+'/'+year
		calendar_unselect_all_days()
		calendar_highlight_day(day,month,year,1)
		calendar_from_date=new Date(year,month,day)
		calendar_to_date=calendar_from_date
		calendar_container.style.height="300px"
		
	}
	function calendar_select_second_day(day,month,year){
		calendar_second_date=day+'/'+month+'/'+year
		calendar_container=document.getElementById('calendar_container')
		if (calendar_second_date !== calendar_first_date){
			calendar_highlight_day(day,month,year,1)
			calendar_select_period()
			calendar_container.style.height="370px"
		}else{
			calendar_check_click=1
			
		}
	}
	function calendar_highlight_day(day,month,year,opacity) {
			day=document.getElementById('calendar_day_id_'+day+'_'+month+'_'+year)
			day.style.background='<%= $blue %>'
			day.style.color='<%= $white %>'
			day.style.opacity=opacity
	}
	function calendar_select_period(){
		first_date=new Date(calendar_first_date.split('/')[2],calendar_first_date.split('/')[1],calendar_first_date.split('/')[0])
		second_date=new Date(calendar_second_date.split('/')[2],calendar_second_date.split('/')[1],calendar_second_date.split('/')[0])
		
		if (first_date < second_date){
			calendar_from_date=first_date
	 	  	calendar_to_date=second_date
		}else{
			calendar_from_date=second_date
	 	  	calendar_to_date=first_date
		}
		period_day=new Date(calendar_from_date)
		period_day.setDate(period_day.getDate() + 1)
		calendar_set_pickers(calendar_from_date,calendar_to_date)
		for (period_day;period_day < calendar_to_date;period_day.setDate(period_day.getDate() + 1)){
			calendar_highlight_day(period_day.getDate(),period_day.getMonth(),period_day.getFullYear(),0.7)
		}
		
	}
	function calendar_select_day(from_day,to_day){
		calendar_unselect_all_days()
		if (from_day == to_day){
			calendar_select_first_day(to_day.getDate(),to_day.getMonth(),to_day.getFullYear())
		}else{
			calendar_select_first_day(from_day.getDate(),from_day.getMonth(),from_day.getFullYear())
			calendar_select_second_day(to_day.getDate(),to_day.getMonth(),to_day.getFullYear())
		}
		document.getElementById('caledar_body_container').scrollTop=0
		document.getElementById('caledar_body_container').scrollTop=$('#calendar_month_id_'+to_day.getMonth()+'_'+to_day.getFullYear()).offset().top - 100
		calendar_head_build_full_name()
		update_date(calendar_from_date,calendar_to_date)
		
		
	}
	function calendar_back_for_today(){
		calendar_select_day(calendar_set_date,calendar_set_date)
		update_date(calendar_from_date,calendar_to_date)
	}
	function calendar_initial_setup(){
				
				<% if session[:user_id] != nil %>
					<% @user=User.find(session[:user_id]) %>	
					calendar_user_date={'from' : new Date('<%= @user[:from_date] %>'), 'to' : new Date('<%= @user[:to_date] %>')}	
				<% end %>
				<% if defined?(calendar_from_date) != nil &&  defined?(calendar_to_date) != nil%>
					calendar_user_date={'from' : <%= calendar_from_date %>, 'to' : <%= calendar_to_date %>}
				<% end %>
				if (typeof calendar_user_date == 'undefined'){
					from_day=calendar_set_date
					to_day=calendar_set_date
				}else{
					from_day=calendar_user_date.from
					to_day=calendar_user_date.to
				}
				if (<%= @calendar_select_interval %> == 1){from_day = to_day}
				calendar_build_selected_month(from_day.getMonth()+'/'+from_day.getFullYear(),to_day.getMonth()+'/'+to_day.getFullYear())
				calendar_select_day(from_day,to_day)
	}
	
	
	
	
	function calendar_head_build_full_name(){
		from_header=document.getElementById('calendar_head_from_date')
		to_header=document.getElementById('calendar_head_to_date')
		from_header_short=document.getElementById('calendar_head_from_date_short')
		to_header_short=document.getElementById('calendar_head_to_date_short')
		if (calendar_from_date == calendar_to_date){
			from_string=calendar_from_date.getDate()+' '+calendar_month_names[calendar_from_date.getMonth()].form+' '+calendar_from_date.getFullYear()
			from_header.innerHTML=from_string
			from_header.style.top='9px'
			to_header.style.top='38px'
			
			from_header_short.style.top='9px'
			to_header_short.style.top='38px'
			from_string_short=calendar_from_date.getDate()+' '+calendar_month_names[calendar_from_date.getMonth()].shortname
			from_header_short.innerHTML=from_string_short
			
			
		}else{
			from_string='<%=  t(:calendar_from) %> '+calendar_from_date.getDate()+' '+calendar_month_names[calendar_from_date.getMonth()].form+' '+calendar_from_date.getFullYear()
			to_string='<%=  t(:calendar_to) %> '+calendar_to_date.getDate()+' '+calendar_month_names[calendar_to_date.getMonth()].form+' '+calendar_to_date.getFullYear()
			
			from_header.innerHTML=from_string
			from_header.style.top='0px'
			
			to_header.innerHTML=to_string
			to_header.style.top='19px'
			
			
			
			from_header_short.style.top='0px'
			to_header_short.style.top='19px'
			from_string_short='<%=  t(:calendar_from) %> '+calendar_from_date.getDate()+' '+calendar_month_names[calendar_from_date.getMonth()].shortname
			to_string_short='<%=  t(:calendar_to) %> '+calendar_to_date.getDate()+' '+calendar_month_names[calendar_to_date.getMonth()].shortname
			from_header_short.innerHTML=from_string_short
			to_header_short.innerHTML=to_string_short
		}
	}
	function calendar_open(){
		if (calendar_open_check == 1){calendar_close();calendar_update_click();return 0}
		document.getElementById('calendar_container').style.left="0px"
		document.getElementById('calendar_block_screen').style.display='block'
		document.getElementById('calendar_selected_date_full').style.left="0px"
		document.getElementById('calendar_selected_date_short').style.left="-100px"
		document.getElementById('calendar_head_container').style.width="185px"
		calendar_open_check=1
	}
	function calendar_close(){
		document.getElementById('calendar_container').style.left="-252px"
		document.getElementById('calendar_block_screen').style.display='none'
		document.getElementById('calendar_selected_date_full').style.left="100px"
		document.getElementById('calendar_selected_date_short').style.left="0px"
		document.getElementById('calendar_head_container').style.width="100px"
		calendar_open_check=0
		
	}
	function calendar_set_pickers(start_date,end_date){
		document.getElementById('calendar_picker_from_year').value=start_date.getFullYear()
		document.getElementById('calendar_picker_to_year').value=end_date.getFullYear()
		
		document.getElementById('calendar_picker_from_month').value=start_date.getMonth()+1
		document.getElementById('calendar_picker_to_month').value=end_date.getMonth()+1
		
		calendar_from_picker_day_calc()
		calendar_to_picker_day_calc()
		
		document.getElementById('calendar_picker_from_day').value=start_date.getDate()
		document.getElementById('calendar_picker_to_day').value=end_date.getDate()
	}
	<% date_pickers.each do |picker|%>
	function calendar_<%= picker[:name] %>_picker_day_calc(){
		y=document.getElementById('calendar_picker_<%= picker[:name] %>_year').value
		m=document.getElementById('calendar_picker_<%= picker[:name] %>_month').value
		$('.calendar_picker_<%= picker[:name] %>_day_row_remove').remove();
		days=new Date(y, m, 0).getDate()
		x=1
		while (x < (days+1)){
			$('<option class="calendar_picker_<%= picker[:name] %>_day_row_remove" value="'+x+'">'+x+'</option>').appendTo($("#calendar_picker_<%= picker[:name] %>_day"));
			x++
		}
	}
	<% end %>
	function calendar_update_period_from_pickers(){
		f_day = document.getElementById('calendar_picker_from_day').value
		f_month = document.getElementById('calendar_picker_from_month').value-1
		f_year = document.getElementById('calendar_picker_from_year').value
		
		t_day = document.getElementById('calendar_picker_to_day').value
		t_month = document.getElementById('calendar_picker_to_month').value-1
		t_year = document.getElementById('calendar_picker_to_year').value
		
		$('.calendar_month_container').remove()
		calendar_build_selected_month(f_month+'/'+f_year,t_month+'/'+t_year)
		calendar_select_first_day(f_day,f_month,f_year)
		calendar_select_second_day(t_day,t_month,t_year)
		calendar_select_period()
		calendar_head_build_full_name()
	}	
	function calendar_select_predefind_period(days) {
		past=new Date(calendar_to_date)
		past.setDate(past.getDate() - days)
		$('.calendar_month_container').remove()
		calendar_build_selected_month(past.getMonth()+'/'+past.getFullYear(),calendar_to_date.getMonth()+'/'+calendar_to_date.getFullYear())
		calendar_select_day(past,calendar_to_date)
		calendar_update()
		calendar_close()
	}
	
	
	function calendar_update_click(){
		calendar_update()
	}
	
	</script>
<% end %>
<!-------------------------------------- Меню ------------------------------------------------>	
	<%
	if filter_use == 1
   	 	@filter=GlobalFilter.where(:user_id => session[:user_id]).first
   	 	@server_id= @filter.operation_server_id != nil ? @filter.operation_server_id  : 0
   	 	@source_id=@filter.operation_source_id != nil ? @filter.operation_source_id  : 0
	 	@custom_filter_id=@filter.custom_filter_id != nil ? @filter.custom_filter_id  : 0
    end
	%>
	<div id="menu_container" style="width:<%= 120*menu_structure.count + 320 %>px;">
		<div id="menu_bottom_border"></div>
		<% home_position = filter_use == 0 ? "left:0px" : '' %>
		<%= image_tag( "shared/home_db.png", id: "menu_home_button", onclick: "get_to_page('/common/index')", style: home_position ) %>
	<!-------------------------------- Фильтры начало -------------------------------->
		<% if filter_use == 1 %>
		<div id="menu_filter_container">
		
	   	 	<%= image_tag( "shared/filter.png", id: "menu_filter_button", onclick: "menu_show_global_filters()") %>
			<%
			@filter_count=0
			if @server_id > 0 ; @filter_count+=1 ; end
			if @source_id > 0 ; @filter_count+=1 ; end
			if @custom_filter_id > 0 ; @filter_count+=1 ; end
				
			
			%>
			<div id="menu_filters_count" style="width:14px;height:14px;position:absolute;bottom:0px;right:0px;background:<%= $blue %>;border-radius:7px;line-height:13px;color:white;font-size:12px;<% if @filter_count == 0 %>display:none<% end %>" align="center"><b><%= @filter_count %></b></div>
		</div>
		<table class="table_body" id="menu_global_filter_container" style="width:320px;top:-400px;background:white;left:0px;height:200px;border:1px solid gray;transition:0.4s">
			<tr>
				<td align="right"><%= t(:menu_filter_server_select) %>:</td>
				<td>
					<select size="1" id="menu_server_filter" style="width:140px">
						<option value="0"><%= t(:all) %></option>
						<% 	OperationServer.all.each do |item| %>
							<option value="<%= item[:id] %>" <%= if item[:id] == @server_id;'selected';end %> ><%= item[:name] %></option>
						<% 	end %>
					</select>
				</td>
			</tr>
			<tr>
				<td align="right"><%= t(:menu_filter_source_select) %>:</td>
				<td>
					<select size="1" id="menu_source_filter" style="width:140px">
						<option value="0"><%= t(:all) %></option>
						<% 	OperationSource.all.each do |item| %>
							<option value="<%= item[:id] %>" <%= if item[:id] == @source_id;'selected';end %> ><%= item[:name] %></option>
						<% 	end %>
					</select>
				</td>
			</tr>
			<tr>
				<td align="right"><%= t(:menu_filter_select) %>:</td>
				<td>
					<select size="1" id="menu_custom_filter" style="width:140px">
						<option value="0"><%= t(:none_s) %></option>
						<% 	CustomFilter.all.each do |item| %>
							<option value="<%= item[:id] %>" <%= if item[:id] == @custom_filter_id;'selected';end %> ><%= item[:name] %></option>
						<% 	end %>
					</select>
				</td>
			</tr>
			<tr>
				<td align="right"><div class="red_button" onclick="menu_close_global_filters()" style="position:relative;width:100px"><%= t(:cancel) %></div></td>
				<td align="left"><div class="button" onclick="menu_update_global_filters()" style="position:relative;width:100px"><%= t(:update) %></div></td>	
			</tr>
		</table>
		<% end %>
	<!-------------------------------- Фильтры конец -------------------------------->
		<% 
			i=0
			menu_structure.each do |item|
				count_menu=0
				item[:sub_menu].each do |sub_item|
					if sub_item[:visible] == 1
						count_menu=count_menu+1
					end
				end	
		%> 
				
				<div id="menu_<%= item[:name_eng] %>" class="menu_sub_button_container" onmouseover="menu_show_sub_menu('<%= item[:name_eng] %>')" onmouseout="menu_hide_sub_menu(<%= count_menu * -40 %>,'<%= item[:name_eng] %>')" style="left:<%= i*120 + 45 %>px;height:<%= count_menu * 40 %> px;top:<%= count_menu * -40 %>px;">
		<%		
				item[:sub_menu].each do |sub_item|
					if sub_item[:visible] == 1
		%>
						<div onclick="get_to_page('/<%= item[:name_eng] %>/<%= sub_item[:name_eng] %>')"  class="menu_sub_button"><%= sub_item[:name_rus] %></div>
		<%			end
				end
				
		%>
				</div>
			<%
			if i==0
				@border="border-left:1px solid #{$gray};width:119px"
			elsif i == menu_structure.count-1
				@border="border-right:1px solid #{$gray};width:119px"
			else
				@border=""
			end
			%>
			<div class="menu_button" onmouseover="menu_show_sub_menu('<%= item[:name_eng] %>')" onmouseout="menu_hide_sub_menu(<%= count_menu * -40 %>,'<%= item[:name_eng] %>')"  style="left:<%= i*120 + 45 %>px;<%= @border %>"><%= item[:name_rus] %></div>
		<% 
			i=i+1
			end 
		%>	
			<div id="menu_login_form" >
				<% if session[:user_id] != nil %>
					 <div id="menu_login_name_container">
						 <%= image_tag( "shared/user.png", id: "menu_login_icon") %>
						 <%= t(:user) %>:<br><b><%= User.find(session[:user_id]).username%></b>
					 </div>
					 <div id="menu_laguage_container">
					 	<%= image_tag( "language/ru.png", id: "menu_language_ru", onclick: "menu_change_language(0)") %>
						<%= image_tag( "language/en.png", id: "menu_language_en", onclick: "menu_change_language(1)") %>
					 </div>
					 <%= image_tag( "shared/exit_db.png", id: "menu_exit_button", onclick: "menu_logout()") %>
				<% end %>
			</div>	
	</div>
		
<script>

function menu_show_sub_menu(name){
	document.getElementById('menu_'+name).style.top='50px'
}

function menu_hide_sub_menu(position,name){
	document.getElementById('menu_'+name).style.top=position+'px'
}
function get_to_page(name){
		window.open(name,'_self');	
}
function get_to_page_with_parametr(name,param){	
	window.open(name+'?'+param,'_self');	
}
function menu_logout(){
	$.post('/sessions/logout', function(data) {
  	 	location.reload()
	})
}
function menu_change_language(lang_id){
	$.post('/sessions/change_language',{lang:lang_id}, function(data) {
  	 	location.reload(true)
	})
}

	<!-------------------------------- Фильтры начало -------------------------------->
		<% if filter_use == 1 %>

var menu_active_filters={}
function menu_show_global_filters(){
	if (document.getElementById('menu_global_filter_block_screen').style.display == 'block'){
		menu_close_global_filters()
		return true
	}
	menu_active_filters['server_id']=document.getElementById('menu_server_filter').value
	menu_active_filters['source_id']=document.getElementById('menu_source_filter').value
	document.getElementById('menu_global_filter_container').style.top='49px'
	document.getElementById('menu_global_filter_block_screen').style.display='block'
}
function menu_close_global_filters(){
	document.getElementById('menu_global_filter_container').style.top='-400px'
	document.getElementById('menu_global_filter_block_screen').style.display='none'
	menu_restore_global_filters()
}
function menu_update_global_filters(){
	document.getElementById('menu_global_filter_container').style.top='-400px'
	document.getElementById('menu_global_filter_block_screen').style.display='none'
	server_id=document.getElementById('menu_server_filter').value
	source_id=document.getElementById('menu_source_filter').value
	custom_filter_id=document.getElementById('menu_custom_filter').value
	
	check_filter= (server_id > 0 ? 1 : 0) + (source_id > 0 ? 1 : 0) + (custom_filter_id > 0 ? 1 : 0)
	if (check_filter > 0){
		document.getElementById('menu_filters_count').style.display=''
		document.getElementById('menu_filters_count').innerHTML='<b>'+check_filter+'</b>'
	}else{
		document.getElementById('menu_filters_count').style.display='none'
	}
	
	
	$.post('/sessions/update_global_filter', { server_id:server_id, source_id:source_id,
    custom_filter_id:custom_filter_id}, function() {
		<% if defined?(@calendar_view_disable) == nil %>
			calendar_update_click()
		<%else %> 
			location.reload(true)
		<% end %>
	})
}
function menu_restore_global_filters(){
	document.getElementById('menu_server_filter').value=menu_active_filters['server_id']
	document.getElementById('menu_source_filter').value=menu_active_filters['source_id']
}
		<% end %>
	<!-------------------------------- Фильтры конец -------------------------------->



</script>




</div>