function displayError(message, url, lineno){
	alert("JavaScript error detected!\n\nError: " + message + "\nLine: " + lineno + "\nURL: " + url + "\nBrowser: " + navigator.userAgent);
	return false;
}
window.onerror = displayError;

function init() {
	// warn people about their very old browsers
	if (is.IEapp && is.version < 5.5 || (is.NSapp && is.version < 5))
		idOpen("browserwarn");
	if (typeof(local_init) == "function")
		local_init();
	//showheadings();
}
window.onload = init;

function detectBrowser(){
	this.IE=0;
	this.NS=0;
	this.NSapp=(navigator.appName=="Netscape") ? 1 : 0;
	this.IEapp=(navigator.appName=="Microsoft Internet Explorer") ? 1 : 0;
	this.appver=navigator.appVersion;
	if(this.IEapp)
		this.IE=(typeof(document.all)=="object") ? 1 : 0;
	else if(this.NSapp)
		this.NS=(typeof(document.layers)=="object") ? 1 : 0;
	if(this.NSapp)
		this.version=parseFloat(this.appver);
	else
		this.version=parseFloat(this.appver.substr(this.appver.indexOf("MSIE") + 5, 3));
}
var is=new detectBrowser();

function idGet(id) {
	if (typeof(document.getElementById) != "undefined") {
		return document.getElementById(id);
	} else {
		return document.all[id];
	}
}

function idOpen(id) {
	var x = idGet(id);
	if (!x)
		return;
	if (x.style.display == '' || x.style.display == 'none')
		x.style.display = 'block';
	else
		x.style.display = 'none';
}

function obj(o,ot) {
	if (ot) {
		if (typeof(o) == t) {
			return 1;
		} else {
			return 0;
		}
	} else {
		if (typeof(o) != "undefined") {
			return 1;
		} else {
			return 0;
		}
	}
}

function addSidebar(n, u, c) {
	if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) {
		try {
			window.sidebar.addPanel(n, u, c);
		} catch(e) {
			alert("Unable to add sidebar. Make sure that sidebars are active (via View -> Show/Hide -> Sidebar or press F9.");
			if (u == "http://gemal.dk/sidebar.html") {
				document.location = "http://gemal.dk/archives/000122.html";
			} else {
				document.location = "http://gemal.dk/archives/000228.html";
			}
		}
	} else {
		alert("Sidebars are only available to Gecko based browsers such as Mozilla and Netscape 6/7.");
		if (u == "http://gemal.dk/sidebar.html") {
			document.location = "http://gemal.dk/archives/000122.html";
		} else {
			document.location = "http://gemal.dk/archives/000228.html";
		}
	}
}

function testXPIinstall() {
	if (typeof(navigator.product) != "undefined" && navigator.product) {
		if (!InstallTrigger.updateEnabled())
			document.writeln('<div class="warning">You do not have Software Installation enabled! Go to <span class="content-code">Edit -&gt; Preferences -&gt; Advanced -&gt; Software installation</span> and enable it.</div>');
	} else {
		document.writeln('<div class="warning">You do not seem to be running a Gecko based browser. Linky only works in Gecko based browsers!</div>');
	}
}

function showheadings() {
	var h;
	// Support both Gecko and IE
	try {
		h = document.getElementsByTagNameNS("*", "h2");
	} catch(err) {
		h = document.getElementsByTagName("h2");
	}
	// if there are some headings
	if (h.length) {
		idOpen("nav-headings");
		var headings = idGet("nav-headings");
		for (var i = 0; i < h.length; i++) {
			// get the text of the heading and insert it
			var txt;
			if (h[i].childNodes[0]) {
				if (h[i].childNodes[0].nodeValue)
					txt = h[i].childNodes[0].nodeValue;
				else
					txt = h[i].childNodes[0].childNodes[0].nodeValue;
				if (txt) {
					var txts = txt;
					if (txt.length > 25) {
						txts = txt.substring(0,25);
						txts += "...";
					}
					headings.innerHTML += "<div><a href=\"#" + i + "\" title=\"" + txt + "\">" + txts + "</a></div>";
				}
			}

			// now create a href ala <a name="1"></a>
			var hl = document.createElement("A");
			hl.setAttribute("name", i);
			h.item(i).insertBefore(hl, null);
		}
	}
}
