<!--#include file="../../owFunctions/I_GeneralFunctions.asp"-->
<!--#include file="../header.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 iBeginPagination, sURL, iTtlNumItems, iDBLoc, sQuerystring, sTarget, iPaginationCount, sTempSearch, sPaymentDesc
	
	sAction			= Trim(Request("sAction"))
	sSort			= Trim(Request("sSort"))
	sSearchText		= Trim(Request("sSearchText"))
	sSearch			= Trim(Request("sSearch"))
	bResetDBLoc		= False
	sURL			= "owListCountries.asp"
	sQuerystring	= "sAction=" & sAction & "&sSort="
	sTarget			= "owMain"

	If ( sAction = "Delete" ) Then
		For Each sCheckbox In Request.Form
			If ( InStr(sCheckbox, "sDelete") > 0 ) Then
				sTemp = Replace(sCheckbox, "sDelete", "")
				sSuccess = DeleteCountries(sTemp)
			End If
		Next
		bResetDBLoc = True
	ElseIf ( sAction = "Update" ) Then
		For Each sTextField In Request.Form
			If ( InStr(sTextField, "sOldActive") > 0 ) Then
				sCountryCode	= Replace(sTextField, "sOldActive", "")
				sActive			= Request("sActive" & sCountryCode)
				sOldActive		= Request("sOldActive" & sCountryCode)
				If ( sOldActive <> sActive ) Then
					If ( sActive = "" ) Then
						sActive = "N"
					End If
					Call DB_updateDatabase("UPDATE countryCodes SET Active = '" & SQLEncode(sActive) & "' WHERE CountryCode = '" & SQLEncode(sCountryCode) & "'")
					If ( sSuccess = "" ) Then
						sSuccess = LANG_DT( "COUNTRIES_UPDATEOK", "** Update Successful **" )
					End If
				End If
			End If
		Next
	End If
	If ( sAction = "Search" ) Then
		If ( sSearchText <> "" ) Then
			If ( sSearch = "FirstChar" ) Then
				sTempSearch = " WHERE countryName LIKE '" & sSearchText & "%'"
			Else
				sTempSearch = " WHERE countryName LIKE '%" & sSearchText & "%'"
			End If
		Else
			sTempSearch = ""
		End If
	End If
	If ( sSort <> "" ) Then
		sTempSort = " ORDER BY " & sSort
	End If

	sSQLText	= "SELECT * FROM countryCodes" & sTempSearch & sTempSort
	sSQLCount	= "SELECT Count(*) FROM countryCodes" & sTempSearch

	iBeginPagination = SetupPagination( sSQLCount, bResetTtlNumItems, bResetDBLoc )
	Call PaginationQuery( sSQLText, rsStoreData, iBeginPagination )

	%>
	<script language = "javascript">
		parent.owBodyFooter.location="owBodyFooter.asp?<%=sQueryString%><%=sSort%>&sSearch=<%=sSearch%>&sSearchText=<%=sSearchText%>&iOWNumPerPage=<%=iOWNumPerPage%>&iTtlNumItems=<%=iTtlNumItems%>&iDBLoc=<%=iDBLoc%>"
	</script>
	<%
	
	If ( sSuccess <> "" ) Or ( rsStoreData.EOF ) Then
		If ( sSuccess <> "" ) Then
			%>
			<script language = "javascript">
				parent.owBodyTopNav.location="owBodyTopNav.asp?sMessage=<%=Server.URLEncode(sSuccess)%>"
			</script>
			<%
		End If
		If ( rsStoreData.EOF ) Then
			%>
			<script language = "javascript">
				parent.owBodyTopNav.location="owBodyTopNav.asp?sMessage=<%=Server.URLEncode(LANG_DT( "COUNTRIES_NOCOUNTRIES", "** No Countries found **" ))%>"
			</script>
			<%
		End If
	Else
		' just refresh the top bar to remove any "Save" buttons or old messages
		%>
		<script language = "javascript">
			parent.owBodyTopNav.location="owBodyTopNav.asp?sMessage="
		</script>
		<%
	End If
	%>
	<script language = "javascript">
		
		function ColumnOn(sStyle)
		{
			sStyle.background	= "#F5C058";
		}
		function ColumnOff(sStyle)
		{
			sStyle.background	= "#C3DAF9";
		}
		
		function ColumnDataOn(sStyle)
		{
			sStyle.background	= "#EAF1F9";
		}
		function ColumnDataOff(sStyle)
		{
			sStyle.background	= "#FFFFFF";
		}
		
	</script>
	
	<body style="font-family: Arial; font-size: 11px" topmargin="0" leftmargin="0" bgcolor=C3DAF9>
	<div id="tablediv" style="position: absolute; top: 0px; height: 100%; width:100%">
		<table width=100% border="0" cellpadding="2" cellspacing="0" style="font-size: 11px" bgcolor=FFFFFF>
		<form action='owListCountries.asp' method='post' name='Countries'>
			<input type='hidden' name='sAction' value=''>
			<input type='hidden' name='iTtlNumItems' value='<%=iTtlNumItems%>'>
			<input type='hidden' name='iDBLoc' value='<%=iDBLoc%>'>
			<input type='hidden' name='sSort' value='<%=sSort%>'>
			<input type='hidden' name='sSearchText' value='<%=sSearchText%>'>
			<input type='hidden' name='sSearch' value='<%=sSearch%>'>
			<tr>
				<td class="ColumnHead" align="center"><%=LANG_DT( "DELETEQUESTION", "Delete?" )%></td>
				<td onclick="location.href='owListCountries.asp?sSort=countryName'" onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead" bgcolor="#C3DAF9"><%=LANG_DT( "COUNTRY_NAME", "Country Name" )%></td>
				<td class="ColumnHead" align="center"><%=LANG_DT( "PROVENCESTATE", "Provence/State" )%></td>
				<td onclick="location.href='owListCountries.asp?sSort=countryCode'" onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead" bgcolor="#C3DAF9" align="center"><%=LANG_DT( "COUNTRY_CODE", "Country Code" )%></td>
				<td onclick="location.href='owListCountries.asp?sSort=Active DESC'" onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead" bgcolor="#C3DAF9"><%=LANG_DT( "COUNTRY_ACTIVEQUEST", "Active?" )%></td>
				<td onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead" bgcolor="#C3DAF9" align=center><%=LANG_DT( "COUNTRY_TAX", "Tax" )%></td>
			</tr>
			<%
			If ( NOT rsStoreData.EOF ) Then
				iPaginationCount = 0
				While ( ( NOT rsStoreData.EOF ) And ( iPaginationCount < iOWNumPerPage ) )
					sCountryName	= rsStoreData("countryName")
					sCountryCode	= rsStoreData("countryCode")
					sActive			= Trim(rsStoreData("Active"))

					If ( sSearchText <> "" ) Then
						If ( sSearch = "FirstChar" ) Then
							sQueryString2 = "sAction=Search&sSearch=FirstChar&sSearchText=" & sSearchText & "&sSort=" & sSort & "&sCountryCode=" & sCountryCode & "&iOWNumPerPage=" & iOWNumPerPage & "&iTtlNumItems=" & iTtlNumItems & "&iDBLoc=" & iDBLoc
						Else
							sQueryString2 = "sAction=Search&sSearch=countryName&sSearchText=" & sSearchText & "&sSort=" & sSort & "&sCountryCode=" & sCountryCode & "&iOWNumPerPage=" & iOWNumPerPage & "&iTtlNumItems=" & iTtlNumItems & "&iDBLoc=" & iDBLoc
						End If
					Else
						sQueryString2 = "sSort=" & sSort & "&sCountryCode=" & sCountryCode & "&iOWNumPerPage=" & iOWNumPerPage & "&iTtlNumItems=" & iTtlNumItems & "&iDBLoc=" & iDBLoc
					End If
					%>
					<tr onMouseOver="ColumnDataOn(this.style);" onMouseOut="ColumnDataOff(this.style);">
						<td width=5% class='ColumnData' align="center"><input size="1" type="checkbox" style="font-size: 6px;" name="sDelete<%=sCountryCode%>" value="Y"></td>
						<td onClick="location.href='owModifyCountries.asp?<%=sQueryString2%>'" class='ColumnData'><%=sCountryName%>&nbsp;</td>
						<td width=5% class='ColumnData' align="center">
								<%
								sSQLText = "select * from stateCodes SC, countryCodes CC where CC.CountryCode = SC.CountryCode AND CC.CountryCode = '" & rsStoreData("CountryCode") & "'"
								Call DB_getFromDatabase(sSQLText, rsStoreData2, "") 
								If ( rsStoreData2.EOF ) Then
									Response.Write "No " & rsStoreData("TerritoryLabel") & " assigned"
								Else
									%>
									<SELECT name=stateCode size=1 align=top>
										<OPTION value=""><%=rsStoreData2("TerritoryLabel")%></OPTION>
										<%do while not rsStoreData2.eof
											%><option value="<%=rsStoreData2("stateCode")%>"><%=rsStoreData2("stateName")%></OPTION><%
											rsStoreData2.movenext
										loop%>
									</SELECT>
									<%
								End If
								Call DB_closeRecordset(rsStoreData2)
								%>
						</td>
						<td width=75 onClick="location.href='owModifyCountries.asp?<%=sQueryString2%>'" class='ColumnData' align="center"><%=sCountryCode%>&nbsp;</td>
						<td width=5% class='ColumnData' align="center">
							<input type='hidden' name='sOldActive<%=sCountryCode%>' value='<%=sActive%>'>
							<input type='checkbox' name='sActive<%=sCountryCode%>' value='Y' <%If ( sActive = "Y" ) Then Response.Write "checked" End If%>>
						</td>
						<td width=25 onClick="location.href='owModifyCountries.asp?<%=sQueryString2%>'" class='ColumnData' align="center">
							<%
							sSQLText = "SELECT Sum(Percentage) FROM CountryTax WHERE CountryCode = '" & sCountryCode & "'"
							Call DB_getFromDatabase(sSQLText, rsStoreData2, "")
							If ( NOT rsStoreData2.EOF ) Then
								If ( NOT IsNull(rsStoreData2(0)) ) Then
									If ( CDbl(rsStoreData2(0)) > 0 ) Then
										Response.Write rsStoreData2(0) & "%"
									Else
										Response.Write "&nbsp;"
									End If
								Else
									Response.Write "&nbsp;"
								End If
							End If
							Call DB_closeRecordset(rsStoreData2)
							%>
						</td>
					</tr>
					<%
					rsStoreData.movenext
					iPaginationCount = iPaginationCount + 1
				Wend
			End If
			Call DB_closeRecordset(rsStoreData)
			%>
		</form>
	</table>
	<!--#include file="../footer.asp"-->
	
	<%
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Function DeleteCountries(sCountryCode)
	
		if bOWBackOfficeDemoMode then
			DeleteCountries = LANG_DT( "COUNTRY_DISABLED", "Function disabled in demo mode." )
		Else
			if trim(sCountryCode)="" then
				DeleteCountries = LANG_DT( "COUNTRY_SELECTCOUNTRY", "You must specify a country to delete." )
			Else
				sSQLText = "SELECT * FROM StateCodes WHERE CountryCode = '" & sCountryCode & "'"
				Call DB_getFromDatabase(sSQLText, rsStoreData, "")
				While ( NOT rsStoreData.EOF )
					Call DB_updateDatabase("DELETE FROM StateTax WHERE StateCode = '" & rsStoreData("StateCode") & "'")
					rsStoreData.MoveNext
				Wend
				Call DB_closeRecordset(rsStoreData)
				Call DB_updateDatabase("DELETE FROM StateCodes WHERE CountryCode = '" & sCountryCode & "'")
				Call DB_updateDatabase("DELETE FROM CountryTax WHERE CountryCode = '" & sCountryCode & "'")
				Call DB_updateDatabase("DELETE FROM countryCodes WHERE CountryCode = '" & sCountryCode & "'")
			end if
		end if

	End Function
	'************************************************************************************
%>