// util.js - everyday utilities
// Requires JavaScript 1.1 - by this point, I can't really 
//  say I care much about old browsers anymore.

var nav = window.navigator;
var ua = nav.userAgent.toLowerCase();


function popupWin(w,h,winName) {
	windowSpecs = "width=" + w + ",height=" + h + ",resizable=yes,scrollbars=yes,location=no,toolbar=no";
	newWindowRef = window.open("", winName, windowSpecs);
	return newWindowRef;
}
function popup(winName,windowSpecs) {
	newWindowRef = window.open('', winName, windowSpecs);
	return newWindowRef;
}
function popupDefWin() {
	newWindowRef = popup('win_def','width=540,height=440,top=8,left=8,resizable=yes,scrollbars=yes,location=no,toolbar=no');
	return newWindowRef;
}

// kick browser window out to specified minimum width
//  (put call in body onload attribute)
function adjwidth(minw) {
	w = window.innerWidth;
	if (w < minw) 
		self.resizeBy(minw - w, 0);
}


// Handy functions
function noop() {}
function noerror() { return true; }

function defaultOnError(msg, url, line)
{
	//if (top.location.href.indexOf('_files/errors/') == -1)
	//	top.location = 'default.asp?msg=' + escape(msg) + '&url=' + escape(url) + '&line=' + escape(line);
	alert(msg + '\nurl = '+url + '\nline = '+line);
}

function detectBrowser() {
	var oldOnError = window.onerror;
	var element = null;
	
	window.onerror = defaultOnError;

	nav.OS		= '';
	nav.version	= 0;
	nav.org		= '';
	nav.family	= '';

	var platform;
	if (typeof(nav.platform) != 'undefined') {
		platform = nav.platform.toLowerCase();
		if (platform.indexOf('win') != -1)
			nav.OS = 'win';
		else if (platform.indexOf('mac') != -1)
			nav.OS = 'mac';
		else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
			nav.OS = 'nix';
	}
	var i = 0;	
	if (ua.indexOf('opera') != -1) {
		i = ua.indexOf('opera');
		nav.family	= 'opera';
		nav.org		= 'opera';
		nav.version	= parseFloat('0' + ua.substr(i+6), 10);
	}
	else if ((i = ua.indexOf('msie')) != -1) {
		nav.org		= 'microsoft';
		nav.version	= parseFloat('0' + ua.substr(i+5), 10);
		
		if (nav.version < 4)
			nav.family = 'ie3';
		else
			nav.family = 'ie4'
	}
	else if (typeof(window.controllers) != 'undefined' && typeof(window.locationbar) != 'undefined') {
		i = ua.lastIndexOf('index.html')
		nav.version = parseFloat('0' + ua.substr(i+1), 10);
		nav.family = 'gecko';

		if (ua.indexOf('netscape') != -1)
			nav.org = 'netscape';
		else if (ua.indexOf('compuserve') != -1)
			nav.org = 'compuserve';
		else
			nav.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(nav.appVersion);
    
		if (is_major < 4)
			nav.version = is_major;
		else
		{
			i = ua.lastIndexOf('index.html')
			nav.version = parseFloat('0' + ua.substr(i+1), 10);
		}
		nav.org = 'netscape';
		nav.family = 'nn' + parseInt(nav.appVersion);
	}
	else if ((i = ua.indexOf('aol')) != -1 ) {
		// aol
		nav.family	= 'aol';
		nav.org		= 'aol';
		nav.version	= parseFloat('0' + ua.substr(i+4), 10);
	}

	nav.DOMCORE1 = (typeof(document.getElementsByTagName) != 'undefined' && typeof(document.createElement) != 'undefined');
	nav.DOMCORE2 = (nav.DOMCORE1 && typeof(document.getElementById) != 'undefined' && typeof(document.createElementNS) != 'undefined');
	nav.DOMHTML  = (nav.DOMCORE1 && typeof(document.getElementById) != 'undefined');
	nav.DOMCSS1  = ( (nav.family == 'gecko') || (nav.family == 'ie4') );

	nav.DOMCSS2  = false;
	if (nav.DOMCORE1) {
		element = document.createElement('p');
		nav.DOMCSS2 = (typeof(element.style) == 'object');
	}
	nav.DOMEVENTS = (typeof(document.createEvent) != 'undefined');

	window.onerror = oldOnError;
}
detectBrowser();



// ClientSnifferJr Object Constructor
// Mike Foster, 12/12/01
// cross-browser.com

function ClientSnifferJr() {
	this.major = parseInt(nav.appVersion);
	this.minor = parseFloat(nav.appVersion);
	// DOM Support
	if (document.addEventListener && document.removeEventListener) 
		this.dom2events = true;
	if (document.getElementById) 
		this.dom1getbyid = true;
	// Opera
	this.opera = ua.indexOf('opera') != -1;
	if (this.opera) {
		this.opera5 = (ua.indexOf("opera 5") != -1 || ua.indexOf("opera/5") != -1);
		this.opera6 = (ua.indexOf("opera 6") != -1 || ua.indexOf("opera/6") != -1);
		return;
	}
	// Konqueror
	this.konq = ua.indexOf('konqueror') != -1;
	// MSIE
	this.ie = ua.indexOf('msie') != -1;
	if (this.ie) {
		this.ie3 = this.major < 4;
		this.ie4 = (this.major == 4 && ua.indexOf('msie 5') == -1 && ua.indexOf('msie 6') == -1);
		this.ie4up = this.major >= 4;
		this.ie5 = (this.major == 4 && ua.indexOf('msie 5.0') != -1);
		this.ie5up = !this.ie3 && !this.ie4;
		this.ie6 = (this.major == 4 && ua.indexOf('msie 6.0') != -1);
		this.ie6up = (!this.ie3 && !this.ie4 && !this.ie5 && ua.indexOf("msie 5.5") == -1);
		return;
	}
	// Misc.
	this.hotjava = ua.indexOf('hotjava') != -1;
	this.webtv = ua.indexOf('webtv') != -1;
	this.aol = ua.indexOf('aol') != -1;
	if (this.hotjava || this.webtv || this.aol) 
		return;
	// Gecko, NN4+, and NS6
	this.gecko = ua.indexOf('gecko') != -1;
	this.nav = (ua.indexOf('mozilla') != -1 && ua.indexOf('spoofer') == -1 && ua.indexOf('compatible') == -1);
	if (this.nav) {
		this.nav4 = this.major == 4;
		this.nav4up = this.major >= 4;
		this.nav5up = this.major >= 5;
		this.nav6 = this.major == 5;
		this.nav6up = this.nav5up;
	}
}
window.is = new ClientSnifferJr();



// image swapping code which will work with images within nested divs

if (is.ie4 && ! nav.version < 5)
	document.getElementById = new Function("id", "return document.all[id];");

else if (is.nav4)
	document.getElementById = nav4GetLayerById;


function nav4GetLayerById(id) {
	return nav4FindLayer(this, id);
}
function nav4FindLayer(doc, id) {
	var i, subdoc, obj;
	
	for (i = 0; i < doc.layers.length; ++i) {
		if (doc.layers[i].id && id == doc.layers[i].id)
			return doc.layers[i];
		
		subdoc = doc.layers[i].document;
		obj = nav4FindLayer(subdoc, id);
		if (obj != null)
			return obj;
	}
	return null;
}
function swap(id,img) {
	el = document.getElementById(id);
	el.src = eval(img + ".src");
}

