var _____WB$wombat$assign$function_____ = function(name) {return (self._wb_wombat && self._wb_wombat.local_init && self._wb_wombat.local_init(name)) || self[name]; };
if (!self.__WB_pmw) { self.__WB_pmw = function(obj) { this.__WB_source = obj; return this; } }
{
  let window = _____WB$wombat$assign$function_____("window");
  let self = _____WB$wombat$assign$function_____("self");
  let document = _____WB$wombat$assign$function_____("document");
  let location = _____WB$wombat$assign$function_____("location");
  //let top = _____WB$wombat$assign$function_____("top");
  let parent = _____WB$wombat$assign$function_____("parent");
  let frames = _____WB$wombat$assign$function_____("frames");
  let opener = _____WB$wombat$assign$function_____("opener");

$(function(){
	
	function buildTableContent()
		{
			var tableContent='<div class="table-content-list-inner-wrapper"><table class="table-content-list">';
			
			for (var i = 0; i < letters.length; i++)
				{
					
					var sender = (letters[i].sender != '') ? 'от ' + letters[i].sender : '',
					
						tr = '<tr data-url="#letter' + letters[i].id +'"><td>' + sender + '</td><td><span class="tc-surname">' + letters[i].surname + '</span> ' + letters[i].name_patronymic + '</td></tr>';
					
					tableContent += tr;
				}
				
			tableContent += '</table></div>';
			
			return tableContent;
		}
	
	function buildContents()
		{
			var mobW = 600, 
			
				winW = $(window).outerWidth();
			
			var contents = '<div class="table-content-popup popup"><a class="close-popup" href="#"><img src="img/close_popup.png" /></a><header><h3>Оглавление</h3><p>В этом разделе вы можете найти адресатов и получателей писем с фронта</p></header><div class="popup-content-wrapper"><table class="table-content-head"><tr><th data-hname="sender" data-sort="1"><a class="sort-icon asc"></a><span>Отправитель</span></th><th data-hname="surname" data-sort="1"><a class="sort-icon asc"></a><span>Получатель</span></th></tr></table><div class="table-content-list-wrapper">' + buildTableContent()  + '</div><div class="close-btn-wrapper"><a class="close-btn" href="#">Закрыть</a></div></div></div>';
			
			$(contents).prependTo('body');
			
			if (winW > mobW)
				{
					$('.table-content-popup').show();
				}
						
			else
				{
					$('.table-content-popup').slideDown();
				}
				
			$('.table-content-list-inner-wrapper').mCustomScrollbar({
				theme:"my-theme",
				scrollbarPosition: "outside",
				autoHideScrollbar: true,
				scrollInertia: 0
			});
		}
		
	function updateTableContent()
		{
			$('.table-content-list-inner-wrapper').remove();
			
			$(buildTableContent()).appendTo('.table-content-list-wrapper');
			
			$('.table-content-list-inner-wrapper').mCustomScrollbar({
				theme:"my-theme",
				scrollbarPosition: "outside",
				autoHideScrollbar: true,
				scrollInertia: 0
			});
		}
		
	$('body').on('click', '.contents-link', function(e){

		e.preventDefault();
				
		$('.screen-overlay').show();
					
		buildContents();		

	});
	
	/********  Сортировка ***********/
	 
	 $('body').on('click', '.table-content-head th', function(){
		 
		 var hname = $(this).attr('data-hname');
		 
		 var sortData = parseInt($(this).attr('data-sort'));
		 
		  letters.sort(function (a, b) {
			 
			  if (a[hname] > b[hname]) {
				return sortData;
			  }
			  
			  if (a[hname] < b[hname]) {
				return -sortData;
			  }
			  // a должно быть равным b
			  return 0;
		  });
		  
		  sortData = -sortData;
		  
		  $('.table-content-head th').attr('data-sort', 1);
		  
		  $(this).attr('data-sort', sortData);
		  
		  var sortIcon = $(this).find('.sort-icon');
		 
			if (sortData == 1)
				 {
					 sortIcon.removeClass('asc').addClass('desc');
				 }
				 
			else
				{
					sortIcon.removeClass('desc').addClass('asc');
				}
		 
		  updateTableContent();
		 
	  });

});


}
/*
     FILE ARCHIVED ON 16:22:01 Jan 19, 2020 AND RETRIEVED FROM THE
     INTERNET ARCHIVE ON 10:33:45 Nov 16, 2024.
     JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE.

     ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.
     SECTION 108(a)(3)).
*/
/*
playback timings (ms):
  captures_list: 0.464
  exclusion.robots: 0.018
  exclusion.robots.policy: 0.008
  esindex: 0.01
  cdx.remote: 6.094
  LoadShardBlock: 52.603 (3)
  PetaboxLoader3.datanode: 66.675 (4)
  load_resource: 70.914
  PetaboxLoader3.resolve: 50.07
*/