/***************************************************************************************
 * Copyright (c) 2001-2004, NeoGrid Informática.  Todos os direitos reservados. 
 *
 * Os Programas desta Aplicação (que incluem tanto o software quanto a sua documentação) 
 * contém informações proprietárias da NeoGrid Informática; eles são licenciados de acordo 
 * com um contrato de licença contendo restrições de uso e confidencialidade, e são também 
 * protegidos pela Lei 9609/98 e 9610/98, respectivamente Lei do  Software  e  Lei  dos 
 * Direitos Autorais. Engenharia reversa, descompilação e desmontagem dos programas  são 
 * proibidos. Nenhuma parte destes  programas pode ser  reproduzida  ou  transmitida  de 
 * nenhuma forma e por nenhum meio, eletrônico ou mecânico,  por  motivo  algum,  sem  a 
 * permissão escrita da NeoGrid Informática.
 **************************************************************************************/
var NG_VERSION = "$PRODUCTVERSION$2.00$COMPONENTVERSION$0004$";
/*
  - Give Credit Where Its Due -
  Please acknowledge this article and its author, at
  least in code comments, when using this code.

  Author: Justin Whitford
  Source: www.evolt.org

  Thank you.
*/

/*
  filtery(pattern, list)
  pattern: a string of zero or more characters by which to filter the list
  list: reference to a form object of type, select

  Example:
  <form name="yourForm">
    <input type="text" name="yourTextField" onchange="filtery(this.value,this.form.yourSelect)">
    <select name="yourSelect">
      <option></option>
      <option value="Australia">Australia</option>
       .......
*/
function filtery(pattern, list){
  /*
  if the dropdown list passed in hasn't
  already been backed up, we'll do that now
  */
  if (!list.bak){
    /*
    We're going to attach an array to the select object
    where we'll keep a backup of the original dropdown list
    */
    list.bak = new Array();
    for (n=0;n<list.length;n++){
      list.bak[list.bak.length] = new Array(list[n].value, list[n].text, list[n].className);
    }
  }

  /*
  We're going to iterate through the backed up dropdown
  list. If an item matches, it is added to the list of
  matches. If not, then it is added to the list of non matches.
  */
  match = new Array();
  nomatch = new Array();
  for (n=0;n<list.bak.length;n++){
    if(list.bak[n][1].toLowerCase().indexOf(pattern.toLowerCase())!=-1){
      match[match.length] = new Array(list.bak[n][0], list.bak[n][1], list.bak[n][2]);
    }else{
      nomatch[nomatch.length] = new Array(list.bak[n][0], list.bak[n][1], list.bak[n][2]);
    }
  }

  /*
  Now we completely rewrite the dropdown list.
  First we write in the matches, then we write
  in the non matches
  */
  for (n=0;n<match.length;n++){
    list[n].value = match[n][0];
    list[n].text = match[n][1];
    list[n].className = match[n][2];
  }
  for (n=0;n<nomatch.length;n++){
    list[n+match.length].value = nomatch[n][0];
    list[n+match.length].text = nomatch[n][1];
    list[n+match.length].className = nomatch[n][2];
  }

  /*
  Finally, we make the 1st item selected - this
  makes sure that the matching options are
  immediately apparent
  */
  list.selectedIndex=0;
}










