Link to home
Start Free TrialLog in
Avatar of ab10
ab10

asked on

I want to change the bgcolor of my web page

i want to change the bgcolor of my asp page and rerender it to a different color...

i want to give the users of my site the facility to change the color of the interface. So if i give them three colors Blue, Yellow and Green if the click one the bgcolor will turn to that color and when my user ges to another page on my site it stays the same color.

I have been trying to put some code together using Response.Write and Sessions but i can form some kind of a structure to work with

i would like to call blue.css for a blue background and so on... but i cannot just call the css because i want the color to be the same one other pages.

Thank You,

ab10
Avatar of DesertWarrior
DesertWarrior

you sure you tried with session variables?

I think it's the best way of doing it

you create a session variable named let's say BgCSS that will store the name of the CSS file to call to be used

when the user clicks on blue... Session("BgCSS") = "blue.css"
on green ... Session("BgCSS") = "Green.css"

and it will stay the same in each page cause the session variable doesn't change
check this out we used it on an html http://www.alpha-omega.tk/ it changes colours randomely i think you can come up with the code of how to set to 3 instead
Avatar of ab10

ASKER

I new to this so i could you give me some code to work with.

Does Session("BgCSS") = "blue.css" go in a onClick action in a button? i am not sure..........

and if i change the bgcolor to blue will it stay blue on another page?

Thank You,

Ab10

