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

	If Request("Command") = "ThankYou" Then
%>
		<br><br>Thank you for becoming an Advertiser.<br>
		Use the link bellow to check your Advertising Stats<br><br>
		<b><%= CurrentPath %>advertiser.asp?EGold=<%= Request.Form("PAYER_ACCOUNT") %></b><br><br><br>
<%
	Else
		If Len(Request.Form.Item) < 10 Then
%>
			<p class=Title>Advertisers</p>
			<p align=right><a href=advertiser.asp>Check out your statistics.</a>&nbsp; &nbsp; &nbsp; &nbsp;</p>
<%
			PurchaseVisitors
			Response.Write "<br><br><br>"
			PurchaseBanners
		Else
			If IsValidPayment Then
				OpenConnection

				If Request.Form("Type") = "visitor" Then
					VisitorPayment
				Else
					BannerPayment
				End If

				If Str2Num(Request.Form("SpEGold")) <> 0 Then
					DBC.Execute("INSERT INTO Payouts (ToEGold, Cash, Description) " & _
							"VALUES (" &	Str2Num(Request.Form("SpEGold"))				& ", " & _
									CDbl(Request("PAYMENT_AMOUNT")) * AdvCommission / 100		& ", " & _
									"'" & SiteName & ": " & AdvCommission & "% commission on adv. sale'"	& ")")
				End If

				Response.End
			End If
		End If
	End If
	PageEnd


	Sub PurchaseVisitors()
%>
		<form name=VF action="https://www.e-gold.com/sci_asp/payments.asp" method="post" onsubmit="return AddVisitors()">
		<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="Visitors SpEGold SiteTitle SiteURL Type EMail">
		<input type="hidden" name="SpEGold" value="<%= Session(Prefix & "SponsorEGold") %>">
		<input type="hidden" name="SUGGESTED_MEMO" value="<%= SiteName %> link">
		<input type="hidden" name="Type" value="visitor">

		<font size=+1>Purchase Unique Visitors</font>

		<blockquote width="90%">
		<p align="left" class="PageText">
		Our members are all waiting eagerly for your website because we pay them well to do so. 
		In order to receive cash, a member must stay on your site for a full <%=MemberDelay %> seconds. 
		Each member will only be able to view your website one time. 
		We now accept e-gold.<br><br>

		The information bellow 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.
		</p>
		</blockquote>

		<table border="0" cellpadding="2" cellspacing="0">
		<tr class="Odd" valign="top">
			<td>Purchase</td>
			<td>
				<% VisitorPackage %>
				<input type="hidden" name="PAYMENT_AMOUNT" value="">
			</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="100" class="ClientText">
			</td>
		</tr>
		<tr class=Odd>
			<td>Your E-Mail</td>
			<td>
				<input name="EMail" value="" size="50" class="ClientText">
			</td>
		</tr>
		<tr class=Odd>
			<td valign="top" colspan="2" align="center">
				<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 AddVisitors()
		{
			if (document.VF.SiteTitle.value.length < 3)
			{
				alert ("Please enter a Site's Title.");
				document.VF.SiteTitle.focus();
				return false;
			}

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

			if (! /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.VF.EMail.value))
			{
				alert ('Please enter a valid e-mail address.');
				document.VF.EMail.focus();
				return false;
			}

			return true;
		}

		function SetAmount()
		{
			document.VF.PAYMENT_AMOUNT.value = parseInt(document.VF.Visitors(document.VF.Visitors.selectedIndex).value) * <%= PageCost4GoldMembers + ReferralCommission + MyCommission %>;
			document.VF.PAYMENT_AMOUNT.value = document.VF.PAYMENT_AMOUNT.value.substr(0, 7);
		}

		SetAmount()
		//-->
		</script>
<% 
	End Sub



	Sub PurchaseBanners()
