var userAgent  =   navigator.userAgent.toLowerCase();
var is_opera   =   (userAgent.indexOf('opera') != -1);
var is_saf     =   ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == "Apple Computer, Inc."));
var is_webtv   =   (userAgent.indexOf('webtv') != -1);
var is_ie      =   ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4     =   ((is_ie) && (userAgent.indexOf("msie 4.") != -1));
var is_moz     =   ((navigator.product == 'Gecko') && (!is_saf));
var is_kon     =   (userAgent.indexOf('konqueror') != -1);
var is_ns      =   ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4     =   ((is_ns) && (parseInt(navigator.appVersion) == 4));

var text = "";
var txt = "";
var tags = new Array();
var slide;

var ol_bgcolor = "#F9920D";
var ol_fgcolor = "#FBF0CD";
var ol_closecolor = "#ffffff";

var today = new Date();
var expires = new Date();
expires.setTime(today.getTime()+1000*60*60*24*365);

Object.extend(Element, {
	getWidth: function(element) {
		element = $(element);
		return element.offsetWidth;
	},
	setWidth: function(element,w) {
		element = $(element);
		element.style.width = w +"px";
	},
	setHeight: function(element,h) {
		element = $(element);
		element.style.height = h +"px";
	},
	setTop: function(element,t) {
		element = $(element);
		element.style.top = t +"px";
	},
	setSrc: function(element,src) {
		element = $(element);
		element.src = src;
	},
	setHref: function(element,href) {
		element = $(element);
		element.href = href;
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});

/*
	Cookies
*/
function getCookieVal (offset){
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name){
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while(i<clen){
		var j=i+alen;
		if(document.cookie.substring(i, j) == arg) return getCookieVal (j);
		i=document.cookie.indexOf(" ", i) + 1;
		if(i<=0)break;
	}
	return null;
}

function SetCookie (name, value){

	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;

	document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires="+expires.toGMTString())) + ((path == null) ? "; path=/" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");

}

function posleft(elm){
	var left=elm.offsetLeft;
	while((elm=elm.offsetParent)!=null){
		left+=elm.offsetLeft;
	}
	return left;
}

function postop(elm){
	var top=elm.offsetTop;
	while((elm=elm.offsetParent)!=null){
		top+=elm.offsetTop;
	}
	return top;
}


/*
	Switch, bitch!
*/
function setCSS(sheet,obj) {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == sheet){
				a.disabled = false;
				SetCookie('logzNET_sheet',sheet,expires);
			}
		}
	}
	obj.blur();
}

function toggleDiv(divname){

	if($(divname).style.display=='none'){
		SetCookie(divname,'1',expires);
	}else{
		SetCookie(divname,'0',expires);
	}
	new Effect.toggle(divname,'Blind');
}


/*
	Funktionen
*/
function array_push(arr,value){
	var arr_size=sizeof(arr);
	arr[arr_size]=value;
	return arr[arr_size];
}


function array_pop(arr){
	var arr_size=sizeof(arr);
	var retval=arr[arr_size-1];
	delete arr[arr_size-1];
	return retval;
}


function is_array(arr,i){
	if(typeof(arr[i])=="undefined" || (arr[i]=="") || (arr[i]==null)){
		return false;
	}else{
		return true;
	}
}

function makeTimeStamp() {
	now=new Date();
    return(now.getTime());
}

function wannaCookie(){
	$('brnd').style.top='0px';
	$('brnd').onmouseout=function(){$('brnd').style.top='-5px';}
}

function addExistingTag(tname){
	if($('tags').value!='' &&  $('tags').value.substr(-1)!=' '){
		$('tags').value=$('tags').value+' ';
	}
	if(tname.match(/ /)){
		tname='"'+tname+'"';
	}
	$('tags').value=$('tags').value+tname;
}


function addNewTag(tname,tid){

    doNotAdd=false;

    if(!doNotAdd){
		ajax('saveTagForPost','&t='+tname+'&i='+tid,
			function(ndata){
				ndata=parseInt(ndata);
				if(ndata>=0){
					$('div_taglist').innerHTML=ndata;
				}
			}
		);
    }

}


