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


	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
		BetValue = Str2Float(Request.Querystring("Bet"))

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

		If rs.EOF Then
			' insert
			DBC.Execute("INSERT INTO Bets (Bet) VALUES(" & BetValue & ")")
		Else
			' update
			DBC.Execute("UPDATE Bets SET Bet = " & BetValue & " WHERE ID = " & ID)
		End If
	End If

	If Command = "Delete" Then
		DBC.Execute("DELETE FROM Bets WHERE ID = " & ID)
	End If


%>
	<p align=center>
	<a href="admin_bet.asp">Show all bets</a>&nbsp;&nbsp;&nbsp;
	<a href="admin_bet.asp?Command=Edit">Add a bet</a>
	</p>
<%
	If Command = "Edit" Then
		EditBet
	Else
		BetList
	End If


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


	Sub BetList()

		Dim l

		Set rs = DBC.Execute("SELECT * FROM Bets ORDER BY Bet")
%>
		<table border=0 align=center bgcolor=FFEFB2 cellspacing=1 cellpadding=3>
		<tr class=PageText>
			<td align=center>
				<font color=black>N</font>
			</td>
			<td align=center>
				<font color=black>Bet</font>
			</td>
			<td>
				&nbsp;
			</td>
		</tr>
<%
		l = 0

		Do While Not rs.EOF
%>
		<tr bgcolor=white class=PageText>
			<td align=center>
				<%= l + 1 %>
			</td>
			<td align=right>
				$<%= FormatNumber(rs("Bet"), 2) %>
			</td>
			<td align=center>
				<a href="admin_bet.asp?Command=Edit&ID=<%= rs("ID") %>">Change</a>
				&nbsp;
				<a href="admin_bet.asp?Command=Delete&ID=<%= rs("ID") %>">Delete</a>
			</td>
		</tr>
<%
			l = l + 1
			rs.MoveNext
		Loop
%>
		</table>
<%
	End Sub


	Sub EditBet()

		Dim b

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

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

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

		<form name=F action="admin_bet.asp" onsubmit="return Validate()">
		<input type=hidden name=ID value="<%= ID %>">
		<p align=center class=PageText>
			Bet <input name=Bet value="<%= b %>" size=10 maxlength=10 class=ClientText>
			<input type=submit name=Command value=Save>
		</p>
		</form>
<%
	End Sub
%>