<!--#include file="../../owFunctions/I_GeneralFunctions.asp"-->
<!--#include file="../Functions/I_AccountsProcess.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 sSort, bRefresh, sSearch, sSearchText, sActive, sGroupUnq, sAction, sError, sMessage
	Dim sPassword, sFName, sLName, sPhone, sEmail, sCustomerCompany, sCreditLimit
	Dim sCreditUsed, sBillingAddress, sBillingCity, sBillingStateCode
	Dim sBillingState, sBillingCountryCode, sBillingZip, sShippingAddress, sShippingCity
	Dim sShippingStateCode, sShippingState, sShippingCountryCode, sShippingZip, sLogin
	
	sAction					= Trim(Request("sAction"))
	sAccountUnq				= Trim(Request("sAccountUnq"))
	bRefresh				= Trim(Request("bRefresh"))
	sSort					= Trim(Request("sSort"))
	sSearch					= Trim(Request("sSearch"))
	sSearchText				= Trim(Request("sSearchText"))
	sBillingCountryCode2	= Trim(Request("sBillingCountryCode2"))
	sGroupUnq				= Trim(Request("sGroupUnq"))
	If ( sGroupUnq = "" ) Then
		sGroupUnq = C_GROUP_RETAIL
	Else
		If ( IsNumeric(sGroupUnq) ) Then
			sGroupUnq = CInt(sGroupUnq)
		Else
			sGroupUnq = C_GROUP_RETAIL
		End If
	End If
	If ( sAccountUnq = "" ) Then sAccountUnq = 0 End If
	
	If ( sAction = "UpdateCountry" ) Then
		sError = RetrieveData(sAccountUnq)
	ElseIf ( sAction = "ModifyCustomer" ) Then
		If ( NOT bOWBackOfficeDemoMode ) Then	' just do a cursory check in case hackers try to replicate the forms on their computers (return no error)
			sEncryptedPassword = EnCrypt(Trim(Request("sPassword")), sOWEncryptionPassword)
			If ( AccountExists(sEmail, sEncryptedPassword) ) Then
				sMessage = LANG_DT( "CUSTOMER_EXISTS", "** Account Exists. Enter new email & password. **" )
			Else
				sAccountUnq			= CONVERSION_SQLEncode2(request("sAccountUnq"),10)
				sCity				= CONVERSION_SQLEncode2(Request("sCity"),100)
				sZip				= CONVERSION_SQLEncode2(Request("sZip"),20)
				sBillingCountryCode	= CONVERSION_SQLEncode2(Request("sBillingCountryCode"),20)
				sBillingState		= CONVERSION_SQLEncode2(Request("sState"),50)
				sBillingStateCode	= CONVERSION_SQLEncode2(Request("sStateCode"),10)
				sAddress			= CONVERSION_SQLEncode2(Request("sAddress"),100)
			    sActive				= CONVERSION_SQLEncode2(Request("sActive"),10)

				' ADV's don't need sql conversion - the ADV write function does it
				sPhone				= Trim(Request("sPhone"))
				sFName				= Trim(Request("sFName"))
				sLName				= Trim(Request("sLName"))
				sCustomerCompany	= Trim(Request("sCustomerCompany"))
			    sEmail				= Trim(Request("sEmail"))
			    sLogin				= Trim(Request("sLogin"))
			    
			    if sState<>"" and sStateCode<>"" then sState = "" end if
			    
			    ' update CustAltBill
			    Call DB_updateDatabase("UPDATE CustAltBill SET BillingAddress = '" & sAddress & "', BillingCity = '" & sCity & "', BillingStateCode = '" & sBillingStateCode & "', BillingState = '" & sBillingState & "', BillingCountryCode = '" & sBillingCountryCode & "', BillingZip = '" & sZip & "' WHERE AccountUnq = " & sAccountUnq)
			
				' update owAccounts
				If ( sActive = "Y" ) Then
					If ( ACCNT_InGroup(sAccountUnq, C_GROUP_ADMIN) ) Then	' admins use an actual login, customers use their email address
						Call DB_updateDatabase("UPDATE owAccounts SET Login = '" & sLogin & "', Password = '" & sEncryptedPassword & "' WHERE AccountUnq = " & sAccountUnq)
					Else
						Call DB_updateDatabase("UPDATE owAccounts SET Login = '" & sEmail & "', Password = '" & sEncryptedPassword & "' WHERE AccountUnq = " & sAccountUnq)
					End If
				Else
					' deactivate this account
					Call DB_updateDatabase("UPDATE owAccounts SET RemoveDate = #" & CONVERSION_FormatDate(Now(), "L") & "# WHERE AccountUnq = " & sAccountUnq)
				End If
				
				Call UpdateGroups(sAccountUnq)
	
				' update any ADV information
				Call ACCNT_WriteADV("OW_CUSTPHONE", sPhone, "V", sAccountUnq, sViewLvl)
				Call ACCNT_WriteADV("OW_CUSTEMAIL", sEmail, "V", sAccountUnq, sViewLvl)
				Call ACCNT_WriteADV("OW_CUSTCOMPANY", sCustomerCompany, "V", sAccountUnq, sViewLvl)
				Call ACCNT_WriteADV("OW_CUSTFNAME", sFName, "V", sAccountUnq, sViewLvl)
				Call ACCNT_WriteADV("OW_CUSTLNAME", sLName, "V", sAccountUnq, sViewLvl)
				
				sMessage = LANG_DT( "CUSTOMER_CHANGES_SAVED", "** Changes saved **" )
			End If
		Else
			sMessage = LANG_DT( "GLOBAL_FUNCTION_DISABLED", "Function Disabled in Demo." )
		End If
	Else
		sError = RetrieveData(sAccountUnq)
	End If
	
	If ( sError = "" ) Then
		Call WriteForm()
	Else
		Call owMessage(sError, C_ERROR)
	End If
	
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Sub WriteForm()
		%>
		<script type="text/javascript" src="../Script/fValConfig.js"></script>
		<script type="text/javascript" src="../Script/fValidate.js"></script>
		
		<script language = "javascript">
	
			parent.owBodyTopNav.location="owBodyTopNav.asp?sPage=ModifyCustomer&sMessage=<%=Server.URLEncode(sMessage)%>"
			parent.owBodyFooter.location="owBodyFooter.asp?sAction=Null"
			
		</script>
		<body onLoad = 'toForm()' style="font-family: Arial; font-size: 11px;" topmargin="0" leftmargin="0" bgcolor=C3DAF9>
		
		<style>
			input.owDisabled, select.owDisabled, textarea.owDisabled {
				border: 2px inset #FFFFFF;
				background-color: #BBBBBB;
			}
			.owDisabledContainerW {
				font-family: verdana, arial, helvetica, sans-serif;
				font-size: 10px;
				position: relative; left: 1px; top: 1px; color: #777777;
			}
			.owDisabledTextW {
				font-family: verdana, arial, helvetica, sans-serif;
				font-size: 10px;
				position: absolute; left: -1px; top: -1px; color: #DDDDDD;
			} 
		</style>
		
		<form method="post" name="modifyCust" action='owModifyCustomer.asp'>
			<input type='hidden' name='sAction' value='ModifyCustomer'>
			<input type='hidden' name='sSort' value='<%=sSort%>'>
			<input type='hidden' name='sSearchText' value='<%=sSearchText%>'>
			<input type='hidden' name='sSearch' value='<%=sSearch%>'>
			<input type="hidden" name="sAccountUnq" value="<%=sAccountUnq%>">
			<input type="hidden" name="sGroupUnq" value="<%=sGroupUnq%>">
			<table border="0" cellpadding="0" cellspacing="0" width="100%" style="padding:5px; FONT-WEIGHT: bold; FONT-SIZE: 11px; COLOR: #808080" bgcolor="#ffffff"><tr><td>
			<table border="0" cellpadding="0" cellspacing="0" width="100%" style="FONT-WEIGHT: bold; FONT-SIZE: 11px; COLOR: #808080" bgcolor="#ffffff">
				<tr>
					<td style='padding-top: 5px;'>
						<%=LANG_DT( "CUSTOMER_FNAME", "First Name" )%>
					</td>
					<td>
						<%=LANG_DT( "CUSTOMER_LNAME", "Last Name" )%>
					</td>
					<td>
						<%=LANG_DT( "CUSTOMER_COMPANY", "Company" )%>
					</td>
					<td>
						<%=LANG_DT( "CUSTOMER_EMAIL", "Email" )%>
					</td>
				</tr>
				<tr>
					<td>
						<%VALIDATE_textbox "sFName", sFName, 25, "textbox", "blank"%>
					</td>
					<td>
						<%VALIDATE_textbox "sLName", sLName, 25, "textbox", "blank"%>
					</td>
					<td>
						<%VALIDATE_textbox "sCustomerCompany", sCustomerCompany, 25, "textbox", "blank|bok"%> 
					</td>
					<td>
						<%VALIDATE_textbox "sEmail", sEmail, 25, "textbox", "email"%>
					</td>
				</tr>
				
				<tr>
					<td style='padding-bottom: 2px; padding-top: 6px;'>
						<%=LANG_DT( "CUSTOMER_ADDRESS", "Address" )%>
					</td>
					<td style='padding-bottom: 2px; padding-top: 6px;'>
						<%=LANG_DT( "CUSTOMER_CITY", "City" )%>
					</td>
					<td style='padding-bottom: 2px; padding-top: 6px;'>
						<%=LANG_DT( "CUSTOMER_STATE", "State" )%>
					</td>
					<td style='padding-bottom: 2px; padding-top: 6px;'>
						<%=LANG_DT( "CUSTOMER_ZIP", "Zip" )%>
					</td>
				</tr>
				<tr>
					<td>
						<%VALIDATE_textbox "sAddress", sBillingAddress, 25, "textbox", "blank"%>
					</td>
					<td>
						<%VALIDATE_textbox "sCity", sBillingCity, 25, "textbox", "blank"%>
					</td>
					<td>
						<SELECT name=sStateCode size=1 align=top>
						<%
						sSQLText = "SELECT * FROM stateCodes WHERE Active='Y' AND CountryCode = '" & sBillingCountryCode & "'"
						Call DB_getFromDatabase(sSQLText, rsStoreData2, "") 
						If ( NOT rsStoreData2.EOF ) Then
							do while not rsStoreData2.eof
								pStateCode2 = rsStoreData2("stateCode")
								%><option value="<%=pStateCode2%>" <%if pStateCode2=sBillingStateCode then response.write "selected" end if%>><%=rsStoreData2("stateName")%></OPTION><%
								rsStoreData2.movenext
							loop
						Else
							Response.Write LANG_DT( "CUSTOMER_STATE_EMPTY", "State/Provence database is empty." )
						End If
						Call DB_closeRecordset(rsStoreData2)
						%>
						</SELECT>
						<%VALIDATE_textbox "sStates", sBillingState, 2, "textbox", ""%> 
						<!input type='hidden' name='sStates2' value='' alt='eitheror|,|sStateCode,sStates'>
					</td>
					<td>
						<%VALIDATE_textbox "sZip", sBillingZip, 10, "textbox", "blank"%>
					</td>
				</tr>
				
				<tr>
					<td style='padding-bottom: 2px; padding-top: 6px;'>
						<%=LANG_DT( "CUSTOMER_COUNTRY", "Country" )%>
					</td>
					<td style='padding-bottom: 2px; padding-top: 6px;'>
						<%=LANG_DT( "CUSTOMER_PHONE", "Phone" )%>
					</td>
					<td style='padding-bottom: 2px; padding-top: 6px;'>
						<%=LANG_DT( "CUSTOMER_PASSWORD", "Password" )%>
					</td>
					<td style='padding-bottom: 2px; padding-top: 6px;'>
						
					</td>
				</tr>
				<tr>
					<td>
						<%
						sSQLText = "SELECT * FROM countryCodes WHERE Active = 'Y' ORDER BY Position"
						Call DB_getFromDatabase(sSQLText, rsStoreData2, "")
						If ( NOT rsStoreData2.EOF ) Then
							%>
							<SELECT onChange='modifyCust.submit();' name=sBillingCountryCode style="BORDER-RIGHT: #C3DAF9 1px solid; BORDER-TOP: #C3DAF9 1px solid; FONT-SIZE: 9px; BORDER-LEFT: #C3DAF9 1px solid; BORDER-BOTTOM: #C3DAF9 1px solid">
								<%
								do while not rsStoreData2.eof
									sBillingCountryCode2 = rsStoreData2("countryCode")
									%><option value="<%=sBillingCountryCode2%>" <%if sBillingCountryCode=sBillingCountryCode2 then response.write "selected" end if%>><%=LCase(rsStoreData2("countryName"))%></OPTION><%
									rsStoreData2.movenext
								loop
								%>
							</SELECT>
							<%
						Else
							Response.Write LANG_DT( "CUSTOMER_COUNTRY_EMPTY", "Country Database is empty." )
						End If
						Call DB_closeRecordset(rsStoreData2)
						%>
					</td>
					<td>
						<%VALIDATE_textbox "sPhone", sPhone, 25, "textbox", ""%>
					</td>
					<td>
						<%VALIDATE_textbox "sPassword", sPassword, 25, "password", "blank"%>
					</td>
					<td>
						
					</td>
				</tr>
				<tr>
					<td valign=top style='padding-bottom: 2px; padding-top: 6px;'>
						<span class="owDisabledContainerW"><%=LANG_DT( "CUSTOMER_ACTIVE", "Active " )%><font color="#FFFFFF" class="owDisabledTextW"><%=LANG_DT( "CUSTOMER_ACTIVE", "Active " )%></font></span>
						<br>
						<select name="sActive" class='owDisabled'>
							<option value='Y'><%=LANG_DT( "CUSTOMER_YES", "Yes" )%></option>
						</select>
					</td>
					<td style='padding-bottom: 2px; padding-top: 6px;' valign=top>
						<%=LANG_DT( "CUSTOMER_TYPE", "Type" )%><br>
						<select name="sCustGroupUnq">
						<%
						' doing it this way so if we want to remove the dealers for SOHO, etc. it's easy enough to just del the db entry
						'	these Groups are mutually-exclusive, hence the drop-down list
						sSQLText = "SELECT GroupUnq, Name FROM owAGroups WHERE (GroupUnq = " & C_GROUP_RETAIL & " OR GroupUnq = " & C_GROUP_WHOLESALE & ") ORDER BY GroupUnq"
						Call DB_getFromDatabase(sSQLText, rsStoreData2, "")
						While ( NOT rsStoreData2.EOF )
							iGroupUnq = rsStoreData2("GroupUnq")
