// written by Dean Edwards, 2005
// with input from Tino Zijdel, Matthias Miller, Diego Perini

// http://dean.edwards.name/weblog/2005/10/add-event/

function addEvent(element, type, handler) {
	if (element.addEventListener) {
		element.addEventListener(type, handler, false);
	} else {
		// assign each event handler a unique ID
		if (!handler.$$guid) handler.$$guid = addEvent.guid++;
		// create a hash table of event types for the element
		if (!element.events) element.events = {};
		// create a hash table of event handlers for each element/event pair
		var handlers = element.events[type];
		if (!handlers) {
			handlers = element.events[type] = {};
			// store the existing event handler (if there is one)
			if (element["on" + type]) {
				handlers[0] = element["on" + type];
			}
		}
		// store the event handler in the hash table
		handlers[handler.$$guid] = handler;
		// assign a global event handler to do all the work
		element["on" + type] = handleEvent;
	}
};
// a counter used to create unique IDs
addEvent.guid = 1;

function removeEvent(element, type, handler) {
	if (element.removeEventListener) {
		element.removeEventListener(type, handler, false);
	} else {
		// delete the event handler from the hash table
		if (element.events && element.events[type]) {
			delete element.events[type][handler.$$guid];
		}
	}
};

function handleEvent(event) {
	var returnValue = true;
	// grab the event object (IE uses a global event object)
	event = event || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
	// get a reference to the hash table of event handlers
	var handlers = this.events[event.type];
	// execute each event handler
	for (var i in handlers) {
		this.$$handleEvent = handlers[i];
		if (this.$$handleEvent(event) === false) {
			returnValue = false;
		}
	}
	return returnValue;
};

function fixEvent(event) {
	// add W3C standard event methods
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
};
fixEvent.preventDefault = function() {
	this.returnValue = false;
};
fixEvent.stopPropagation = function() {
	this.cancelBubble = true;
};
/* 
 * ie-note.js -- alerts users of IE about lack of standards-compliance
 *
 * to use, source this script from the HTML file:
 *
 *   <script type="text/javascript" src="js/ie-note.js"></script>
 *
 * Note that you need an event handler, such as
 *   http://dean.edwards.name/weblog/2005/10/add-event/
 * or insure otherwise that insertNote() is called *after* the whole page has
 * been rendered and the DOM initialised.
 *
 * The notice can be styled with CSS, using the ie-note class name.
 *
 * SVN url: http://svn.madduck.net/pub/web/martin-krafft.net/js/ie-note.js
 *
 * Copyright © martin f. krafft <madduck@madduck.net>
 * Released under the terms of the Artistic Licence 2.0
 *
 * Revision: $Id: dchangesfilename 295 2006-10-07 11:20:26Z madduck $
 */

function isIE()
{
  return navigator.appName.indexOf('Internet Explorer') > 0 ||
    navigator.appName.indexOf('MSIE') > 0;
}

function insertNote()
{
  var query = unescape(location.search);
  if (isIE() || query.indexOf('ie-note') > 0) {
    var container = document.createElement("p");
    container.className = 'ie-note';
    container.innerHTML =
    '<strong>Notice:</strong> you are using Microsoft\'s Internet Explorer, '
    + 'which does not properly support the <a '
    + 'href="http://www.w3.org/MarkUp">XHTML</a> and <a '
    + 'href="http://www.w3.org/Style/CSS">CSS</a> standards used in writing '
    + 'this page the way it is supposed to look. The information is still '
    + 'all there, but for a better result, please consider alternative ' 
    + 'browsers, such as <a href="http://www.mozilla.org/products/firefox">'
    + 'Mozilla Firefox</a>.';
    var body = document.getElementsByTagName("body")[0];
    body.insertBefore(container, body.firstChild);
  }
}

// see http://dean.edwards.name/weblog/2005/10/add-event/
addEvent(window, 'DOMContentLoaded', insertNote);

