
var offline_mode = false;
var naviTimer;

function naviFadeIn(element) {
		naviTimer = setTimeout(function () {
			var fromLeft = $j(element).position().left - 1;
			var fromTop  = $j(element).position().top + 19;
			$j(element).find('a:first').addClass('active').parent().find('ul:first').css({'left' : fromLeft, 'top' : fromTop}).fadeIn('fast');
		}, 200);
}

addLoadEvent(function () {
		$j('input.submit').bind("focus", function () { if (this.blur) this.blur(); });
		styleTooltips();
		styleCheckboxes();
});

function styleCheckboxes() {
		$j('input:radio, input:checkbox').checkbox();
}

function styleTooltips() {
        $j("input.help[title!=''], a.help[title!=''], img.help[title!='']").tooltip({
			    track: true,
			    delay: 0,
			    showURL: false,
			    fade: 100
		});
}

function removeMe() {
		$j(this).remove();
}

function shortenText(text, chars) {
        return (text.length > chars) ? text.substring(0, chars-3) + '...' : text;
}

function initNavi() {
		$j('#mainnavi ul.sub').each(function () {
				$j(this).parent().hover(function () {
						naviFadeIn(this);
				}, function () {
						clearTimeout(naviTimer);
						$j(this).find('a:first').removeClass('active').parent().find('ul:first').fadeOut('fast');
				});
		});

		$j('#mainnavi ul.subsub').each(function () {
				$j(this).parent().hover(function () {
						// only IE!
						if ($j.browser.msie) {
							$j(this).css('marginBottom', '-3px');
						}
						var fromLeft = parseInt($j(this).css('width')) + 1;
						var fromTop  = $j(this).position().top - 1;
						$j(this).find('ul:first').css({'left' : fromLeft, 'top' : fromTop}).show();
				}, function () {
						$j(this).css('marginBottom', '0px').find('ul:first').hide();
				});
		});

		$j('#mainnavi a.thread').each(function () {
				// only IE!
				if ($j.browser.msie) {
					$j(this).parent().css('marginBottom', '-3px');
				}
				$j(this).parent().hover(function () {
						$j(this).css('background', '#e5e5e5').find('img:first').addClass('navi-new-thread');
				}, function () {
						$j(this).css('background', '#fff').find('img:first').removeClass('navi-new-thread');
				})
		});
}

// ==== Globale Funktionen =====================================================

