//
//
//

// browser detection stuff goes here
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var global_is_gecko = ((clientPC.indexOf('gecko')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('khtml') == -1) && (clientPC.indexOf('netscape/7.0')==-1));
var global_is_safari = ((clientPC.indexOf('AppleWebKit')!=-1) && (clientPC.indexOf('spoofer')==-1));
var global_is_khtml = (navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled ));
if (clientPC.indexOf('opera') != -1) {
    var global_is_opera = true;
    var global_is_opera_preseven = (window.opera && !document.childNodes);
    var global_is_opera_seven = (window.opera && document.childNodes);
}


// make sure global_path_prefix exists:
if (!global_path_prefix) {
	var global_path_prefix = "";
}

// make sure global_debug_mode exists:
if (!global_debug_mode) {
	var global_debug_mode = false;
}


// open a popup window
function popup(url, width, height, level) {
	// adjust the params
	if (url.charAt(0) != "/") url = global_path_prefix + url;
	if (!width) width = 600;
	if (!height) height = 400;
	if (!level) level = 1;
	var x = (screen.availWidth-width)/2;
	var y = (screen.availHeight-height)/2;

	// build the option string
	var opt = "width="+width+",height="+height+",left="+x+",top="+y+",dependent=yes,resizable=yes,scrollbars=yes,menubar=no,toolbar=no";
	if (global_debug_mode)
		opt += ",location=yes,status=yes";
	else
		opt += ",location=no,status=no";

	// open + focus the window
	new_window = window.open(url, "popup_"+level, opt);
	if (new_window) {
		new_window.focus();
	}
}


function jumpTo(url) {
	window.location.href = url;
}


function shiftChars(string) {
	var shifted = "";
	var min = 0x20;
	var max = 0x7F;
	var offset = -2;

	// encode:
	for (i = 0; i < string.length; i++) {
		k = string.charCodeAt(i);
		if ((min <= k) && (k <= max)) {
			k = ((k - min + offset) % (max-min)) + min;
		}
		shifted += String.fromCharCode(k);
	}

	return shifted;
}


function mailLink(user, mailbox, content, opts) {
	var m = "mai" + "lto:";
	var r = shiftChars(user) + '@' + shiftChars(mailbox);
	var l = (content)? shiftChars(content) : r;
	if (opts) opts = " " + opts;
	document.write('<a href="' + m + r + '"' + opts + '>' + l + '</a>');
}


// Search the DOM tree for an anchor and follow its href
function followFirst(object) {
	if (object) {
		var kids = object.childNodes;
		// check the child nodes:
		for (i = 0; i < kids.length; i++) {
			if (kids[i].nodeName == "A") {
				document.location.href = kids[i].href;
				return true;
			}
		}
		// recursion
		for (i = 0; i < kids.length; i++) {
			if (followFirst(kids[i])) return true;
		}
	}
	return false;
}


function followElement(element) {
	if (typeof element != "object") {
		element = document.getElementById(element);
	}
	if (element) {
		document.location.href = element.href;
	}
}

// EOF