/*^*************************************************************/
/*  p:  Print to screen                                        */
/***************************************************************/
function p (msg)
{
document.write (msg);
}   /*  print  */


// document.write ("Hello, world");
// p ("Hello there, world");


/*^*************************************************************/
/*  back:  Same effect as "Back" button on browser             */
/***************************************************************/
   function back() {

       browserName = navigator.appName;
       browserVer = parseInt(navigator.appVersion);
       if ( (browserName == "Netscape" && browserVer >= 3) ||
            (browserName == "Microsoft Internet Explorer" && browserVer >= 4)) 
           compat = "true";
           else compat = "false";

       if (compat == "true") {
           history.go(-1)
   	}
   }   //  back


/*^*************************************************************/
/*  next:  Same effect as "Next" button on browser             */
/***************************************************************/
   function next() {

       browserName = navigator.appName;
       browserVer = parseInt(navigator.appVersion);
       if ( (browserName == "Netscape" && browserVer >= 3) ||
            (browserName == "Microsoft Internet Explorer" && browserVer >= 4)) 
           compat = "true";
           else compat = "false";

       if (compat == "true") {
           history.go(+1)
   	}
   }   //  next



/*^*************************************************************/
/*  GetColor:  Get a random color from set of n colors.        */
/*             n must be 215 or 216.                           */
/*             If n = 215 exclude background color, bg.        */
/***************************************************************/
function GetColor (n, bg)
{
var bgb, bgg, bgr, c, r, random, rr, g, gg, b, bb, t;
var s = "0369CF"
var ts = "" + bg;


                                /*  DEBUG  **********************
if ( n == 215 )
    {
    p ("Black");
    }
else 
    {
    p ("White");
    }				    End-Of-DEBUG  ***************/

                                //  Output the number sign.
p ("#");

                                //  Get random integer between 
                                //  zero and n - 1.
random = parseInt (Math.random () * n);
if ( random == n ) {
    random = 0;
}

                                //  Get random char for r, g, b.
if ( (n == 215)  ||  (n == 216) ) 
    {
    r = parseInt (random / 36);
    t = random  -  36 * r;

    g = parseInt (t / 6);
    b = t  -  6 * g;
    }   /*  if ( n == 215 or 216 )  */

                                //  If 215 char omit bg color.
if ( n == 215 ) 
    {
                                //  Break hexadecimal into 
                                //  nybble values                 
    bgr  = ts.substr (0, 1);
    bgg  = ts.substr (2, 1);
    bgb  = ts.substr (4, 1);

                                //  Is the randomly selected 
                                //  color the background color?
    if ( (bgr == r)  &&  (bgg == g)  &&  (bgb == b) ) 
        {
                                //  Backgroud = random            
                                //  Make color black or white 
                                //  based upon the value of 
                                //  green.
        if ( bgg <= 2 ) 
            {
                                //  Make color white            
            r = 5;
            g = 5;
            b = 5;
            }
        else 
            {
                                //  Make color black            
            r = 0;
            g = 0;
            b = 0;
            }
        }
    }   //  if n == 215

                                //  Output the random color.                                  
c = s.substr (r, 1);            //  Red.
p (c + c);

c = s.substr (g, 1);            //  Green.
p (c + c);

c = s.substr (b, 1);            //  Blue.
p (c + c);
}   /*  GetColor  */


/*^*************************************************************/
/*  GetTitle:  Print specified title in                        */
/*             specified number of colors.                     */
/***************************************************************/
function GetTitle (s, n, bg)
{
var jsfontface = "Times New Roman";

                                /*  DEBUG  **********************
p ("<FONT face=");
p (jsfontface);
p (" size=+3 color=black>");

p ("s = ");
p (s);
p ("  n = ");

p (n);
p ("  bg = ");
p (bg);

                                    End-Of-DEBUG ****************/

                                //  Test background color.
if ( TestBG (bg) == "error" )
    {
                                //  Error in specified 
                                //  background color must be of 
                                //  the form rrggbb, where 
                                //  r, g, and b are each 
                                //  0, 3, 6, 9, C, or F.
                                //  Use "black" for the color 
                                //  of the string, s.
    p ("<FONT face=");
    p (jsfontface);
    p (" size=+3 color=Black><B>");
    p (s);
    p ("</B><BR><FONT face=");
    p (jsfontface);
    p (" size=-1 color=black>");
    return;
    }

                                //  Print text (s) random colors
for (i = 0; i < s.length; i++) 
    {
    p ("<FONT face=");
    p (jsfontface);
    p (" size=+3 color=");
                                //  DEBUG    p ("Black");
    GetColor (n, bg);

    p ("><B>");
    p (s.substr (i, 1));
    p ("</B>");
    }   //  FOR loop for random colors.

                                //  Print the 
                                //  "In n random colors" line.
p ("<BR><FONT face=");
p (jsfontface);
p (" size=-1 color=black>");
p (s);
p (" in ");
p (n);
p (" random colors</FONT>");

/*******************  Remove  2004/10/19  ***********************
                                //  Set the font for 
                                //  the next line.
p ("<BR><FONT face=");
p (jsfontface);
p (" size=-1 color=black>");
*******************   End-Of-Remove  2004/10/19  ****************/

p ("<BR><FONT face=");
p (jsfontface);
p (" size=+2 color=black>");

}   //  GetTitle



/*^*************************************************************/
/*  TestBG:  Test the specified background color.              */
/***************************************************************/
function TestBG (bg)
{
var bgb, bgg, bgr, rr, gg, bb;
var s = "0369CF"
var ts = "" + bg;

if ( ts != "" ) 
    {
                                //  Check for illegitimate 
                                //  background color            
                                //  Break hexadecimal into 
                                //  nybble values                 
    bgr  = ts.substr (0, 1);
    rr   = ts.substr (1, 1);

    bgg  = ts.substr (2, 1);
    gg   = ts.substr (3, 1);

    bgb  = ts.substr (4, 1);
    bb   = ts.substr (5, 1);

                                //  Legitimate must be of 
                                //  form rrggbb 
    if ( (bgr != rr)  ||  (bgg != gg)  || (bgb != bb) ) 
        {
        alert ("Illegal background color (mm); Using Black");
        return ("error");
        }

                                //  Legitimate must be 
                                //  characters in string s
    if ( (s.indexOf (bgr) == -1)  ||  
         (s.indexOf (bgg) == -1)  ||  
         (s.indexOf (bgb) == -1) )
        {
        alert ("Illegal background color (bc); Using Black");
        return ("error");
        }
    }   //  if background color supplied


return ("OK");
}   //  TestBG;

//  End-Of-File FUNCTION.JS