function globalFade(e,f,t,d){
	//if ($E(e)) {
			var myEff=new Fx.Style(e,'opacity',{duration:d});
			myEff.custom(f,t);
	//}
	//jQuery(e).animate({opacity: t}, d);
}
function globalFadeOut(e){
	globalFade(e,1,.6,300);
}
function globalFadeIn(e){
	globalFade(e,.6,1,300);
}
function globalFadeOff(e){
	globalFade(e,1,0,300);
}
function globalFadeOn(e){
	globalFade(e,0,1,300);
}
function globalIncrease(e,f,t, d){
	if (typeof d === 'undefined') {
			d = 500;
	}
	//var myEff = new Fx.Style(e, 'height',{duration:500});
	//myEff.custom(f,t);
	$j('#' + e).animate({height: t}, d);
}
function globalSet(e,p,v){
	new Fx.Style(e, p).set(v)
}
function $S(e){
	return $(e).style;
}
function $E(e){
	return document.getElementById(e);
}
function $I(e){
	return $(e).innerHTML;
}
function gT(e, t) {
	return (typeof e === 'object') ? e.getElementsByTagName(t) : document.getElementsByTagName(t);
}
function cE(t){
	return document.createElement(t);
}
function isError(t){
	return (t.substring(0,5)=='error') ? true : false;
}
function printError(t){
	alert(t.substring(6));
	return false;
}
function $sI(element) {
	return $(element).options[$(element).selectedIndex].value
}
function _f(file){
	return rootdir + '/ajax/' + file + '/';
}
function _a(file){
	return gotoincludes + '/admin/ajax.'+file+'.php';
}
function setCookie(n,v,d){
	var now = new Date();
	if(d==0){
		var exp='';
	}else{
		var exp = new Date(now.getTime() + (1000 * 60 * 60 * 24 * d));
		exp = ' expires='+exp.toGMTString()+';';
	}
	document.cookie = n+'='+v+'; path=/;'+exp;
	return false;
}
function getCookie(n)
{
	if(document.cookie.length>0){
		var c_start=document.cookie.indexOf(n + "=");
		if(c_start!=-1){
			c_start=c_start+n.length+1;
			var c_end=document.cookie.indexOf(";",c_start);
			if(c_end==-1){
				c_end=document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}
function disableButton(button){
		if ($E(button)) {
				$(button).disabled='true';
				$(button).blur();
				globalFade(button,1,.4,100);
		}
}
function enableButton(button){
	globalFade(button,.4,1,100);
	$(button).disabled='';
}
function waitButton(button)
{
	if($E('okMess') && $S('okMess').display!='none')
	{
		$('okMess').innerHTML='';
		Element.hide('okMess');
	}
	if ($E(button)) {
		disableButton(button);
		$(button).value = 'Bitte warten...';
	}
}
function saveButton(button, message, error, value)
{
	if(message != '') {
		setMessage(message, error, button, '');
	}
	enableButton(button);
	$(button).value = (typeof value == 'undefined') ? 'Speichern' : value;
}
function setMessage(mess, isError, button, loadDiv)
{
	Element.scrollTo('content');
	$('okMess').innerHTML = (isError === true) ? '<span style="color:#f00;">'+mess+'</span>' : mess;

	if($S('okMess').display == 'none')
	{
		globalSet('okMess', 'opacity', 0);
		Element.show('okMess');
	}

	globalFadeOn('okMess');

	if(isError === false)
	{
		setTimeout(function() {
			globalFadeOff('okMess');
			setTimeout(function() {
				Element.hide('okMess');
			}, 500);
		}, 2000);
	}

	if($E(button)) {
		enableButton(button);
	}

	if($E(loadDiv)) {
		Element.hide(loadDiv);
		$(loadDiv).innerHTML = '';
	}
}

function dotti(e){
	if(i<5){
		if(e.innerHTML=='&nbsp;'){
			e.innerHTML='';
		}
		e.innerHTML+='&#8226;';
		i++;
	}
	else{
		e.innerHTML='&#8226;';i=1;
	}
	return false;
}
function getNumberedFields(fid)
{
	var l=fid.length;
	var f=$$('input');
	var a=new Array();
	for(var i=0;i<f.length;i++)
	{
		f[i].value=trim(f[i].value);
		if(f[i].id.substr(0,l)==fid)
		{
			a.push(f[i].value);
		}
	}
	return a;
}

// =============================================================================

// ==== Globale Variablen ======================================================


var i=0, lastbmlist='', bmloader, shownDiv='';

var show_related = false;
var cookie_sidebar = getCookie('sidebar');

if(cookie_sidebar!=''){
	var cookie_obj=cookie_sidebar.parseQuery();
	if(typeof cookie_obj.rl!='undefined'&&cookie_obj.rl==1){
		show_related=true;
	}
}

// =============================================================================

function togglePageFlip(bAjax, oClickedElement) {
		var parent = oClickedElement.parentNode;
		var position = parent.id.split('_').pop();

		if (!$E('pageflip-' + position)) {

				var form = cE('form');
				form.action = '';
				form.method = 'post';
				form.onsubmit = function () {
						submitPageFlip(bAjax, position);
						return false;
				};

				var input = cE('input');
				input.className = 'searchfield';
				input.id = 'page-input-' + position;
				input.type = 'text';
				form.appendChild(input);

				var newFlip = cE('div');
				newFlip.className = 'pageflip';
				newFlip.id = 'pageflip-' + position;
				newFlip.appendChild(form);
				newFlip.style.visibility = 'hidden';
				parent.parentNode.appendChild(newFlip);
		}

		$('page-input-' + position).observe('keyup', function (event) {
				if (event.keyCode == 27) {
						this.value = '';
						this.blur();
						globalFadeOff('pageflip-' + position);
				}
		});

		if ($S('pageflip-' + position).visibility == 'hidden') {
				globalFadeOn('pageflip-' + position);
				setTimeout(function () { $('page-input-' + position).focus() }, 500);
		}
		else {
				$('page-input-' + position).value = '';
				$('page-input-' + position).blur();
				globalFadeOff('pageflip-' + position);
		}

		return false;
}

function submitPageFlip(bAjax, position) {
		var newPage = parseInt($('page-input-' + position).value);
		newPage = isNaN(newPage) || newPage == 0 ? 1 : newPage;
		if (bAjax === true) {
				switchRecent(newPage);
				window.location.hash = '#' + newPage;
				$('page-input-' + position).value = '';
				$('page-input-' + position).blur();
				globalFadeOff('pageflip-' + position);
		}
		else {
				new Ajax.Request(_f('pageflip'), {
						method : 'post',
						parameters : { url : location.href,
									   page : newPage },
						onSuccess : function (x) {
								if (x.responseText != 'none') {
										location.href = x.responseText;
								}
						}
				});
		}

		return false;
}

function CheckNewMsg()
{
	new Ajax.Request(_f('pm'),{
			method:'post',
			parameters:'d='+lastTime,
			onSuccess:function(xh)
			{
				var t=xh.responseText;
				if(isError(t)) {
					printError(t);
				}
				else
				{
					if($E('pmlist'))
					{

					}
					else
					{
						if($E('globalAnnounce'))
						{
							var p = cE('div');
							p.innerHTML = t;
							$E('globalAnnounce').appendChild(p);
						}
						else
						{
							t = '<div class="divclose"><a class="ignore" href="#" onclick="closeAnnounce();return false;">&nbsp;&nbsp;&nbsp;</a></div>' + t;
							var b = getElementsByClassName($('rahmen'), 'div', 'threadnaviheader');
							new Insertion.After(b[0], '<div class="alert">' + t + '</div>');
						}
					}
				}
			}
		});
}

function setCalendar(thedate, mode, inputID, prevLink, nextLink, titleID, calID) {

		inputID 	= typeof(inputID) !== 'undefined' ? inputID : '';
		prevLink 	= typeof(prevLink) !== 'undefined' ? prevLink : 'calPrev';
		nextLink 	= typeof(nextLink) !== 'undefined' ? nextLink : 'calNext';
		titleID 	= typeof(titleID) !== 'undefined' ? titleID : 'caltitle';
		calID 		= typeof(calID) !== 'undefined' ? calID : 'calTable';

		new Ajax.Request(_f('calendar'),{
			method: 'post',
			parameters: 'date=' + thedate + '&m=' + mode + '&input=' + inputID,
			onSuccess: function(xh){
				var resp = xh.responseText;
				if(resp == 'error') {
					alert(_("An error occurred."));
				}
				else {
					eval('var data = ' + resp);
					data = data.shift();

					$(prevLink).onclick = function () {
							setCalendar(data.prevmonthid, mode, inputID, prevLink, nextLink, titleID, calID);
							return false;
					}
					$(nextLink).onclick = function () {
							setCalendar(data.nextmonthid, mode, inputID, prevLink, nextLink, titleID, calID);
							return false;
					}

					$(titleID).innerHTML = data.currmonth;
					$(calID).innerHTML = data.calendar;
				}
			}
		});
		return false;
}

function storeDate(sDate, sInput, oLink) {
		if (!$E(sInput)) {
				return false;
		}
		$(sInput).value = sDate;

		/*
		$$('.calTODAY').each = function (e) {
				e.removeClassName('calTODAY');
				//e.removeClassName('calUNDER');
		}

		//oLink.addClassName('calUNDER');
		oLink.parentNode.addClassName('calTODAY');
		*/
		return false;
}

function toggleDiv(newDiv){
	if (!$E(newDiv)) {
			return false;
	}
	if(shownDiv==newDiv||$S(newDiv).display!='none'){return false;}
	if($E('okMess')){if($S('okMess').display!='none'){Element.hide('okMess');}}
	Element.hide(shownDiv);
	Element.show(newDiv);
	shownDiv=newDiv;
	return false;
}
function closeAnnounce(){
	if($E('globalAnnounce') && $S('globalAnnounce').display!='none')
	{
		new Ajax.Request(_f('announce'),{
			method:'post',
			parameters:'m=close',
			onSuccess:function(xh){
				var t=xh.responseText;
				if(isError(t)){
					printError(t);
				}
				else{
					globalFadeOff('globalAnnounce');
					setTimeout("Element.remove('globalAnnounce')",500);
				}
			}
		});
	}
	return false;
}
function removeAnnounce(e){
	Element.remove(e);
	if($('globalAnnounce').getElementsByTagName('li').length==0){
		closeAnnounce();
	}
}
function delAnnounceElement(id)
{
	new Ajax.Request(_f('announce'),{
			method:'post',
			parameters:'m=del&i='+id,
			onSuccess:function(xh)
			{
				var t=xh.responseText;
				if(isError(t)){
					printError(t);
				}
				else{
					if($('globalAnnounce').getElementsByTagName('li').length==1)
					{
						globalFadeOff('globalAnnounce');
						setTimeout(function(){Element.remove('globalAnnounce');},500);
					}
					else
					{
						globalFadeOff('msg'+id);
						setTimeout(function(){removeAnnounce('msg'+id);},500);
					}
				}
			}
		});
}
function Msg(mode, id, imgelem)
{
	if(mode != 'del' && mode != 'fw') {
		return false;
	}
	imgelem.id='img'+id;
	globalFadeOff('img'+id);
	setTimeout(function(){Element.remove('img'+id);},500);
	new Ajax.Request(_f('msg'),
	{
		method:'post',
		parameters:'m='+mode+'&i='+id,
		onSuccess:function(xh){
			var t=xh.responseText;
			if(isError(t)) {
				printError(t);
			}
			else
			{
				if(mode == 'del')
				{
					// nur noch ein Element (das soeben geloeschte)
					if($('globalAnnounce').getElementsByTagName('li').length==1)
					{
						// Div ausblenden
						globalFadeOff('globalAnnounce');
						setTimeout(function(){Element.remove('globalAnnounce');},500);
					}
					else
					{
						// Element ausblenden
						globalFadeOff('msg'+id);
						setTimeout(function(){Element.remove('msg'+id);},500);
					}
				}
			}
		}
	});
	return false;
}
function doContact(c, m)
{
	var e = 'contact'+c;
	new Ajax.Request(_f("profile"),{
		method:'post',
		parameters:'type=contact&id='+c+'&mode='+m,
		onSuccess:
			function(xh){
				var r=xh.responseText;
				if(isError(r)){
					printError(r);
				}
				else{
					globalFadeOff(e);
					setTimeout("removeAnnounce('"+e+"')",500);
				}
			}
	});
	return false;
}
function togglePlusMinus(elem, div) {

	$(div).toggle();

	var icon = $(elem).firstChild.src;

	var cookie_key=div.replace(/div/,"");
	var cookie_value=(icon.indexOf('plus')!=-1)?1:0;

	if(div=='divrl'&&cookie_value==1&&show_related===false){
		searchRelatedTopics();
	}

	if(cookie_value==1) {
		if(div=='divposttags'){$('new_topic_tags').focus();}
		$(elem).innerHTML = symbol_minus;
	}
	else {
		if(div=='divposttags'){$('new_topic_tags').blur();}
		$(elem).innerHTML = symbol_plus;
	}

	if(div=='divcalendar'){
		var old=$('caltitle').innerHTML;
		$('caltitle').innerHTML=oldcalmonth;
		oldcalmonth=old;
	}

	var oldvalue=getCookie('sidebar');
	if(oldvalue==''){
		var newvalue=cookie_key+'='+cookie_value;
	}else{
		var obj=oldvalue.parseQuery();
		eval('obj.'+cookie_key+'='+cookie_value);
		var newvalue=$H(obj).toQueryString();
	}
	setCookie('sidebar',newvalue,10950);
}
function showHideOptions(shownone){
	if(typeof shownone=='undefined'){shownone=true;}
	var link1=false,link2=false;
	if ($E('markreadlink')) {
			if(getUnread().length>0){Element.show('markreadlink');}
	}
	if($E('markreadlink')){if(Element.visible('markreadlink')){link2=true;}}
	if($E('nooptions')){
		if(link2===false){Element.show('nooptions');}
		else{Element.hide('nooptions');}
	}
}
function changeVis(elemId,modus){
	if($E(elemId)){
		if(modus=='over'){
			$S(elemId).visibility='visible';
		}
		else{
			$S(elemId).visibility='hidden';
		}
	}
}
function setRead(element,bookmark)
{
	if(typeof bookmark=='undefined'){bookmark=false;}
	var e=$(element);

	if(bookmark===false){
		var tid=e.id.substring(2);
		$j(e).addClass('threadREAD');

		if($E('markreadlink')){
		if(getUnread().length>0){Element.show('markreadlink');showHideOptions();}
		else{Element.hide('markreadlink');showHideOptions();}
		}
		if($E('bm'+tid) && $('bm'+tid).parentNode.id=='UnreadBookmarks'){
			Element.remove('bm'+tid);
			lastbmlist='';
		}
	}
	else{
		var tid=element.substring(2);
		new Ajax.Request(_f("markread"),{method:'post',
			parameters:'ids='+tid,
			onSuccess:function(xh){
				Element.remove(element);
				if($('bmplusminus').innerHTML=='&nbsp;'){
					$('bmplusminus').innerHTML='<a href="#" onclick="return showBookmarks();" title="'+_('Show list')+'">'+symbol_plus+'</a>';
				}
				lastbmlist='';
			}
		}
		);
	}
	return false;
}
function remBookmark(element)
{
	if(element.indexOf('post')!=-1){
		var pid=element.substring(6);
		var para='pid='+pid;
		//if(document.getElementById('pbm'+pid)){}
	}
	else{
		var tid=element.substring(2);
		var para='tid='+tid;
	}
	globalFadeOut(element);

	new Ajax.Request(_f("deletebookmark"),{
		method:'post',
		parameters:para,
		onSuccess:function(xh){
			if(xh.responseText!='OK'){
				alert(_(xh.responseText));
				globalFadeIn(element);
			}
			else{
				Element.remove(element);
				lastbmlist='';
				if($('bmdivt').nextSibling.id=='bmdivp'){
					Element.remove($('bmdivt'));
				}
				if($('bmdivp').nextSibling==null){
					Element.remove($('bmdivp'));
				}
			}
		}
	});

	return false;
}

/**
 * Als gelesen markieren
 */

function getUnread() {
		return $$('#itemsdiv a.threadNEW');
}

function allRead() {

		var unreadElements = getUnread();
		var ids = new Array();
		unreadElements.each(function (elem) {
				ids.push(elem.id.substring(2));
		});

		var idstring = ids.join('|');
		if (idstring.length > 0) {

				new Ajax.Request(_f("markread"), {
						method: 'post',
						parameters: 'ids=' + idstring,
						onSuccess: function (xh) {

								if (isError(xh.responseText)) {
										printError(xh.responseText);
								}
								else {
										unreadElements.each(function (elem) {
												elem.className = 'threadREAD';
										});

										Element.hide('markreadlink');
										showHideOptions();
								}
						}
				});
		}

		if ($E('UnreadBookmarks') && $('UnreadBookmarks').childElements() && typeof(isMain) !== 'undefined') {
				$$('#UnreadBookmarks ul li').each(function (elem) {
						setRead(elem.id, true);
				});
		}

		return false;
}


function showBookmarks() {
		var what = ($('bmplusminus').firstChild.firstChild.src == imgdir+'/plus1.gif') ? 'show' : 'hide';
		if (what=='show') {
				if (lastbmlist=='') {
						$('ExtendedBookmarks').className='loading';
						bmloader=setInterval("dotti($('ExtendedBookmarks'))",100);
						new Ajax.Request(_f("extendbookmarks"),{
								method: 'get',
								onSuccess: function(xh){
										clearInterval(bmloader);
										$('ExtendedBookmarks').innerHTML='';
										Element.removeClassName('ExtendedBookmarks','loading');
										if(xh.responseText=='error'){
												alert(_("An error occurred."));
												Element.hide('ExtendedBookmarks');
										}
										else{
												var ret=xh.responseText;
												$('ExtendedBookmarks').innerHTML=ret;
												lastbmlist=ret;
												initDropMe();
										}
								}
						});
				}
				else {
						$('ExtendedBookmarks').innerHTML=lastbmlist;
						initDropMe();
				}
				Element.show('ExtendedBookmarks');
				$('bmplusminus').firstChild.innerHTML=symbol_minus;
				$('bmplusminus').firstChild.title=_("Hide list");
		}
		else {
				$('bmplusminus').firstChild.innerHTML=symbol_plus;
				$('bmplusminus').firstChild.title=_("Show list");
				$('ExtendedBookmarks').hide();
		}
		return false;
}

function checkEmail(s){var a=false;var res=false;if(typeof(RegExp)=='function'){var b=new RegExp('abc');if(b.test('abc')==true){a=true;}}if(a==true){reg=new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+'(\\@)([a-zA-Z0-9\\-\\.]+)'+'(\\.)([a-zA-Z]{2,4})$');res=(reg.test(s));}else{res=(s.search('@')>=1&&s.lastIndexOf('.')>s.search('@')&&s.lastIndexOf('.')>=s.length-5);}return(res);}

/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}
function sendmail(vorn,hinten){location.href='mailto:'+vorn+'@'+hinten;}
function printErrors(errors){var err='';errors.each(function(e){err+=e+"\n";});alert(_("Error")+":\n"+err);return;}
function Redirect(link){location.href=link;}
function changeValue(input,output){$(output).value=$(input).value;}

function checkRadioButton(buttonname){
	if(typeof buttonname!='string'){return false;}
	var opt_no=buttonname+'0';
	var opt_yes=buttonname+'1';
	if($E(opt_yes)&&$E(opt_no)){
		if($(opt_no).checked===true){return '0';}
		else{return '1';}
	}
	return false;
}

function select_redirect(select,url){var val=select.options[select.selectedIndex].value;if(val=='#'){return false;}window.location=url+val;}

function switchCatForNewTopic(){
	var val=$('newcategory2').options[$('newcategory2').selectedIndex].value;
	//if(isNaN(val)||val==0){return false;}
	window.location=rootdir+'/'+val+'/new';
}

function getCheckBoxValue(input_checkbox_id) {
		if (!$E(input_checkbox_id)) {
				return 0;
		}
		return $F(input_checkbox_id) === null ? 0 : $F(input_checkbox_id);
}

function switchTagsForNewCategory(){
    if ($E('topic_tags')) {
            var old_category=sub_category;
        	var new_category=$('subcatmenu').options[$('subcatmenu').selectedIndex].value;
        	if(new_category==0){return false;}
        	var input_value=$F('topic_tags');
        	var cat_tags=all_sub_tags;
        	var old_tags,new_tags;
        	if(cat_tags.length){
        		for(i=0; i<cat_tags.length; i++){
                	if(cat_tags[i].id==old_category){
            			old_tags=cat_tags[i].tags;
                	}
                	if(cat_tags[i].id==new_category){
                		new_tags=cat_tags[i].tags;
                	}
            	}
            	var output=trim(input_value.replace(new RegExp(old_tags,"g"), ''));
            	if(output!=''){new_tags=' '+new_tags;}
            	$('topic_tags').value=output+new_tags+' ';
            	sub_category=new_category;
        	}
    }

	return false;
}

function addEvent(obj, evType, func, useCaption)
{ // cross browser event handler
	if (obj.addEventListener) { // gecko
		obj.addEventListener(evType, func, useCaption);
		return true;
	}
	else if (obj.attachEvent) { // ie
		obj.attachEvent("on"+evType, func);
		return true;
	}
	else {
		return false;
	}
}

function trim(s)
{
	while (s.substring(0,1) == ' ') {
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') {
		s = s.substring(0,s.length-1);
	}
	return s;
}

function seterror(text, divid)
{
	var fehler = document.getElementById('error_'+divid);
	fehler.innerHTML = text;
	return;
}

function var_dump(obj) {
   if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
   } else {
      return "Type: "+typeof(obj)+"\nValue: "+obj;
   }
}

