/*********************************************************************/
/* system.js                                                         */
/* core system functions and variables                               */
/* (c) 2001-2005 Jon Gilkison, Interfacelab Inc.                     */
/*********************************************************************/

/*********************************************************************/

function _indexOf(item) {
	for (var i in this)
		if (this[i]==item)
			return i;
	
	return -1;
}

Array.prototype.indexOf=_indexOf;

/*********************************************************************/

var included=["system.js"];
var basePath="js/";

function include(libFile) {
	if (included.indexOf(libFile)>-1)
		return;
	document.write("<script src='"+basePath+libFile+"'></script>");
	included[included.length]=libFile;
}

function includeIf(libFile,doInclude) {
	if (doInclude)
		include(libFile);
}

function setBasePath(pth) {
	basePath=pth;
}

/*********************************************************************/

var loadProcs=[]

function addLoadProc(proc) {
	if (loadProcs.indexOf(proc)>-1)
		return;
	
	loadProcs[loadProcs.length]=proc;
}

onload=function() {
	for (var i=0; i<loadProcs.length; i++)
		loadProcs[i]();
}

/*********************************************************************/

function BrowserCheck() {
	// def props
	this.ns4 = this.ns4up = this.ns5up = this.ns5 = this.ns6 = this.ns6up = this.nav5up = false;
	this.opera = this.opera5 = false;
	this.ie = this.ie3 = this.ie4 = this.ie4up = this.ie5 = this.ie5up = this.ie6 = this.ie6up = false;

	this.hotjava = this.webtv = this.aol = false; 

	this.gecko = this.ns = this.ns4  = this.ns4up= this.ns5up = this.ns5 = this.ns6 = this.ns6up= false;

	// user agent/major version/minor version
	this.ua = navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.minor = parseFloat(navigator.appVersion);

	this.mac=(this.ua.indexOf('Mac')>0);
	this.linux=(this.ua.indexOf('Linux')>0);
	this.unix=(this.ua.indexOf('Unix')>0);
	this.windows=( (!this.mac) && (!this.linux) && (!this.unix));

	// DOM Support
	this.dom2events=(document.addEventListener && document.removeEventListener);
	this.dom1getbyid = (document.getElementById);

	// Opera
	this.opera = this.ua.indexOf('opera') != -1;
	if (this.opera) {
		this.opera5 = (this.ua.indexOf("opera 5") != -1 || this.ua.indexOf("opera/5") != -1);
		this.opera6 = (this.ua.indexOf("opera 6") != -1 || this.ua.indexOf("opera/6") != -1);
	}  

	// MSIE
	this.ie = this.ua.indexOf('msie') != -1;
	if (this.ie) {
		this.ie3 = this.major < 4;
		this.ie4 = (this.major == 4 && this.ua.indexOf('msie 5') == -1 && this.ua.indexOf('msie 6') == -1);
		this.ie4up = this.major >= 4;
		this.ie5 = (this.major == 4 && this.ua.indexOf('msie 5.0') != -1);
		this.ie5up = !this.ie3 && !this.ie4;
		this.ie6 = (this.major == 4 && this.ua.indexOf('msie 6.0') != -1);
		this.ie6up = (!this.ie3 && !this.ie4 && !this.ie5 && this.ua.indexOf("msie 5.5") == -1);
	}

	// Misc.
	this.hotjava = this.ua.indexOf('hotjava') != -1; 
	this.webtv = this.ua.indexOf('webtv') != -1;
	this.aol = this.ua.indexOf('aol') != -1; 

	// Gecko, NN4+, and NS6
	this.gecko = this.ua.indexOf('gecko') != -1;
	this.ns = (this.ua.indexOf('mozilla') != -1 && this.ua.indexOf('spoofer') == -1 && this.ua.indexOf('compatible') == -1);
	if (this.ns) {
		this.ns4  = this.major == 4;
		this.ns4up= this.major >= 4;
		this.ns5up= this.major >= 5;
		this.ns5=this.ns6  = this.major == 5;
		this.ns6up= this.nav5up;
	}
}

var is = new BrowserCheck();

 if (document.all) { 
 	if (!document.getElementById) 
		document.getElementById=document.all; 
		document.getElementsByTagName=function(a) { 
			if (a=="*") 
				return document.all; 
			return document.all.tags(a); 
		} 
}