Avatar of Dean OBrien
I think desertwarrior has the right idea using session variables;

    i) you need to post a variable ie. 'color' to your ASP page.

   ii) at the begining of each of your ASP page have a check to see if the posted 'color' is different to your session("BgCSS"), if so change it so Session("BgCSS") = color.

  iii) Then whenever one of your ASP pages writes out a HTML reply page to send to the client, check Session(BgColor) to see which CSS page to include.

  i.e.   if  its blue
         
          response.write("<link rel='stylesheet' title='Default' href='blue.css'>
")

Might need to double check the syntax.

Easynow
On the top of each asp page, where you define the html header, you can also define the style, i.e.:
<link rel="stylesheet" type="text/css" href="http://www.mysite.com/styles/global.css">
so:
-------------------------
changeStylepage.asp sample
-------------------------

<%
'checks for the newStyle in querystring and sets session variable
Select Case request.querystring("newstyle")
Case 0
  Session("BgCSS") = "blue.css"
Case 1
  Session("BgCSS") = "red.css"
Case Else
  'always set a default, if session wasn't already defined:
  if Session("BgCSS") = "" then Session("BgCSS") = "blue.css"
End Select

%>

<html>
<head>
  <META http-equiv="Content-Type" content="text/html">
  <title>web sitel</title>
 
  <link rel="stylesheet" type="text/css" href="http://www.mysite.com/styles/<%=Session("BgCSS")%>">
</head>

<body>
<a href="changeStylepage.asp?newstyle=0">Blue Style</a>
<a href="changeStylepage.asp?newstyle=1">Red Style</a>

</body>
</html>



----------------------
other asp pages sample
----------------------

<%
'some asp code
checks if the session variable is set else, set it to a default
  if Session("BgCSS") = "" then Session("BgCSS") = "blue.css"
%>

<html>
<head>
  <META http-equiv="Content-Type" content="text/html">
  <title>web sitel</title>
 
<%
'just below here it chooses the css curretly in session
%>
  <link rel="stylesheet" type="text/css" href="http://www.mysite.com/styles/<%=Session("BgCSS")%>">
</head>

<body>
Change style
<a href="changeStylepage.asp?newstyle=0" target="_blank">Blue Style</a>
<a href="changeStylepage.asp?newstyle=1" target="_blank">Red Style</a>


More HTML More HTML More HTML More HTML More HTML More HTML
More HTML More HTML More HTML More HTML More HTML More HTML
More HTML More HTML More HTML More HTML More HTML More HTML

<%
'some asp code
%>

----------------------

Regards
Pedro
Avatar of ab10

ASKER

pedros

how can i change the bgcolor from another page without going back to the changeStylepage.asp and then chnaging it? so on each separate page i can change the color, is there a way to do a separte script and when the users clicks on the link it changes the color. So all i have to do is provide a link to that script from any page i would like?

Thank You,

i am very pleased witht he answers and will award the points soon....

Ab10
ab10

yes you can put it in a OnClick event, here's the way you can do this :

you have a listBox with all three choices that will call a function and in that function you will call another ASP page that will apply the changes to the server and client side...




<select name="lstColor" onChange="ChangeColor(this.form.lstColor.value)">
<option value=1>Blue</option>
<option value=2>Green</option>
<option value=3>Yellow</option>
</select>


function ChangeColor(NewColor)
{
window.document.forms[0].action="ApplyColor.asp?color="+NewColor
window.document.forms[0].submit();
}



and in the page called ApplyColor.asp you only have to check the value of the listbox retrieved from previous page:

var Value = Request.querystring(color)

if (Value == 1 )
         Session("BgColor") = "Blue.css"
if (Value == 2)
         Session("BgColor") = "green.css"
if (Value == 3)
         Session("BgColor") = "yellow.css"


you get the point? by the way this is jscript so if you want me to convert it in VbScript just ask

hope this helps




Avatar of ab10

ASKER

the thing is i dont want to use a list box i want to do it so i give the color blue as an image and the users click the image and it changes the bgcolor.

i like the way Pedros7 has done it, i just want to be able to change the color from another page because in that code it goes from test.asp to changecolor.asp to chnage the color wher ei just want to change the color from a different page instead of going back to changecolor.asp


thanks

Ab10
hi,

in the 'other asp pages sample', you'll notice that i've placed a couple of links that calls the changestylepage.asp!!! i've also set the target window to be _blank, so it will open in a separate window!!

what you can do is on the 'changeStylepage.asp sample' is the following:

-------------------------
changeStylepage.asp sample
-------------------------

<%
'checks for the newStyle in querystring and sets session variable
Select Case request.querystring("newstyle")
Case 0
 Session("BgCSS") = "blue.css"
Case 1
 Session("BgCSS") = "red.css"
Case Else
 'always set a default, if session wasn't already defined:
 if Session("BgCSS") = "" then Session("BgCSS") = "blue.css"
End Select

%>

<html>
<head>
 <META http-equiv="Content-Type" content="text/html">
 <title>web sitel</title>
</head>

<body onload="window.opener.reload();window.close;">
</body>
</html>
----------------------------------

to explain:
some page will call the changeStylepage.asp will be set the session variable
like any asp page is generates whatever appropriate html content (in this case not much at all!!)
once the html content is fully loaded in the browser, it will action the body tag onload event, which will refresh whichever page called it and auto close the changeStylepage.asp page!!


try this then have a look below for another slight modification of my answer.

----------------------------------------------------------

as an alternative to web links, you can use a select box (as sugested by DesertWarrior's), but i'd implement it in a slightly different way:

----------------------
other asp pages sample (form approach)
----------------------

<%
'some asp code
checks if the session variable is set else, set it to a default
 if Session("BgCSS") = "" then Session("BgCSS") = "blue.css"
%>

<html>
<head>
 <META http-equiv="Content-Type" content="text/html">
 <title>web sitel</title>
 
<%
'just below here it chooses the css curretly in session
%>
 <link rel="stylesheet" type="text/css" href="http://www.mysite.com/styles/<%=Session("BgCSS")%>">
</head>

<body>
<form action="changestylepage.asp">
<select name="newstyle" onChange="if (Confirm('Change style?')==true){this.submit();}">
<option value=0>Blue Style</option>
<option value=1>Red Style</option>
</select>
</form>


More HTML More HTML More HTML More HTML More HTML More HTML
More HTML More HTML More HTML More HTML More HTML More HTML
More HTML More HTML More HTML More HTML More HTML More HTML

<%
'some asp code
%>

---------------------------------------

if you use the form approach then on the changestylepage.asp, you need to change request.querystring to request.form in the example above.
Alternatively, I include here a method that will detect either approach:

-------------------------
changeStylepage.asp sample (detects either form or link approach)
-------------------------

<%
'checks for the newStyle in form and sets session variable
if request.form("newstyle") then
    Select Case request.form("newstyle")
    Case 0
        Session("BgCSS") = "blue.css"
    Case 1
        Session("BgCSS") = "red.css"
    Case Else
         'always set a default, if session wasn't already defined:
        if Session("BgCSS") = "" then Session("BgCSS") = "blue.css"
    End Select
else
    Select Case request.querystring("newstyle")
    Case 0
        Session("BgCSS") = "blue.css"
    Case 1
        Session("BgCSS") = "red.css"
    Case Else
        'always set a default, if session wasn't already defined:
        if Session("BgCSS") = "" then Session("BgCSS") = "blue.css"
    End Select
end if

%>

<html>
<head>
 <META http-equiv="Content-Type" content="text/html">
 <title>web sitel</title>
</head>

<body onload="window.opener.reload();window.close;">
</body>
</html>
----------------------------------


try it and see what you prefer.
something else you can do is to define the asp code in changestylepage.asp into a sub, save it separately into another file, so you maintain the code once for all your pages.

use asp includes to include that file, and at the beginning of every page execute the sub which will attempt to detect a style change request!!!
the page can then call itself and if a different style is chosen, it reload with the new style applied.
well you only have to call the page ChangeColor.asp again to change the color

so basically all you have to do is put your images and on the onClick event you call the function ChangeColor(NewColor)


<img src="whatever" name="imgGreen" onClick="ChangeColor('green.css')">
<img src="whatever" name="imgRed" onClick="ChangeColor(red.css')">
<img src="whatever" name="imgBlue" onClick="ChangeColor(blue.css')">

function ChangeColor(NewColor)
{
window.document.forms[0].action="ApplyColor.asp?color="+NewColor
window.document.forms[0].submit();
}


ApplyColor.asp :
in this page you only apply the new "color" variable that you retrieve by querystring as i demonstrated in my previous post
to the Session Variable

you can put your images in all pages if you want to give the possibility to change the bgcolor everywhere
it will always call ApplyColor.asp no matter where it is called from

and once the session variable is set it will stay the same on each page untill the user clicks one of those images again
Avatar of ab10

ASKER

DesertWarrior

does the function go in a java script tag or ?

I like the way Pedros7 done his code so i would like to use that but all i want to do is change the color from a different page so can i use your code like this:

<img src="whatever" name="imgGreen" onClick="ChangeColor('green.css')">
<img src="whatever" name="imgRed" onClick="ChangeColor(red.css')">
<img src="whatever" name="imgBlue" onClick="ChangeColor(blue.css')">

<javascript...................?????
function ChangeColor(NewColor)
{
window.document.forms[0].action="changeStylepage.asp?color="+NewColor
window.document.forms[0].submit();
}
OK... let's back up a bit. I suspect all this conflicting code is a bit too much.

What EXACTLY do you want?

If you want to allow users to change the background color, that can be done just as easily with JAVASCRIPT, on the CLIENT. If you want to allow users to select the color they want (regardless of how), and use that color on ALL pages of your site, that can also be done using javascript OR ASP. You can set a cookie (or use session variables, but the cookie is easier). You then read the cookie in every page, and adjust the color accordingly. No cookie, you use the default color. Cookies can be set/read with javascript or ASP, and is a much simpler solution than what's been proposed so far.

Doesn't need CSS (though it can use different stylesheets, if you want to allow more customization than just the bg color), doesn't need any extensive scripting in ASP (it would be a few lines of code) and it doesn't require you use ANY specific page to set the colors, though you could. It's a bit harder in javascript, but not particularly hard.
Avatar of ab10

ASKER

webwoman

i would like to let my users select a color from which i have provided say blue yellow and green and when the click green that will be the color on every page and if they then click red thats the color on every page.

here is an example of how i want it to be like:


www.e-mol.com
ab10 yes it goes in a javascript tag

<SCRIPT TYPE = "text/javascript">
-- you put the function here
</SCRIPT>

and you use those three img tags to call your function on ANY page you want (the javascript function must be included in the page too)
Avatar of ab10

ASKER

Hi for now i will leave it. I will just let the user change the color of the page on one specific page and not any other page.


i am searching an access db in asp. on the same page as changing the color, it is like a search engine, the results display on the same page but underneathe the search box. how can i chnage the color of the page wothout refreshing the page and loosing the search?


Thanks

ab10

you can create an invisible frame and you call your ApplyColor.asp in it so you don't lose anything in your main frame
you only need to create a frame of size 0 and all you need to do afterwards is specify the target when you call your page..

you know what i mean?
You don't need to do ANY of that. Are all your pages ASP pages? .asp extensions?

Really, it's a few lines of code. It's NOT hard. You don't need frames, or special files, or even stylesheets.

You read a cookie, if it doesn't exist you set a cookie, and you use the cookie value in your body tag. No stylesheets. No fancy code. No frames. EASY.
 
Avatar of ab10

ASKER

Yes web woman all of my pages are .asp extensions

have you got code to allow me to set this cookie and will it let me change the color of pages like the following web site:

www.e-mol.com

thanks,

AB10
unfortunately, i can't see that web site. i'll have a look tonight.

IMHO, bear in mind the opssibilities and risks:

. cookies - not many people feel safe about them, and consequently disable them.
. javascript - not everyone has javacript enabled.
. stylesheets should be used whenever possible so you can change most of the look of a full site by swapping or changing a stylesheet only.


the code i gave above will only work during each session and settings are not kept between visits.

if you are using profiles, then keep the colour scheme in the user profile and my asp sample code is the better option, if not, cookies will be the way to go.





Hi,
Just had a look at www.e-mol.com and the method they use is.. querystring!! just like in my first example!!
The setting isn't kept between sessions! the user simply sets it as and when he/she visits the site.

find below the code that emulates what e-mol.com is doing, its been tested:

-------------------------
blue.css sample
-------------------------
body {font-size:10pt; color: 0000ff;}

-------------------------
red.css sample
-------------------------
body {font-size:10pt; color: ff0000;}

-------------------------
somewebpage.asp sample (detects either form or link approach)
-------------------------
<%
' -=-=-=-=  general Subs Begin  ======-
  'checks for the newStyle in form OR Querystring and sets session variable fr the duration of the visit!!
  sub checkStylepage ()
    if request.form("newstyle") then
      Select Case request.form("newstyle")
      Case 0
        Session("BgCSS") = "blue.css"
      Case 1
        Session("BgCSS") = "red.css"
      Case Else
        'always set a default, if session wasn't already defined:
        if Session("BgCSS") = "" then Session("BgCSS") = "blue.css"
      End Select
    else
      Select Case request.querystring("newstyle")
      Case 0
        Session("BgCSS") = "blue.css"
      Case 1
        Session("BgCSS") = "red.css"
      Case Else
        'always set a default, if session wasn't already defined:
        if Session("BgCSS") = "" then Session("BgCSS") = "blue.css"
       End Select
    end if
  end sub
' -=-=-=-=  Exec Init  ======-
  Call checkStylepage()
 
' -=-=-=-=  Content Init  ======-
  %>
  <html>
  <head>
  <META http-equiv="Content-Type" content="text/html">
  <title>web sitel</title>
  <link rel="stylesheet" type="text/css" href="<%=Session("BgCSS")%>">
  </head>
  <body>
  More HTML More HTML More HTML More HTML More HTML More HTML<br/>
  More HTML More HTML More HTML More HTML More HTML More HTML<br/>
 
  <form action="somewebpage.asp">
  Change style using the form method<br/>
  <select name="newstyle" onChange="javascript: form.submit();">
  <option>Change style</option>
  <option value=0>Blue Style</option>
  <option value=1>Red Style</option>
  </select>
  </form>
 
 
 
  Change style using the querystring method<br/>
  <a href="somewebpage.asp?newstyle=0">Blue Style</a><br/>
  <a href="somewebpage.asp?newstyle=1">Red Style</a>
 
 
  </body>
  </html>
 
  <%
' -=-=-=-=  cleaning/finishing processes  ======-
 
 
  %>
assuming you have the 3 css files in the same directory.

<%

if Session("color") = "" then
      Session("color") = "blue" 'default
end if

if request("change") then
      Session("color") = Request("newColor")
end if

%>

<html>
<head>
      <link REL="Stylesheet" TYPE="text/css" HREF=<%=Session("color")%>.css>
</head>
<body>

<a href=color.asp?change=1&newColor=blue>blue</a><br>
<a href=color.asp?change=1&newColor=yellow>yellow</a><br>
<a href=color.asp?change=1&newColor=green>green</a><br>

</body>
</html>
also assuming you name the asp file  color.asp...  :)

hope this works for you...
you can obviously create a folder for stylesheet files, which is what i do!!!!
e.g. create a folder called 'styles' place your css files inside and use the modification below:

  <link REL="Stylesheet" TYPE="text/css" HREF=./styles/<%=Session("color")%>.css>

its been tested and it works as i set it above.


the one other thing i'd consider doing is use the function from an include file.
you copied that from my submission. !!!  lol

true, you could add the folder...

pedros7,  your example included the .css with the strings though..., same concept though...

;)
tx a1programmer ..
<link rel="stylesheet" type="text/css" href="./styles/<%=Session("BgCSS")%>">