function check_img(img)
{
	var maxwidth = 570;
 	var w = img.width;
 	var h = img.height;
	// wie viel prozent von maximalgroesse?
    var d = Math.ceil( (w * 100) / maxwidth );
    // zu gross verkleinern
    if( d > 100 )
	{
		// faktor der verkleinerung
    	var faktor = (d / 100);
    	// die neuen abmessungen
    	var newh = Math.round(h / faktor);
    	var neww = Math.round(w / faktor);
    	img.width  = neww;
    	img.height = newh;
    	img.className = 'oversizedIMG';
		img.alt   = _("Please click to see the full image.");
		img.title = _("Please click to see the full image.");
		img.onclick = function() { window.open(img.src); }
    }
    return false;
}

function radioValue(formName, radioName)
{
	var radios = document.forms[formName].elements[radioName];
	var ret = '';
	for(var i=0; i<radios.length; i++)
	{
		if(radios[i].checked === true) {
			ret = radios[i].value;
			break;
		}
	}
	return ret;
}

// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that
// (a) you leave this copyright notice intact, and
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site
//     with a link back to http://www.albionresearch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// And thanks to everyone else who has provided comments and suggestions.
// ====================================================================
function URLEncode(the_text)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = the_text.toLowerCase();
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '"
                        + ch
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

