var req;
 
// FUNÇÃO PARA BUSCA NOTICIA
function buscarNoticias(valor) {
 
// Verificando Browser
if(window.XMLHttpRequest) {
   req = new XMLHttpRequest();
}
else if(window.ActiveXObject) {
   req = new ActiveXObject("Microsoft.XMLHTTP");
}
 
// Arquivo PHP juntamente com o valor digitado no campo (método GET)
var url = "busca.php?valor="+valor;
 
// Chamada do método open para processar a requisição
req.open("Get", url, true); 


req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
req.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
req.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
req.setRequestHeader("Pragma", "no-cache");
 
// Quando o objeto recebe o retorno, chamamos a seguinte função;
req.onreadystatechange = function() {
 
		
 
	// Verifica se o Ajax realizou todas as operações corretamente
	if(req.readyState == 4 && req.status == 200) {
			
	// Resposta retornada pelo busca.php
	var resposta = req.responseText.split("|");	
				
			document.getElementById('imagem').src = resposta[0];
			document.getElementById('titulo').innerHTML = resposta[1];
			document.getElementById('subtitulo').innerHTML = resposta[2];	
			document.getElementById('resumo').innerHTML = resposta[3];
			document.getElementById('link_noticia').href = resposta[4];
			document.getElementById('titulo_img').innerHTML = resposta[5];
			
			
	}
}
req.send(null);
}



function troca_cor(valor)
{
			var a = 1;
			var b = 2;
			var c = 3;
			var d = 4;
			
			if (valor == 5)
			{
				document.getElementById(1).style.backgroundColor = '#F00';	
			}
			
						
			if (a == valor)
			{
				if (document.getElementById(4)){
					document.getElementById(4).style.backgroundColor = '#0650B1';
				}
				if (document.getElementById(3)){
					document.getElementById(3).style.backgroundColor = '#0650B1';
				}
				if (document.getElementById(2)){
					document.getElementById(2).style.backgroundColor = '#0650B1';
				}
				if (document.getElementById(1)){
					document.getElementById(1).style.backgroundColor = '#F00';
				}
			}
			if (b == valor)
			{
				if (document.getElementById(4)){
					document.getElementById(4).style.backgroundColor = '#0650B1';
				}
				if (document.getElementById(3)){
					document.getElementById(3).style.backgroundColor = '#0650B1';
				}
				if (document.getElementById(1)){
					document.getElementById(1).style.backgroundColor = '#0650B1';
				}
				if (document.getElementById(2)){
					document.getElementById(2).style.backgroundColor = '#F00';
				}
			}
			if (c == valor)
			{
				if (document.getElementById(4)){
					document.getElementById(4).style.backgroundColor = '#0650B1';
				}
				if (document.getElementById(1)){
					document.getElementById(1).style.backgroundColor = '#0650B1';
				}
				if (document.getElementById(2)){
					document.getElementById(2).style.backgroundColor = '#0650B1';
				}
				if (document.getElementById(3)){
					document.getElementById(3).style.backgroundColor = '#F00';
				}
			}
			if (d == valor)
			{
				if (document.getElementById(1)){
					document.getElementById(1).style.backgroundColor = '#0650B1';
				}
				if (document.getElementById(3)){
					document.getElementById(3).style.backgroundColor = '#0650B1';
				}
				if (document.getElementById(2)){
					document.getElementById(2).style.backgroundColor = '#0650B1';
				}
				if (document.getElementById(4)){
					document.getElementById(4).style.backgroundColor = '#F00';
				}
			}
}



// FUNÇÃO PARA EXIBIR NOTICIA
function exibirConteudo(id) {
 
// Verificando Browser
if(window.XMLHttpRequest) {
   req = new XMLHttpRequest();
}
else if(window.ActiveXObject) {
   req = new ActiveXObject("Microsoft.XMLHTTP");
}
 
// Arquivo PHP juntamento com a id da noticia (método GET)
var url = "exibir.php?id="+id;
 
// Chamada do método open para processar a requisição
req.open("Get", url, true); 
 
// Quando o objeto recebe o retorno, chamamos a seguinte função;
req.onreadystatechange = function() {
 
	// Exibe a mensagem "Aguarde..." enquanto carrega
	if(req.readyState == 1) {
		document.getElementById('conteudo').innerHTML = 'Aguarde...';
	}
 
	// Verifica se o Ajax realizou todas as operações corretamente
	if(req.readyState == 4 && req.status == 200) {
 
	// Resposta retornada pelo exibir.php
	var resposta = req.responseText;
 
	// Abaixo colocamos a resposta na div conteudo
	document.getElementById('conteudo').innerHTML = resposta;
	}
}
req.send(null);
}
