function txt_auszeichnung(ff_id, mark_start, mark_ende, mark_txt) {
	/*  Copyright 2004 Patrick R. Michaud (pmichaud@pobox.com)
    	This file is part of PmWiki; you can redistribute it and/or modify
	    it under the terms of the GNU General Public License as published
    	by the Free Software Foundation; either version 2 of the License, or
	    (at your option) any later version.  See pmwiki.php for full details.
	*/
	var tarea = document.getElementById(ff_id);
	if (tarea.setSelectionRange > '') {
		var p0 = tarea.selectionStart;
		var p1 = tarea.selectionEnd;
		var top = tarea.scrollTop;
		var str = mark_txt;
		var cur0 = p0 + mark_start.length;
		var cur1 = p0 + mark_start.length + str.length;
		while (p1 > p0 && tarea.value.substring(p1-1, p1) == ' ') p1--; 
		if (p1 > p0) {
			str = tarea.value.substring(p0, p1);
			cur0 = p0 + mark_start.length + str.length + mark_ende.length;
			cur1 = cur0;
		}
		tarea.value = tarea.value.substring(0,p0)
			+ mark_start + str + mark_ende
			+ tarea.value.substring(p1);
		tarea.focus();
		tarea.selectionStart = cur0;
		tarea.selectionEnd = cur1;
		tarea.scrollTop = top;
	} else if (document.selection) {
		var str = document.selection.createRange().text;
		tarea.focus();
		range = document.selection.createRange()
		if (str == '') {
			range.text = mark_start + mark_txt + mark_ende;
			range.moveStart('character', -mark_ende.length - mark_txt.length );
			range.moveEnd('character', -mark_ende.length );
		} else {
			if (str.charAt(str.length - 1) == " ") {
				mark_ende = mark_ende + " ";
				str = str.substr(0, str.length - 1);
			}
			range.text = mark_start + str + mark_ende;
		}
	range.select();
	} else { tarea.value += mark_start + mark_txt + mark_ende; }
  return;
}

function aufklappen(idHTML, idLink, se_auf, se_zu) {
	if($(idHTML).style.display == 'none') {
		Effect.BlindDown(idHTML, {duration:0.8});
		Effect.Fade(idLink, {duration:0.4});
		setTimeout("$('"+idLink+"').innerHTML = '"+se_zu+"';",400);
		setTimeout("$('"+idLink+"').removeClassName('aufklappen');",400);
		setTimeout("$('"+idLink+"').addClassName('zuklappen');",400);
		setTimeout("Effect.Appear('"+idLink+"', {duration:0.4});",400);
	} else {
		Effect.BlindUp(idHTML, {duration:0.8});
		Effect.Fade(idLink, {duration:0.4});
		setTimeout("$('"+idLink+"').innerHTML = '"+se_auf+"';",400);
		setTimeout("$('"+idLink+"').removeClassName('zuklappen');",400);
		setTimeout("$('"+idLink+"').addClassName('aufklappen');",400);
		setTimeout("Effect.Appear('"+idLink+"', {duration:0.4});",400);
	}
}

function bbLinkIntern(ff_id, mark_start, mark_ende, mark_txt, id_select, popup_name) {
	txt_auszeichnung(ff_id, mark_start+$(id_select).value+' ', mark_ende, mark_txt);
	popupDivBB(ff_id, popup_name);
	$(id_select).value = 0;
}

function emptyInputOnFocus(idInput, valueStandard) {
	if($(idInput).value == valueStandard) {
		$(idInput).removeClassName('value_standard');
		$(idInput).value = '';
	} else {
		$(idInput).select();
	}
}

function emptyInputOnBlur(idInput, valueStandard) {
	if($(idInput).value == '') {
		$(idInput).value = valueStandard;
		$(idInput).addClassName('value_standard');
	} else {
		$(idInput).removeClassName('value_standard');
	}
}

function auswahl_sprache() {
	// gibt die ausgewählte Sprache beim Sprachauswahl-Formular zurück
	// wird als »aendern_zu« in die Ajax-Funktion »sprache_aendern()« übergeben
	var selected_index = $('form_sprachwahl').elements['sprachliste'].selectedIndex;
	return $('form_sprachwahl').elements['sprachliste'].options[selected_index].value;
}

