<%
dim PageId, PageName, PageTitle, PageKeywords, PageDescription, PageHeading, PageContent
sub GetPageDetails(thisPageId)
  if not isObject(objConn) then openDB DBFile
  strSQL = "SELECT PageName, Title, Keywords, Heading, Description, Content FROM Page WHERE PageId=" & thisPageId
  openRS stRSQL
  if not objRS.eof then
    PageName = objRS(0)
    PageTitle = objRS(1)
    PageKeywords = objRS(2)
    PageDescription = objRS(4)
    PageHeading = objRS(3)
    PageContent = objRS(5)
  end if
  closeRS
  closeDB
end sub
function getBackground(theSection)
  dim theBackground, randNum
  strSQL = "SELECT * FROM SectionImage WHERE SectionName='" & theSection & "'"
  openRS strSQL
  if not objRS.eof then
    Randomize()
    randNum = CInt((objRS.RecordCount - 1) * Rnd)
    objRS.Move randNum
    theBackground = objRS(2)
  end if
  closeRS
  getBackground = theBackground
end function
' ***********************************************************
' Login methods
' ***********************************************************
dim lastURL, LoginUserName, LoginUserPassword, LoginbooRememberMe, strLoginError
sub RememberMe(theName, thePassword)
  if request("RememberMe") = "yes" then
    response.cookies("User")("ID") = theName
    response.cookies("User")("Password") = thePassword
    response.cookies("User").path = "/"
    response.cookies("User").expires = dateadd("M",6,now)
  end if
end sub
sub LoginUser(UserName, UserPassword, booRememberMe)
  if not isObject(objConn) then openDB DBFile
  strSQL = "SELECT id FROM Admins WHERE loginID='" & replace(UserName,"'","''") & "' AND strcomp([loginPassword],'" & replace(UserPassword,"'","''") & "',0) = 0 AND loginActive=Yes"
  openRS strSQL
  if not objRS.eof then
    session("AdminLoggedIn") = true
    session("UserId") = objRS(0)
    if booRememberMe then
      response.cookies("User")("ID") = UserName
      response.cookies("User")("Password") = UserPassword
      response.cookies("User").path = "/"
      response.cookies("User").expires = dateadd("M",6,now)
    end if
  end if
  closeRS
end sub
sub CheckLogin()
  LoginUser request.cookies("User")("ID"), request.cookies("User")("Password"), true
end sub
sub LogoutUser
  response.cookies("User").expires = dateadd("D",-1,now)
  session.abandon()
end sub
function ShowLogOut()
  dim strLogOut
  strLogOut = "<form name=""Logout"" id=""Logout"" action=""login.asp"" method=""post"">" & vbcrlf & _
    "<input type=""Submit"" name=""DoLogout"" id=""DoLogout"" value=""Log Out"">" & vbcrlf & "</form>"
  ShowLogOut = strLogOut
end function

' ***********************************************************
' Rich Text editor methods
' ***********************************************************
function RTESafe(strText)
  on error resume next
  'returns safe code for preloading in the RTE
  dim tmpString
  tmpString = trim(strText)
  'convert all types of single quotes
  tmpString = replace(tmpString, chr(145), chr(39))
  tmpString = replace(tmpString, chr(146), chr(39))
  tmpString = replace(tmpString, "'", "&#39;")
  'convert all types of double quotes
  tmpString = replace(tmpString, chr(147), chr(34))
  tmpString = replace(tmpString, chr(148), chr(34))
  '	tmpString = replace(tmpString, """", "\""")
  'replace carriage returns & line feeds
  tmpString = replace(tmpString, chr(10), " ")
  tmpString = replace(tmpString, chr(13), " ")
  RTESafe = tmpString
  on error goto 0
end function
%>