$("#event-creator-initiate").click(function(){
	document.getElementById("event-creator-initiate").style.display = "none";
	$("#event-creator").append( "<input type='text' name='date' id='newDate' placeholder='DD/MM' minlength='3' maxlength='5' autocomplete='off' >");
	document.getElementById("newDate").focus();
	
	$("#event-creator").append( "<button id='reject'>X</button>");
	$("#event-creator").append( "<button id='confirm'>Y</button>");
	
	$("#reject").click(function(){
		resetCreation();
	});

	$("#confirm").click(function(){
		var date = document.getElementById("newDate").value;
		var arr = date.split('/');
		
		var currentDate = new Date();
		var monthNumber = currentDate.getMonth();
		
		if(arr[0].length < 2){
			arr[0] = "0" + arr[0];
		}
		if(arr[1].length < 2){
			arr[1] = "0" + arr[1];
		}

		if(arr[1] < monthNumber){
			var realDate = "2016-" + arr[1] + "-" + arr[0];
		}
		else{
			var realDate = "2015-" + arr[1] + "-" + arr[0];
		}
		
		var prelDate = new Date(realDate);
		prelDate.setDate(prelDate.getDate() - 14);
		prelDate = formatDate(prelDate);
		
		var payDate = new Date(realDate);
		payDate.setDate(payDate.getDate() - 10);
		payDate = formatDate(payDate);

		$.ajax({
			type: 'POST',
			url: 'db/dbAjax.php',
			data: 'action=addSitting&date=' + realDate + '&preldate=' + prelDate + '&paydate=' + payDate,
			success: function(data){
				$(".event-window:nth-last-child(2)").clone().insertBefore("#event-creator");
				$(".event-window:nth-last-child(2)").attr("id",realDate);
				$(".event-window:nth-last-child(2)").find(".event-window-date").html(date);
				resetCreation()
			}
		});
	});
});

function formatDate(date) {
    var d = new Date(date),
        month = '' + (d.getMonth() + 1),
        day = '' + d.getDate(),
        year = d.getFullYear();

    if (month.length < 2) month = '0' + month;
    if (day.length < 2) day = '0' + day;

    return [year, month, day].join('-');
}

function resetCreation(){
	$('#newDate').remove();
	$('#reject').remove();
	$('#confirm').remove();
	document.getElementById("event-creator-initiate").style.display = "block";
}
@@ -1336,16 +1336,47 @@
  payDate
++ '&resName=' + RESTAURANT_NAME
 ,%0A%09%09%09suc
@@ -1397,16 +1397,33 @@
 (data)%7B%0A
+%09%09%09%09alert(data);%0A
 %09%09%09%09$(%22.

Send resname when creating event