window.onload = init;
function init(){
	if (document.getElementById('diashow'))	diashow();
}
var bilder = '';
var curimg=0;
function diashow() {
	bilder = document.getElementById('diashow').getElementsByTagName('img');
	if (bilder.length>1) {
		rotateimages();
		setInterval("rotateimages()", 5000);
}	}
function rotateimages() {
	for (i=0;i<bilder.length;i++) {
		bilder[i].parentNode.parentNode.style.display="none";
	}
	bilder[curimg].parentNode.parentNode.style.display="block";
	window.curimg=(window.curimg<bilder.length-1)? window.curimg+1 : 0;
} 
function addimg(src) {
	var anz_bilder = document.getElementById('bildupload').getElementsByTagName('input').length;
	var newinput1 = document.createElement('input');
	if (anz_bilder<7) {
		newinput1.setAttribute("name", "bild[forum_"+anz_bilder+"]", 0);
		newinput1.setAttribute("type", "file", 0);
		newinput1.setAttribute("size", "30", 0);
		newinput1.setAttribute("value", "", 0);
		document.getElementById('bildupload').appendChild(newinput1);
	}
	else alert(document.getElementById('bildzahl').innerHTML);
//	alert(document.getElementById('bildupload').innerHTML);
} 
function showimg(src) {
	var bild_window = window.open("","Bild","toolbar=no,width=700,height=500,directories=no,scrollbars,status=no,menubar=no,resizable=yes");
	bild_window.document.writeln('<html><head>');
	bild_window.document.writeln('</head><body onblur="self.close()" style="height:90%;background: url(/'+src.replace('thumbs/','')+') no-repeat center">');
	bild_window.document.writeln('<div style="position:absolute;right:3px;bottom:3px;"><a href="javascript:" onclick="self.close()">Schliessen</a></div>');
	bild_window.document.writeln('</body></html>');
	bild_window.document.close();
	bild_window.focus();
}
function gb_verify() {
	var verify = Math.random();
	if (document.getElementById('gb_verify'))
		document.getElementById('gb_verify').innerHTML ='<input type="hidden" name="verify" value="'+verify+'" />';
}
function header(id)	{edit("[h]","[/h]","header",id);}
function fett(id)	{edit("[b]","[/b]","fett",id);}
function italic(id)	{edit("[i]","[/i]","italic",id);}
function uline(id) 	{edit("[u]","[/u]","uline",id);}
function addSmiley(smiley,id) {edit("","["+smiley+"]",smiley,id);}
function url(id) {
	addurl = prompt("Bitte geben Sie die gewünschte URL ein:", "http://");
	edit("[url="+addurl+"]","[/url]","url",id);
}
function edit(start,end,id) {
	var textfield = document.getElementsByTagName('textarea')[0];
	if (textfield.selectionStart || textfield.selectionStart == '0') {
		textfield.focus();
		var startPos = textfield.selectionStart;
		var endPos = textfield.selectionEnd;
		strSelection = start + textfield.value.substring(startPos, endPos)+ end;
		textfield.value = textfield.value.substring(0, startPos) + strSelection + textfield.value.substring(endPos, textfield.value.length);
	}
	else if (document.selection && document.selection.createRange().text != '') {
		document.selection.createRange().text = start + document.selection.createRange().text + end;
	}
	else {
		if (document.getElementById(id).style.color=="#aaa") {
			textfield.value += end;
			document.getElementById(id).style.color="blue";
		}
		else {
			textfield.value += start;
			document.getElementById(id).style.color="#aaa";
}	}	}
function vorschau() {
	var textarea = document.getElementsByTagName('textarea')[0].value.split('[');
	vorschautext = textarea[0];
	for (var i=0; i<textarea.length; i++) {
		bracket = textarea[i].split(']')[0];
		if (bracket == 'b')		vorschautext += '<span style="font-weight: bolder;">' + textarea[i].split('b]')[1].split('/b]')[0];
		if (bracket == 'i')		vorschautext += '<span style="font-style: italic;">' + textarea[i].split('i]')[1].split('/i]')[0];
		if (bracket == 'u')		vorschautext += '<span style="text-decoration: underline;">' + textarea[i].split('u]')[1].split('/u]')[0];
		if (bracket == '/b' || bracket == '/i' || bracket == '/u') 	vorschautext += '</span>' + textarea[i].split(']')[1];
		else {
			if (document.getElementById(bracket) && bracket != '') {
				vorschautext +=  '<img src="'+document.getElementById(bracket).src+'">'+textarea[i].split(']')[1];
	}	}	}
	vorschau_window = window.open('',"Vorschau","toolbar=no,width=500,height=200,directories=no,scrollbars,status=no,menubar=no,resizable=yes");
	vorschau_window.document.open();
	vorschau_window.document.writeln('<html><head>');
	vorschau_window.document.writeln('<title>Vorschau</title>');
	vorschau_window.document.writeln('</head><body onblur="self.close()">');
	vorschau_window.document.writeln('<p>'+vorschautext.replace('\n','<br />')+'</p>');
	vorschau_window.document.writeln('<div style="position:absolute;right:3px;bottom:3px;"><a href="javascript:" onclick="self.close()">Schließen</a></div>');
	vorschau_window.document.writeln('</body></html>');
	vorschau_window.document.close();
	vorschau_window.focus();
}
