// Generic useful javascript
// browserchecker.

var sp = ' ';
var csp = ', ';

// Shortcut for document.getElementById
function $(id) {
	return document.getElementById(id);	
}

function hide(what) {
	if (typeof what == 'string') what = $(what);
	if (what) 	
		what.style.display = 'none';	
}

function show(what) {
	if (typeof what == 'string') what = $(what);
	if (what) 	
		what.style.display = '';	
}

function toggle(what) {
	if (typeof what == 'string') what = $(what);
	if (what) {	
		if (what.style.display == 'none') {
			what.style.display = '';	
		} else {
			what.style.display = 'none';	
		}
	}
}

function space2nbsp(s) {
	while (s.indexOf(' ') >= 0) s = s.replace(' ','&nbsp;');
	return s;	
}

function maxLength(s,len) {
	if (s.length > len) return s.substring(0,len-2) + '...';
	return s;
}

function BrowserDetector() {

	this.browser = '';
	this.os = '';
	
	var detect = navigator.userAgent.toLowerCase();

	function checkIt(aString) {
		return detect.indexOf(aString) + 1;
	}	
		
	if (checkIt('konqueror')) {
		this.browser = "Konqueror";
		this.os = "Linux";
	} else if (checkIt('safari')) this.browser = "Safari"
	else if (checkIt('omniweb')) this.browser = "OmniWeb"
	else if (checkIt('opera')) this.browser = "Opera"
	else if (checkIt('webtv')) this.browser = "WebTV";
	else if (checkIt('icab')) this.browser = "iCab"
	else if (checkIt('msie')) this.browser = "Internet Explorer"
	else if (checkIt('firefox')) this.browser = "Firefox"
	else if (!checkIt('compatible')) {
		this.browser = "Netscape Navigator"
	} else {
		this.browser = "Unknown";
	}
		
	if (!this.os) {
		if (checkIt('linux')) this.os = "Linux";
			else if (checkIt('x11')) this.os = "Unix";
			else if (checkIt('mac')) this.os = "Mac"
			else if (checkIt('win')) this.os = "Windows"
			else this.os = "Unknown";
	}
	
	this.isIE = this.browser == "Internet Explorer";
	this.isGecko = checkIt('gecko');
}

var browser = new BrowserDetector();	
	
// Return the x coordinate of an element relative to the page.
function getPageOffsetLeft(el) {
	var x;
	x = el.offsetLeft;
	if (el.offsetParent != null) x += getPageOffsetLeft(el.offsetParent);
	return x;
}

function getPageOffsetTop(el) {
	var y;
	// Return the x coordinate of an element relative to the page.
	y = el.offsetTop;
	if (el.offsetParent != null)  y += getPageOffsetTop(el.offsetParent);
	return y;
}

function dump(o,desc) {
	var s = '';
	if (typeof desc != 'undefined') s+= desc+': ';
	s += '[ Type = '+(typeof o)+' ]<br><br>';
	for (var prop in o) {
		try {
			s += prop + ' = ' + o[prop] + '<BR>';
		} catch (exception) {
			s += prop + ' = [error displaying value]' + '<BR>';
		}
	}       
	var newwin = window.open();     
	newwin.document.write(s);
}




var W3CDOM = (document.createElement && document.getElementsByTagName);

var mouseOvers = new Array();
var mouseOuts = new Array();

function loadMouseOvers(container,modifier,className) {
	if (!W3CDOM) return;
	var nav = $(container);
	var imgs = nav.getElementsByTagName('img');
	for (var i=0;i<imgs.length;i++) {
		if (imgs[i].className == className) {
			if (imgs[i].style.cursor) {
				imgs[i].style.cursor = 'pointer';
			}
			var suffix = imgs[i].src.substring(imgs[i].src.lastIndexOf('.'));
			mouseOuts[i] = new Image();
			mouseOuts[i].src = imgs[i].src;
			mouseOvers[i] = new Image();
			mouseOvers[i].src = imgs[i].src.substring(0,imgs[i].src.lastIndexOf('.')) + modifier + suffix;
			imgs[i].number = i;
			imgs[i].onmouseover = mouseGoesOverImage;
			imgs[i].onmouseout = mouseGoesOutImage;
		}
	}
}

function mouseGoesOverImage() {
	try {
		if (mouseOvers && mouseOvers[this.number]) {
			if (this.src != mouseOvers[this.number].src) {
				this.src = mouseOvers[this.number].src;
			}
		}
	} catch (error) {
		// This is just for a weird problem with Firefox when the page unloads.
	}
}

function mouseGoesOutImage() {
	try {
		if (mouseOuts && mouseOuts[this.number]) {
			if (this.src != mouseOuts[this.number].src) {
				this.src = mouseOuts[this.number].src;
			}
		}
	} catch (error) {
		// This is just for a weird problem with Firefox when the page unloads.
	}
}