var PM = {
	readAll: function(user, forum)
	{
		Ubk.confirm(Locale.string(3029), function() {
			var onComplete = function() { 
				Ubk.working(false);
				var links = $$('div.post_info a.read');
				links.each(function(el){ 
					var post = el.id.substr(el.id.lastIndexOf('_') + 1);
					var p = $('post_'+post);
					new Effect.BlindUp(p.select('.post_content').reduce());
					Element.toggle(el.next());
					Element.remove(el);
				});
			};
			Ubk.follow(null, 'general.php', 'AZIONE=esegui_stored_procedure&NOME-STORED=forum_read&PARAMETRO-0='+user+'&PARAMETRO-1='+forum, false, true, onComplete);
		});
	},
	// segna pm letto
	read: function(user, topic, post)
	{
		Ubk.confirm(Locale.string(3034), function() {
			var onComplete = function() { 
				Ubk.working(false);
				var link = $('read_'+post);
				var p = $('post_'+post);
				new Effect.BlindUp(p.select('.post_content').reduce());
				Element.toggle(link.next());
				Element.remove(link);
			};
			Ubk.follow(null, 'general.php', 'AZIONE=esegui_stored_procedure&NOME-STORED=topic_read&PARAMETRO-0='+user+'&PARAMETRO-1='+topic, false, true, onComplete);
		});
	},

	// apri/chiudi pm letti
	toggle: function(post)
	{
		var link = $('toggle_' + post);
		var p = $('post_' + post);

		if (link.className == 'open') {
			p.select('.post_content').reduce().toggle();
// 			new Effect.BlindDown(p.select('.post_content').reduce(), { duration: 0.2 });
			link.className = 'close';
			link.title = Locale.string(347);
		} else {
			p.select('.post_content').reduce().toggle();
// 			new Effect.BlindUp(p.select('.post_content').reduce(), { duration: 0.2 });
			link.className = 'open';
			link.title = Locale.string(356);
		}
	},

	// apri/chiudi nuovo pm da inbox
	toggleNew: function()
	{
		var link = $('pm-toggle-new');
		var mid = $('new_topic').select('.mid').reduce();
		var bot = mid.next();

		if (link.className == 'open') {
			new Effect.BlindDown(mid, {afterFinish: bot.show.bind(bot)});
			Element.show('pm-buttons');
			link.className = 'close';
			link.title = Locale.string(347);
		} else {
			new Effect.BlindUp(mid, {afterFinish: bot.hide.bind(bot)});
			Element.hide('pm-buttons');
			$('new_topic').up('form').reset();
			$('new_pm_reply').value = null;
			Emo.hide();
			Post.Preview.hide();
			link.className = 'open';
			link.title = Locale.string(356);
		}
	},


	close: function()
	{
		$('new_topic').up('form').reset();
		$('new_pm_reply').value = null;
		
		Emo.hide();
		Post.Preview.hide();

		if ($('new_topic').up('#pm') != undefined) {
			Ubk.hide('pm');
		}
	},

	// quote
	quote: function(post)
	{
		var link = $('pm-toggle-new');
		var mid = $('new_topic').select('.mid').reduce();

		if (link.className == 'open') {
			new Effect.BlindDown(mid);
			Element.show('pm-buttons');
			link.className = 'close';
			link.title = Locale.string(347);
		}

		Element.scrollTo('new_topic');
		
		var onComplete = function(request) {
			Ubk.working(false);
			var o = request.responseText.evalJSON(true);
			$('new_pm_content').value = o.body+"\n";
			$('new_pm_title').value = o.title;
			$('new_pm_reply').value = o.replyTo;
			$('new_users').value = o.to.join(', ');
			$('new_pm_content').focus();
		}
		Ubk.follow(null, 'forum.php', 'AZIONE=pm_quote&TABELLA=t_s_post&CAMPO-ID=i_post_id&ID='+post, false, true, onComplete);
	}
};