<%
include("language.html")
if _SESSION["logined"] ~= nil then
%>
<!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>Gateway list</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
html, body {height: 100%;}
<%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;
}


.listhead
{
		border-top: 1px solid white; border-right: 1px solid #ACA899; border-left: 1px solid white; border-bottom: 2px solid #E1E2E3;
		font: 12px/22px arial; cursor: hand; text-align: center; background-color: #EFEFEF; overflow:hidden; height:18px;
}

.listhead2
{
		border-top: 1px solid white; border-right: 1px solid #ACA899; border-left: 1px solid white; border-bottom: 2px solid #FCC247;
		font: 12px/22px arial; cursor: hand; text-align: center; background-color: #FAF9F4; overflow:hidden; height:18px;
}

.listtr01
{
		background-color: #FFFFFF;
		text-align: left;
		padding: 3px;
}

.listtr02
{
		background-color: #3366CC;
		color: #FFF;
		text-align: left;
		padding: 3px;
}

.resizeblock{
	background-color:transparent;
	width:2px;
	float:right;
	cursor:e-resize;
}

</style>

<script language="javascript" src="include/common.js"></script>
<script language="javascript">
var nowrows = 0;
var ajaxlock = false;
var selectedRow = null;
var lastObj = null;
var lastObjIndex = -1;

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(page != "")
			$("waitingdiv").style.display = "";

		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_gatewaylist':	getlist_result();break;
					case 'admin_delete_gateway':	getlist_req();break;
				}
			}
			catch(e)
			{
				alert("<%=LANG['error_ajax']%>");
			}
			finally
			{
				$("waitingdiv").style.display = "none";
			}
		}
		else
		{
			$("waitingdiv").style.display = "none";
			alert("<%=LANG['error_ajax']%>");
		}
	}
}

function getlist_req()
{
	ajaxRequest("admin_get_gatewaylist", "r=" + Math.random());
}

function getlist_result()
{
	$("waitingdiv").style.display = "";
	try
	{
		var xmldoc = xmlhttp.responseXML;
		var row = xmldoc.getElementsByTagName("gatewaylist");
		var rownum = row.length;

		var htmltext = "<table id='listtable' width='100%' border='0' cellpadding='2' cellspacing='0' style='table-layout:fixed;'><thead><tr height='0'><td width='60%'></td><td width='20%'></td><td width='20%'></td></tr></thead><tbody id='maintable'>";

		for(var i=0; i < rownum; i++)
		{
			var myrow = row[i];
			var f_host = xmlFieldValue(myrow,"host");
			var f_enable = xmlFieldValue(myrow,"enable");
			var f_running = xmlFieldValue(myrow,"running");
			var gateway_status = 0;
			if(f_running == "true")
			{
				gateway_status = 1;
			}
			htmltext += "<tr class='listtr01' onmouseup='do_list_click(this, "+gateway_status+");'><td>"+f_host+"</td><td><img src='images/"+f_enable+".png'></td><td><img src='images/"+f_running+".png'></td></tr>";
		}
		htmltext += "</tbody></table>";
		clear("listview_div");
		write("listview_div",htmltext);
		selectedRow = null;
		lastsortcol = -1;
		nowrows = rownum;
	}
	catch(e){}
	$("waitingdiv").style.display = "none";
	if(lastArrow != null)
		lastArrow.style.backgroundImage="";
}


function do_list_click(obj, status)
{
	var row_index = obj.rowIndex-1;
	if(selectedRow != $("maintable").rows[row_index])
	{
		if(lastObj != null)
			lastObj.className = "listtr01";

		selectedRow = $("maintable").rows[row_index];
		obj.className = "listtr02";
		lastObj = obj;
		try{
			lastObjIndex = parseInt(selectedRow.cells[0].innerHTML);
		}catch(e){
			lastObjIndex = -1;
		}
	}
	else
	{
		ModifyGateway(status);
	}

	return false;
}


function AddGateway()
{
	var frametag = new Date().getTime();
	showMessagebox("Add Gateway","<iframe src='admin_addgateway_form.html?seeds=" + Math.random() +"' width=500 height=400 border=0 frameborder=0 id='add"+frametag+"'></iframe>",callback_return,500,410);
}

function callback_return(value)
{
	if(value != null)
	{
		getlist_req();
		setTimeout("getlist_req()",100);
	}
	return true;
}

function DeleteGateway()
{
	if(selectedRow == null)
	{
		alert("<%=LANG['str_norow_tip']%>");
		return;
	}

	var host = selectedRow.cells[0].innerHTML;
	if(confirm("<%=LANG['str_gateway_delete_tip']%> ("+host+")?"))
		ajaxRequest("admin_delete_gateway","host="+host+"&r=" + Math.random());
}

function ModifyGateway(status)
{
	if(selectedRow == null)
	{
		alert("<%=LANG['str_norow_tip']%>");
		return;
	}

	var host = urlEncode(selectedRow.cells[0].innerHTML);
	var frametag = new Date().getTime();
	showMessagebox("Modify Gateway","<iframe src='admin_addgateway_form.html?status="+status+"&host="+host+"&seeds=" + Math.random() +"' width=500 height=400 border=0 frameborder=0 id='modify"+frametag+"'></iframe>",callback_return,500,410);
}

function Refresh()
{
	getlist_req();
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="background-color:#E6E6E6;">

<div id="waitingdiv" style="position:absolute; z-index:100; top:0px; left:0px; width:100%; height:100%; background:#777; filter:alpha(opacity=60); -moz-opacity: 0.60; opacity:0.60; display:none;" align="center">
<div style="position:absolute; top:20%; left:40%; width:250px; height:100px;"><img src="images/loading2.gif" border="0">
<H2><b><%=LANG["title_updating"]%></b></H2></div></div>

<div style="width:100%; padding-top:2px; overflow-x:hidden; padding-left:4px;">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
	<td style="padding:2px;">
		<button onclick="AddGateway();"><span><em><%=LANG["str_add_gateway"]%></em></span></button>
		<button onclick="DeleteGateway();"><span><em><%=LANG["button_delete"]%></em></span></button>
		<button onclick="Refresh();"><span><em><%=LANG["button_refresh"]%></em></span></button>
	</td>
	</tr>

	<tr>
	<td>
	<table width="550" border="0" cellpadding="0" cellspacing="0" style="border:1px solid #919B9C;">
		<tr>
		<td class="listhead" width="60%" onmouseover="className='listhead2';" onmouseout="className='listhead';" onmousedown="sortTable(this,'listtable', 0)"><%=LANG["str_gateway_host"]%></td>
		<td class="listhead" width="20%" onmouseover="className='listhead2';" onmouseout="className='listhead';" onmousedown="sortTable(this,'listtable', 1)"><%=LANG["str_gateway_enabled"]%></td>
		<td class="listhead" width="20%" onmouseover="className='listhead2';" onmouseout="className='listhead';" onmousedown="sortTable(this,'listtable', 2)"><%=LANG["str_gateway_running"]%></td>
		</tr>
		<tr>
		<td colspan="3">
		<div id="listview_div" style="height:400px; width:100%; background-color:#FFF; overflow:auto; overflow-x:hidden;">
		<table id="listtable" width="100%" border="0" cellpadding="2" cellspacing="0" style="table-layout:fixed;"></table>
		</div>
		</td></tr>
	</table>
	</td></tr>

	</table>
</div>


<script language="javascript">
	getlist_req();
</script>
</body>
</html>

<% 
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>