/*

file: api-phj.js

2001dec17 phj

Modified to use "Ultimate client-side JavaScript client sniff." from
developer.netscape.com/docs/examples/javascript/browser_type.html and
to take account of netscape gecko clients, i.e., clients that 

*/

var iexp = (navigator.appName == "Microsoft Internet Explorer");
var nscp = (navigator.appName == "Netscape");
var ismc = (navigator.appVersion.indexOf("Mac") != -1);
var vers = parseFloat(navigator.appVersion.substring(22,25));

// Ultimate client-side JavaScript client sniff.
// (C) Netscape Communications 1999.  Permission granted to reuse and
// distribute.
// Revised 17 May 99 to add is_nav5up and is_ie5up (see below).
// Revised 20 Dec 00 to add is_gecko and change is_nav5up to is_nav6up
//                      also added support for IE5.5 Opera4&5 HotJava3 AOLTV

// Everything you always wanted to know about your JavaScript client
// but were afraid to ask. Creates "is_" variables indicating:
// (1) browser vendor:
//     is_nav, is_ie, is_opera, is_hotjava

// (2) browser version number:
//     is_major (integer indicating major version number: 2, 3, 4 ...)
//     is_minor (float   indicating full  version number: 2.02, 3.01, 4.04 ...)

// (3) browser vendor AND major version number
//     is_nav2, is_nav3, is_nav4, is_nav4up, is_nav6, is_nav6up, is_gecko
//     is_ie3, is_ie4, is_ie5, is_ie5up, is_ie4up, is_ie5_5, is_ie5_5up
//     is_hotjava3,is_hotjava3up,
//     is_opera4, is_opera5, is_opera5up

// (4) JavaScript version number:
//     is_js (float indicating full JavaScript version number: 1, 1.1, 1.2 ...)

// (5) OS platform and version:
//     is_win, is_win16, is_win32, is_win31, is_win95, is_winnt, is_win98
//     is_os2
//     is_mac, is_mac68k, is_macppc
//     is_unix
//        is_sun, is_sun4, is_sun5, is_suni86
//        is_irix, is_irix5, is_irix6
//        is_hpux, is_hpux9, is_hpux10
//        is_aix, is_aix1, is_aix2, is_aix3, is_aix4
//        is_linux, is_sco, is_unixware, is_mpras, is_reliant
//        is_dec, is_sinix, is_freebsd, is_bsd
//     is_vms

