function addEvent(obj, evType, fn){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent('on' + evType, fn);
		return r;
	} else {
		return false;
	}
}

/* text aus vorausgefüllten formularfeldern entfernen */
function removeDefaultValue(field) {
	if (!field.defaultValue) {
		field.defaultValue = field.value;
	}
	if(field.value == field.defaultValue) {
		field.value = '';
	}
}

function setDefaultValue(field) {
	if(field.value == '') {
		field.value = field.defaultValue;
	}
}

/* ein- und ausblenden der navgation */
function toggleMainNav(on) {
	var nav = document.getElementById('nav-main');
	nav.className = (on != 0 && (!nav.className || nav.className == '')) ? 'on' : '';
	return true;
}

function setHome(sel, url){
	sel.style.behavior = 'url(#default#homePage)';
	sel.setHomePage(url);
	return false;
}

function setBookmark(url, desc){
	if (window.external && (!document.createTextNode || "unknown" == typeof(window.external.AddFavorite))) {
		window.external.AddFavorite(url, desc);
	} else if (window.external && window.external.addPanel) {
		window.external.addPanel(desc, url, '');
	} else if (window.sidebar && window.sidebar.addPanel) {
		window.sidebar.addPanel(desc, url, '');
	}
}

function window_print() {
	window.print();
}

function hideHrefStatus() {
	if (document.getElementsByTagName) {
		var a = document.getElementsByTagName("A");
		for (var i in a) {
			if (!a[i].onmouseover) {
				a[i].onmouseover = hideWindowStatus;
			}
			if (!a[i].onmouseout) {
				a[i].onmouseout = showWindowStatus;
			}
		}
	}

	if (navigator.userAgent.indexOf('Netscape') != -1 && document.styleSheets[0].insertRule) {
		document.getElementById('main').style.overflow = "auto";
		document.styleSheets[0].insertRule(".newsbox { overflow:visible; clear:both }", document.styleSheets[0].cssRules.length);
	}
}

function hideWindowStatus() {
	window.self.status = ' ';
	return true;
}

function showWindowStatus() {
	window.self.status = '';
	return true;
}

function setWindowStatus(s) {
	window.self.status = s;
	return true;
}

function popup(purl, pwidth, pheight) {
	var ts 	= new Date();
	var ts 	= ts.getTime();
	if (!pwidth) { pwidth = 400; }
	if (!pheight) { pheight = 400; }
	window.open(purl,'networld-popup-' + ts,'width=' + pwidth + ',height=' + pheight + ',menubar=0,toolbar=0,location=0,status=0,resizable=0,scrollbars=0,copyhistory=0,directories=0').focus();
	return false;
}

function popit(l,n,w,h,p){
	pt=''; ap= new Array('menubar','resizable','toolbar','scrollbars','location','copyhistory','status','directories');
	for(i=0;i<ap.length;i++){ pt+= ','+ap[i]+'='+p.substr(i,1); }
	window.open(l,n,'width='+w+',height='+h+pt).focus();
	return false;
}

function get_current_style(el, prop) {
	var val, a;
	if (window.getComputedStyle) {
		val = window.getComputedStyle(el, "").getPropertyValue(prop);
	} else {
		var a = prop.split("-");
		prop = a[0];
		for (var i = 1; i < a.length; i++) {
			prop += a[i].substr(0, 1).toUpperCase() + a[i].substr(1);
		}
		if (el.currentStyle) {
			val = el.currentStyle[prop];
		} else if (document.all) {
			val = el.style[prop];
		}
	}
	if (val) {
		if ('rgb' == val.substr(0, 3)) {
			a = val.match(/\d+/g);
			val = "#";
			for (var i = 0; 3 > i; i++) {
				val += ('0' + '' + (a[i] - 0).toString(16)).replace(/^.*(..)$/, '$1');
			}
		}
		if ('#' == val.substr(0, 1)) {
			val = val.substr(1);
			if (3 == val.length) {
				val = val.substr(0, 1) + val.substr(0, 1) + val.substr(1, 1) + val.substr(1, 1) + val.substr(2, 1) + val.substr(2, 1);
			}
		}
	}
	return val;
}

function get_first_child_element(el) {
	if (el) {
		el = el.firstChild;
		while (el && 1 != el.nodeType) {
			el = get_next_sibling_element(el);
		}
	}
	return el;
}

