<% Option Explicit %>
<!--#include file="config.asp"-->
<!--#include file="common.asp"-->
<!--#include file="adm_admin.asp"-->
<%
	Dim rs, Password

	PageHeader

	If Session("IsAdminLogin") Then
		PageMenu
	Else
		PageLogin
		Response.End
	End If


	Command = Request.Form("Command")


	OpenConnection

	If Command = "Save" Then
		SiteName			= Request.Form("SiteName")
		MyEGold				= Str2Num(Request.Form("MyEGold"))
		ContactEMail		= Request.Form("ContactEMail")
		ReferralCommission	= Str2Num(Request.Form("ReferralCommission"))
		PlayerEarnings		= Str2Num(Request.Form("PlayerEarnings"))
		MyCommission		= Str2Num(Request.Form("MyCommission"))
		Password			= Request.Form("Password")
		AltPass				= Request.Form("AltPass")

		DBC.Execute("UPDATE Admin SET " & _
			"Password			= " & EscapeSQLData(Password)		& "," & _
			"SiteName			= " & EscapeSQLData(SiteName)		& "," & _
			"MyEGold			= " & MyEGold						& "," & _
			"ContactEMail		= " & EscapeSQLData(ContactEMail)	& "," & _
			"AltPass			= " & EscapeSQLData(AltPass)		& "," & _
			"ReferralCommission	= " & ReferralCommission			& "," & _
			"PlayerEarnings		= " & PlayerEarnings				& "," & _
			"MyCommission		= " & MyCommission)

		Application("PL_MyEGold") = 0
	End If


	Edit
%>
	</body>
	</html>
<%


	Sub Edit()
		Set rs = DBC.Execute("SELECT Password, AltPass FROM Admin")

		If rs.EOF Then
			Password	= ""
			AltPass		= ""
		Else
			Password	= rs("Password")
			AltPass		= rs("AltPass")
		End If
%>
		<script language=JavaScript>
		<!--
		function Validate()
		{
			if (document.EF.SiteName.value.length == 0)
			{
				alert("Please enter Your site title.");
				document.EF.SiteName.focus();
				return false;
			}

			if (document.EF.MyEGold.value.length == 0)
			{
				alert("Please enter Your E-Gold number.");
				document.EF.MyEGold.focus();
				return false;
			}
			else
			{
				if (isNaN(document.EF.MyEGold.value))
				{
					alert("Please enter Your E-Gold number.");
					document.EF.MyEGold.focus();
					return false;
				}
			}

			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.EF.ContactEMail.value))
			{
			}
			else
			{
				alert("Please enter Your E-Mail address.");
				document.EF.ContactEMail.focus();
				return false;
			}

			if (document.EF.ReferralCommission.value.length == 0)
			{
				alert("Please enter a commission for direct referrals (%).");
				document.EF.ReferralCommission.focus();
				return false;
			}
			else
			{
				if (isNaN(document.EF.ReferralCommission.value))
				{
					alert("Please enter a commission for direct referrals (%).");
					document.EF.ReferralCommission.focus();
					return false;
				}
			}

			if (document.EF.PlayerEarnings.value.length == 0)
			{
				alert("Please enter a commission (%).");
				document.EF.PlayerEarnings.focus();
				return false;
			}
			else
			{
				if (isNaN(document.EF.PlayerEarnings.value))
				{
					alert("Please enter a commission (%).");
					document.EF.PlayerEarnings.focus();
					return false;
				}
			}

			if (document.EF.MyCommission.value.length == 0)
			{
				alert("Please enter a commission (%).");
				document.EF.MyCommission.focus();
				return false;
			}
			else
			{
				if (isNaN(document.EF.MyCommission.value))
				{
					alert("Please enter a commission (%).");
					document.EF.MyCommission.focus();
					return false;
				}
			}

			if (document.EF.Password.value.length == 0)
			{
				alert("Please enter a password.");
				document.EF.Password.focus();
				return false;
			}

			if (document.EF.AltPass.value.length == 0)
			{
				alert("Please enter your alternate e-gold's password.");
				document.EF.AltPass.focus();
				return false;
			}

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

		<form name=EF action="adm_main.asp" method=post onsubmit="return Validate()">
		<table border=0 align=center bgcolor=006699 cellspacing=1 cellpadding=3>
		<tr class=PageText bgcolor=006699>
			<td colspan=2 align=center>
				<font color=white>Common Information</font>
			</td>
		</tr>
		<tr class=PageText bgcolor=white>
			<td>
				Site Title
			</td>
			<td>
				<input name=SiteName value="<%= SiteName %>" size=25 maxlength=50 class=ClientText>
			</td>
		</tr>
		<tr class=PageText bgcolor=white>
			<td>
				Your E-Gold number
			</td>
			<td>
				<input name=MyEGold value="<%= MyEGold %>" size=25 maxlength=10 class=ClientText>
			</td>
		</tr>
		<tr class=PageText bgcolor=white>
			<td>
				Your E-Mail (contact e-mail)
			</td>
			<td>
				<input name=ContactEMail value="<%= ContactEMail %>" size=25 maxlength=50 class=ClientText>
			</td>
		</tr>
		<tr class=PageText bgcolor=white>
			<td>
				Commission for direct referrals (%)
			</td>
			<td>
				<input name=ReferralCommission value="<%= ReferralCommission %>" size=25 maxlength=5 class=ClientText>
			</td>
		</tr>
		<tr class=PageText bgcolor=white>
			<td>
				User winnings of his spend (%)
			</td>
			<td>
				<input name=PlayerEarnings value="<%= PlayerEarnings %>" size=25 maxlength=5 class=ClientText>
			</td>
		</tr>
		<tr class=PageText bgcolor=white>
			<td>
				My commission for every spend (%)
			</td>
			<td>
				<input name=MyCommission value="<%= MyCommission %>" size=25 maxlength=5 class=ClientText>
			</td>
		</tr>
		<tr class=PageText bgcolor=white>
			<td>
				Your password
			</td>
			<td>
				<input name=Password value="<%= Password %>" size=25 maxlength=25 class=ClientText>
			</td>
		</tr>
		<tr class=PageText bgcolor=white valign=top>
			<td>
				Your altername e-gold's password<br>
				(for transaction validity)
			</td>
			<td>
				<input name=AltPass value="<%= AltPass %>" size=25 maxlength=25 class=ClientText>
			</td>
		</tr>
		<tr>
			<td colspan=2 bgcolor=white align=center>
				<input type=submit name=Command value="Save">
			</td>
		</tr>
		</table>
		</form>
<%
	End Sub
%>