/*--------------------------------------------------------------------------------
Name: menu_slide
Description: slides the submenu up, down and saves the state in a sql_database
Author: Martin Brack
--------------------------------------------------------------------------------*/
function menu_slide(id) {
	new Effect.toggle($(id),'blind', { delay: 0.2, duration: 0.7});
}

/*--------------------------------------------------------------------------------
Name: login_usermenue
Description: login to user menu
Author: Martin Brack
--------------------------------------------------------------------------------*/
function login_usermenue() {
	new Effect.Fade('login_div',{duration:1.0, from:1.0, afterFinish: function(){new Effect.Appear('user_div'); xajax_show_page_edit(); new Effect.Appear('editable')} });
}

/*--------------------------------------------------------------------------------
Name: usermenu_login
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function usermenu_login() {
	new Effect.Fade('user_div',{duration:1.0, from:1.0, afterFinish: function(){delete_usermenu(); new Effect.Appear('login_div'); new Effect.Fade('editable'); xajax_hide_page_edit();} });
}

/*--------------------------------------------------------------------------------
Name: send_login
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function send_login() {
	var nick = document.login.l1.value;
	var pw = document.login.l2.value;
	var pbody = "nick="+nick+"&pw="+pw;
	var myAjax = new Ajax.Request(
		'config/ajax/login.php',
		{
			method: 'post',
			postBody: pbody,
			onComplete: function(req){
				if(req.responseText!="false"){
					create_usermenu(req.responseText);
					login_usermenue();
					change_comment_picture();
					show_delete_picture(req.responseText);
					show_comment_editable(req.responseText);
					if(document.getElementById('intern'))
						Effect.Fade('intern', {afterFinish: function() { allow_intern(); }});
					Effect.Fade('admin', {afterFinish: function() { allow_admin(); }});
				}else{
					alert("Login war nicht erfolgreich. Falsches Passwort oder falscher Username");	
				}
			}
		});
}

/*--------------------------------------------------------------------------------
Name: observe_input
Description: observe the input of loginfomr
Author: Martin Brack
--------------------------------------------------------------------------------*/
function observe_input(e) {
	if(document.all){
		if(event.keyCode==13){
			alert("Bitte klicke auf den LOGIN-Button um dich anzumelden");
		}
	}else{
		if(e.which==13){
			alert("Bitte klicke auf den LOGIN-Button um dich anzumelden");
		}
	}
}

/*--------------------------------------------------------------------------------
Name: send_logout
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function send_logout() {
	var myAjax = new Ajax.Request(
		'config/ajax/logout.php',
		{
			method: 'post',
			onComplete: function(req){
				hide_comment_editable();
				hide_delete_picture();
				change_comment_picture();
				usermenu_login();
				hide_page_edit();
			}
		});
	deny_admin();
	deny_intern();
}

/*--------------------------------------------------------------------------------
Name: create_usermenu
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function create_usermenu(admin) {
	if(admin=="11"){
		var pbody = "func=34";
		var myAjax = new Ajax.Request(
		'config/ajax/functions.php',
		{
			method: 'post',
			postBody: pbody,
			onComplete: function(req){
				if(req.responseText=="0"){
				document.getElementById("user_div").innerHTML = '<ul><li><a class="grey_white" href="index.php?site=lobby">Lobby</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="grey_white" href="index.php?site=profil_bearbeiten">Profil bearbeiten</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="grey_white" href="index.php?site=nachrichten">Nachrichten</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="grey_white" href="index.php?site=profils">alle Profile</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="grey_white" href="#" onclick="send_logout()">Logout</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="red_white" href="index.php?site=admin">Admin Men&uuml;</a>&nbsp;&nbsp;&nbsp;|</li></ul>';
				}else{
				document.getElementById("user_div").innerHTML = '<ul><li><a class="grey_white" href="index.php?site=lobby">Lobby</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="grey_white" href="index.php?site=profil_bearbeiten">Profil bearbeiten</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="red_white" href="index.php?site=nachrichten">Nachrichten ('+req.responseText+')</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="grey_white" href="index.php?site=profils">alle Profile</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="grey_white" href="#" onclick="send_logout()">Logout</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="red_white" href="index.php?site=admin">Admin Men&uuml;</a>&nbsp;&nbsp;&nbsp;|</li></ul>';
				}
			}
		});
	}else{
		var pbody = "func=34";
		var myAjax = new Ajax.Request(
		'config/ajax/functions.php',
		{
			method: 'post',
			postBody: pbody,
			onComplete: function(req){
				if(req.responseText=="0"){
					document.getElementById("user_div").innerHTML = '<ul><li><a class="grey_white" href="index.php?site=lobby">Lobby</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="grey_white" href="index.php?site=profil_bearbeiten">Profil bearbeiten</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="grey_white" href="index.php?site=nachrichten">Nachrichten</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="grey_white" href="index.php?site=profils">alle Profile</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="grey_white" href="#" onclick="send_logout()">Logout</a>&nbsp;&nbsp;&nbsp;|</li></ul>';
				}else{
					document.getElementById("user_div").innerHTML = '<ul><li><a class="grey_white" href="index.php?site=lobby">Lobby</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="grey_white" href="index.php?site=profil_bearbeiten">Profil bearbeiten</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="red_white" href="index.php?site=nachrichten">Nachrichten ('+req.responseText+')</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="grey_white" href="index.php?site=profils">alle Profile</a>&nbsp;&nbsp;&nbsp;|</li><li><a class="grey_white" href="#" onclick="send_logout()">Logout</a>&nbsp;&nbsp;&nbsp;|</li></ul>';
				}
			}
		});
	}
}


/*--------------------------------------------------------------------------------
Name: delete_usermenu
Description: user log out
Author: Martin Brack
--------------------------------------------------------------------------------*/
function delete_usermenu() {
	document.getElementById("user_div").innerHTML = '';
}

/*--------------------------------------------------------------------------------
Name: rand_pic
Description: random mode for picture
Author: Martin Brack
--------------------------------------------------------------------------------*/
function rand_pic() {
	var myAjax = new Ajax.Request(
		'config/ajax/random_picture.php?pic=2',
		{
			method: 'get',
			onComplete: function(req){
				new Effect.Fade("random_pix", {afterFinish: function(){document.getElementById("random_pix").innerHTML = req.responseText; new Effect.Appear("random_pix");} });
			}
		});
}

/*--------------------------------------------------------------------------------
Name: changes_were_saved
Description: show div when saved in editmode
Author: Martin Brack
--------------------------------------------------------------------------------*/
function changes_were_saved() {
	//updates the value of the FCKEditor
	for ( i = 0; i < parent.frames.length; ++i ) {
		if ( parent.frames[i].FCK )
			parent.frames[i].FCK.UpdateLinkedField();
	}
	xajax_save_changes(document.getElementById("FCKeditor1").value);
	if(document.getElementById('edit_output').style.display=='none'){
		new Effect.toggle('edit_output', 'blind');
	}else{
		Effect.toggle('edit_output', 'blind', {afterFinish: function() { Effect.toggle('edit_output', 'blind'); }});
	}
}

/*--------------------------------------------------------------------------------
Name: hide_page_edit
Description: by logout hide edit modus
Author: Martin Brack
--------------------------------------------------------------------------------*/
function hide_page_edit() {
	Effect.Fade('show_edit', {
		afterFinish: function() {
				document.getElementById('show_edit').innerHTML = '<h1>!!! Kein Zutritt !!!</h1><p style="text-align: center">Dieser Bereich ist f&uuml;r dich leider gesperrt!</p>';
				Effect.Appear('show_edit');
		}
	});	
}

/*--------------------------------------------------------------------------------
Name: textarea_resize
Description: resize textarea
Author: Martin Brack
--------------------------------------------------------------------------------*/
function textarea_resize(new_height, id) {
	if(document.all){
		document.getElementById(id).style.height = new_height+'px';
	}
}

/*--------------------------------------------------------------------------------
Name: on_select
Description: on select the textarea
Author: Martin Brack
--------------------------------------------------------------------------------*/
function on_select() {
	if(document.getElementById('c2').value=="Klicke hier um deinen Kommentar zu schreiben")
		document.getElementById('c2').value='';
}

/*--------------------------------------------------------------------------------
Name: on_leave
Description: on leave the textarea
Author: Martin Brack
--------------------------------------------------------------------------------*/
function on_leave() {
	if(document.getElementById('c2').value=="")
		document.getElementById('c2').value="Klicke hier um deinen Kommentar zu schreiben";
}

/*--------------------------------------------------------------------------------
Name: on_select
Description: on select the input field
Author: Martin Brack
--------------------------------------------------------------------------------*/
function on_select2() {
	if(document.getElementById('c1').value=="Klicke hier um deinen Namen anzugeben")
		document.getElementById('c1').value='';
}

/*--------------------------------------------------------------------------------
Name: on_leave
Description: on leave the input field
Author: Martin Brack
--------------------------------------------------------------------------------*/
function on_leave2() {
	if(document.getElementById('c1').value=="")
		document.getElementById('c1').value="Klicke hier um deinen Namen anzugeben";
}

