<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>
<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">
$(function () {
	$('#blocks-edit-form').verify_values ({
		handler: 'blocks/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 %}

	$('#blocks-edit-form').autosave ();
	$('#blocks-edit-form').bgsave ({
		url: '/blocks/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_add_title_to_id (f) {
	if (f.elements.id.value == '') {
		f.elements.id.value = f.elements.title.value.toLowerCase ().replace (/[^a-z0-9\-]+/g, '-');
	}
}
</script>
