/*
 * Clubbing.pl Forum AJAX scripts.
 * (c) 2009 Mariusz Woloszyn
 *
 */


function REPLY(id, username)
{
	url='gimme_post_body.php?id='+id;
	new Ajax.Request(url, {
		method: 'get',
			onSuccess: function(transport) {
				body='[quote '+username+'] '+transport.responseText+' [/quote]';
				$('comment').value=body;
				Element.scrollTo($('end'));
			}
	});
	//alert('Hello out there!');
}

function ULUBIONY(thread_id)
{
	url='thread_favorite.php?thread_id='+thread_id;
	new Ajax.Request(url, {
		method: 'post',
			onSuccess: function(transport) {
				resp=transport.responseText;
				alert(resp);
			}
	});
}

function HIDDEN(thread_id)
{
	url='thread_hidden_toggle.php?thread_id='+thread_id;
	new Ajax.Request(url, {
		method: 'get',
			onSuccess: function(transport) {
				resp=transport.responseText;
			}
	});
}

function ZABLOKUJ(thread_id)
{
	url='thread_lock_toggle.php?thread_id='+thread_id;
	new Ajax.Request(url, {
		method: 'get',
			onSuccess: function(transport) {
				resp=transport.responseText;
			}
	});
}

function PRZYKLEJ(thread_id, stickDate)
{
	url='thread_stick_toggle.php?thread_id='+thread_id+'&stick='+stickDate;
	new Ajax.Request(url, {
		method: 'get',
			onSuccess: function(transport) {
				resp=transport.responseText;
			}
	});
}

/* This function updates the element Element with new contenti from Url */
function UpdateElementFromUrl(Element, Url, onSuccessFunction)
{
	new Ajax.Request(Url, {
		method: 'post',
			onSuccess: function(transport) {
				body=transport.responseText;
				$(Element).update(body);
				onSuccessFunction();
				//urchinTracker(url);
			}
	});
}

function ThreadBodyFixup()
{
	updateWroc();
	if ($('new')!=null) {
		Element.scrollTo($('new'));
	} else {
		Element.scrollTo($('end'));
	}
}

function LoadThreadBody2ElementAndNoScroll(element, id, category_id, page)
{
	if (arguments[5]!=undefined) {
		bonus=arguments[5];
	} else {
		bonus="";
	}
	url='thread_body.php?id='+id+'&category_id='+category_id+'&page='+page+bonus;

	UpdateElementFromUrl(element, url, function() {
			updateWroc();
			});
}

function LoadThreadBody2Element(element, id, category_id, page)
{
	if (arguments[4]!=undefined) {
		bonus=arguments[4];
	} else {
		bonus="";
	}
	url='thread_body.php?id='+id+'&category_id='+category_id+'&page='+page+bonus;

	UpdateElementFromUrl(element, url, function() {ThreadBodyFixup()});
}


/* Loads thread_body.php to RealBody element and scrolls the page accordingly */
function LoadThreadBody2RealBody(id, category_id, page)
{
	if (arguments[3]!=undefined) {
		bonus=arguments[3];
	} else {
		bonus="";
	}
	LoadThreadBody2Element('RealBody', id, category_id, page, bonus);
}

