// Copyright Marcus Haas
function check(){
	if (self != top) {
		top.location.href=self.location.href;
	}
	if (document.getElementsByTagName("img")[0]) {
		var images = document.getElementsByTagName("img");
		for ( var i=0; i<images.length; i++ ) {
			if (images[i].className != "link") {
				images[i].onclick = function () {showimg(this.src,this.alt)};
				images[i].style.cursor="pointer";
	}	}	}	
}
function showimg(src,alt) {
	var bild_window = window.open("http://"+window.location.hostname+"/bild.php?src="+src.replace(/-LQ.jpg/,".jpg")+"&alt="+alt,"Bild","toolbar=no,width=600,height=600,directories=no,scrollbars,status=no,menubar=no,resizable=yes");
	bild_window.document.close();
	bild_window.focus();
}
function color(color) {edit("[color="+color+"]","[/color]","color");}
function fett() {edit("[b]","[/b]","fett");}
function italic() {edit("[i]","[/i]","italic");}
function uline() {edit("[u]","[/u]","uline");}
function header() {edit("[h]","[/h]","header");}
function list() {edit("[list]","[/list]","list");}
function addSmiley(id) {edit("","["+id+"]","addSmiley");}
function url() {
	url = prompt("Bitte geben Sie die gewünschte URL ein:", "http://");
	edit("[url="+url+"]","[/url]","url");
}
function edit(start,end,id) {
	var ta = 'text';
	var textfield = document.getElementById(ta);
	var ot = textfield.scrollTop,ol = textfield.scrollLeft;
	if (textfield.selectionStart || textfield.selectionStart == '0') {
		textfield.focus();var startPos = textfield.selectionStart;var endPos = textfield.selectionEnd;
		if (id == 'list') strSelection = start + textfield.value.substring(startPos, endPos).replace(/(\r\n|\r|\n)/g, '\n[*]') + end;
		else 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 != '') {
		if (id == 'list') selection.createRange().text.replace(/(\r\n|\r|\n)/g, '\n[*]');
		document.selection.createRange().text = start + document.selection.createRange().text + end;
	}
	else {textfield.value += end + start;
		if (document.getElementById(id).style.color=="#aaa") document.getElementById(id).style.color="blue";
		else {textfield.value += start;document.getElementById(id).style.color="#aaa";}
	}
	if (typeof(textfield.selectionStart) != "undefined") {
		textfield.selectionStart = startPos+start.length;
		textfield.selectionEnd = endPos+start.length;
		textfield.scrollTop=ot;
	}
}