function login(data, config)
{
	var form = $('#form');
	
	//if we were logged in
	if(data.userid)
	{
		form
			.find('form').remove().end()
			.find('#logged-in').show()
				.find('strong').html(data.user_alias);
	}
	else if(config.type == 'login')
	{
		form.find('.notice').show().find('div').html('Invalid username or password.');
	}
	
	if(config.type == 'form')
		form_update(data, config);
}

function login_submit(form)
{
	//submit the request
	$(form).ajaxSubmit(
		{
			iframe: false,
			success: function(data) { login(data, {type: 'login', form: form}); },
			error: form_error,
			dataType: 'json'
		}
	);
	
	return false;
}

function preview_post(instanceName)
{
    var e = FCKeditorAPI.GetInstance(instanceName) ;
	if( !e.EditorDocument )
	{
	    alert('This function can only be used in WYSIWYG mode');
	    return false;
	}
	else
	{
		$("#wysiwyg_content").empty().html(e.EditorDocument.body.innerHTML).end();
		$('#wysiwyg_preview').show().end();
	    return true;
	}
}
