Random Quotes

<% @ Language="JavaScript" %>

<HTML>
<HEAD><TITLE>
Quote of the day</TITLE></HEAD>

<BODY>

<H1>Quote Of The Day:</H1>

<%

var abs_path;
var file_to_open;
var lin_num;
var quote;
var random_number;

var quotes = "Quotes.txt";

// this gives us the absolute path of this script which we'll use
// to get the path to the current directory so we can open a file in it (the quotes, above).

abs_path = String(Request.ServerVariables("PATH_TRANSLATED"));

// get rid of script name in absolute path
// and replace with name of file we want to open
// replace, ie, ..\Quotes.asp with ..\Quotes.txt

file_to_open = abs_path.replace(/\\\w*\.asp/,"\\") + quotes;

var fso = new ActiveXObject("Scripting.FileSystemObject");

// Make sure we can find quotes file before we get carried away

if (fso.FileExists(file_to_open)) {
     var file_stream = fso.OpenTextFile(file_to_open);  // open file and read contents:

     var Quotes = new Array();

     while (! file_stream.AtEndOfStream) {  // loop through file and collect tips
          line_num = file_stream.Line;  // line number within the file

          quote = file_stream.ReadLine();  // read the line in the file & assign it to quote

          Quotes[line_num - 1] = quote;
     }

     file_stream.Close();

     // generate random number based on number of quotes we found and print one.

     random_number = Math.round((Quotes.length - 1)  *  Math.random());

     Response.write("<P>" + Quotes[random_number]);
}
else Response.
write("<P>Sorry, the quotes file seems to be missing");

%>

</BODY>
</HTML>