function addTag(tid,tname){
	if(tname!='' && tid>0){
		obj=document.getElementById('div_taglist');
		obj.innerHTML=obj.innerHTML+'<div class="tag_list" id="tag_'+tid+'">'+tname+'<a href="javascript:void(0);" onclick="removeTagFromList('+tid+');" class="small_grey">[X]</a></div>';
		ptags[tid]=tname;
	}
}


function removeTagFromList(tid){
    obj=document.getElementById('tag_'+tid);
    if(obj!=undefined){
		document.getElementById('div_taglist').removeChild(obj);
		newTags=new Array();

		 $H(ptags).keys().each(
			function(val,idx){
				if(val!=tid){
					newTags[val]=ptags[val];
				}
			}
		);
		ptags=newTags;
	}
}


function doClickST(){
	var dit=document.getElementsByTagName('div');
	$H(dit).values().each(
		function(val,idx){
			if(val.id!=undefined){
				ret=val.id.match(/tags_\d+/);
				if(ret) showTagsForPost(ret[0].split('_')[1]);
			}
		}
	);
}


function showTagsForPost(pid){
	obj=document.getElementById('tags_'+pid);
	obj2=document.getElementById('btags_'+pid);
	hideTags();
	if(obj.style.display!='block'){
		obj.style.width='120px';
		obj.style.height='150px';
		obj.style.left=fetch_object_posleft(obj2)+"px";
		obj.style.top=(fetch_object_postop(obj2)+20)+"px";
		obj.style.display='block';
		obj2.className='showtags_active';
		mbody=document.getElementsByTagName('body')[0];
		addEvent(mbody,"mouseup",hideTags,false);
	}
}


function hideTags(){

	mbody=document.getElementsByTagName('body')[0];
	removeEvent(mbody,"mouseup");

	var reg1 = new RegExp('^tags_([0-9]+)$');
	var elem=document.getElementsByTagName('div');

	elem = $A(elem);
	var opt = elem.findAll(
		function(el){
			var e=reg1.exec(el.id);
			if(e!=null){
				el.style.display='none';
				document.getElementById('btags_'+e[1]).className='showtags_dead';
			}
		}
	);

}


function fp_createDir(dirName){
	if(dirName.length>2){
		ajax('fp_createDir','&dirname='+encodeURIComponent(dirName),function(ndata){ $('dirContainer').innerHTML=ndata; });
	}else{
		alert('Der Name des Verzeichnisses muss länger als 2 Zeichen sein!');
	}
}


function del_attachment(fid,aid,tmp_id,tmid){

	ajax('delAttachment','&fid='+fid+'&tmp_id='+tmp_id+'&tmid='+tmid,function(ndata){ refreshAttachments(tmid,tmp_id) });

}


function refreshAttachments(tmid,tmp_id){

	new Ajax.Updater('div_attach',_wp+'logz_ajax.php?fn=refreshAttachments&tmid='+tmid+'&tmp_id='+tmp_id,{asynchronous:true});

}


function refreshMood(m,cm){

	new Ajax.Updater('p_mood_cnt',_wp+'logz_ajax.php?fn=refreshMood&m='+m+'&cm='+cm,{asynchronous:true});

}


function refreshAttrs(bid){

	new Ajax.Updater('p_attr_cnt',_wp+'logz_ajax.php?fn=refreshAttrs&bid='+bid,{asynchronous:true});

}


function activateDraft(id){
	ajax('activateDraft','&id='+id,
		function(ndata){
			ret=ndata.split('|||');
			if(ret[0]=='suc'){
				tmp_id='p-'+id;
				cnt=ret[1].split('[<nextplease>]');
				refreshAttachments(id,tmp_id);
				refreshAttrs(cnt[4]);
				refreshMood(cnt[2],cnt[3]);
				document.getElementById('p_title').value=cnt[0];
				document.getElementById('t_content').value=cnt[1];
				document.getElementById('p_is_draft').value=id;
				document.getElementById('tmp_id').value=tmp_id;
				document.getElementById('tmid').value=id;
				document.getElementById('tags').value=cnt[5];
			}else{
				alert(ret[1]);
			}
		}
	);
}


