<%
	Dim DBC, Command, rsUser

	Command = Request.Querystring("Command")


	If Command = "LogIn" Then
		Session("IsAdminLogin") = (MyEGold = Str2Num(Request.Form("EGold")) And LCase(Password) = LCase(Request.Form("Password")))
	End If

	If Command = "LogOut" Then
		Session("IsAdminLogin") = False
		Response.Redirect "admin_stat.asp"
	End If

	If Not IsEmpty(Request.QueryString("Ref")) Then
		Session("EO_Ref") = Request.QueryString("Ref")
	End If



	Sub OpenConnection()
		Set DBC = Server.CreateObject("ADODB.Connection")
		DBC.Open "DBQ=" & Server.MapPath("EvenOdd.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;MaxBufferSize=8192;Threads=20;", "", "pass"
	End Sub


	Sub PageHeader()

	Response.Expires = -1
%>
	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
	<html>
	<head>
	<title><%= SiteName %></title>
	<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
	<meta name=author content="http://free-sign-up.com/LowCostScripts">
	<link rel=stylesheet href=common.css>
	</style>
	</head>
	<body>
<%
	End Sub


	Sub PageBegin(Title)
%>
	<table border=0 cellspacing=0 cellpadding=0 width=100% height="100%">
	<tr>
		<td background="images/topbg.gif" height="70" width="100%">
			&nbsp;<font face=Arial size=9 color=black><b><%= SiteName %></b></font>
		</td>
	</tr>
	<tr valign="top">
		<td valign="top">
			<table width="100%" cellspacing=0 cellpadding="3" border=0 class="border" height="100%">
			<tr valign="top">
				<td valign="top" background="images/bg.gif" height="20" class="border" colspan=2>
					<b><%= Title %></b>
				</td>
			</tr>
			<tr valign="top">
				<td valign="top" abgcolor=EFD7A5 bgcolor=F7F3CE>
<%
	End Sub


	Sub PageEnd()
%>
				</td>
				<td width=200 align=center valign="top" bgcolor=F7F3CE>
					<a href=default.asp><b>Play</b></a><br>
					<a href=payouts.asp><b>Payouts</b></a><br>
					<a href=mailto:<%= ContactEMail %>><b>Contact Us</b></a><br>
					<a href="javascript:window.external.AddFavorite('<%= CurrentPath %>','<%= SiteName %>')"><b>Bookmark Us</b></a><br>
					<br>
					<% Links %>
				</td>
			</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td align=center class=PageText width=100% height=30 background=images/bgdown.gif>
			Copyright 2003 © <%= SiteName %>  All Rights Reserved
		</td>
	</tr>
	<tr>
		<td align=center class=PageText width="100%" height="30">
			Website development by <a href="http://free-sign-up.com/LowCostScripts/" target=_blank>Low Cost Scripts</a>
		</td>
	</tr>
	</table>

	</body>
	</html>
<%
	End Sub


	Function IIf(cond, value1, value2)
		If cond Then IIf = value1 Else IIf = value2 End If
	End Function


	Function HTMLEncode(s)
		If IsNull(s) Then
			HTMLEncode = ""
		Else
			HTMLEncode = Server.HTMLEncode(s)
		End If
	End Function


	Function EscapeSQLData(s)
		If IsNull(s) Then
			EscapeSQLData = "''"
		Else
			EscapeSQLData = "'" & Replace(s, "'", "''") & "'"
		End If
	End Function


	Function Str2Num(s)
		If IsNull(s) Then
			Str2Num = 0
		Else
			If IsNumeric(s) Then
				Str2Num = CLng(s)				
			Else
				Str2Num = 0
			End If
		End If
	End Function


	Function Str2Float(s)
		If IsNull(s) Then
			Str2Float = 0
		Else
			If IsNumeric(s) Then
				Str2Float = CDbl(s)
			Else
				Str2Float = 0
			End If
		End If
	End Function


	Function CurrentPath()
		Dim s
		s = Request.ServerVariables("SCRIPT_NAME")

		s = Left(s, InStrRev(s, "/"))

		CurrentPath = "http://" & Request.ServerVariables("SERVER_NAME") & s
	End Function


	Function CurrentFile()
		CurrentFile = "http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("SCRIPT_NAME")
	End Function



	Function IsValidPayment()
		Dim MD, MD5String

		Set MD = New MD5

		MD5String =	Request("PAYMENT_ID")				& ":" & _
					Request("PAYEE_ACCOUNT")			& ":" & _
					Request("PAYMENT_AMOUNT")			& ":" & _
					Request("PAYMENT_UNITS")			& ":" & _
					Request("PAYMENT_METAL_ID")			& ":" & _
					Request("PAYMENT_BATCH_NUM")		& ":" & _
					Request("PAYER_ACCOUNT")			& ":" & _
					MD.DigestStrToHexStr(AltPass)		& ":" & _
					Request("ACTUAL_PAYMENT_OUNCES")	& ":" & _
					Request("USD_PER_OUNCE")			& ":" & _
					Request("FEEWEIGHT")				& ":" & _
					Request("TIMESTAMPGMT")

		IsValidPayment = (MD.DigestStrToHexStr(MD5String) = Request("V2_HASH"))
	End Function


	Sub Links()
		Dim TBGcolor, BGcolor, rsLinks, i

		TBGcolor	= "F9D47E"
		BGcolor		= "white"

		OpenConnection

		Set rsLinks = DBC.Execute("SELECT Title, URL FROM Links WHERE DateDiff('d', '" & Date() & "', ValidTo) >= 0")

		Response.Write "<table align=center cellpadding=2 cellspacing=1 width=100% bgcolor=" & TBGcolor & ">"
		Response.Write "<col align=center>"

		Response.Write "<tr><td align=center>" & _
					"<font face=Tahoma color=555555 size=3><b>Advertise Here</b></font></td>" & _
					"</tr><tr bgcolor=" & BGcolor & ">"

		Do While Not rsLinks.EOF
			Response.Write "<tr bgcolor=" & BGcolor & "><td><a href='" & rsLinks("URL") & "' target=_new>" & rsLinks("Title") & "</a></td></tr>"

			rsLinks.MoveNext
		Loop

		For i = 1 To 6
			Response.Write "<tr bgcolor=" & BGcolor & "><td bgcolor=EEEEEE><a href='" & CurrentPath & "addlink.asp'>add link for $" & LinkCost4aMonth & " / month</a></td></tr>"
		Next

		Response.Write "</table>"
	End Sub


	' Admin subs and functions ----------------------
	Sub UserLogin()
%>
		<form name=F action="admin_stat.asp?Command=LogIn" method="post" onsubmit="return EGoldPresent() && PasswordPresent()">
		<p align="center" class="PageText">
			E-Gold
			<input name="EGold" size="15" maxlength="20" class="ClientText">
			&nbsp;&nbsp;&nbsp;
			Password
			<input type="Password" name="Password" size="15" maxlength="20" class="ClientText">
			&nbsp;
			<input type="submit" value="Log In" class="Button">
		</p>
		</form>

		<script language="JavaScript">
		<!--
		function EGoldPresent()
		{
			if (document.F.EGold.value.length == 0)
			{
				alert ('Please enter your E-Gold number.');
				document.F.EGold.focus();
				return false;
			}

			return true;
		}

		function PasswordPresent()
		{
			if (document.F.Password.value.length == 0)
			{
				alert ('Please enter your password.');
				document.F.Password.focus();
				return false;
			}

			return true;
		}
		//-->
		</script>

		<script language=JavaScript for=window event=onload>
		<!--
			document.F.EGold.focus();
		//-->
		</script>
<%
	End Sub


	Sub AdminMenu()
%>
	<table border=0 width=100% cellspacing=0 cellpadding=2 bgcolor=006699>
	<tr>
		<td align="center" class=PageText bgcolor="FFD695">
			<a href="admin_payments.asp">Send Money</a>&nbsp;|&nbsp;
			<a href="admin_links.asp">Links</a>&nbsp;|&nbsp;
			<a href="admin_stat.asp">Balance</a>&nbsp;|&nbsp;
			<a href="default.asp?Command=LogOut">Log Out</a>
		</td>
	</tr>
	</table>
<%
	End Sub
%>