function ajax_previousmonth(month, year)
{
	ajax_month(month,year,"previous");
}

function ajax_nextmonth(month, year)
{
	ajax_month(month,year,"next");
}

function dateonclick(day, month, year)
{
	event_div = "#ajax_event_" + day;
	
	if($(event_div).css('display') == 'block')
	{
		remove_event(day);
	}
	else
	{
		get_event(day,month,year);
	}
}

function get_event(day,month,year)
{
	$.ajax({
		type: "POST",
		url: BASE + '/ajax/calendarday',
		data: "day=" + day + "&month=" + month + '&year=' + year,
		beforeSend: function()
		{
			$("#calendar_day_" + day).addClass("active_day");
			$("#calendarmessage").html("Getting event(s)...").slideDown("slow");
		},
		success: function(msg)
		{
			$("#calendarmessage").slideUp("slow");
			$("#calendarresponse").slideDown().prepend(msg);
			$("#ajax_event_" + day).slideDown("slow");
		},
		error: function()
		{
			$("#calendarbox").html("Calendar Error");
		} 
	});
}
	
function remove_event(day)
{
	event_div = "#ajax_event_" + day;
	$("#calendar_day_" + day).removeClass("active_day");
	$(event_div).slideUp("slow");
}

function remove_all_events()
{
	$(".calendar_event_box").remove();
}

function ajax_month(month,year,requestType)
{
	requestUrl = BASE + '/ajax/calendar' + requestType;
	
	$.ajax({
		type: "POST",
		url: requestUrl,
		data: "month=" + month + '&year=' + year,
		beforeSend: function()
		{	
			$("#calendarresponse").slideUp("slow");
			$("#calendarmessage").html("Requesting Month...").slideDown("slow");
		},
		success: function(msg)
		{
			remove_all_events();
			$("#chuggCalendarContent").html(msg);
			$("#calendarmessage").slideUp("slow");
		},
		error: function()
		{
			$("#chaseCalendarContent").html("Calendar Error");
			$("#calendarmessage").slideUp("slow");
		} 
	});
}
