<%
include("language.html")
if _SESSION["logined"] ~= nil then
%>
<%
local domain = _GET["domain"] or _POST["domain"]
local page = _GET["page"] or _POST["page"] or nil
local accessway = c_AccessDataWay(domain)
local totalrecords = 0
local totalpages = 0
if accessway == 2 or accessway == 3 then
	totalrecords,totalpages = c_GetUserPageCount(domain)
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>User Selector</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;
}


.listhead
{
		border-top: 1px solid white; border-right: 1px solid white; 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:24px;
}

.listhead2
{
		border-top: 1px solid white; border-right: 1px solid white; 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:24px;
}

.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?v=new"></script>
<script language="javascript">
var domain = "<%=domain%>";
var accessway = "<%=accessway%>";
var totalrecords = "<%=totalrecords%>";
var totalpages = "<%=totalpages%>";
var nowpage = 1;
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_userlist':	getuserlist_result();break;
				}
			}
			catch(e)
			{
				alert("<%=LANG['error_ajax']%>");
			}
			finally
			{
				$("waitingdiv").style.display = "none";
			}
		}
		else
		{
			$("waitingdiv").style.display = "none";
			alert("<%=LANG['error_ajax']%>");
		}
	}
}

function getuserlist_req()
{
	ajaxRequest("admin_get_userlist","domain="+domain);
}

function getuserlistpage(page)
{
	ajaxRequest("admin_get_userlist","domain="+domain+"&page="+page);
}

function getuserlist_result()
{
	$("waitingdiv").style.display = "";
	try
	{
		var headcell = $("listhead").rows[0].cells;
		var htmltext = "<table id='listtable' width='100%' border='0' cellpadding='2' cellspacing='0' style='table-layout:fixed;'><thead><tr height='0'><td></td></tr></thead><tbody id='maintable'>";

		var userArray = xmlhttp.responseText.split("\n");
		var n = 0;
		if (accessway > 1) n = 1;
		for(var i=n;i<userArray.length;i++)
		{
			var fieldArray = userArray[i].split("|");
			htmltext += "<tr class='listtr01' onmouseup='do_list_click(this);'><td id='td_"+i+"' username='"+fieldArray[0]+"' myname='"+fieldArray[0].toLowerCase()+"'><input type='checkbox' cid='"+i+"'> "+fieldArray[0]+"</td></tr>";
		}
		htmltext += "</tbody></table>";
		clear("listview_div");
		write("listview_div",htmltext);
		selectedRow = null;
		lastsortcol = -1;
	}
	catch(e){}
	sortTable(null, "listtable", 0, "myname");
	$("waitingdiv").style.display = "none";
	if(lastArrow != null)
		lastArrow.style.backgroundImage="";
}


function submitUser()
{
	var checkedlist = "";
	var checkboxs = document.getElementsByTagName("input");
	for(var i=0;i<checkboxs.length;i++)
	{
		if(checkboxs[i].type == "checkbox" && checkboxs[i].checked == true)
		{
			try
			{
				var cid = checkboxs[i].getAttribute("cid");
				if(checkedlist != "") checkedlist += "||";
				checkedlist += htmldecode($("td_"+cid).getAttribute("username"));
			}
			catch (e){}
		}
	}

	if(checkedlist != "")
	{
		top.closewindow(checkedlist);
	}
	else
	{
		if(selectedRow == null || selectedRow.cells[0].getAttribute("username") == null || selectedRow.cells[0].getAttribute("username") == "")
			alert("<%=LANG['str_nouser_tip']%>");
		else
			top.closewindow(selectedRow.cells[0].getAttribute("username"));
	}
}

function do_list_click(obj)
{
	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;
	}
	else
	{
		submitUser();
	}

	return false;
}

function DoSelectAll()
{
	var checkboxs = document.getElementsByTagName("input");
	for(var i=0;i<checkboxs.length;i++)
	{
		if(checkboxs[i].type == "checkbox")
		{
			if($("selectall").checked)
				checkboxs[i].checked = true;
			else
				checkboxs[i].checked = false;
		}
	}
}
</script>
</head>
<body style="background-color:#E6E6E6;" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<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:10%; width:250px; height:100px;"><img src="images/loading2.gif" border="0">
<H2><b><%=LANG["title_updating"]%></b></H2></div></div>

<div style="background-color:#E6E6E6;">
	<div style="margin-top:3px; margin-left:5px; border:1px solid #919B9C; border-bottom:0px; width:96%;">
		<table id="listhead" width="100%" border="0" cellpadding="0" cellspacing="0" style="table-layout:fixed;">
		<tr>
		<td class="listhead" width="100%" onmouseover="className='listhead2';" onmouseout="className='listhead';" onmousedown="sortTable(this,'listtable', 0, 'myname')"><span style="float:left; margin-left:-2px;"><input type='checkbox' id='selectall' onclick="DoSelectAll();"></span><%=LANG["str_username"]%></td>
		<td class="listhead"></td>
		</tr>
		</table>
	</div>
	<div id="listview_div" style="background-color:#FFF; margin-left:5px; border:1px solid #919B9C; border-top:0px; width:96%; height:270px; overflow:auto; overflow-x:hidden;">
		<table id="listtable" width="100%" border="0" cellpadding="2" cellspacing="0" style="table-layout:fixed;">
		<thead><tr height="0">
		<td width="100%"></td>
		</tr></thead>
		<tbody id="maintable">
		</tbody>
		</table>
	</div>
</div>

<div style="margin-top:5px;width:100%;text-align:center;">
<button type='submit' onclick='submitUser();'><span><em><%=LANG["button_submit"]%></em></span></button>&nbsp;
<button onclick='top.closewindow();'><span><em><%=LANG["button_cancel"]%></em></span></button>&nbsp;
<script>
try
{
	totalpages = parseInt(totalpages);
	if(accessway == "2" || accessway == "3")
	{
		pagejump(nowpage);
		document.write("<select onchange=\"pagejump(this.value)\">");
		for(i=1;i<=totalpages;i++)
		{
			document.write("<option value='"+i+"'>"+i+"</option>");
		}
		document.write("</select>");
	}
	else
	{
		getuserlist_req();
	}
}
catch(e){}

function jumpprevious()
{
	page = nowpage-1;
	pagejump(page);
}

function jumpnext()
{
	page = nowpage+1;
	pagejump(page);
}

function pagejump(page)
{
	page = parseInt(page);
	if(page < 1)
		page = 1;
	if(page > totalpages)
		page = totalpages;
	nowpage = page;
	getuserlistpage(nowpage);
}
</script>
</div>

</body>
</html>

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