<% Option Explicit %>
<!--#include file="config.asp"-->
<!--#include file="common.asp"-->
<!--#include file="md5.asp"-->
<%
	PageBegin

	If Request("Command") = "ThankYou" Then
		Session(Prefix & "MemberID") = 0
%>
		<br><br>Thank you for becoming a GOLD Member.<br>Your advertising information will be approved ASAP.<br><br>
		Please <a href="log.asp">log-in</a> to your account.<br><br><br>
<%
	Else
		If Len(Request.Form.Item) < 10 Then
			If MemberID = 0 Then
				Response.Write "<br>Your session has been expired. Please <a href=log.asp>log in</a> again.<br><br><br><br><br>"
			Else
				UpgradeMember
			End If
		Else
			If IsValidPayment Then
				AcceptPayment

				Response.End
			End If
		End If
	End If
	PageEnd


	Sub UpgradeMember()
%>
		<form name=F action="https://www.e-gold.com/sci_asp/payments.asp" method=POST onsubmit="return UpgradeAccount()">
		<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="BAGGAGE_FIELDS" value="MemberEGold Sponsor SiteTitle SiteURL Banner URL">
		<input type=hidden name=FORCED_PAYER_ACCOUNT value=<%= Session(Prefix & "EGold") %>>
		<input type=hidden name="MemberEGold" value="<%= Session(Prefix & "EGold") %>">
		<input type=hidden name="SUGGESTED_MEMO" value="<%= SiteName %> Gold Membership">
		<input type=hidden name="PAYMENT_AMOUNT" value="<%= GoldFee %>">
		<input type=hidden name="Sponsor" value="<%= Session(Prefix & "SponsorEGold") %>">

		<table border="0" width=560 cellpadding="2" cellspacing="0">
		<col width="200">
		<col>
		<tr class="Title" valign="top">
			<td align="center" colspan="2">
				Upgrade to GOLD Member<br><br>
			</td>
		</tr>
		<tr class="Odd">
			<td colspan=2>
				You will receive <%= GoldFreeVisitors %> unique visitors to your website/affiliate program.<br><br>
			</td>
		</tr>
		<tr class="Odd">
			<td>Site's Title</td>
			<td>
				<input name="SiteTitle" value size="50" maxlength="50" class="ClientText">
			</td>
		</tr>
		<tr class="Odd">
			<td>Site's URL</td>
			<td>
				<input name="SiteURL" value="http://" size="50" maxlength="120" class="ClientText">
			</td>
		</tr>
		<tr class="Odd">
			<td colspan=2>
				<br><br>Unlimited banner impressions for <%= GoldBannerDays %> days<br><br>
			</td>
		</tr>
		<tr class="Odd">
			<td>Banner's URL</td>
			<td>
				<input name="Banner" value="http://" size="50" maxlength="120" class="ClientText">
			</td>
		</tr>
		<tr class="Odd">
			<td>Site's URL</td>
			<td>
				<input name="URL" value="http://" size="50" maxlength="120" class="ClientText">
			</td>
		</tr>
		<tr class="Odd">
			<td colspan=2>
				<br>
			</td>
		</tr>
		<tr class="Odd">
			<td>Life-time fee</td>
			<td>
				$<%= FormatNumber(GoldFee, 2) %>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<font color="red">The fee is non-refundable!</font>
			</td>
		</tr>
		<tr class="Odd">
			<td valign="top" colspan="2" align="center">
				<br>
				The information above will be submit to our site 
				administrator for approval. Your advertising information 
				will be approved ASAP, if it does not contain any illegal 
				information or adult materials.<br><br>
				<input type="image" name="PAYMENT_METHOD" src="images/egold.gif" alt="Pay through e-gold" WIDTH="88" HEIGHT="31">
			</td>
		</tr>
		</form>
		</table>

		<script language="JavaScript">
		<!--
		function UpgradeAccount()
		{
			if (document.F.SiteTitle.value.length < 3)
			{
				alert ("Please enter your Site's Title.");
				document.F.SiteTitle.focus();
				return false;
			}

			if (document.F.SiteURL.value.length < 10)
			{
				alert ("Please enter your Site's URL.");
				document.F.SiteURL.focus();
				return false;
			}

			if (document.F.Banner.value.length < 10)
			{
				alert ("Please enter your Banner's URL.");
				document.F.Banner.focus();
				return false;
			}

			if (document.F.URL.value.length < 3)
			{
				alert ("Please enter your Site's Title.");
				document.F.URL.focus();
				return false;
			}

			return true;
		}
		//-->
		</script>
