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 emptyInputOnFocus(idInput, valueStandard) {
	if($(idInput).value == valueStandard) {
		$(idInput).removeClassName('value_standard');
		$(idInput).value = '';
	} else {
		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 focus_form() {
	if(document.forms.length > 0) {
		for(var i=0; i<document.forms[0].elements.length; i++) {
			if(document.forms[0].elements[i].type == 'text') {
				document.forms[0].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);
			var arr_ersetzen = new Array('-', 'oe', 'ae', 'ue', 'ss');
			for(i=0; i<arr_suchen.length; i++) {
				var titel_url = titel_url.replace(arr_suchen[i], arr_ersetzen[i]);
			}
			$('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 divQuickOpenClose(idElement, wert) {
	if(wert == 1) {
		$(idElement).setStyle('display:block');
//		Effect.Appear(idElement, {duration:0.5});
	} else if(wert == 0) {
		$(idElement).setStyle('display:none');
//		Effect.Fade(idElement, {duration:0.5});
	}
}

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

/*-----------------------------------------
	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 globale Variable globalVarVerzeichnis wird in der Funktion body_onload() definiert
			location.reload(true);
		}
	}
}

function displayCountdown(logoutSeconds) {
	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;
}
