function mudaOnde() {
	if (document.getElementById('onde').innerHTML == 'Livro') {
		document.getElementById('onde').innerHTML = 'Revista';
		document.getElementById('local').value = 'Revista';
	} else {
		document.getElementById('onde').innerHTML = 'Livro';
		document.getElementById('local').value = 'Livro';		
	}
}

function Busca(valor) {
	if (formulario.busca.value == '') { 
		alert("Digite algo a ser procurado!") ; formulario.busca.focus() ; return false ;
	}

	var check = formulario.busca.value
	
	if (check.length < 3) {
		alert("O que você está procurando deve ter mais de 2 caracteres") ; formulario.busca.focus() ; return false ;
	}
	document.forms["formulario"].submit();
}

function openAjax() {
	var Ajax;
	try {Ajax = new XMLHttpRequest();
	}catch(ee) {
	try {Ajax = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e) {
	try {Ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e) {Ajax = false;
	}
	}
	}
	return Ajax;
}

function rs(url, div, ind, tp) { // url, div
	if (tp == 1) { 	window.scrollTo(0,0); }
	if(document.getElementById) {
	var exibeResultado = document.getElementById(div);
		if (document.getElementById("ca").innerHTML == "") {
			if (ind == 1) {
				document.getElementById("ca").innerHTML = exibeResultado.innerHTML;
			}
		}
	var Ajax = openAjax();
	Ajax.open("GET", url, true);
	Ajax.onreadystatechange = function() {
		if(Ajax.readyState == 1) {
			if (ind == 1) {
			exibeResultado.innerHTML = '<div class="pl10 f16 fb pt20">Aguarde...</div>';
			document.getElementById("load").innerHTML = '<img src="/images/home/loading.gif" width="16" height="16" align="absmiddle">';
			}
		}
		if(Ajax.readyState == 4) {
			if(Ajax.status == 200) {
			var resultado = Ajax.responseText;
			resultado = resultado.replace(/\+/g," ");
			resultado = unescape(resultado);

			if (ind == 1) {
				document.getElementById("load").innerHTML = '<img src="/images/home/load.gif" alt="Carregado"  width="16" height="16" align="absmiddle">';
			}

			if (resultado.length > 5 ) {
				exibeResultado.innerHTML = resultado;
			}

			} else {
				if (ind == 1) {
				exibeResultado.innerHTML = '<div class="pt20 pr10" style="cursor:pointer; float:right; text-align:center;" onclick="rc();"><img src="/images/home/voltar.gif" width="44" height="44" /><br />Voltar</div><div class="pl10 f16 fb pt20 fcr">Erro: Verifique se sua conexao com a internet está ativa.</div><br /><div class="pl10 f12">Caso o problema persista entre em contato com nosso suporte: (17) 3211-9500</div>';
				document.getElementById("load").innerHTML = '<img src="/images/home/load.gif" alt="Carregado"  width="16" height="16" align="absmiddle">';
				}
			}
		}
	}
	Ajax.send(null);
	}
}

function rc() {
	document.getElementById("conteudo").innerHTML = document.getElementById("ca").innerHTML;
}

function SetVis(x,y) {
	document.getElementById(x).style.visibility = y;
}

function l() {
	document.getElementById("load").innerHTML='<img src="/images/home/load.gif" alt="" width="16" height="16" />';
}

function mudaimg(i,x) {
x.src = 'images/lateral/'+i+'.gif';
}

function Abre(page,nome,w,h) {
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
janela=window.open(page,nome,'resizable=no,width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+'');
}

var tempo=setInterval("rs('/secure/conn.asp','message',0,0)",5000);

function Pg(x) {
	
	pp = '<img src="/forum/imgs/pp.gif" alt="Próxima página" width="110" height="25" style="padding-left:15px;" />';
	pa = '<img src="/forum/imgs/pa.gif" alt="Página anterior" width="110" height="25" />';
	
	var nn = document.getElementById("npag").value;
	
	if(x == 'p') {
		
		if(nn <= 14) {
			document.getElementById("npag").value = parseFloat(nn)+1;
			if(document.getElementById("npag").value == 2) { document.getElementById("anterior").innerHTML = pa; }
		}
		if(document.getElementById("npag").value == 15) { document.getElementById("proxima").innerHTML = ''; }

	} else {

		if(nn > 1) {
			document.getElementById("npag").value = parseFloat(nn)-1;
			if(document.getElementById("npag").value == 14) { document.getElementById("proxima").innerHTML = pp; }
		}
		if(document.getElementById("npag").value == 1) { document.getElementById("anterior").innerHTML = ''; }
	}
	
	document.getElementById("pga").innerHTML = document.getElementById("npag").value;		
	
	rs('/materias/pag.asp?p='+x, 'mats', 0, 0);	
}