function popupUpload(was, modul, idElement) {
	popup = window.open(rootDir+"upload.php?was="+was+"&modul="+modul+"&id_modulelement="+idElement+"", "neufenster", "width=700,height=550,location=0,scrollbars=1,menubar=0,toolbar=0,status=1,resizable=1,screenX=300,screenY=50");
	popup.focus();
}

function zeigeEditSelect(verzeichnis,idItem,divEdit) {
	divEditName = divEdit+'_'+idItem;
	if($(divEditName).style.display == 'none') {
		$(divEditName).setStyle('display:block');
	} else {
		$(divEditName).setStyle('display:none');
	}
}

function loadURLfromSelect(idSelect,setSelection) {
	window.location.href = $(idSelect).value;
	$(idSelect).value = setSelection;
}

function showPopupDiv(divID, chgZNx) {
	// wenn chgZNx gesetzt ist, wird die Z-Index-Reihenfolge der Top-Navigation und des Inhaltsfeldes getauscht
	// (z. B. bei Aufruf der Bearbeiten-Auswahlliste in der Liste der angelegten Seiten, da diese sonst bei den ersten Seiten teilweise unter der Top-Navigation verschwinden würde)
	if($(divID).style.display == 'none') {
//		Effect.Appear(divID, {duration:0.4});
		$(divID).setStyle('display:block');
		if(chgZNx) {
			$('inhalt_oben').setStyle('z-index:1');
			$('inhalt_unten').setStyle('z-index:2');
		}
	} else {
//		Effect.Fade(divID, {duration:0.4});
		$(divID).setStyle('display:none');
		if(chgZNx) {
			$('inhalt_oben').setStyle('z-index:2');
			$('inhalt_unten').setStyle('z-index:1');
		}
	}
}

function popupDivBB(idFF, divName) {
	divID = idFF+'_'+divName;
	if($(divID).style.display == 'none') {
		Effect.Appear(divID, {duration:0.8});
	} else {
		Effect.Fade(divID, {duration:0.8});
	}
}

function focus_form(aktion) {
	if(aktion != '') {
		formFocusNo = (document.forms.length > 1) ? 1 : 0;
		for(var i=0; i<document.forms[formFocusNo].elements.length; i++) {
			if(document.forms[formFocusNo].elements[i].type == 'text') {
				document.forms[formFocusNo].elements[i].focus();
				break;
			}
		}
	}
}

function refreshH2(idInput) {
	if($('form_h2_item_name')) {
		$('form_h2_item_name').innerHTML = $(idInput).value;
	}
}

function refreshH2TitelURL(idInput) {
	refreshH2(idInput);
	if($('ff_titel_url')) {
//		if($('ff_titel_url').value == '') {
			var titel_url = $(idInput).value.toLowerCase();
			/*
			var titel_url = titel_url.substr(0, 25);
			var letztes_leerzeichen = titel_url.lastIndexOf(' ');
			var titel_url = (letztes_leerzeichen > 0) ? titel_url.substr(0, letztes_leerzeichen) : titel_url;
			*/
			var arr_suchen = 	new Array(/ /g, /ö/g, /ä/g, /ü/g, /ß/g, /á/g, /à/g, /â/g, /ǎ/g, /å/g, /ã/g, /æ/g, /ç/g, /č/g, /ĉ/g, /è/g, /é/g, /ê/g, /ě/g, /ë/g, /ì/g, /í/g, /î/g, /ǐ/g, /ï/g, /ł/g, /ǹ/g, /ń/g, /ñ/g, /ň/g, /ò/g, /ó/g, /ô/g, /õ/g, /ǒ/g, /ø/g, /œ/g, /ř/g, /š/g, /ù/g, /ú/g, /ũ/g, /û/g, /ǔ/g, /ž/g, /ẑ/g, /[^a-z0-9\-]/g);
			var arr_ersetzen = 	new Array('-',  'oe', 'ae', 'ue', 'ss', 'a',  'a',  'a',  'a',  'a',  'a',  'ae', 'c',  'c',  'c',  'e',  'e',  'e',  'e',  'e',  'i',  'i',  'i',  'i',  'i',  'l',  'n',  'n',  'n',  'n',  'o',  'o',  'o',  'o',  'o',  'oe', 'oe', 'r',  's',  'u',  'u',  'u',  'u',  'u',  'z',  'z',  '_');
			for(i=0; i<arr_suchen.length; i++) {
				var titel_url = titel_url.replace(arr_suchen[i], arr_ersetzen[i]);
			}
			if($('ff_titel_url').value == '') {
				$('ff_titel_url').value = titel_url;
			}
//		}
	}
}