function is_array(value)
{
   var s = typeof value;
   if (s === 'object')
   {
      if (value)
      {
         if (value instanceof Array)
         {
            s = 'array';
         }
      }
      else
      {
         s = 'null';
      }
   }
   return s;
}

function str_replace(search, replace, subject)
{
   if ( is_array(search) == 'array' )
   {
      //alert('Array');
      for(i=0; i<search.length; i++)
      {
         subject = subject.split(search[i]).join(replace[i]);
      }
   }
   else
   {
      //alert('String');
      subject = subject.split(search).join(replace);
   }
   return subject;
}

function number_format (number, decimals, dec_point, thousands_sep)
{
  var exponent = "";
  var numberstr = number.toString ();
  var eindex = numberstr.indexOf ("e");
  if (eindex > -1)
  {
    exponent = numberstr.substring (eindex);
    number = parseFloat (numberstr.substring (0, eindex));
  }

  if (decimals != null)
  {
    var temp = Math.pow (10, decimals);
    number = Math.round (number * temp) / temp;
  }
  var sign = number < 0 ? "-" : "";
  var integer = (number > 0 ?
      Math.floor (number) : Math.abs (Math.ceil (number))).toString ();

  var fractional = number.toString ().substring (integer.length + sign.length);
  dec_point = dec_point != null ? dec_point : ".";
  fractional = decimals != null && decimals > 0 || fractional.length > 1 ?
               (dec_point + fractional.substring (1)) : "";
  if (decimals != null && decimals > 0)
  {
    for (i = fractional.length - 1, z = decimals; i < z; ++i)
      fractional += "0";
  }

  thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ?
                  thousands_sep : null;
  if (thousands_sep != null && thousands_sep != "")
  {
	for (i = integer.length - 3; i > 0; i -= 3)
      integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
  }

  return sign + integer + fractional + exponent;
}

