/*************************************************************************************************************************************************
			SEND FORMA SIMPLES
*************************************************************************************************************************************************/
function ajx_SendForm (FORM, URL, REF)
{
	var TEXTO	= $('form#'+FORM+' input#Texto').val();

	if (TEXTO == '')
		return false;

	$.ajax({
		type		: 'POST',
		data		: 'ACT=REC&TXT='+TEXTO,
		url			: URL,
		success		: function(res)
		{
			if (res=='ERRO')
			{
				ShwAlert('Houve um erro na aplicação, tente novamente mais tarde', REF, 'ERRO');
			}
			else
			{
				if(REF)
					$(REF).prepend(res);
			}
		},
		error		: function(txt)
		{
			ShwAlert(txt, REF, 'ERRO');
		}
	});
}

function ajx_RemCnx(ID)
{
	if (confirm ('Deseja realmente excluir este registro?') )
	{
		$.ajax({
			type		: 'POST',
			data		: 'ACT=REM&ID='+ID,
			url			: 'ajx_conexao.php',
			success		: function(res)
			{
				if (res == 'ERRO')
				{
					ShwAlert(res, 'div#CNX_'+ID, 'ERRO');
				}
				else
				{
					$('div#CNX_'+ID).remove();
				}
			},
			error		: function(txt)
			{
				ShwAlert(txt, 'div#CNX_'+ID, 'ERRO');
			}
		});
	}
}

function ajx_RemRecado(ID)
{
	if (confirm ('Deseja realmente excluir este recado?') )
	{
		$.ajax({
			type		: 'POST',
			data		: 'ACT=REM&ID='+ID,
			url			: 'ajx_recados.php',
			success		: function(res)
			{
				if (res == 'ERRO')
				{
					ShwAlert(res, 'div#RECADO_'+ID, 'ERRO');
				}
				else
				{
					$('div#RECADO_'+ID).remove();
				}
			},
			error		: function(txt)
			{
				ShwAlert(txt, 'div#RECADO_'+ID, 'ERRO');
			}
		});
	}
}

function ajx_RemFoto(ID, PERFIL, SEXO)
{
	if (confirm ('Deseja realmente excluir esta foto?') )
	{
		$.ajax({
			type		: 'POST',
			data		: 'ACT=REM&ID='+ID+'PERFIL'+PERFIL,
			url			: 'ajx_fotos.php',
			success		: function(res)
			{
				if (res == 'ERRO')
				{
					ShwAlert(res, 'li#FOTO_'+ID, 'ERRO');
				}
				else
				{
					$('li#FOTO_'+ID).remove();
					if (PERFIL == 2)
						$('img#PERFIL').attr('src', 'fotos/'+SEXO+'_m.jpg');
				}
			},
			error		: function(txt)
			{
				ShwAlert(txt, 'li#FOTO_'+ID, 'ERRO');
			}
		});
	}
}
/*************************************************************************************************************************************************
			AGENDA
*************************************************************************************************************************************************/
function ajx_AgendaConfirm (ID, ACT)
{
	var TXT = (ACT=='OK') ? 'Deseja confirmar sua presença neste evento?' : 'Deseja cancelar a confirmação de presença neste evento?';
	if (confirm(TXT))
	{
		$.ajax({
			type		: 'POST',
			data		: 'ACT='+ACT+'&ID='+ID,
			url			: 'ajx_agenda.php',
			success		: function(msg)
			{
				var ARR = msg.split(';')
				if (ACT == 'REM')
					$('li#CONF_'+ARR[0]).remove();

				ShwAlert(ARR[1], null);
			},
			error		: function(txt)
			{
				ShwAlert(txt, 'ul#AGENDA', 'ERRO');
			}
		});
	}
}

/*************************************************************************************************************************************************
			GERENCIAMENTO DE SOLICITAÇÕES
*************************************************************************************************************************************************/
function ajx_ADD (ID, ACT)
{
	$.ajax({
		type		: 'POST',
		data		: 'id='+ID+'&act='+ACT,
		url			: 'ajx_pedidos.php',
		success		: function(msg)
		{
			ShwAlert(msg, null);
			
			if (ACT == 'a')
				location.reload();

			$('div#ADD_'+ID).fadeOut();

			$('img#PDD_'+ID+'_'+ACT).fadeOut();
		},
		error		: function(txt)
		{
			ShwAlert(txt, 'div#ADD_'+ID, 'ERRO');
		}
	});
}

/*************************************************************************************************************************************************
			GERENCIAMENTO DE COMENTÁRIOS
*************************************************************************************************************************************************/
//	INSERE NOVO COMENTÁRIO
function ajx_AddComent (TIPO, ID)
{
	var TEXTO	= $('form#fm_com textarea#Seu_comentario').val();

	if(!TEXTO || TEXTO == 'undefined')
	{
		ShwAlert('Preencha o campo com seu coment&aacute;rio!', null);
		return false;	
	}
	
	$.ajax({
		type		: 'POST',
		data		: 'id='+ID+'&tipo='+TIPO+'&texto='+TEXTO,
		url			: 'ajx_coment.php',
		success		: function(msg)
		{
			if(msg == 'ERRO' || msg == 'LOGIN')
			{
				var MSG = (msg=='LOGIN') ? 'Voc&ecirc; precisa estar logado para usar essa fun&ccedil;&atilde;o' : 'Sua mensagem n&atilde;o pode ser enviada, tente novamente mais tarde';
				ShwAlert(MSG, null);
			}
			else
			{
				ShwAlert('Coment&aacute;rio adicionado com sucesso', null);
				$('div#COMMS').prepend(msg);
				$('form#fm_com textarea#Seu_comentario').val('');
			}
		},
		error		: function()
		{
			ShwAlert('Ocorreu um erro, tente novamente mais tarde', null);
		}
	});
}

//	EXCLUI COMENTÁRIO
function ajx_RemComent (ID, TIPO)
{
	if( confirm('Deseja realmente excluir este comentário?') )
	{
		$.ajax({
			type		: 'POST',
			data		: 'id='+ID+'&tipo='+TIPO,
			url			: 'ajx_coment_rem.php',
			success		: function(msg)
			{
				switch(msg)
				{
					case 'GO_AWAY_PUNK' :
						ShwAlert('Voc&ecirc; n&atilde;o pode remover um coment&aacute;rio que n&atilde;o foi criado por voc&ecirc;', null);
					break;
					case 'ERRO'	:
						ShwAlert('Seu coment&aacute;rio n&atilde;o pode ser removido, tente novamente mais tarde', null);
					break;
					case 'SHOW'	:
//						ShwAlert('Coment&aacute;rio exclu&iacute;do com sucesso', null);
						$('div#dvCmt_'+ID).remove();
					break;
				}
			},
			error		: function()
			{
				ShwAlert('Ocorreu um erro, tente novamente mais tarde', null);
			}
		});
	}
}

/*************************************************************************************************************************************************
			GERENCIAMENTO DE DENÚNCIAS
*************************************************************************************************************************************************/
function ajx_AddDenuncia (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);
		}
	});
}
