<% Option Explicit %>
<!--#include file="config.asp"-->
<!--#include file="common.asp"-->
<!--#include file="md5.asp"-->
<%
	If Len(Request.Form.Item) > 0 And Request.Form("Command") <> "ThankYou" Then
		If IsValidPayment Then
			ReceivePayment
		End If
	End If


	PageHeader
	PageBegin
%>
	<br>
	<table border=0 width="100%" cellspacing="0" cellpadding="8">
	<tr valign=top class=PageText>
		<td>
<%
			If Request("Payment") = "Continue" Then
				ThankYou
			Else
				Welcome
			End If

			Response.Write "<br><br>"
			Affiliates
			Response.Write "<br><br>"
			Disclaimer
%>
		</td>
		<td width=210 align="center">
<%
			Table()
			Response.Write "<br>"
			PlayNow()
			Response.Write "<br>"
			LastPayoutList
%>
		</td>
	</tr>
	</table>
<%
	PageEnd



	Sub Affiliates()
%>
		<b>Affiliates</b><br><br>

		Get <b><%= ReferralCommission %>%</b> from all spend made by the person 
		you refer. You need only to put this link into your page: 
		<b><%= CurrentPath %>?ref=YourEGoldNumber</b> .<br>
		Change <b>YourEGoldNumber</b> with your e-gold account number.<br><br>

		We will not pay you if you refer yourself.
<%
	End Sub


	Sub Disclaimer ()
		Response.Write "<b>Disclaimer</b><br><br>This is a game, SPEND ONLY what you CAN afford to lose."
	End Sub


	Sub Table()

	Dim i
%>
	<table border="0" width="190" cellspacing="1" cellpadding="2" bgcolor="BBBBBB">
	<tr bgcolor=FFEFB2>
		<td align="center"><b>Last Digit</b></td>
		<td align="center"><b>Win</b></td>
	</tr>
<%
	For i = 0 To 9
%>
	<tr bgcolor=<%= IIf(i Mod 2 = 0, "FFFAC6", "FFEFB2") %> class=PageText>
		<td align=center>
			<b><%= i %></b>
		</td>
		<td align=right>
			<b><font color="<%= IIf(LastBatchNumber(i) < 100, "FF0000", "green") %>"><%= LastBatchNumber(i) %> %</font></b>
		</td>
	</tr>
<%
	Next
%>
	</table>
<%
	End Sub


	Sub PlayNow()
		Dim b, Cols

		Response.Write "Winnings are in <font color=green><b>green</b></font><br><br>"
		Response.Write "Choose your bet "

		Response.Write "<table border=0 cellspacing=6><tr>"

		Cols = 4

		For b = 0 To UBound(Bet)
			If b Mod Cols = 0 Then
				Response.Write "</tr><tr>"
			End If
%>
		<td>
		<form action="https://www.e-gold.com/sci_asp/payments.asp" method=post>
		<input type=hidden name=PAYEE_ACCOUNT value="<%= MyEGold %>">
		<input type=hidden name=PAYEE_NAME value="">
		<input type=hidden name=PAYMENT_AMOUNT value="<%= Bet(b) %>">
		<input type=hidden name=PAYMENT_UNITS value=1>
		<input type=hidden name=PAYMENT_METAL_ID value=1>
		<input type=hidden name=STATUS_URL value="<%= CurrentFile %>">
		<input type=hidden name=PAYMENT_URL value="<%= CurrentFile %>?Command=ThankYou">
		<input type=hidden name=NOPAYMENT_URL value="<%= CurrentFile %>">
		<input type=hidden name=SUGGESTED_MEMO value="<%= SiteName %> bet">
		<input type=hidden name=BAGGAGE_FIELDS value="Referral">
		<input type=hidden name=Referral value="<%= Session("EGG_Ref") %>">
		<input type=submit name=PAYMENT_METHOD value="$<%= FormatNumber(Bet(b), 2) %>" class=Button>
		</form>
		</td>
<%
		Next
%>
		</tr>
		</table>
<%
	End Sub


	Sub Welcome()
%>
		<b>Welcome to <%= SiteName %></b>.<br>
		You can earn up to <%= EarnUpTo %>% of your bet.<br><br>

		All you have to do is send an amount <b>between $<%= Bet(0) %> 
		and $<%= Bet(UBound(Bet)) %></b> to <%= SiteName %> (<%= MyEGold %>). 
		The last digit of the spend batch will decide how much you will 
		get back. There are no limits on how often you can play, every 
		day or hour. You can play as much as you want.

		You should get paid ASAP. All payments are paid in US dollars 
		by E-Gold.
