// combine ua.js to save opening another file.
var leftside = 125;
var topside = 120;
var dropMenuDx = 0;
var dropMenuDy = 0;
// ua.js - Detect Browser -- copied from Netscape site
// Requires JavaScript 1.1
/*
The contents of this file are subject to the Netscape Public
License Version 1.1 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.mozilla.org/NPL/

Software distributed under the License is distributed on an "AS
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.

The Initial Developer of the Original Code is Bob Clary.

Contributor(s): Bob Clary, Original Work, Copyright 1999-2000
                Bob Clary, Netscape Communications, Copyright 2001

Alternatively, the contents of this file may be used under the
terms of the GNU Public License (the "GPL"), in which case the
provisions of the GPL are applicable instead of those above.
If you wish to allow use of your version of this file only
under the terms of the GPL and not to allow others to use your
version of this file under the NPL, indicate your decision by
deleting the provisions above and replace them with the notice
and other provisions required by the GPL.  If you do not delete
the provisions above, a recipient may use your version of this
file under either the NPL or the GPL.
*/

// work around bug in xpcdom Mozilla 0.9.1
window.saveNavigator = window.navigator;

// Handy functions
function noop() {}
function noerror() { return true; }

function defaultOnError(msg, url, line)
{
	// customize this for your site
	if (top.location.href.indexOf('_files/errors/') == -1)
		top.location = '/evangelism/xbProjects/_files/errors/index.html?msg=' + escape(msg) + '&url=' + escape(url) + '&line=' + escape(line);
}

// Display Error page... 
// XXX: more work to be done here
//
function reportError(message)
{
	// customize this for your site
	if (top.location.href.indexOf('_files/errors/') == -1)
		top.location = '/evangelism/xbProjects/_files/errors/index.html?msg=' + escape(message);
}

function pageRequires(cond, msg, redirectTo)
{
	if (!cond)
	{
		msg = 'This page requires ' + msg;
		top.location = redirectTo + '?msg=' + escape(msg);
	}
	// return cond so can use in <A> onclick handlers to exclude browsers
	// from pages they do not support.
	return cond;
}

