function confirmAction(theMessage){

    if (typeof(window.opera) != 'undefined') {
        return true;
    }

    var is_confirmed = confirm(theMessage);

    return is_confirmed;
}

function subselect(){

	document.getElementById("articleList").className = "invisible";
	document.getElementById("galleryList").className = "invisible";
	
	if (document.getElementById("homeModulSelector").value=="wiki"){
		document.getElementById("articleList").className = "visible";
	}else if (document.getElementById("homeModulSelector").value=="gallery"){
		document.getElementById("galleryList").className = "visible";
	}

	
return true;
}

// SUCHBUTTONS

searchIsDisabled = false;

function searchChange(e) {
    var value = e.value.replace(/\s+/, '');
    if (value == '' || searchIsDisabled) {
        searchSetDisabled(true);
    } else {
        searchSetDisabled(false);
    }
}

function searchSetDisabled(flag) {
    // Enable or disable search
    document.getElementById('searchbutton').disabled = flag;
}

function searchFocus(e) {
    // Update search input content on focus
    if (e.value == 'Suche') {
        e.value = '';
        e.className = '';
        searchIsDisabled = false;
    }
}

function searchBlur(e) {
    // Update search input content on blur
    if (e.value == '') {
        e.value = 'Suche';
        e.className = 'disabled';
        searchIsDisabled = true;
    }
}

function positionSelection(selectionIndex,arrowIndex){
	if(document.getElementById('menuTarget')){
		document.getElementById('menuTarget').checked = true;
		updateTreeSelectorDisplay();	
	}
	document.getElementById('position').value=selectionIndex;
	i=1;
	while(currentElement = document.getElementById("insertItem"+i))
	{
		if(i == arrowIndex){
			currentElement.className="arrowselect";
		}else{
			currentElement.className="arrow";
		}
		i++;
	}
}

function menuExtLink(){
	if (document.getElementById("menuModulSelector").value=="external"){
		document.getElementById("extLinkTr").className = "visible";
	}else{
		document.getElementById("extLinkTr").className = "invisible";
	}
	
	/* Enable the correct InsertionsLinks */
	if(document.getElementById("menuModulSelector").value == "folder"){
		elements = document.getElementsByName('insertionLinkPage');
		for (var i = 0; i < elements.length; ++i) {
			elements[i].style.visibility = 'hidden';
		}

		elements2 = document.getElementsByName('insertionLinkFolder');
		for (var i = 0; i < elements2.length; ++i) {
			elements2[i].style.visibility = 'visible';
		}
	}else{
		elements = document.getElementsByName('insertionLinkPage');
		for (var i = 0; i < elements.length; i++) {
			elements[i].style.visibility = 'visible';
		}

		elements2 = document.getElementsByName('insertionLinkFolder');
		for (var i = 0; i < elements2.length; i++) {
			elements2[i].style.visibility = 'hidden';
		}
	}
}


function change_edit_input_state(){
	if (document.getElementById("news_titel").disabled == true){
		document.getElementById("news_titel").disabled = false;
		document.getElementById("news_text").disabled = false;
	}else{
		document.getElementById("news_titel").disabled = true;
		document.getElementById("news_text").disabled = true;
	}
	return true;
}

function change_image(loadfile,obj){
	window.document.getElementById('rg_pic_'+obj).src = loadfile;
	return true;
}

function show_rg(){
	  Fenster1 = window.open("./ext_scripts/rg.php", "Rundgang", "width=640,height=470,left="+(screen.width/2-320)+",top="+(screen.height/2-240));
	  Fenster1.focus();
	return true;
}

function show_help_popup(link){
	  Fenster1 = window.open(link, "Hilfe", "scrollbars=yes,width=840,height=419,left="+(screen.width/5*3-320)+",top="+(screen.height/3-240));
	  Fenster1.focus();
	return true;
}

function set_cursor(cur,obj){
	// window.document.getElementById('rg_pic_'+obj).className = "cur"+cur;
	return true;
}