<%
	End Sub


	Sub ThankYou()
		Dim BatchNumber

		BatchNumber = Str2Num(Request.Form("PAYMENT_BATCH_NUM"))

		If LastBatchNumber(Right(BatchNumber, 1)) = 0 Then
%>
		Your batch number is <%= BatchNumber %>. You lose.<br><br>
		Sorry!  Try Again
<%
		Else
%>
		Your batch number is <%= BatchNumber %>. You get <%= LastBatchNumber(Right(BatchNumber, 1)) %>% of your bet amount.<br><br>
		We will send your winnings ASAP.<br><br>
		Thank You!  Play Again
<%
		End If
	End Sub


	Sub LastPayoutList()
		Dim i

		Set rs = DBC.Execute("SELECT TOP " & LastPayouts & " * FROM Payments WHERE [From] = " & MyEGold & " ORDER BY ID DESC")
%>
		<table border=0 width=190 cellspacing=1 cellpadding=2 bgcolor=BBBBBB>
		<tr bgcolor=FFEFB2 class=PageText>
			<td align=center><b>Account</b></td>
			<td align=center><b>Amount</b></td>
		</tr>
<%
		i = 0

		Do While Not rs.EOF
%>
		<tr bgcolor=<%= IIf(i Mod 2 = 0, "FFFAC6", "FFEFB2") %> class=PageText>
			<td align=center>
				<%= rs("To") %>
			</td>
			<td align=right>
				$<%= FormatNumber(rs("Cash"), 2) %>
			</td>
		</tr>
<%
			i = i + 1
			rs.MoveNext
		Loop
%>
		<font color=red><b>Last <%= LastPayouts %> payouts<br>
		<a href="payouts.asp">Check out all payouts.</a></b></font><br><br>

		</table>
<%
	End Sub


	Sub ReceivePayment()
		Dim PAYMENT_AMOUNT, BatchNumber, PAYER_ACCOUNT, Referral, rsPayment

		' ---- is payment units correct ------
		If Str2Num(Request.Form("PAYMENT_UNITS")) <> 1 Then
			Exit Sub
		End If
		' ------------------------------------

		BatchNumber		= Str2Num(Request.Form("PAYMENT_BATCH_NUM"))

		' ---- is payment recorded -----------
		Set rsPayment = DBC.Execute("SELECT COUNT(*) FROM Payments WHERE BatchNumber = " & BatchNumber)

		If rsPayment(0) > 0 Then
			Exit Sub
		End If
		' ------------------------------------

		' ---- is amount correct -------------
		PAYMENT_AMOUNT	= Str2Float(Request.Form("PAYMENT_AMOUNT"))

		If PAYMENT_AMOUNT < Bet(0) Or PAYMENT_AMOUNT > Bet(UBound(Bet)) Then
			Exit Sub
		End If
		' ------------------------------------

		PAYER_ACCOUNT	= Str2Num(Request.Form("PAYER_ACCOUNT"))
		Referral		= Str2Num(Request.Form("Referral"))


		If Referral = Str2Num(MyEGold) Then	
			Referral = 0
		End If

		If Referral = PAYER_ACCOUNT Then	
			Referral = 0
		End If

		' add payment
		DBC.Execute("INSERT INTO Payments ([From], To, Cash, BatchNumber) " & _
			"VALUES (" &	PAYER_ACCOUNT	& "," & _
							MyEGold			& "," & _
							PAYMENT_AMOUNT	& "," & _
							BatchNumber		& ")")

		If Str2Float(LastBatchNumber(Right(BatchNumber, 1))) > 0 Then
			' ----- prepare player payment if any ------
			DBC.Execute("INSERT INTO Payments " & _
				"([From], To, Cash, BatchNumber, Description) " & _
				"VALUES (" &	MyEGold													& "," & _
								PAYER_ACCOUNT											& "," & _
								PAYMENT_AMOUNT * Str2Float(LastBatchNumber(Right(BatchNumber, 1))) / 100	& "," & _
								"0"														& "," & _
								"'Your winnings at " & SiteName & "'"					& ")")

			If Referral > 0 Then
				' ----- prepare referral payment if any ------
				DBC.Execute("INSERT INTO Payments " & _
					"([From], To, Cash, BatchNumber) " & _
					"VALUES (" &	MyEGold			& "," & _
									Referral		& "," & _
									PAYMENT_AMOUNT / ReferralCommission * Str2Float(LastBatchNumber(Right(BatchNumber, 1))) / 100	& "," & _
									"0"				& "," & _
									"'Your commission at " & SiteName & "'"		& ")")
			End If
		End If

	End Sub
%>