<script type="text/javascript">
   //<![CDATA[
	$(document).ready(function() {				
		var height = document.documentElement.clientHeight - 230; 		
 		$("#ylog").flexigrid({
	 		url: "/ViewLog_p.json",
			dataType: 'json',
	 		method: 'GET',
	 		colModel: [	
				{display: 'Level', name : 'icon', width : 25, sortable : true, align: 'center'},
				{display: 'Date', name : 'date', width : 75, sortable : true, align: 'left'},
				{display: 'Type', name : 'type', width : 125, sortable : true, align: 'left'},
				{display: 'Server Log', name : 'logline', width : 700, sortable : true, align: 'left'}
			],											
			hideOnSubmit: false,
			striped: true,
			nowrap: false,			 									    				
	 		height: height,
	 		autoload: true,
	 		useRp: true,
			rp: 50,
			usepager: false,
			rpOptions: [50,100,200,300,400],
			searchitems : [
				{display: 'Filter RegExp', name : 'filter'}
			],
			query: '.*.*',	 		
	 		buttons: [
				{name: '50', bclass: 'log-new', onpress: filter},
				{name: '200', bclass: 'log-more', onpress: filter},
				{name: '400', bclass: 'log-more', onpress: filter},
				{separator: true},
				{name: 'Debug', bclass: 'log-debug', onpress: filter},
				{name: 'Info', bclass: 'log-info', onpress: filter},
				{name: 'System', bclass: 'log-system', onpress: filter},						
				{name: 'Warning', bclass: 'log-warning', onpress: filter},
				{name: 'Error', bclass: 'log-error', onpress: filter},
				{separator: true},
				{name: 'Help', bclass: 'help', onpress: function() {}},						
			],	 		
	 		preProcess: function(data) {
		   		var clientname = data.clientname;  		
		   		var lines = data.line;
			   	var maxlines = data.maxlines;
			   	var reverse = data.reverse;		   	
				var rows = {};
				var counter = 0;			   	
			   	$.each (
					data.loglines,
					function(i,item) {	
						if (item) {
							var icon = "";
							if (item.loglevel == "Debug") icon = "<img style='margin-top: 8px;' src='img-2/magnify.png' alt='Debug' title='Debug'/>";
							 else if (item.loglevel == "Info") icon = "<img style='margin-top: 8px;' src='img-2/info.png' alt='Info' title='Info'/>";
							 else if (item.loglevel == "System") icon = "<img style='margin-top: 8px;' src='img-2/accept_green.png' alt='System' title='System'/>";
							 else if (item.loglevel == "Warning") icon = "<img style='margin-top: 8px;' src='img/blacklist.png' alt='Warning' title='Warning'/>";
							 else if (item.loglevel == "Error") icon = "<img style='margin-top: 8px;' src='img-2/stop.png' alt='Error' title='Error'/>";					
							var date = item.logline.substring(2,21);
							var type = item.logline.substring(22,40).split(' ');
							var log = item.logline.substring(22+type[0].length);							 
							rows[i] = {id: i, cell: [icon, date, type[0], log]};
							counter++;																						
						}								
					}
				);								
				counter--;
				this.pagestat = "Displaying "+counter+" matching log lines of "+this.rp+" parsed log lines";
				var pdata = {
					page: 1,
					total: lines,
					rows: rows							
				};
				$('#ylog tbody').empty();
				return pdata;		 				
	 		},	 		
	 		onSubmit: function() {
				$('#ylog').empty();
				$('#ylog').append("<div class='yloading'><h3 class='linktitle'><em>Loading Server Log...</em><br/><img src='/yacy/ui/img/loading2.gif' align='absmiddle'/></h3></div>");	 			

				var p = this;
	 			var g = $("#ylog");	 							

				$('.pPageStat',this.pDiv).html(p.procmsg);
				$('.pReload',this.pDiv).addClass('loading');
				if (g.bDiv) $(g.block).css({top:g.bDiv.offsetTop});
				if (p.hideOnSubmit) $(this.gDiv).prepend(g.block); //$(t).hide();
				// if ($.browser.opera) $(t).css('visibility','hidden');				
				if (!p.newp) p.newp = 1;				
				if (p.page>p.pages) p.page = p.pages;					
				
				var param = [
					 { name : 'lines', value : p.rp }
					,{ name : 'json', value : "true" }
					,{ name : 'filter', value : p.query }		
					,{ name : 'reverse', value : "true"}
				];						 
				if (p.params) {
					for (var pi = 0; pi < p.params.length; pi++) param[param.length] = p.params[pi];
				}				
				$.getJSON(p.url, param,
			        function(json, status){			        	
						g.flexAddData(json);
			        }
			    );				
	 		}								    				
 		});
	});
	function filter(com) {
		var f = ".*.*";
		var rp = 400;
		if(com == "50") { f=".*.*"; rp = 50; };
		if(com == "200") { f=".*.*"; rp = 200; };
		if(com == "400") { f=".*.*"; rp = 400; };
		if(com == "Debug") f="^D.*";
		if(com == "Info") f="^I.*";
		if(com == "System") f="^S.*";
		if(com == "Warning") f="^W.*";
		if(com == "Error") f="^E.*";		
		$('#ylog').flexOptions({
			query: f,
			qtype: "filter",
			rp: rp
		});
		$('#ylog').flexReload();	
	}	
  //]]>
</script>		
<!-- Flexigrid -->	
<table id="ylog">
	<tbody></tbody>
</table>