function ajax_SaveSubscriberForBlog(){

	new Element.update('show_abo_status','<img src="'+_wp+'/_img/loading.gif" alt="lade" title="lade" /> Speichere deine Adresse...')

	abo_bid=$('abo_bid').value;
	abo_email=$('abo_email').value;

	ajax('saveSubscriberForBlog','&abo_bid='+abo_bid+'&abo_email='+abo_email,
		function(ndata){
			ndata=ndata.split('|||');
			if(ndata[0]=='suc'){
				$('show_abo_status').innerHTML='Danke! Wir haben dich '+((ndata[1]=='in')?'eingetragen':'ausgetragen')+'.';
			}else{
				$('show_abo_status').innerHTML='Ooops! Da ist ein Fehler aufgetreten. Bitte vergewissere dich, dass deine Adresse korrekt ist!';
			}
		}
	);
}


function ajax_previewPosting(){
	var bid=$('p_blog').value;
	var p_title=encodeURIComponent($('p_title').value);
	var p_content=encodeURIComponent($('t_content').value);
	myLightbox.start($('showPreview'),'/logz_ajax.php?width=600&height=300&fn=previewPosting&bid='+bid+'&p_title='+p_title+'&p_content='+p_content);
}



function ajax_showCompletePM(id){
	ajax('fetchPM','&id='+id,
		function(ndata){
			$('pm_'+id).innerHTML=ndata;
		}
	);
}


function ajax_SaveBuddies(){
	var m2=document.getElementById('bid_to')
	var users='';
	for(i=0;i<m2.options.length;i++){
		users+=m2.options[i].value+'!:!';
	}

	ajax('saveBuddies','&ids='+users,
		function(ndata){
			ndata=parseInt(ndata);
			if(ndata>=0){
				myLightbox.showMsg("Buddyliste gespeichert!",ndata+" Benutzer sind nun in deiner Buddyliste.",400,300);
			}
		}
	);

}


function ajax_AddBuddy(id){
	ajax('addBuddy','&id='+id,
		function(ndata){
			Effect.SwitchOff('infobox');
		}
	);
}


