<script type="text/javascript" src="/js/json2.js"></script>
<script type="text/javascript" src="/js/jstorage.js"></script>
<script type="text/javascript" src="/js/jquery.autosave.js"></script>
<style type="text/css">
/* css for timepicker */
.ui-timepicker-div .ui-widget-header{ margin-bottom: 8px; }
.ui-timepicker-div dl{ text-align: left; }
.ui-timepicker-div dl dt{ height: 25px; }
.ui-timepicker-div dl dd{ margin: -25px 0 10px 65px; }
.ui-timepicker-div td { font-size: 90%; }

.ui-datepicker { z-index: 9999 !important; }
.ui-timepicker { z-index: 9999 !important; }
</style>
<script type="text/javascript" src="/apps/blog/js/jquery.timepicker.js"></script>
<link rel="stylesheet" type="text/css" href="/apps/blog/css/jquery.tagit.css" />
<!-- script type="text/javascript" src="/apps/blog/js/autocomplete.js"></script -->
<script type="text/javascript" src="/apps/blog/js/tag-it.js"></script>
<script type="text/javascript" src="/js/jquery.bgsave.js"></script>
<script type="text/javascript" src="/js/jquery.verify_values.js"></script>
<script type="text/javascript">
var tagit_available_tags = [];
$(function () {
	function subtract_array (a1, a2) {
		var result = [];
		for (var i = 0; i < a1.length; i++) {
			if ($.inArray (a1[i], a2) == -1) {
				result.push (a1[i]);
			}
		}
		return result;
	};
	$.getJSON ('/blog/taglist', function (res) {
		tagit_available_tags = res;
	});
	$('#ts').datetimepicker ({
		timeFormat: 'hh:mm:ss',
		dateFormat: 'yy-mm-dd',
		hourGrid: 4,
		minuteGrid: 10
	});
	$('#tagit').tagit ({
		singleFieldNode: document.getElementById ('tags'),
		allowSpaces: true,
		singleField: true,
		caseSensitive: false,
		tagSource: function (search, showChoices) {
			var filter = search.term.toLowerCase ();
			var choices = $.grep (tagit_available_tags, function (element) {
				return (element.toLowerCase ().indexOf(filter) === 0);
			});
			showChoices (subtract_array (choices, $('#tagit').tagit ('assignedTags')));
		}
	});
	$('#blog-edit-form').verify_values ({
		handler: 'blog/edit',
		callback: function (failed) {
			// highlight the failed elements
			for (var i = 0; i < failed.length; i++) {
				$('#' + failed[i] + '-notice').show ();
			}
		},
		reset: function (fields) {
			for (var i = 0; i < fields.length; i++) {
				$('#' + fields[i] + '-notice').hide ();
			}
		}
	});
	{% foreach failed %}
	$('#{{ loop_value }}-notice').show ();
	{% end %}

	$('#blog-edit-form').autosave ();
	$('#blog-edit-form').bgsave ({
		url: '/blog/bgsave?id=',
		id: '{{ id }}',
		msg_saving: '{"Saving..."}',
		msg_saved: '{"Saved!"}',
		msg_failed: '{"Failed to save..."}'
	});
});
function webpage_show_extra_options (link) {
	var eo = $('#extra-options');
	if (eo.css ('display') == 'none') {
		eo.slideDown ('fast', function () {
			window.scrollTo (0, 1000);
		});
		$(link).find ('.arrow').removeClass ('arrow-off');
	} else {
		eo.slideUp ('fast', function () {
			$(this).css ('display', 'none');
		});
		$(link).find ('.arrow').addClass ('arrow-off');
	}
	return false;
}
function webpage_preview (f) {
	var t = f.target,
		a = f.action;

	f.target = 'elefant-preview';
	f.action = '/blog/preview';
	f.submit ();

	f.target = t;
	f.action = a;
	return false;
}
</script>
