
	function sure ()
	{
		if (confirm ('Bist Du sicher?'))
		{
			return true;
		}
		return false;
	}
	
	function newEntry ()
	{
		$('#msg').hide('fast');
		$('#show').hide('slow');
		$('#edit').hide('slow');
		$('#new').show('slow');
	}
	
	function cancelEntry ()
	{
		$('#msg').hide('fast');
		$('#show').hide('slow');
		$('#edit').hide('slow');
		$('#new').hide('slow');
	}
	
	function editReminder (id, sid)
	{
		$('#msg').hide('fast');
		$.getJSON("run.php",
		  { action: "reminder", mode: "get", id: id, sid: sid, ajax: "true" },
		  function(json){
			if (json.status == 'success')
			{
				if (document.getElementById('edit').style.display == 'block')
				{
					$("#edit").css({ visibility: "hidden" });
				}
				$("#day").val(json.day);
				$("#month").val(json.month);
				$("#event").val(json.event.replace(/<br\s*\/?>/mg,"\n"));
				$("#recur").val(json.recur);
				$("#notice").val(json.notice);
				$("#id").val(json.id);
				if (document.getElementById('edit').style.display == 'block')
				{
					$("#edit").fadeIn(500);
					$("#edit").css({ visibility: "visible" });
				}
				else
				{
					$('#new').hide('slow');
					$('#edit').show('slow');
				}
				return false;
			}
			else if (json.status == 'logout')
			{
				alert ('Du wurdest vom System abgemeldet, bitte melde Dich erneut an!');
				window.location.href = 'index.php';
				return false;
			}
			else
			{
				alert ('Es ist ein Fehler aufgetreten, versuch es noch einmal!');
				return false;
			}
		  }
		);
		return false;
	}
	
	function toggleMonths (id)
	{
		$('#msg').hide('fast');
		for (var i = 1; i < 13; i++)
		{
			$('#month_' + i).hide('slow');
		}
		$('#month_' + id).show('slow');
	}
	
	function editNote (sid)
	{
		var id = $("#notes").val();
		$.getJSON("run.php",
		  { action: "notes", mode: "get", id: id, sid: sid, ajax: "true" },
		  function(json){
			if (json.status == 'success')
			{
				if (document.getElementById('edit').style.display == 'block')
				{
					$("#edit").css({ visibility: "hidden" });
				}
				$("#title").val(json.title);
				$("#text").val(json.text.replace(/<br\s*\/?>/mg,"\n"));
				$("#id").val(json.id);
				if (document.getElementById('edit').style.display == 'block')
				{
					$("#edit").fadeIn(500);
					$("#edit").css({ visibility: "visible" });
				}
				else
				{
					$('#msg').hide('fast');
					$('#show').hide('slow');
					$('#new').hide('slow');
					$('#edit').show('slow');
				}
				return false;
			}
			else if (json.status == 'logout')
			{
				alert ('Du wurdest vom System abgemeldet, bitte melde Dich erneut an!');
				window.location.href = 'index.php';
				return false;
			}
			else
			{
				alert ('Es ist ein Fehler aufgetreten, versuch es noch einmal!');
				return false;
			}
		  }
		);
	}
	
	function showNote (sid)
	{
		var id = $("#notes").val();
		$.getJSON("run.php",
		  { action: "notes", mode: "get", id: id, sid: sid, ajax: "true" },
		  function(json){
			if (json.status == 'success')
			{
				$('#showTitle').empty();
				$('#showText').empty();
				$('#delBtn').empty();
				$('<h3>' + json.title + '</h3>').appendTo("#showTitle");
				$('<div>' + json.text + '</div>').appendTo("#showText");
				$('<div>[<a class="delete" href="run.php?' + sid + '&action=notes&mode=delete&id=' + json.id + '" title="L&ouml;schen" onclick="return sure();"> X </a>]</div>').appendTo("#delBtn");
				$('#msg').hide('fast');
				$('#new').hide('slow');
				$('#edit').hide('slow');
				$('#show').show('slow');
				return false;
			}
			else if (json.status == 'logout')
			{
				alert ('Du wurdest vom System abgemeldet, bitte melde Dich erneut an!');
				window.location.href = 'index.php';
				return false;
			}
			else
			{
				alert ('Es ist ein Fehler aufgetreten, versuch es noch einmal!');
				return false;
			}
		  }
		);
	}
	
	function msg (txt)
	{
		$('#msg').empty();
		$('<div><p>' + txt + '</p></div>').appendTo("#msg");
		$('#msg').show('fast');
	}
	
	function checkForms (ids)
	{
		for (var i = 0; i < ids.length; i++)
		{
			if ($("#" + ids[i]).val() == '')
			{
				msg ('Du hast nicht alle ben&ouml;tigten Felder ausgef&uuml;llt!');
				$('#' + ids[i]).css({ border: "1px solid red" });
				document.getElementById(ids[i]).focus();
				return false;
			}
			$('#' + ids[i]).css({ border: "1px solid #a4b97f" });
		}
		return true;
	}
	
	function toggleHelp ()
	{
		$('#help').toggle('slow');
	}