function ajax_SavePersonalInfo(){

	var vErr=false;

	var emailPat=/^[a-z0-9_]+([a-z0-9_|\-|.]+)*\@([a-z0-9]+((-*)(.*)[a-z0-9]+)*\.([a-z]{2,5})|(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))$/;
	var nickPat=/^[a-z0-9_\-\'\$\!\?: ]{3,25}$/i;

	var nickname=document.getElementById('nickname').value;
	var vorname=document.getElementById('vorname').value;
	var nachname=document.getElementById('nachname').value;
	var adr_plz=document.getElementById('adr_plz').value;
	var adr_ort=document.getElementById('adr_ort').value;
	var adr_strasse=document.getElementById('adr_strasse').value;
	var adr_land=document.getElementById('adr_land').value;
	var email=document.getElementById('email').value;

	if(nickPat.test(nickname)===false){
		document.getElementById('nickname').style.backgroundColor='#FFE6C3';
		vErr = true;
	}else{
		document.getElementById('nickname').style.backgroundColor='#ffffff';
	}

	if(emailPat.test(email)===false){
		document.getElementById('email').style.backgroundColor='#FFE6C3';
		vErr = true;
	}else{
		document.getElementById('email').style.backgroundColor='#ffffff';
	}

	if(!vErr){
		ajax('SavePersonalInfo','&nickname='+nickname+'&vorname='+vorname+'&nachname='+nachname+'&adr_plz='+adr_plz+'&adr_ort='+adr_ort+'&adr_strasse='+adr_strasse+'&adr_land='+adr_land+'&email='+email,
			function(ndata){
				ret=ndata.split('-');
				if(ret[0]=='suc'){
					msgb('Persönliche Daten gespeichert','Deine persönlichen Daten wurden erfolgreich aktualisiert.<br />Vielen Dank, dass du deine Daten auf dem aktuellen Stand hältst.');
				}else{
					alert(ret[1]);
				}
			}
		);
	}else{
		alert('Leider fehlt die ein oder andere Angabe bei deinen persönlichen Daten. Bitte korrigiere die Eingaben in den hervorgehobenen Feldern!');
	}
}


function ajax_del_attr(aid){

	if(confirm('Zusatzinfo wirklich löschen?\n\nAchtung:\nAlle Daten für dieser Info werden ebenfalls gelöscht und können nicht mehr wiederhergestellt werden.')){
		ajax('del_attr','&id='+aid,
			function(ndata){
				obj=document.getElementById('attributes');
				obj.innerHTML=ndata;
			}
		);
	}

}


function ajax_add_attr(bid){

	val=document.getElementById('add_attr').value;

	if(val.length>=3){
		ajax('add_attr','&bid='+bid+'&val='+val,
			function(ndata){

				ret=ndata.split('---');

				if(ret[0]=='err'){
					alert('Zusatzinfo konnte nicht hinzugefügt werden.\n\n'+ret[1]+'\n\nBitte versuch\' es nochmal!');
				}else if(ret[0]=='suc'){
					obj=$('attributes');
					obj.innerHTML=ret[1];
				}


			}
		);
	}else{

		alert('Zusatzinfo konnte nicht hinzugefügt werden. Der Name muss aus mindestens 3 Zeichen bestehen!');

	}

}


function requestMoreBlogs(nstart,num){
	ajax('requestMoreBlogs','&start='+nstart+'&num='+num,
		function(ndata){
			$('recentBlogs_cnt').innerHTML=ndata;
		}
	);
}


function requestMoreNews(nstart,num){
	ajax('requestMoreNews','&start='+nstart+'&num='+num,
		function(ndata){
			$('recentNews_cnt').innerHTML=ndata;
		}
	);
}


function requestMoreThreads(nstart,num){
	ajax('requestMoreThreads','&start='+nstart+'&num='+num,
		function(ndata){
			$('recentForum_cnt').innerHTML=ndata;
		}
	);
}



function requestMorePosts(nstart,num,uid){

	if(uid=='c' || uid==''){
		divid='recentPosts_cnt';
	}else if(uid=='b'){
		divid='recentBuddyPosts_cnt';
	}

	if(divid!=''){
		new Ajax.Updater(divid,_wp+'logz_ajax.php?fn=requestMorePosts&start='+nstart+'&num='+num+'&uid='+uid,{asynchronous:true});
	}

}

function requestMoreComments(nstart,num,uid){
	if(uid=='c'){
		divid='recentComments_cnt';
	}
	if(divid!=''){
		new Ajax.Updater(divid,_wp+'logz_ajax.php?fn=requestMoreComments&start='+nstart+'&num='+num+'&uid='+uid,{asynchronous:true});
	}
}

function delComment(commentid){
	if(confirm("Sicher, dass du diesen Kommentar löschen möchtest?")){
		commentid=parseInt(commentid);
		if(commentid>0){
			ajax("delComment","&cid="+commentid+"",function(){ ret=ndata.split('|||'); if(ret[0]=='suc'){ request_new_comments(ret[1]); }else{ alert(ret[1]) }; });
		}
	}
}

function ajax_toggleFavorite(pid){
	var s=document.getElementById('favp_'+pid);
	var pfad=s.src.split("/");
	var image=pfad.pop();
	pfad=pfad.join('/')+'/';
	ajax("toggleFavorite","&pid="+pid+"",function(){ ret=ndata.split('|||'); if(ret[0]=='suc'){ s=$('favp_'+pid); s.src=pfad+"star_"+ret[1]+".gif"}else{ alert(ret[1]) }; });
}


function tbRequestAD(txt_links){

	var obj=document.getElementById('txt_trackback');

	obj.value='einen Moment...';

	if(window.XMLHttpRequest){
		var ajax=new XMLHttpRequest();
	}else if(window.ActiveXObject){
		var ajax=new ActiveXObject("Microsoft.XMLHTTP")
	}

	ajax.open('POST',_wp+'logz_ajax.php',true);
	ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");

	txt_data='fn=tbRequestAD&links='+txt_links;

	ajax.onreadystatechange=function(){
		if(ajax.readyState==4){
			var sstr="!-- start:ajax_out //-->";
			var estr="!-- end:ajax_out //-->";
			ndata=ajax.responseText.substring((ajax.responseText.indexOf('<'+sstr)+sstr.length+1),ajax.responseText.indexOf('<'+estr));

			ret=ndata.split('---');

			if(ret[0]=='err'){
				obj.value=ret[1];
			}else if(ret[0]=='suc'){
				obj.value=ret[1];
			}

		}
	}

	ajax.send(txt_data);

}


function newPM(){

	var handler = function(x){
		ndata=ajax_strip(x.responseText);
		ndata=ndata.split('|||');
		if(ndata[0]=='suc'){
			ids=ndata[1].split(',');
			for(i=0;i<ids.length;i++){
				if(ids[i]!=''){
					showPageRW(_wp+'forum_pm_read.php?id='+ids[i],420,330,1);
				}
			}
		}
	}

	new Ajax.Request(_wp+'logz_ajax.php', {asynchronous:'true', method:'post', parameters:'fn=requestNewPM', onSuccess:handler});

}


function msgb_bg_back(){
	new Effect.Fade('meldung',{ duration:0.2 });
	new Effect.Fade('overlay', { duration: 0.2});
	showSelectBoxes();
	slide.stop();
}


function createMsgBox(){

	if(!document.getElementsByTagName) return;

	var btag=document.getElementsByTagName("body").item(0);

	var newDiv2=document.createElement("div");
	newDiv2.setAttribute('id','meldung');
	newDiv2.style.display='none';
	btag.appendChild(newDiv2);

	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objOverlay.onclick = function() { return false; }
	btag.appendChild(objOverlay);

}


function centerMsgBox(newDiv2){

	curr_width=newDiv2.offsetWidth/2;
	curr_height=newDiv2.offsetHeight/2;

	var _scroll = Position.Window.getDeltas();
	var _window = Position.Window.size();

	var moveX = (_window[0]/2) - (curr_height/2);
	var moveY = ((_window[1]/2) + _scroll[1]) - (curr_height/2);

	newDiv2.style.left=moveX+"px";
	newDiv2.style.top=moveY+"px";
}


function untenRechts(newDiv2){

	curr_width=newDiv2.offsetWidth/2;
	curr_height=newDiv2.offsetHeight/2;

	var _scroll = Position.Window.getDeltas();
	var _window = Position.Window.size();

	var moveY = _window[1] + _scroll[1] - curr_height - 16;

	newDiv2.style.right="4px";
	newDiv2.style.top=moveY+"px";
}


function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}


