// JavaScript Document

function valor_radio(){
var escolha_radio;
for(var i=0; i < document.getElementsByName('radiobusca').length; i++){
 if(document.getElementsByName('radiobusca')[i].checked == true)
 escolha_radio=document.getElementsByName('radiobusca')[i].value;
}
return escolha_radio;
//escolha_radio é a variavel que quarda o valor dos radios
}

function valor_select_cidade(){
var escolha_cidade=document.getElementById("listcidade").value;
//escolha_cidade retorna a cidade escolhida;
if(escolha_cidade!="" && escolha_cidade!="MUNICÍPIO")
return escolha_cidade;
else
return;
}
function valor_select_estado(){
var escolha_estado=document.getElementById("listestado").value;
//escolha_estado retorna a cidade escolhida;
if(escolha_estado!="")
return escolha_estado;
else
return;
}

function busca(){
//escolha_imput tem o valor do imput
var vr=valor_radio();
var vi=document.getElementById("txtbusca").value;
var vc=valor_select_cidade();
var ve=valor_select_estado();

if(vr===undefined){
//alert("Escolha uma das opções acima!");
return false
}
else if(vi===""){
document.getElementById("txt_aviso").innerHTML="Digite uma palavra chave!";
form1.txtbusca.focus();
return false
}
else if(vc===undefined){
document.getElementById("txt_aviso").innerHTML="Escolha uma cidade!";
return false
}
else if(ve===undefined){
//alert("Escolha um estado!");
return false
}
else if(vi.length<3){
document.getElementById("txt_aviso").innerHTML="Digite uma palavra com no minimo 4 caracteres!";
vi.focus();
return false
}
else{
var pagina="conteudo.php?radiobusca="+vr+"&listcidade="+vc+"&listestado="+ve+"&txtbusca="+vi+"&rand=" + Math.random()+"";
var data=carrregando3(pagina);
return  verifica_conteudo(data);
}
return false;
}

function alimentartxt(txt) { 
var txts=txt;
 document.getElementById("txtbusca").value = txts;
 return busca();
}

function verifica_conteudo(data){
	if(data===undefined){
		document.getElementById("conteudo").innerHTML ="<div class=\"top2\"><div id=\"aviso\"><div id=\"txt_aviso\"><img src=\"imagens/loop.gif\" alt=\"Aguarde\" border=\"0\"  /></div></div></div>";
	}
	else{
		document.getElementById("conteudo").innerHTML =data;
	verifica();
	}
}

function reset(){
	location.href="index.php?resetar=reset";	
}


function ver_estado(){
	var ve=valor_select_estado();
	if(ve===undefined){
		document.getElementById("conteudo").innerHTML ="<img src=\"imagens/MAPA_LIMPO.gif\" alt=\"\" width=\"700\" height=\"630\" border=\"0\" usemap=\"#Map\" />";
		}
		else{
	alimentarCombo(ve);
		}
}

function relacionados(){
	bannerw();
	var vr=valor_radio();
	var vi=document.getElementById("txtbusca").value;
	var vc=valor_select_cidade();
	var ve=valor_select_estado();
	var pagina2="relaciona.php?radiobusca="+vr+"&listcidade="+vc+"&listestado="+ve+"&txtbusca="+vi+"&rand=" + Math.random()+"";
	return carrregando(pagina2,'relacionados');
}
//tempo
function tempo(){
	var ve=valor_select_estado();
	carrregando('clima_tempo.php?listestado='+ve,'recursos');
}

//configura estado
function verifica(){
	setTimeout(ver_estado(),5000);
	
}

function contador(){
var exibidos= document.getElementById("exibido").innerHTML;
var exibir=document.getElementById("exibir").innerHTML=exibidos;
if(exibir)
return true
else
return
}

//conteudo2
function conteudo2(p){
	var pg=p;
	carrregando(pg,"conteudo");
}

function redirect(){
	location.href="index.php";
}

function releases(){
}
//enter

function enter(){
var apertou;
if(event.keyCode){
apertou=event.keyCode;
 if (apertou == 13)
busca();
}else{
 apertou=(event.charCode)?event.charCode:event.which;
 if (apertou == 13)
busca(); 
}
return true;
}

document.onkeypress=enter;

//bannerw
function bannerw(){
	if(contador()){
	document.getElementById("pbl").style.visibility="visible";
	document.getElementById("pbl").style.display="block";
	}else{
	document.getElementById("relacionados").innerHTML=document.getElementById("pbl").innerHTML.value;
}}
//desabiitando erros

function handleError(){
return true;
}

function valida(){
function qt(){
var elem=document.Cadastro.length;
return elem;
}
for(i=0;i<=qt();i++){
var elementos=Cadastro.elements[i].value;
if (elementos==""){
avisos("Favor preencha o campo " + Cadastro.elements[i].name);
return false;
}
}
}

//avisos
function mostracoordenadas()
{
var y = event.clientY;
return y;
}

var taviso;
function avisos(aviso){
document.getElementById("avisot").innerHTML=aviso;
document.getElementById("aviso").style.display="block";
document.getElementById("aviso").style.top=mostracoordenadas();

}
function fechar(){
document.getElementById("aviso").style.display="none";
}

window.onerror=handleError;

	
