/* ***** ExecCP Function ***** */
var ExecCP = new function() {
	/**
	 * Event Function
	 */
	this.Event = new function() {
		/**
		 * Deletes the specified event
		 *
		 * @param	integer	Event ID
		 * @param	boolean	(Optional)	Flag for deleting events from the event page
		 *
		 * @return	boolean	Returns FALSE
		 */
		this.delete = function(id, reload) {
			reload = reload == undefined ? true : reload;
			$.alerts.draggable = false;
			jConfirm("Are you sure you wish to delete the event '" + $("#event_" + id).html() + "'?", "Delete Event", function(r) {
				if (r) {
					$.ajax(WFS.base + "/execcp/?page=delete-event", {
						data: "id=" + id,
						success: function(data, textStatus, jqXHR) {
							if (reload) {
								window.location.reload();
							} else {
								window.location.href = WFS.base + "execcp/delete-event";
							}
						},
						type: "POST"
					});
				}
			});
			return false;
		}
	};
	
	/**
	 * News Function
	 */
	this.News = new function() {
		/**
		 * Deletes the specified news item
		 *
		 * @param	integer	News ID
		 * @param	boolean	(Optional)	Flag for deleting news from the event page
		 *
		 * @return	boolean	Returns FALSE
		 */
		this.delete = function(id, reload) {
			reload = reload == undefined ? true : reload;
			$.alerts.draggable = false;
			jConfirm("Are you sure you wish to delete the news item '" + $("#news_" + id).html() + "'?", "Delete News", function(r) {
				if (r) {
					$.ajax(WFS.base + "/execcp/?page=delete-news", {
						data: "id=" + id,
						success: function(data, textStatus, jqXHR) {
							if (reload) {
								window.location.reload();
							} else {
								window.location.href = WFS.base + "execcp/delete-news";
							}
						},
						type: "POST"
					});
				}
			});
			return false;
		}
	};
	
	/**
	 * Creates a CKFinder pop-up
	 *
	 * @return	boolean	Returns FALSE
	 */
	this.browseServer = function() {
		var finder = new CKFinder();
		finder.basepath = "/ckfinder/";
		finder.selectActionFunction = function(fileUrl, data) {
			$("body", $("iframe").contents()).append("<img src=\"" + fileUrl + "\" />");
		};
		finder.popup();
		return false;
	};
};

/* ***** ExecCP JS ***** */
$(function() {
    $(".cledit").each(function() {
        $(this).cleditor({
            controls: "bold italic underline strikethrough subscript superscript | font size style | color highlight removeformat | bullets numbering | outdent indent | alignleft center alignright justify | undo redo | rule image link unlink | cut copy paste pastetext | print source",
            height: 250,
            width: 713
        });
    });
	$(".dtpick").each(function() {
		$(this).datetimepicker({
			dateFormat: "dd/mm/yy",
			hourGrid: 4,
			minuteGrid: 10,
			onClose: function(dateText, inst) {
				$(this).val(dateText).focus();
			},
			separator: ", ",
			timeFormat: "hh:mm"
		});
	});
	$(".ckedit").each(function() {
		$(this).ckeditor();
	});
	$("#view-mailing-lists").colorbox({
		height: "80%",
		href: "#mailing-lists",
		inline: true,
		width: "80%"
	});
});
