-- This is the proverbial "Hello World" example.
-- The goal is to demonstrate the basic mechanics of CGI.

on appleEvent class,event,sender
  if class = "WWW½" then
    if event = "sdoc" then
      reply HTTP() & myResponsePage()
    else
      pass appleEvent
    end if
  else
    pass appleEvent
  end if
end appleEvent

function HTTP
  put (the numToChar of 13) & (the numToChar of 10) into crlf
  put "HTTP/1.0 200 OK" & crlf into header
  put header & "Server: MacHTTP" & crlf into header
  put header & "MIME-Version: 1.0" & crlf into header
  put header & "Content-type: text/html" & crlf & crlf into header
  return header
end HTTP

function myResponsePage
  put "Hello World" into title
  put "HELLO WORLD" into content
  return "<html><head><title>" & title & "</title></head><body>" & content & "</body></html>"
end myResponsePage

on startUp
	-- This Handler is run if some silly nut enters "cgi.txt" when Joker asks
	-- for a file to execute.
	put "To execute this script, name it 'cgi.txt' and"
	put " place it in the same folder as the Joker application."
	put return&return& "Joker will then run it whenever it receives an Apple Event." &return&return
end startUp