function addST()
{
	if ((typeof window.sidebar == "object") && (typeof
		window.sidebar.addSearchEngine == "function")) {
		window.sidebar.addSearchEngine(
		rootdir + "/tools/st_search.src",
		rootdir + "/tools/st_search.gif",
		"Supertopic!", "general");
	}else{
		alert("Please install Firefox to use this function!");
	}
	return false;
}

function SmileBar(ta)
{
	var s = [
		'smile :-)',
		'freuen :-D',
		'lol',
		'ja',
		'rockon',
		'trippel',
		'hammer',
		'love',
		'cheer',
		'umarm',
		'honks',
		'gumbo',
		'nudgenudge ;-)',
		'zunge',
		'rrr',
		'jump',
		'traurig :-(',
		'heul',
		'hm',
		'troesten :tröst',
		'baeh :-P',
		'boes :bös',
		'scream',
		'schimpf',
		'haha',
		'fuckoff',
		'kotz',
		'schnellweg',
		'werber',
		'schonklar',
		'nana',
		'hoerthoert :hörthört',
		'pfeif',
		'vogel',
		'rafftnix',
		'brain',
		'verlegen',
		'angst',
		'planlos',
		'pee',
		'tuse',
		'zzz',
		'bounce'
	];
	var list = '';
	for(var i=0; i<s.length; i++)
	{
		p = s[i].split(' ');
		if(p.length > 1)
		{
			f = p[0];
			t = p[1];
		}
		else
		{
			f = p;
			t = ':'+p;
		}
		list += '<a href="#" onclick="return insertUBB(\''+t+'\',\'\',\''+ta+'\');"><img src="'+imgdir+'/emoticons/'+f+'.gif" alt="" border="0" class="inlineimg" /></a>';
	}

	if(ta == "editarea") {
		var divtoshow="divsmiliesedit";
	}
	else if(ta == "message") {
		var divtoshow="divsmilies";
	}
	else {
		var divtoshow='divsmilies'+type;
	}
	var smileydiv = $(divtoshow);
	smileydiv.innerHTML = list;
	Element.toggle(smileydiv);
	return false;
}

