<%
	Option Explicit
	Response.Buffer=True       
    Const vDebug = 0
	'@BEGINVERSIONINFO

	'@APPVERSION: 5.10.10

	'@FILENAME: process_order.asp
		
	'@FILEVERSION: 1.0.2

     '@VERSIONDATETIME: 3/1/01
	
	'@DESCRIPTION: Gathers Information For order.

	'@STARTCOPYRIGHT
	'The contents of this file is protected under the United States
	'copyright laws  and is confidential and proprietary to
	'LaGarde, Incorporated.  Its use or disclosure in whole or in part without the
	'expressed written permission of LaGarde, Incorporated is expressly prohibited.
	'
	'(c) Copyright 2000,2001 by LaGarde, Incorporated.  All rights reserved.
	'@ENDCOPYRIGHT

	'@ENDVERSIONINFO

%>

<!--#include file="SFLib/db.conn.open.asp"-->
<!--#include file="SFLib/incProcOrder.asp"-->
<!--#include file="error_trap.asp"-->
<!--#include file="SFLib/incDesign.asp"-->
<!--#include file="SFLib/incGeneral.asp"-->
<!--#include file="SFLib/ADOVBS.inc"-->
<SCRIPT language="javascript" src="SFLib/sfCheckErrors.js"></SCRIPT>
<%
Dim sSql,sEmail,iOrderID,rsMyOrders, sPassword, iAuthenticate, bLoggedIn, sCondition, sPaymentMethod, sPaymentList
Dim sProdID,iQuantity,iShip,sTotalPrice,strProdID,intQuantity,rstAdmin,sTotalCost,blnFree, iFreeShip
' initially false
bLoggedIn = false
iShip = 0
sSQL = "SELECT * FROM sfTmpOrderDetails WHERE odrdttmpShipping >= 1 AND odrdttmpSessionID = " & Session("SessionID")
Set rsMyOrders = Server.CreateObject("ADODB.RecordSet")
Set rstAdmin = Server.CreateObject("ADODB.RecordSet")
rsMyOrders.Open sSQL, cnn, adOpenForwardOnly, adLockReadOnly, adCmdText
rstAdmin.Open "sfAdmin", cnn, adOpenForwardOnly, adLockReadOnly, adCmdTable
sTotalPrice =Request.Form("TotalPrice")

If Not rsMyOrders.EOF Then
rsMyOrders.MoveFirst 
iShip = 0
Do While NOT rsMyOrders.EOF
 iShip = iShip + rsMyOrders.Fields("odrdttmpShipping")
  rsMyOrders.MoveNext 
loop
End If

blnFree =False
if iShip <> 0 then
iFreeShip = rstAdmin.Fields("adminFreeShippingIsActive") 
  if (cdbl(sTotalPrice) > cdbl(rstAdmin.Fields("adminFreeShippingAmount")) AND iFreeShip = "1")  then
    blnFree =True
  end if
elseif iShip = 0 then
   blnFree =True
     else
  blnFree =False
     end if  
rsMyOrders.Close 
rstAdmin.Close 
 set rstAdmin =nothing
 set rsMyOrders = nothing    

'-------------------------------------------------------
' See if session is repeating, if so, give new id to use
'-------------------------------------------------------
If Session("SessionID") = Request.Cookies("EndSession") Then	
	bLoggedIn = false
End If	

'-------------------------------------------------------
' Check if custID exists 
'-------------------------------------------------------
iCustID = Session("custID")
If iCustID <> "" Then
	 Dim bCustIdExists
	   	bCustIdExists = CheckCustomerExists(iCustID)
    	If bCustIdExists = false Then
    		Response.Cookies("sfCustomer")("custID") = ""
	   		Response.Cookies("sfCustomer").Expires = NOW()
	   	Else
			Response.Cookies("sfCustomer")("custID") = iCustID
			Response.Cookies("sfCustomer").Expires = Date() + 730
		End If
End If	
	
If Request.Cookies(Session("GeneratedKey") & "sfOrder")("SessionID") = Session("SessionID") AND Request.Cookies(Session("GeneratedKey") & "sfOrder")("SessionID") <> ""  AND bCustIdExists Then
	bLoggedIn = true
End If

' Get Payment List
	sPaymentList = getPaymentMethods()

