/* Move the submit/reset buttons to the button bar */
window.addEvent('domready', function() {
	/* Remove the old buttons */
	$('feedForm').Save.destroy();
	$('feedForm').Clear.destroy();

	var saveButton = addButtonToButtonBar('Save');
	saveButton.addEvent('click', function() {
		var form = $('feedForm');
		form.submit();
	});

	var cancelButton = addButtonToButtonBar('Cancel');
	cancelButton.addEvent('click', function() {
		window.location = BaseURL;
	});

	/* Create a preview button */
	var previewButton = addButtonToButtonBar('Preview');
	previewButton.addEvent('click', function () {
		var form = $('feedForm');
		var previewContainer = $('previewContainer');
		previewContainer.empty();
		previewContainer.set('text', 'Loading preview');
		
		req = new Request.HTML({
			url: BaseURL + 'feed/previewFeedWithXPath',
			evalScripts: false,
			update: previewContainer,
			onFailure: function() {
				previewContainer.empty();
				previewContainer.set('text', 'An error occured while loading the preview');
			}
		}).send(form);
	});
});
