// JavaScript Document
function el(x) { return document.getElementById(x);}
var lastzindex=1;
var lastToggle=new Array();
function toggle(id, soll, plus){
	if (lastToggle[0] && lastToggle[0]!=id && lastToggle[0]!='entry' && plus==lastToggle[2]){
		toggle(lastToggle[0],lastToggle[1],-1);
		lastToggle=new Array();
	}
	if (id){
		var div=document.getElementById(id);
		plus= (plus<0 || parseInt(div.style.height)>=soll) ? Math.ceil((soll-1)/15)*-1 : Math.ceil((soll-1)/15);
		if (plus>0) div.style.zIndex=lastzindex++;
		div.style.height=parseInt(div.style.height)+plus+"px";
		div.style.paddingTop=((parseInt(div.style.height)+plus)/soll)*4 +"px";
		div.style.paddingBottom=((parseInt(div.style.height)+plus)/soll)*4 +"px";
		div.style.opacity=(parseInt(div.style.height)+plus)/soll;
		div.style.filter='alpha(opacity='+ (((parseInt(div.style.height)+plus)/soll)*100) +')';
		if (plus<0 && el("icon"+id)) el("icon"+id).style.background="transparent";
	
		if ((plus>0 && parseInt(div.style.height)<=soll) || (plus<0 && parseInt(div.style.height)>0)){
			setTimeout("toggle('"+id+"','"+soll+"','"+plus+"')",0);
		}
	
		else if (plus>0) {
			if (el("icon"+id)) el("icon"+id).style.background="#999999";
			lastToggle=new Array(id,soll,1);
		}
	}
}

function togglechat(id, soll, plus){
	plus=(plus<0 || parseInt(el(id).style.height)>=soll) ? Math.ceil((soll-1)/15)*-1 : Math.ceil((soll-1)/15);
	el(id).style.height=parseInt(el(id).style.height)+plus+"px";
	if ((plus>0 && parseInt(el(id).style.height)<=soll) || (plus<0 && parseInt(el(id).style.height)>45)){
		setTimeout("togglechat('"+id+"','"+soll+"','"+plus+"')",0);
	}
	sessionStorage.chat=(plus>0)?1:0;
}

function bild(src){
	if (src){
		el('fotoframef').src=src;
		if (el('fotoframef').complete==true) {
			el("inhalt").style.opacity = el("menu").style.opacity = 0.4;
			el('fotoframe').style.visibility='visible';
		}
	}
	else {
		el("inhalt").style.opacity = el("menu").style.opacity = 1;
		el('fotoframe').style.visibility='hidden';
	}
}

var pre=new Array;
function initselect(x){
	if (x=='a') for (var i=0;i<5;i++) el('stern'+i).src=pre[i]; // alten stand wiederherstellen
	else {
		for (var i=0;i<5;i++) pre[i]=el('stern'+i).src; //alten stand sichern
		
		for (var i=0;i<x+1;i++) el('stern'+i).src="bilder/design/stern1.png";
		for (var i=x+1;i<5;i++) el('stern'+i).src="bilder/design/stern2.png";
	}
}

function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest)		return new XMLHttpRequest(); //Not IE
	else if(window.ActiveXObject)	return new ActiveXObject("Microsoft.XMLHTTP"); //IE
}			

var StatusReq = getXmlHttpRequestObject();		
function mehrkommentare(seite,page) {
	if (StatusReq.readyState == 4 || StatusReq.readyState == 0) {
		el('laden').src='bilder/design/load.gif';
		StatusReq.open("GET", "ajax.php?request=kommentare&seite="+parseInt(seite)+"&page="+page+"&cache="+Math.round(Math.random()*100000+1), true);
		StatusReq.onreadystatechange = UpdateStatus; 
		StatusReq.send(null);
	}
}

function addkommentare(page) {
	var captcha=document.getElementById('capkommentar').value;
	var commentname=escape(el('commentname').value.replace (/^\s+/, '').replace (/\s+$/, ''));
	var commenttext=escape(el('commenttext').value.replace (/^\s+/, '').replace (/\s+$/, ''));
	if (StatusReq.readyState == 4 || StatusReq.readyState == 0) {
		el('laden').src='bilder/design/load.gif';
		StatusReq.open("GET", "ajax.php?request=addkommentar&captcha="+captcha+"&commentname="+commentname+"&commenttext="+commenttext+"&page="+page+"&cache="+Math.round(Math.random()*100000+1), true);
		StatusReq.onreadystatechange = UpdateStatus; 	StatusReq.send(null);
	}
	toggle('kommentar',57,1);
}