'Response.Write ":" & iGroupUnq & ":<Br>"
'Response.Write ":" & sAccountUnq & ":<Br>"
'Response.Write ":" & ACCNT_InGroup(sAccountUnq, iGroupUnq) & ":<Br>"
							If ( ACCNT_InGroup(sAccountUnq, iGroupUnq) ) Then
								Response.Write "<option value='" & iGroupUnq & "' selected>" & rsStoreData2("Name") & "</option>"
								'sEXOrigGroupUnq = iGroupUnq & ", "
								sOrigGroupUnq	= iGroupUnq
							Else
								Response.Write "<option value='" & iGroupUnq & "'>" & rsStoreData2("Name") & "</option>"
							End If
							rsStoreData2.MoveNext
						Wend
						Call DB_closeRecordset(rsStoreData2)
						%>
						</select>
						<input type='hidden' name='sOrigGroupUnq' value='<%=sOrigGroupUnq%>'>
					</td>
					<td style='padding-bottom: 2px; padding-top: 6px;'>
						<%=LANG_DT( "CUSTOMER_EXTYPE", "Extended Type" )%><br>
						<select name="sEXGroupUnq" multiple>
						<option value=''>None</option>
						<%
						sSQLText = "SELECT GroupUnq, Name FROM owAGroups WHERE (GroupUnq <> " & C_GROUP_RETAIL & " AND GroupUnq <> " & C_GROUP_WHOLESALE & ") ORDER BY GroupUnq"
						Call DB_getFromDatabase(sSQLText, rsStoreData2, "")
						While ( NOT rsStoreData2.EOF )
							iGroupUnq = rsStoreData2("GroupUnq")
							If ( ACCNT_InGroup(sAccountUnq, iGroupUnq) ) Then
								Response.Write "<option value='" & iGroupUnq & "' selected>" & rsStoreData2("Name") & "</option>"
								sEXOrigGroupUnq = sEXOrigGroupUnq & iGroupUnq & ", "
							Else
								Response.Write "<option value='" & iGroupUnq & "'>" & rsStoreData2("Name") & "</option>"
							End If
							rsStoreData2.MoveNext
						Wend
						Call DB_closeRecordset(rsStoreData2)
						%>
						</select>
						<input type='hidden' name='sEXOrigGroupUnq' value='<%=sEXOrigGroupUnq%>'>
					</td>
					<td valign=top style='padding-bottom: 2px; padding-top: 6px;'>
						<span class="owDisabledContainerW"><%=LANG_DT( "CUSTOMER_TAXEXEMPTSTATUS", "Tax Exempt?" )%><font color="#FFFFFF" class="owDisabledTextW"><%=LANG_DT( "CUSTOMER_TAXEXEMPTSTATUS", "Tax Exempt?" )%></font></span><br>
						<select name='sOW_TAXEXEMPTSTATUS' class='owDisabled'>
							<option value='N'><%=LANG_DT( "CUSTOMER_NO", "No" )%></option>
						</select>
					</td>
				</tr>
				<tr>
					<td style='padding-bottom: 2px; padding-top: 6px;' colspan=4>
						<table border="0" cellpadding="5" cellspacing="0" style="FONT-WEIGHT: bold; FONT-SIZE: 11px; COLOR: #808080" bgcolor="#ffffff">
							<tr>
								<td>
									<span class="owDisabledContainerW"><%=LANG_DT( "CUSTOMER_LINEOFCREDIT", "Line of Credit" )%><font color="#FFFFFF" class="owDisabledTextW"><%=LANG_DT( "CUSTOMER_LINEOFCREDIT", "Line of Credit" )%></font></span><br>
									<input type='text' name='' value='' class='owDisabled' size=10 readonly>
								</td>
								<td>
									<span class="owDisabledContainerW"><%=LANG_DT( "CUSTOMER_CREDITUSED", "Credit Used" )%><font color="#FFFFFF" class="owDisabledTextW"><%=LANG_DT( "CUSTOMER_CREDITUSED", "Credit Used" )%></font></span><br>
									<input type='text' name='' value='' class='owDisabled' size=10 readonly>
								</td>
								<td valign=top>
									<span class="owDisabledContainerW"><%=LANG_DT( "CUSTOMER_CREDITLEFT", "Credit Left" )%><font color="#FFFFFF" class="owDisabledTextW"><%=LANG_DT( "CUSTOMER_CREDITLEFT", "Credit Left" )%></font></span><br>
									<span class="owDisabledContainerW">0<font color="#FFFFFF" class="owDisabledTextW">0</font></span><br>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td style='padding-bottom: 2px; padding-top: 6px;' colspan=4>
						<%If ( ACCNT_InGroup(sAccountUnq, C_GROUP_ADMIN) ) Then%>
						<%=LANG_DT( "CUSTOMER_ADMINLOGIN", "Administration Login" )%><br>
						<%VALIDATE_textbox "sLogin", sLogin, 25, "textbox", "blank"%><br>
						<font size=-2><%=LANG_DT( "CUSTOMER_ADMINLOGIN2", "If this is your account, changing the login or password will immediately log you out." )%></font>
						<%End If%>
					</td>
				</tr>
			</table>
			</td></tr></table>
		</form>
		<form method='post' name='delcustomer' action='owListCustomers.asp'>
			<input type='hidden' name='sDelete<%=sAccountUnq%>' value=''>
			<input type='hidden' name='sAction' value='Delete'>
			<input type='hidden' name='sSort' value='<%=sSort%>'>
		</form>
		<%
	End Sub
	'************************************************************************************
	
	
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Function RetrieveData(sAccountUnq)
	
		RetrieveData = ""
	
		sSQLText = "SELECT * FROM CustAltBill CAB, CustAltShip CAS, owAccounts A WHERE A.AccountUnq = CAB.AccountUnq AND CAB.AccountUnq = CAS.AccountUnq AND CAB.AccountUnq = " & sAccountUnq & " AND CAB.Position = 0 AND CAS.Position = 0"
		Call DB_getFromDatabase(sSQLText, rsStoreData, "") 
		If ( NOT rsStoreData.EOF ) Then
			sPassword				= Decrypt(rsStoreData("password"), sOWEncryptionPassword)
			sFName					= ACCNT_ReturnADV("OW_CUSTFNAME", "V", sAccountUnq, C_OVERRIDE_ADV)
			sLName					= ACCNT_ReturnADV("OW_CUSTLNAME", "V", sAccountUnq, C_OVERRIDE_ADV)
			sPhone					= ACCNT_ReturnADV("OW_CUSTPHONE", "V", sAccountUnq, C_OVERRIDE_ADV)
			sEmail					= ACCNT_ReturnADV("OW_CUSTEMAIL", "V", sAccountUnq, C_OVERRIDE_ADV)
			sCustomerCompany		= ACCNT_ReturnADV("OW_CUSTCOMPANY", "V", sAccountUnq, C_OVERRIDE_ADV)
			
			sBillingAddress			= Trim(rsStoreData("BillingAddress"))
			sBillingCity			= Trim(rsStoreData("BillingCity"))
			sBillingStateCode		= Trim(rsStoreData("BillingStateCode"))
			sBillingState			= Trim(rsStoreData("BillingState"))
			sBillingCountryCode		= Trim(rsStoreData("BillingCountryCode"))
			sBillingZip				= Trim(rsStoreData("BillingZip"))
			
			sShippingAddress		= Trim(rsStoreData("ShippingAddress"))
			sShippingCity			= Trim(rsStoreData("ShippingCity"))
			sShippingStateCode		= Trim(rsStoreData("ShippingStateCode"))
			sShippingState			= Trim(rsStoreData("ShippingState"))
			sShippingCountryCode	= Trim(rsStoreData("ShippingCountryCode"))
			sShippingZip			= Trim(rsStoreData("ShippingZip"))
			
			dAddDate				= rsStoreData("AddDate")
			dRemoveDate				= rsStoreData("RemoveDate")
			sLogin					= Trim(rsStoreData("Login"))	' changeable if the user is an admin
			
			If ( IsNull(dRemoveDate) ) Then
				sActive = "Y"
			Else
				If ( DateDiff("s", dAddDate, dRemoveDate) > 0 ) Then
					sActive = "N"
				Else
					sActive = "Y"
				End If
			End If

			If ( sCreditUsed = "" ) Or ( IsNull(sCreditUsed) ) Then
				sCreditUsed = 0
			End If
			If ( sCreditLimit = "" ) Or ( IsNull(sCreditLimit) ) Then
				sCreditLimit = 0
			End If
			
			If ( sBillingCountryCode2 <> "" ) Then
				' if they submit the form via changing the country
				sBillingCountryCode = sBillingCountryCode2
			End If
			
			Select Case sGroupUnq
				Case C_GROUP_ADMIN
				Case C_GROUP_RETAIL
				Case C_GROUP_WHOLESALE
				Case C_GROUP_DISTRIBUTOR
			End Select
		Else
			RetrieveData = LANG_DT( "CUSTOMER_MISSING", "** Missing Customer! **" )
		End If
		Call DB_closeRecordset(rsStoreData)
		
	End Function
	'************************************************************************************
	
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Sub UpdateGroups(sAccountUnq)
	
	    sCustGroupUnq		= Trim(SQLEncode(request("sCustGroupUnq")))
	    sOrigGroupUnq		= Trim(SQLEncode(request("sOrigGroupUnq")))

		If ( sOrigGroupUnq <> sCustGroupUnq ) Then
			If ( sOrigGroupUnq <> "" ) Then		' this should rarely - if ever - be false
				Call DB_updateDatabase("DELETE FROM owAGroupMap WHERE AccountUnq = " & sAccountUnq & " AND GroupUnq = " & sOrigGroupUnq)
				Session.Contents.Remove("GROUP_" & sOrigGroupUnq & "_" & sAccountUnq)
			End If
			sSQLText = "INSERT INTO owAGroupMap (GroupUnq, AccountUnq, IgnoreGlobal, DomainUnq) VALUES (" & sCustGroupUnq & ", " & sAccountUnq & ", '', 0)"
			Call DB_updateDatabase(sSQLText)
		End If
	    
	    sEXGroupUnq			= Trim(SQLEncode(request("sEXGroupUnq")))
	    aEXGroupUnq			= Split(sEXGroupUnq, ", ", -1)
	    sEXOrigGroupUnq		= Trim(SQLEncode(request("sEXOrigGroupUnq")))
	    aEXOrigGroupUnq		= Split(sEXOrigGroupUnq, ", ", -1)
				
		' update the Groups this user is in
		'	have to see which ones they were actually removed from, then also delete associated ADV's and deallocate any session caching
		'sGroupUnq - change by replacing ", " with just "," and adding a , at the front. so it looks like
		'	,23,3,2,123,
		sEXGroupUnq	= "," & Replace(sEXGroupUnq, ", ", ",") & ","
		'	loop through the old list (in the form, put into #, #, #, # format then run the Split() to make into an array
		'		any from the old list that aren't in the new list, delete! and their ADV's
