function initQuickEvents() {
	var datepickerOptions = { 
		altFormat: 'yy-mm-dd' 
	};
	$( "#event-date-from input" ).datepicker(datepickerOptions);
	$( "#event-date-to input" ).datepicker(datepickerOptions);

	$('.main-form').ajaxForm({
		//dataType: 'json', // no anda
		success: function(responseText, statusText, xhr) {
			//Why the plugin inserts this tags to the response ?
			responseText = responseText.replace(/<head><\/head><body>/gi, "");
			responseText = responseText.replace(/<\/body>/gi, "");
			//alert(responseText);
			var resp = null ;
			try{
				var resp = eval("("+responseText+")") ;
			}catch(e) {
				alert("invalid response") ;
			}	
			if (resp.error) {
				$("#quick-event-message").fadeOut().html(resp.msg).fadeIn() ;
				Recaptcha.reload() ;
				scroll(0,0);
				
			}else {
				$("#quick-event-form").dialog('close');
				$("#quick-event-form").html(resp.msg) ;
				$("#quick-event-form").dialog({
					modal:true,
					"close": function() { $(this).dialog("destroy"); $("#quick-event-form").html("");}, 
					buttons: { "Close": function() { $(this).dialog("close"); } }
				});
			}

		}
	});
}



$(document).ready(function(){

	$("#add-event-button").click( function(){		
		var url = "forms/quick-event/index.php" ;
		var dialogId = "quick-event-form" ;	
		var dialog = $("#"+dialogId) ;		
		
		
		
		var dialogOptions = {
			modal:true, 
			width:750,
			title: 'Add Event',
			buttons: { 
				"Close": function() { $(this).dialog("destroy"); dialog.html("") ; } ,
				"Submit": function() { $(".main-form").submit(); }
				
			},
			"close": function() { $(this).dialog("destroy"); dialog.html("") ; } 
		};
		
		

				
		if ( dialog.length == 0 )  {
			var dialog = $('<div id="'+dialogId+'"></div>').appendTo('body');
		}
			// load remote content
		dialog.load(
			url, 
			{},
			function (responseText, textStatus, XMLHttpRequest) {
				dialog.dialog(dialogOptions);
				
			}
		);

		return false;

	});
	
});
