<% Option Explicit %>
<!--#include file="../config.asp"-->
<!--#include file="../common.asp"-->
<!--#include file="main.asp"-->
<%
	Dim rs, EGold, Password, SponsorEGold, Cash, IsGold

	Command	= Request.Form("Command")
	MemberID	= Str2Num(Request("MemberID"))

	OpenConnection

	If Command = "Save" Then
		Set rs = DBC.Execute("SELECT * FROM Members WHERE MemberID = " & MemberID)

		If rs.EOF Then
			DBC.Execute("INSERT INTO Members (EGold, Password, SponsorEGold, Cash, IsGold) "	& _
				"VALUES (" &	Request.Form("Egold")				& ", " & _
						EscapeSQLData(Request.Form("Password"))		& ", " & _
						Str2Num(Request.Form("SponsorEGold"))		& ", " & _
						Request.Form("Cash")				& ", " & _
						IIf(Str2Num(Request.Form("IsGold")) = 1, "true", "false")	& ")")
		Else
			DBC.Execute("UPDATE Members SET " & _
				"EGold		= " & Request.Form("EGold")										& ", " & _
				"Password	= " & EscapeSQLData(Request.Form("Password"))			& ", " & _
				"SponsorEGold	= " & Str2Num(Request.Form("SponsorEGold"))			& ", " & _
				"Cash		= " & Request.Form("Cash")					& ", " & _
				"IsGold		= " & IIf(Str2Num(Request.Form("IsGold")) = 1, "true", "false")	& "  " & _
				"WHERE MemberID = " & MemberID)
		End If

		Application(Prefix & "MyEGold") = 0

		Response.Redirect "member_list.asp?page=" & Session(Prefix & "MemberList_Page")
	End If


	PageHeader

	If Not Session("IsAdminLogin") Then
		PageLogin
		Response.End
	End If

	AdminPageBegin "Add Member"
	MemberEdit
	AdminPageEnd



	Sub MemberEdit()
		Set rs = DBC.Execute("SELECT * FROM Members WHERE MemberID = " & MemberID)

		If rs.EOF Then
			EGold		= ""
			Password		= ""
			SponsorEGold	= ""
			Cash		= ""
			IsGold		= False
		Else
			EGold		= rs("EGold")
			Password		= rs("Password")
			SponsorEGold	= rs("SponsorEGold")
			Cash		= rs("Cash")
			IsGold		= rs("IsGold")
		End If
%>
		<script language=JavaScript>
		<!--
		function Validate()
		{
			if (! IsNumber (document.F.EGold, "Please enter a number."))
				return false;

			if (document.F.Password.value.length == 0)
			{
				alert ('Please enter a password.');
				document.F.Password.focus();
				return false;
			}

			if (isNaN(document.F.SponsorEGold.value))
				document.F.SponsorEGold.value = 0;

			if (! IsNumber (document.F.Cash, "Please enter a number."))
				return false;

			return true;
		}

		<% JS_IsNumber %>
		//-->
		</script>

		<form name=F action="member_edit.asp" method=post onsubmit="return Validate()">
		<input type=hidden name=MemberID value="<%= MemberID %>">
		<table border=0 align=center bgcolor=black cellspacing=1 cellpadding=3>
		<tr>
			<td colspan=2 class=SelectedParent align=center>
				Member information
			</td>
		</tr>
		<tr class=Odd>
			<td>E-Gold</td>
			<td>
				<input name=EGold value="<%= EGold %>" size=20 maxlength=10 class=ClientText>
			</td>
		</tr>
		<tr class=Odd>
			<td>Password</td>
			<td>
				<input name=Password value="<%= Password %>" size=20 maxlength=20 class=ClientText>
			</td>
		</tr>
		<tr class=Odd>
			<td>Sponsor's e-gold</td>
			<td>
				<input name=SponsorEGold value="<%= SponsorEGold %>" size=20 maxlength=10 class=ClientText>
			</td>
		</tr>
		<tr class=Odd>
			<td>Cash</td>
			<td>
				<input name=Cash value="<%= Cash %>" size=20 maxlength=7 class=ClientText>
			</td>
		</tr>
		<tr class=Odd>
			<td>Gold member</td>
			<td>
				<input type=checkbox name=IsGold value=1 <%= IIf(IsGold, " checked", "") %> class=ClientText>
			</td>
		</tr>
		<tr>
			<td colspan=2 bgcolor=white align=center>
				<input type=submit name=Command value=Save style="width:200">
			</td>
		</tr>
		</table>
		</form>
<%
	End Sub
%>