'-------------------------------------------------------
' If login button is depressed
'-------------------------------------------------------
If Trim(Request.Form("btnLogin.x")) <> "" Then
	
	sEmail			= Trim(Request.Form("Email"))
	sPassword		= Trim(Request.Form("Passwd"))
	
	' Authenticate
	iAuthenticate	= customerAuth(sEmail,sPassword,"loose")
		
	If iAuthenticate > 0 Then
		If Request.Cookies("sfCustomer")("custID") <> "" AND iAuthenticate <> Request.Cookies("sfCustomer")("custID")  Then
			Dim bSvdCartCust
			bSvdCartCust = CheckSavedCartCustomer(Request.Cookies("sfCustomer")("custID"))
			'Response.write "Saved Cart Cust?" & Request.Cookies("sfCustomer")("custID") & "False?" & bSvdCartCust 
			If bSvdCartCust Then
				' Delete SvdCartCustomer Row
				Call DeleteCustRow(Request.Cookies("sfCustomer")("custID"))
				' See if saved cart has any remaining saved
				Call setUpdateSavedCartCustID(iAuthenticate,Request.Cookies("sfCustomer")("custID"))
			End If
		End If	
		Response.Cookies(Session("GeneratedKey") & "sfOrder")("SessionID") = Session("SessionID")
		Response.Cookies(Session("GeneratedKey") & "sfOrder").Expires = Date() + 1
		Response.Cookies("sfCustomer")("custID") = iAuthenticate
		Response.Cookies("sfCustomer").Expires = Date() + 730
		Session("custID") = iAuthenticate
		bLoggedIn = true
		iCustID = iAuthenticate
	Else 	
		If customerAuth(sEmail,sPassword,"loosest") > 0 Then
			sCondition = "EmailMatch"   
			Response.Cookies("sfCustomer").Expires = Now()
		Else 
			sCondition = "WrongCombination"
			Response.Cookies("sfCustomer").Expires = Now()		
		End If			
	End If			
End If		
%>

<html>
<input type="hidden" name="FreeShip" value="<%= blnFree %>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>SF Information Gathering Page for Check Out/Second Step in Checkout</title>
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
</head>


<body background="<%= C_BKGRND %>" bgproperties="fixed" bgcolor="<%= C_BGCOLOR %>" link="<%= C_LINK %>" vlink="<%= C_VLINK %>" alink="<%= C_ALINK %>">
<table border="0" cellpadding="1" cellspacing="0" bgcolor="<%= C_BORDERCOLOR1 %>" width="<%= C_WIDTH %>" align="center">
  <tr>
    <td>
      <table width="100%" border="0" cellspacing="1" cellpadding="2">
        <tr>
          <%If C_BNRBKGRND = "" Then%>
            <td align="middle" width="100%" background="<%= C_BKGRND1 %>" bgcolor="<%= C_BGCOLOR1 %>"><b><font face="<%= C_FONTFACE1 %>" color="<%= C_FONTCOLOR1 %>" SIZE="<%= C_FONTSIZE1 %>"><%= C_STORENAME %></font></b></td>
		  <%Else%>
			<td align="middle" width="100%" bgcolor="<%= C_BNRBGCOLOR %>"><img src="<%= C_BNRBKGRND %>" border="0"></td>
		  <%End If%>
        </tr>
        <tr>
          <td align="center" background="<%= C_BKGRND2 %>" bgcolor="<%= C_BGCOLOR2 %>"><b><font face="<%= C_FONTFACE2 %>" color="<%= C_FONTCOLOR2 %>" SIZE="<%= C_FONTSIZE2 %>">Customer Information</font></b></td>
        </tr>
        <tr>
          <td background="<%= C_BKGRND3 %>" bgcolor="<%= C_BGCOLOR3 %>" align="left"><font face="<%= C_FONTFACE3 %>" color="<%= C_FONTCOLOR3 %>" size="<%= C_FONTSIZE3 %>">
            <p style="margin-top:1pt">