function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}


function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}


function msgBg(){

	hideSelectBoxes();
	var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);
	new Effect.Appear('overlay', { duration: 0.1, from: 0.0, to: 0.1 });

}


function msgb(a,b){

	msgBg();
	var newDiv2=document.getElementById('meldung');
	newDiv2.style.width="300px";
	newDiv2.style.height="200px";
	centerMsgBox(newDiv2);

	newDiv2.innerHTML='<p class="meldungs_box_topic">'+a+"</p>"+b+'<a class="meldungs_box_button" href="javascript:void(0);" onclick="msgb_bg_back();">OK</a>';

	slide=new PeriodicalExecuter(feedback,1);
	Effect.Appear(newDiv2,{ duration:0.2 });
}


function ea_dialog(a,b,c,d){

	msgBg();

	var newDiv2=document.getElementById('meldung');
	newDiv2.style.width=c+"px";
	newDiv2.style.height=d+"px";
	centerMsgBox(newDiv2);

	if(window.XMLHttpRequest){
		var ajax=new XMLHttpRequest();
	}else if(window.ActiveXObject){
		var ajax=new ActiveXObject("Microsoft.XMLHTTP")
	}

	ajax.open('GET',a,true);

	ajax.onreadystatechange=function() {
		if(ajax.readyState==4){
			var sstr="<!-- start:ajax_out //-->";
			var estr="<!-- end:ajax_out //-->";
			ndata=ajax.responseText.substring((ajax.responseText.indexOf(sstr)+sstr.length),ajax.responseText.indexOf(estr));
			newDiv2.innerHTML='<form method="post" enctype="multipart/form-data">'+ndata+'<div style="width:300px;position:absolute;bottom:10px;right:10px;"><a class="meldungs_box_button" href="javascript:void(0);" onclick="msgb_bg_back();">Abbrechen</a><a class="meldungs_box_button" href="javascript:void(0);" onclick="'+b+'">OK</a><div></form>';

		}
	}

	slide=new PeriodicalExecuter(feedback,1);
	Effect.Appear(newDiv2,{ duration:0.2 });

	ajax.send(null);

}