function get_next_sibling_element(el) {
	if (el) {
		el = el.nextSibling;
		while (el && 1 != el.nodeType) {
			el = el.nextSibling;
		}
	}
	return el;
}

function get_sidebox() {
	var el = get_first_child_element(get_first_child_element(document.getElementById('content')));
	while (el && 'sidebox' != el.className.substr(0, 7)) {
		el = get_next_sibling_element(el);
	}
	return el;
}

function detectFlash(usedVers){
	var version = '';
	if (navigator.plugins && navigator.mimeTypes.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if (x && x.description) {
			version = x.description.replace(/[a-zA-Z\s]+/, "").split(".")[0];
		}
	} else if (window.ActiveXObject) {
		try {
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = axo.GetVariable("$version").split(" ")[1].split(",")[0];
		} catch (e) {}
	}
	return usedVers - 0 <= version - 0;
}

function displayFlash(o, val){
	var usedVers = o['codebase'].toString().split(',')[0];
	if (!detectFlash(usedVers)){
		if (undefined == val){
			val = '<div id="butFlash"><a href="http://www.macromedia.com/go/getflashplayer" target="_blank">Flash ' + usedVers + '-Plugin required. Klicken Sie hier, um das Plugin zu installieren.</a></div>';
		}
		document.write(val);
		return;
	}
	var i, n, cObj;

	cObj = new Object();
	cObj['param'] = '';
	cObj['embed'] = '<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" ';
	cObj['obj']	  = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';

	for (i in o){
		n = i.toLowerCase();
		switch (n){
			case 'movie':
			case 'name':
			break;

			case 'codebase':
			cObj.obj += n + '="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + o[i] + '" ';
			break;

			case 'src':
			cObj.embed += 'src="' + o[i] + '" ';
			cObj.param += '<param name="movie" value="' + o[i] + '" /> ';
			break;

			case 'width':
			case 'height':
			case 'align':
			case 'vspace':
			case 'hspace':
			case 'class':
			case 'title':
			case 'accesskey':
			case 'tabindex':
			cObj.embed += n + '="' + o[i] + '" ';
			cObj.obj += n + '="' + o[i] + '" ';
			break;

			case 'id':
			cObj.embed += 'name="' + o[i] + '" ';
			cObj.obj += 'id="' + o[i] + '" ';
			break;

			default:
			cObj.embed += n + '="' + o[i] + '" ';
			cObj.param += '<param name="' + n + '" value="' + o[i] + '" /> ';
		}
	}
	document.write(cObj.obj + '>' + cObj.param + cObj.embed + ' ></embed></object>');
}

function showhide_footer_element(elId, bShow) {
	var el = document.getElementById(elId);
	if (el) {
		var cn = " " + el.className + " ";
		var bShown = 0 > cn.indexOf(" hide ");
		bShow = "undefined" == typeof(bShow) ? !bShown : bShow != false;
		if (bShow != bShown) {
			cn = bShow ? cn .replace(/ hide /, "") : cn + "hide";
			el.className = cn.replace(/^ +| +$/, "");
			if (bShow && !el.posDone) {
				el.style.left = el.parentNode.offsetWidth - el.offsetWidth + 2 + "px";
				el.style.right = "auto";
				el.posDone = true;
			}
		}
	}
}

