<%
include("language.html")
if _SESSION["logined"] ~= nil then
%>
<%
local filterStr = _GET["filter"]
if filterStr == nil then
	filterStr = ""
end
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Domain Log</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<%if _COOKIE["admin_lang"] == "schinese" or _COOKIE["admin_lang"] == "tchinese" or _COOKIE["admin_lang"] == "japanese" then%>
body,td,span {font:12px/20px Verdana, Geneva, Arial, Helvetica, sans-serif;}
<%else%>
body,td,span {font:11px/20px Verdana, Geneva, Arial, Helvetica, sans-serif;}
<%end%>
img {border:0px;}

button{
border:none;background:none;padding:0;
margin:0;width:auto;overflow:visible;text-align:center;
white-space:nowrap;height:24px;line-height:24px;
cursor:pointer;
color:#000;
margin-left:2px;
margin-top:2px;
}
button span, button em{
display:block;height:24px;line-height:22px;margin:0;
}	
button span{
font-size:8pt;
padding-left:12px;
background:url("images/button_left.gif") no-repeat 0 0;
}
<%if _COOKIE["admin_lang"] == "schinese" or _COOKIE["admin_lang"] == "tchinese" or _COOKIE["admin_lang"] == "japanese" then%>
button em{
font-style:normal;padding-right:14px;
background:url("images/button.gif") no-repeat 101% 0;
}
<%else%>
button em{
font-style:normal;padding-right:10px;
background:url("images/button.gif") no-repeat 100% 0;
}
<%end%>
button:hover{
filter:alpha(opacity=60);
opacity:0.60;
color:#5488C9;
}
button span:hover{
filter:alpha(opacity=60);
opacity:0.60;
color:#5488C9;
}
.buttonhover{
filter:alpha(opacity=60);
opacity:0.60;
color:#5488C9;
}


</style>

<script language="javascript" src="include/common.js"></script>
<script language="javascript">
var domain = "<%=_GET['domain']%>";
var ajaxlock = false;
var filterStr = "<%=filterStr%>";
var filterStr2 = "";
var _TIMER_LOG = null;
var ispaused = false;
var autoscroll = false;
var lastResult = "";

var xmlhttp,page,post;
xmlhttp = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();

function ajaxRequest(pagename,poststring,method)
{
	if(ajaxlock == false)
	{	
		delete xmlhttp;
		xmlhttp = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();

		ajaxlock = true;
		page = pagename;
		post = poststring;

		if(method == "GET")
			xmlhttp.open("GET",page+".html"+post);
		else
			xmlhttp.open("POST",page+".html");

		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.onreadystatechange = ajaxResponse;
		if(method != "GET")
			xmlhttp.send(post);
		else
			xmlhttp.send("");
	}
}

function ajaxResponse()
{
	if (xmlhttp.readyState == 4)
	{
		ajaxlock = false;
		if (xmlhttp.status == 200)
		{
			try
			{
				switch(page)
				{
					case 'admin_get_log':	receiveLog();break;
				}
			}
			catch(e)
			{
			}
		}
		else
		{
		}
	}
}

function receiveLog()
{
	try
	{
		var result = filter(removeXSS(xmlhttp.responseText), filterStr, filterStr2);
		if(lastResult != result)
		{
			$("listview_div").innerHTML = result;
			lastResult = result;

			if(autoscroll == true)
			{
				if($("listview_div").offsetHeight < $("listview_div").scrollHeight)
					$("listview_div").scrollTop = $("listview_div").scrollHeight - $("listview_div").offsetHeight;
			}

		}
	}
	catch(e){}

}

function pauseLog()
{
	ispaused = true;
	$("btn_pause").style.display = "none";
	$("btn_resume").style.display = "";
	clearInterval(_TIMER_LOG);
}

function resumeLog()
{
	ispaused = false;
	$("btn_pause").style.display = "";
	$("btn_resume").style.display = "none";
	clearInterval(_TIMER_LOG);
	_TIMER_LOG = setInterval("getlog_loop()",2000);
}

function clearLog()
{
	var httpObj = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();
	httpObj.open("POST","admin_clear_log.html");
	httpObj.send("domain="+domain+"&r="+Math.random());
}

