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


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

		' user is not logged in, redirect to login page
		if ( NOT bHasAccount ) then 
			response.redirect "../owCustomerAuthenticate.asp"
		Else
			sAction = Trim(Request("sAction"))
			
			If ( sAction = "EditProfile" ) Then
				Call EditProfile()
			End If
			
			' get customer data
			sSQLText = "SELECT * FROM CustAltBill CAB, owAccounts A WHERE A.AccountUnq = CAB.AccountUnq AND CAB.AccountUnq = " & iLoginAccountUnq
			Call DB_getFromDatabase(sSQLText, rsStoreData, "")
			If ( rsStoreData.EOF ) Then
				Response.Write LANG_DT( "CUSTINFO_MISSINGINFO", "Cannot locate customer information." )
			Else
				sName				= ACCNT_ReturnADV("OW_CUSTFNAME", "V", iLoginAccountUnq, C_OVERRIDE_ADV)
				sLastName			= ACCNT_ReturnADV("OW_CUSTLNAME", "V", iLoginAccountUnq, C_OVERRIDE_ADV)
				sPhone				= ACCNT_ReturnADV("OW_CUSTPHONE", "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)
				sStateCode			= rsStoreData("BillingStateCode")
				sCountryCode		= rsStoreData("BillingCountryCode")
				
				%>
				<script type="text/javascript" src="../../owManager/Script/fValConfig.js"></script>
				<script type="text/javascript" src="../../owManager/Script/fValidate.js"></script>
				
				<script language='JavaScript1.2' type='text/javascript'>
			
					function SubmitForm(objForm, sAction){
					
						if ( validateForm( objForm, false, false, false, true, 17 ) )
						{
							objForm.sAction.value = sAction;
							objForm.submit();
						}else{
							return false;
						}
					}
					
				</script>
				<table width=<%=sOWStoreTableWidth%> border=0 style='border: 1px solid #000000;' cellspacing=0 cellpadding=5>
				<form action="owCustomerEditProfile.asp" name="EditProfile" method="post" onSubmit='return SubmitForm(this, "EditProfile");'>
				<input type="hidden" name="sAction" value="EditProfile">
					<tr bgcolor="#eeeeee"><td colspan=2 style='border-bottom: 1px solid #000000;'><b><%=LANG_DT( "CUSTINFO_HEAD", "Modify Customer Data" )%></b></td></tr>

					<tr> 
						<td><%=LANG_DT( "CUSTINFO_CUSTNUM", "Customer Number" )%></td>
						<td><%=sOWCustomerPrefix&iLoginAccountUnq%></td>
					</tr>
					<tr> 
						<td>*<%=LANG_DT( "CUSTINFO_FNAME", "First Name" )%></td>
						<TD><%VALIDATE_textbox "customerName", sName, 30, "textbox", "blank"%></TD>
					</tr>    
					<tr> 
						<td>*<%=LANG_DT( "CUSTINFO_LNAME", "Last Name" )%></td>
						<TD><%VALIDATE_textbox "lastName", sLastName, 30, "textbox", "blank"%></TD>
					</tr>
					<tr> 
						<td><%=LANG_DT( "CUSTINFO_COMPANY", "Company Name" )%></td>
						<TD><%VALIDATE_textbox "customerCompany", sCustomerCompany, 30, "textbox", ""%></TD>
					</tr>
					<tr> 
						<td>*<%=LANG_DT( "CUSTINFO_PHONE", "Phone Number" )%></td>
						<TD><%VALIDATE_textbox "phone", sPhone, 30, "textbox", "blank"%></TD>
					</tr>
					<tr> 
						<td><%=LANG_DT( "CUSTINFO_EMAIL", "Email" )%></td>
						<td>   
							<%=sEmail%>       
							<input type="hidden" name="email" value="<%=sEmail%>">
						</td>
					</tr>
					<tr> 
						<td>*<%=LANG_DT( "CUSTINFO_PW", "Password" )%></td>
						<TD><%VALIDATE_textbox "password", DeCrypt(rsStoreData("password"), sOWEncryptionPassword), 30, "textbox", "blank"%></TD>
					</tr>
					<tr> 
						<td>*<%=LANG_DT( "CUSTINFO_ADDRESS", "Address" )%></td>
						<TD><%VALIDATE_textbox "address", rsStoreData("BillingAddress"), 30, "textbox", "blank"%></TD>
					</tr>
					<tr> 
						<td>*<%=LANG_DT( "CUSTINFO_ZIP", "Zip/Postal Code" )%></td>
						<TD><%VALIDATE_textbox "zip", rsStoreData("BillingZip"), 30, "textbox", "blank"%></TD>
					</tr>
					<tr> 
						<td><%=LANG_DT( "CUSTINFO_STATE", "State/Provence" )%></td>
						<td>         
							<%
							sSQLText = "SELECT S.StateCode, S.StateName FROM StateCodes S, CountryCodes C WHERE S.Active = 'Y' AND S.CountryCode = C.CountryCode AND C.Active = 'Y' ORDER BY S.StateName"
							Call DB_getFromDatabase(sSQLText, rsStoreData2, "")
							%>
							<SELECT name=stateCode size=1>
							<%
							While ( NOT rsStoreData2.EOF )
								sStateCode2 = rsStoreData2("stateCode")
								%><option value="<%=sStateCode2%>"<%if sStateCode2 = sStateCode then response.write "selected" End If%>><%=rsStoreData2("stateName")%></option><%
								rsStoreData2.movenext
							Wend
							Call DB_closeRecordset(rsStoreData2)
							%>
							</SELECT>
						</td>
					</tr>
					<tr> 
						<TD><%=LANG_DT( "CUSTINFO_ANOTHERSTATE", "Another State/Provence" )%></TD>
						<TD><%VALIDATE_textbox "state", rsStoreData("BillingState"), 30, "textbox", ""%></TD>
					</tr>
					<tr> 
						<td>*<%=LANG_DT( "CUSTINFO_CITY", "City" )%></td>
						<TD><%VALIDATE_textbox "city", rsStoreData("BillingCity"), 30, "textbox", ""%></TD>
					</tr>    
					<tr> 
						<td><%=LANG_DT( "CUSTINFO_COUNTRY", "Country" )%></td>
						<td>         
							<SELECT name=CountryCode>
							<%
							sSQLText = "SELECT countryCode, countryName FROM countryCodes WHERE Active = 'Y' ORDER BY Position"
							Call DB_getFromDatabase(sSQLText, rsStoreData2, "")
							While ( NOT rsStoreData2.EOF )
								sCountryCode2 = rsStoreData2("countryCode")
								%><option value="<%=sCountryCode2%>" <%if sCountryCode = sCountryCode2 then response.write "selected" End If%>><%=rsStoreData2("countryName")%></OPTION><%
								rsStoreData2.MoveNext
							Wend
							Call DB_closeRecordset(rsStoreData2)
							%>
							</SELECT>       
						</td>
					</tr>
	    
					<TR> 
						<td style='border-top: 1px solid #000000;'>
							* <%=LANG_DT( "CUSTINFO_REQUIRED", "required field" )%>
						</td>
						<td align=right style='border-top: 1px solid #000000;'>
							<input type="submit" name="save" value=" <%=LANG_DT( "CUSTINFO_SAVE", "Save Changes" )%> ">
						</td>
					</TR>
				</form>
				</table>
				<%
			End If
			Call DB_closeRecordset(rsStoreData)
		End If
		
	End Sub
	'************************************************************************************
	
	
	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Sub EditProfile()

		sEmail				= CONVERSION_SQLEncode2(Request("email"),30)
		sPassword			= CONVERSION_SQLEncode2(EnCrypt(Request("password"), sOWEncryptionPassword),50)
		sAddress			= CONVERSION_SQLEncode2(Request("address"),50)
		sCity				= CONVERSION_SQLEncode2(Request("city"),30)
		sZip				= CONVERSION_SQLEncode2(Request("zip"),20)
		sState				= CONVERSION_SQLEncode2(Request("state"),20)
		sStateCode			= CONVERSION_SQLEncode2(Request("stateCode"),4)
		sCountryCode		= CONVERSION_SQLEncode2(Request("countryCode"),4)

		Call ACCNT_WriteADV("OW_CUSTPHONE", Request("phone"), "V", iLoginAccountUnq, sViewLvl)
		Call ACCNT_WriteADV("OW_CUSTCOMPANY", Request("customerCompany"), "V", iLoginAccountUnq, sViewLvl)
		Call ACCNT_WriteADV("OW_CUSTFNAME", Request("customerName"), "V", iLoginAccountUnq, sViewLvl)
		Call ACCNT_WriteADV("OW_CUSTLNAME", Request("LastName"), "V", iLoginAccountUnq, sViewLvl)

		If ( bOWSFDemo ) Then
			Call owMessage(LANG_DT( "CUSTINFO_DEMODISABLED", "Option disabled in demo mode." ), C_ERROR)
		Else
			if sState<>"" and sStateCode<>"" then
				Call owMessage(LANG_DT( "CUSTINFO_SELSTATE", "You must select a State Code or Another State, you cannot select both." ), C_ERROR)
			Else
				' update customer record
				sSQLText = "UPDATE CustAltBill SET BillingAddress = '" & sAddress & "', BillingCity = '" & sCity & "', BillingState = '" & sState & "', BillingStateCode = '" & sStateCode & "', BillingZip = '" & sZip & "', BillingCountryCode = '" & sCountryCode & "' WHERE AccountUnq = " & iLoginAccountUnq
				call DB_updateDatabase(sSQLText)
				
				' update owAccounts
				Call DB_updateDatabase("UPDATE owAccounts SET Password = '" & sPassword & "' WHERE AccountUnq = " & iLoginAccountUnq)
				
				Call SF_ClosePage()
				Call owMessage(LANG_DT( "CUSTINFO_CONFIRM", "Your data has been successfully modified." ), C_SUCCESS)
			End If
		End If
		
	End Sub
	'************************************************************************************
%>