'response.write "a:" & sEXOrigGroupUnq & ":<BR><BR>"
		For iX = 0 To UBound(aEXOrigGroupUnq)
			sTemp = Replace(aEXOrigGroupUnq(iX), ",", "")
'response.write "b:" & sTemp & ":<BR>"
'response.write "c:" & sEXGroupUnq & ":<BR><BR>"
			If ( InStr(sEXGroupUnq, "," & sTemp & "," ) <= 0 ) Then
				Call DB_updateDatabase("DELETE FROM owAGroupMap WHERE AccountUnq = " & sAccountUnq & " AND GroupUnq = " & sTemp)
				Session.Contents.Remove("GROUP_" & sTemp & "_" & sAccountUnq)
'response.write "d:" & "GROUP_" & sTemp & "_" & sAccountUnq & ":<BR>"
			End If
		Next
		
		sEXOrigGroupUnq	= "," & Replace(sEXOrigGroupUnq, ", ", ",") & ","
		For iX = 0 To UBound(aEXGroupUnq)
			If ( InStr(sEXOrigGroupUnq, "," & aEXGroupUnq(iX) & "," ) <= 0 ) Then	' don't want to re-enter ones they didn't change
				sSQLText = "INSERT INTO owAGroupMap (GroupUnq, AccountUnq, IgnoreGlobal, DomainUnq) VALUES (" & aEXGroupUnq(iX) & ", " & sAccountUnq & ", '', 0)"
'response.write "e:" & sSQLText & "<Br>"
				Call DB_updateDatabase(sSQLText)
			End If
		Next
'response.end

	End Sub
	'************************************************************************************
	%>
<!--#include file="../footer.asp"-->