.. this is the one that should be inserted in my code from Date: 06/02/2003 07:45PM BST.

it works fine having ab10's needs in mind.

------------------------------------

yes, i'm using a number (0 for blue, 1 for red, etc) to set the css file, so you can call it whatever you want.
This approach easily allows some degree of checking in case the user tries to trick the asp page by supplying an unhandled value in the querystring method!!

you could even extend my code and in the beginning of each asp or an include file, you could set an array to hold the name of available css files:

dim myArray (2)
myArray (0) = "blue.css"
myArray (1) = "red.css"
myArray (2) = "whatever.css"

use code to decide whether the number x returned by querystring/form method is within the UBound of the array, if so use myArray(x) value, if not then its an invalid number therefor use myArray(0) as default (for instance).

------------------------------------
Avatar of ab10

ASKER

hi pedros,


i tried you example it works when i refresh the page but how can i change the color of a page from another page?

Do i repeat the code? Or can i call that code?

How can i do it so if i have searched a searched engine and the results display but when i change the bgcolor it refreshes the page and i loose my results...How can i avoid this?

Or if a user has logged into a restricted are it doesn't kick them out......


Thanks AB10
none of this code should log out any user as the code doesn't interfere with the login process. are you actually experiencing any problems?!

put the same code and execute it..
when you call the function it sets a css file which are applied for as many pages as you use this in: sitewise or selected pages only!!


