//<!--
function search_int_db_sf(str) {
  result_counter = 0;
  myflag = true;
  for (mi=1; mi<=dblength; mi++) {
    aux = false;
    for (mk=1;mk<=nit;mk++) {
        if (str!='') {
	       if (substring_eval(str,myval_xl_out(mi,mk))) aux = true;
		}
	}
	if (aux) {
	   if (myflag) {
	     show_header();
		 myflag = false;
	   }
	   show_result(mi);
	   result_counter++;
	}
  }
  if (result_counter==0) {show_null_result()}
  else {
    show_footer();
    show_number_of_results(result_counter)
  }
}

ua = new Array();
myfield = 1; //aqui é o campo por onde se organiza qd entra a bd
function parse_choice(m) {
    saux = self.location + '';
    ls = saux.length;
    return saux.substring(ls-m,ls);
}
if (parse_choice(4)=='titu') {myfield = 3;}
if (parse_choice(4)=='data') {myfield = 5;}
if (parse_choice(4)=='auto') {myfield = 1;}
if (parse_choice(4)=='inst') {myfield = 4;}
if (parse_choice(4)=='publ') {myfield = 6;}
if (parse_choice(4)=='link_txt') {myfield = 7;}
if (parse_choice(4)=='link_txt_dest') {myfield = 8;}
//  alert(parse_choice(4));

if (parse_choice(6)=='search') {
  saux = self.location + '';
  ls = saux.length;
  nc = 1*saux.substring(ls-8,ls-6);
  str = saux.substring(ls-nc-8,ls-8);
//  alert(str);
  search_int_db_sf(str);
} else {
  for (i=1; i<=dblength; i++) {
     ua[i] = i;
  }
  if (myfield == 5) {
    for (i=1; i<=dblength; i++) {
	  for (j=1; j<=dblength; j++) {
	     if (myval_xl_out(ua[i],myfield) > myval_xl_out(ua[j],myfield)) {
		    mybuffer = ua[i];
		    ua[i] = ua[j];
		    ua[j] = mybuffer;
         }
      }
   }
    for (i=1; i<=dblength; i++) {
	  for (j=1; j<=dblength; j++) {
	     if (myval_xl_out(ua[i],myfield+1) > myval_xl_out(ua[j],myfield+1)) {
		    mybuffer = ua[i];
		    ua[i] = ua[j];
		    ua[j] = mybuffer;
         }
      }
    }
    for (i=1; i<=dblength; i++) {
	  for (j=1; j<=dblength; j++) {
	     if (myval_xl_out(ua[i],myfield+2) > myval_xl_out(ua[j],myfield+2)) {
		    mybuffer = ua[i];
		    ua[i] = ua[j];
		    ua[j] = mybuffer;
         }
      }
    }
  } else {
    for (i=1; i<=dblength; i++) {
	  for (j=1; j<=dblength; j++) {
	     if (myval_xl_out(ua[i],myfield) < myval_xl_out(ua[j],myfield)) {
		    mybuffer = ua[i];
		    ua[i] = ua[j];
		    ua[j] = mybuffer;
         }
      }
    }
  }
  show_header();
  for (i=1; i<=dblength; i++)  {
    show_result(ua[i])
  }
  show_footer();
}
function show_footer() {
document.write('<IMG SRC=\"p.gif\" WIDTH=\"1\" HEIGHT=\"1\" ALT=\"\" BORDER=\"0\">')
}

function show_null_result() {
  myhtml= "<BR><BR><P ALIGN=\"center\" CLASS=\"azul12b\">Sem Produtos</FONT>\n";
  myhtml+= "<TABLE WIDTH=\"98%\" BORDER=\"0\" CELLSPACING=\"6\" CELLPADDING=\"6\"><TR><TD CLASS=\"preto10\" ALIGN=\"center\"><A HREF=\"catalogo.html\"><IMG SRC=\"seta_e.gif\" WIDTH=\"10\" HEIGHT=\"9\" BORDER=\"1\" ALIGN=\"ABSMIDDLE\"> ver todos os produtos</A></TD></TR></TABLE>";
  document.write(myhtml);
}
function show_number_of_results(i) {
  if (i==1) myhtml= "<BR><BR><P ALIGN=\"center\" CLASS=\"azul12b\">1 Produto</FONT>\n"
  else myhtml= "<BR><BR><P ALIGN=\"center\" CLASS=\"azul12\"><FONT CLASS=\"azul12b\">" + i + "</FONT> Produtos</FONT>\n"
  document.write(myhtml);
}


//-->