/*
function addFilter()
{
	var retval = prompt("filter",filterStr2);
	if(retval != null)
		filterStr2 = retval;
	getlog_loop();
}
*/

function addFilter()
{
	showMessagebox("<%=LANG['str_addfilter']%>","<br><table width='100%' border='0' cellpadding='0' cellspacing='0' style='padding-left:10px;'><tr><td height=70><%=LANG['str_filterstring']%>: <input type='text' style='width:190px' id='filter_string'></td></tr><tr><td height=90><button id='btn_submit' type='submit' onclick='return addFilter_submit()'><span><em><%=LANG['button_submit']%></em></span></button>&nbsp;<button id='btn_cancel' onclick='top.closewindow();'><span><em><%=LANG['button_cancel']%></em></span></button></td></tr></table>",callback_return,330,190);
	top.$("filter_string").value = filterStr2;
	top.$("filter_string").focus();

	top.$("btn_submit").onclick = function(){return addFilter_submit();};
	top.$("btn_cancel").onclick = function(){top.closewindow();};
}

function addFilter_submit()
{
	var retval = top.$("filter_string").value;
	if(retval != filterStr2)
	{
		filterStr2 = retval;
		getlog_loop();
	}
	top.closewindow();
}

function showLegend()
{
	var strLegend = "";
	for(var i=0;i<logLegend.length;i++)
	{
		strLegend += "<tr><td style='line-height:150%;font-size:8pt;background-color:"+logBackColor[i]+";color:"+logFontColor[i]+";'>"+logLegend[i]+"</td></tr>";
	}
	showMessagebox("<%=LANG['str_loglegend']%>","<br><table width='100%' border='0' cellpadding='0' cellspacing='2'>"+strLegend+"<tr><td style='padding:3px;'><button id='btn_cancel' onclick='top.closewindow();'><span><em><%=LANG['button_cancel']%></em></span></button></td></tr></table>",callback_return,440,340);
}

top.cancelTimerCallback = function()
{
	clearInterval(_TIMER_LOG);
}

function callback_return(value)
{
	if(ispaused == false)
	{
		clearInterval(_TIMER_LOG);
		_TIMER_LOG = setInterval("getlog_loop()",2000);
	}
	return true;
}
</script>
</head>
<body style="background-color:#E6E6E6;" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td>
	<div id="listview_div" onmouseover="this.focus();" style="margin:10px; width:97%; border:1px solid #919B9C; height:460px; overflow:auto; overflow-x:hidden;background-color:#FFF;"></div>
</td></tr>
<tr><td style="padding-left:10px;">
	<button onclick="pauseLog();" id="btn_pause"><span><em><%=LANG["button_pause"]%></em></span></button>
	<button onclick="resumeLog();" id="btn_resume" style="display:none;"><span><em><%=LANG["button_resume"]%></em></span></button>
	<button onclick="addFilter();"><span><em><%=LANG["button_filter"]%></em></span></button>
	<button onclick="clearLog();"><span><em><%=LANG["str_clear_domainlog"]%></em></span></button>
	<button onclick="showLegend();"><span><em><%=LANG["button_legend"]%></em></span></button>
	<input id="bAutoscroll" type="checkbox" onclick="setAutoscroll();" checked> <%=LANG["title_autoscroll"]%>
	<input id="hiddenInput" type="text" style="width:0px;height:0px; border:0px;">
</td></tr>
</table>

</body>
</html>
<script>
$("hiddenInput").focus();
$("bAutoscroll").focus();
setAutoscroll();

function getlog_loop()
{
	ajaxRequest("admin_get_log","domain="+domain+"&r="+Math.random());
}
clearInterval(_TIMER_LOG);
_TIMER_LOG = setInterval("getlog_loop()",2000);
getlog_loop();


function setAutoscroll()
{
	if($("bAutoscroll").checked)
		autoscroll = true;
	else
		autoscroll = false;
}

if(window.addEventListener)
{
	document.onmousedown = function(){
		return true;
	}
}
else
{
	document.onselectstart = function(){
		return true;
	}
}
</script>

<% 
else
	print("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>")
	print("<script>alert('"..LANG["session_expire"].."');top.location='admin_login.html';</script>")
end 
%>

<noscript><center><H2><%=LANG["error_nojavascript"]%></H2></center></noscript>