PeriodicalExecuter.prototype.registerCallback = function() {
	this.intervalID = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
}

PeriodicalExecuter.prototype.stop = function() {
	clearInterval(this.intervalID);
}


Position.Window = {

	getDeltas: function() {
		var deltaX =  window.pageXOffset
			|| document.documentElement.scrollLeft
			|| document.body.scrollLeft
			|| 0;
		var deltaY =  window.pageYOffset
			|| document.documentElement.scrollTop
			|| document.body.scrollTop
			|| 0;
		return [deltaX, deltaY];
	},

	size: function() {
		var winWidth, winHeight, d=document;
		if (typeof window.innerWidth!='undefined') {
			winWidth = window.innerWidth;
			winHeight = window.innerHeight;
		} else {
			if (d.documentElement && typeof d.documentElement.clientWidth!='undefined' && d.documentElement.clientWidth!=0) {
				winWidth = d.documentElement.clientWidth
				winHeight = d.documentElement.clientHeight
			} else {
				if (d.body && typeof d.body.clientWidth!='undefined') {
					winWidth = d.body.clientWidth
					winHeight = d.body.clientHeight
				}
			}
		}
		return [winWidth, winHeight];
	}
}


Effect.KeepFixed = function(element, offsetx, offsety) {
	var _scroll = Position.Window.getDeltas();
	var _window = Position.Window.size();
	var elementDimensions = Element.getDimensions(element);
	var eWidth = elementDimensions.width;
	var eHeight = elementDimensions.height;
	var moveX = (_window[0]/2) - (eWidth/2);
	var moveY = ((_window[1]/2) + _scroll[1]) - (eHeight/2);
	return new Effect.Move(element, { x: moveX, y: moveY, mode: 'absolute', duration:'0.3' });
}


function toggleWdwSize(w,h){
	var _window = Position.Window.size();
	if(_window[0]<=w) resizeME(screen.width-200,screen.height-200); else resizeME(w,h);
	centerME();
}

function centerME(){
	var _window = Position.Window.size();
	IE4 = (document.all) ? true : false;
	NS4 = (document.layers) ? true : false;
	xsize = _window[0];
	ysize = _window[1];
	ScreenWidth = screen.width;
	ScreenHeight = screen.height;
	xpos = (ScreenWidth/2)-(xsize/2);
	ypos = (ScreenHeight/2)-(ysize/2);
	window.moveTo(xpos,ypos)
}

function resizeME(w,h){
	if(document.all){
		window.resizeTo(w,h);
	}else if (document.layers||document.getElementById){
		window.outerHeight = h;
		window.outerWidth = w;
	}
}

function feedback() {
	var _window = Position.Window.size();
	new Effect.KeepFixed('meldung',_window[0],_window[1]);
}


function sizeof(arr){
	for(i=0;i<arr.length;i++) if(!is_array(arr,i)) return i;
	return arr.length;
}

function BlurLinks(){
  	links=document.getElementsByTagName('a');
  	for(i=0;i<links.length;i++) links[i].onfocus=new Function("if(this.blur)this.blur()");
}

function showPageRW(seite, xwidth, xheight, scroll,resize) {
	if(resize>0) resize=' resizeable=yes,'; else resize='';
	window.open(seite, "", "menubar=0,scrollbars="+scroll+","+resize+" width="+xwidth+", height="+xheight+",left=500 top=50");
	return false;
}