function show_form_anmeldung() {
	// zeigt das per CSS versteckte Anmelde-Formular und versteckt das DIV mit dem JS-Warnung
	if($('hide_with_js')) {
		$('hide_with_js').setStyle('display:none');
		$('formular_anmeldung').setStyle('display:block');
	}
	if($('form_sprachwahl')) {
		$('form_sprachwahl').setStyle('display:block');
	}
}

function closeDIV(idElement) {
	Effect.Fade(idElement, {duration:1.0});
}

function body_onload(logoutSeconds, verzeichnis, aktion) {
	globalVarVerzeichnis = verzeichnis;
	globalVarAktion = aktion;
	show_form_anmeldung();
	countdownStart(logoutSeconds);
	preloadImages();
	return focus_form(aktion);
}

function cmtShowConfig() {
	// bei Kommentar-Freigabe: einblenden der Freigabe-Einstellungen:
	if($('ff_cmt_permit').checked) {
		Effect.BlindDown('div_cmt_config', {duration:0.4});
	} else {
		Effect.BlindUp('div_cmt_config', {duration:0.4});
	}
}

function cmtShowSelectRedakteur() {
	// bei Kommentar-Veröffentlichung nach redaktioneller Freigabe: einblenden der Auswahl des Redakteurs:
	if($('ff_cmt_publish').value == 3) {
		Effect.BlindDown('p_cmt_redakteur', {duration:0.4});
	} else {
		Effect.BlindUp('p_cmt_redakteur', {duration:0.4});
	}
}

function showEditCmt(idCmt) {
	// blendet das Kommentar-Editieren-Formular ein oder aus 
	idShow = 'cmt_show_'+idCmt;
	idEdit = 'cmt_edit_'+idCmt;
	if($(idEdit).style.display == 'none') {
		Effect.Fade(idShow, {duration:0.4});
		setTimeout("Effect.Appear('"+idEdit+"', {duration:0.4})",300);
	} else if($(idShow).style.display == 'none') {
		Effect.Fade(idEdit, {duration:0.4});
		setTimeout("Effect.Appear('"+idShow+"', {duration:0.4})",300);
	}
}

function seShowDetails(seGroup) {
	// zeigt die Sprachschnipsel der jeweiligen Gruppen an
	idDIV = 'div_se_'+seGroup;
	if($(idDIV).style.display == 'none') {
		Effect.BlindDown(idDIV, {duration:0.8});
	} else {
		Effect.BlindUp(idDIV, {duration:0.8});
	}
}

/*-----------------------------------------
	Preload-Image-Scripte
//---------------------------------------*/

