function wrexSbDelete(id, type)
{
	$.get('shoutbox/delete/'+id, function(response) {
		if(response != 'OK')
		{
			alert('Error');
		}
		else
		{
			wrexSbRefresh(type);
		}
	});
}

function wrexSbRefresh(type)
{
	$.get('shoutbox/get/'+type, function(response) {
		$('#shoutbox-posts-'+type).html(response);
	});
}

function wrexSbPost(type, input)
{	
	value = $('#'+input).val();

	$('#shoutbox-send-'+type).attr('disabled', true); 
	$('#shoutbox-refresh-'+type).attr('disabled', true);
	
	$.post('shoutbox/post/'+type, { content: value }, function(response) {
		if(response != 'OK')
		{
			alert('Error');
		}
		else
		{
			$('#'+input).val('');
			wrexSbRefresh(type);
		}
		
		$('#shoutbox-send-'+type).removeAttr('disabled');
		$('#shoutbox-refresh-'+type).removeAttr('disabled');
	});
}

function wrexGetComments(cid, page)
{
	$.post('comments/get/' + page, { cid: cid }, function(response) {
		$('#comments-container').html(response);
	});
}

function wrexMenuSwitch(id)
{
	// Hide
	$('.menu_sub_item').css('display', 'none');
	$('#menu_top li.active').removeClass('active');
	
	// Show
	$('#menu-sub-'+id).show('slow');
	$('#menu-top-'+id).addClass('active');
}

function wrexUserAutocomplete(id)
{
	$('#'+id).autocomplete('index.php?kohana_uri=messages/autocomplete');
}

function validateRegister(field, myvalue)
{
	if(!myvalue || myvalue == 'http://')
	{
		$('#error-'+field).fadeOut('slow');
		return;
	}

	if(field == 'password2')
	{
		data = { value: myvalue, password: document.getElementById('password').value };
	}
	else
	{
		data = { value: myvalue };
	}

	$.post('register/check_field/'+field, data,
	function(data)
	{
		$('#error-'+field).text(data).fadeIn('slow');
	}
	);
}

function wrexOpenWindow(id, url, width, height)
{
	return window.open(url, id, 'width='+width+',height='+height+',toolbar=no,menubar=no,scrollbars=yes');
}

function validateUcp(field, myvalue)
{
	if(!myvalue || myvalue == 'http://')
	{
		$('#error-'+field).fadeOut('slow');
		return;
	}

	$.post('profile/check_field/'+field, { value: myvalue },
	function(data)
	{
		$('#error-'+field).text(data).fadeIn('slow');
	}
	);
}

function doDeleteComment(data)
{
	if(!data)
	{
		alert('Error');
		return;
	}

	$('#comment-id-'+data).hide('slow');
}

function deleteComment(id)
{
	$.get('comments/delete/'+id, doDeleteComment);
}
