function onoff(variable) {
  if (document.getElementById(variable).style.display == "none") document.getElementById(variable).style.display = "block";
  else document.getElementById(variable).style.display = "none";
}

function seitenmenu_onoff() {
	if (document.getElementById('seitenmenu').style.display == "none") {
		document.getElementById('seitenmenu').style.display = "block";
		document.getElementById('main').style.width = "550px";
		document.getElementById('sideBar').style.right = "21px";
		document.getElementById('sideBar').style.position = "relative";
		document.getElementById('sideBar').style.top = "0";
		document.getElementById('sideBar').style.margin = "0 5px 0 0";
	}
	else {
		document.getElementById('seitenmenu').style.display = "none";
		document.getElementById('main').style.width = "730px";
		document.getElementById('sideBar').style.right = "auto";
		document.getElementById('sideBar').style.position = "absolute";
		document.getElementById('sideBar').style.top = "237px";
		document.getElementById('sideBar').style.margin = "0 0 0 580px";
	}
}

function zeige(ordner,bild,x,y) {
	if (!x) x = 660;
	if (!y) y = 670;
	seite = './zeige_bild.php?ordner=' + ordner + '&bild=' + bild;
	optionen = 'scrollbars=auto,width=' + x + ',height=' + y;
	window.open(seite,'Bild',optionen);
}

function tooltip_an(variable) {
	document.getElementById('seitenfoto').style.display = "none";
	document.getElementById('tooltip').style.display = "block";
	document.getElementById(variable).style.display = "block";
}

function tooltip_aus(variable) {
	document.getElementById(variable).style.display = "none";
	document.getElementById('tooltip').style.display = "none";
	document.getElementById('seitenfoto').style.display = "block";
}

function einfuegen(tagOpen, tagClose, sampleText) {
	var txtarea;
	if (document.formular) {
		txtarea = document.formular.text;
	} 
	else {  				// some alternate form? take the first one we can find
		var areas = document.getElementsByTagName('textarea');
		txtarea = areas[0];
	}
	var selText, isSample = false;

	if (document.selection  && document.selection.createRange) { // IE/Opera
		//save window scroll position
		if (document.documentElement && document.documentElement.scrollTop)
			var winScroll = document.documentElement.scrollTop
		else if (document.body)
			var winScroll = document.body.scrollTop;
		//get current selection  
		txtarea.focus();
		var range = document.selection.createRange();
		selText = range.text;
		//insert tags
		checkSelectedText();
		range.text = tagOpen + selText + tagClose;
		//mark sample text as selected
		if (isSample && range.moveStart) {
			if (window.opera)
				tagClose = tagClose.replace(/\n/g,'');
			range.moveStart('character', - tagClose.length - selText.length); 
			range.moveEnd('character', - tagClose.length); 
		}
		range.select();   
		//restore window scroll position
		if (document.documentElement && document.documentElement.scrollTop)
			document.documentElement.scrollTop = winScroll
		else if (document.body)
			document.body.scrollTop = winScroll;

	} 
	else if (txtarea.selectionStart || txtarea.selectionStart == '0') { // Mozilla 
		//save textarea scroll position
		var textScroll = txtarea.scrollTop;
		//get current selection
		txtarea.focus();
		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		selText = txtarea.value.substring(startPos, endPos);
		//insert tags
		checkSelectedText();
		txtarea.value = txtarea.value.substring(0, startPos)
			+ tagOpen + selText + tagClose
			+ txtarea.value.substring(endPos, txtarea.value.length);
		//set new selection
		if (isSample) {
			txtarea.selectionStart = startPos + tagOpen.length;
			txtarea.selectionEnd = startPos + tagOpen.length + selText.length;
		} else {
			txtarea.selectionStart = startPos + tagOpen.length + selText.length + tagClose.length;
			txtarea.selectionEnd = txtarea.selectionStart;
		}
		//restore textarea scroll position
		txtarea.scrollTop = textScroll;   
	}
	 
	function checkSelectedText() {
		if (!selText) {
			selText = sampleText;
			isSample = true;
		} else if (selText.charAt(selText.length - 1) == ' ') { //exclude ending space char
			selText = selText.substring(0, selText.length - 1);
			tagClose += ' '
		} 
	}
}

function elink_einfuegen() {
	var elink = prompt('Bitte Adresse eingeben:','http://www.ADRESSE.DE/');
	if (elink) einfuegen('<a href="' + elink + '" target="_blank">','</a>','externer Link');
}

function datei_einfuegen(ordner) {
	var datei = prompt('Bitte vollständigen Datei-Namen (inkl. Endung) eingeben (Upload erfolgt dann weiter unten):','datei.doc');
	if (datei) einfuegen('<a href="./download/' + ordner + '/' + datei + '" target="_blank">','</a>','Datei');
}

function ilink_einfuegen() {
	var ilink_seite = prompt('Bitte Seiten-Name (kleingeschrieben) eingeben:','seite');
	var ilink_id = prompt('Ggf. ID der Unterseite:','');
	if (ilink_id) ilink_id = '&id=' + ilink_id;
	if (ilink_seite) einfuegen('<a href="index.php?seite=' + ilink_seite + ilink_id + '">','</a>','interner Link');
}

function getSelected(opt) {
   var selected = new Array();
   var index = 0;
   for (var intLoop = 0; intLoop < opt.length; intLoop++) {
      if ((opt[intLoop].selected) ||
          (opt[intLoop].checked)) {
         index = selected.length;
         selected[index] = new Object;
         selected[index].value = opt[intLoop].value;
         selected[index].index = intLoop;
      }
   }
   return selected;
}

function felderanzeigen(opt,seite) {
   var sel = getSelected(opt);
   var strSel = "";
   for (var item in sel) {
		if(sel[item].value) strSel += sel[item].value + ",";
	}
	var link = 'index.php?seite=' + seite + '&felder=' + strSel;
   document.location.href=link;
}
