Knight-Celotex Locator

Celotex Logo

<% ' controller code here if request.querystring("state") = "" then displaySearch else 'validate then searchByZip valid = true if len(Request.Form("zipcode")) < 5 or len(Request.form("zipcode")) > 5 then session("error") = "Please submit a 5 Digit Zipcode" valid = "false" elseif isnumeric(Request.Form("zipcode")) = false then session("error") = "Please submit 5 Digit Zipode" valid = "false" end if if valid = "false" then Response.Redirect("distribution_dealerlocator.asp?error=true") else searchbyzip2(clng(Request.form("zipcode"))) end if end if %> <% function displaySearch %>
Enter Your Zip code:
 
 
No results for your Zip code?
No problem,click hereto get in contact with us and we can help.
<% end function Function displayresults(resultarray) 'going to get passed an array of customerid's to be displayed 'if array is Null then no dealers near user, boo! dim i i = 0 if resultarray(i) = "" then session("error") = "No Results For Specified Search" Response.Redirect("distribution_dealerlocator.asp?error=true") end if 'still around? we have results to display '---------------------------------------------- '----------declare some variables-------------- set cn1 = server.CreateObject("ADODB.Connection") set rs1 = server.CreateObject("ADODB.Recordset") set rs2 = server.CreateObject("ADODB.Recordset") cn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Inetpub2\celotex\pages\_private\knightdata.mdb;" '------------------------------------------------- '------------------------------------------------- 'DISPLAY SEARCH RESULT HEADER HTML---------------- %>
 
New Search
<%if session("searchfor") <> "" then %> Search Results For <%=session("searchfor")%> <% session("searchfor") = "" else Response.Write "Search Results" end if %>
<% dim x x = 0 while resultarray(i) <> "" and x < 10 'HERE IS THE HEART x = x + 1 'OPEN CUSTOMER CURRENT CUSTOMER RECORD rs1.open "SELECT * FROM kcdatabase_newdealerlocater WHERE UID=" & resultarray(i),cn1 '--------DISPLAY SPECIFIC DISTRIBUTOR---------------------------------------- %>
<%=rs1("customer")%>
<%=rs1("address")%>
<%Response.Write rs1("city") & ", " & rs1("state") & " " & rs1("zipcode")%>
Phone: <%=rs1("phone")%>
<% maplink = "http://www.mapquest.com/maps/map.adp?country=US&addtohistory=&address=" & parseaddress(rs1("address")) & "&city=&state=&zipcode=" & rs1("zipcode") & "&homesubmit.x=35&homesubmit.y=15" %>
<%'need to connect to dealerlocater table to get stocking products for dealer 'rs2.open "SELECT * FROM kcdatabase_dealerlocater WHERE customerid=" & rs1("ID"),cn1 if rs1("flamespec") = 1 then %> <% end if %> <% if rs1("korlite") = 1 then %> <% end if %> <% if rs1("roofing") = 1 then %> <%end if %> <% if rs1("sheathing") = 1 then %> <%end if %> <% if rs1("sturdybrace") = 1 then %> <%end if %> <% if rs1("soundstop") = 1 then %> <%end if %> <% if rs1("versakore") = 1 then %> <%end if %>
Stocking Products

FlameSpec®

Korlite
Structodek® Roof Insulation
Premium Insulating Sheathing
SturdyBrace
SoundStop®
Versakor® IB


<% rs1.close i = i + 1 wend %>
Return to top of page | New Search
<% '------------------------------- '-------CLEAN UP---------------- set rs1 = nothing set rs2 = nothing cn1.close set cn1 = nothing set i = nothing End Function %>
 