function editProfileData(id,typ,len){
	obj=document.getElementById('edit_'+id);
	if(typ=='varchar' || typ=='int' || typ=='tinyint' || typ=='datetime' || typ=='date'){
		if(len<=0){
			if(typ=='datetime'){
				len=20;
			}else if(typ=='date'){
				len=10;
			}
		}
		iwidth=len*10;
		if(iwidth>200) iwidth=200;
		obj.innerHTML='<input type="text" id="i_edit_'+id+'" style="width:'+iwidth+'px" value="'+obj.innerHTML+'" maxlength="'+len+'" style="width:200px;" onBlur="ajax_saveProfileData(\''+id+'\',\''+typ+'\',\''+len+'\');" />';
	}else if(typ=='text'){
		obj.innerHTML='<textarea id="i_edit_'+id+'" onBlur="ajax_saveProfileData(\''+id+'\',\''+typ+'\',\''+len+'\');">'+obj.innerHTML+'</textarea>';
	}else if(typ=='enum'){
		pval=obj.innerHTML;
		if(pval=='Keine Angaben') pval='';
		obj.innerHTML='<select id="i_edit_'+id+'" onBlur="ajax_saveProfileData(\''+id+'\',\''+typ+'\',\''+len+'\');"></select>';
		len=len.split('|||');
		for(i=0;i<len.length;i++){
			npos=$('i_edit_'+id+'').options.length;
			$('i_edit_'+id+'').options[npos]=new Option(len[i]);
			if(len[i]==pval) $('i_edit_'+id+'').options[npos].selected=true;
		}
	}
	obj.innerHTML+='<p style="font-size:10px;color:#999999;">Um deine Änderung zu speichern, klick neben das Eingabefeld</p>';
	obj.setAttribute("onClick","",false);
	document.getElementById('i_edit_'+id).focus();
}


function ajax_saveProfileData(id,typ,len){
	obj=document.getElementById('i_edit_'+id);
	txt=obj.value;
	if(txt=='Keine Angaben') $txt='';

	ajax('saveProfileData','&id='+id+'&cnt='+encodeURIComponent(txt),
		function(ndata){
		alert (txt);
			obj=$('edit_'+id);
			if(txt=='') txt='Keine Angaben';
			obj.innerHTML=txt;
			obj.setAttribute("onclick","editProfileData('"+id+"','"+typ+"','"+len+"');","false");
		}
	);

}


function ajax_activateModule(st,mid,bid){
	new Element.update('modules','<img src="_img/loading.gif" alt="lade" title="lade" />Lade Konfiguration...')
	new Ajax.Updater('modules',_wp+'logz_ajax.php?fn=activateModule&mid='+mid+'&bid='+bid+'&st='+st,{asynchronous:true});
}



function ajax_send_email(id){

	var emailPat=/^[a-z0-9_]+([a-z0-9_|\-|.]+)*\@([a-z0-9]+((-*)(.*)[a-z0-9]+)*\.([a-z]{2,5})|(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))$/;
/*
	var email_name=document.getElementById('email_name').value;
	var email_email=document.getElementById('email_email').value;
*/
	var email_text=document.getElementById('email_text').value;

	vMsg='';
	vErr=false;

	if (email_text=='' || email_text=='Deine Nachricht') {
		vMsg = vMsg + "- Nachricht\n";
		document.getElementById('email_text').style.backgroundColor='#FFE6C3';
		vErr = true;
	}else{
		document.getElementById('email_text').style.backgroundColor='#ffffff';
	}

/*
	if (email_name=='') {
		vMsg = vMsg + "- Name\n";
		document.getElementById('email_name').style.backgroundColor='#FFE6C3';
		vErr = true;
	}else{
		document.getElementById('email_name').style.backgroundColor='#ffffff';
	}

	if (!emailPat.test(email_email.toLowerCase())) {
		vMsg = vMsg + "- e-mail Adresse\n";
		document.getElementById('email_email').style.backgroundColor='#FFE6C3';
		vErr = true;
	}else{
		document.getElementById('email_email').style.backgroundColor='#ffffff';
	}
*/
	if(vErr){

		alert('Folgende Felder musst du noch korrekt ausfüllen:\n\n'+vMsg);

	}else{

		var obj=document.getElementById('div_email_me');
		var obj2=document.getElementById('email_status');

		obj2.innerHTML='Bitte warten: deine e-mail wird verschickt...';

		ajax('send_email','&id='+id+'&text='+email_text,
			function(ndata){
				ret=ndata.split('---');

				if(ret[0]=='err'){
					obj2.innerHTML=ret[1];
				}else if(ret[0]=='suc'){
					obj.innerHTML='<p style="background-color:#FBF0CD;padding:10px 4px 10px 4px;"><strong>Deine e-mail wurde erfolgreich verschickt.</strong></p>';
				}

			}
		);

	}
}

