window.onload = init;
var limitNum = new Array();
function init() {
	if(ie) {
		var menu = document.getElementById('links').getElementsByTagName('ul');
		for (i=0;i<menu.length;i++) {
			menu[i].setAttribute("id","menu"+i);
			if (menu[i].parentNode.nodeName == "LI") {
				menu[i].parentNode.onmouseover = function () {
					this.lastChild.style.display = "block";
				}
				menu[i].parentNode.onmouseout = function () {
					this.lastChild.style.display = "none";
	}	}	}	}
	if (top.location != self.location) {top.location = self.location.href;}
	if (document.getElementById('gesucheseite')) {
		var inputs = $('.textinput').get();
		for ( var i=0; i<inputs.length; i++ ) {
			if (inputs[i].id != '') {
				$("#"+inputs[i].id).after("&nbsp;<a href=\"javascript:\" onclick=\"document.getElementById('"+inputs[i].id+"').value='(keine Vorgabe)';return false;\">keine Vorgabe</a>");
	}	}	}
	if (document.getElementById('content')) {
		var images = document.getElementById('content').getElementsByTagName("img");
		for ( var i=0; i<images.length; i++ ) {
			var cn = images[i].className.split(' ');
			if (cn[0] == "bild") {
				$(images[i]).fancyzoom();
	}	}	}
	if (document.getElementsByTagName('textarea')) {
		var this_focus = '';
		var tas = document.getElementsByTagName('textarea');
		if (document.getElementsByTagName('form')) {
			var forms = document.getElementsByTagName('form');
			for ( var j=0; j<forms.length; j++ ) {
				forms[j].onsubmit = function () {
					if(document.getElementById('myfocus')) {
						document.getElementById('myfocus').value = this_focus
						var myfocus = document.getElementById(this_focus);
						if (document.getElementById(this_focus+'_cpos')) document.getElementById(this_focus+'_cpos').value = doGetCaretPosition(myfocus);
		}	};	}	}
		for ( var i=0; i<tas.length; i++ ) {
			if (tas[i].id) 	$(tas[i]).autogrow();
		}
		if (document.getElementById('myfocus') && document.getElementById('myfocus').value != '') {
			myfocus = document.getElementById('myfocus');
			this_focus = myfocus.value;
			if (document.getElementById(this_focus+'_cpos') && document.getElementById(this_focus+'_cpos').value > 0) {
				setCaretPosition(document.getElementById(this_focus),document.getElementById(this_focus+'_cpos').value);
			}
			if (document.getElementById(this_focus)) {
				document.getElementById(this_focus).focus();
				var this_parent = document.getElementById(this_focus).parentNode;
				window.scrollTop = this_parent.offsetTop + this_parent.offsetHeight + 'px';
}	}	}	}
function header(id)	{edit("[h]","[/h]","header",id);}
function list(id)	{edit("[list][*]","[/list]","list",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 hoch(id) 	{edit("[sup]","[/sup]","sup",id);}
function tief(id) 	{edit("[sub]","[/sub]","sub",id);}
function hr(id) 	{edit("[hr/]","","hr",id);}
function br(id) 	{edit("[br/]","","br",id);}
function table(id) 	{edit("[table]","[/table]","table",id);}
function tab(id) 	{edit("\t","","tab",id);}
function klein(id)  {edit("[small]","[/small]","small",id);}
function center(id) {edit("[center]","[/center]","center",id);}
function rechts(id) {edit("[rechts]","[/rechts]","rechts",id);}
function elinks(id)  {edit("[links]","[/links]","links",id);}
function pre(id) 	{edit("[pre]","[/pre]","pre",id);}
function color(color,id)					{edit("[color="+color+"]","[/color]","color",id);}
function verweise(add_verweis,add_text,id) 	{edit("","[url="+add_verweis+"]"+add_text+"[/url]","url",id);}
function url(id) 							{addurl = prompt(unescape("Bitte geben Sie den gew%FCnschten Link ein:"), "http://");edit("[url="+addurl+"]","[/url]","url",id);}
function addSmiley(id) {
	if (document.selection && document.selection.createRange().text != '') {
		document.selection.createRange().text = document.selection.createRange().text + "["+id+"]";
	}
	else {
		document.getElementsByTagName('textarea')[0].value += "["+id+"]";
		document.getElementsByTagName('textarea')[0].focus();
}	}
function show_or_hide(id,name,selected,group,groups) {
	if (groups != '') {
		var  gs = groups.split(',');
		for (var i=0; i<gs.length; i++) {
			if (group !=gs[i]) {
				$("."+gs[i]).hide();
				$("."+gs[i]).find("input").val("");
	}	}	}
	if (group != '') {
		var v = document.getElementById(id).value;
		if (document.getElementById(id).checked == true)	$("."+group).show();
		else 	{
			$("."+group).hide();
			$("."+group).find("input").val("");
	}	}
	if (hide_by_class[name]) {
		for (x in hide_by_class[name]) {
			if (hide_by_class[name][x] == selected) $("."+x).hide();
			else 									$("."+x).show();
	}	}
	if (show_by_class[name]) {
		for (x in show_by_class[name]) {
			if (show_by_class[name][x] == selected) $("."+x).show();
			else 									$("."+x).hide();
}	}	}
function mylink(id) {
	vorschau_window = window.open('/mylink.php?id='+id,"Link","toolbar=no,width=330,height=370,directories=no,scrollbars,status=no,menubar=no,resizable=yes");
	vorschau_window.focus();
}
function bilder(id,sessid) {
	vorschau_window = window.open('/bilder.php?id='+id+'&PHPSESSID='+sessid,"bilder","toolbar=no,width=400,height=500,directories=no,scrollbars,status=no,menubar=no,resizable=yes");
	vorschau_window.focus();
}
function verweis(id) {
	var site_id = document.getElementById('site_id').value;
	vorschau_window = window.open('/verweis.php?id='+id+'&site_id='+site_id,"Verweis","toolbar=no,width=330,height=370,directories=no,scrollbars,status=no,menubar=no,resizable=yes");
	vorschau_window.focus();
}
function cp(id) {
	vorschau_window = window.open('/cp2.html?id='+id,"Farben","toolbar=no,width=330,height=370,directories=no,scrollbars,status=no,menubar=no,resizable=yes");
	vorschau_window.focus();
}
function bbremover(this_focus) {
	if (this_focus == '') this_focus = 'textarea';
	var textfield = document.getElementById(this_focus);
	var ot = textfield.scrollTop,ol = textfield.scrollLeft;
    var pattern = new RegExp(/\[[^\]]*\]/g);
	if (textfield.selectionStart || textfield.selectionStart == '0') {
		textfield.focus();var startPos = textfield.selectionStart;var endPos = textfield.selectionEnd;
		strSelection = textfield.value.substring(startPos, endPos);
		textfield.value = textfield.value.substring(0, startPos) + strSelection.replace(pattern,"") + textfield.value.substring(endPos, textfield.value.length);
	}
	else if (document.selection && document.selection.createRange().text != '') {
		document.selection.createRange().text = document.selection.createRange().text.replace(pattern,"");
	}
	else if (document.selection) {
		var cpos = caret(textfield);
		textfield.value = textfield.value.replace(pattern,"");
	}
	textfield.focus(); 
	if (typeof(textfield.selectionStart) != "undefined") {
		textfield.scrollTop=ot;
	}
}
function edit(start,end,id,ta) {
	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 {
			if (start == '')	strSelection = 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')	document.selection.createRange().text = document.selection.createRange().text.replace(/(\r\n|\r|\n)/g, '\n[*]');
		if (start == '')	document.selection.createRange().text = end;
		else				document.selection.createRange().text = start + document.selection.createRange().text + end;
	}
	else if (document.selection) {
		var cpos = caret(textfield);
		textfield.value = textfield.value.substring(0,cpos) +  start  + end  + textfield.value.substring(cpos,textfield.value.length);
	}
	textfield.focus(); 
	if (typeof(textfield.selectionStart) != "undefined") {
		textfield.selectionStart = startPos+start.length;
		textfield.selectionEnd = endPos+start.length;
		textfield.scrollTop=ot;
}	}
function insert_image(ipath,bildid,siteid) {
	if (this_focus == '') this_focus = 'textarea';
	var textfield = document.getElementById(this_focus);
	var align = document.getElementById('align_'+bildid).value;
	var size = document.getElementById('size_'+bildid).value;
	var alt = document.getElementById('alt_'+bildid).value;
	var caretPos = doGetCaretPosition (textfield);
	if (size == 'big')  			ipath = ipath.replace('/thumbs','');
	else if (size == 'original')  	ipath = ipath.replace('/thumbs','/originale').replace(siteid+'_','');
	textfield.value = textfield.value.substring(0, caretPos) + "[bild="+ipath+" align="+align+" alt="+escape(alt)+"/]" + textfield.value.substring(caretPos, textfield.value.length);
}
function remove_image(ipath,bildid,siteid) {
	if (this_focus == '') this_focus = 'textarea';
	var textfield = document.getElementById(this_focus);
	var alt = document.getElementById('alt_'+bildid).value;
	var textfield = document.getElementById(this_focus);textfield.value = textfield.value.replace("[bild="+ipath+" align=left alt="+escape(alt)+"/]", "");
	var textfield = document.getElementById(this_focus);textfield.value = textfield.value.replace("[bild="+ipath+" align=right alt="+escape(alt)+"/]", "");
	opath = ipath.replace('/thumbs','/originale').replace(siteid+'_','');
	var textfield = document.getElementById(this_focus);textfield.value = textfield.value.replace("[bild="+opath+" align=left alt="+escape(alt)+"/]", "");
	var textfield = document.getElementById(this_focus);textfield.value = textfield.value.replace("[bild="+opath+" align=right alt="+escape(alt)+"/]", "");
	tpath = ipath.replace('/thumbs','');
	var textfield = document.getElementById(this_focus);textfield.value = textfield.value.replace("[bild="+tpath+" align=left alt="+escape(alt)+"/]", "");
	var textfield = document.getElementById(this_focus);textfield.value = textfield.value.replace("[bild="+tpath+" align=right alt="+escape(alt)+"/]", "");
}
function caret(node) {
	node.focus();  /* without node.focus() IE will returns -1 when focus is not on node */
	if(node.selectionStart) return node.selectionStart;
	else if(!document.selection) return 0;
	var c		= "\001";
	var sel	= document.selection.createRange();
	var dul	= sel.duplicate();
	var len	= 0;
	dul.moveToElementText(node);
	sel.text	= c;
	len		= (dul.text.indexOf(c));
	sel.moveStart('character',-1);
	sel.text	= "";
	if (len < 1) len = doGetCaretPosition (node);
	return len;
}
function doGetCaretPosition (ctrl) {
	var CaretPos = 0;
	if (document.selection) {	// IE Support
		ctrl.focus ();
		var Sel = document.selection.createRange ();
		Sel.moveStart ('character', -ctrl.value.length);
		CaretPos = Sel.text.length;
	}
	else if (ctrl.selectionStart || ctrl.selectionStart == '0')	// Firefox support
		CaretPos = ctrl.selectionStart;
	return (CaretPos);
}
function setCaretPosition(ctrl,pos) {
	if(ctrl.setSelectionRange) {
		ctrl.focus();
		ctrl.setSelectionRange(pos,pos);
	}
	else if (ctrl.createTextRange) {
		var range = ctrl.createTextRange();
		range.collapse(true);
		range.moveEnd('character', pos);
		range.moveStart('character', pos);
		range.select();
}	}