%>
		<font size=+1>Purchase Unlimited Banner Impressions</font>

		<blockquote>
		<p align="left" class="PageText">
		Your banner inserted into our banner rotation on the top of each 
		page of the website. This is a great way to catch peoples interest, 
		just as much publicity, if not more than, advertising in the member 
		e-mails. The banners will be displayed on every page of the site, 
		randomly mixed in with other banners.<br><br>

		The information bellow 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.
		</p>
		</blockquote>

		<form name=BF action="https://www.e-gold.com/sci_asp/payments.asp" method="post" onsubmit="return AddBanner()">
		<input type="hidden" name="PAYEE_ACCOUNT" value="<%= MyEGold %>">
		<input type="hidden" name="PAYEE_NAME" value>
		<input type="hidden" name="PAYMENT_AMOUNT" value="<%= BannerCost4aMonth %>">
		<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 %> Banner for a month">
		<input type="hidden" name="SpEGold" value="<%= Session(Prefix & "SponsorEGold") %>">
		<input type="hidden" name="Type" value="banner">

		<table border="0">
		<tr class=Odd>
			<td>Site's URL</td>
			<td>
				<input name="URL" value="http://" size="50" class="ClientText">
			</td>
		</tr>
		<tr class=Odd>
			<td>Banner's URL</td>
			<td>
				<input name="Banner" value="http://" size="50" class="ClientText">
			</td>
		</tr>
		<tr class=Odd>
			<td>Your E-Mail</td>
			<td>
				<input name="EMail" value="" size="50" class="ClientText">
			</td>
		</tr>
		<tr class=Odd>
			<td>Cost for a month</td>
			<td>
				<b>$<%= BannerCost4aMonth %></b>
			</td>
		</tr>
		</table>
		<br>

		<input type="hidden" name="BAGGAGE_FIELDS" value="SpEGold URL Banner EMail Type">
		<input type="image" name="PAYMENT_METHOD" src="images/egold.gif" alt="Pay through e-gold" WIDTH="88" HEIGHT="31">
		</form>


		<script language="JavaScript">
		<!--
		function AddBanner()
		{
			if (document.BF.URL.value.length < 10)
			{
				alert ("Please enter a Site's URL.");
				document.BF.URL.focus();
				return false;
			}

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

			if (! /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.BF.EMail.value))
			{
				alert ('Please enter a valid e-mail address.');
				document.BF.EMail.focus();
				return false;
			}

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


	Sub VisitorPayment()
		Dim rs, BatchNumber, PAYER_ACCOUNT, Visitors, SiteTitle, SiteURL, EMail

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

		BatchNumber	= Str2Num(Request("PAYMENT_BATCH_NUM"))

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

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

		PAYER_ACCOUNT	= Str2Num(Request("PAYER_ACCOUNT"))
		Visitors		= Str2Num(Request("Visitors"))
		SiteTitle		= RequestForm("SiteTitle")
		SiteURL		= Request.Form("SiteURL")
		EMail		= Request("EMail")

		' ----- add campaign -----
		DBC.Execute("INSERT INTO Campaigns " & _
				"(EGold, SiteTitle, SiteURL, VisitsLeft, BatchNumber, EMail) " & _
				"VALUES (" &	PAYER_ACCOUNT		& ", " & _
						EscapeSQLData(SiteTitle)	& ", " & _
						EscapeSQLData(SiteURL)	& ", " & _
						Visitors			& ", " & _
						BatchNumber		& ", " & _
						EscapeSQLData(EMail)	& ")")
	End Sub


	Sub BannerPayment()
		Dim rs, BatchNumber, PAYMENT_AMOUNT, PAYER_ACCOUNT, Banner, URL, EMail

		' ---- 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(BannerCost4aMonth) Then
			Exit Sub
		End If
		' ------------------------------------

		BatchNumber	= Str2Num(Request("PAYMENT_BATCH_NUM"))

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

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

		PAYER_ACCOUNT	= Str2Num(Request("PAYER_ACCOUNT"))
		URL		= Request.Form("URL")
		Banner		= Request.Form("Banner")
		EMail		= Request("EMail")

		' ----- add banner -----
		DBC.Execute("INSERT INTO Banners " & _
				"(EGold, Banner, URL, BatchNumber, EMail, ValidTo) " & _
				"VALUES (" &	PAYER_ACCOUNT			& ", " & _
						EscapeSQLData(Banner)		& ", " & _
						EscapeSQLData(URL)		& ", " & _
						BatchNumber			& ", " & _
						EscapeSQLData(EMail)		& ", " & _
						EscapeSQLData(Date() + 31)	& ")")
	End Sub


	Sub VisitorPackage()

		Dim i, v

		Response.Write "<select name=Visitors class=ClientText size=7 onchange='SetAmount()' style='width:100%'>"

		v = Split(Trim(VisitorPackages), " ")

		For i = 0 To UBound(v)
			Response.Write "<option value=" & v(i)

			If i = 0 Then
				Response.Write " selected"
			End If

			Response.Write ">" & v(i) & " unique visitors just for $" & FormatNumber(v(i) * (PageCost4GoldMembers + ReferralCommission + MyCommission), 2) & "</option>" & vbNewLine
		Next

		Response.Write "</select>"
	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
%>