function nnw_flog_create_entry(obj){
	var oC, el, c;

	var c = document.createElement('div');
	c.className = 'nnw-flog-elem' + (obj['id'] == obj['parent'] ? '-root' : '');
	c.id = 'nnw-flog-id-' + obj['id'];

	var bGroup = 'undefined' != typeof(obj['vgngroup']) && 1 == obj['vgngroup'] ? true : false;
	var currClass = 'nnw-flog-elem-content';
	if (bGroup){
		currClass += ' nnw-flog-elem-vgngroup';
	}
	oC = { className:currClass };
	//oC = { className:'nnw-flog-elem-content' };
	nnw_flog_append_child('div', c, oC);
	oC = { className:'nnw-flog-action' };
	nnw_flog_append_child('div', c, oC);
	oC = { className:'nnw-flog-elem-interact' };
	nnw_flog_append_child('div', c, oC);
	oC = { className:'nnw-flog-elem-reply' };
	nnw_flog_append_child('div', c, oC);

	oC = { className:'nnw-flog-user', innerHTML:unescape(obj['user'] + ', ' + obj['date']) };
	nnw_flog_append_child('div', c.firstChild, oC);
	oC = { id:('nnw-flog-title-' + obj['id']), className:'nnw-flog-title', innerHTML:unescape(obj['title']) };
	nnw_flog_append_child('div', c.firstChild, oC);
	oC = { className:'nnw-flog-text', innerHTML:unescape(obj['text']) };
	nnw_flog_append_child('div', c.firstChild, oC);

	if (!bGroup){
		oC = { className:'nnw-flog-alert', onclick:nnw_flog_alert_init, innerHTML:'melden' };
		nnw_flog_append_child('a', c.childNodes[1], oC);
	}

	var p = obj['id'] == obj['parent'] ? 0 : obj['parent'];

	if (!p){
		oC = { className:'nnw-flog-reply', onclick:nnw_flog_reply_init, innerHTML:'antworten' };
		nnw_flog_append_child('a', c.childNodes[1], oC);
	}

	if (el = document.getElementById('nnw-flog-id-' + p)){
		if (!el.lastChild.hasChildNodes() || obj['append']){
			el.lastChild.appendChild(c);
		}else{
			el.lastChild.insertBefore(c, el.lastChild.firstChild);
		}
		el.lastChild.style.display = 'block';
		nnwFlogShowEntries++;
		return true;
	}
	return false;
}
function nnw_flog_find_parent(o){
	while (o){
		if (o.id && 0 == o.id.search(/^nnw-flog-id-/)){
			return o;
		}
		o = o.parentNode;
	}
	return false;
}
function nnw_flog_append_child(t, p, oC){
	var i, c;
	c = document.createElement(t);
	if (oC){
		for (i in oC){
			c[i] = oC[i];
		}
	}
	return p.appendChild(c);
}
function nnw_flog_comment(){
	if ('undefined' != typeof(nnwFlogStoryID)){
		var p;
		if (p = document.getElementById('nnw-flog-id-0')){
			nnw_flog_reply_build(p, 'write');
		}
	}
	//return false;
}
function nnw_flog_reply_init(){
	nnw_flog_reply(this);
}
function nnw_flog_reply(sel){
	var p = nnw_flog_find_parent(sel);
	if (p){
		nnw_flog_reply_build(p, 'write');
	}
}
function nnw_flog_reply_build(p, topic){
	var el, tel;
	var id = p.id.replace(/\D/g, '');
	var str = '<iframe id="nnw-flog-interact" name="nnw-flog-interact" width="100%" height="100%" frameborder="0" border="0" marginwidth="0" marginheight="0" allowtransparency="true" scrolling="no"></iframe>';

	nnw_flog_close();

	for (var i = p.childNodes.length - 1; i >= 0; i--){
		if ('nnw-flog-elem-interact' == p.childNodes[i].className){
			p.childNodes[i].innerHTML = str;
			if (el = document.getElementById('nnw-flog-interact')){
				var src = '/nw1/dyn/flogs/index.php?s=' + topic + '&id=' + nnwFlogStoryID + '&p=' + id + '&url=' + encodeURIComponent(location.href);
				if (id && (tel = document.getElementById('nnw-flog-title-' + id))){
					src += '&t=' + escape(tel.firstChild.data);
				}
				el.src = src;
			}
			p.childNodes[i].style.display = 'block';
			break;
		}
	}
}
function nnw_flog_alert_init(){
	nnw_flog_alert(this);
}
function nnw_flog_alert(sel){
	var p = nnw_flog_find_parent(sel);
	if (p){
		nnw_flog_reply_build(p, 'alert');
	}
}
function nnw_flog_close(){
	var el;
	if (el = document.getElementById('nnw-flog-interact')){
		el.parentNode.style.display = 'none';
		el.parentNode.removeChild(el);
	}
}
function nnw_flog_expand(){
	var i, j, httpRequest;
	if (httpRequest = nnw_flog_http_request_init()){
		httpRequest.onreadystatechange = function(){
			if (4 == httpRequest.readyState && 200 == httpRequest.status){
				var xmlDoc = httpRequest.responseXML;
				var oNode;
				if (!xmlDoc.hasChildNodes() || 'nnwflog' != xmlDoc.lastChild.nodeName){
					alert('Sorry, Initialisierung ist fehlgeschlagen - versuchen Sie es bitte nochmals.');
					return;
				}else{
					var oNode = nnw_flog_xml_array_to_object(xmlDoc.lastChild.attributes);
					if ('undefined' != typeof(oNode['error'])){
						alert(unescape(oNode['error']));
						return;
					}
					if (xmlDoc.lastChild.hasChildNodes()){
						var n = xmlDoc.lastChild.childNodes.length;
						for (i = 0; i < n; i++){
							if (1 == xmlDoc.lastChild.childNodes[i].nodeType){
								if (oNode = nnw_flog_xml_array_to_object(xmlDoc.lastChild.childNodes[i].attributes)){
									oNode['text'] = xmlDoc.lastChild.childNodes[i].firstChild.nodeValue;
									if (nnw_flog_create_entry(oNode)){
										nnwFlogLastID = oNode['id'];
										nnwFlogLastParent = oNode['parent'];
									}
								}
							}
						}
						nnw_flog_set_navi();
					}
				}
			}
		}
		var src = '/nw1/dyn/flogs/expand.php?id=' + nnwFlogStoryID + '&all=' + (-1 == this.className.search(/more$/) ? 1 : 0);
		if ('undefined' != typeof(nnwFlogLastID)){
			src += '&last=' + nnwFlogLastID + '&p=' + nnwFlogLastParent;
		}
		httpRequest.open('GET', src, true);
		httpRequest.send(null);
	}
}
function nnw_flog_set_navi(){
	var el, oC, str;
	if ('undefined' == typeof(nnwFlogEntries)){
		return false;
	}
	var aChilds = ['upper', 'lower'];
	for (var i in aChilds){
		if (el = document.getElementById('nnw-flog-navi-' + aChilds[i])){
			if (el.firstChild){
				el.removeChild(el.firstChild);
			}
			nnw_flog_append_child('div', el);
			if (0 < nnwFlogEntries){
				oC = { className:'fL', innerHTML:(nnwFlogShowEntries + ' von ' + nnwFlogEntries + ' Kommentaren') };
				nnw_flog_append_child('span', el.firstChild, oC);
			}
			if (nnwFlogFirstPage < nnwFlogEntries){
				oC = { onclick:nnw_flog_expand, className:'fR nnw-flog-more', innerHTML:'&#187;&nbsp;mehr anzeigen' };
				nnw_flog_append_child('a', el.firstChild, oC);
				oC = { onclick:nnw_flog_expand, className:'fR nnw-flog-all', innerHTML:'&#187;&nbsp;alle anzeigen' };
				nnw_flog_append_child('a', el.firstChild, oC);
			}
			el.style.display = 0 < nnwFlogEntries ? 'block' : 'none';
		}
	}
}
function nnw_flog_http_request_init(){
	var httpRequest;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
	    httpRequest = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
	    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (httpRequest && httpRequest.overrideMimeType){
		httpRequest.overrideMimeType('text/xml');
	}
	return httpRequest;
}
function nnw_flog_http_get_node(xmlDoc, node){
	for (var i = xmlDoc.childNodes.length - 1; i >= 0; i--){
		if (1 == xmlDoc.childNodes[i].nodeType && node == xmlDoc.childNodes[i].nodeName){
			return nnw_flog_xml_array_to_object(xmlDoc.childNodes[i].attributes);
		}
	}
	return false;
}
function nnw_flog_xml_array_to_object(a){
	var oNode = {};
	for (var i = a.length - 1; i >= 0; i--){
		oNode[a[i].name] = a[i].value;
	}
	return oNode;
}
function nnw_flog_init(){
	var el;
	if (el = document.getElementById('aabox')){
		var oC = { id:'aa-flog', innerHTML:'<a href="#nnwflogroot" onClick="nnw_flog_comment();">Artikel&nbsp;kommentieren</a>' };
		nnw_flog_append_child('li', el, oC);
	}
	if (el = document.getElementById('nnw-flog-id-0')){
		if (0 < el.lastChild.childNodes.length){
			el.lastChild.style.display = 'block';
		}
	}
}
function nnw_set_current_channel(){
	if (-1 != document.body.className.search(/ch\-([0-9]+)/)){
		var el = document.getElementById('nnw-sbn-' + RegExp.$1);
		if (el){
			el.className = ('' == el.className ? '' : el.className + ' ') + 'hilite';
		}
	}
}