/*--------------------------------------------------------------------------------
Name: show_comment_form
Description: slides the comment form in
Author: Martin Brack
--------------------------------------------------------------------------------*/
function show_comment_form() {
	if(document.getElementById('preview').style.display=="none"){
		Effect.toggle('comment_form', 'slide');
	}else{
		Effect.toggle('preview', 'slide', {afterFinish: function() { Effect.toggle('comment_form', 'slide'); }});
	}
}

/*--------------------------------------------------------------------------------
Name: show_comment_form
Description: saves a new Comment and shows it by old ones
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_comment() {
	Effect.toggle('comment_form', 'slide', {afterFinish: function() { if(document.getElementById('preview').style.display!=="none"){ Effect.toggle('preview', 'slide'); } }});
}

/*--------------------------------------------------------------------------------
Name: get_preview_comment
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function get_preview_comment(in1, in2) {
	var comment_name = document.getElementById(in1).value;
	var comment_text = document.getElementById(in2).value;
	var pbody = "func=1&name="+comment_name+"&comment="+comment_text;
	if(comment_name!=="Klicke hier um deinen Namen anzugeben" && comment_text!=="Klicke hier um deinen Kommentar zu schreiben" && comment_name!=="" && comment_text!==""){
		var myAjax = new Ajax.Request(
			'config/ajax/comment_script.php',
			{
				method: 'post',
				postBody: pbody,			
				onComplete: function(req){
					var div_id = document.getElementById("preview").style.display;
					if(div_id=="none"){
						document.getElementById("preview").innerHTML = req.responseText;
						Effect.toggle('preview', 'slide');
					}else{
						Effect.toggle('preview', 'slide', {
							afterFinish: function() {
								document.getElementById("preview").innerHTML = req.responseText;
								Effect.toggle('preview', 'slide');
							}
						});	
					}
				}
			});
	}else{
		alert("Du hast keinen Namen oder keinen Text eingegeben!");	
	}
}

/*--------------------------------------------------------------------------------
Name: get_preview_comment2
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function get_preview_comment2(in1, in2, pic) {
	var comment_name = document.getElementById(in1).value;
	var comment_text = document.getElementById(in2).value;
	var pbody = "func=5&name="+comment_name+"&comment="+comment_text+'&pic='+pic;
	if(comment_name!=="Klicke hier um deinen Namen anzugeben" && comment_text!=="Klicke hier um deinen Kommentar zu schreiben" && comment_name!=="" && comment_text!==""){
		var myAjax = new Ajax.Request(
			'config/ajax/comment_script.php',
			{
				method: 'post',
				postBody: pbody,			
				onComplete: function(req){
					var div_id = document.getElementById("preview").style.display;
					if(div_id=="none"){
						document.getElementById("preview").innerHTML = req.responseText;
						Effect.toggle('preview', 'slide');
					}else{
						Effect.toggle('preview', 'slide', {
							afterFinish: function() {
								document.getElementById("preview").innerHTML = req.responseText;
								Effect.toggle('preview', 'slide');
							}
						});	
					}
				}
			});
	}else{
		alert("Du hast keinen Namen oder keinen Text eingegeben!");	
	}
}

/*--------------------------------------------------------------------------------
Name: save_new_comment
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_new_comment(gallery_id, pic_id, picture_id) {
	var gallery = gallery_id;
	var pic = pic_id;
	var comment_name = document.getElementById('c1').value;
	var comment_text = document.getElementById('c2').value;
	var currentTime = new Date();
	var month = currentTime.getMonth() + 1;
	if(month<10)
		month = '0'+month;
	var day = currentTime.getDate();
	if(day<10)
		day = '0'+day;
	var year = currentTime.getFullYear();
	var hour = currentTime.getHours();
	if(hour<10)
		hour = '0'+hour;
	var minute = currentTime.getMinutes();
	if(minute<10)
		minute = '0'+minute;
	var pbody = "func=2&gallery="+gallery+"&picname="+pic+"&name="+comment_name+"&comment="+comment_text+"&picid="+picture_id;
	if(comment_name!=="Klicke hier um deinen Namen anzugeben" && comment_text!=="Klicke hier um deinen Kommentar zu schreiben" && comment_name!=="" && comment_text!==""){
		var myAjax = new Ajax.Request(
			'config/ajax/comment_script.php',
			{
				method: 'post',
				postBody: pbody,			
				onComplete: function(req){
					var div_id = document.getElementById("preview").style.display;
					if(div_id=="none"){
						comment_text = search_replace(comment_text, ':)', "<img src='data/div_data/smileys/smile.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ':D', "<img src='data/div_data/smileys/biggrin.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, '^^', "<img src='data/div_data/smileys/normales.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, '=D', "<img src='data/div_data/smileys/smilewinkgrin.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ':yes:', "<img src='data/div_data/smileys/yes.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ';)', "<img src='data/div_data/smileys/wink.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, '8)', "<img src='data/div_data/smileys/cool.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ':P', "<img src='data/div_data/smileys/bigrazz.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ':roll:', "<img src='data/div_data/smileys/rolleyes.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ':|', "<img src='data/div_data/smileys/none.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ':O', "<img src='data/div_data/smileys/bigeek.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ':no:', "<img src='data/div_data/smileys/no.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ':`(', "<img src='data/div_data/smileys/cry.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, '>(', "<img src='data/div_data/smileys/mad.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, 'XP', "<img src='data/div_data/smileys/dead.gif' style='margin-bottom: -3px'>");
						var insertComment = '<div class="title_right" style="letter-spacing: 0px; font-size: 12px; padding-left: 5px; padding-top: 2px; height: 16px; width: 170px">'+day+'.'+month+'.'+year+' - '+hour+':'+minute+'</div><div class="right_bg" style="margin: 0 0 10px 0;"><p class="newest_comment_title">'+comment_name+'</p><p class="newest_comment_content">'+comment_text+'</p><p class="newest_comment_link"><a class="red_black" href="gallery.php?id='+gallery_id+'&amp;pic='+picture_id+'">zum Bild &gt;&gt;</a></p></div>';
						new Insertion.Top('comments', req.responseText);
						new Insertion.Top('new_comments', insertComment);
						Effect.toggle('comment_form', 'slide', {delay: 0.8,
							afterFinish: function() {
									document.getElementById('c1').value="Klicke hier um deinen Namen anzugeben";
									document.getElementById('c2').innerHTML="Klicke hier um deinen Kommentar zu schreiben";
							}
						});
					}else{
						comment_text = search_replace(comment_text, ':)', "<img src='data/div_data/smileys/smile.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ':D', "<img src='data/div_data/smileys/biggrin.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, '^^', "<img src='data/div_data/smileys/normales.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, '=D', "<img src='data/div_data/smileys/smilewinkgrin.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ':yes:', "<img src='data/div_data/smileys/yes.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ';)', "<img src='data/div_data/smileys/wink.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, '8)', "<img src='data/div_data/smileys/cool.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ':P', "<img src='data/div_data/smileys/bigrazz.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ':roll:', "<img src='data/div_data/smileys/rolleyes.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ':|', "<img src='data/div_data/smileys/none.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ':O', "<img src='data/div_data/smileys/bigeek.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ':no:', "<img src='data/div_data/smileys/no.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, ':`(', "<img src='data/div_data/smileys/cry.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, '>(', "<img src='data/div_data/smileys/mad.gif' style='margin-bottom: -3px'>");
						comment_text = search_replace(comment_text, 'XP', "<img src='data/div_data/smileys/dead.gif' style='margin-bottom: -3px'>");
						var insertComment = '<div class="title_right" style="letter-spacing: 0px; font-size: 12px; padding-left: 5px; padding-top: 2px; height: 16px; width: 170px">'+day+'.'+month+'.'+year+' - '+hour+':'+minute+'</div><div class="right_bg" style="margin: 0 0 10px 0;"><p class="newest_comment_title">'+comment_name+'</p><p class="newest_comment_content">'+comment_text+'</p><p class="newest_comment_link"><a class="red_black" href="gallery.php?id='+gallery_id+'&amp;pic='+picture_id+'">zum Bild &gt;&gt;</a></p></div>';
						new Insertion.Top('comments', req.responseText);
						new Insertion.Top('new_comments', insertComment);
						Effect.toggle('preview', 'slide', {delay: 0.4,
							afterFinish: function() {
									Effect.toggle('comment_form', 'slide', {afterFinish: function() {																											  
											document.getElementById('c1').value="Klicke hier um deinen Namen anzugeben";
											document.getElementById('c2').innerHTML="Klicke hier um deinen Kommentar zu schreiben";																  
										}
									});
							}
						});	
					}
				}
			});
	}else{
		alert("Du hast keinen Namen oder keinen Text eingegeben!");	
	}
}

/*--------------------------------------------------------------------------------
Name: change_comment_picture
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function change_comment_picture() {
	if(document.getElementById('comment_form_img')){
		var pbody = 'func=3';
		var myAjax = new Ajax.Request(
			'config/ajax/comment_script.php',
			{
				method: 'post',
				postBody: pbody,			
				onComplete: function(req){
					Effect.Fade('comment_form_img', {
						afterFinish: function() {
							document.getElementById('comment_form_img').src = req.responseText;
							Effect.Appear('comment_form_img');
						}								
					});
					if(document.getElementById('comment_preview_img')){
						Effect.Fade('comment_preview_img', {
							afterFinish: function() {
								document.getElementById('comment_preview_img').src = req.responseText;
								Effect.Appear('comment_preview_img');
							}								
						});
					}
				}
			});
	}
}

/*--------------------------------------------------------------------------------
Name: calendar_change
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function calendar_change(date) {
	var pbody = 'func=1&date='+date;
	var myAjax = new Ajax.Request(
		'config/ajax/functions.php',
		{
			method: 'post',
			postBody: pbody,			
			onComplete: function(req){
				document.getElementById('calendar').innerHTML = req.responseText;
			}
		});
}

/*--------------------------------------------------------------------------------
Name: allow_admin
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function allow_admin() {
	if(document.getElementById('admin')){
		document.getElementById('admin').innerHTML = '<h1>!!! Bitte Seite neuladen !!!</h1><p style="text-align: center">Um die Sicherheit zu gew&auml;hrleisten, aktualisiere bitte zuerst die Seite (dr&uuml;cke F5)</p>';
		Effect.Appear('admin');
	}
}

/*--------------------------------------------------------------------------------
Name: deny_admin
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function deny_admin() {
	if(document.getElementById('admin')){
		Effect.Fade('admin', {afterFinish: function() {
			document.getElementById('admin').innerHTML = '<h1>!!! Kein Zutritt !!!</h1><p style="text-align: center">F&uuml;r diesen Bereich besitzt du keine Berechtigung!!!</p>';
			Effect.Appear('admin');
		}});
	}
}

/*--------------------------------------------------------------------------------
Name: allow_intern
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function allow_intern() {
	if(document.getElementById('intern')){
		document.getElementById('intern').innerHTML = '<h1>!!! Bitte Seite neuladen !!!</h1><p style="text-align: center">Um die Sicherheit zu gew&auml;hrleisten, aktualisiere bitte zuerst die Seite (dr&uuml;cke F5)</p>';
		Effect.Appear('intern');
	}
}

/*--------------------------------------------------------------------------------
Name: deny_intern
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function deny_intern() {
	if(document.getElementById('intern')){
		Effect.Fade('intern', {afterFinish: function() {
			document.getElementById('intern').innerHTML = '<h1>!!! Kein Zutritt !!!</h1><p style="text-align: center">F&uuml;r diesen Bereich besitzt du keine Berechtigung!!!</p>';
			Effect.Appear('intern');
		}});
	}
}

/*--------------------------------------------------------------------------------
Name: show_delete_picture
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function show_delete_picture(admin) {
	if(admin == '11'){
		if(document.getElementById('delete_img')){
			document.getElementById('delete_img').innerHTML = '<img src="layout/admin_images/delete.png" style="margin-bottom: -1px"><a class="grey_white2" href="#"> Bild l&ouml;schen</a>';
			Effect.toggle('delete_img', 'blind');
		}
	}
}

/*--------------------------------------------------------------------------------
Name: hide_delete_picture
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function hide_delete_picture() {
	if(document.getElementById('delete_img')){
		Effect.BlindUp('delete_img',{afterFinish: function() {document.getElementById('delete_img').innerHTML = '';} });
	}
}

/*--------------------------------------------------------------------------------
Name: create_folder
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function create_folder(){
	var state = window.confirm('Durch drücken auf `OK` wird ein neuer Ordner für die Bilder erstellt')
	if(state){
		var pbody = 'func=1';
		var myAjax = new Ajax.Request(
		'config/ajax/create_gallery.php',
		{
			method: 'post',
			postBody: pbody,			
			onComplete: function(req){
				document.getElementById('folder_button').style.display = 'none';
				document.getElementById('continue').style.display = 'block';
				document.getElementById('edit_output').innerHTML = req.responseText;
				Effect.BlindDown('edit_output');
			}
		});
	}
}

/*--------------------------------------------------------------------------------
Name: show_gallery_form
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function show_gallery_form(){
	var folder = document.getElementById('folder_name').value;
	var pbody1 = 'func=6&folder='+folder;
	var myAjax1 = new Ajax.Request(
	'config/ajax/create_gallery.php',
	{
		method: 'post',
		postBody: pbody1,			
		onComplete: function(req){
			var nr_of_pics = req.responseText;	
			if(nr_of_pics!=='0'){
				var state = window.confirm('In dem Ordner befinden sich '+nr_of_pics+' Bilder. \nWenn die Anzahl stimmt klicke auf OK ansonsten auf Abbrechen und lade die restlichen Bilder noch in den Ordner.')
				if(state){
					var pbody = 'func=2&gal_id='+folder;
					var myAjax = new Ajax.Request(
					'config/ajax/create_gallery.php',
					{
						method: 'post',
						postBody: pbody,			
						onComplete: function(req){
							document.getElementById('continue').style.display = 'none';
							document.getElementById('edit_output').style.display = 'none';
							document.getElementById('create_gallery_form').innerHTML = req.responseText;
						}
					});
				}
			}else{
				alert("In dem Ordner befinden sich noch keine Bilder! Bitte lade deine Bilder in den Ordner mit der Nummer "+folder);	
			}
		}
	});
}

/*--------------------------------------------------------------------------------
Name: create_pictures
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function create_pictures(start, nr_of_pictures, gal_id) {
	var title = document.getElementById('g1').value;
	var photograph = document.getElementById('g2').value;
	var day = document.getElementById('g3').value;
	var month = document.getElementById('g4').value;
	var year = document.getElementById('g5').value;
	var maennerturnen = document.getElementById('maennerturnen_50').checked;
	var turnerinnen = document.getElementById('turnerinnen').checked;
	var frauenriege = document.getElementById('frauenriege').checked;
	var jugi_maedchen = document.getElementById('jugi_maedchen').checked;
	var jugi_knaben = document.getElementById('jugi_knaben').checked;
	var rhoenrad = document.getElementById('rhoenrad').checked;
	var rope_skipping = document.getElementById('rope_skipping').checked;
	var seniorenturnen = document.getElementById('seniorenturnen').checked;
	var spielturnen = document.getElementById('spielturnen').checked;
	var turnzirkus = document.getElementById('turnzirkus').checked;
	var kunstturnen = document.getElementById('kunstturnen').checked;
	if(title!='' && day!='' && month!='' && year!=''){
		document.getElementById('create_gallery_form').style.display = 'none';
		var pbody = 'func=3&pic_id='+start+'&gal_id='+gal_id+'&nr_of_pics='+nr_of_pictures+'&title='+title+'&photograph='+photograph+'&day='+day+'&month='+month+'&year='+year+'&maennerturnen='+maennerturnen+'&turnerinnen='+turnerinnen+'&frauenriege='+frauenriege+'&jugi_maedchen='+jugi_maedchen+'&jugi_knaben='+jugi_knaben+'&rhoenrad='+rhoenrad+'&rope_skipping='+rope_skipping+'&seniorenturnen='+seniorenturnen+'&spielturnen='+spielturnen+'&turnzirkus='+turnzirkus+'&kunstturnen='+kunstturnen;
		if(start==0){
			document.getElementById('status').innerHTML = '<p style="margin: 10px;">Die Bildergalerie wird erstellt.<br /><br /><b>Die Seite darf während dieser Zeit nicht geschlossen werden!!!</b><br /><br /><img src="layout/admin_images/loading.gif" style="margin-bottom: -10px"> 0/'+nr_of_pictures+' Bilder erstellt</p>';
			Effect.SlideDown('status');
		}
		var myAjax = new Ajax.Request(
		'config/ajax/create_gallery.php',
		{
			method: 'post',
			postBody: pbody,			
			onComplete: function(req){
				if((start+1)<nr_of_pictures){
					document.getElementById("status").innerHTML = req.responseText;
					create_pictures((start+1),nr_of_pictures,gal_id);
				}else{
					document.getElementById("status").style.height = '50px';
					document.getElementById("status").innerHTML = '<p style="margin-top: 20px">Die Original-Bilder werden nun vom Server gel&ouml;scht</p>';
					delete_imgs(nr_of_pictures, gal_id);
				}
			}
		});
	}else{
		alert('Bitte alle Felder ausfüllen!!!');
	}
}

/*--------------------------------------------------------------------------------
Name: delete_imgs
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function delete_imgs(nr_of_pictures, gal_id) {
	var pbody = 'func=4&gal_id='+gal_id+'&nr_of_pics='+nr_of_pictures;
	var myAjax = new Ajax.Request(
	'config/ajax/create_gallery.php',
	{
		method: 'post',
		postBody: pbody,			
		onComplete: function(req){
				document.getElementById("status").innerHTML = req.responseText;
		}
	});
}

/*--------------------------------------------------------------------------------
Name: del_image
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function del_image(gal_id, pic_name,id) {
	var state = window.confirm('Willst du das Bild wirklich löschen');
	if(state){
		window.location = 'config/php/del_img.php?gal_id='+gal_id+'&pic='+pic_name+'&id='+id;
	}
}

/*--------------------------------------------------------------------------------
Name: del_comment
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function del_comment(gal_id, pic_name, pic_id, comment_id) {
	var state = window.confirm('Willst du den Kommentar wirklich löschen');
	if(state){
		window.location = 'config/php/del_com.php?gal_id='+gal_id+'&pic='+pic_name+'&pic_id='+pic_id+'&comment_id='+comment_id+'';
	}
}

/*--------------------------------------------------------------------------------
Name: show_comment_editable
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function show_comment_editable(admin) {
	if(admin=='11'){
		var edit_array = document.getElementsByClassName('comment_panel');
		if(edit_array.length!=0){
			for(var i=0; i<edit_array.length; i++){
				edit_array[i].style.display = 'block';
			}
		}
	}
}

/*--------------------------------------------------------------------------------
Name: hide_comment_editable
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function hide_comment_editable() {
	var edit_array = document.getElementsByClassName('comment_panel');
	if(edit_array.length!=0){
		for(var i=0; i<edit_array.length; i++){
			edit_array[i].style.display = 'none';
		}
	}
}

/*--------------------------------------------------------------------------------
Name: show_edit_form
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function show_edit_form(name, pic, comment, id, gal_id, pic_id) {
var pbody = 'func=4&name='+name+'&pic='+pic+'&comment='+comment+'&id='+id+'&gal_id='+gal_id+'&pic_id='+pic_id+'';
	var myAjax = new Ajax.Request(
	'config/ajax/comment_script.php',
	{
		method: 'post',
		postBody: pbody,			
		onComplete: function(req){
				document.getElementById("comment_edit_img").src = req.responseText;
				show_edit_form2(name, pic, comment, id, gal_id, pic_id);
		}
	});
}

/*--------------------------------------------------------------------------------
Name: show_edit_form2
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function show_edit_form2(name, pic, comment, id, gal_id, pic_id) {
var pbody = 'func=6&name='+name+'&pic='+pic+'&comment='+comment+'&id='+id+'&gal_id='+gal_id+'&pic_id='+pic_id+'';
	var myAjax = new Ajax.Request(
	'config/ajax/comment_script.php',
	{
		method: 'post',
		postBody: pbody,			
		onComplete: function(req){
			req.responseText = search_replace(name, '&ouml;', 'ö');
			document.getElementById("e1").value = req.responseText;
			show_edit_form3(name, pic, comment, id, gal_id, pic_id);
		}
	});
}

/*--------------------------------------------------------------------------------
Name: show_edit_form3
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function show_edit_form3(name, pic, comment, id, gal_id, pic_id) {
var pbody = 'func=7&name='+name+'&pic='+pic+'&comment='+comment+'&id='+id+'&gal_id='+gal_id+'&pic_id='+pic_id+'';
	var myAjax = new Ajax.Request(
	'config/ajax/comment_script.php',
	{
		method: 'post',
		postBody: pbody,			
		onComplete: function(req){
			req.responseText = search_replace(comment, '&ouml;', 'ö');
			req.responseText = search_replace(comment, '&auml;', 'ä');
			req.responseText = search_replace(comment, '&uuml;', 'ü');
			req.responseText = search_replace(comment, '&Uuml;', 'Ü');
			req.responseText = search_replace(comment, '&Auml;', 'Ä');
			req.responseText = search_replace(comment, '&Ouml;', 'Ö');
			req.responseText = search_replace(comment, '&Ouml;', 'Ö');
				document.getElementById("e2").value = req.responseText;
				show_edit_form4(name, pic, comment, id, gal_id, pic_id);
		}
	});
}

/*--------------------------------------------------------------------------------
Name: show_edit_form4
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function show_edit_form4(name, pic, comment, id, gal_id, pic_id) {
var pbody = 'func=8&name='+name+'&pic='+pic+'&comment='+comment+'&id='+id+'&gal_id='+gal_id+'&pic_id='+pic_id+'';
	var myAjax = new Ajax.Request(
	'config/ajax/comment_script.php',
	{
		method: 'post',
		postBody: pbody,			
		onComplete: function(req){
				document.getElementById("save_edit").innerHTML = req.responseText;
				show_edit_form5(name, pic, comment, id, gal_id, pic_id);
		}
	});
}

/*--------------------------------------------------------------------------------
Name: show_edit_form5
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function show_edit_form5(name, pic, comment, id, gal_id, pic_id) {
var pbody = 'func=9&name='+name+'&pic='+pic+'&comment='+comment+'&id='+id+'&gal_id='+gal_id+'&pic_id='+pic_id+'';
	var myAjax = new Ajax.Request(
	'config/ajax/comment_script.php',
	{
		method: 'post',
		postBody: pbody,			
		onComplete: function(req){
				document.getElementById("preview_edit").innerHTML = req.responseText;
				Effect.toggle('comment_edit', 'slide');
		}
	});
}

/*--------------------------------------------------------------------------------
Name: save_edit_comment
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_edit_comment(pic, id, gal_id, pic_id) {
	var name = document.getElementById('e1').value;
	var comment = document.getElementById('e2').value;
	name = search_replace(name, '&ouml;', 'ö');
	name = search_replace(name, '&auml;', 'ä');
	name = search_replace(name, '&uuml;', 'ü');
	name = search_replace(name, '&Uuml;', 'Ü');
	name = search_replace(name, '&Auml;', 'Ä');
	name = search_replace(name, '&Ouml;', 'Ö');
	comment = search_replace(comment, '\n', '<br />');
	window.location.href = 'config/php/edit_com.php?name='+name+'&pic='+pic+'&comment='+comment+'&id='+id+'&gal_id='+gal_id+'&pic_id='+pic_id+'';
}

/*--------------------------------------------------------------------------------
Name: search_replace
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function search_replace(QuellText, SuchText, ErsatzText){   // Erstellt von Ralf Pfeifer
	// Fehlerpruefung
	if ((QuellText == null) || (SuchText == null))           { return null; }
	if ((QuellText.length == 0) || (SuchText.length == 0))   { return QuellText; }

	// Kein ErsatzText ?
	if ((ErsatzText == null) || (ErsatzText.length == 0))    { ErsatzText = ""; }

	var LaengeSuchText = SuchText.length;
	var LaengeErsatzText = ErsatzText.length;
	var Pos = QuellText.indexOf(SuchText, 0);

	while (Pos >= 0)
	{
		QuellText = QuellText.substring(0, Pos) + ErsatzText + QuellText.substring(Pos + LaengeSuchText);
		Pos = QuellText.indexOf(SuchText, Pos + LaengeErsatzText);
	}
	return QuellText;
}

/*--------------------------------------------------------------------------------
Name: search_replace
Description: shows the preview of a comment
Author: Martin Brack
--------------------------------------------------------------------------------*/
function delete_gallery(id){
	var state = window.confirm('Bist du sicher, dass du diese Galerie löschen möchtest?');
	if(state){
		window.location = 'config/php/del_gallery.php?id='+id;
	}
}