// Note: you don't want your Nav4 or IE4 code to "turn off" or stop working
// when new versions of browsers are released, so in conditional code forks,
// use is_ie5up ("IE 5.0 or greater") is_opera5up ("Opera 5.0 or greater")
// instead of is_ie5 or is_opera5 to check version in code which you want to
// work on future versions.

    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) &&
		(agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) &&
		(agt.indexOf('hotjava')==-1));
    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_gecko = (agt.indexOf('gecko') != -1);


    var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3 = (is_ie && (is_major < 4));
    var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5")==-1) );
    var is_ie4up = (is_ie  && (is_major >= 4));
    var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5 = (is_ie && (is_major == 4) &&
		   (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);

    // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
    var is_aol   = (agt.indexOf("aol") != -1);
    var is_aol3  = (is_aol && is_ie3);
    var is_aol4  = (is_aol && is_ie4);

    var is_opera = (agt.indexOf("opera") != -1);
	var is_opera4 = (agt.indexOf("opera 4") != -1);
	var is_opera5 = (agt.indexOf("opera 5") != -1);
	var is_opera5up = (is_opera && (is_major >=4));

    var is_webtv = (agt.indexOf("webtv") != -1); 

	
    var is_TVNavigator = ((agt.indexOf("navio") != -1) ||
			 (agt.indexOf("navio_aoltv") != -1)); 
	var is_AOLTV = is_TVNavigator;

    var is_hotjava = (agt.indexOf("hotjava") != -1);
    var is_hotjava3 = (is_hotjava && (is_major == 3));
    var is_hotjava3up = (is_hotjava && (is_major >= 3));

    // *** JAVASCRIPT VERSION CHECK ***
    var is_js;
    if (is_nav2 || is_ie3) is_js = 1.0;
    else if (is_nav3 || is_opera) is_js = 1.1;
    else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
    else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
	else if (is_hotjava3up) is_js = 1.4;
    else if (is_nav6 || is_gecko) is_js = 1.5;
    // NOTE: In the future, update Ithis code when newer versions of JS
    // are released. For now, we try to provide some upward compatibility
    // so that future versions of Nav and IE will show they are at
    // *least* JS 1.x capable. Always check for JS version compatibility
    // with > or >=.
	else if (is_nav6up) is_js = 1.5;
    else if (is_ie && (is_major > 5)) is_js = 1.3

    // HACK: no idea for other browsers; always check for JS version with > or
    // >=

    else is_js = 0.0;

    // *** PLATFORM ***
    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );

    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on
    // all Win32, so you can't distinguish between Win95 and WinNT.

    var is_win95 = ((agt.indexOf("win95")!=-1) ||
		   (agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    var is_win16 = ((agt.indexOf("win16")!=-1) || 
               (agt.indexOf("16bit")!=-1) ||
	       (agt.indexOf("windows 3.1")!=-1) || 
               (agt.indexOf("windows 16-bit")!=-1) );  

    var is_win31 = ((agt.indexOf("windows 3.1")!=-1) ||
		   (agt.indexOf("win16")!=-1) ||
                    (agt.indexOf("windows 16-bit")!=-1));

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".

    var is_win98 = ((agt.indexOf("win98")!=-1) ||
		   (agt.indexOf("windows 98")!=-1));
    var is_winnt = ((agt.indexOf("winnt")!=-1) ||
		   (agt.indexOf("windows nt")!=-1));
    var is_win32 = (is_win95 || is_winnt || is_win98 || 
                    ((is_major >= 4) && (navigator.platform == "Win32")) ||
                    (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

    var is_os2   = ((agt.indexOf("os/2")!=-1) || 
                    (navigator.appVersion.indexOf("OS/2")!=-1) ||   
                    (agt.indexOf("ibm-webexplorer")!=-1));

    var is_mac    = (agt.indexOf("mac")!=-1);
    var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) || 
                               (agt.indexOf("68000")!=-1)));
    var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) || 
                                (agt.indexOf("powerpc")!=-1)));

    var is_sun   = (agt.indexOf("sunos")!=-1);
    var is_sun4  = (agt.indexOf("sunos 4")!=-1);
    var is_sun5  = (agt.indexOf("sunos 5")!=-1);
    var is_suni86= (is_sun && (agt.indexOf("i86")!=-1));
    var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
    var is_irix5 = (agt.indexOf("irix 5") !=-1);
    var is_irix6 = ((agt.indexOf("irix 6") !=-1) ||
		   (agt.indexOf("irix6") !=-1));
    var is_hpux  = (agt.indexOf("hp-ux")!=-1);
    var is_hpux9 = (is_hpux && (agt.indexOf("09.")!=-1));
    var is_hpux10= (is_hpux && (agt.indexOf("10.")!=-1));
    var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
    var is_aix1  = (agt.indexOf("aix 1") !=-1);    
    var is_aix2  = (agt.indexOf("aix 2") !=-1);    
    var is_aix3  = (agt.indexOf("aix 3") !=-1);    
    var is_aix4  = (agt.indexOf("aix 4") !=-1);    
    var is_linux = (agt.indexOf("inux")!=-1);
    var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
    var is_unixware = (agt.indexOf("unix_system_v")!=-1); 
    var is_mpras    = (agt.indexOf("ncr")!=-1); 
    var is_reliant  = (agt.indexOf("reliantunix")!=-1);
    var is_dec = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) || 
          (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) ||
           (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1)); 
    var is_sinix = (agt.indexOf("sinix")!=-1);
    var is_freebsd = (agt.indexOf("freebsd")!=-1);
    var is_bsd = (agt.indexOf("bsd")!=-1);
    var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux ||
                 is_sco ||is_unixware || is_mpras || is_reliant || is_dec ||
                 is_sinix || is_aix || is_linux || is_bsd || is_freebsd);

    var is_vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));



