﻿_j = jQuery.noConflict();

var tocalendar =
{
	step: 1,
	created: 0,
	
	init: function()
	{
		if(_j('#create-event-button').text() != 'Event erstellen')
			tocalendar.created = 1;
		
		_j('#create-event-button').live('click', function()
		{
			if(tocalendar.created == 0)
			{
				if(tocalendar.step == 1)
				{
					_j(this).text('Event speichern');
					_j('#create-event').slideDown();
					tocalendar.step = 2;
				}
				else
				{
					_j(this).text('Event löschen');
					_j('#create-event').slideUp();
					tocalendar.created = 1;
					
					_j.ajax({
						type: 'POST',
						url: 'xmlhttp.php?action=tocalendar_create_event&tid=' + _j('#create-event-tid').val() + '&date=' + _j('#create-event-date').val(),
						success: function(ret)
						{
							alert('Event wurde erstellt!');
						}
					});
						
				}
			}
			else
			{
				tocalendar.step = 1;
				tocalendar.created = 0;
				_j(this).text('Event erstellen');
				
				_j.ajax({
					type: 'POST',
					url: 'xmlhttp.php?action=tocalendar_delete_event&tid=' + _j('#create-event-tid').val(),
					success: function(ret)
					{
						alert('Event wurde gelöscht!');
					}
				});
			}
		});
	}
};

_j(document).ready(function()
{
	tocalendar.init();
});
