<!--#include file="../owFunctions/I_GeneralFunctions.asp"-->
<%
	'************************************************************************************
	'*																					*
	'*	MODIFICATION TO THIS SCRIPT OR ANY FILES INCLUDED WITH 							*
	'*		ONEWORLDSTORE IS DONE AT YOUR OWN RISK!										*
	'*	Product  : OneWorldStore														*
	'*	Version  : 9.0000																*
	'*	Modified : June 2004															*
	'*	Copyright:	Copyright (C) 2004 OneWorldStore.Com								*
	'*				Registration Number: 1024507										*
	'*				http://strategis.ic.gc.ca/											*
	'*																					*
	'************************************************************************************
	
	Dim sAction, sError, sSuccess, sEmail, sRedirectUrl
	Dim sEmailBody, sSubject, sForgottenEmail
	
	Call SF_OpenPage()	' call this to populate the cart information - this is also called in the template, but since we are doing this out of order, we need a special case here
	Call owMain()
	
	' must put the include down here so that the ActionSubroutine() Sub will have access to the globals
	'	that are set in owMain()
	%><!--#include file="../owTemplates/Template_AllLeft.asp"--><%
	
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Sub owMain()
		sAction = Trim(Request("sAction"))
		sError	= ""
		
		Select Case sAction
			Case "Login"
				sEmail 			= CONVERSION_SQLEncode2(Request("sEmail"),50)
				sPassword 		= CONVERSION_SQLEncode2(Request("sPassword"),50)
				sRedirectUrl 	= CONVERSION_SQLEncode2(Request("sRedirectUrl"),50)
				
				If ( ( sEmail = "" ) Or ( sPassword = "" ) ) Then
					sError = LANG_DT( "AUTHCUST_ENTEREMAIL", "Please enter your email and password to log into your account and checkout." )
				Else
					sPassword = EnCrypt(sPassword, sOWEncryptionPassword)
					sSQLText = "SELECT AccountUnq FROM owAccounts WHERE Login = '" & sEmail & "' AND Password = '" & sPassword & "' AND ( AddDate > RemoveDate OR RemoveDate IS NULL ) AND Authenticated = 'Y'"
					Call DB_getFromDatabase(sSQLText, rsStoreData, "") 
					If ( rsStoreData.EOF ) Then
						sError = LANG_DT( "AUTHCUST_NOTVALIDATE", "Unable to validate your password. Please go back and try again." )
					Else
						Session("Login")		= sEmail
						Session("Password")		= sPassword
						Session("AccountUnq")	= rsStoreData("AccountUnq")
						Session("Auto")			= "N"	' for future use
		
						Call DB_closeRecordset(rsStoreData)
						if sRedirectUrl = "" then
							response.redirect "CustomerAdmin/owCustomerAdminMain.asp"
						else
							Select Case sRedirectUrl
								Case "1"
									Response.Redirect "owCheckOut.asp"	' coming from the owCheckOut.asp page and they weren't logged in
								Case Else
									Response.Redirect "CustomerAdmin/owCustomerAdminMain.asp"	' coming from anywhere else
							End Select
						End If
					End If
				End If
				
		End Select
	
	End Sub
	'************************************************************************************
		
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Sub ActionSubroutine()

		if ( bHasAccount ) then
			response.redirect "CustomerAdmin/owCustomerAdminMain.asp"
		Else
			If ( sError <> "" ) Then
				Call owMessage(sError, C_ERROR)
			End If
			If ( sSuccess <> "" ) Then
				Call owMessage(sSuccess, C_SUCCESS)
			End If
			%>
			<script type="text/javascript" src="../owManager/Script/fValConfig.js"></script>
			<script type="text/javascript" src="../owManager/Script/fValidate.js"></script>
			
			<script language='JavaScript1.2' type='text/javascript'>
		
				function SubmitForm(objForm, sAction){
				
					if ( validateForm( objForm, false, false, false, true, 17 ) )
					{
						objForm.sAction.value = sAction;
						objForm.submit();
					}else{
						return false;
					}
				}
				
			</script>

			<center>
			<table width=<%=sOWStoreTableWidth%> border=0 style='border: 1px solid #000000;' cellspacing=0 cellpadding=5>
			<form method="post" name="auth" action="owCustomerAuthenticate.asp" onSubmit='return SubmitForm(this, "Login");'>
			<input type="hidden" name="sAction" value="Login">
			<input type="hidden" name="sRedirectUrl" value="<%=Server.HTMLEncode(Trim(Request("sRedirectUrl")))%>">
				<tr bgcolor="#eeeeee"><td colspan=3 style='border-bottom: 1px solid #000000;'><b><%=LANG_DT( "CHECKOUT_CUSTLOGIN", "Customer Log In" )%></b></td></tr>
				<tr>
					<td><%=LANG_DT( "CHECKOUT_LOGINEMAIL", "E-mail" )%></td>
					<td><%VALIDATE_textbox "sEmail", "", 50, "textbox", "blank"%></td>
					<td valign=center rowspan=3>
						<table border=0 cellspacing=0 cellpadding=5>
							<tr>
								<td>
									<%if bOWAllowNewCustomer then%>
									<i><%=LANG_DT( "CHECKOUT_NOTMMBR", "Not a member yet?" )%><br>
									<a href="owRegister.asp"><%=LANG_DT( "CHECKOUT_CLICKTOREG", "Click here to register." )%></a></i><br>
									<%End If%>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td><%=LANG_DT( "CHECKOUT_PW", "Password" )%></td>
					<td><%VALIDATE_textbox "sPassword", "", 50, "password", "blank"%></td>
				</tr>
				<tr>
					<td colspan=2>
						<input type="submit" name="Submit" value=" <%=LANG_DT( "CHECKOUT_LOGIN", "Log In" )%> &gt; ">
					</td>
				</tr>
			</table>
			</form>
			<%
		End If
		
	End Sub
	'************************************************************************************
%>