<!--#include file="../../owFunctions/I_GeneralFunctions.asp"-->
<!--#INCLUDE file="../../owFunctions/clsUpload.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/											*
	'*																					*
	'************************************************************************************

	sCountryCode	= Trim(Request("sCountryCode"))
	sNewCountryCode	= Trim(Request("sNewCountryCode"))
	sCountryName	= Trim(Request("sCountryName"))
	sPosition		= Trim(Request("sPosition"))
	sActive			= Trim(Request("sActive"))
	sTaxName		= Trim(Request("TaxName"))
	sPercentage		= Trim(Request("Percentage"))
	sAction			= Trim(Request("sAction"))
	sTerritoryLabel	= Trim(Request("sTerritoryLabel"))
	sPostalCodeLabel	= Trim(Request("sPostalCodeLabel"))
	sStateTaxCode	= Trim(Request("sStateTaxCode"))
	If ( sActive = "" ) Then
		sActive = "N"
	End If

	If ( NOT bOWBackOfficeDemoMode ) Then	' just do a cursory check in case hackers try to replicate the forms on their computers (return no error)
		sSQLText = "UPDATE CountryCodes SET countryName = '" & SQLEncode(sCountryName) & "', CountryCode = '" & SQLEncode(sNewCountryCode) & "', Position = " & sPosition & ", Active = '" & SQLEncode(sActive) & "', TerritoryLabel = '" & SQLEncode(sTerritoryLabel) & "', PostalCodeLabel = '" & SQLEncode(sPostalCodeLabel) & "' WHERE CountryCode = '" & sCountryCode & "'"
		Call DB_updateDatabase(sSQLText)

		If ( sAction = "NewTax" ) Then
			Call DB_updateDatabase("INSERT INTO CountryTax (CountryCode, TaxName, Percentage) VALUES ('" & SQLEncode(sCountryCode) & "', ' ', 0)")
		ElseIf ( sAction = "NewState" ) Then
			Call DB_updateDatabase("INSERT INTO StateCodes (stateCode, stateName, Active, CountryCode) VALUES (' ', ' ', 'N', '" & SQLEncode(sCountryCode) & "')")
		ElseIf ( sAction = "NewStateTax" ) Then
			Call DB_updateDatabase("INSERT INTO StateTax (StateCode, TaxName, Percentage) VALUES ('" & SQLEncode(sStateTaxCode) & "', ' ', 0)")
		Else
			For Each sTextField In Request.Form
				If ( InStr(sTextField, "sTaxName") > 0 ) Then
					sTaxName		= Trim(Request(sTextField))
					sID				= Replace(sTextField, "sTaxName", "")
					sPercentage		= Trim(Request("sPercentage" & sID))
					If ( sTaxName <> "" ) Then
						Call DB_updateDatabase("UPDATE CountryTax SET TaxName = '" & SQLEncode(sTaxName) & "', Percentage = " & SQLEncode(sPercentage) & " WHERE ID = " & sID)
					End If
				ElseIf ( InStr(sTextField, "sStateCode") > 0 ) Then
					sStateCode		= Trim(Request(sTextField))
					sStateID		= Replace(sTextField, "sStateCode", "")
					sStateName		= Trim(Request("sStateName" & sStateID))
					sActiveState	= Trim(Request("sActiveState" & sStateID))
					If ( sActiveState = "" ) Then
						sActiveState = "N"
					End If
					' check to see if the statecode already exists
					sSQLText = "SELECT * FROM stateCodes WHERE StateCode = '" & sStateCode & "'"
					Call DB_getFromDatabase(sSQLText, rsStoreData, "")
					If ( NOT rsStoreData.EOF ) Then
						Call DB_updateDatabase("UPDATE StateCodes SET StateName = '" & SQLEncode(sStateName) & "', Active = '" & SQLEncode(sActiveState) & "' WHERE StateID = " & sStateID)
					Else
						Call DB_updateDatabase("UPDATE StateCodes SET CountryCode = '" & SQLEncode(sCountryCode) & "', StateCode = '" & SQLEncode(sStateCode) & "', StateName = '" & SQLEncode(sStateName) & "', Active = '" & SQLEncode(sActiveState) & "' WHERE StateID = " & sStateID)
					End If
					Call DB_closeRecordset(rsStoreData)
				ElseIf ( InStr(sTextField, "sStateTaxName") > 0 ) Then
					sStateTaxName = Trim(Request(sTextField))
					If ( sStateTaxName <> "" ) Then
						sID			= Replace(sTextField, "sStateTaxName", "")
						sPercentage	= Request("sStatePercent" & sID)
						Call DB_updateDatabase("UPDATE StateTax SET TaxName = '" & SQLEncode(sStateTaxName) & "', Percentage = " & SQLEncode(sPercentage) & " WHERE ID = " & sID)
					End If
				ElseIf ( InStr(sTextField, "sDelete") > 0 ) Then
					sID = Replace(sTextField, "sDelete", "")
					Call DB_updateDatabase("DELETE FROM CountryTax WHERE ID = " & sID)
				ElseIf ( InStr(sTextField, "sStateDelete") > 0 ) Then
					sStateID = Replace(sTextField, "sStateDelete", "")
					Call DB_updateDatabase("DELETE FROM StateTax WHERE ID = " & sStateID)
					Call DB_updateDatabase("DELETE FROM StateCodes WHERE StateID = " & sStateID)
				ElseIf ( InStr(sTextField, "sDelStateTax") > 0 ) Then
					sStateID = Replace(sTextField, "sDelStateTax", "")
					Call DB_updateDatabase("DELETE FROM StateTax WHERE ID = " & sStateID)
				End If
			Next

		End If
	End If

	%>
	<script language = "javascript">
		<%If ( sMessage = "" ) Then%>
		location="owModifyCountries.asp?bRefresh=TRUE&sSort=<%=sSort%>&sSearch=<%=sSearch%>&sSearchText=<%=sSearchText%>&sCountryCode=<%=sCountryCode%>";
		<%Else%>
		location="owModifyCountries.asp?sMessage=<%=sMessage%>&sSort=<%=sSort%>&sSearch=<%=sSearch%>&sSearchText=<%=sSearchText%>&sCountryCode=<%=sCountryCode%>";
		<%End If%>
	</script>