/*************************************************************************************************************************************************
			GERENCIAMENTO DE DENÚNCIAS
*************************************************************************************************************************************************/
function ajx_SEND_Denuncia (NM_FORM, TIPO, USR, ID)
{
	var TEXTO = document.forms[NM_FORM].CMP_DEN.value;
	if(TEXTO === '' || TEXTO == 'undefined')
	{
		ShwAlert('Preencha o campo de texto com a sua mensagem', null);
		return false;
	}

	$.ajax({
		type		: "POST",
		data		: 'usr='+USR+'&id='+ID+'&tipo='+TIPO+'&texto='+TEXTO,
		url			: "ajx_denuncia.php",
		success		: function(msg)
		{
			var MSG = (msg == 'OK') ? 'Denuncia cadastrada, estaremos analisando este caso e tomando as atitudes cabíveis' : 'Sua mensagem não pode ser enviada, tente novamente mais tarde ou envie nos um email';
			ShwAlert(MSG, null);
			$('div#BOX_DENUNCIA').fadeOut();
		},
		error		: function(txt)
		{
			ShwAlert(txt, 'input#BT_ENVIAR', 1);
		}
	});
}
/*************************************************************************************************************************************************
			GERENCIAMENTO DE COMENTÁRIOS
*************************************************************************************************************************************************/
//	INSERE NOVO COMENTÁRIO
function ajx_SEND_Coment (NM_FORM, TIPO, ID)
{
	var TEXTO	= document.fm_com.CMP_COM.value;

	$.ajax({
		type		: "POST",
		data		: 'id='+ID+'&tipo='+TIPO+'&texto='+TEXTO,
		url			: "ajx_coment.php",
		success		: function(msg)
		{
			if(msg != 'ERRO')
				{
					ShwAlert('Comentário adicionado com sucesso', null);
					$('div#COMENTS').fadeIn();
					$('div#COMMS').prepend(msg);

					$('div#BOX_COMENT').fadeOut();
					document.fm_com.CMP_COM.value = null;
				}
				else
				{
					ShwAlert('Sua mensagem não pode ser enviada, tente novamente mais tarde', null);
				}
		},
		error		: function()
		{
			ShwAlert('Ocorreu um erro, tente novamente mais tarde', null);
		}
	});
}

//	EXCLUI COMENTÁRIO
function ajx_REM_Coment (ID, TIPO)
{
	$.ajax({
		type		: "POST",
		data		: 'id='+ID+'&tipo='+TIPO,
		url			: "ajx_coment_rem.php",
		success		: function(msg)
		{
			switch(msg)
			{
				case 'GO_AWAY_PUNK' :
					ShwAlert('Você não pode remover um comentário que não foi criado por você', null);
				break;
				case 'ERRO'	:
					ShwAlert('Sua comentário não pode ser removido, tente novamente mais tarde', null);
				break;
				case 'SHOW'	:
					ShwAlert('Comentário excluído com sucesso', null);
					$('div#dvCmt_'+ID).remove();
				break;
			}
		},
		error		: function()
		{
			ShwAlert('Ocorreu um erro, tente novamente mais tarde', null);
		}
	});
}

/*************************************************************************************************************************************************
			GERENCIAMENTO DE VOTOS
*************************************************************************************************************************************************/
function ajx_SEND_vote (TIPO, VAL, ID)
{
	$.ajax({
		type		: 'POST',
		data		: 'id='+ID+'&tipo='+TIPO+'&vote='+VAL,
		url			: "ajx_vote.php",
		success		: function(msg)
		{
			switch(msg)
			{
			case 'AGAIN':	var MSG = 'Você já votou neste conteúdo';
			break;
			case 'OK':		var MSG = 'Voto cadastrado com sucesso';
			break;
			default :		var MSG = 'Seu voto não pode ser cadastrado, tente novamente mais tarde';
			break;
			}
			ShwAlert(MSG, null);
		},
		error		: function(txt)
		{
			ShwAlert(txt, null);
		}
	});
}

/*************************************************************************************************************************************************
			REMOVER CONTEÚDOS
*************************************************************************************************************************************************/
function ajx_REM_Conteudo (TIPO, ID)
{
	$.ajax({
		type		: "POST",
		data		: 'id='+ID+'&tipo='+TIPO,
		url			: "ajx_remover.php",
		success		: function(msg)
		{
			if(AJAX.responseText == 'OK')
			{
				window.location = TIPO+'s.php';
			} else {
				ShwAlert('O conteúdo não pode ser removido, tente novamente mais tarde', null);
			}
		},
		error		: function()
		{
			ShwAlert('Ocorreu um erro, tente novamente mais tarde', null);
		}
	});
}

/*************************************************************************************************************************************************
			ENQUETE
*************************************************************************************************************************************************/
function ajx_Enquete (NM_FORM, ID)
{
	var DOC		= document.forms[NM_FORM];
	var LIST	= DOC.elements;
	var CHK		= false;
	
	for (i=0; i<LIST.length-1; i++)
	{
		if (LIST[i].checked)
		{
			CHK = LIST[i].value;
		}
	}
	
	if(CHK === false)
	{
		ShwAlert('Selecione uma resposta para a enquete', 'fieldset#OPTS');
		return false;
	}
	
	$.ajax({
		type		: "POST",
		data		: 'ID='+ID+'&CHK='+CHK,
		url			: "ajx_enquete.php",
		beforeSend	: function()
		{
			$('fieldset#OPTS').html('<span><img src="images/ajx_loading.gif" vspace="10"><br /> Aguarde</span>');
		},
		success		: function(msg)
		{
			if(msg != 'ERRO') {
				$('fieldset#OPTS').html(msg);
			} else {
				ShwAlert('Seu voto não pode ser registrado, tente novamente mais tarde', 'fieldset#OPTS');
			}
		},
		error		: function()
		{
			ShwAlert('Ocorreu um erro, tente novamente mais tarde', 'fieldset#OPTS');
		}
	});
}