<% Function searchbyzip2(zipcode) session("resulttype") = "" session("recordcount") = "" session("resultpointer") = "" dim closedealers(30) dim closedealersid(30) dim cn1 dim rs1 set cn1 = server.CreateObject("ADODB.Connection") set rs1 = server.CreateObject("ADODB.Recordset") cn1.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Inetpub2\celotex\pages\_private\knightdata.mdb;" 'FIRST ALGORITHIM RETURN THE CLOSEST 10 dim closedealerszip(30) dim temprs dim maxdif dim mindif dim tempdif dim counter 'dim i 'dim x counter = 0 fuck = 1 rs1.Open "SELECT * FROM kcdatabase_newdealerlocater", cn1 while rs1.EOF = false 'first lets go through each record and put the 20 ID's into array that have the least 'distance from zip code if rs1("zipcode") <> "" then 'temprs = left(rs1("ZIP"),5) temprs = clng(rs1("zipcode")) tempdif = abs(zipcode - temprs) '--------------- THE ABOVE WORKS FINE 'FILL UP THE ARRAY If counter < 30 then closedealers(counter) = tempdif closedealersid(counter) = rs1("UID") closedealerszip(x) = rs1("zipcode") counter = counter + 1 else 'we know that the array is full lets go ahead and get max value i = 0 while i < 30 'first time in the while loop lets have maxdif = first index in array if i = 0 then maxdif = closedealers(i) x = i else 'compare current value to maxdif if closedealers(i) > maxdif then maxdif = closedealers(i) x = i end if end if i = i + 1 wend if tempdif < maxdif then closedealers(x) = tempdif closedealersid(x) = rs1("UID") closedealerszip(x) = rs1("zipcode") end if end if end if rs1.MoveNext wend '-- get rid of 0's i = 0 While i < 30 if closedealers(i) = 0 then closedealers(i) = 1 i = i + 1 wend i = 0 Dim intTempStore dim switch intAsc = 1 For i = 0 To UBound(closedealers) - 1 For j = i To UBound(closedealers) 'Sort Ascending if intAsc = 1 Then if closedealers(i) > closedealers(j) Then intTempStore = closedealers(i) closedealers(i) = closedealers(j) closedealers(j) = intTempStore intTempStore = closedealersid(i) closedealersid(i) = closedealersid(j) closedealersid(j) = intTempStore End if 'i > j 'Sort Descending Else if closedealers(i) < closedealers(j) Then intTempStore = closedealers(i) closedealers(i) = closedealers(j) closedealers(j) = intTempStore switch = closedealersid(i) closedealersid(i) = closedealersid(j) closedealersid(j) = switch End if 'i < j End if 'intAsc = 1 Next 'j Next 'i x = 1 z = 1 dim newarray(30) mm = 0 while x < 30 if closedealersid(x) <> "" then session("closedealersid" & z) = closedealersid(x) newarray(mm) = closedealersid(x) mm = mm + 1 z = z + 1 end if x = x + 1 wend 'NOW GO THROUGH 30 CLOSEST AND WEED OUT ONES THAT ARE NOT WITHIN 200 MILES rs1.close rs1.open "SELECT * FROM zipcodedata WHERE zipcode=" & clng(Request.Form("zipcode")),cn1 if rs1.eof and rs1.EOF then 'displayerror to user, unable to get lat and long for zipcode rs1.Close set rs1 = nothing cn1.Close set cn1 = nothing session("error") = "Could Not Find Data For Your Zipcode, Please Try A Differnet Zip or Search by State" Response.Redirect("distribution_dealerlocator.asp?error=true") end if lat1x = rs1("lat") long1x = rs1("long") rs1.close ii = 0 xx = 0 dim resultarray(30) while newarray(ii) 'lets go ahead and look up the lat and long for specific customer rs1.open "SELECT * FROM kcdatabase_newdealerlocater WHERE UID =" & newarray(ii), cn1 if getdistance(lat1x,long1x,rs1("latitude"),rs1("longitude")) < 95 then 'lets display it resultarray(xx) = newarray(ii) xx = xx + 1 end if rs1.close ii = ii + 1 wend set rs1 = nothing cn1.Close set cn1 = nothing session("searchfor") = Request.Form("zipcode") 'AT THIS POINT WE HAVE GOTTEN ALL OF THE RESULTS IN AN ARRAY LETS NOW DISPLAY THOSE RESULTS 'BY CALLING THE DISPLAYRESULTS FUNCTION AND PASSING THE RESULTARRAY AS A PARAM THAT HAS ID'S 'OF CUSTOMERS TO BE DISPLAYED. displayresults(resultarray) End Function Function getdistance(lat1,long1,lat2,long2) 'takes 2 coordinates and returns the distance in miles 'not exact, but close enough 'Convert all the degrees to radians */ 'Response.Write "lat1 is" & "---" & lat1 & " " & "long1is" & "---" & long1 lat1d = lat1 long1d = long1 lat1 = deg_to_rad(lat1) long1 = deg_to_rad(long1) lat2 = deg_to_rad(lat2) long2 = deg_to_rad(long2) 'Find the deltas */ delta_lat = lat2 - lat1 delta_long = long2 - long1 'response.write "delta_lat is" & delta_lat 'response.write "lat2 is" & lat2 'response.write "delta_long is" & delta_long 'Find the Great Circle distance */ temp = pow(sin(delta_lat/2.0)) + cos(lat1) * cos(lat2) * pow(sin(delta_long/2.0)) EARTH_RADIUS = 3956 getdistance = EARTH_RADIUS * 2 * atn((sqr(temp)/sqr(1-temp))) lat1 = lat1d long1 = long1d End Function Function deg_to_rad(deg) radians = 0.0 radians = deg * 3.14159/180.0 deg_to_rad = radians End Function Function pow(param) pow = param * param End Function Function parseaddress(address) slen = len(address) i = 1 while i <= slen 'take each character off one at a time, and put into another new string temp = left(address,1) if Asc(temp) = "32" then ' add + sign newaddress = newaddress & "+" else newaddress = newaddress & left(address,1) end if 'pull offf that left most character i = i + 1 address = right(address,len(address)-1) wend parseaddress = newaddress End Function %>