var db_category = new Array();
db_category[ "pdbstr" ] = "prot";
db_category[ "prf" ] = "prot";
db_category[ "refpept" ] = "prot";
db_category[ "refpep" ] = "prot";
db_category[ "swissprot" ] = "prot";
db_category[ "uniprot" ] = "prot";
db_category[ "genes" ] = "prot";
db_category[ "genesall" ] = "prot";
db_category[ "mine-aa" ] = "prot";
db_category[ "myspecies-aa" ] = "prot";
db_category[ "mgenes" ] = "prot";
db_category[ "vgenes.pep" ] = "prot";
db_category[ "nr-aa" ] = "prot";
db_category[ "dbsts" ] = "nucl";
db_category[ "nr-nt" ] = "nucl";
db_category[ "refseq" ] = "nucl";
db_category[ "refnuc" ] = "nucl";
db_category[ "dbest" ] = "nucl";
db_category[ "genes-nt" ] = "nucl";
db_category[ "genesall-nt" ] = "nucl";
db_category[ "mine-nt" ] = "nucl";
db_category[ "myspecies-nt" ] = "nucl";
db_category[ "mine_genome" ] = "nucl";
db_category[ "mygenome" ] = "nucl";
db_category[ "egenes-nt" ] = "nucl";
db_category[ "mgenes-nt" ] = "nucl";
db_category[ "vgenes.nuc" ] = "nucl";
db_category[ "genome" ] = "nucl";
db_category[ "vgenome" ] = "nucl";
db_category[ "dbgss" ] = "nucl";
db_category[ "htgs" ] = "nucl";
db_category[ "epd" ] = "nucl";
db_category[ "embl-wgs" ] = "nucl";

var dbtype = "prot";

function set_enable_dbname(theForm){
  var dbObj = theForm.dbname;
  for( var i=0; i<dbObj.length; i++ ){
    var db = dbObj[i].value;
    if( dbtype == db_category[ db ] ){
      dbObj[i].disabled = false;
    } else {
      dbObj[i].disabled = true;
    }
  }

/*
  var myaa;
  var mynt;
  if( document.getElementById ){
    myaa = document.getElementById('myspecies-aa');
    mynt = document.getElementById('myspecies-nt');
  }
  else if( document.all ){
    myaa = document.all('myspecies-aa');
    mynt = document.all('myspecies-nt');
  }

  if( dbtype == "prot" ){
    mynt.value = "";
    myaa.readOnly = false;
    mynt.readOnly = true;
  } else {
    myaa.value = "";
    myaa.readOnly = true;
    mynt.readOnly = false;
  }
*/

}

function set_dbtype( theForm, stype ){
  if( stype != dbtype ){
    dbtype = stype;
    set_enable_dbname( theForm );
    if( stype == "prot" ) set_db( theForm, "genes" );
    else set_db( theForm, "genes-nt" );
  }
}

function set_db( theForm, db ){
  var dbObj = theForm.dbname;
  for( var i=0; i<dbObj.length; i++ ){
    if( dbObj[i].value == db ){
      dbObj[i].checked = true;
    }
  }
}

function set_mysp( theForm, stype ){
  if( stype != dbtype ){
    dbtype = stype;
    set_enable_dbname( theForm );
    if( stype == "prot" ){
      // prog[0] is blastp/fasta
      theForm.prog[0].checked = true;
    }
    else if( stype == "nucl" ){

      if( theForm.prog[0].value.match(/blast/) ){
	// prog[2] is blastn
	theForm.prog[2].checked = true;
      }
      else{
 	// prog[1] is fasta
	theForm.prog[1].checked = true;
      }

    }
  }

  if( stype == "prot" ){
    set_db( theForm, "mine-aa" );
  }
  else if( stype == "nucl" ){
    set_db( theForm, "mine-nt" );
  }

}

function set_mygn( theForm, stype ){
  if( stype != dbtype ){
    dbtype = stype;
    set_enable_dbname( theForm );
    if( theForm.prog[0].value.match(/blast/) ){
      // prog[2] is blastn
      theForm.prog[2].checked = true;
    }
    else{
      // prog[1] is fasta
      theForm.prog[1].checked = true;
    }
  }

  set_db( theForm, "mine_genome" );

}

function formClear( theForm ){
  dbtype = "prot";
  set_enable_dbname(theForm);
  theForm.reset;
}