to keep the search results you must retain the search options, somehow!!

if the search settings, in the results page, are present in a form instead of the  querystring, then the best solution for that particular page would be to call a seperate page like i sugested in the very beggining, which in turn refreshes the (parent) search page using javascript opener.reload().
look in posting from Date: 05/29/2003 04:00PM BST

if the actual results page are in the querystring its fairly straight forward, when the url refreshes the pages you can use the code below - in fact use this in all cases not requiring persisting form data, as this way you only have to cut and paste in place without having to type each page name in the URL calls.

-------------------------
blue.css sample
-------------------------
body {font-size:10pt; color: 0000ff;}

-------------------------
red.css sample
-------------------------
body {font-size:10pt; color: ff0000;}

-------------------------
somewebpage.asp sample (detects either form or link approach)
-------------------------
<%
' -=-=-=-=  general Subs Begin  ======-
 'checks for the newStyle in form OR Querystring and sets session variable fr the duration of the visit!!
 sub checkStylepage ()
   if request.form("newstyle") then
     Select Case request.form("newstyle")
     Case 0
       Session("BgCSS") = "blue.css"
     Case 1
       Session("BgCSS") = "red.css"
     Case Else
       'always set a default, if session wasn't already defined:
       if Session("BgCSS") = "" then Session("BgCSS") = "blue.css"
     End Select
    else
     Select Case request.querystring("newstyle")
     Case 0
       Session("BgCSS") = "blue.css"
     Case 1
       Session("BgCSS") = "red.css"
     Case Else
       'always set a default, if session wasn't already defined:
       if Session("BgCSS") = "" then Session("BgCSS") = "blue.css"
      End Select
    end if
 end sub
' -=-=-=-=  Exec Init  ======-

Dim myURL, myQuerystring

myQuerystring = Request.ServerVariables("Query_String")
if myQuerystring <> "" then myQuerystring = myQuerystring & "&"

myURL = "http://" & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("URL") & "?" & myQuerystring
Call checkStylepage()

' -=-=-=-=  Content Init  ======-
 %>
 <html>
 <head>
 <META http-equiv="Content-Type" content="text/html">
 <title>web sitel</title>
 <link rel="stylesheet" type="text/css" href="<%=Session("BgCSS")%>">
 </head>
 <body>
 More HTML More HTML More HTML More HTML More HTML More HTML<br/>
  More HTML More HTML More HTML More HTML More HTML More HTML<br/>
 
 <form action="<%=myURL%>">
 Change style using the form method<br/>
 <select name="newstyle" onChange="javascript: form.submit();">
 <option>Change style</option>
 <option value=0>Blue Style</option>
 <option value=1>Red Style</option>
 </select>
 </form>
 
Change style using the querystring method<br/>
<a href="<%=myURL%>newstyle=0">Blue Style</a><br/>
<a href="<%=myURL%>newstyle=1">Red Style</a>

  </body>
 </html>
 
 <%
' -=-=-=-=  cleaning/finishing processes  ======-
 
 %>
Avatar of ab10

ASKER

Hi pedros,

I have noticed that when i try to chnage the bgcolor it takes the url and puts it in the string so it won't work. For example:

if i set it to newstyle0 the url would be

www.mysite.com/somewebpage.asp?newstyle=0

but if i then chnage it to newstyle1 it would be

www.mysite.com/somewebpage.asp?newstyle=0newstyle=1

because it take the URL in the following bit of code:

myURL = "http://" & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("URL") & "?" & myQuerystring