function detectBrowser()
{
	var oldOnError = window.onerror;
	var element = null;
	
	window.onerror = defaultOnError;

	navigator.OS		= '';
	navigator.version	= 0;
	navigator.org		= '';
	navigator.family	= '';

	var platform;
	if (typeof(window.navigator.platform) != 'undefined')
	{
		platform = window.navigator.platform.toLowerCase();
		if (platform.indexOf('win') != -1)
			navigator.OS = 'win';
		else if (platform.indexOf('mac') != -1)
			navigator.OS = 'mac';
		else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
			navigator.OS = 'nix';
	}

	var i = 0;
	var ua = window.navigator.userAgent.toLowerCase();
	
	if (ua.indexOf('opera') != -1)
	{
		i = ua.indexOf('opera');
		navigator.family	= 'opera';
		navigator.org		= 'opera';
		navigator.version	= parseFloat('0' + ua.substr(i+6), 10);
	}
	else if ((i = ua.indexOf('msie')) != -1)
	{
		navigator.org		= 'microsoft';
		navigator.version	= parseFloat('0' + ua.substr(i+5), 10);
		
		if (navigator.version < 4)
			navigator.family = 'ie3';
		else
			navigator.family = 'ie4'
	}
	else if (typeof(window.controllers) != 'undefined' && typeof(window.locationbar) != 'undefined')
	{
		i = ua.lastIndexOf('/')
		navigator.version = parseFloat('0' + ua.substr(i+1), 10);
	        if (navigator.version > 20020101) navigator.version = 1.0;
		navigator.family = 'gecko';

		if (ua.indexOf('netscape') != -1)
			navigator.org = 'netscape';
		else if (ua.indexOf('compuserve') != -1)
			navigator.org = 'compuserve';
		else
			navigator.org = 'mozilla';
	}
	else if ((ua.indexOf('mozilla') !=-1) && (ua.indexOf('spoofer')==-1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera')==-1)&& (ua.indexOf('webtv')==-1) && (ua.indexOf('hotjava')==-1))
	{
	    var is_major = parseFloat(navigator.appVersion);
    
		if (is_major < 4)
			navigator.version = is_major;
		else
		{
			i = ua.lastIndexOf('/')
			navigator.version = parseFloat('0' + ua.substr(i+1), 10);
		}
		navigator.org = 'netscape';
		navigator.family = 'nn' + parseInt(navigator.appVersion);
	}
	else if ((i = ua.indexOf('aol')) != -1 )
	{
		// aol
		navigator.family	= 'aol';
		navigator.org		= 'aol';
		navigator.version	= parseFloat('0' + ua.substr(i+4), 10);
	}

	//alert(navigator.family+" "+navigator.version+" "+navigator.OS);
/* change to Netscape code -- don't need these variables and they fail in Opera 6.0.
	navigator.DOMCORE1	= (typeof(document.getElementsByTagName) != 'undefined' && typeof(document.createElement) != 'undefined');
	navigator.DOMCORE2	= (navigator.DOMCORE1 && typeof(document.getElementById) != 'undefined' && typeof(document.createElementNS) != 'undefined');
	navigator.DOMHTML	= (navigator.DOMCORE1 && typeof(document.getElementById) != 'undefined');
	navigator.DOMCSS1	= ( (navigator.family == 'gecko') || (navigator.family == 'ie4') );

	navigator.DOMCSS2   = false;
	if (navigator.DOMCORE1)
	{
		element = document.createElement('p');
		navigator.DOMCSS2 = (typeof(element.style) == 'object');
	}

	navigator.DOMEVENTS	= (typeof(document.createEvent) != 'undefined');
 end change to Netscape code */
	window.onerror = oldOnError;
}

detectBrowser();

// **************** Netscape Resize bug ********************
/**
 * resize.js 0.3 970811
 * by gary smith
 * js component for "reloading page onResize"
 */

if(!window.saveInnerWidth) {
  window.onresize = resizeIt;
  window.saveInnerWidth = window.innerWidth;
  window.saveInnerHeight = window.innerHeight;
}

function resizeIt() {
    if (saveInnerWidth < window.innerWidth || 
        saveInnerWidth > window.innerWidth || 
        saveInnerHeight > window.innerHeight || 
        saveInnerHeight < window.innerHeight ) {
        window.history.go(0);
    }
} // resizeIt
	
// ================================================================
// drop down windows facility

//alert("OS="+navigator.OS+" fam="+navigator.family+" ver="+navigator.version);
// **************** Gecko Relative coord bug
// Some versions of Netscape used to have a bug in what offsetLeft and offsetTop reported
var objectPosAbsolute = 0; // IE does it as relative to parent object
if ((navigator.family == 'gecko')&&((navigator.version > 6.0)&&(navigator.version < 7.0))) {
    objectPosAbsolute = 1;
}
if (navigator.OS == 'mac' && navigator.family == 'ie4') {
    dropMenuDx = 12;
    dropMenuDy = 15;
}
else if (navigator.OS == 'mac' && navigator.family == 'nn5') { // safari
    dropMenuDx = 20;
    dropMenuDy = 10;
}
else if (navigator.OS == 'win' && navigator.family == 'ie4') {
    dropMenuDx = -10;
    dropMenuDy = -5;
}
else if (navigator.family == 'nn4') { // dont work on Mac
    dropMenuDx = 0;
    dropMenuDy = 0;
}
else if (navigator.family == 'gecko') {
  dropMenuDx = 0;
  dropMenuDy = 0;
}
else if (navigator.family == 'opera') {
  //dropMenuDx = 150; // who knows why
  //dropMenuDy = 90;
}

function findObj(n, d) { //v4.0
  var p,i,x = null;  
  if (!d) d = document; 
  if ((p = n.indexOf("?"))>0 && parent.frames.length) {
    d = parent.frames[n.substring(p+1)].document; 
    n = n.substring(0,p);
  }
  if (!(x = d[n]) && d.all) x = d.all[n]; 
  for (i = 0;!x && i<d.forms.length;i++) x = d.forms[i][n];
  for (i = 0;!x && d.layers && i<d.layers.length;i++) x = findObj(n,d.layers[i].document);
  if (!x && document.getElementById) x = document.getElementById(n); 
  return x;
} // findObj

function showMenus() {
  //alert("showMenus");
  var i,obj,args = showMenus.arguments;
  if (objectPosAbsolute == 1) { // is menu positioning relative or absolute
    var spot = eval('document.images["'+args[0]+'"]');
    leftside = dropMenuDx+spot.offsetLeft;
    topside = dropMenuDy+spot.offsetTop;
    //alert("document.images['"+args[0]+"'] "+leftside+" "+topside);
    for (i = 1; i<(args.length-2); i += 3) {
     if ((obj = findObj(args[i]))!= null) { 
       if (obj.style) obj = obj.style; 
       obj.visibility = 'visible';
       obj.left = leftside+args[i+1];
       obj.top = topside+args[i+2];
     }
    } // for
  } else if ((navigator.family == 'ie4')||(navigator.family == 'opera')||(navigator.family == 'nn5')||(navigator.family == 'gecko')) {
    var spot = eval('document.images["'+args[0]+'"]');
    leftside = dropMenuDx;
    topside = dropMenuDy;
    while(spot.offsetParent != null) {
      leftside += spot.offsetLeft;
      topside += spot.offsetTop;
      spot = spot.offsetParent;
    }
    for (i = 1; i<(args.length-2); i += 3) {
     if ((obj = findObj(args[i])) != null) { 
       if (obj.style) obj = obj.style; 
       obj.visibility = 'visible';
       obj.left = leftside+args[i+1];
       obj.top = topside+args[i+2];
     }
    } // for
    if (navigator.family == 'ie4') {
      window.event.cancelBubble = true; // DHTML p145
    }
  } else if (navigator.family == 'nn4') {
    leftside = eval('document.images["'+args[0]+'"].x');
    topside = eval('document.images["'+args[0]+'"].y');
    leftside += dropMenuDx;
    topside += dropMenuDy;
    for (i = 1; i < (args.length-2); i += 3) {
     if ((obj = findObj(args[i])) != null) { 
       obj.visibility = 'visible'; // ??? seems to work
       eval('document.layers.'+args[i]+'.moveTo('+(leftside+args[i+1])+', '+(topside+args[i+2])+')');
     }
    } // for
  } else {
    //alert("unknown navigator.family "+navigator.family);
  }
} // showMenus

function hideLayers() {
  var i,obj,args = hideLayers.arguments;
  for (i = 0; i < (args.length); i++) {
   if ((obj = findObj(args[i])) != null) { 
     if (obj.style) obj = obj.style; 
     obj.visibility = 'hidden';
   }
  } // for
} // hideLayers

function showLayers() {
  var i,obj,args = showLayers.arguments;
  for (i = 0; i < (args.length); i++) {
   if ((obj = findObj(args[i]))!=null) { 
     if (obj.style) obj = obj.style; 
     obj.visibility = 'visible';
   }
  } // for
} // showLayers