function displayBrowserInfo()
{

	document.write("<H2>Profile of your browser</H2>" + "<BR>");
	document.write("<P>navigator.appName: " + navigator.appName + "<BR>");
	document.write("navigator.userAgent: " + navigator.userAgent + "<BR>");
	document.write("navigator.appVersion: " + navigator.appVersion + "</P>");

	document.write("<P>Version number:" + "<BR>");
	document.write("major:" + is_major + ", ");
	document.write("minor:" + is_minor + "</P>");

	document.write("<P>" + "Browser version:" + "<BR>");

	if ( is_nav )
	{
	  document.write("<P>nav:" + is_nav + ", &nbsp;");
	  document.write("nav2:" + is_nav2 + ", &nbsp;");
	  document.write("nav3:" + is_nav3 + ", &nbsp;");
	  document.write("nav4:" + is_nav4 + ", &nbsp;");
	  document.write("nav4up:" + is_nav4up + ", &nbsp;");
	  document.write("nav6:" + is_nav6 + ", &nbsp;");
	  document.write("nav6up:" + is_nav6up + ", &nbsp;");
          document.write("gecko:" + is_gecko + ", &nbsp;");
	  document.write("navonly:" + is_navonly + "</P>");
	}

	if ( is_ie )
	{
	  document.write("<P>" + "ie:" + is_ie + ", &nbsp;");
	  document.write("ie3:" + is_ie3 + ", &nbsp;");
	  document.write("ie4:" + is_ie4 + ", &nbsp;");
	  document.write("ie4up:" + is_ie4up + ", &nbsp;");
	  document.write("ie5:" + is_ie5 + ", &nbsp;");
	  document.write("ie5up:" + is_ie5up + ", &nbsp;");
          document.write("ie5_5:" + is_ie5_5 + ", &nbsp;");
          document.write("ie5_5up:" + is_ie5_5up + "</P>");
	}

	if ( is_aol )
	{
	  document.write("<P>" + "aol:" + is_aol + ", &nbsp;");
	  document.write("aol3:" + is_aol3 + ", &nbsp;");
	  document.write("aol4:" + is_aol4 + "</P>");
        }

	if ( is_opera )
	{
	  document.write("<P>" + "opera:" + is_opera + ", &nbsp;");
	  document.write("opera4:" + is_opera4 + ", &nbsp;");
	  document.write("opera5:" + is_opera5 + ", &nbsp;");
	  document.write("opera5up:" + is_opera5up + "</P>");
	}

	if ( is_webtv )
	{
	  document.write("<P>" + "webtv:" + is_webtv + "</P>");
        }

	if ( is_hotjava )
	{
	  document.write("<P>" + "hotjava:" + is_hotjava + ", &nbsp;");
	  document.write("hotjava3:" + is_hotjava3 + ", &nbsp;");
	  document.write("hotjava3up:" + is_hotjava3up + "</P>");
        }

	if ( is_TVNavigator )
	{
	  document.write("<P>AOL TV(TVNavigator):" + is_TVNavigator + "</P>");
	}

	document.write("<P>js:" + is_js + "</P>");

	if ( is_win )
	{
	  document.write("<P>win:" + is_win + ", &nbsp;");
	  document.write("win16:" + is_win16 + ", &nbsp;");
	  document.write("win31:" + is_win31 + ", &nbsp;");
	  document.write("win32:" + is_win32 + ", &nbsp;");
	  document.write("win95:" + is_win95 + ", &nbsp;");
	  document.write("win98:" + is_win98 + ", &nbsp;");
	  document.write("winnt:" + is_winnt + "</P>");
	}

	if ( is_os2 )
	{
	  document.write("<P>" + "os2:" + is_os2 + "</P>");
	}

	if ( is_mac )
	{
	  document.write("<P>" + "mac:" + is_mac + ", &nbsp;");
	  document.write("mac68k:" + is_mac68k + ", &nbsp;");
	  document.write("macppc:" + is_macppc + "</P>");
	}

	if ( is_unix )
	{
	  document.write("<P>" + "unix:" + is_unix + ", &nbsp;");
	  document.write("sun:" + is_sun + ", &nbsp;");
	  document.write("sun4:" + is_sun4 + ", &nbsp;");
	  document.write("sun5:" + is_sun5 + ", &nbsp;");
	  document.write("suni86:" + is_suni86 + ", &nbsp;");
	  document.write("irix:" + is_irix + ", &nbsp;");
	  document.write("irix5:" + is_irix5 + ", &nbsp;");
	  document.write("irix6:" + is_irix6 + "</P>");

	  document.write("<P>hpux:" + is_hpux + ", &nbsp;");
	  document.write("hpux9:" + is_hpux9 + ", &nbsp;");
	  document.write("hpux10:" + is_hpux10 + ", &nbsp;");
	  document.write("aix:" + is_aix + ", &nbsp;");
	  document.write("aix1:" + is_aix1 + ", &nbsp;");
	  document.write("aix2:" + is_aix2 + ", &nbsp;");
	  document.write("aix3:" + is_aix3 + ", &nbsp;");
	  document.write("aix4:" + is_aix4 + "</P>");

	  document.write("<P>linux:" + is_linux + ", &nbsp;");
	  document.write("sco:" + is_sco + ", &nbsp;");
	  document.write("unixware:" + is_unixware + ", &nbsp;");
	  document.write("mpras:" + is_mpras + ", &nbsp;");
	  document.write("reliant:" + is_reliant + ", &nbsp;");
	  document.write("dec:" + is_dec + ", &nbsp;");
	  document.write("sinix:" + is_sinix + "</P>");
	}

	if ( is_bsd )
	{
	  document.write("<P>bsd:" + is_bsd + "</P>");
	}

	if ( is_freebsd )
	{
	  document.write("<P>freebsd:" + is_freebsd + "</P>");
	}

	if ( is_vms )
	{
	  document.write("<P>" + "vms:" + is_vms + "</P>");
	}

} //end of displayBrowserInfo().



