// SET VARIABLE ############################################################################################################# //
var paginaAtual = "home";
var idAtivo = "";

// FUNCTIONS ################################################################################################################ //

function abrirHome(load) {
	if (load != "") {
		abrirLink(load);

	} else {
		document.getElementById("meio_carregando").style.display = "none";
		document.getElementById("meio_home").style.display = "block";

	}

}


function abrirLink(ref) {
	if (ref == "home") {
		document.getElementById("meio_subpagina").style.display = "none";
		document.getElementById("meio_home").style.display = "block";
//		document.getElementById("texto_home").innerHTML = "carregando...";

		idAtivo = "home";
		
	} else {
		document.getElementById("meio_home").style.display = "none";
		document.getElementById("meio_subpagina").style.display = "block";
		document.getElementById("texto_subpagina").innerHTML = "carregando...";
		idAtivo = "subpagina";

		listar(ref);

	}

}

function abrirNoticia(id) {
	document.getElementById("meio_home").style.display = "none";
	document.getElementById("meio_subpagina").style.display = "block";
	document.getElementById("texto_subpagina").innerHTML = "carregando...";
	idAtivo = "subpagina";

	ref = "noticia&id=" + id;

	listar(ref);

}

function abrirNoticiaDestaque() {
	document.getElementById("meio_home").style.display = "none";
	document.getElementById("meio_subpagina").style.display = "block";
	document.getElementById("texto_subpagina").innerHTML = "carregando...";
	idAtivo = "subpagina";

	ref = "noticiaDdestaque";

	listar(ref);

}

// AJAX #################################################################################################################### //
function getDate() {
	var d = new Date();

	var dia = d.getDate();
	var mes = d.getMonth();
	if (mes == 12) {
		mes = 0;

	}
	mes = mes + 1;

	var ano = d.getYear()
	var hora = d.getHours();
	var minuto = d.getMinutes();
	var segundo = d.getSeconds();

	d = new String(ano) + new String(mes) + new String(dia) + new String(hora) + new String(minuto) + new String(segundo);

	return d;

}

function listar(pagina) {
	var d = getDate();

	var url = "get/?pagina=" + pagina + "&d=" + d;

	ajaxGet(url, "resposta");
	listarLOOP();

}

function listarLOOP() {
	if (respostaAjax["resposta"] == "") {
		Tloop = setTimeout("listarLOOP()", 100);

	} else {
		clearTimeout(Tloop);

		r = respostaAjax["resposta"];

		respostaAjax["verificando"] = 0;
		respostaAjax["resposta"] = "";

		resultado(r);

	}

}

function resultado(r) {
	var titulo = "";

	var textoTitulo = "";
	if (r.length > 50) {
		textoTitulo = r.substring(0, 50);

	} else {
		textoTitulo = r;

	}

	var ponto = textoTitulo.indexOf("[+]");
	titulo = textoTitulo.substring(0, ponto);
	if (titulo == "Pagseguro") {
		titulo = "Pagamento via PagSeguro";

	}

	if (titulo != "") {
		r = r.substring(ponto + 3, r.length);

	}

	if (titulo != "") {
		document.getElementById("titulo_" + idAtivo).innerHTML = titulo;

	}

	if (r != "") {
		document.getElementById("texto_" + idAtivo).innerHTML = r;

	}

	document.getElementById("meio_carregando").style.display = "none";
	window.focus();
//	document.body.scrollTop = 0;

}
