<% 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
			If CDbl(Bet) = Str2Float(Request.Form("PAYMENT_AMOUNT")) Then
				ReceivePayment
				Response.End
			End If
		End If
	End If


	If Not IsEmpty(Request.QueryString("egold")) Then
		Session("N8_Sponsor") = Str2Num(Request.QueryString("egold"))
	End If


	PageHeader
	PageBegin
	If Request.QueryString("Command") = "ThankYou" Then
		ThankYou
	Else
		Play
	End If
	PageEnd


	Sub Play()
%>
		<table border="0" width="100%" cellspacing="0" cellpadding="0">
		<tr>
			<td>
				<img src="images/howitworks.gif" alt="How it works" WIDTH="191" HEIGHT="28"></td>
		</tr>
		<tr>
			<td>
				<table border="0" width="100%" cellspacing="1" cellpadding="5" bgcolor=9CAAF7>
				<tr>
					<td bgcolor="C6F39C">
						Spend an amount of <b>$<%= FormatNumber(Bet, 2) %></b>, and if the batch number 
						ends in <font color=red><b><%= LuckyNumber %></b></font>, 
						you get <b>$<%= FormatNumber(Win, 2) %></b> back!<br><br>

						<font color="red" size="3"><b>WOW <b>$<%= FormatNumber(Win, 2) %></b> in a couple of minutes</b></font><br><br>

						You can play as much as you want. You should get 
						paid ASAP. Please read our <a href=faq.asp>F.A.Q.</a> page before play.
					</td>
				</tr>
				</table>
			</td>
		</tr>
		</table>
		<br>

		<table border="0" width="100%" cellspacing="0" cellpadding="0">
		<tr>
			<td>
				<img src="images/affiliates.gif" alt="Affiliates" WIDTH="191" HEIGHT="28"></td>
		</tr>
		<tr>
			<td>
				<table border="0" width="100%" cellspacing="1" cellpadding="5" bgcolor=9CAAF7>
				<tr bgcolor="C6F39C">
					<td>
						Get <b>$<%= FormatNumber(SponsorEarn, 2) %></b> from all 
						spend made by the person you refer. We will instantly 
						pay into your e-gold account.<br><br>
						You need only to put this link into your page:<br>
						<%= CurrentPath %>?egold=<b>YourEGoldNumber</b><br><br>
						Change <b>YourEGoldNumber</b> with your e-gold account number.
					</td>
				</tr>
				</table>
			</td>
		</tr>
		</table>
		<br>

		<table border="0" width="100%" cellspacing="0" cellpadding="0">
		<tr>
			<td>
				<img src="images/playnow.gif" alt="Play now" WIDTH="191" HEIGHT="28"></td>
		</tr>
		<tr>
			<td>
				<table border=0 width="100%" cellspacing="1" cellpadding="5" bgcolor=9CAAF7>
				<form action="https://www.e-gold.com/sci_asp/payments.asp" method=post>
				<tr>
					<td bgcolor="C6F39C">
<%
						If Str2Num(Session("N8_Sponsor")) > 0 Then
							Response.Write "Your Sponsor e-gold number is <font color=blue><b>" & Session("N8_Sponsor") & "</b></font><br><br>"
						End If
%>
						<input type="hidden" name="PAYEE_ACCOUNT" value="<%= MyEGold %>">
						<input type="hidden" name="PAYEE_NAME" value="<%= SiteName %>">
						<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 %> spend">
						<input type="hidden" name="Sponsor" value="<%= Session("N8_Sponsor") %>">
						<input type="hidden" name="BAGGAGE_FIELDS" value="Sponsor">
						<input type="hidden" name="PAYMENT_AMOUNT" value="<%= Bet %>">
						Spend $<%= FormatNumber(Bet, 2) %>&nbsp;
						<input type="image" src="images/egold.gif" name="PAYMENT_METHOD" alt="Pay with e-gold" align="absmiddle" WIDTH="88" HEIGHT="31">
					</td>
				</tr>
				</form>
				</table>
			</td>
		</tr>
		</table>
<%
	End Sub


	Sub ThankYou()
		Dim BatchNumber
		BatchNumber = CDbl(Request.Form("PAYMENT_BATCH_NUM"))

		If CDbl(Right(BatchNumber, 1)) = LuckyNumber Then
			Response.Write "Your batch number is " & BatchNumber & ". You win $" & FormatNumber(Win, 2) & ".<br><br>"
			Response.Write "We will send your winnings ASAP. If you have not recieved any payment within 48 hours please <a href='mailto:" & ContactEMail & "'>contact us</a>.<br><br>"
		Else
			Response.Write "Your batch number is " & BatchNumber & ". You lose.<br><br>Please <a href=default.asp>play again</a>.<br><br>"
		End If
	End Sub


	Sub ReceivePayment()
		Dim rsPayment, PAYMENT_AMOUNT, BatchNumber, PAYER_ACCOUNT, Sponsor, Winnings

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

		OpenConnection

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

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

		PAYMENT_AMOUNT	= Str2Float(Request.Form("PAYMENT_AMOUNT"))
		PAYER_ACCOUNT	= Str2Num(Request.Form("PAYER_ACCOUNT"))
		Sponsor			= Str2Num(Request.Form("Sponsor"))

		If Sponsor = CDbl(MyEGold) Then
			Sponsor = 0
		End If

		If Sponsor = PAYER_ACCOUNT Then
			Sponsor = 0
		End If


		Winnings = IIf(CDbl(Right(BatchNumber, 1)) = LuckyNumber, Win, 0)


		' add payment
		DBC.Execute("INSERT INTO PayIns (EGold, Invest, BatchNumber) " & _
			"VALUES (" &	PAYER_ACCOUNT	& "," & _
							PAYMENT_AMOUNT	& "," & _
							BatchNumber		& ")")

		If Winnings > 0 Then
			' ----- add player payment ------
			DBC.Execute("INSERT INTO Payouts " & _
				"(EGold, Payout, Description) " & _
				"VALUES (" &	PAYER_ACCOUNT						& "," & _
								Winnings							& "," & _
								"'Your winnings at " & SiteName & "')")
		End If


		If Sponsor > 0 Then
			' ----- add sponsor payment if any ------
			DBC.Execute("INSERT INTO Payouts " & _
				"(EGold, Payout, Description) " & _
				"VALUES (" &	Sponsor									& "," & _
								SponsorEarn								& "," & _
								"'Your commission at " & SiteName & "'"	& ")")
		End If

	End Sub
%>