<% Option Explicit %>
<!--#include file="config.asp"-->
<!--#include file="common.asp"-->
<%
	Dim ID, Number


	PageHeader

	If Session("IsAdminLogin") Then
		AdminMenu
	Else
		UserLogin
		Response.End
	End If


	ID		= Str2Num(Request.Querystring("ID"))
	Command	= Request.Querystring("Command")


	If Command = "Save" Then
		Number = Str2Num(Request.Querystring("Number"))

		' update
		DBC.Execute("UPDATE LastBatchNumbers SET LastBatchNumber = " & Number & " WHERE ID = " & ID)

		Set rs = DBC.Execute("SELECT MAX(LastBatchNumber) FROM LastBatchNumbers")
	End If


	If Command = "Edit" Then
		EditNumber
	Else
		NumberList
	End If

	Response.Write "</body>"
	Response.Write "</html>"


	Sub NumberList()

		Dim i

		Set rs = DBC.Execute("SELECT * FROM LastBatchNumbers ORDER BY ID ASC")
%>
		<br>
		<table border=0 align=center bgcolor=FFEFB2 cellspacing=1 cellpadding=3>
		<tr class=PageText>
			<td align=center>
				<font color=black>Last Batch Number</font>
			</td>
			<td align=center>
				<font color=black>Player Win</font>
			</td>
			<td>
				&nbsp;
			</td>
		</tr>
<%
		i = 0

		Do While Not rs.EOF
%>
		<tr bgcolor=white class=PageText>
			<td align=center>
				<%= i %>
			</td>
			<td align=right>
				<%= rs("LastBatchNumber") %> %
			</td>
			<td align=center>
				<a href="admin_batchnumber.asp?Command=Edit&ID=<%= rs("ID") %>">Change</a>
			</td>
		</tr>
<%
			i = i + 1
			rs.MoveNext
		Loop
%>
		</table>
<%
	End Sub


	Sub EditNumber()

		Dim n

		Set rs = DBC.Execute("SELECT * FROM LastBatchNumbers WHERE ID = " & ID)

		If rs.EOF Then
			n = 0
		Else
			n = rs("LastBatchNumber")
		End If
%>
		<script language=JavaScript>
		<!--
		function Validate()
		{
			if (document.F.Number.value.length == 0)
			{
				alert("Please enter a number.");
				document.F.Number.focus();
				return false;
			}
			else
			{
				if (isNaN(document.F.Number.value))
				{
					alert("Please enter a number.");
					document.F.Number.focus();
					return false;
				}
			}

			return true;
		}
		//-->
		</script>

		<br>
		<form name=F action="admin_batchnumber.asp" onsubmit="return Validate()">
		<input type=hidden name=ID value="<%= ID %>">
		<p align=center class=PageText>
			Player Win <input name=Number value="<%= n %>" size=5 maxlength=5 class=ClientText> %
			<input type=submit name=Command value=Save>
		</p>
		</form>
<%
	End Sub
%>