// *********************************************************************
// funcoes para a area de filtro
function MostraFiltro() {
 // exibe a area de filtragem
 document.getElementById("filtros").style.height = 74;
 document.bt_filtro.src = "/pesquisaweb/menos.gif";
}

function EscondeFiltro() {
 // esconde a area de filtragem
 document.getElementById("filtros").style.height = 1;
 document.bt_filtro.src = "/pesquisaweb/mais.gif";
}

function Filtro(bCookie) {
 // exibe ou esconde a area de filtragem
 a = getCookie("filtropesq");

 if (bCookie) {
  if ((a == "off") || (a == null)) {
   MostraFiltro();
   setCookie("filtropesq", "on");
  }
  else {
   EscondeFiltro();
   setCookie("filtropesq", "off");
  }
 }
 else {
  if ((a == "off") || (a == null)) {EscondeFiltro();} else {MostraFiltro();}
 }
}

function Filtrar() {
 // verifica campos - evita problemas com IE5 x undefined
 c_fam = false;
 c_sec = false;
 
 for (a = 0; a < document.GERAL.elements.length; a++) {
  if (document.GERAL.elements[a].name == "_FAMILIAN2") c_fam = true;
  if (document.GERAL.elements[a].name == "_SECAON2") c_sec = true;
 }
 
 // capta valores selecionados nos filtros e posta
 if (c_fam) {
  document.FILTRO.ESTRUTN2.value = document.GERAL._FAMILIAN2.options[document.GERAL._FAMILIAN2.selectedIndex].value;
 }
 
 if (document.GERAL._ESTRUTN2.options[document.GERAL._ESTRUTN2.selectedIndex].value != "") {
  document.FILTRO.ESTRUTN2.value = document.GERAL._ESTRUTN2.options[document.GERAL._ESTRUTN2.selectedIndex].value;
 }
 
 if (c_sec) {
  if (document.GERAL._SECAON2.options[document.GERAL._SECAON2.selectedIndex].value != "") {
   document.FILTRO.ESTRUTN2.value = document.GERAL._SECAON2.options[document.GERAL._SECAON2.selectedIndex].value;
  }
 }
 
 document.FILTRO.PRECON2.value = document.GERAL._PRECON2.options[document.GERAL._PRECON2.selectedIndex].value;
 document.FILTRO.FILTRON2.value = document.GERAL._FILTRON2.options[document.GERAL._FILTRON2.selectedIndex].value;
 document.FILTRO.ORDEMN2.value = document.GERAL._ORDEMN2.options[document.GERAL._ORDEMN2.selectedIndex].value;
 document.FILTRO.MODELON2.value = document.GERAL._MODELON2.options[document.GERAL._MODELON2.selectedIndex].value;
 
 document.FILTRO.PALAVRASN2.value = document.GERAL._PALAVRASN2.value;

 document.FILTRO.submit(); 
}

// *********************************************************************
// funcoes para a area de paginacao
function MostraPaginacao() {
 // exibe a area de paginacao
 document.getElementById("paginas").style.overflow = "visible";
 document.bt_paginacao.src = "/pesquisaweb/menosb.gif";
}

function EscondePaginacao() {
 // esconde a area de paginacao
 document.getElementById("paginas").style.overflow = "hidden";
 document.bt_paginacao.src = "/pesquisaweb/maisb.gif";
}

function Paginacao() {
 // exibe ou esconde a area de paginacao
 if (paginacao == 1) {
  MostraPaginacao();
  paginacao = 2;
 }
 else {
  EscondePaginacao();
  paginacao = 1;
 }
}

function Pagina(id) {
 // vai para a pagina de resultado informada
 document.FILTRO.PAGINA.value = id;
 document.FILTRO.submit();
}

function Criterios() {
 // posiciona nos criterios de pesquisa
 document.location = String(document.location).split("#")[0] + "#criterios";
}

// *********************************************************************
// funcoes para combos
function PosicionaCombo(obj, valor) {
 // posiciona combo informado no item com o valor fornecido
 if ((valor != "") && (valor != "*-*")) {
  for (a = 0; a < obj.length; a++) {
   if (obj.options[a].value == valor) {
    obj.selectedIndex = a;
   }
  }
 }
}

function AtualizaCombo(obj, aCodigo, aTexto, sFiltro) {
 // alimenta combo de estruturado
 obj.length = 1;

 for (i = 0; i < aCodigo.length; i++) {
  if (aCodigo[i].substring(0, sFiltro.length) == sFiltro) {
   obj.length++;
   obj.options[obj.length - 1].text = aTexto[i];
   obj.options[obj.length - 1].value = aCodigo[i];
  }
 }
}

function Secao() {
 a = document.GERAL._ESTRUTN2.options[document.GERAL._ESTRUTN2.selectedIndex].value;

 document.GERAL._SECAON2.length = 1;
  
 if (document.GERAL._ESTRUTN2.selectedIndex != 0) {
  AtualizaCombo(document.GERAL._SECAON2, CDESTN4, NOMEESTN4, a);
 }
 
 if (document.GERAL._SECAON2.length == 1) {
  if (document.GERAL._ESTRUTN2.selectedIndex != 0) {
   document.GERAL._SECAON2.options[0].text = 'Todas as Seções';
  }
  else {
   document.GERAL._SECAON2.options[0].text = '(selecione uma categoria)';
  }
 }
 else {
  document.GERAL._SECAON2.options[0].text = 'Todas as Seções';
 }
}

// *********************************************************************
// demais funcoes
function Outros(fam) {
 // libera filtro de estruturado e mantem o restante
 if (fam != document.FILTRO.ESTRUTN1.value) {
  document.FILTRO.ESTRUTN1.value = "";
 }

 document.FILTRO.ESTRUTN2.value = fam;
 document.FILTRO.submit();
}

function Palavra() {
 // posiciona combo na opcao padrao se houver digitacao
 if ((document.GERAL._PALAVRASN2.value != "") && (document.GERAL._FILTRON2.selectedIndex == 0)) {
  document.GERAL._FILTRON2.selectedIndex = 1;
 }
}

function Player(id) {
 window.open("/produto/produto.dll/player?pro_id=" + id, "player", "toolbar=no,location=no, status=no,directories=no,menubar=no,resizable=no,menubar=no,width=565,height=555,left=50,top=50")
}

// *********************************************************************
// cookie
function getCookieVal(offset) {
 var endstr = document.cookie.indexOf(";", offset);
  
 if (endstr == -1) {endstr = document.cookie.length;}
  
 return unescape(document.cookie.substring(offset, endstr));
}

function getCookie(name) {
 var arg = name + "=";
 var alen = arg.length;
 var clen = document.cookie.length;
 var i = 0;
 
 while (i < clen) {
  var j = i + alen;
  
  if (document.cookie.substring(i, j) == arg) {return getCookieVal(j);}
  
  i = document.cookie.indexOf(" ", i) + 1;
  
  if (i == 0) {break;}
 }
 
 return null;
}

function setCookie(name, value, expires, path, domain, secure) {
 document.cookie =
  name + "=" + escape(value) +
  ((expires) ? "; expires=" + expires.toGMTString() : "") +
  ((path) ? "; path=" + path : "") +
  ((domain) ? "; domain=" + domain : "") +
  ((secure) ? "; secure" : "");
}