'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
P.S does anyone have any asp code to send and recieve email from a web page like hotmail etc...
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


Thanks

AB10

see if you like mine

assuming you have the 3 css files in the same directory. (can be changed to anything)


<!-- start of file -->
<%
if Session("color") = "" then Session("color") = "blue" 'default
if request("change") then Session("color") = Request("newColor")
%>

<html>
<head>
    <link REL="Stylesheet" TYPE="text/css" HREF=<%=Session("color")%>.css>
</head>
<body>

<a href=color.asp?change=1&newColor=blue>blue</a><br>
<a href=color.asp?change=1&newColor=yellow>yellow</a><br>
<a href=color.asp?change=1&newColor=green>green</a><br>

</body>
</html>
<!--- end of file --->




To make it show up on each page, just put the small asp and <link >  on each page.
You can name the asp file above color.asp, which is where they would go to change the color.
ASKER CERTIFIED SOLUTION
Avatar of pedros7
pedros7
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ab10

ASKER

pedros when i click a button and submit a form for a search engine the color chnages back to blue, why?
because the search engine probably isn't returning the colour parameter!!!
the code not detecting it in the querystring or form,  defaults to a particular setting, in this case: blue!!

its too specific to be able to give options just now! send us the link of your page, with the search engine call.
Avatar of ab10

ASKER

hi pedros here is my code fr the page, can you tell me what i have to do to make it work and when i return to this page from another page it shows the default color the link is default.asp so what do i have to do to show the color selected by the user. Also can you just have a look and see if you can add a bit in my code so it displays numbers next to my results. so i can have like search results 1,2,3,4,5.  i would be really gratefull Thanks.


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

<% Option Explicit %>
<!--#include file="common.inc" -->
<%
'checks for the newStyle in form OR Querystring and sets session variable fr the duration of the visit!!
sub checkStylepage ()
Select Case request.querystring("newstyle")
    Case 0
      Session("BgCSS") = "green.css"
    Case 1
      Session("BgCSS") = "maroon.css"
    Case 2
      Session("BgCSS") = "navyblue.css"
    Case 3
      Session("BgCSS") = "purple.css"
    Case Else
      'always set a default, if session wasn't already defined:
     if Session("BgCSS") = "" then Session("BgCSS") = "green.css"
     End Select
end sub

Function ReplaceTest(str1, patrn, replStr)
  Dim regEx
  Set regEx = New RegExp
  regEx.Pattern = patrn
  regEx.IgnoreCase = True
  ReplaceTest = regEx.Replace(str1, replStr)
End Function

' -=-=-=-=  Exec Init  ======-

Dim myURL, myQuerystring

myQuerystring = Request.ServerVariables("Query_String")
myQuerystring = ReplaceTest(myQuerystring, "(&)?newstyle=\d", "")
if myQuerystring <> "" then
    myQuerystring = myQuerystring & "&"
end if

myURL = "http://" & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("URL") & "?" & myQuerystring
Call checkStylepage()

Response.Buffer = True

'Dimension variables
Dim rsSearchResults             'database Recordset Variable
Dim intRecordPositionPageNum       'Holds the record position
Dim intRecordLoopCounter       'Loop counter for displaying the database records
Dim lngTotalRecordsFound       'Holds the total number of records in the database
Dim lngTotalNumPages             'holds the total number of pages in the database
Dim intLinkPageNum             'Holds the page number to be linked to
Dim intLoopCounter            'Holds the loop counter number
Dim sarySearchWord             'Holds the keywords for the URL
Dim strSearchKeywords            'Holds the keywords to be searched
Dim intSQLLoopCounter            'Loop counter for the loop for the sql query
Dim intSearchWordLength            'Holds the length of the word to be searched
Dim blnSearchWordLenthOK      'Boolean set to false if the search word length is not OK
Dim intRecordDisplayFrom      'Holds the number of the search result that the page is displayed from
Dim intRecordDisplayedTo      'Holds the number of the search result that the page is displayed to


'If this is the first time the page is displayed then the page position is set to page 1
If Request.QueryString("PagePosition") = "" Then
      intRecordPositionPageNum = 1

'Else the page has been displayed before so the page postion is set to the Record Position number
Else
      intRecordPositionPageNum = CInt(Request.QueryString("PagePosition"))
End If      


'Read in all the search words into one variable
strSearchKeywords = Trim(Request.QueryString("search"))

'If the use has not entered a value then let the search words variable contain a space (chr10)
If strSearchKeywords = "" Then strSearchKeywords = chr(10)

'Replace any less than or greater than signs with the HTML equivalent (stops people entering HTML tags)
strSearchKeywords = Replace(strSearchKeywords, "<", "&lt;")
strSearchKeywords = Replace(strSearchKeywords, ">", "&gt;")
strSearchKeywords = Replace(strSearchKeywords, "'", "''")

'Read in the search words to be searched
sarySearchWord = Split(Trim(strSearchKeywords), " ")

'Return the tow '' back to one' for displaying on the screen
strSearchKeywords = Replace(strSearchKeywords, "''", "'")


'Initalise the word search length variable
blnSearchWordLenthOK = True

'Loop round to check that each word to be searched has more than the minimum word length to be searched
For intLoopCounter = 0 To UBound(sarySearchWord)
      
      'Initialise the intSearchWordLength variable with the length of the word to be searched
      intSearchWordLength = Len(sarySearchWord(intLoopCounter))
      
      'If the word length to be searched is less than or equal to min word length then set the blnWordLegthOK to false
      If intSearchWordLength <= intMinuiumSearchWordLength Then
            blnSearchWordLenthOK = False            
      End If
