<%
include("language.html")
if _SESSION["logined"] ~= nil then

local domain = _GET["domain"]
local sessionID = _GET["sessionID"]
%>
<!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>Send Message</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 = "<%=domain%>";
var sessionID = "<%=sessionID%>";
var ajaxlock = false;
var _TIMER_MSG = null;
var ispaused = false;
var autoscroll = false;

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_getmsg':	receiveMessage();break;
				}
			}
			catch(e)
			{
			}
		}
		else
		{
		}
	}
}

function color_filter(s)
{
	var strArray = s.split("\r\n");
	for(var i=0;i<strArray.length;i++)
	{
		if(strArray[i].indexOf("Local Manager:") != -1)
			strArray[i] = "<span style='color:#009900;'>"+strArray[i]+"</span><br>";
		else
			strArray[i] = "<span style='color:#0000FF;'>"+strArray[i]+"</span><br>";
	}
	return strArray.join("");
}

function receiveMessage()
{
	try
	{
		$("listview_div").innerHTML = color_filter(removeXSS(xmlhttp.responseText));
	}
	catch(e){}
	if(autoscroll == true)
	{
		if($("listview_div").offsetHeight < $("listview_div").scrollHeight)
			$("listview_div").scrollTop = $("listview_div").scrollHeight - $("listview_div").offsetHeight;
	}

}

function pauseMessage()
{
	ispaused = true;
	$("btn_pause").style.display = "none";
	$("btn_resume").style.display = "";
	clearInterval(_TIMER_MSG);
	_TIMER_MSG = null;
}

function resumeMessage()
{
	ispaused = false;
	$("btn_pause").style.display = "";
	$("btn_resume").style.display = "none";
	if(_TIMER_MSG == null)
		_TIMER_MSG = setInterval("getmsg_loop()",2000);
}

function sendMessage()
{
	var msg = trim($("strMessage").value);
	if(msg == "") return;

	ajaxRequest("admin_sendmsg","domain="+domain+"&sessionID="+sessionID+"&msg="+encodeURIComponent(msg)+"&r="+Math.random());
	$("strMessage").value = "";
}

top.cancelTimerCallback = function()
{
	if(_TIMER_MSG != null)
		clearInterval(_TIMER_MSG);
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="background-color: #E6E6E6;">

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td style="background-color: #E6E6E6;">
	<div id="status_div">
	<table width='100%' border='0' cellpadding='2' cellspacing='2'>
	<tr><td>
	<%=LANG["str_sendmessage_tip"]%>:
	</td></tr>
	<tr><td>
	<textarea id="strMessage" style="width:460px;height:110px;" onmouseover="this.focus();"></textarea>
	</td></tr>
	<tr><td>
	<button onclick="sendMessage();" id="btn_send"><span><em><%=LANG["button_sendmessage"]%></em></span></button>
	<!--<button onclick="clearLog();"><span><em>Clear Log</em></span></button>-->
	<button onclick="pauseMessage();" id="btn_pause"><span><em><%=LANG["button_pause"]%></em></span></button>
	<button onclick="resumeMessage();" id="btn_resume" style="display:none;"><span><em><%=LANG["button_resume"]%></em></span></button>
	<input id="bAutoscroll" type="checkbox" onclick="setAutoscroll();" checked> <%=LANG["title_autoscroll"]%>
	</td></tr>
	</table>
	</div>
</td></tr>
<tr><td align="center">
	<div id="listview_div" style="width:99%; height:250px; overflow:auto; overflow-x:hidden; border:1px solid #919B9C; background-color: #FFF; text-align:left;"></div>
</td></tr>
</table>


</body>
</html>
<script>
function getmsg_loop()
{
	ajaxRequest("admin_getmsg","domain="+domain+"&sessionID="+sessionID);
}
_TIMER_MSG = setInterval("getmsg_loop()",1000);
getmsg_loop();


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

setAutoscroll();
</script>

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

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