function GoUrl( s )
{
  var d = s.options[s.selectedIndex].value;
  window.top.location.href = d;
  s.selectedIndex=0;

  return true;
}



function getName(obj)
{	
	return obj;
}



/* 2009nov10, phj: Added final else clause that uses what I think is the best
solution.  */

function getObj( obj )
{

  if ( is_nav6up )
    compLayr = document.getElementById( obj );

  else if ( nscp )
    compLayr = document.layers[obj];

  else if ( iexp )
    compLayr = eval("document.all." + obj + ".style");

  else
    compLayr = document.getElementById( obj );

  return compLayr;
}



function advGetObj(id) //advanced version of getObj(), taken from
			 // www.xs4all.nl/~ppk/js/index.html 
/*

advGetObj() is called like so:

var x = new advGetObj('layerid');

which creates a new JavaScript object x. The function takes care that
the new object gets two properties: x.obj gives access to the object
itself and x.style gives access to the style object. In Netscape 4
this is the same thing, but all other browsers have a special style
property for the style sheets added to the HTML element.

So to alert the ID of the object, do

alert(x.obj.id)

After all the ID is a property of the object itself, not of the
style. To change the top coordinate, do

x.style.top = '20px';

This function is much more versatile than the old one. I'm going to
extend it so that it can also search for layers within layers in
Netscape 4. When that's done I have the perfect function to solve all
DOM problems.

*/
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(id);
	this.style = document.getElementById(id).style;
  }
  else if (document.all)
  {
	this.obj = document.all[id];
	this.style = document.all[id].style;
  }
  else if (document.layers)
  {
//  alert( "in advgetobj, id = " + id + "." );
   	this.obj = document.layers[id];
   	this.style = document.layers[id];
  }
} //end advGetObj().



function advGetObj_ns4(id, subId) // like advGetObj, but looks for
				      // a layer in a layer.
/*
advGetObj_ns4() is called like so:

var x = new advGetObj_ns4( <layerid>, <sub layer id> );

which creates a new JavaScript object x.  For cases in which
document.getElementById or document.all exist, only subId is used; id is
ignored.  For the case in which document.layers exists, both id and subId
are used, the object returned is the layer subId within layer id.

*/
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById( subId);
	this.style = document.getElementById(subId).style;
  }
  else if (document.all)
  {
	this.obj = document.all[subId];
	this.style = document.all[subId].style;
  }
  else if (document.layers)
  {
/*
	alert( "# layers = " + document.layers.length );

	alert( "# sublayers = " +
	       document.layers['recently'].document.layers.length );

	alert( "# sublayers = " +
	       document.layers[id].document.layers.length );

	alert( "recently left = " +
	       document.recently.left );

	alert( id + " left = " +
	       document.layers[id].left );

	alert( "recently2001fall left = " +
	       document.recently.document.recently2001fall.left );

	alert( subId + " left = " +
	       document.layers[id].document.layers[subId].left );

	alert( subId + " visibility = " +
	       document.layers[id].document.layers[subId].visibility );
*/

// Following works, as long as there is a <LAYER> named lrecently2001fall
// inside a <DIV> named recently.

//	alert( "recently2001fall visibility = " +
//	       document.recently.document.lrecently2001fall.visibility );

   	this.obj = document.layers[id].document.layers[subId];
   	this.style = document.layers[id].document.layers[subId];
  }
} //end advGetObj_ns4().



