<!--

// Pesquisa

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; neste caso é POSIÇÃO

function parse_choice(m) {
    saux = self.location + '';
    ls = saux.length;
    return saux.substring(ls-m,ls);
}

// ordenamento da bd?? pq^ parse choice = 4? a chamada ?xxxx acima é feita por referências de 4 caracteres....

if (parse_choice(4)=='codi') {myfield = 1;}
if (parse_choice(4)=='dati') {myfield = 4;}
if (parse_choice(4)=='datt') {myfield = 7;}
if (parse_choice(4)=='tipo') {myfield = 8;}
if (parse_choice(4)=='auto') {myfield = 10;}
if (parse_choice(4)=='inst') {myfield = 12;}
if (parse_choice(4)=='priv') {myfield = 17;}

//  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;
  }

// é aqui que o campo 5 se junta aos restantes da data...

  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();
}


// rodapé normal

function show_footer() {

document.write('<IMG SRC=\"p.gif\" WIDTH=\"1\" HEIGHT=\"1\" ALT=\"\" BORDER=\"0\">')

}

// rodapé sem resultados na pesquisa

function show_null_result() {
  myhtml= "<BR><BR><P ALIGN=\"center\" CLASS=\"azul12b\">- SEM RESULTADOS -</P>\n";

  document.write(myhtml);
}


// rodapé com o número de resultados da pesquisa

function show_number_of_results(i) {
  if (i==1) myhtml= "<HR SIZE=\"1\" COLOR=\"#F39B45\"><TABLE WIDTH=\"96%\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" ALIGN=\"center\"><TR><TD WIDTH=\"32%\"><a href=\"javascript:print()\" CLASS=\"navama\" TITLE=  \"imprimir\">[=]</a></TD><TD ALIGN=\"center\" WIDTH=\"32%\"><A HREF=\"#topo\" CLASS=\"navama\" TITLE=\"topo\">[ î ]</A></TD><TD WIDTH=\"32%\" ALIGN=\"right\"><A HREF=\"javascript:self.close()\" TITLE=\"fechar esta janela\" CLASS=\"navama\">[ x ]</A></TD></TR></TABLE><BR></TABLE>\n";
  else myhtml= "<P ALIGN=\"center\" CLASS=\"azul12\"><FONT CLASS=\"azul12b\">" + i + "</FONT></P><BR>\n";
  document.write(myhtml);
}


//  -->