function LobeMich()
{
	new Ajax.Request(_f('lob'),{
		method:'get',
		onSuccess:function(xh){
			$('lob').innerHTML=xh.responseText;
		}
	});
}

var enlargeClicked = 0;

function enlargeField(e) {

		var oldHeight = $(e).getHeight() - 18;
		var newHeight = oldHeight + 150;

		globalIncrease(e, oldHeight, newHeight, 250);
		oldHeight = newHeight;
		enlargeClicked++;

		if (enlargeClicked > 0 && $('rf_' + e).getStyle('display') == 'none') {
				$('rf_' + e).show();
		}

		return false;
}


function reduceField(e) {

		var oldHeight = $(e).getHeight() - 18;
		var newHeight = oldHeight - 150;

		if (newHeight < 150) {
				enlargeClicked = 1;
				newHeight = 150;
		}

		globalIncrease(e, oldHeight, newHeight, 250);
		oldHeight = newHeight;
		enlargeClicked--;

		if (enlargeClicked == 0 && $('rf_' + e).getStyle('display') != 'none') {
				$('rf_' + e).hide();
		}

		return false;

}

// Fenstermasse ermitteln
function getWinSize() {

	var size = {w : 0, h : 0};
	var win = window;

	size.w = win.innerWidth ? win.innerWidth : win.document.body.clientWidth;
	size.h = win.innerHeight ? win.innerHeight : win.document.body.clientHeight;

	return size;
}

function emotSidebar(browser) {
		if (browser == 'ff') {
				if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function')) {
						window.sidebar.addPanel('Supertopic Emoticons', rootdir + '/emoticons/','');
				}
		}
		if (browser == 'ie') {
				void(_search = open(rootdir + '/emoticons/', '_search'));
		}
		return false;
}

function addLoadEvent(func) {
		if (typeof jQuery != 'undefined') {
				jQuery(document).ready(func);
		}
		else if (typeof window.onload != 'function') {
	        	window.onload = func;
	    }
	    else {
				var oldonload = window.onload;
		        window.onload = function() {
			            oldonload();
			            func();
		        }
	    }
}

// admin message

function msg(msg, div) {
		if (typeof(div) == 'undefined') {
			div = 'admin-message';
		}
		$j('#' + div)
			.html(msg)
			.show('fast')
			.animate({opacity: 1}, 2500) // delay
			.hide('fast');
}

function debugInfo() {
		$j('.debug h3').click(function () {
			if ($j(this).next().is(':hidden')) {
				$j(this).next().show('fast');
				setCookie('showDebug', 1, 365);
			}
			else {
				$j(this).next().hide('fast');
				setCookie('showDebug', 0, 365);
			}
		});
}