/*--------------------------------------------------------------------------------
Name: save_gallery_changes
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_gallery_changes(id) {
	var title = document.getElementById('g1').value;
	var photograph = document.getElementById('g2').value;
	var day = document.getElementById('g3').value;
	var month = document.getElementById('g4').value;
	var year = document.getElementById('g5').value;
	var turnerinnen = document.getElementById('turnerinnen').checked;
	var frauenriege = document.getElementById('frauenriege').checked;
	var maennerturnen = document.getElementById('maennerturnen_50').checked;
	var seniorenturnen = document.getElementById('seniorenturnen').checked;
	var jugi_maedchen = document.getElementById('jugi_maedchen').checked;
	var jugi_knaben = document.getElementById('jugi_knaben').checked;
	var rhoenrad = document.getElementById('rhoenrad').checked;
	var rope_skipping = document.getElementById('rope_skipping').checked;
	var spielturnen = document.getElementById('spielturnen').checked;
	var turnzirkus = document.getElementById('turnzirkus').checked;
	var kunstturnen = document.getElementById('kunstturnen').checked;
	if(title!='' && day!='' && month!='' && year!=''){
		var pbody = 'func=5&id='+id+'&title='+title+'&photograph='+photograph+'&day='+day+'&month='+month+'&year='+year+'&turnerinnen='+turnerinnen+'&frauenriege='+frauenriege+'&jugi_maedchen='+jugi_maedchen+'&jugi_knaben='+jugi_knaben+'&rhoenrad='+rhoenrad+'&rope_skipping='+rope_skipping+'&spielturnen='+spielturnen+'&turnzirkus='+turnzirkus+'&kunstturnen='+kunstturnen+'&maennerturnen='+maennerturnen+'&seniorenturnen='+seniorenturnen;
		var myAjax = new Ajax.Request(
		'config/ajax/create_gallery.php',
		{
			method: 'post',
			postBody: pbody,			
			onComplete: function(req){
					document.getElementById("status_output").innerHTML = req.responseText;
					Effect.toggle('status_output', 'blind');
			}
		});
	}else{
		alert("Du hast kein Datum eingegeben");	
	}
}

/*--------------------------------------------------------------------------------
Name: save_new_event
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_new_event() {
	var titel = document.getElementById('k1').value;
	var day = document.getElementById('k2').value;
	var month = document.getElementById('k3').value;
	var year = document.getElementById('k4').value;
	var during = document.getElementById('k5').value;
	for ( i = 0; i < parent.frames.length; ++i ) {
		if ( parent.frames[i].FCK )
			parent.frames[i].FCK.UpdateLinkedField();
	}
	var infos = document.getElementById('infos').value;
	infos = search_replace(infos, '&', ':and:');
	infos = search_replace(infos, "'", ':cir:');
	infos = search_replace(infos, "+", ':plus:');
	var titel_next_event = document.getElementById('k7').value;
	var content_next_event = document.getElementById('k6').value;
	var pbody = 'func=2&titel='+titel+'&day='+day+'&month='+month+'&year='+year+'&during='+during+'&infos='+infos+'&titel_next_event='+titel_next_event+'&content_next_event='+content_next_event;
	if(day!='' && month!='' &&year!=''){
		var myAjax = new Ajax.Request(
		'config/ajax/functions.php',
		{
			method: 'post',
			postBody: pbody,
			onComplete: function(req){
				document.getElementById('insert_calendar').style.display = 'none';
				document.getElementById('req_output').innerHTML = req.responseText;
				Effect.toggle('req_output', 'blind');
			}
		});
	}else{
		alert("Datum wurde nicht vollständig eingegeben!");	
	}
}

/*--------------------------------------------------------------------------------
Name: update_event
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function update_event(id) {
	var titel = document.getElementById('k1').value;
	var day = document.getElementById('k2').value;
	var month = document.getElementById('k3').value;
	var year = document.getElementById('k4').value;
	for ( i = 0; i < parent.frames.length; ++i ) {
		if ( parent.frames[i].FCK )
			parent.frames[i].FCK.UpdateLinkedField();
	}
	var infos = document.getElementById('infos').value;
	infos = search_replace(infos, '&', ':and:');
	infos = search_replace(infos, "'", ':cir:');
	infos = search_replace(infos, "+", ':plus:');
	var titel_next_event = document.getElementById('k7').value;
	var content_next_event = document.getElementById('k6').value;
	var pbody = 'func=3&titel='+titel+'&day='+day+'&month='+month+'&year='+year+'&infos='+infos+'&titel_next_event='+titel_next_event+'&content_next_event='+content_next_event+'&id='+id;
	if(day!='' && month!='' &&year!=''){
		var myAjax = new Ajax.Request(
		'config/ajax/functions.php',
		{
			method: 'post',
			postBody: pbody,
			onComplete: function(req){
				document.getElementById('insert_calendar').style.display = 'none';
				document.getElementById('req_output').innerHTML = req.responseText;
				Effect.toggle('req_output', 'blind');
			}
		});
	}else{
		alert("Datum wurde nicht vollständig eingegeben!");	
	}
}

/*--------------------------------------------------------------------------------
Name: delete_cal_entry
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function delete_cal_entry(id) {
	var state = window.confirm('Willst du den Kalendereintrag wirklick löschen?')
	if(state){
		var pbody = 'func=4&id='+id;
		var myAjax = new Ajax.Request(
		'config/ajax/functions.php',
		{
			method: 'post',
			postBody: pbody,
			onComplete: function(req){
				window.location = 'index.php?site=admin&sec=4';
			}
		});
	}
}

/*--------------------------------------------------------------------------------
Name: navi_slide
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function navi_slide(pic_id, gal_id) {
	var pbody = 'func=5&pic='+pic_id+'&id='+gal_id;
	var myAjax = new Ajax.Request(
		'config/ajax/functions.php',
		{
			method: 'post',
			postBody: pbody,
			onComplete: function(req){
				document.getElementById('navigat_pictures').innerHTML = req.responseText;
			}
		});
}

/*--------------------------------------------------------------------------------
Name: save_changes_of_profil
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_changes_of_profil(user) {
	var firstname = document.getElementById('p1').value;
	var lastname = document.getElementById('p2').value;
	var street = document.getElementById('p3').value;
	var plz = document.getElementById('p4').value;
	var city = document.getElementById('p5').value;
	var tel = document.getElementById('p6').value;
	var natel = document.getElementById('p7').value;
	var mail = document.getElementById('p8').value;
	var website = document.getElementById('p17').value;
	var day = document.getElementById('p9').value;
	var month = document.getElementById('p10').value;
	var year = document.getElementById('p11').value;
	var job = document.getElementById('p13').value;
	if(document.getElementById('p12'))
		var new_pw = document.getElementById('p12').value;
	else
		var new_pw = '';
	if(document.getElementById('p20'))
		var new_pw_w = document.getElementById('p20').value;
	else
		var new_pw_w = '';
	var about = document.getElementById('p14').value;
	var hobbys = document.getElementById('p15').value;
	var motto = document.getElementById('p16').value;
	if(new_pw==new_pw_w){
		var pbody = 'func=7&user='+user+'&firstname='+firstname+'&lastname='+lastname+'&street='+street+'&plz='+plz+'&city='+city+'&tel='+tel+'&natel='+natel+'&mail='+mail+'&website='+website+'&day='+day+'&month='+month+'&year='+year+'&job='+job+'&new_pw='+new_pw+'&new_pw_w='+new_pw_w+'&about='+about+'&hobbys='+hobbys+'&motto='+motto;
		if(firstname != '' && lastname != '' && mail != '' && day != '' && month != '' && year != ''){
			var myAjax = new Ajax.Request(
				'config/ajax/functions.php',
				{
					method: 'post',
					postBody: pbody,
					onComplete: function(req){
						document.getElementById('profil_output').innerHTML = req.responseText;
						if(document.getElementById('profil_output').style.display == 'none'){
							Effect.toggle('profil_output', 'blind');
						}else{
							Effect.toggle('profil_output', 'blind', { afterFinish: function() { Effect.toggle('profil_output', 'blind') } });
						}
					}
				});
		}else{
			alert('Bitte alle Pflichtfelder ausfüllen');
		}
	}else{
		alert("Passwort wurde nicht 2 mal gleich eingegeben!");
	}
}

/*--------------------------------------------------------------------------------
Name: save_state
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_state(user) {
	var status = document.getElementById('feels').value;
	var pbody = 'func=6&user='+user+'&value='+status;
	var myAjax = new Ajax.Request(
		'config/ajax/functions.php',
		{
			method: 'post',
			postBody: pbody,
			onComplete: function(req){
				document.getElementById('status_output').innerHTML = req.responseText;
				if(document.getElementById('status_output').style.display=='none'){
					Effect.toggle('status_output', 'blind');
				}else{
					Effect.toggle('status_output', 'blind', { afterFinish: function() { Effect.toggle('status_output', 'blind'); } });
				}
			}
		});
}

/*--------------------------------------------------------------------------------
Name: uploading_img
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function uploading_img() {
	document.getElementById('upload_form').innerHTML = 'Bild wird hochgeladen. Bitte warten';
}

/*--------------------------------------------------------------------------------
Name: show_status_comments
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function show_status_comments(id) {
	Effect.toggle(id, 'blind', {duration: 0.3});
}

/*--------------------------------------------------------------------------------
Name: status_kommentieren
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function status_kommentieren(id) {
	Effect.toggle(id, 'blind', {duration: 0.3});
}

/*--------------------------------------------------------------------------------
Name: save_status_comment
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_status_comment(id, input_id) {
	var comment = document.getElementById('input_comment_'+input_id).value;
	var pbody = 'func=10&comment='+comment+'&id='+id;
	var myAjax = new Ajax.Request(
		'config/ajax/functions.php',
		{
			method: 'post',
			postBody: pbody,
			onComplete: function(req){
					Effect.toggle('write_status_comment_'+input_id, 'blind', {afterFinish: function() { top.location.href='index.php?site=lobby'; } });
			}
		});
}

/*--------------------------------------------------------------------------------
Name: show_more_gallery_comments
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function show_more_gallery_comments(){
	Effect.toggle('older_comments', 'slide', {duration: 0.7});
}

/*--------------------------------------------------------------------------------
Name: insert_smiley
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function insert_smiley(id, smiley){
	if(document.getElementById(id).value == 'Klicke hier um deinen Kommentar zu schreiben'){
		document.getElementById(id).value = smiley;	
	}else{
		document.getElementById(id).value += 	smiley;
	}
}

/*--------------------------------------------------------------------------------
Name: show_smileys_div
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function show_smileys_div(id){
	Effect.toggle(id, 'slide', {duration: 0.4});
}

/*--------------------------------------------------------------------------------
Name: save_menu_entry
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_menu_entry(nr_radios){
	var title = document.getElementById('m1').value;
	title = search_replace(title, '+', ':plus:');
	var new_page = document.getElementById('m2').checked;
	var order = document.getElementById('order').value;
	order = search_replace(order, '+', ':plus:');
	var radio = '';
	for(i=0; i<nr_radios; i++){
		if(document.getElementsByName('page')[i]){
			if(document.getElementsByName('page')[i].checked){
				radio = document.getElementsByName('page')[i].value;
			}
		}
	}
	if(title!='' && order!='Bitte Auswahl treffen'){
		var pbody = 'func=11&title='+title+'&order='+order+'&radio='+radio+'&new_page='+new_page;
		var myAjax = new Ajax.Request(
			'config/ajax/functions.php',
			{
				method: 'post',
				postBody: pbody,
				onComplete: function(req){
					document.getElementById('status_output').innerHTML = req.responseText;
					document.getElementById('menu_form').style.display = 'none';
					Effect.toggle('status_output', 'blind');
				}
			});
	}else{
		alert('Bitte alle Felder ausfüllen');	
	}
}

/*--------------------------------------------------------------------------------
Name: save_menu_top_changes
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_menu_top_changes(nr_radios, id){
	var title = document.getElementById('m1').value;
	if(document.getElementById('m2'))
		var new_page = document.getElementById('m2').checked;
	else
		var new_page = '';
	var radio = '';
	for(i=0; i<nr_radios; i++){
		if(document.getElementsByName('page')[i]){
			if(document.getElementsByName('page')[i].checked){
				radio = document.getElementsByName('page')[i].value;
			}
		}
	}
	if(title!=''){
		var pbody = 'func=21&id='+id+'&title='+title+'&radio='+radio+'&new_page='+new_page;
		var myAjax = new Ajax.Request(
			'config/ajax/functions.php',
			{
				method: 'post',
				postBody: pbody,
				onComplete: function(req){
					document.getElementById('status_output').innerHTML = req.responseText;
					document.getElementById('menu_form').style.display = 'none';
					Effect.toggle('status_output', 'blind');
				}
			});
	}else{
		alert('Bitte alle Felder ausfüllen');	
	}
}

/*--------------------------------------------------------------------------------
Name: show_menu_linking
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function show_menu_linking(){
	document.getElementById('pages').style.display = 'block';
}

/*--------------------------------------------------------------------------------
Name: hide_menu_linking
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function hide_menu_linking(){
	document.getElementById('pages').style.display = 'none';
}

/*--------------------------------------------------------------------------------
Name: save_menu_order
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_menu_order(string1, length1, string2, lengths2){
	var myAjax = new Ajax.Request(
		'config/ajax/functions.php',
		{
			method: 'post',
			parameters: { data: 'func=12&'+string1+'&length1='+length1+'&'+string2+'&lengths2='+lengths2},
			onComplete: function(req){
				window.location.href = 'index.php?site=admin&sec=7';
				alert("Die Reihenfolge wurde erfolgreich geändert"+req.responseText);
			}
		});
}

/*--------------------------------------------------------------------------------
Name: hide_pw_status
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function hide_pw_status(){
	document.getElementById('pw_status').innerHTML = '';
}

/*--------------------------------------------------------------------------------
Name: show_pw_status
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function show_pw_status(){
	if(document.getElementById('r11').value == document.getElementById('r12').value){
		document.getElementById('pw_status').style.color = '#24ed24';
		document.getElementById('pw_status').innerHTML = '<b>o.k.</b>';	
	}else{
		document.getElementById('pw_status').style.color = '#ff6868';
		document.getElementById('pw_status').innerHTML = '<b>nicht gleich!!!</b>';
	}
}

/*--------------------------------------------------------------------------------
Name: send_registration
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function send_registration(){
	var nickname = document.getElementById('r1').value;
	var fname = document.getElementById('r2').value;
	var lname = document.getElementById('r3').value;
	var adress = document.getElementById('r4').value;
	var plz = document.getElementById('r5').value;
	var city = document.getElementById('r6').value;
	var day = document.getElementById('r7').value;
	var month = document.getElementById('r8').value;
	var year = document.getElementById('r9').value;
	var mail = document.getElementById('r10').value;
	var pw1 = document.getElementById('r11').value;
	var pw2 = document.getElementById('r12').value;
	var captcha = document.getElementById('r13').value;
	var captcha_true = false;
	if(nickname!=''&&fname!=''&&lname!=''&&day!=''&&month!=''&&year!=''&&mail!=''&&pw1!=''&&pw2!=''){
		var pbody = 'func=15&sicherheitscode='+captcha;
		var myAjax = new Ajax.Request(
		'config/ajax/functions.php',
		{
			method: 'post',
			postBody: pbody,
			onComplete: function(req){
				if(req.responseText=='true')
					captcha_true = true;
						
				if(captcha_true){
					if(pw1==pw2){
						var pbody = 'func=13&username='+nickname+'&fname='+fname+'&lname='+lname+'&street='+adress+'&plz='+plz+'&city='+city+'&day='+day+'&month='+month+'&year='+year+'&mail='+mail+'&pw1='+pw1+'&pw2='+pw2;
						var myAjax = new Ajax.Request(
						'config/ajax/functions.php',
						{
							method: 'post',
							postBody: pbody,
							onComplete: function(req){
								if(req.responseText=='username'){
									alert('Username wird bereits verwendet. Bitte wählen sie einen neuen!');	
								}
								else if(req.responseText=='mail'){
									alert('Die angegebene E-Mail Adresse wird bereits von einer anderen Person verwendet!');
								}
								else if(req.responseText=='sonderzeichen'){
									alert('Bitte keine Sonderzeichen im Username verwenden!');
								}else{
									document.getElementById('form').style.display = 'none';
									document.getElementById('status_output').innerHTML = req.responseText;
									Effect.toggle('status_output', 'blind');
								}
								
							}
						});
					}else{
						alert("Die Passwörter stimmen nicht überein!!!");
					}
				}else{
					alert("Die Lösung der Rechnung stimmt nicht");	
				}
			}
		});
	}else{
		alert("Bitte füllen sie alle Pflichtfelder aus!!!");
	}
}

/*--------------------------------------------------------------------------------
Name: send_pw_mail
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function send_pw_mail(){
	var mail_adi = document.getElementById('p1').value;
	var pbody = 'func=14&mail_adi='+mail_adi;
	if(mail_adi!=''){
		var myAjax = new Ajax.Request(
		'config/ajax/functions.php',
		{
			method: 'post',
			postBody: pbody,
			onComplete: function(req){
				if(req.responseText != 'false'){
					document.getElementById('send_mail_div').style.display = 'none';
					document.getElementById('status_output').innerHTML = req.responseText;
					Effect.toggle('status_output', 'blind');
				}else{
					alert('Die eingegebene Mailadresse wurde nicht gefunden!\nSollten sie ihre Mailadresse nicht mehr wissen, kontaktieren sie bitte den Admin');
				}
			}
		});
	}else{
		alert('Du musst deine Mailadresse eingeben, um dein Passwort zu erhalten!');	
	}
}

/*--------------------------------------------------------------------------------
Name: nr_sub_menus
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function nr_sub_menus(){
	var nr_of_subs = document.getElementById('n2').value;
	if(nr_of_subs !=''){
		document.getElementById('submenus').style.display = 'block';
		document.getElementById('titel_submenus').innerHTML = '';
		document.getElementById('linking').style.display = 'none';
		document.getElementById('linking').innerHTML = '<div class="profil_edit_title">Verlinkung</div><div class="profil_edit_border" id="linking1" style="line-height: 23px;"><table style="margin: 0; padding: 0; width: 510px;" cellspacing="0" cellpadding="0" id="linking2"></table></div>';
		for(i=1; i<=nr_of_subs; i++){
			(i<10) ? k = '0'+i : k = i;
			var insertion_text ='Titel Submen&uuml; '+k+': <input onKeyUp="update_linking(this.id)" type="text" class="profil_input" name="s'+i+'" id="s'+i+'" style="margin-left: 35px" />&nbsp;<input type="radio" id="r'+i+'" name="r'+i+'" value="1" onMouseUp="hide_linking(\'s'+i+'\')" checked/>1 &nbsp;&nbsp;<input type="radio" id="q'+i+'" name="r'+i+'" value="2"  onMouseUp="show_linking(\'s'+i+'\')" />2<br />';
			new Insertion.Bottom('titel_submenus', insertion_text);
		}
	}else{
		document.getElementById('submenus').style.display = 'none';	
	}
}

/*--------------------------------------------------------------------------------
Name: show_linking
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function show_linking(id){
	if(!document.getElementById(id+'span')){
		document.getElementById('linking').style.display = 'block';
		var pbody = 'func=16&id='+id+'&menu_title='+document.getElementById(id).value;
		var myAjax = new Ajax.Request(
			'config/ajax/functions.php',
			{
				method: 'post',
				postBody: pbody,
				onComplete: function(req){
					new Insertion.Bottom('linking2', req.responseText);
				}
			});
	}
}

/*--------------------------------------------------------------------------------
Name: hide_linking
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function hide_linking(id){
	if(document.getElementById(id+'tr'))
		$(id+'tr').remove();
}

/*--------------------------------------------------------------------------------
Name: update_linking
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function update_linking(id){
	if(document.getElementById(id+'span')){
		document.getElementById(id+'span').innerHTML = document.getElementById(id).value+'';
	}
}

/*--------------------------------------------------------------------------------
Name: save_new_menu_with()
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_new_menu_with(){
	var title_menu_top = document.getElementById('n1').value;
	var nr_of_subs = document.getElementById('n2').value;
	title_menu_top = search_replace(title_menu_top, '+', ':plus:');
	var no_empty_fields = true;
	if(title_menu_top!='' && nr_of_subs!=''){
		var sub_titles = new Array();
		var radio_choices = new Array();
		for(i=1; i<=nr_of_subs; i++){
			sub_title = document.getElementById('s'+i).value;
			sub_title = search_replace(sub_title, '+', ':plus:');
			sub_titles[(i-1)] = sub_title;
			if(sub_titles[(i-1)]==''){
				no_empty_fields = false;
			}
			if(document.getElementById('s'+i+'tr')){
				radio_choices[(i-1)] = 1;
			}else{
				radio_choices[(i-1)] = 0;
			}
		}
		if(no_empty_fields){
			var links = new Array();
			var link_selected = true;
			for(i=1; i<=nr_of_subs; i++){
				if(document.getElementById('s'+i+'l')){
					links[(i-1)] = document.getElementById('s'+i).value+'='+document.getElementById('s'+i+'l').value;
					var li = document.getElementById('s'+i+'l').value;
					if(li=='--------------------------------' ||li=='--------------------------' || li=='Bearbeitbare Seiten:' || li=='Nicht bearbeitbare Seiten:' || li=='Bitte eine Seite auswählen' ){
						link_selected = false;
					}
				}else{
					links[(i-1)] = document.getElementById('s'+i).value+'= ';	
				}
			}
			if(link_selected){
				var pbody = 'func=17&title='+title_menu_top+'&sub_items='+nr_of_subs;
				for(i=0; i<nr_of_subs; i++){
					pbody += '&sub_title'+(i+1)+'='+sub_titles[i];
					pbody += '&radio'+(i+1)+'='+radio_choices[i];
					pbody += '&'+links[i];
				}
				var myAjax = new Ajax.Request(
					'config/ajax/functions.php',
					{
						method: 'post',
						postBody: pbody,
						onComplete: function(req){
							document.getElementById('menu_form_div').style.display = 'none';
							document.getElementById('status_output').innerHTML = req.responseText;
							Effect.toggle('status_output', 'blind');
						}
					});
			}else{
				alert('Bitte bei den zu verlinkenden Seiten einen Link angeben!');	
			}
		}else{
			alert("Bitte alle Sub-Felder ausfüllen!");	
		}
	}else{
		alert('Bitte alle Felder ausfüllen!');	
	}
}

/*--------------------------------------------------------------------------------
Name: save_submenu_entry
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_submenu_entry(nr_radios){
	var title = document.getElementById('u1').value;
	title = search_replace(title, '+', ':plus:');
	var new_page = document.getElementById('u2').checked;
	var of = document.getElementById('of').value;
	var radio = '';
	for(i=0; i<nr_radios; i++){
		if(document.getElementsByName('page')[i]){
			if(document.getElementsByName('page')[i].checked){
				radio = document.getElementsByName('page')[i].value;
			}
		}
	}
	if(title!='' && of!='Bitte Auswahl treffen'){
		var pbody = 'func=18&title='+title+'&of='+of+'&radio='+radio+'&new_page='+new_page;
		var myAjax = new Ajax.Request(
			'config/ajax/functions.php',
			{
				method: 'post',
				postBody: pbody,
				onComplete: function(req){
					document.getElementById('status_output').innerHTML = req.responseText;
					document.getElementById('menu_form').style.display = 'none';
					Effect.toggle('status_output', 'blind');
				}
			});
	}else{
		alert('Bitte alle Felder ausfüllen');	
	}
}

/*--------------------------------------------------------------------------------
Name: delete_top_menu
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function delete_top_menu(title) {
	var state = window.confirm('Willst du den Menü-Eintrag "'+title+'" und dessen Unterkapitel wirklich löschen?')
	title = search_replace(title, '+', ':plus:');
	if(state){
		var pbody = 'func=19&title='+title;
		var myAjax = new Ajax.Request(
			'config/ajax/functions.php',
			{
				method: 'post',
				postBody: pbody,
				onComplete: function(req){
					window.location.href = 'index.php?site=admin&sec=10';
				}
			});
	}
}

/*--------------------------------------------------------------------------------
Name: delete_sub_menu
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function delete_sub_menu(id,title) {
	var state = window.confirm('Willst du den Menü-Eintrag "'+title+'" wirklich löschen?')
	if(state){
		var pbody = 'func=20&id='+id;
		var myAjax = new Ajax.Request(
			'config/ajax/functions.php',
			{
				method: 'post',
				postBody: pbody,
				onComplete: function(req){
					window.location.href = 'index.php?site=admin&sec=10';
				}
			});
	}
}

/*--------------------------------------------------------------------------------
Name: delete_sub_menu
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_changes_sub(nr_radios,id) {
	var title = document.getElementById('u1').value;
	title = search_replace(title, '+', ':plus:');
	var new_page = document.getElementById('u2').checked;
	var of = document.getElementById('of').value;
	var radio = '';
	for(i=0; i<nr_radios; i++){
		if(document.getElementsByName('page')[i]){
			if(document.getElementsByName('page')[i].checked){
				radio = document.getElementsByName('page')[i].value;
			}
		}
	}
	if(title!='' && of!='Bitte Auswahl treffen'){
		var pbody = 'func=22&id='+id+'&title='+title+'&of='+of+'&radio='+radio+'&new_page='+new_page;
		var myAjax = new Ajax.Request(
			'config/ajax/functions.php',
			{
				method: 'post',
				postBody: pbody,
				onComplete: function(req){
					document.getElementById('status_output').innerHTML = req.responseText;
					document.getElementById('menu_form').style.display = 'none';
					Effect.toggle('status_output', 'blind');
				}
			});
	}else{
		alert('Bitte alle Felder ausfüllen');	
	}
}

/*--------------------------------------------------------------------------------
Name: save_new_page
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_new_page(){
	for ( i = 0; i < parent.frames.length; ++i ) {
		if ( parent.frames[i].FCK )
			parent.frames[i].FCK.UpdateLinkedField();
	}
	var content = document.getElementById("FCKeditor1").value;
	var title = document.getElementById('np1').value;	
	xajax_save_new_page_content(content, title);
	if(document.getElementById('edit_output').style.display=='none'){
		new Effect.toggle('edit_output', 'blind');
	}
}

/*--------------------------------------------------------------------------------
Name: delete_page
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function delete_page(id, title){
	var state = window.confirm('Willst du die Seite "'+title+'" wirklick löschen?')
	if(state){
		var pbody = 'func=24&id='+id;
		var myAjax = new Ajax.Request(
			'config/ajax/functions.php',
			{
				method: 'post',
				postBody: pbody,
				onComplete: function(req){
					window.location.href = 'index.php?site=admin&sec=12'
				}
			});
	}
}

/*--------------------------------------------------------------------------------
Name: admin_page_changes_save
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function admin_page_changes_save(id) {
	for ( i = 0; i < parent.frames.length; ++i ) {
		if ( parent.frames[i].FCK )
			parent.frames[i].FCK.UpdateLinkedField();
	}
	var content = document.getElementById("FCKeditor1").value;
	var title = document.getElementById('np1').value;	
	xajax_save_change_page_content(content, title, id);
	if(document.getElementById('edit_output').style.display=='none'){
		new Effect.toggle('edit_output', 'blind');
	}else{
		Effect.toggle('edit_output', 'blind', {afterFinish: function() { Effect.toggle('edit_output', 'blind'); }});
	}
}

/*--------------------------------------------------------------------------------
Name: show_galeries
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function show_galleries(){
	var element = document.getElementById('galleries');
	if(element.style.display=='none')
		element.style.display = 'block';
	else
		element.style.display = 'none';
}

/*--------------------------------------------------------------------------------
Name: save_news_entry
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_news_entry(nr_of_gal){
	for ( i = 0; i < parent.frames.length; ++i ) {
		if ( parent.frames[i].FCK )
			parent.frames[i].FCK.UpdateLinkedField();
	}
	var content = document.getElementById("FCKeditor1").value;
	var title = document.getElementById('n1').value;	
	var author = document.getElementById('n2').value;
	var gallery = document.getElementById('n3').checked;
	var radio = '';
	if(gallery){
		for(var i=1; i<=nr_of_gal; i++){
			if(document.getElementById(i).checked==true){
				radio = document.getElementById(i).value;
			}
		}
	}
	if(content!='' && title!='' && author!==''){
		xajax_save_news(content, title, author, radio);
		Effect.toggle('status_output', 'blind');
	}else{
		alert('Bitte alle Pflichtfelder ausfüllen!');
	}
}

/*--------------------------------------------------------------------------------
Name: delete_news_entry
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function delete_news_entry(id){
	var state = window.confirm('Willst du den News-Eintrag wirklich löschen?')
	if(state){
		var pbody = 'func=25&id='+id;
		var myAjax = new Ajax.Request(
			'config/ajax/functions.php',
			{
				method: 'post',
				postBody: pbody,
				onComplete: function(req){
					window.location.href = 'index.php?site=admin&sec=14'
				}
			});
	}
}

/*--------------------------------------------------------------------------------
Name: save_news_changes
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_news_changes(nr_of_gal, id){
	for ( i = 0; i < parent.frames.length; ++i ) {
		if ( parent.frames[i].FCK )
			parent.frames[i].FCK.UpdateLinkedField();
	}
	var content = document.getElementById("FCKeditor1").value;
	var title = document.getElementById('n1').value;	
	var author = document.getElementById('n2').value;
	var gallery = document.getElementById('n3').checked;
	var radio = '';
	if(gallery){
		for(var i=1; i<=nr_of_gal; i++){
			if(document.getElementById(i).checked==true){
				radio = document.getElementById(i).value;
			}
		}
	}
	if(content!='' && title!='' && author!==''){
		xajax_save_newschanges(content, title, author, radio, id);
		if(document.getElementById('status_output').style.display=='none'){
			Effect.toggle('status_output', 'blind');
		}else{
			Effect.toggle('status_output', 'blind', {afterFinish: function() { Effect.toggle('status_output', 'blind'); }});
		}
	}else{
		alert('Bitte alle Pflichtfelder ausfüllen!');
	}
}

/*--------------------------------------------------------------------------------
Name: guestbook_form
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function guestbook_form(){
	Effect.toggle('gbook_form', 'slide');
}

/*--------------------------------------------------------------------------------
Name: save_gbook_entry
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_gbook_entry(){
	var name = document.getElementById('g1').value;
	var mail = document.getElementById('g2').value;
	var www = document.getElementById('g3').value;
	var text = document.getElementById('g4').value;
	text = search_replace(text, '&', ':and:');
	name = search_replace(name, '&', ':and:');
	if(name!='' && text!=''){
		var pbody = 'func=26&name='+name+'&mail='+mail+'&www='+www+'&text='+text;
		var myAjax = new Ajax.Request(
			'config/ajax/functions.php',
			{
				method: 'post',
				postBody: pbody,
				onComplete: function(req){
					window.location.href = 'index.php?site=gaestebuch'
				}
			});
	}else{
		alert('Bitte alle Pflichtfelder ausfüllen');	
	}
}

/*--------------------------------------------------------------------------------
Name: delete_gbook
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function delete_gbook(id){
	var state = window.confirm('Willst du diesen Eintrag wirklich löschen?')
	if(state){
		var pbody = 'func=27&id='+id;
		var myAjax = new Ajax.Request(
			'config/ajax/functions.php',
			{
				method: 'post',
				postBody: pbody,
				onComplete: function(req){
					window.location.href = 'index.php?site=gaestebuch'
				}
			});
	}
}

/*--------------------------------------------------------------------------------
Name: edit_gbook
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function edit_gbook(id){
	if(document.getElementById('gbook_edit_form').style.display == 'none'){
		xajax_edit_gbook_entry(id);
		document.getElementById('gbook_edit_form').style.display = 'block';
	}else{
		document.getElementById('gbook_edit_form').style.display = 'none';
	}
}

/*--------------------------------------------------------------------------------
Name: gbook_change
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function gbook_change(){
	var name = document.getElementById('e1').value;
	var mail = document.getElementById('e2').value;
	var www = document.getElementById('e3').value;
	var text = document.getElementById('e4').value;
	var id = document.getElementById('e5').value;
	text = search_replace(text, '&', ':and:');
	name = search_replace(name, '&', ':and:');
	if(name!='' && text!=''){
		var pbody = 'func=28&name='+name+'&mail='+mail+'&www='+www+'&text='+text+'&id='+id;
		var myAjax = new Ajax.Request(
			'config/ajax/functions.php',
			{
				method: 'post',
				postBody: pbody,
				onComplete: function(req){
					window.location.href = 'index.php?site=gaestebuch'
				}
			});
	}else{
		alert('Bitte alle Pflichtfelder ausfüllen');	
	}
}

/*--------------------------------------------------------------------------------
Name: send_message
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function send_message(){
	var subject = document.getElementById('m1').value;
	var message = document.getElementById('m2').value;
	var receiver = document.getElementById('m3').value;
	message = search_replace(message, '&', ':and:');
	subject = search_replace(subject, '&', ':and:');
	if(message!='' && receiver!='auswahl'){
		var pbody = 'func=29&subject='+subject+'&receiver='+receiver+'&message='+message;
		var myAjax = new Ajax.Request(
			'config/ajax/functions.php',
			{
				method: 'post',
				postBody: pbody,
				onComplete: function(req){
					alert("Nachricht wurde geschickt");
					window.location.href = 'index.php?site=nachrichten'
				}
			});
	}else{
		alert('In der Nachricht sollte schon ein Text vorhanden und ein Empfänger gewählt sein!');	
	}
}

/*--------------------------------------------------------------------------------
Name: send_delete_message
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function send_delete_message(id){
	var state = window.confirm('Willst du diese Nachricht wirklich löschen?')
	if(state){
		var pbody = 'func=30&id='+id;
		var myAjax = new Ajax.Request(
			'config/ajax/functions.php',
			{
				method: 'post',
				postBody: pbody,
				onComplete: function(req){
					window.location.href = 'index.php?site=nachrichten'
				}
			});
	}
}

/*--------------------------------------------------------------------------------
Name: send_delete_message2
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function send_delete_message2(id){
	var state = window.confirm('Willst du diese Nachricht wirklich löschen? Die Nachricht wird nur aus deinem Postausgang gelöscht')
	if(state){
		var pbody = 'func=31&id='+id;
		var myAjax = new Ajax.Request(
			'config/ajax/functions.php',
			{
				method: 'post',
				postBody: pbody,
				onComplete: function(req){
					window.location.href = 'index.php?site=nachrichten&sub=out'
				}
			});
	}
}

/*--------------------------------------------------------------------------------
Name: admin_changes
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function admin_changes(nr_of_profils){
	var nr_of_admins = 0;
	var admins = '';
	for(i=1; i<=nr_of_profils; i++){
		if(document.getElementById(i).checked){
			admins += 'admin'+i+'='+document.getElementById(i).value+'&';
			nr_of_admins++;
		}
	}
	var pbody = 'func=32&'+admins+'nr_of_admins='+nr_of_admins;
	var myAjax = new Ajax.Request(
		'config/ajax/functions.php',
		{
			method: 'post',
			postBody: pbody,
			onComplete: function(req){
				alert('Die Änderungen wurden erfolgreich gespeichert');
			}
		});
}

/*--------------------------------------------------------------------------------
Name: send_delete_user
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function send_delete_user(id, nick){
	var state = window.confirm('Willst du "'+nick+'" wirklich löschen?')
	if(state){
		var pbody = 'func=33&id='+id;
		var myAjax = new Ajax.Request(
		'config/ajax/functions.php',
		{
			method: 'post',
			postBody: pbody,
			onComplete: function(req){
				window.location.href = 'index.php?site=admin&sec=15';
			}
		});
	}
}

/*--------------------------------------------------------------------------------
Name: save_new_report
Description: saves a report
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_new_report(){
	for ( i = 0; i < parent.frames.length; ++i ) {
		if ( parent.frames[i].FCK )
			parent.frames[i].FCK.UpdateLinkedField();
	}
	var content = document.getElementById("FCKeditor1").value;
	var title = document.getElementById('r1').value;	
	var author = document.getElementById('r2').value;
	if(document.getElementById('r3').checked){
		var vorstand = 1
	}else{
		var vorstand = 0
	}
	if(document.getElementById('r4').checked){
		var riegen = 1
	}else{
		var riegen = 0
	}
	if(content!='' && title!='' && author!=='' && (riegen!==0 || vorstand!==0)){
		xajax_save_report(content, title, author, vorstand, riegen);
		Effect.toggle('status_output', 'blind');
	}else{
		alert('Bitte alle Pflichtfelder ausfüllen!');
	}
}

/*--------------------------------------------------------------------------------
Name: delete_report_entry
Description: user_menu to login
Author: Martin Brack
--------------------------------------------------------------------------------*/
function delete_report_entry(id){
	var state = window.confirm('Willst du diesen Bericht wirklich löschen?')
	if(state){
		var pbody = 'func=35&id='+id;
		var myAjax = new Ajax.Request(
			'config/ajax/functions.php',
			{
				method: 'post',
				postBody: pbody,
				onComplete: function(req){
					window.location.href = 'index.php?site=admin&sec=17'
				}
			});
	}
}

/*--------------------------------------------------------------------------------
Name: save_report_changes
Description: saves a report
Author: Martin Brack
--------------------------------------------------------------------------------*/
function save_report_changes(id){
	for ( i = 0; i < parent.frames.length; ++i ) {
		if ( parent.frames[i].FCK )
			parent.frames[i].FCK.UpdateLinkedField();
	}
	var content = document.getElementById("FCKeditor1").value;
	var title = document.getElementById('r1').value;	
	var author = document.getElementById('r2').value;
	if(document.getElementById('r3').checked){
		var vorstand = 1
	}else{
		var vorstand = 0
	}
	if(document.getElementById('r4').checked){
		var riegen = 1
	}else{
		var riegen = 0
	}
	if(content!='' && title!='' && author!=='' && (riegen!==0 || vorstand!==0)){
		xajax_save_reportchanges(content, title, author, id, vorstand, riegen);
		if(document.getElementById('status_output').style.display=='none'){
			Effect.toggle('status_output', 'blind');
		}else{
			Effect.toggle('status_output', 'blind', {afterFinish: function() { Effect.toggle('status_output', 'blind'); }});
		}
	}else{
		alert('Bitte alle Pflichtfelder ausfüllen!');
	}
}