function objExists(name) //taken from advGetObj().

/*
objExists() is called like so:

if ( objExists('layername') )

*/

{
  result = false; // assume; check below and change as necessary.

  if (document.getElementById)
  {
  	if ( document.getElementById(name) )
	  result = true;
  }
  else if (document.all)
  {
	if ( document.all[name] )
	   result = true;
  }
  else if (document.layers)
  {
   	if ( document.layers[name] )
   	   result = true;
  }

 return result;
} //end objExists().



// Sample call is show( "layer0off" ). 
// Called from init(), menuRoll(), checkMenu().

/* 2009nov10, phj: Added final else clause that uses what I think is the best
solution.  */

function show( myLayer )
{	
  myObj = getObj( myLayer );

  if ( is_nav6up )
  {
//     alert( myLayer );
    myObj.style.visibility = "visible";
  }

  else if ( nscp )
  {
    // alert( "in show: " + myLayer ); //debugging, 2001nov16.
    myObj.visibility = "visible";
  }

  else if ( iexp )
    myObj.visibility = "visible";

  else
    myObj.style.visibility = "visible";
}



/* 2009nov10, phj: Added final else clause that uses what I think is the best
solution.  */

function hide( myLayer )
{
  myObj = getObj( myLayer );

  if ( is_nav6up )
      {
	  // alert( "in hide: " + myLayer + "." ); //debugging, 2010apr14.
	  myObj.style.visibility = "hidden";
      }
  else if ( nscp )
  {
    // alert( "in hide: " + myLayer ); //debugging, 2001nov16.
    myObj.visibility = "hidden";
  }

  else if ( iexp )
    myObj.visibility = "hidden";

  else
    myObj.style.visibility = "hidden";
}



/*

Added by phj, 2001dec11.  This does work in ns4.7 and up, and IE 5.5 and up
browsers I have tested.  Writes the given text into the <DIV>
specified by the given id.

text would be something like:

<A HREF="images/2001-winterArtShow/n-mays.html">
<IMG SRC="images/2001-winterArtShow/n-mays-011-reduced.jpg" ALT="From the 2001 Winter Art Show." BORDER="0">
</A>

and id would be something like "timelypicture" and this function
would be called from init().

*/

function writeIt( text, id )
{
	if (document.getElementById)
	{
		x = document.getElementById(id);
		x.innerHTML = text;
	}
	else if (document.all)
	{
		x = document.all[id];
		x.innerHTML = text;
	}
	else if (document.layers)
	{
		x = document.layers[id];
		x.document.open();
		x.document.write(text);
		x.document.close();
	}
} // end of writeIt().



/*
Very much like writeIt(), but also handles a <LAYER> inside a <DIV> in
a NS 4 browser.
*/
function writeIt_ns4( text, id, subId )
{
	if (document.getElementById)
	{
		x = document.getElementById(id);
		x.innerHTML = text;
	}
	else if (document.all)
	{
		x = document.all[id];
		x.innerHTML = text;
	}
	else if (document.layers)
	{
		x = document.layers[id].document.layers[subId];
		x.document.open();
		x.document.write(text);
		x.document.close();
	}
} // end of writeIt_ns4().



/*
Opens a window of the given width and height which contains the
specified URL.  Note there may be no blanks in the string that begins
'width=...', which is kind of a pain.  A string may be built up in a
variable, however, so there is no need for statements that extend way
past the right edge of the window.
*/

function myOpenWindow( url, width, height ) 
{

  winProperties = "width=" + width + ",height=" + height;
  winProperties += ",scrollbars=yes";
  winProperties += ',resizable=yes';

  window.open( url, 'jav', winProperties )

} // end of myOpenWindow().