<script src="/js/json2.js"></script>
<script src="/js/jstorage.js"></script>
<script src="/js/jquery.autosave.js"></script>
<script src="/js/jquery.bgsave.js"></script>
<script src="/js/jquery.verify_values.js"></script>
<script src="/js/urlify.js"></script>
<script>
$(function () {
	$('#admin-edit-form').verify_values ({
		handler: 'admin/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 %}

	$('#admin-edit-form').autosave ();
	$('#admin-edit-form').bgsave ({
		url: '/admin/bgsave?id=',
		id: '{{ id }}',
		msg_saving: '{"Saving..."}',
		msg_saved: '{"Saved!"}',
		msg_failed: '{"Failed to save..."}'
	});
});
function webpage_add_title_to_id (f) {
	if (f.elements.id.value == '') {
		f.elements.id.value = URLify (f.elements.title.value, 60).replace (/-$/, '');
	}
}
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 = '/admin/preview';
	f.submit ();

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