// <script>
var chN = {
	somethingChanged: false,
	msg: 'Die eingegebenen Daten wurden noch nicht gespeichert! Ohne Speichern fortfahren?',

	addEvent: function(elm, evType, fn, useCapture) {
		// cross-browser event handling for IE5+, NS6 and Mozilla
		// By Scott Andrew
		if (elm.addEventListener) {
			elm.addEventListener(evType, fn, useCapture);
			return true;
		} else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		} else {
			elm['on' + evType] = fn;
		}
	},

	init: function() {
		if (!document.getElementById) return;

		var inputs = document.getElementById('content').getElementsByTagName('input');
		for (var i = 0; i < inputs.length; i++){
			if (inputs[i].type == 'text') {
				chN.addEvent(inputs[i], 'change', chN.changeFound, false);
			}
		}
		var textareas = document.getElementById('content').getElementsByTagName('textarea');
		for (var i = 0; i < textareas.length; i++){
			chN.addEvent(textareas[i], 'change', chN.changeFound, false);
		}

		var pagelinks = document.getElementsByTagName('a');
		for (var i = 0; i < pagelinks.length; i++){
			chN.addEvent(pagelinks[i], 'click', chN.changeAlert, false);
		}
	},

	changeFound: function(e) {
		chN.somethingChanged = true;
	},

	changeAlert: function(e) {
		if (chN.somethingChanged && !confirm(chN.msg) ) {
			// default verhindern
			if (e && e.stopPropagation && e.preventDefault) {
				e.stopPropagation();
				e.preventDefault();
			}
			if (window.event) {
				window.event.cancelBubble = true;
				window.event.returnValue = false;
				return false;
			}
		}
	}
}

chN.addEvent(window, 'load', chN.init, false);