function ComboFiltro(obj, fam) {
 // alimenta combo de filtro
	obj.length = 2;
	obj.length++;
	obj.options[obj.length - 1].text = "Autor / Artista";
	obj.options[obj.length - 1].value = "B";
	obj.length++;
	obj.options[obj.length - 1].text = "Editora / Marca";
	obj.options[obj.length - 1].value = "C";

	switch (fam) {
		case "0301":
		case "0314":	
		   /*
		   obj.length++;
		   obj.options[obj.length - 1].text = "No autor";
		   obj.options[obj.length - 1].value = "B";
		   obj.length++;
		   obj.options[obj.length - 1].text = "Na editora";
		   obj.options[obj.length - 1].value = "C";
		   */	
		   obj.length++;
		   obj.options[obj.length - 1].text = "ISBN";
		   obj.options[obj.length - 1].value = "G";
   		break;
   			/*
			case "0303":
			case "0312":
			obj.length++;
			obj.options[obj.length - 1].text = "Na distribuidora";
			obj.options[obj.length - 1].value = "C";
	   	break;
			*/
	   	case "0304":
			/*
			obj.length++;
			obj.options[obj.length - 1].text = "No artista";
			obj.options[obj.length - 1].value = "B";
			obj.length++;
			obj.options[obj.length - 1].text = "Na gravadora";
			obj.options[obj.length - 1].value = "C";
			*/    
			obj.length++;
			obj.options[obj.length - 1].text = "Faixas (CD)";
			obj.options[obj.length - 1].value = "D";
   		break;
   		case "0305":
		case "0398":
			/*
			obj.length++;
			obj.options[obj.length - 1].text = "No artista";
			obj.options[obj.length - 1].value = "B";
			obj.length++;
			obj.options[obj.length - 1].text = "Na distribuidora";
			obj.options[obj.length - 1].value = "C";
			*/    
			obj.length++;
			obj.options[obj.length - 1].text = "Elenco";
			obj.options[obj.length - 1].value = "E";
			obj.length++;
			obj.options[obj.length - 1].text = "Diretor";
			obj.options[obj.length - 1].value = "F";
		break;
			/*	
	  	default:
			obj.length++;
			obj.options[obj.length - 1].text = "Autor / Artista";
			obj.options[obj.length - 1].value = "B";
			obj.length++;
			obj.options[obj.length - 1].text = "Editora / Marca";
			obj.options[obj.length - 1].value = "C";
		break;
			*/
	}
}
function ComboOrdem(obj, fam) {
 // alimenta combo de ordenacao
	obj.length = 1;
	switch (fam) {
		case "0301":
		case "0314":
			obj.length++
			obj.options[obj.length - 1].text = "Autor";
			obj.options[obj.length - 1].value = "B";
			obj.length++
			obj.options[obj.length - 1].text = "Editora";
			obj.options[obj.length - 1].value = "C";
		break;
		case "0303":
		case "0312":
			obj.length++
			obj.options[obj.length - 1].text = "Distribuidora";
			obj.options[obj.length - 1].value = "C";
		break;
		case "0304":
			obj.length++
			obj.options[obj.length - 1].text = "Artista";
			obj.options[obj.length - 1].value = "B";
			obj.length++
			obj.options[obj.length - 1].text = "Gravadora";
			obj.options[obj.length - 1].value = "C";
		break;
		case "0305":
		case "0398":
			obj.length++
			obj.options[obj.length - 1].text = "Artista";
			obj.options[obj.length - 1].value = "B";
			obj.length++
			obj.options[obj.length - 1].text = "Distribuidora";
			obj.options[obj.length - 1].value = "C";
		break;
		default:
			obj.length++
			obj.options[obj.length - 1].text = "Fornecedor";
			obj.options[obj.length - 1].value = "B";
		break;
	}
	obj.length++
	obj.options[obj.length - 1].text = "Disponibilidade";
	obj.options[obj.length - 1].value = "D";
	obj.length++
	obj.options[obj.length - 1].text = "Mais Vendidos";
	obj.options[obj.length - 1].value = "E";
	obj.length++
	obj.options[obj.length - 1].text = "Lançamento";
	obj.options[obj.length - 1].value = "F";
	obj.length++
	obj.options[obj.length - 1].text = "Preço";
	obj.options[obj.length - 1].value = "G";
}


function AtualizaComboALL() {
	with(document.GERAL) {
		a = _FAMILIAN2.options[_FAMILIAN2.selectedIndex].value;   // acerta filtros		
		ComboFiltro(_FILTRON2, a);
		//ComboOrdem(_ORDEMN2, a); // alimenta combo		
		_ESTRUTN2.length = 1;		
		if (a != "") {
			AtualizaCombo(_ESTRUTN2, CDESTN3, NOMEESTN3, a);
		}		
		if (_ESTRUTN2.length == 1) {
			_ESTRUTN2.options[0].text = '(selecione um tipo de produto)';
		}
		else {
			_ESTRUTN2.options[0].text = 'Todas as Categorias de ' + _FAMILIAN2.options[_FAMILIAN2.selectedIndex].text;
		}
	}
}

function Familia(fam) {
	PosicionaCombo(document.GERAL._FAMILIAN2, fam);
	Filtrar();
}
function Area(are) {
	PosicionaCombo(document.GERAL._FAMILIAN2, are.substring(0, 4));
	AtualizaComboALL();
	PosicionaCombo(document.GERAL._ESTRUTN2, are);
    document.GERAL._PRECON2.selectedIndex = 0;
	Filtrar();
}



// *********************************************************************
// 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" : "");
}

