<!--#include file="../owFunctions/I_GeneralFunctions.asp"-->
<!--#include file="../owTemplates/Template_AllLeft.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 sFName, sLName, sCustomerCompany
	Dim sEmail, sPhone, sAddress, sZip, sStateCode
	Dim sState, sCity, sCountryCode, sShippingName, sShippingLastName, sShippingAddress, sShippingZip
	Dim sShippingStateCode, sShippingState, sShippingCity, sShippingCountryCode
	Dim sCartTax, aTaxStateInfo, aTaxCountryInfo	' globals required for CART_CalculateTax()
	Dim sShipmentTotal, sShipmentDesc, sHandlingFee, sHandlingVisibility

	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Sub ActionSubroutine()

		Dim rsStoreData3
		
		sError					= Trim(Request("sError"))
		Set rsStoreData3		= CreateObject("ADODB.Recordset")
		sOWCompanyAddress		= owCONFIG_ReturnConfigValue("sOWCompanyAddress")
		sOWCompanyZip			= owCONFIG_ReturnConfigValue("sOWCompanyZip")
		sOWCompanyCity			= owCONFIG_ReturnConfigValue("sOWCompanyCity")
		sOWCompanyStateCode		= owCONFIG_ReturnConfigValue("sOWCompanyStateCode")
		sOWCompanyCountryCode	= owCONFIG_ReturnConfigValue("sOWCompanyCountryCode")
		sOWCompanyPhone			= owCONFIG_ReturnConfigValue("sOWCompanyPhone")
		sOWCompanyFax			= owCONFIG_ReturnConfigValue("sOWCompanyFax")
		bOWTaxShipping			= owCONFIG_ReturnConfigValue("bOWTaxShipping")
		sPaymentMethod			= CInt(SQLEncode(Trim(Request("sPaymentMethod"))))
		sPaymentMethodFee		= 0
		pCanUseCode				= -1
		sShipmentDesc			= ""
		sShipmentTotal			= 0
		sTaxAmount				= 0
		
		If ( sError <> "" ) Then
			' the customer tried to submit an invalid amount or value as credit to use to pay for this order
			'	and since we don't want to have to carry large amounts of data on the querystring, read the comments, etc. from the database
			sSQLText = "SELECT CustomerComments, VatNumber, user1, user2, user3 FROM Orders WHERE SessionID = '" & Session.SessionID & "' AND OrderStatus = 7"
			Call DB_getFromDatabase(sSQLText, rsStoreData, "")   
			If ( NOT rsStoreData.EOF ) Then
				sComments		= rsStoreData("CustomerComments")
				sVatNumber		= rsStoreData("VatNumber")
				sCustomField1	= rsStoreData("user1")
				sCustomField2	= rsStoreData("user2")
				sCustomField3	= rsStoreData("user3")
			End If
			Call DB_closeRecordset(rsStoreData)
			
			If ( sError = "1" ) Then
				Call owMessage(LANG_DT( "ORDERVERIFY_CREDITNUMERIC",  "Please only enter numeric values as credit."), C_ERROR)
			ElseIf ( sError = "2" ) Then
				Call owMessage(LANG_DT( "ORDERVERIFY_NOTENOUGHCREDIT",  "You do not have that much credit. Please enter a lower amount for the credit you would like to use on this order."), C_ERROR)
			Else
				Call owMessage(LANG_DT( "ORDERVERIFY_GENERICCREDITERROR",  "Credit value is invalid."), C_ERROR)
			End If
		Else
			' just get the comments and such from the form
			sComments				= SQLEncode(CONVERSION_SQLEncode2(Request("sComments"),100))
			sVatNumber				= SQLEncode(CONVERSION_SQLEncode2(Request("sVATNumber"),6))
			sCustomField1			= SQLEncode(Trim(Request("sCustomField1")))
			sCustomField2			= SQLEncode(Trim(Request("sCustomField2")))
			sCustomField3			= SQLEncode(Trim(Request("sCustomField3")))
		End If
		
		If ( sOWCurrencyCode <> "" ) Then
			sTempCurrencyCode = "(" & sOWCurrencyCode & ")"
		End If
	
		' if cart has no items cancel the order
		if CART_CountRows() = 0 then 
			Call owMessage(Replace(LANG_DT( "ORDERVERIFY_NOITEMS", "No items in cart. Please return to the <A href='1:'>main page</a> to add products to your cart." ), "1:", sOWStoreUrlNonSSL), C_ERROR)
		Else
		
			sSubTotal  			= CART_CalcTotal()
			sTaxExemptAmount	= CART_CalcTotalTaxExempt()		' this returns the monitary amount of product that's been set as tax exempt - subtract this from the subtotal when calculating tax

			CART_CalculateTax()		' populates sCartTax and tax arrays for display
			Call ReturnShipInfo(sShipMethod)
			
			Call CART_PaymentMethodInfo(sPaymentMethod, bPaymentActive, sPaymentDesc, sPaymentPriceToAdd, sPaymentPercentageToAdd)
			If ( ( sPaymentPriceToAdd <> 0 ) Or ( sPaymentPercentageToAdd <> 0 ) ) Then
				sPaymentMethodFee = sPaymentPriceToAdd + ( sPaymentPercentageToAdd * sSubTotal/100 )
			End If
			
			If ( sHandlingVisibility = "Y" ) Then
				'this means that the shipping total passed in from the previous page did not have the handling fees added to it because
				'	the handling fees are visible (hidden fees would have to be added to the original shipping quotes)
				'	"Visibility" means that the handling appears on THIS page, but NOT on the shipping estimate or owShippingCostQuery.asp pages
				If ( ( sSubTotal <> 0 ) And ( sVatNumber = "" ) ) Then
					If ( bOWTaxShipping ) Then
						sTaxAmount 	= Round(( sSubTotal - sTaxExemptAmount + sShipmentTotal + sHandlingFee ) * ( sCartTax/100 ), 2)
					Else
						sTaxAmount 	= Round(( sSubTotal - sTaxExemptAmount + sHandlingFee ) * ( sCartTax/100 ), 2)
					End If
				End If
				sTotalAmount = sSubTotal + sPaymentMethodFee + sShipmentTotal + sHandlingFee + sTaxAmount
			Else
				' the handling is hidden, so it was already added to the sShipmentTotal
				If ( ( sSubTotal <> 0 ) And ( sVatNumber = "" ) ) Then
					If ( bOWTaxShipping ) Then
						sTaxAmount 	= Round(( sSubTotal - sTaxExemptAmount + sShipmentTotal ) * ( sCartTax/100 ), 2)
					Else
						sTaxAmount 	= Round(( sSubTotal - sTaxExemptAmount ) * ( sCartTax/100 ), 2)
					End If
				End If
				sTotalAmount = sSubTotal + sPaymentMethodFee + sShipmentTotal + sTaxAmount
			End If			

			Call PopulateCustInfo()
			%>
			<table width=<%=sOWStoreTableWidth%> border=0 style='border: 1px solid #000000;' cellspacing=0 cellpadding=5>
			<form method="post" action="owSaveOrder.asp" name="saveorder">
			<input type='hidden' name='sPaymentMethod' value='<%=sPaymentMethod%>'>
				<tr> 
					<td colspan="5">
						<table border="0" cellspacing="0" width=100%>
							<tr>
								<td width=33%>&nbsp;</td>
								<td width=33% align=center valign=top>
									<b><font size="4"><%=sOWCompany%></font></b><br>
									<font size="1"><%=sOWCompanyAddress%><br>
									<%=sOWCompanyCity&", "&sOWCompanyStateCode&" "& sOWCompanyZip &" "& sOWCompanyCountryCode%></font><br><br>
								</td>
								<td width=33% valign=top align=right>
									<b><%=LANG_DT( "ORDERVERIFY_DATE", "Date" )%> </b>:<%=CONVERSION_FormatDate(Now(), "S")%>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td colspan=5>
						<table width=100%>
							<tr>
								<td width=50% valign=top>
									<table width=100%>
										<tr>
											<td colspan=3 style='border-bottom: 1px solid #000000;' bgcolor=EEEEEE>
												<b><%=LANG_DT( "ORDERVERIFY_BILLINGADDRESS", "Billing Address" )%>:
											</td>
										</tr>
										<tr>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=LANG_DT( "ORDERVERIFY_NAME", "Name" )%>
											</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>&nbsp;&nbsp;&nbsp;</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=sFName&" "&sLName%>
											</td>
										</tr>
										<tr>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=LANG_DT( "ORDERVERIFY_COMPANY", "Company" )%>
											</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>&nbsp;&nbsp;&nbsp;</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=sCustomerCompany%>
											</td>
										</tr>
										<tr>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=LANG_DT( "ORDERVERIFY_COUNTRY", "Country" )%>
											</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>&nbsp;&nbsp;&nbsp;</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%
												sSQLText = "SELECT CountryName FROM CountryCodes WHERE CountryCode = '" & SQLEncode(sCountryCode) & "'"
												Call DB_getFromDatabase(sSQLText, rsStoreData, "")
												If ( NOT rsStoreData.EOF ) Then
													Response.Write rsStoreData("CountryName")
												Else
													Response.Write sCountryCode
												End If
												Call DB_closeRecordset(rsStoreData)
												%>
											</td>
										</tr>
										<%If ( sStateCode <> "" ) Then%>
										<tr>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=STRUCTURE_TerritoryLabel(sCountryCode)%>
											</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>&nbsp;&nbsp;&nbsp;</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%
												sSQLText = "SELECT StateName FROM StateCodes WHERE StateCode = '" & SQLEncode(sStateCode) & "' AND CountryCode = '" & SQLEncode(sCountryCode) & "'"
												Call DB_getFromDatabase(sSQLText, rsStoreData, "")
												If ( NOT rsStoreData.EOF ) Then
													Response.Write rsStoreData("StateName")
												Else
													Response.Write sStateCode
												End If
												Call DB_closeRecordset(rsStoreData)
												%>
											</td>
										</tr>
										<%End If%>
										<%If ( sCity <> "" ) Then%>
										<tr>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=LANG_DT( "ORDERVERIFY_CITY", "City" )%>
											</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>&nbsp;&nbsp;&nbsp;</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=sCity%>
											</td>
										</tr>
										<%End If%>
										<tr>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=STRUCTURE_PostalCodeLabel(sCountryCode)%>
											</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>&nbsp;&nbsp;&nbsp;</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=sZip%>
											</td>
										</tr>
									</table>
								</td>
								<%If ( ( bOWAllowShippingAddress ) And ( sShippingAddress <> "" ) ) Then%>
								<td style='border-right: 1px solid #000000;'>&nbsp;</td>
								
								<td width=50% valign=top>
									<table width=100%>
										<tr>
											<td colspan=3 style='border-bottom: 1px solid #000000;' bgcolor=EEEEEE>
												<b><%=LANG_DT( "ORDERVERIFY_SHIPPINGADDRESS", "Shipping Address" )%>:
											</td>
										</tr>
										<%If ( Trim(sShippingAddress) <> "" ) Then%>
										<tr>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=LANG_DT( "ORDERVERIFY_NAME", "Name" )%>
											</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>&nbsp;&nbsp;&nbsp;</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=sShippingName & " " & sShippingLastName%>
											</td>
										</tr>
										<tr>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=LANG_DT( "ORDERVERIFY_COUNTRY", "Country" )%>
											</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>&nbsp;&nbsp;&nbsp;</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%
												sSQLText = "SELECT CountryName FROM CountryCodes WHERE CountryCode = '" & SQLEncode(sShippingCountryCode) & "'"
												Call DB_getFromDatabase(sSQLText, rsStoreData, "")
												If ( NOT rsStoreData.EOF ) Then
													Response.Write rsStoreData("CountryName")
												Else
													Response.Write sShippingCountryCode
												End If
												Call DB_closeRecordset(rsStoreData)
												%>
											</td>
										</tr>
										<%If ( sShippingState <> "" ) Then%>
										<tr>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=STRUCTURE_TerritoryLabel(sShippingCountryCode)%>
											</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>&nbsp;&nbsp;&nbsp;</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%
												sSQLText = "SELECT StateName FROM StateCodes WHERE StateCode = '" & SQLEncode(sShippingStateCode) & "' AND CountryCode = '" & SQLEncode(sShippingCountryCode) & "'"
												Call DB_getFromDatabase(sSQLText, rsStoreData, "")
												If ( NOT rsStoreData.EOF ) Then
													Response.Write rsStoreData("StateName")
												Else
													Response.Write sShippingStateCode
												End If
												Call DB_closeRecordset(rsStoreData)
												%>
											</td>
										</tr>
										<%End If%>
										<%If ( sShippingCity <> "" ) Then%>
										<tr>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=LANG_DT( "ORDERVERIFY_CITY", "City" )%>
											</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>&nbsp;&nbsp;&nbsp;</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=sShippingCity%>
											</td>
										</tr>
										<%End If%>
										<tr>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=STRUCTURE_PostalCodeLabel(sShippingCountryCode)%>
											</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>&nbsp;&nbsp;&nbsp;</td>
											<td style='border-bottom: 1px solid #EEEEEE;'>
												<%=sShippingZip%>
											</td>
										</tr>
										<%Else%>
										<tr>
											<td align=center valign=center>
												<br><br><b><%=LANG_DT( "ORDERVERIFY_USESAMEADD", "Same as billing" )%>
											</td>
										</tr>
										<%End If%>
									</table>
								</td>
								<%End If%>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td colspan=5>
						<b><%=LANG_DT( "ORDERVERIFY_PHONE", "Phone #" )%>: </b> <%=sPhone%><br>
						<br><b><%=LANG_DT( "ORDERVERIFY_COMMENTS", "Comments" )%>: </b><%=sComments%>
						<%if sOWOrderFieldName1<>"" then%>
						<br><b><%=sOWOrderFieldName1%>: </b><%=sCustomField1%>
						<%End If%>
						<%if sOWOrderFieldName2<>"" then%>
						<br><b><%=sOWOrderFieldName2%>: </b><%=sCustomField2%>
						<%End If%>
						<%if sOWOrderFieldName3<>"" then%>
						<br><b><%=sOWOrderFieldName3%>: </b><%=sCustomField3%>
						<%End If%>
					</td>
				</tr>
				<tr><td colspan="5"><hr size=1 color=000000></td></tr>
				<tr> 
					<td width="40"> <b><%=LANG_DT( "ORDERVERIFY_QTY", "Quant." )%></b></td>
					<td width=""><b><%=LANG_DT( "ORDERVERIFY_SKU", "SKU" )%></b></td>
					<td width="189"><b><%=LANG_DT( "ORDERVERIFY_ITEM", "Item" )%></b></td>
					<td width="148"><b><%=LANG_DT( "ORDERVERIFY_OPTIONS", "Options" )%></b></td>
					<td width="76"> <b><%=LANG_DT( "ORDERVERIFY_PRICE", "Price" )%></b></td>
				</tr>
				<%
				sSQLText = "SELECT C.idCartRow, C.idProduct, C.quantity, C.unitPrice, C.unitBtoBPrice, P.description, P.sku FROM CartProducts C, products P  WHERE C.idProduct = P.idProduct AND C.IDCart = " & sIDCart
				Call DB_getFromDatabase(sSQLText, rsStoreData2, "")
				do while not rsStoreData2.eof
					sIDCartRow				= rsStoreData2("idCartRow")
					sIDProduct				= rsStoreData2("idProduct")
					pQuantity				= rsStoreData2("quantity")
					sUnitPrice				= Cdbl(rsStoreData2("unitPrice"))
					sUnitBtoBPrice			= Cdbl(rsStoreData2("unitBtoBPrice"))
					pDescription			= rsStoreData2("description")
					sSKU					= rsStoreData2("sku")
					%> 
					<tr> 
						<td width="40"><%=pQuantity%></td>
						<td>
							<%if sSKU="" then%>
							<%=sIDProduct%>
							<%else%>
							<%=sSKU%>
							<%End If%>
						</td>
						<td width="189" valign=top>
							<%=pDescription%>
						</td>
						<td width="148"> 
							<%         
							' get optionals data for current cart row
							sSQLText = "SELECT idOption, optionDescrip, priceToAdd, TextDetail FROM CartProductsOptions WHERE idCartRow = " & sIDCartRow
							Call DB_getFromDatabase(sSQLText, rsStoreData3, "")
							do while not rsStoreData3.eof
								sOptionDescrip	= rsStoreData3("optionDescrip")
								sPriceToAdd		= Cdbl(rsStoreData3("priceToAdd"))
								sTextDetail		= Trim(rsStoreData3("TextDetail"))
								response.write sOptionDescrip 
								if sPriceToAdd>0 then
									response.write " " & CONVERSION_Currency(sPriceToAdd)
								End If
								response.write "<br>"
								If ( sTextDetail <> "" ) Then
									Response.Write "<input type='text' name='' value=""" & Server.HTMLEncode(sTextDetail) & """ readonly><br>"
								End If
								sOptionGroupsTotal	= sOptionGroupsTotal+ sPriceToAdd        
								rsStoreData3.movenext
							loop                   
							Call DB_closeRecordset(rsStoreData3)
							%>
						</td>
						<td width="76">
							<%
							if ACCNT_InGroup(iLoginAccountUnq, C_GROUP_RETAIL) then
								sRowPrice = Cdbl(pQuantity * (sOptionGroupsTotal+sUnitPrice) )
							else
								sRowPrice = Cdbl(pQuantity * (sOptionGroupsTotal+sUnitBtoBPrice) )
							End If
							%>        
							<%=CONVERSION_Currency(sRowPrice) %> 
						</td>
					</tr>
					<%
					rsStoreData2.movenext
				loop
				Call DB_closeRecordset(rsStoreData2)
				%> 
				<tr><td colspan="5"><hr size=1 color=000000></td></tr>
				<tr> 
					<td colspan="3">&nbsp;</td>
					<td width="148"> 
						<div align="right"><b><%=LANG_DT( "ORDERVERIFY_SUBTOTAL", "Subtotal" )%>: </b></div>
					</td>
					<td width="76"> 
						<%=CONVERSION_Currency(sSubTotal) %>
					</td>
				</tr>
				<tr> 
					<td colspan="3">&nbsp;</td>
					<td width="148" align=right><b><%=LANG_DT( "ORDERVERIFY_PMTTYPE", "Payment type" )%>:</b><br>(<%=sPaymentDesc%>)</td>
					<td width="76">
						<%If ( sPaymentMethodFee = 0 ) Then%>
						<%=LANG_DT( "ORDERVERIFY_NOFEE", "No fees" )%>
						<%Else%>
						<%=CONVERSION_Currency(sPaymentMethodFee)%>
						<%End If%>
					</td>
				</tr>
				<tr> 
					<td colspan="3">&nbsp;</td>
					<td width="148" align=right><b><%=LANG_DT( "ORDERVERIFY_SHIPPING", "Shipping" )%>:</b><br>(<%=sShipmentDesc%>)</td>
					<td width="76">
						<%=CONVERSION_Currency(sShipmentTotal)%>
						<%If ( sShipmentTotal = 0 ) Then%>
						<u><%=LANG_DT( "ORDERVERIFY_FREE", "FREE!" )%></u>
						<%End If%>
					</td>
				</tr>
				<%If ( sHandlingVisibility = "Y" ) Then%>
				<tr> 
					<td colspan="3">&nbsp;</td>
					<td width="148"> 
						<div align="right"><b><%=LANG_DT( "ORDERVERIFY_HANDLING", "Handling" )%>: </div>
					</td>
					<td width="76"> 
						<%=CONVERSION_Currency(sHandlingFee)%>
					</td>
				</tr>
				<%End If%>
				
				<%Call DisplayTaxes()%>

				<tr> 
					<td colspan="3">&nbsp;</td>
					<td width="148"> 
						<div align="right"><b><%=LANG_DT( "ORDERVERIFY_TOTAL", "Total" )%></b>&nbsp;<%=sTempCurrencyCode%>: </div>
					</td>
					<td width="76"> 
						<b><font size=+1><%=CONVERSION_Currency(sTotalAmount) %></b></font>
					</td>
				</tr>
				<tr><td colspan="5">&nbsp;</td></tr>  
				<tr> 
					<td colspan="3" style='border-top: 1px solid #000000;'> 
						<input type="button" name="Cancel" value=" <%=LANG_DT( "ORDERVERIFY_CANCEL", "Cancel order" )%> " onClick='location="owCheckOutCancelOrder.asp";'>
					</td>
					<td colspan="3" align=right style='border-top: 1px solid #000000;'> 
						<input type="submit" name="Save" value=" <%=LANG_DT( "ORDERVERIFY_FINALIZE", "Finalize Order" )%>* ">
					</td>
				</tr>
			</form>
			</table>
			<table width=<%=sOWStoreTableWidth%> border=0 cellspacing=0 cellpadding=5>
				<tr>
					<td>
						<i>* <%=LANG_DT( "ORDERVERIFY_AGREE", "Before pressing Finalize Order you must agree with our " )%> 
						<a href="../owInfoPagePopup.asp?idLongText=TERMS_CONDS" target="_blank"><%=LANG_DT( "ORDERVERIFY_GCOND", "General Conditions" )%></a></i>
					</td>
				</tr>
			</table>
			<%
			Call SF_ClosePage()
			
			' ************SAVE order as unfinalized*************
			sSQLText = "SELECT idOrder FROM Orders WHERE SessionID = '" & Session.SessionID & "' AND OrderStatus = " & C_UNFINALIZED
			Call DB_getFromDatabase(sSQLText, rsStoreData, "")
			If ( NOT rsStoreData.EOF ) Then
				' the customer has either refreshed the page or left and come back, possible w/ different contents of their cart, or different
				'	shipping, taxes, etc. So, delete the order information that's in the database now and recreate it below
				sIDOrder = rsStoreData("idOrder")
				Call DB_updateDatabase("DELETE FROM OrdersProdOptions WHERE idOrder = " & sIDOrder)
				Call DB_updateDatabase("DELETE FROM OrdersProdRef WHERE idOrder = " & sIDOrder)
				call DB_updateDatabase("DELETE FROM OrdersCreditCards WHERE idOrder=" & sIDOrder)
				call DB_updateDatabase("DELETE FROM ordersTaxes WHERE idOrder=" & sIDOrder)
				call DB_updateDatabase("DELETE FROM orders WHERE idOrder = " & sIDOrder)
			End If
			Call DB_closeRecordset(rsStoreData)
			
			sTtlWeight = CART_CalcWeight() - CART_CalcFreeShipWeight()
			Call CART_CalcVolume(sTtlLength, sTtlHeight, sTtlWidth)
			
			sSQLText = "INSERT INTO orders (orderDate, AccountUnq, total, address, zip, stateCode, state, city, countryCode, CustomerComments, taxAmount, shipmentDetails, ShippingFee, PaymentMethod, PaymentMethodFee, shippingName, shippingLastName, shippingAddress, shippingStateCode, shippingState, shippingCity, shippingCountryCode, shippingZip, orderStatus, viewed, idAffiliate, browserIp, TrackingNumber, vatNumber, user1, user2, user3, TtlWeight, TtlLength, TtlHeight, TtlWidth, SessionID, HandlingVisibility, HandlingFee, InternalComments, Email, FName, LName, Phone, SubTotal, DiscountCode, DiscountAmount) VALUES ('" & CONVERSION_FormatDate(Date(), "S")  & "'," & iLoginAccountUnq & "," & sTotalAmount & ",'" & SQLEncode(sAddress) & "','" & SQLEncode(sZip) & "','" & SQLEncode(sStateCode) & "','" & SQLEncode(sState) & "','" & SQLEncode(sCity) & "','" & SQLEncode(sCountryCode) & "','" & SQLEncode(sComments) & "'," & sTaxAmount & ",'" & SQLEncode(sShipmentDesc) & "'," & sShipmentTotal & ",'" & SQLEncode(sPaymentDesc) & "'," & sPaymentPriceToAdd & ",'" & SQLEncode(sShippingName) & "','" & SQLEncode(sShippingLastName) & "','" & SQLEncode(sShippingAddress) & "','" & SQLEncode(sShippingStateCode) & "','" & SQLEncode(sShippingState) & "','" & SQLEncode(sShippingCity) & "','" & SQLEncode(sShippingCountryCode) & "','" & SQLEncode(sShippingZip) & "'," & C_UNFINALIZED & ",1,0,'" & request.ServerVariables("REMOTE_HOST") & "','','" & SQLEncode(sVatNumber) & "','" & SQLEncode(sCustomField1) & "', '" & SQLEncode(sCustomField2) & "','"& SQLEncode(sCustomField3) &"', " & sTtlWeight & ", " & sTtlLength & ", " & sTtlHeight & ", " & sTtlWidth & ", '" & Session.SessionID & "', '" & sHandlingVisibility & "', " & sHandlingFee & ", '', '" & SQLEncode(sEmail) & "', '" & SQLEncode(sFName) & "', '" & SQLEncode(sLName) & "', '" & SQLEncode(sPhone) & "', " & sSubTotal & ", '', 0)"
			Call DB_updateDatabase(sSQLText)

			sSQLText = "SELECT idOrder FROM orders WHERE SessionID = '" & Session.SessionID & "' AND OrderStatus = " & C_UNFINALIZED
			Call DB_getFromDatabase(sSQLText, rsStoreData, "")
			If ( NOT rsStoreData.EOF ) Then
				sIDOrder = rsStoreData("idOrder")
				Call SaveTaxLines(sIDOrder)
				Call SaveItemLines(sIDOrder)
			End If
			Call DB_closeRecordset(rsStoreData)
			
		End If
		
		Set rsStoreData3 = Nothing
		
	End Sub
	'************************************************************************************
	
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Sub ReturnShipInfo(sShipMethod)
	
		If ( sShipMethod = "" ) Then
			' they get free shipping and didn't have to choose a method -- ie. for digital downloads
			sShipmentDesc		= "Free Shipping!"
			sHandlingFee		= 0
			sHandlingVisibility	= "N"
		Else
			aShipInfo		= Split(sShipMethod, "|", -1)
			sShipmentTotal	= replace(aShipInfo(0), ",", ".")
			sOrigShipTotal	= sShipmentTotal
			sShipmentDesc	= aShipInfo(1)
	
			If ( InStr(sShipmentDesc, "UPS") ) Then
				sSQLText = "SELECT * FROM UPSShippingMethods WHERE UPSInternalIDNum = '" & Replace(sShipmentDesc, "UPS", "") & "'"
				Call DB_getFromDatabase(sSQLText, rsStoreData, "")   
				If ( NOT rsStoreData.EOF ) Then
					sShipmentDesc		= Trim(rsStoreData("Name"))
					sHandlingFee		= rsStoreData("HandlingFee")
					sHandlingVisibility	= Trim(rsStoreData("HandlingVisibility"))
				End If
				Call DB_closeRecordset(rsStoreData)
			Else
				sSQLText = "SELECT * FROM Shipments WHERE idShipment = " & sShipmentDesc
				Call DB_getFromDatabase(sSQLText, rsStoreData, "")   
				If ( NOT rsStoreData.EOF ) Then
					sShipmentDesc		= Trim(rsStoreData("ShipmentDesc"))
					sHandlingFee		= rsStoreData("HandlingFix")
					sHandlingVisibility	= "Y"
				End If
				Call DB_closeRecordset(rsStoreData)
			End If
		End If
		
	End Sub
	'************************************************************************************
	
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Sub PopulateCustInfo()
	
		sSQLText = "SELECT * FROM CustAltBill CAB, CustAltShip CAS, owAccounts A WHERE A.AccountUnq = " & iLoginAccountUnq & " AND CAB.AccountUnq = CAS.AccountUnq AND CAB.AccountUnq = A.AccountUnq AND CAS.Position = 0"
		Call DB_getFromDatabase(sSQLText, rsStoreData, "")
		if not rsStoreData.eof then
			sFName					= ACCNT_ReturnADV("OW_CUSTFNAME", "V", iLoginAccountUnq, C_OVERRIDE_ADV)
			sLName					= ACCNT_ReturnADV("OW_CUSTLNAME", "V", iLoginAccountUnq, C_OVERRIDE_ADV)
			sEmail					= ACCNT_ReturnADV("OW_CUSTEMAIL", "V", iLoginAccountUnq, C_OVERRIDE_ADV)
			sCustomerCompany		= ACCNT_ReturnADV("OW_CUSTCOMPANY", "V", iLoginAccountUnq, C_OVERRIDE_ADV)
			sPhone					= ACCNT_ReturnADV("OW_CUSTPHONE", "V", iLoginAccountUnq, C_OVERRIDE_ADV)
			sPassword				= rsStoreData("password")
			sAddress				= rsStoreData("BillingAddress")
			sZip					= rsStoreData("BillingZip")
			sStateCode				= rsStoreData("BillingStateCode")
			sState					= rsStoreData("BillingState")
			sCity					= rsStoreData("BillingCity")
			sCountryCode			= rsStoreData("BillingCountryCode")
			sShippingName			= rsStoreData("ShippingName")
			sShippingLastName		= rsStoreData("ShippingLastName")
			sShippingAddress		= rsStoreData("ShippingAddress")
			sShippingZip			= rsStoreData("ShippingZip")
			sShippingStateCode		= rsStoreData("ShippingStateCode")
			sShippingState			= rsStoreData("ShippingState")
			sShippingCity			= rsStoreData("ShippingCity")
			sShippingCountryCode    = rsStoreData("ShippingCountryCode")
		End If
		Call DB_closeRecordset(rsStoreData)
	
	End Sub
	'************************************************************************************
	
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Sub DisplayTaxes()
	
		iCount = 0
		%>
		<%If ( aTaxCountryInfo(0, 0) <> "" ) Or ( ( aTaxStateInfo(0, 0) <> "" ) ) Then%>
		<tr> 
			<td colspan="3">&nbsp;</td>
			<td width="148"> 
				<div align="right"></div>
			</td>     
			<td width="76" bgcolor=EEEEEE> 
				<b><%=LANG_DT( "ORDERVERIFY_TAXES", "Taxes" )%></b>
			</td>
		</tr>
		<%
		If ( aTaxStateInfo(0, 0) <> "" ) Then
		While ( aTaxStateInfo(0, iCount) <> "" )
			%>
			<tr> 
				<td colspan="3">&nbsp;</td>
				<td width="148"> 
					<div align="right"><b><%=aTaxStateInfo(0, iCount)%></b></div>
				</td>     
				<td width="76" bgcolor=EEEEEE> 
					<%=aTaxStateInfo(1, iCount)%>%
				</td>
			</tr>
			<%
			iCount = iCount + 1
		Wend
		End If
		%>
		<%
		iCount = 0
		If ( aTaxCountryInfo(0, 0) <> "" ) Then
		While ( aTaxCountryInfo(0, iCount) <> "" )
			%>
			<tr> 
				<td colspan="3">&nbsp;</td>
				<td width="148"> 
					<div align="right"><b><%=aTaxCountryInfo(0, iCount)%></b></div>
				</td>     
				<td width="76" bgcolor=EEEEEE> 
					<%=aTaxCountryInfo(1, iCount)%>%
				</td>
			</tr>
			<%
			iCount = iCount + 1
		Wend
		End If
		%>
		<tr> 
			<td colspan="3">&nbsp;</td>
			<td width="148"> 
				<div align="right"><b><%=LANG_DT( "ORDERVERIFY_TTLTAXPERCENT", "Total Tax Percentile" )%>: </b></div>
			</td>     
			<td width="76" bgcolor=EEEEEE> 
				<%=sCartTax%>%
			</td>
		</tr>
		<%End If%>
		<tr> 
			<td colspan="3">&nbsp;</td>
			<td width="148"> 
				<div align="right"><b><%=LANG_DT( "ORDERVERIFY_TAXAMOUNT", "Tax Amount" )%>: </b></div>
			</td>     
			<td width="76">
				<%=CONVERSION_Currency(sTaxAmount)%>
			</td>
		</tr>
		<%
		
	End Sub
	'************************************************************************************
	
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Sub SaveTaxLines(sIDOrder)

		Dim sTempCountry, sTempState, sTempZip
		
		iCount			= 0
		
		If ( Trim(sShippingCountryCode) = "" ) Then
			sTempCountry	= sCountryCode
			sTempState		= sStateCode
			sTempZip		= sZip
		Else
			sTempCountry	= sShippingCountryCode
			sTempState		= sShippingStateCode
			sTempZip		= sShippingZip
		End If

		While ( aTaxStateInfo(0, iCount) <> "" )
			Call DB_updateDatabase("INSERT INTO OrdersTaxes (idOrder, TaxName, Percentage, CountryCode, StateCode, ZipCode) VALUES (" & sIDOrder & ", '" & SQLEncode(aTaxStateInfo(0, iCount)) & "', " & aTaxStateInfo(1, iCount) & ", '" & SQLEncode(sTempCountry) & "', '" & SQLEncode(sTempState) & "', '" & SQLEncode(sTempZip) & "')")
			iCount = iCount + 1
		Wend

		iCount = 0
		While ( aTaxCountryInfo(0, iCount) <> "" )
			Call DB_updateDatabase("INSERT INTO OrdersTaxes (idOrder, TaxName, Percentage, CountryCode, StateCode, ZipCode) VALUES (" & sIDOrder & ", '" & SQLEncode(aTaxCountryInfo(0, iCount)) & "', " & aTaxCountryInfo(1, iCount) & ", '" & SQLEncode(sTempCountry) & "', '" & SQLEncode(sTempState) & "', '" & SQLEncode(sTempZip) & "')")
			iCount = iCount + 1
		Wend

	End Sub
	'************************************************************************************
	
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Sub SaveItemLines(sIDOrder)
	
		Dim rsStoreData
		
		Set rsStoreData = CreateObject("ADODB.Recordset")

		' compile order details memo field (the field used for Download links, serials, etc)
		sSQLText = "SELECT * FROM CartProducts C, products P WHERE C.idProduct = P.idProduct AND C.IDCart = " & sIDCart
		Call DB_getFromDatabase(sSQLText, rsStoreData, "")    
		do while not rsStoreData.eof
			sIDCartRow				= rsStoreData("idCartRow")
			sIDProduct				= rsStoreData("idProduct")
			sQuantity				= rsStoreData("quantity")
			sUnitPrice				= Cdbl(rsStoreData("unitPrice"))
			sUnitBtoBPrice			= Cdbl(rsStoreData("unitBtoBPrice"))
			sDescription			= rsStoreData("description")
			sSku					= rsStoreData("sku")
			sImageURL				= rsStoreData("ImageURL")
			sSmallImageURL			= rsStoreData("SmallImageURL")
			sUnitWeight				= rsStoreData("Weight")
			sUnitHeight				= rsStoreData("Height")
			sUnitLength				= rsStoreData("Length")
			sUnitDepth				= rsStoreData("Width")
			sDetails				= rsStoreData("Details")
			sOptionsDescripCompound	= ""
			sUnitDealerPrice		= 0

			Call DB_updateDatabase("INSERT INTO OrdersProdRef (idOrder, idProduct, ActualShipCost, Quantity, UnitPrice, UnitBtoBPrice, UnitDealerPrice, UnitWeight, UnitHeight, UnitLength, UnitDepth, Description, SKU, ImageURL, SmallImageURL, SupplierName, Details, DigitalDownload, ExpireDays, AllowedDownloads, NumDownloads, TaxExempt) VALUES (" & sIDOrder & ", " & sIDProduct & ", 0, " & sQuantity & ", " & sUnitPrice & ", " & sUnitBtoBPrice & ", " & sUnitDealerPrice & ", " & sUnitWeight & ", " & sUnitHeight & ", " & sUnitLength & ", " & sUnitDepth & ", '" & SQLEncode(sDescription) & "', '" & SQLEncode(sSku) & "', '" & SQLEncode(sImageURL) & "', '" & SQLEncode(sSmallImageURL) & "', '', '" & SQLEncode(sDetails) & "', '', 0, 0, 0, 'N')")

			' get optionals for current cart row
			sSQLText = "SELECT O.OptionDescrip, O.PriceToAdd, O.Weight, CPO.TextDetail, OG.OptionGroupDesc FROM CartProductsOptions CPO, Options O, OptionsGroups OG, Options_OptionsGroups OOG WHERE CPO.idOption = O.idOption AND o.idOption = OOG.idOption AND OOG.idOptionGroup = OG.idOptionGroup AND CPO.idCartRow = " & sIDCartRow & " AND CPO.idOptionGroup = OOG.idOptionGroup"
			Call DB_getFromDatabase(sSQLText, rsStoreData2, "")
			Do While ( NOT rsStoreData2.EOF )
				sPriceToAdd				= Cdbl(rsStoreData2("PriceToAdd"))
				sWeightToAdd			= Cdbl(rsStoreData2("Weight"))
				sTextDetail				= Trim(rsStoreData2("TextDetail"))
				sOptionDescrip			= rsStoreData2("OptionDescrip")
				sOptionGroupDescription	= rsStoreData2("OptionGroupDesc")
				sOptionsDescripCompound	= sOptionsDescripCompound & sOptionGroupDescription & " : " & sOptionDescrip & " "
				if sPriceToAdd > 0 then
					sOptionsDescripCompound	= sOptionsDescripCompound & " : " & CONVERSION_Currency(sPriceToAdd)
				End If
				sOptionsDescripCompound	= sOptionsDescripCompound & "<BR>"
				Call DB_updateDatabase("INSERT INTO OrdersProdOptions (idOrder, idProduct, OptionDescription, PriceToAdd, WeightToAdd, OptionGroupDescription, TextDetail) VALUES (" & sIDOrder & ", " & sIDProduct & ", '" & SQLEncode(sOptionDescrip) & "', " & sPriceToAdd & ", " & sWeightToAdd & ", '" & SQLEncode(sOptionGroupDescription) & "', '" & SQLEncode(sTextDetail) & "')")
				rsStoreData2.movenext
			Loop
			Call DB_closeRecordset(rsStoreData2)

			rsStoreData.movenext
		loop
		Call DB_closeRecordset(rsStoreData)

		Set rsStoreData = Nothing

	End Sub
	'************************************************************************************
%>