<% 
	End Sub


	Sub AcceptPayment()
		Dim rs, BatchNumber, MemberEGold, SiteTitle, SiteURL, Banner, URL, Sponsor, PAYMENT_AMOUNT

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

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

		If CDbl(PAYMENT_AMOUNT) <> CDbl(GoldFee) Then
			Exit Sub
		End If
		' ------------------------------------

		MemberEGold	= Str2Num(Request("MemberEGold"))

		' ---- is GOLD Member ----------------
		OpenConnection

		Set rs = DBC.Execute("SELECT * FROM Members WHERE IsGold = True AND EGold = " & MemberEGold)

		If Not rs.EOF Then
			Exit Sub
		End If
		' ------------------------------------

		BatchNumber	= Str2Num(Request("PAYMENT_BATCH_NUM"))

		SiteTitle		= RequestForm("SiteTitle")
		SiteURL		= Request.Form("SiteURL")
		URL		= Request.Form("URL")
		Banner		= Request.Form("Banner")
		Sponsor		= Str2Num(Request.Form("Sponsor"))

		' ----- add campaign -----
		DBC.Execute("INSERT INTO Campaigns " & _
				"(EGold, SiteTitle, SiteURL, VisitsLeft, BatchNumber) " & _
				"VALUES (" &	MemberEGold		& ", " & _
						EscapeSQLData(SiteTitle)	& ", " & _
						EscapeSQLData(SiteURL)	& ", " & _
						GoldFreeVisitors		& ", " & _
						BatchNumber		& ")")


		' ----- add banner -----
		DBC.Execute("INSERT INTO Banners " & _
				"(EGold, Banner, URL, BatchNumber, ValidTo) " & _
				"VALUES (" &	MemberEGold				& ", " & _
						EscapeSQLData(Banner)			& ", " & _
						EscapeSQLData(URL)			& ", " & _
						BatchNumber				& ", " & _
						EscapeSQLData(Date() + GoldBannerDays)	& ")")


		' ----- make member a GOLD member -----
		DBC.Execute("UPDATE Members SET IsGold = True WHERE EGold = " & MemberEGold)

		Session(Prefix & "IsGold") = True

		' ----- pay to sponsor if any -----
		If Sponsor > 0 Then
			Set rs = DBC.Execute("SELECT * FROM Members WHERE EGold = " & Sponsor)

			If Not rs.EOF Then
				If rs("IsGold") Then
					DBC.Execute("INSERT INTO Payouts (ToEGold, Cash, Description) " & _
						"VALUES (" &	Sponsor					& ", " & _
								GoldMembershipCommission4GoldMembers	& ", " & _
								"'" & SiteName & ": Referral upgrade'"	& ")")
				Else
					DBC.Execute("INSERT INTO Payouts (ToEGold, Cash, Description) " & _
						"VALUES (" &	Sponsor					& ", " & _
								GoldMembershipCommission4FreeMembers	& ", " & _
								"'" & SiteName & ": Referral upgrade'"		& ")")
				End If
			End If
		End If


		Application.Lock
		Application(Prefix & "TotalGoldMembers") = Str2Num(Application(Prefix & "TotalGoldMembers")) + 1
		Application.Unlock
	End Sub


	Function RequestForm(param)

		Dim x, qs
		Dim Separator	:	Separator = "&"

		qs = Request.Form.Item

		If Len(param) = 0 Then
			RequestForm = ""
			Exit Function
		End If

		If InStr(qs, "?" & param & "=") > 0 Then
			x = Right(qs, Len(qs) - InStr(qs, "?" & param & "=") - Len(param) - 1)

			If InStr(x, Separator) > 0 Then
				x = Left(x, InStr(x, Separator) - 1)
			End If
		End If

		If InStr(qs, Separator & param & "=") > 0 Then
			x = Right(qs, Len(qs) - InStr(qs, Separator & param & "=") - Len(param) - 1)

			If InStr(x, Separator) > 0 Then
				x = Left(x, InStr(x, Separator) - 1)
			End If
		End If

		RequestForm = x

	End Function
%>