<%
	'************************************************************************************
	'*																					*
	'*	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/											*
	'*																					*
	'************************************************************************************
	

	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	function SESSION_RetrieveGlobals()
	
		Dim sSessionID
		
		sSessionID = Session.SessionID

		If ( sSessionID ) Then
			
			sSQLText = "SELECT * FROM Cart WHERE SessionUnq = '" & SQLEncode(sSessionID) & "'"
			Call DB_getFromDatabase(sSQLText, rsStoreData, "")
			If ( NOT rsStoreData.EOF ) Then
				' exists so populate the StoreFront globals
				sIDCart					= Trim(rsStoreData("IDCart"))
				sShipMethod				= Trim(rsStoreData("ShipMethod"))
				sSubTotal				= Trim(rsStoreData("SubTotal"))
				sTotalAmount			= Trim(rsStoreData("TotalAmount"))
				sTaxAmount				= Trim(rsStoreData("TaxAmount"))
				sDiscountTotal			= Trim(rsStoreData("DiscountTotal"))
				sPaymentMethod			= Trim(rsStoreData("PaymentMethod"))
				sVatNumber				= Trim(rsStoreData("VatNumber"))
				sDiscountCode			= Trim(rsStoreData("DiscountCode"))
				sCustomField1			= Trim(rsStoreData("CustomField1"))
				sCustomField2			= Trim(rsStoreData("CustomField2"))
				sCustomField3			= Trim(rsStoreData("CustomField3"))
				dSessionDateStart		= Trim(rsStoreData("SessionDateStart"))
				dSessionDateLastUpdate	= Trim(rsStoreData("SessionDateLastUpdate"))
				bCartOpen				= Trim(rsStoreData("CartOpen"))
				sComments				= Trim(rsStoreData("Comments"))
			Else
				' doesn't exist, create a new one
				If ( sSubTotal = "" ) Or ( IsNull(sSubTotal) ) Then sSubTotal = "0.00" End If
				If ( sTotalAmount = "" ) Or ( IsNull(sTotalAmount) ) Then sTotalAmount = "0.00" End If
				If ( sTaxAmount = "" ) Or ( IsNull(sTaxAmount) ) Then sTaxAmount = "0.00" End If
				If ( sDiscountTotal = "" ) Or ( IsNull(sDiscountTotal) ) Then sDiscountTotal = "0.00" End If
				If ( sVatNumber = "" ) Or ( IsNull(sVatNumber) ) Then sVatNumber = "0" End If
				If ( bCartOpen = "" ) Or ( IsNull(bCartOpen) ) Then bCartOpen = "0" End If

				Call DB_updateDatabase("INSERT INTO Cart (SessionUnq, AccountUnq, ShipMethod, SubTotal, TotalAmount, TaxAmount, DiscountTotal, PaymentMethod, VatNumber, DiscountCode, CustomField1, CustomField2, CustomField3, SessionDateStart, SessionDateLastUpdate, CartOpen, Comments) VALUES ('" & SQLEncode(Session.SessionID) & "', " & iLoginAccountUnq & ", '" & SQLEncode(sShipMethod) & "', " & sSubTotal & ", " & sTotalAmount & ", " & sTaxAmount & ", " & sDiscountTotal & ", '" & SQLEncode(sPaymentMethod) & "', '" & SQLEncode(sVatNumber) & "', '" & SQLEncode(sDiscountCode) & "', '" & SQLEncode(sCustomField1) & "', '" & SQLEncode(sCustomField2) & "', '" & SQLEncode(sCustomField3) & "', '" & Now() & "', '" & Now() & "', " & bCartOpen & ", '" & SQLEncode(sComments) & "')")
				
				sSQLText = "SELECT idCart FROM Cart WHERE SessionUnq = '" & sSessionID & "'"
				Call DB_getFromDatabase(sSQLText, rsStoreData2, "")
				If ( NOT rsStoreData2.EOF ) Then
					sIDCart = Trim(rsStoreData2("IDCart"))	' populate the idCart for pages that customers enter directly -- w/o first creating a cart id
				End If
				Call DB_closeRecordset(rsStoreData2)
			End If
			Call DB_closeRecordset(rsStoreData)
			
		Else
			sGlobalError = LANG_DT( "ENABLECOOKIES", "Please enable cookies in your browser before shopping within our store." )
		End If

	end function
	'************************************************************************************
	
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Sub SESSION_SaveGlobals()
	
		If ( sSubTotal = "" ) Or ( IsNull(sSubTotal) ) Then sSubTotal = "0.00" End If
		If ( sTotalAmount = "" ) Or ( IsNull(sTotalAmount) ) Then sTotalAmount = "0.00" End If
		If ( sTaxAmount = "" ) Or ( IsNull(sTaxAmount) ) Then sTaxAmount = "0.00" End If
		If ( sDiscountTotal = "" ) Or ( IsNull(sDiscountTotal) ) Then sDiscountTotal = "0.00" End If
		If ( sVatNumber = "" ) Or ( IsNull(sVatNumber) ) Then sVatNumber = "0" End If
		If ( bCartOpen = "" ) Or ( IsNull(bCartOpen) ) Then bCartOpen = "0" End If
	
		Call DB_updateDatabase("UPDATE Cart SET AccountUnq = " & iLoginAccountUnq & ", ShipMethod = '" & SQLEncode(sShipMethod) & "', SubTotal = " & sSubTotal & ", TotalAmount= " & sTotalAmount & ", TaxAmount = " & sTaxAmount & ", DiscountTotal = " & sDiscountTotal & ", PaymentMethod = '" & SQLEncode(sPaymentMethod) & "', VatNumber = '" & SQLEncode(sVatNumber) & "', DiscountCode = '" & SQLEncode(sDiscountCode) & "', CustomField1 = '" & SQLEncode(sCustomField1) & "', CustomField2 = '" & SQLEncode(sCustomField2) & "', CustomField3 = '" & SQLEncode(sCustomField3) & "', SessionDateLastUpdate = '" & Now() & "', CartOpen = " & bCartOpen & ", Comments = '" & SQLEncode(sComments) & "' WHERE SessionUnq = '" & SQLEncode(Session.SessionID) & "'")
	
	End Sub
	'************************************************************************************
%>