/*Banco de Notícias*/
function buscaNoticias()
{
	desabilitaFundo();
	var pag 		= document.getElementById('paginaAtual').value;
	var pesquisa 	= document.getElementById('textoPesquisa').value;
	var ordenamento = document.getElementById('tipoOrdem').value;
	var ordem 		= (document.getElementById('imagemOrdemAsc').style.display == "none" ? 'desc' : 'asc');
	carregaDados('interacaoBD/bancoNoticiasBusca.php?pag='+pag+'&pesquisa='+pesquisa+'&ordenamento='+ordenamento+'&ordem='+ordem, buscandoNoticias);
}

function buscandoNoticias()
{
	if(xmlHttp.readyState==1){
		document.getElementById("itensBanco").innerHTML = '<center><img src="template/imagens/carregando.gif" alt="Carregando" /> Carregando</center>';
	}
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") 
	{
		resposta = xmlHttp.responseText.split('[|||]');
		habilitaFundo();
		document.getElementById("itensBanco").innerHTML = resposta[0];
		document.getElementById("paginacao").innerHTML = resposta[1];
	}
}

function pesquisa()
{
	document.getElementById('paginaAtual').value = 1;
	buscaNoticias();
}

function reordena()
{
	if (document.getElementById('tipoOrdem').value != "data_postagem" && document.getElementById('imagemOrdemAsc').style.display == "none")
		mudaOrdem('a');
	else if (document.getElementById('tipoOrdem').value == "data_postagem" && document.getElementById('imagemOrdemAsc').style.display != "none")
		mudaOrdem('d');
	document.getElementById('paginaAtual').value = 1;
	buscaNoticias();
}

function mudaOrdem(ord)
{
	document.getElementById('paginaAtual').value = 1;
	if (ord == 'a')
	{
		document.getElementById('imagemOrdemAsc').style.display = "inline";
		document.getElementById('imagemOrdemDesc').style.display = "none";
	}
	else
	{
		document.getElementById('imagemOrdemAsc').style.display = "none";
		document.getElementById('imagemOrdemDesc').style.display = "inline";
	}
	buscaNoticias();
}

function mudaPagina(pag)
{
	document.getElementById('paginaAtual').value = pag;
	buscaNoticias();
}