This is the final step in completing your order. You are now connected using a secure (SSL) connection and all information is transmitted in an encrypted form. 
You should see a small key (Netscape) or lock (IE) indicating that your browser is communicating securely with our web store.
		    </font>
            </p>
          </td>    
        </tr>	
        <tr>
          <td width="100%" align="center" bgcolor="<%= C_BGCOLOR4 %>" align="center" valign="center"><font face="<%= C_FONTFACE3 %>" color="<%= C_FONTCOLOR4 %>" size="<%= C_FONTSIZE4 %>"><b>Step 1: Customer Information</b> | Step 2: Payment Information | Step 3: Complete Order</font></td>
        </tr>
        <tr valign="center">
          <td width="100%" bgcolor="<%= C_BGCOLOR4 %>" align="center" valign="center"> 	
            <% If Not bLoggedIn Then %>   

			   <br>
		       <form action="process_order.asp" method="post" name="frmEmail"> 
		        <input type="hidden" name="FreeShip" value="<%= blnFree %>">
		        <table border="0" width="100%" cellpadding="5" cellspacing="1">
		          <tr>
		            <td width="50%" align="center" bgcolor="<%= C_BGCOLOR4 %>" align="center" valign="center">
					  <table border="0" bgcolor="#000000" width="100%" cellpadding="3" cellspacing="1">
						<tr>
						  <td width="100%" align="center" bgcolor="<%= C_BGCOLOR3 %>"><font face="<%= C_FONTFACE3 %>" color="<%= C_FONTCOLOR3 %>" size="<%= C_FONTSIZE3 + 1 %>"><b>Returning Customer Login</b></font></td>		        
						</tr>
						<tr>
						  <td width="100%" align="center" valign="center" bgcolor="<%= C_BGCOLOR4 %>">
					        <table border="0" width="100%" cellpadding="2">
							  <tr>
							    <td width="15%" align="right"><b><font face="<%= C_FONTFACE4 %>" color="<%= C_FONTCOLOR4 %>" size="<%= C_FONTSIZE4 %>"> E-Mail:</font></b></td>
							    <td width="85%"><input type="text" size="35" name="Email"  title="E-Mail Address" style="<%= C_FORMDESIGN %>"></td>
							  </tr>
							  <tr>
							    <td width="15%" align="right"><b><font face="<%= C_FONTFACE4 %>" color="<%= C_FONTCOLOR4 %>" size="<%= C_FONTSIZE4 %>">Password:</font></b></td>
							    <td width="85%"><input type="password" size="35" name="Passwd" title="Password" style="<%= C_FORMDESIGN %>"></td>
							  </tr>
							  <tr>
							    <td width="100%" align="middle" colspan="2">
							      <input Type="image" src="<%= C_BTN16 %>" name="btnLogin" border="0">
							    </td>
							  </tr>
					        </table>					    
						  </td>
						</tr>
						<tr>
						  <td width="100%" align="center" bgcolor="<%= C_BGCOLOR4  %>"><font face="<%= C_FONTFACE3 %>" color="<%= C_FONTCOLOR3 %>" size="<%= C_FONTSIZE3 %>"><a href="password.asp?status=fpwd">Forgot your password?</a> <br> <a href="password.asp?status=change">Change Login/Password</a></font></td>		        
						</tr>
					  </table>
				    </td>
				    <td width="50%" bgcolor="<%= C_BGCOLOR4 %>">
				      <center>
				      <font face="<%= C_FONTFACE3 %>" color="<%= C_FONTCOLOR4 %>" size="<%= C_FONTSIZE4 + 1 %>"><b>
				      <% If sCondition = "EmailMatch" or sCondition = "WrongCombination" Then %>	
				      <font color="red">Login Failed</font>
				      <% Else %>
						Login Directions
				      <% End If %>
				      </b></font>	
				      <hr width="90%" noshade size="1">
				      </center>
				      <font face="<%= C_FONTFACE4 %>" color="<%= C_FONTCOLOR4 %>" size="<%= C_FONTSIZE3 %>">
					  <% If sCondition = "EmailMatch" Then %>	
						Your combination was wrong, but an e-mail match was found. Please login with the correct password or if you wish to open a new account, you must choose a new password.
					  <% ElseIf sCondition = "WrongCombination" Then %> 		
						Your e-mail and password combination is incorrect. Try again.
					  <% Else %>	
						Please use your e-mail address and password to log in and retrieve your customer information.
					  <% End If %>					
		              </font>
		            </td>
		          </tr>
		        </table>	
		        <input type="hidden" name="TotalPrice" value="<%= sTotalPrice %>">
		        <input type="hidden" name="FreeShip" value="<%= blnFree %>">
		        <input type="hidden" name="bShip" value="<%= iShip %>">
		        </form>		
	        <% End If %>		
	        <!--#include file="orderform.asp"-->	  
	
            <!--#include file="footer.txt"-->    
          </td>
        </tr>
      </table> 
     </td>
     </tr>
     </table>
     <input type="hidden" name="FreeShip" value="<%= blnFree %>">
     <input type="hidden" name="TotalPrice" value="<%= sTotalPrice %>">
      <input type="hidden" name="bShip" value="<%= iShip %>">
</body>







