// post.php calls/*------- Tags -------- */function new_tag_remove_tag() {	var id = this.id;	var num = id.substr(10);	var current_tags = $F('tags').split(',');	delete current_tags[num];	var new_tags = [];	var key = 0;	current_tags.each(function(item) {		if (item && !item.match(/^\s+$/) && '' != item) {			new_tags = new_tags.concat(item);		}		key++;	});	$('tags').setValue(new_tags.join(',').search_replace(/\s*,+\s*/, ',').search_replace(/,+/, ',').search_replace(/,+\s+,+/, ',').search_replace(/,+\s*$/, '').search_replace(/^\s*,+/, ''));	tag_update_quickclicks();	$('newtag').focus();	return false;}function tag_update_quickclicks() {	if ($('tags').length == 0) return;	var current_tags = $F('tags').split(',');	var final_tags = [];	$('tagchecklist').update('');	shown = false;	//	jQuery.merge(current_tags, current_tags); // this doesn't work anymore, need something to array_unique	current_tags = current_tags.uniq();	key = 0;	current_tags.each(function(item) {		item = item.search_replace(/^\s+/, '').search_replace(/\s+$/, ''); // trim		if (!item.match(/^\s+$/) && '' != item) {			txt = '<span><a id="tag-check-' + key + '">X</a>&nbsp;' + item + '</span> ';			$('tagchecklist').show();			$('tagchecklist').insert(txt);			$('tag-check-' + key).observe('click', new_tag_remove_tag);			shown = true;		}		final_tags[key] = item;		key++;	});	$('tags').setValue(final_tags.join(","));	if (shown) $('tagchecklist').insert({ top: '<div>Tags usadas nesse post:</div>' });}function tag_flush_to_text() {	var newtags = $F('tags') + ',' + $F('newtag');	// massage	newtags = newtags.search_replace(/\s+,+\s*/g, ',').search_replace(/,+/g, ',').search_replace(/,+\s+,+/g, ',').search_replace(/,+\s*$/g, '').search_replace(/^\s*,+/g, '');	$('tags').setValue(newtags);	tag_update_quickclicks();	$('newtag').setValue('');	$('newtag').focus();	return false;}function tag_save_on_publish() {	if ($F('newtag') != 'Add new tag')	tag_flush_to_text();}function tag_press_key(e) {	if (13 == e.keyCode) {		tag_flush_to_text();		return false;	}}/*------- Authors -------- */function new_user_remove_user() {	var id = this.id;	var num = id.substr(11);	var current_users = $F('authors').split(',');	delete current_users[num];	var new_users = [];	var key = 0;	current_users.each(function(item) {		if (item && !item.match(/^\s+$/) && '' != item) {			new_users = new_users.concat(item);		}		key++;	});	$('authors').setValue(new_users.join(',').search_replace(/\s*,+\s*/, ',').search_replace(/,+/, ',').search_replace(/,+\s+,+/, ',').search_replace(/,+\s*$/, '').search_replace(/^\s*,+/, ''));	user_update_quickclicks();	$('newuser').focus();	return false;}function user_update_quickclicks() {	if ($('authors').length == 0) return;	var current_users = $F('authors').split(',');	$('userchecklist').update('');	shown = false;	current_users = current_users.uniq();	key = 0;	current_users.each(function(item) {		item = item.search_replace(/^\s+/, '').search_replace(/\s+$/, ''); // trim		if (!item.match(/^\s+$/) && '' != item) {			txt = '<span><a id="user-check-' + key + '">X</a>&nbsp;' + item + '</span> ';			$('userchecklist').show();			$('userchecklist').insert(txt);			$('user-check-' + key).observe('click', new_user_remove_user);			shown = true;		}		key++;	});	$('authors').setValue(current_users.join(","));	if (shown) $('userchecklist').insert({ top: '<div>Authors of this post:</div>' });}function user_flush_to_text() {	var newusers = $F('authors') + ',' + $F('newuser');	// massage	newusers = newusers.search_replace(/\s+,+\s*/g, ',').search_replace(/,+/g, ',').search_replace(/,+\s+,+/g, ',').search_replace(/,+\s*$/g, '').search_replace(/^\s*,+/g, '');	$('authors').setValue(newusers);	user_update_quickclicks();	$('newuser').setValue('');	$('newuser').focus();	return false;}function user_save_on_publish() {	if ($F('newuser') != 'Add new author')	user_flush_to_text();}function user_press_key(e) {	if (13 == e.keyCode) {		user_flush_to_text();		return false;	}}/*------- Categories -------- */function cat_update () {	if ($F('newcat') != '' && $F('newcat') != 'Nome da categoria') {		new Ajax.Updater('category-ajax-response', local_path+'pages/blogs_blog.php?do=add_category', {evalScripts:true, parameters: {			name: $F('newcat'),			blogRel: $F('newcat_blogRel')		},onSuccess: function(transport) {			$('newcat').removeClassName('form-required');			$('newcat').focus();		}});	} else $('newcat').addClassName('form-required');}function cat_press_key(e) {	if (13 == e.keyCode) {		cat_update();		return false;	}}function add_postbox_toggles() {	$$('.postbox .title').each(function(item) {		//item.insert({ top: '<a class="togbox'+(item.className.indexOf('closed') > -1 ? ' closed' : '')+'"></a> '});		item.observe('click', function() {			item.next().toggleClassName('hidden');			swapClassName(item,'closed','open');			if (item.id == 'post_intro') {				$$('.shy').invoke('toggleClassName','hidden');				if ($('intro_block').hasClassName('hidden')) $('intro_block').removeClassName('hidden');				else $('intro_block').addClassName('hidden');			}		});	});}function autoSave () {	if (!$('post_form') && $F('revision') == 1) return false;	tinyMCE.triggerSave();	new Ajax.Updater('auto_save',local_path+'pages/blogs_blog.php?do=auto_save',{evalScripts:true, parameters: $('post_form').serialize(true) });	return;}document.observe("dom:loaded", function() {	new PeriodicalExecuter(autoSave, 90);	return false;});