Next


'Create a recordset object
Set rsSearchResults = Server.CreateObject("ADODB.Recordset")

      
'Initalise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT tblWebsites.* FROM tblWebsites "
            
'Get the mode to decide how we are going to buid the SQL Query
Select Case Request.QueryString("mode")

      'If the user has selected to search any words then intalise the strSQL statement to search for any words in the database
      Case "anywords"

            'Search for the first search word in the URL titles
            strSQL = strSQL & "WHERE Title LIKE '%" & sarySearchWord(0) & "%'"
      
            'Loop to search for each search word entered by the user
            For intSQLLoopCounter = 0 To UBound(sarySearchWord)
                  strSQL = strSQL & " OR Title LIKE '%" & sarySearchWord(intSQLLoopCounter) & "%'"
                  strSQL = strSQL & " OR Keywords LIKE '%" & sarySearchWord(intSQLLoopCounter) & "%'"
                  strSQL = strSQL & " OR Description LIKE '%" & sarySearchWord(intSQLLoopCounter) & "%'"
            Next
            
            'Order the search results by the number of click through hits decending (most popular sites first)
            strSQL = strSQL & " ORDER By Rating DESC, No_of_ratings DESC, Hits DESC;"


      'If the user has selected to search for all words then intalise the strSQL statement to search for entries containing all the search words
      Case "allwords"
      
            'Search for the first word in the URL titles
            strSQL = strSQL & "WHERE (Title LIKE '%" & sarySearchWord(0) & "%'"
            
            'Loop to search the URL titles for each word to be searched
            For intSQLLoopCounter = 1 To UBound(sarySearchWord)
                  strSQL = strSQL & " AND Title LIKE '%" & sarySearchWord(intSQLLoopCounter) & "%'"
            Next
            
            'OR if the search words are in the keywords      
            strSQL = strSQL & ") OR (Keywords LIKE '%" & sarySearchWord(0) & "%'"
            
            'Loop to search the URL keywords for each word to be searched
            For intSQLLoopCounter = 1 To UBound(sarySearchWord)
                  strSQL = strSQL & " AND Keywords LIKE '%" & sarySearchWord(intSQLLoopCounter) & "%'"
            Next
            
            'Or if the search words are in the title      
            strSQL = strSQL & ") OR (Description LIKE '%" & sarySearchWord(0) & "%'"
            
            'Loop to search the URL description for each word to be searched
            For intSQLLoopCounter = 1 To UBound(sarySearchWord)
                  strSQL = strSQL & " AND Description LIKE '%" & sarySearchWord(intSQLLoopCounter) & "%'"
            Next
            
            'Order the search results by the number of click through hits decending (most popular sites first)
            strSQL = strSQL & ") ORDER By Rating DESC, No_of_ratings DESC, Hits DESC;"


      'If the user has selected to see newly enetred URL's then order the search results by date decending
      Case "new"
            'Initalise the strSQL variable with an SQL statement to query the database
            strSQL = "SELECT TOP " & intRecordsPerPage & " tblWebsites.* FROM tblWebsites"
            strSQL = strSQL & " ORDER By SiteIDNo DESC;"
End Select

'Query the database with the strSQL statement
rsSearchResults.Open strSQL, strCon, 3

'Count the number of records found
lngTotalRecordsFound = CLng(rsSearchResults.RecordCount)      

'If this is a random URL then strip all the other URL's and only leave one remaining URL
If Request.QueryString("submit") = "Random Search" and NOT rsSearchResults.EOF Then
      
      'Randomise system timer
      Randomize Timer
      
      'Move to a random record in the recordset
      rsSearchResults.Move CLng(RND * lngTotalRecordsFound) - 0.5

      'Filter out all the other records
      rsSearchResults.Filter = "SiteIDNo =" & rsSearchResults("SiteIDNO")

Else
      'Set the number of records to display on each page by the constant set at the top of the script
      rsSearchResults.PageSize = intRecordsPerPage
      
      'Get the page number record poistion to display from
      IF NOT rsSearchResults.EOF Then rsSearchResults.AbsolutePage = intRecordPositionPageNum
      
      'Count the number of pages the search results will be displayed on calculated by the PageSize attribute set above
      lngTotalNumPages = CLng(rsSearchResults.PageCount)
      
      
      'Calculate the the record number displayed from and to on the page showing
      intRecordDisplayFrom = (intRecordPositionPageNum - 1) * intRecordsPerPage + 1
      intRecordDisplayedTo = (intRecordPositionPageNum - 1) * intRecordsPerPage + intRecordsPerPage
      If intRecordDisplayedTo > lngTotalRecordsFound Then intRecordDisplayedTo = lngTotalRecordsFound

End If
%>


<html>
<head>
<link rel="stylesheet" type="text/css" href="<%=Session("BgCSS")%>">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Search uMuppet: <% = strSearchKeywords %></title>

<BODY TEXT="#FFFFFF" LINK="#FFFFFF" VLINK="#FFFFFF" ALINK="#FFFFFF" TOPMARGIN="0" LEFTMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">



<!-- Check the from is filled in correctly before submitting -->
<SCRIPT  language="JavaScript">
<!-- Hide from older browsers...
//Check the enquiry form is filled in correctly
function CheckForm () {
            
      //If there is aproblem with the form then display an error
      if (document.frmInterSearch.search.value == "") {
            msg = "_________________________________________________________________\n\n";
            msg += "Your search has not been submitted because there are problem(s) with the form.\n";
            msg += "Please correct the problem(s) and re-submit the form.\n";
            msg += "_________________________________________________________________\n\n";
            msg += "\n\tPlease enter at least one keyword to search for."
            
            alert(msg + "\n\n");
            
            return false;
      }
      
      return true;
}