function newImage(arg) {
	if(document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

var preloadFlag = false;
function preloadImages() {
	if(document.images) {
		hover_1 =  newImage(rootDir + "__graphix/konfiguration_hov.png");
		hover_2 =  newImage(rootDir + "__graphix/neuer_eintrag_hov.png");
		hover_3 =  newImage(rootDir + "__graphix/popup_close_hov.png");
		hover_4 =  newImage(rootDir + "__graphix/sprechblase_hov.png");
		hover_5 =  newImage(rootDir + "__graphix/popup_div_150px_mitte.png");
		hover_6 =  newImage(rootDir + "__graphix/popup_div_150px_oben.png");
		hover_7 =  newImage(rootDir + "__graphix/popup_div_150px_unten.png");
		hover_8 =  newImage(rootDir + "__graphix/popup_div_200px_mitte.png");
		hover_9 =  newImage(rootDir + "__graphix/popup_div_200px_oben.png");
		hover_10 = newImage(rootDir + "__graphix/popup_div_200px_unten.png");
		hover_11 = newImage(rootDir + "__graphix/popup_div_300px_mitte.png");
		hover_12 = newImage(rootDir + "__graphix/popup_div_300px_oben.png");
		hover_13 = newImage(rootDir + "__graphix/popup_div_300px_unten.png");
		hover_14 = newImage(rootDir + "__graphix/popup_div_500px_mitte.png");
		hover_15 = newImage(rootDir + "__graphix/popup_div_500px_oben.png");
		hover_16 = newImage(rootDir + "__graphix/popup_div_500px_unten.png");
		hover_17 = newImage(rootDir + "__graphix/popup_div_700px_mitte.png");
		hover_18 = newImage(rootDir + "__graphix/popup_div_700px_oben.png");
		hover_19 = newImage(rootDir + "__graphix/popup_div_700px_unten.png");
		hover_20 = newImage(rootDir + "__graphix/o_li.gif");
		hover_21 = newImage(rootDir + "__graphix/o_re.gif");
		hover_22 = newImage(rootDir + "__graphix/u_li.gif");
		hover_23 = newImage(rootDir + "__graphix/u_re.gif");

		preloadFlag = true;
	}
}
/*-----------------------------------------
	Logout-Countdown
//---------------------------------------*/

var countdownDIV = 'js_countdown';

function countdownStart(logoutSeconds) {
	if(logoutSeconds > 0) {
		displayCountdown(logoutSeconds); // Anzeige der aktuellen Countdown-Zeit
		setTimeout("countdownProceed("+logoutSeconds+")",1000); // nach 1 Sekunde Aufruf der Funktion countdownProceed
	}
}

function countdownProceed(logoutSeconds) {
	// im Unterschied zu countdownStart() wird hier die übergebene Zeit in Sekunden zuerst um 1 runtergezählt
	if(logoutSeconds > 0) {
		/* alle 2 Minuten speichern:
			speicherIntervall = 120;
			speichernJetzt = logoutSeconds/speicherIntervall;
			speichernJetztInt = parseInt(speichernJetzt); // erstellt einen Integer-Wert aus einem numerischen
			if(speichernJetzt == speichernJetztInt) {
				itemSpeichern(globalVarVerzeichnis);
			}
		// automatisches Intervall-Speichern zu Ende
		*/
		--logoutSeconds; // dekrementieren
		displayCountdown(logoutSeconds);
		setTimeout("countdownProceed("+logoutSeconds+")",1000); // Funktion ruft sich nach 1 Sekunde selbst neu auf
	} else {
		if(itemSpeichern(globalVarVerzeichnis, globalVarAktion)) {
			// die globalen Variablen globalVarVerzeichnis und globalVarAktion werden in der Funktion body_onload() definiert
			location.reload(true);
		}
	}
}

function displayCountdown(logoutSeconds) {
	// Aufruf in countdownStart() und countdownProceed()
	seconds = logoutSeconds;

	echoMinutes = Math.floor(seconds/60);
	echoSeconds = String(seconds-echoMinutes*60);
	echoLeadingZero = (echoSeconds.match(/^\d{1}$/g)) ? "0" : "";

	if($(countdownDIV)) { $(countdownDIV).innerHTML = echoMinutes+":"+echoLeadingZero+echoSeconds+" "; }
}

/*-----------------------------------------
	Overlay-DIV
-----------------------------------------*/

function displayOverlay(wert,duration) {
	overlayOpacity = 0.7;	// controls transparency of shadow overlay
	overlayDuration = (!duration) ? 0.8 : duration;	// shadow fade in/out duration
	arrayPageSize = getPageSize();
//	$('overlay').setStyle("width:"+arrayPageSize[0]+"px;");
//	$('overlay').setStyle("height:"+arrayPageSize[1]+"px;");
	setTimeout("$('overlay').setStyle('width:'+arrayPageSize[0]+'px;');",300);
	setTimeout("$('overlay').setStyle('height:'+arrayPageSize[1]+'px;');",300);

	if(!wert || wert == 'Appear') { new Effect.Appear('overlay', { duration: overlayDuration, from: 0.0, to: overlayOpacity }); }
	if(wert == 'Fade') { new Effect.Fade('overlay', { duration: overlayDuration, from: overlayOpacity, to: 0.0 }); }
}

function getPageSize() {
	// Funktion aus lightbox.js

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	//	console.log(self.innerWidth);
	//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	//	console.log("xScroll " + xScroll)
	//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

