<!--#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

	sSort				= Trim(Request("sSort"))
	sSearch				= Trim(Request("sSearch"))
	sSearchText			= Trim(Request("sSearchText"))
	sCountryCode		= Trim(Request("sCountryCode"))
	sAction				= Trim(Request("sAction"))
	
	sPassword			= CONVERSION_SQLEncode2(request("sPassword"), 20)
	sCity				= CONVERSION_SQLEncode2(request("sCity"),100)
	sZip				= CONVERSION_SQLEncode2(request("sZip"),20)
	sState				= CONVERSION_SQLEncode2(request("sState"),50)
	sStateCode			= CONVERSION_SQLEncode2(request("sStateCode"),10)
	sAddress			= CONVERSION_SQLEncode2(request("sAddress"),100)

	sGroupUnq			= request("sGroupUnq")
	sEXGroupUnq			= request("sEXGroupUnq")
	aEXGroupUnq			= Split(sEXGroupUnq, ", ", -1)
	
	sPhone				= Trim(Request("sPhone"))
	sFName				= Trim(Request("sFName"))
	sLName				= Trim(Request("sLName"))
	sCustomerCompany	= Trim(Request("sCustomerCompany"))
    sEmail				= Trim(Request("sEmail"))

	If ( sAction = "UpdateCountry" ) Then
		' do nothing
	ElseIf ( sAction = "AddCustomer" ) Then
		If ( NOT bOWBackOfficeDemoMode ) Then	' just do a cursory check in case hackers try to replicate the forms on their computers (return no error)
			sPassword = EnCrypt(sPassword, sOWEncryptionPassword)
			If ( AccountExists(sEmail, sPassword) ) Then
				sError = LANG_DT( "CUSTOMER_EXISTS", "** Account Exists. Enter new email & password. **" )
			Else
				Call DB_updateDatabase("INSERT INTO owAccounts ( Login, Password, AddDate, RemoveDate, HomeDomain, IgnoreGlobal, Authenticated, AuthID, ExpireDate ) VALUES ('" & sEmail & "', '" & sPassword & "', #" & CONVERSION_FormatDate(Now(), "L") & "#, null, 0, '', 'Y', 0, null)")
				
				sSQLText = "SELECT AccountUnq FROM owAccounts WHERE Login = '" & sEmail & "' AND Password = '" & sPassword & "'"
				Call DB_getFromDatabase(sSQLText, rsStoreData, "") 
				If ( NOT rsStoreData.EOF ) Then
					iAccountUnq = rsStoreData("AccountUnq")
					
					' need to enter it into both - so that the JOINs will work
					Call DB_updateDatabase("INSERT INTO CustAltBill (AccountUnq, BillingAddress, BillingCity, BillingStateCode, BillingState, BillingCountryCode, BillingZip, Position) VALUES (" & iAccountUnq & ", '" & sAddress & "', '" & sCity & "', '" & sStateCode & "', '" & sState & "', '" & sCountryCode & "', '" & sZip & "', 0)")
					Call DB_updateDatabase("INSERT INTO CustAltShip (AccountUnq, ShippingAddress, ShippingCity, ShippingStateCode, ShippingState, ShippingCountryCode, ShippingZip, Position) VALUES (" & iAccountUnq & ", '" & sAddress & "', '" & sCity & "', '" & sStateCode & "', '" & sState & "', '" & sCountryCode & "', '" & sZip & "', 0)")
					
					' insert into the Group they belong to
					For iX = 0 To UBound(aEXGroupUnq)
						Call DB_updateDatabase("INSERT INTO owAGroupMap (GroupUnq, AccountUnq, IgnoreGlobal, DomainUnq) VALUES (" & aEXGroupUnq(iX) & ", " & iAccountUnq & ", '', 0)")
					Next
					Call DB_updateDatabase("INSERT INTO owAGroupMap (GroupUnq, AccountUnq, IgnoreGlobal, DomainUnq) VALUES (" & sGroupUnq & ", " & iAccountUnq & ", '', 0)")
					
					' insert any ADV information
					Call ACCNT_WriteADV("OW_CUSTPHONE", sPhone, "V", iAccountUnq, sViewLvl)
					Call ACCNT_WriteADV("OW_CUSTEMAIL", sEmail, "V", iAccountUnq, sViewLvl)
					Call ACCNT_WriteADV("OW_CUSTCOMPANY", sCustomerCompany, "V", iAccountUnq, sViewLvl)
					Call ACCNT_WriteADV("OW_CUSTFNAME", sFName, "V", iAccountUnq, sViewLvl)
					Call ACCNT_WriteADV("OW_CUSTLNAME", sLName, "V", iAccountUnq, sViewLvl)	
				End If
				Call DB_closeRecordset(rsStoreData)
				
				Response.Redirect "owListCustomers.asp?sMsg=1"	' 1 = Successfully added account
			End If
		Else
			sError = LANG_DT( "GLOBAL_FUNCTION_DISABLED", "Function Disabled in Demo." )
		End If
	Else
	End If
	
	If ( sCountryCode = "" ) Then
		' grab the first country so we can populate the state list
		sSQLText = "SELECT * FROM countryCodes WHERE Active = 'Y' ORDER BY Position"
		call DB_getFromDatabase(sSQLText, rsStoreData, "") 
		If ( NOT rsStoreData.EOF ) Then
			sCountryCode = rsStoreData("CountryCode")
		End If
		Call DB_closeRecordset(rsStoreData)
	End If
	%>
	<script language = "javascript">

		parent.owBodyTopNav.location="owBodyTopNav.asp?sPage=AddCustomer"
		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="addCust" action='owAddCustomer.asp'>
		<input type='hidden' name='sAction' value='AddCustomer'>
		<input type='hidden' name='sSort' value='<%=sSort%>'>
		<input type='hidden' name='sSearchText' value='<%=sSearchText%>'>
		<input type='hidden' name='sSearch' value='<%=sSearch%>'>
		<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", "", 25, "textbox", "blank"%>
				</td>
				<td>
					<%VALIDATE_textbox "sLName", "", 25, "textbox", "blank"%>
				</td>
				<td>
					<%VALIDATE_textbox "sCustomerCompany", "", 25, "textbox", "blank|bok"%> 
				</td>
				<td>
					<%VALIDATE_textbox "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", "", 25, "textbox", "blank"%>
				</td>
				<td>
					<%VALIDATE_textbox "sCity", "", 25, "textbox", "blank"%>
				</td>
				<td>
					<%
					sSQLText = "SELECT * FROM stateCodes WHERE Active='Y' AND CountryCode = '" & sCountryCode & "'"
					Call DB_getFromDatabase(sSQLText, rsStoreData, "") 
					%>
					<SELECT id="stateCode" name="sStateCode" size=1 align=top alt=''>
						<%
						do while not rsStoreData.eof 
							%><option value="<%=rsStoreData("stateCode")%>"><%=rsStoreData("stateName")%></OPTION><%
							rsStoreData.movenext
						loop
						Call DB_closeRecordset(rsStoreData)
						%>
					</SELECT>
					<%VALIDATE_textbox "sState", "", 2, "textbox" ,""%>
					<input type='hidden' name='sStates' value='' alt='eitheror|,|sStateCode,sState'>
				</td>
				<td>
					<%VALIDATE_textbox "sZip", "", 10, "textbox", "blank"%>
				</td>
			</tr>
			
			<tr>
				<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_COUNTRY", "Country" )%>
				</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>
					<%VALIDATE_textbox "sPhone", "", 25, "textbox", ""%>
				</td>
				<td>
					<%
					sSQLText = "SELECT * FROM countryCodes WHERE Active = 'Y' ORDER BY Position"
					Call DB_getFromDatabase(sSQLText, rsStoreData, "")
					If ( NOT rsStoreData.EOF ) Then
						%>
						<SELECT onChange='addCust.sAction.value="UpdateCountry"; addCust.submit();' name=sCountryCode 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 rsStoreData.eof
								sCountryCode2 = rsStoreData("countryCode")
								%><option value="<%=sCountryCode2%>" <%if sCountryCode=sCountryCode2 then response.write "selected" end if%>><%=LCase(rsStoreData("countryName"))%></OPTION><%
								rsStoreData.movenext
							loop
							%>
						</SELECT>
						<%
					Else
						Response.Write LANG_DT( "CUSTOMER_COUNTRY_EMPTY", "Country Database is empty." )
					End If
					Call DB_closeRecordset(rsStoreData)
					%>
				</td>
				<td>
					<%VALIDATE_textbox "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="sGroupUnq">
					<%
					' 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 )
						Response.Write "<option value='" & rsStoreData2("GroupUnq") & "'>" & rsStoreData2("Name") & "</option>"
						rsStoreData2.MoveNext
					Wend
					Call DB_closeRecordset(rsStoreData2)
					%>
					</select>
				</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, rsStoreData, "")
					While ( NOT rsStoreData.EOF )
						Response.Write "<option value='" & rsStoreData("GroupUnq") & "'>" & rsStoreData("Name") & "</option>"
						rsStoreData.MoveNext
					Wend
					Call DB_closeRecordset(rsStoreData)
					%>
					</select>
				</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>
		</table>
		</td></tr></table>
	</form>
	<%%>      
	<!--#include file="../footer.asp"-->