//Function to open pop up window
function openWin(theURL,winName,features) {
        window.open(theURL,winName,'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=350,height=310');
}
// -->
</script>
<form method="get" name="frmInterSearch" action="default.asp" onSubmit="return CheckForm();">
  <table width="100%" border="0" cellspacing="0" cellpadding="1" align="center">
    <tr>
      <td>
    <table color="#808080" width="100%" border="0" cellspacing="0" cellpadding="3" align="center" bgcolor="#808080" bordercolor="#000000">
             <tr>
            <td> <a href="add_url_form.asp" target="_self"><FONT SIZE=2 FACE="Tahoma,Verdana,MS Sans Serif,Arial"><B>Submit
              Web Site</B></FONT></a> |
          </tr>      
        </table>
      </td>
    </tr>
  </table>
  <table width="998" height="347" align=center cellpadding="0" cellspacing="0">
    <!--DWLayoutTable-->
    <tr>
      <td width="219" rowspan="2" align="center" valign="top"> <div align="left">
          <p>&nbsp;</p>
          <p align="center">Change uMuppet Interface Colour:<br/>
          </p>
          <p align="center">
                  <a href="<%=myURL%>newstyle=0"><img src="images/color/green.JPG" width="36" height="41" border="1"></a>
                  <a href="<%=myURL%>newstyle=1"><img src="images/color/maroon.JPG" width="36" height="41" border="1"></a>
                  <a href="<%=myURL%>newstyle=2"><img src="images/color/navyblue.JPG" width="36" height="41" border="1"></a>
                  <a href="<%=myURL%>newstyle=3"><img src="images/color/purple.JPG" width="36" height="41" border="1"></a></p>
        </div>
        </td>
      <td width="777" height="230" align=center valign="top" class="normal">
        <p>&nbsp;</p>
        <p><img src="images/muppets/hannnan.jpg" width="160" height="120"></p>
        <p><font size=2 face="Tahoma,Verdana,MS Sans Serif,Arial"><b>
            Here is your Muppet to search the web:</b></font></p>
        <p>
          <input type="TEXT" name="search" maxlength="50" size="35" value="<% =Request.QueryString("search") %>">
        </p>
        <p>
          <input type="submit" value="uSearch " name="submit">
          <input type="submit" name="submit" value="Random uSearch">
        </p></td>
    </tr>
    <tr>
      <td height="58" align=center valign="top" class="text"> <p>uSearch By :
          <input type="radio" name="mode" value="allwords" CHECKED>
          All Words
          <input type="radio" name="mode" value="anywords">
          Any Words </p>
        <p>&nbsp;</p></td>
    </tr>
  </table>
  <%