function ajax(fn,data,funct){

	var btag=document.getElementsByTagName("body").item(0);

	var newDiv2=document.createElement("div");
	newDiv2.setAttribute('id','bittewarten');
	newDiv2.innerHTML='<img src="/_img/loading.gif" /> Momentchen...';
	btag.appendChild(newDiv2);
	untenRechts(newDiv2);

	var handler = function(x){
		ndata=ajax_strip(x.responseText);
		if(funct) funct(ndata);
		btag.removeChild(newDiv2);
	}

	new Ajax.Request(_wp+'logz_ajax.php', {asynchronous:'true', method:'post', parameters:'fn='+fn+data, onSuccess:handler});

}

function ajax_strip(ndata){
	sstr="!-- start:ajax_out //-->";
	estr="!-- end:ajax_out //-->";
	ret=ndata.substring((ndata.indexOf('<'+sstr)+sstr.length+1),ndata.indexOf('<'+estr));
	return(ret);
}


/*
 * Highlighting von GoogleKeywords
 */
var google_text_color = '#000000';
var google_link_colors = new Array('#ffff66','#a0ffff','#99ff99','#ff9999','#ff66ff');

function init_google(){
	var pattern = /google\./i;
	if (pattern.exec(document.referrer) != null){
		var url_parts = document.referrer.split('?');
		if (url_parts[1]){
			var url_args = url_parts[1].split('&');
			for(var i=0; i<url_args.length; i++){
				var keyval = url_args[i].split('=');
				if (keyval[0] == 'q'){
					go_google(decode_url(keyval[1]));
					return;
				}
			}
		}
	}
}

function decode_url(url){
	return unescape(url.replace(/\+/g,' '));
}

function go_google(terms){
	terms = terms.replace(/\"/g,"");
	var terms_split = terms.split(' ');
	var c = 0;
	for(var i=0; i<terms_split.length; i++){
		highlight_google(terms_split[i], document.body,google_link_colors[c]);
		c = (c == google_link_colors.length-1)?0:c+1;
	}
}

function highlight_google(term, container, color){
	var term_low = term.toLowerCase();

	for(var i=0; i<container.childNodes.length; i++){
		var node = container.childNodes[i];

		if (node.nodeType == 3){
			var data = node.data;
			var data_low = data.toLowerCase();
			if (data_low.indexOf(term_low) != -1){
				var new_node = document.createElement('SPAN');
				node.parentNode.replaceChild(new_node,node);
				var result;
				while((result = data_low.indexOf(term_low)) != -1){
					new_node.appendChild(document.createTextNode(data.substr(0,result)));
					new_node.appendChild(create_node_google(document.createTextNode(data.substr(result,term.length)),color));
					data = data.substr(result + term.length);
					data_low = data_low.substr(result + term.length);
				}
				new_node.appendChild(document.createTextNode(data));
			}
		}else{
			highlight_google(term, node, color);
		}
	}
}

function create_node_google(child, color){
	var node = document.createElement('SPAN');
	node.style.backgroundColor = color;
	node.style.color = google_text_color;
	node.appendChild(child);
	return node;
}

//Event.observe(window,'load',createMsgBox,false);
addEvent(window,'load',createMsgBox);
//addEvent(window,'load',init_google);