// JavaScript Document

//avisos
var taviso;
function avisos(aviso){
document.getElementById("avisot").innerHTML=aviso;
document.getElementById("aviso").style.display="block";

}
function fechar(){
document.getElementById("aviso").style.display="none";
}
function txtexto(t){
var t=document.getElementById(t).value;
return t;
}

function valor_radio(r){
var escolha_radio;
for(var i=0; i < document.getElementsByName(r).length; i++){
 if(document.getElementsByName(r)[i].checked == true)
 escolha_radio=document.getElementsByName(r)[i].value;
}
return escolha_radio;
//escolha_radio a variavel que quarda o valor dos radios
}

function valor_select_cidade(c){
var escolha_cidade=document.getElementById(c).value;
//escolha_cidade retorna a cidade escolhida;
if(escolha_cidade!="")
return escolha_cidade;
else
return;
}
function valor_select_estado(e){
var escolha_estado=document.getElementById(e).value;
//escolha_estado retorna a cidade escolhida;
if(escolha_estado!="")
return escolha_estado;
else
return;
}

function busca(t,r,c,e){
//escolha_imput tem o valor do imput
var vr=valor_radio(r);
var vi=txtexto(t);
var vc=valor_select_cidade(c);
var ve=valor_select_estado(e);

if(vr===undefined){
//alert("Escolha uma das opções acima!");
return false
}
else if(vi===""){
taviso="Digite uma palavra chave!";
avisos(taviso);
c.focus();
return false
}
else if(vc===undefined){
taviso="Carregando...";
avisos(taviso);
return false
}
else if(vi.length<3){
taviso="Digite uma palavra com no minimo 4 caracteres!";
avisos(taviso);
vi.focus();
return false
}
else{
var pagina="index.php?radiobusca="+vr+"&listcidade="+vc+"&listestado="+ve+"&txtbusca="+vi;
location.href=pagina;
}
return true;
}

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;
}

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;
}
}
}

function loginestado(){
	document.getElementById("listestado2").value=valor_select_estado("listestado");
	var g=valida();
	if(!g)
	return true;
	else
	return false;
}
function ver(){
	var c=valor_select_cidade('listcidade');
if(c)
document.getElementById("aviso").style.display="none";
else
avisos("Carregando...");
}

function tops(){
parent.window.scrollTo(0,0); 
window.scrollTo(0,0);
}
document.onkeypress=enter;