If NOT Request.QueryString("mode") = "" Then
      'Display the HTML table with the results status of the search or what type of search it is
      Response.Write vbCrLf & "     <table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""3"" align=""center"">"
      Response.Write vbCrLf & "      <tr>"
      Response.Write vbCrLf & "       <td>"
      Response.Write vbCrLf & "      <table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""3"" align=""center"" bgcolor=#808080>"
      Response.Write vbCrLf & "         <tr>"
      
      'Display that the URL is randomly generated      
      If Request.QueryString("submit") = "Random Search" Then
            Response.Write vbCrLf & "           <td  class=""text""> Your Muppet is Randomly Searching for <span class=""bold"">" & strSearchKeywords & "</span>.</td>"
             
      'Display that one of the words entered was to short
      ElseIf      blnSearchWordLenthOK = False Then
            Response.Write vbCrLf & "           <td class=""text""> Your Muppet searched for <span class=""bold"">" & strSearchKeywords & "</span>. | Displaying Results One of the words searched is to short.</td>"  
      
      'Display that there where no matching records found
      ElseIf rsSearchResults.EOF Then
            Response.Write vbCrLf & "           <td class=""text""> Your Muppet searched for <span class=""bold"">" & strSearchKeywords & "</span>. | Displaying Results Sorry, no results found.</td>"  
      
      'Else Search went OK so display how many records found
      Else      
            Response.Write vbCrLf & "           <td class=""text""> Your Muppet searched for <span class=""bold"">" & strSearchKeywords & "</span>. | Displaying Results " & intRecordDisplayFrom & " - " & intRecordDisplayedTo & " of " & lngTotalRecordsFound & ".</td>"         
      End If
                  
      'Close the HTML table with the search status
      Response.Write vbCrLf & "        </tr>"
      Response.Write vbCrLf & "      </table>"
      Response.Write vbCrLf & "      </td>"
      Response.Write vbCrLf & "      </tr>"
      Response.Write vbCrLf & "     </table>"


      'Display the various results
      
      'HTML table to display the search results or an error if there are no results
      Response.Write vbCrLf & "      <br>" & vbCrLf
      Response.Write vbCrLf & "      <table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""3"" align=""center"">"
      Response.Write vbCrLf & "       <tr>"
      Response.Write vbCrLf & "        <td class=""text"">"  
      
      'Display error message if one of the words is to short
      If blnSearchWordLenthOK = False And NOT Request.QueryString("mode") = "new" Then
      
            'Write HTML displaying the error
            Response.Write vbCrLf & "         Your Search - <span class=""bold"">" & strSearchKeywords & "</span> - Contained a word with " & intMinuiumSearchWordLength & " letters or less, this is to short to search."
               Response.Write vbCrLf & "         <br><br>"
               Response.Write vbCrLf & "         Suggestions:"
               Response.Write vbCrLf & "         <br>"
               Response.Write vbCrLf & "         <ul><li>Try longer keywords.<li>Make sure all words are spelled correctly.<li>Try different keywords.<li>Try more general keywords.</ul>"
               
      'If no search results found then show an error message
      ElseIf rsSearchResults.EOF Then
      
            'Write HTML displaying the error
            Response.Write vbCrLf & "         Your Search - <span class=""bold"">" & strSearchKeywords & "</span> - did not match any documents."
               Response.Write vbCrLf & "         <br><br>"
               Response.Write vbCrLf & "         Suggestions:"
               Response.Write vbCrLf & "         <br>"
               Response.Write vbCrLf & "         <ul><li>Make sure all words are spelled correctly.<li>Try different keywords.<li>Try more general keywords.<li>Try fewer keywords.</ul>"
               
      Else
            'For....Next Loop to display the results from the database
            For intRecordLoopCounter = 1 to intRecordsPerPage
            
                  'If there are no records left to display then exit loop
                  If rsSearchResults.EOF Then Exit For                              
                        
                        'Display the details of the URLs found            
                     Response.Write vbCrLf & "         <a href=""get_url.asp?SiteID=" & CInt(rsSearchResults("SiteIDNo")) & """ target=""_self"">" & rsSearchResults("Title") & "</a>"
                     Response.Write vbCrLf & "         <br>"
                     Response.Write vbCrLf & "         <span class=""bold"">" & rsSearchResults("Description")
                     Response.Write vbCrLf & "         <br>"
                     Response.Write vbCrLf & "         <span>"& Replace(rsSearchResults("URL"),"http://", "") & "</span>"
                     Response.Write vbCrLf & "         <br><br>"
               
                  'Move to the next record in the database
                  rsSearchResults.MoveNext
            
            'Loop back round         
            Next
       End If
      
      'Close the HTML table displaying the results
      Response.Write vbCrLf & "          </td>"
      Response.Write vbCrLf & "        </tr>"
      Response.Write vbCrLf & "      </table>"
      
      
      
      
      'If there are more pages to display then add a title to the other pages
      If intRecordPositionPageNum > 1 OR NOT rsSearchResults.EOF AND blnSearchWordLenthOK = True Then
      
             'Display an HTML table with links to the other search results
            Response.Write vbCrLf & "      <table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""0"" align=""center"">"
            Response.Write vbCrLf & "         <tr>"
            Response.Write vbCrLf & "           <td>"
            Response.Write vbCrLf & "            <table width=""100%"" border=""0"" cellpadding=""0"" cellspacing=""0"">"
            Response.Write vbCrLf & "              <tr>"
            Response.Write vbCrLf & "                <td width=""50%"" align=""center""  class=""text"">"
            
            'If there are more pages to display then add a title to the other pages
            If intRecordPositionPageNum > 1 or NOT rsSearchResults.EOF Then
                  Response.Write vbCrLf & "            Results Page:&nbsp;&nbsp;"
            End If
            
            'If the page number is higher than page 1 then display a back link          
            If intRecordPositionPageNum > 1 Then
                  Response.Write vbCrLf & "             <a href=""default.asp?" &  intRecordPositionPageNum - 1  & "&search=" & Server.URLEncode(strSearchKeywords) & "&mode=" & Request.QueryString("mode") &""" target=""_self"">&lt;&lt;&nbsp;Prev</a>&nbsp; "                    
            End If           
            
            
            'If there are more pages to display then display links to all the search results pages
            If intRecordPositionPageNum > 1 or NOT rsSearchResults.EOF Then
                  
                  'Loop to diplay a hyper-link to each page in the search results          
                  For intLinkPageNum = 1 to lngTotalNumPages            
                        
                        'If the page to be linked to is the page displayed then don't make it a hyper-link
                        If intLinkPageNum = intRecordPositionPageNum Then
                              Response.Write vbCrLf & "                 " & intLinkPageNum
                        Else
                        
                              Response.Write vbCrLf & "                 &nbsp;<a href=""default.asp?PagePosition=" &  intLinkPageNum  & "&search=" & Server.URLEncode(strSearchKeywords) & "&mode=" & Request.QueryString("mode") & """ target=""_self"">" & intLinkPageNum & "</a>&nbsp; "                  
                        End If
                  Next
            End If
            
            
            'If it is Not the End of the search results than display a next link           
            If NOT rsSearchResults.EOF then         
                  Response.Write vbCrLf & "            &nbsp;<a href=""default.asp?PagePosition=" &  intRecordPositionPageNum + 1  & "&search=" & Server.URLEncode(strSearchKeywords) & "&mode=" & Request.QueryString("mode") & """ target=""_self"">Next&nbsp;&gt;&gt;</a>"               
            End If            
            
            
            'Finsh HTML the table            
            Response.Write vbCrLf & "                </td>"            
            Response.Write vbCrLf & "              </tr>"
            Response.Write vbCrLf & "            </table>"            
            Response.Write vbCrLf & "          </td>"
            Response.Write vbCrLf & "        </tr>"
            Response.Write vbCrLf & "      </table>"
            Response.Write vbCrLf & "      <br>"
      
      End If
End If


'Close Server Objects
Set rsSearchResults = Nothing
Set strCon = Nothing
Set adoCon = Nothing
%>

</form>
</body>
</html>

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
can you send me the URL where the web site is?!
cheers
Avatar of ab10

ASKER

my website isn't actually up and running at the moment

but i put it online so you can llok at it

www25.brinkster.com/umuppeta

thanks ab10