function uncryptmail(encmail,shiftval)
{
	var outstr = 'mailto:';
	for (t=0;t<encmail.length;t++){
		shiftval++;
		if (encmail.charAt(t) != "A" && encmail.charAt(t) != "D" && encmail.charAt(t) != "B" && encmail.charAt(t) != "U"){
			if (encmail.charCodeAt(t)-shiftval < 97){
				outstr = outstr + String.fromCharCode(encmail.charCodeAt(t)-shiftval+ 26);
			}else{
				outstr = outstr + String.fromCharCode(encmail.charCodeAt(t)-shiftval);
			}
		}else{
			if (encmail.charAt(t) == "A"){
				outstr = outstr + "@";
			}else if(encmail.charAt(t) == "D"){
				outstr = outstr + ".";
			}else if(encmail.charAt(t) == "B"){
				outstr = outstr + "-";
			}else{
				outstr = outstr + "_";
			}
		}
	}
	location.href=outstr;
}


function oe(){
   return true;
}
window.onerror = oe

var optionsPopup = "scrollbars=yes,resizable=yes,menubar=yes,location=no,width=750,height=480";

function openPopup1(){
	var url = document.URL;
	var url2 = url.search(/id=.+/);
	if (url2 != -1) {
		url=url+"&print=1";
	} else {
		url=url+"?id=home&print=1";
	}
	
	window.open(url, "popup", optionsPopup);
}

function openPopup(url){
	var url2 = url.search(/id=.+/);
	if (url2 != -1) {
		url=url+"&print=1";
	} else {
		url=url+"?id=home&print=1";
	}

	window.open(url, "popup", optionsPopup);
}


function changecontent(ident, content) {
	if (document.layers) {
		document.layers[ident].document.write(content);
		document.layers[ident].document.close();
	}else if (document.all) {
		document.all[ident].innerHTML = content;
	}else if (document.getElementById) {
		document.getElementById(ident).firstChild.nodeValue = content;
	}
}

function gotoDestination(){
	location.href="http://maps.google.com/maps?f=d&source=s_d&daddr="+document.getElementById('destinationAddress').value+"&saddr=" + document.getElementById('routingAddress').value.replace(" ","+")
	return false;
}

function checkDate()
{
	if (window.document.getElementById('validselector').checked){
		var day = window.document.getElementById('validUntilDay').value;
		var month = window.document.getElementById('validUntilMonth').value;
		var year = window.document.getElementById('validUntilYear').value;

		if (day > 0 && day< 32 && isNumeric(day)){
			if (month > 0 && month < 13 && isNumeric(month)){
				if (year > 2000 && year < 3000 && isNumeric(year)){
				   var dt = new Date(parseFloat(year), parseFloat(month)-1, parseFloat(day), 0, 0, 0, 0);
				   if (parseFloat(day) == dt.getDate()) {  
					   if (parseFloat(month)-1 == dt.getMonth()) {
						   return true;
					   }
				   }
				}
			}
		}
		alert("Datum ungültig");
		return false;
	}else{
		return true;
	}
}

function isNumeric(input)
{
   return (input - 0) == input && input.length > 0;
}

function changedDateSelector()
{
	if(window.document.getElementById('validselector').checked){
		enableTextField(window.document.getElementById('validUntilDay'));
		enableTextField(window.document.getElementById('validUntilMonth'));
		enableTextField(window.document.getElementById('validUntilYear'));
	}else{
		disableTextField(window.document.getElementById('validUntilDay'));
		disableTextField(window.document.getElementById('validUntilMonth'));
		disableTextField(window.document.getElementById('validUntilYear'));
	}
	
}

function disableTextField(field)
{
	field.disabled = true;
}

function enableTextField(field)
{
	field.disabled = false;
	field.readonly = false;
}

function updateTreeSelectorDisplay()
{
	if(document.getElementById('menuTarget').checked == true){
		document.getElementById('menuTreeSelector').className = 'menuTreeSelector menuTreeSelector_enabled';
	}else{
		document.getElementById('menuTreeSelector').className = 'menuTreeSelector';
	}
}
