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

			PlayNow
			Response.Write "<br><br>"
			Affiliates
			Response.Write "<br><br><br>"
			TotalPayouts
%>
		</td>
	</tr>
	</table>
<%
	PageEnd
%>
	</body>
	</html>
<%
	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><%= CurrentFile %>?ref=YourEGoldNumber</b> .<br>
		Change <b>YourEGoldNumber</b> with your e-gold account number.

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


	Sub PlayNow()
%>
		<br><br><br><b>Play now</b>

		<form action="https://www.e-gold.com/sci_asp/payments.asp" method=post id=form1 name=form1>
		<input type=hidden name=PAYEE_ACCOUNT value=<%= MyEGold %>>
		<input type=hidden name=PAYEE_NAME value="">
		<input type=hidden name=PAYMENT_AMOUNT value="<%= Bet %>">
		<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 Choice">
		<input type=hidden name=Referral value="<%= Session("EO_Ref") %>">
		<select name=Choice>
		<option value=0>Even (0,2,4,6,8)</option>
		<option value=1>Odd (1,3,5,7,9)</option>
		</select>

		<input type=submit name=PAYMENT_METHOD value="Spend $<%= Bet %>" class=submit>
		</form>
<%
	End Sub


	Sub Welcome()
%>
		<b>Welcome to <%= SiteName %></b>. The game is very easy to play!<br><br>

		All you have to do is send an amount of <b>$<%= Bet %></b>, and guess whether the last digit of your batch number is ODD or EVEN.<br><br>

		Example: if you guess EVEN (0,2,4,6,8) as last number of your batch number, and your batch number is 11819186, You WIN <b>$<%= Win %></b>, 
		If you guess ODD you get <b>$<%= Lose %></b>.<br><br>

		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, Choice

		BatchNumber	= Str2Num(Request.Form("PAYMENT_BATCH_NUM"))
		Choice		= Request.Form("Choice")
%>
		<center>
		Your batch number is <b><%= IIf(IsEven(BatchNumber), "Even", "Odd") %></b> (<%= BatchNumber %>)<br>
		You guessed <b><%= IIf(IsEven(Choice), "Even", "Odd") %></b><br>
		You win <b>$<%= IIf(IsEven(BatchNumber) = IsEven(Choice), Win, Lose) %></b><br><br>
		We will send your winnings ASAP.<br>If you have not recieved any payment within 72 hours please <a href="mailto:<%= ContactEMail %>">contact us</a>.<br><br>
		Thank You!  Play Again
		</center>
<%
	End Sub


	Function IsEven(Num)
		IsEven = (Str2Num(Num) Mod 2 = 0)
	End Function


	Sub PayoutList()

		OpenConnection

		Dim rs, i

		Set rs = DBC.Execute("SELECT * FROM Payments WHERE From = " & MyEGold & " ORDER BY ID DESC")
%>
		<table border=0 width=200 cellspacing=0 cellpadding=3>
		<tr bgcolor=F9F47E class=PageText>
			<td><b>Payout</b></td>
			<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, "F9D47E", "F9F47E") %> class=PageText>
			<td align=center><%= i + 1 %></td>
			<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>There are <%= i %> payouts so far.</b></font><br><br>

		</table>
<%
	End Sub


	Sub TotalPayouts()

		OpenConnection

		Dim rs
		Set rs = DBC.Execute("SELECT COUNT(*) FROM Payments WHERE From = " & MyEGold)
%>
		<font color=red><b>There are <%= rs(0) %> payouts so far.</b></font>
		Please check out our <a href=payouts.asp>payouts</a>.<br><br>
<%
	End Sub



	Sub ReceivePayment()
		Dim PAYMENT_AMOUNT, BatchNumber, PAYER_ACCOUNT, Referral, Choice, Winnings

		PAYMENT_AMOUNT	= Str2Float(Request.Form("PAYMENT_AMOUNT"))
		BatchNumber		= Str2Num(Request.Form("PAYMENT_BATCH_NUM"))
		PAYER_ACCOUNT	= Str2Num(Request.Form("PAYER_ACCOUNT"))
		Referral		= Str2Num(Request.Form("Referral"))
		Choice			= Str2Num(Request.Form("Choice"))

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

		If Referral = PAYER_ACCOUNT Then	
			Referral = 0
		End If

		Winnings = IIf(IsEven(BatchNumber) And IsEven(Choice), Win, Lose)

		OpenConnection

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

		If Winnings > 0 Then
			' ----- prepare player payment ------
			DBC.Execute("INSERT INTO Payments " & _
				"([From], To, Cash, BatchNumber, Description) " & _
				"VALUES (" &	MyEGold									& "," & _
								PAYER_ACCOUNT							& "," & _
								Winnings								& "," & _
								"0"										& "," & _
								"'Your winnings at " & SiteName & "'"	& ")")

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

	End Sub
%>