function addgb(captcha) {
	var name=escape(el('name').value.replace (/^\s+/, '').replace (/\s+$/, ''))
	var mail=escape(el('mail').value.replace (/^\s+/, '').replace (/\s+$/, ''))
	var site=escape(el('site').value.replace (/^\s+/, '').replace (/\s+$/, ''))
	var text=escape(el('text').value.replace (/^\s+/, '').replace (/\s+$/, ''))
	if (StatusReq.readyState == 4 || StatusReq.readyState == 0) {
		el('laden').src='bilder/design/load.gif';
		StatusReq.open("GET", "ajax.php?request=gbschreiben&captcha="+el(captcha).value+"&name="+name+"&mail="+mail+"&site="+site+"&text="+text+"&cache="+Math.round(Math.random()*100000+1), true);
		StatusReq.onreadystatechange = UpdateStatus; 	StatusReq.send(null);
	}
}

function kontakt(captcha) {
	if (StatusReq.readyState == 4 || StatusReq.readyState == 0) {
		el('laden').src='bilder/design/load.gif';
		StatusReq.open("GET", "ajax.php?request=kontakt&name="+el("kontaktname").value+"&mail="+el("kontaktmail").value+"&text="+el("kontakttext").value+"&captcha="+el(captcha).value+"&cache="+Math.round(Math.random()*100000+1), true);
		StatusReq.onreadystatechange = UpdateStatus; 	StatusReq.send(null);
	}
}

function empfehlen(captcha) {
	if (StatusReq.readyState == 4 || StatusReq.readyState == 0) {
		el('laden').src='bilder/design/load.gif';
		StatusReq.open("GET", "ajax.php?request=empfehlen&sendername="+el("sendername").value+"&empfaengername="+el("empfaengername").value+"&sendermail="+el("sendermail").value+"&empfaengermail="+el("empfaengermail").value+"&kommentar="+el("empfkommentar").value+"&captcha="+el(captcha).value+"&cache="+Math.round(Math.random()*100000+1), true);
		StatusReq.onreadystatechange = UpdateStatus; 	StatusReq.send(null);
	}
}

function bewerten(stern,page) {
	if (StatusReq.readyState == 4 || StatusReq.readyState == 0) {
		el('laden').src='bilder/design/load.gif';
		StatusReq.open("GET", "ajax.php?request=bewerten&stern="+parseInt(stern)+"&page="+page+"&cache="+Math.round(Math.random()*100000+1), true);
		StatusReq.onreadystatechange = UpdateStatus; 	StatusReq.send(null);
	}
}

function captchareload(id) {
	if (StatusReq.readyState == 4 || StatusReq.readyState == 0) {
		el('laden').src='bilder/design/load.gif';
		StatusReq.open("GET", "ajax.php?request=captcha&id="+id+"&cache="+Math.round(Math.random()*100000+1), true);
		StatusReq.onreadystatechange = UpdateStatus; 	StatusReq.send(null);
	}
}

function online() {
	if (StatusReq.readyState == 4 || StatusReq.readyState == 0) {
		StatusReq.open("GET", "ajax.php?request=online&cache="+Math.round(Math.random()*100000+1), true);
		StatusReq.onreadystatechange = UpdateStatus; 	StatusReq.send(null);
	}
}

function neugierwecker() {
	if (StatusReq.readyState == 4 || StatusReq.readyState == 0) {
		el('laden').src='bilder/design/load.gif';
		StatusReq.open("GET", "ajax.php?request=neugierwecker&cache="+Math.round(Math.random()*100000+1), true);
		StatusReq.onreadystatechange = UpdateStatus; 	StatusReq.send(null);
	}
}

function UpdateStatus() {
	if (StatusReq.readyState == 4) {
		eval(StatusReq.responseText);
		el('laden').src='bilder/design/blind.gif';
	}
}



var chatstat=0;
function chatstart(){
	if (chatstat==0) { lesen(); chatstartinterval= window.setInterval('lesen();',3000); chatstat=1;}
}

var leseReq = getXmlHttpRequestObject();		
function lesen() {
	var lastID=el("lastID").value;
	
	if (leseReq.readyState == 4 || leseReq.readyState == 0) {
		leseReq.open("GET", "ajax.php?request=chatlesen&&lastID=" + lastID + "&&cache="+Math.round(Math.random()*100000+1), true);
		leseReq.onreadystatechange = UpdateChat; 	leseReq.send(null);
	}
}
function UpdateChat() {
	if (leseReq.readyState == 4) eval(leseReq.responseText);
}

var schreibeReq = getXmlHttpRequestObject();
function schreiben() {
	var Text=escape(el("ctext").value.replace (/^\s+/, '').replace (/\s+$/, ''));
	
	if (Text && (schreibeReq.readyState == 4 || schreibeReq.readyState == 0)) {
		schreibeReq.open("GET", "ajax.php?request=chatschreiben&&text=" + Text, true);
		schreibeReq.onreadystatechange = ClearInput; 	schreibeReq.send(null);
	}
}
function ClearInput() {
	if (schreibeReq.readyState == 4) { el("ctext").value = ""; eval(schreibeReq.responseText); }
}