Event.observe(window, 'load', init);

function init() {
	GmbisAutocompleter.acCommonName = new Autocompleter.Dropdown('commonname', 'commonnameList', [['Alewife','Alewife','Alosa pseudoharengus'],['Alligatorfish','Alligatorfish','Aspidophoroides monopterygius'],['Amberjack, Greater','Greater Amberjack','Seriola dumerili'],['Anchovy, Bay','Bay Anchovy','Anchoa mitchilli'],['Anchovy, Silver','Silver Anchovy','Engraulis eurystole'],['Anchovy, Striped','Striped Anchovy','Anchoa hepsetus'],['Argentine, Atlantic','Atlantic Argentine','Argentina silus'],['Argentine, Striated','Striated Argentine','Argentina striata'],['Astarte, Smooth','Smooth Astarte','Astarte castanea'],['Atlantic Seasnail','Atlantic Seasnail','Liparis atlanticus'],['Atlantic Soft Pout','Atlantic Soft Pout','Melanostigma atlanticum'],['Atlantic Spiny Lumpsucker','Atlantic Spiny Lumpsucker','Eumicrotremus spinosus'],['Barracuda Uncl','Barracuda Uncl','Sphyraena'],['Barracudina, White','White Barracudina','Arctozenus risso'],['Barrelfish','Barrelfish','Hyperoglyphe perciformis'],['Bass, Bank Sea','Bank Sea Bass','Centropristis ocyurus'],['Bass, Black Sea','Black Sea Bass','Centropristis striata'],['Bass, Blackmouth','Blackmouth Bass','Synagrops bellus'],['Bass, Striped','Striped Bass','Morone saxatilis'],['Batfish, Atlantic','Atlantic Batfish','Dibranchus atlanticus'],['Batfish, Longnose','Longnose Batfish','Ogcocephalus corniger'],['Batfish, Shortnose','Shortnose Batfish','Ogcocephalus nasutus'],['Beardfish','Beardfish','Polymixia lowei'],['Beardfish, Stout','Stout Beardfish','Polymixia nobilis'],['Bigeye','Bigeye','Priacanthus arenatus'],['Bigeye, Short','Short Bigeye','Pristigenys alta'],['Bluefish','Bluefish','Pomatomus saltatrix'],['Boarfish, Deepbody','Deepbody Boarfish','Antigonia capros'],['Bobtail, Lesser Shining','Lesser Shining Bobtail','Semirossia tenera'],['Bobtail, Shield','Shield Bobtail','Stoloteuthis leucoptera'],['Bonito, Atlantic','Atlantic Bonito','Sarda sarda'],['Bristled Longbeak','Bristled Longbeak','Dichelopandalus leptocerus'],['Bulleye','Bulleye','Cookeolus japonicus'],['Butterfish','Butterfish','Peprilus triacanthus'],['Capelin','Capelin','Mallotus villosus'],['Cigarfish, Bigeye','Bigeye Cigarfish','Cubiceps pauciradiatus'],['Clapper, Atlantic Surfclam','Atlantic Surfclam Clapper','Clapper Spisula solidissima'],['Clapper, Iceland Scallop','Iceland Scallop Clapper','Clapper Chlamys islandica'],['Clapper, Ocean Quahog','Ocean Quahog Clapper','Clapper Arctica islandica'],['Clapper, Sea Scallop','Sea Scallop Clapper','Clapper Placopecten magellanic'],['Cod, Atlantic','Atlantic Cod','Gadus morhua'],['Cornetfish, Bluespotted','Bluespotted Cornetfish','Fistularia tabacaria'],['Cornetfish, Red','Red Cornetfish','Fistularia petimba'],['Crab, Atlantic Rock','Atlantic Rock Crab','Cancer irroratus'],['Crab, Bathyal Swimming','Bathyal Swimming Crab','Bathynectes longispina'],['Crab, Coarsehand Lady','Coarsehand Lady Crab','Ovalipes stephensoni'],['Crab, Green','Green Crab','Carcinus maenas'],['Crab, Horseshoe','Horseshoe Crab','Limulus polyphemus'],['Crab, Jonah','Jonah Crab','Cancer borealis'],['Crab, Lady','Lady Crab','Ovalipes ocellatus'],['Crab, Northern Stone','Northern Stone Crab','Lithodes maja'],['Crab, Red Deepsea','Red Deepsea Crab','Chaceon quinquedens'],['Crab, Snow','Snow Crab','Chionoecetes opilio'],['Crab, Toad','Toad Crab','Hyas araneus'],['Croaker, Atlantic','Atlantic Croaker','Micropogonias undulatus'],['Cucumber, Rat-tail','Rat-tail Cucumber','Caudina arenata'],['Cucumber, Sea','Sea Cucumber','Cucumaria frondosa'],['Cunner','Cunner','Tautogolabrus adspersus'],['Cusk','Cusk','Brosme brosme'],['Cusk Eel','Cusk Eel','Ophidiidae'],['Cusk-Eel, Blotched','Blotched Cusk-Eel','Ophidion grayi'],['Cusk-Eel, Fawn','Fawn Cusk-Eel','Lepophidium profundorum'],['Cusk-Eel, Mooneye','Mooneye Cusk-Eel','Ophidion selenops'],['Cusk-Eel, Striped','Striped Cusk-Eel','Ophidion marginatum'],['Cutlassfish, Atlantic','Atlantic Cutlassfish','Trichiurus lepturus'],['Cyclocardia, Northern','Northern Cyclocardia','Cyclocardia borealis'],['Dogfish, Black','Black Dogfish','Centroscyllium fabricii'],['Dogfish, Chain','Chain Dogfish','Scyliorhinus retifer'],['Dogfish, Smooth','Smooth Dogfish','Mustelus canis'],['Dogfish, Spiny','Spiny Dogfish','Squalus acanthias'],['Dory, Buckler','Buckler Dory','Zenopsis conchifera'],['Dragonet, Spotfin','Spotfin Dragonet','Foetorepus agassizii'],['Dragonfish, Boa','Boa Dragonfish','Stomias boa'],['Driftfish, Spotted','Spotted Driftfish','Ariomma regulus'],['Eel, American','American Eel','Anguilla rostrata'],['Eel, Conger','Conger Eel','Conger oceanicus'],['Eel, Margined Snake','Margined Snake Eel','Ophichthus cruentifer'],['Eel, Slender Snipe','Slender Snipe Eel','Nemichthys scolopaceus'],['Eel, Snubnose','Snubnose Eel','Simenchelys parasitica'],['Eelpout, Arctic','Arctic Eelpout','Lycodes reticulatus'],['Eelpout, Wolf','Wolf Eelpout','Lycenchelys verrillii'],['Egg mops, Longfin Squid','Longfin Squid Egg mops','Egg Mops Loligo pealeii'],['Eualid, Arctic','Arctic Eualid','Eualus fabricii'],['Filefish, Orange','Orange Filefish','Aluterus schoepfii'],['Filefish, Planehead','Planehead Filefish','Stephanolepis hispida'],['Flounder, Deepwater','Deepwater Flounder','Monolene sessilicauda'],['Flounder, Fourspot','Fourspot Flounder','Hippoglossina oblonga'],['Flounder, Gulf Stream','Gulf Stream Flounder','Citharichthys arctifrons'],['Flounder, Smallmouth','Smallmouth Flounder','Etropus microstomus'],['Flounder, Summer','Summer Flounder','Paralichthys dentatus'],['Flounder, Winter','Winter Flounder','Pseudopleuronectes americanus'],['Flounder, Witch','Witch Flounder','Glyptocephalus cynoglossus'],['Flounder, Yellowtail','Yellowtail Flounder','Limanda ferruginea'],['Flying Gurnard','Flying Gurnard','Dactylopterus volitans'],['Gaper, Redeye','Redeye Gaper','Chaunax stigmaeus'],['Goosefish','Goosefish','Lophius americanus'],['Greeneye, Longnose','Longnose Greeneye','Parasudis truculenta'],['Greeneye, Shortnose','Shortnose Greeneye','Chlorophthalmus agassizi'],['Grenadier, Longnose','Longnose Grenadier','Caelorinchus caelorhincus carminatus'],['Grenadier, Roughhead','Roughhead Grenadier','Macrourus berglax'],['Grenadier, Western Softhead','Western Softhead Grenadier','Malacocephalus occidentalis'],['Grubby','Grubby','Myoxocephalus aenaeus'],['Gunnel, Rock','Rock Gunnel','Pholis gunnellus'],['Haddock','Haddock','Melanogrammus aeglefinus'],['Hagfish, Atlantic','Atlantic Hagfish','Myxine glutinosa'],['Hake, Blue','Blue Hake','Antimora rostrata'],['Hake, Longfin','Longfin Hake','Phycis chesteri'],['Hake, Offshore','Offshore Hake','Merluccius albidus'],['Hake, Red','Red Hake','Urophycis chuss'],['Hake, Silver','Silver Hake','Merluccius bilinearis'],['Hake, Spotted','Spotted Hake','Urophycis regia'],['Hake, White','White Hake','Urophycis tenuis'],['Halfbeak, Silverstripe','Silverstripe Halfbeak','Hyporhamphus unifasciatus'],['Halibut, Atlantic','Atlantic Halibut','Hippoglossus hippoglossus'],['Halibut, Greenland','Greenland Halibut','Reinhardtius hippoglossoides'],['Hatchetfish, Silver','Silver Hatchetfish','Argyropelecus aculeatus'],['Headlightfish','Headlightfish','Diaphus dumerilii'],['Herring, Atlantic','Atlantic Herring','Clupea harengus'],['Herring, Blueback','Blueback Herring','Alosa aestivalis'],['Herring, Round','Round Herring','Etrumeus teres'],['Horsemussel, Northern','Northern Horsemussel','Modiolus modiolus'],['Inquiline Snailfish','Inquiline Snailfish','Liparis inquilinus'],['Jack, Yellow','Yellow Jack','Carangoides bartholomaei'],['Kingfish, Northern','Northern Kingfish','Menticirrhus saxatilis'],['Lamprey, Sea','Sea Lamprey','Petromyzon marinus'],['Lanternfish, Horned','Horned Lanternfish','Ceratoscopelus maderensis'],['Lanternfish, Spotted','Spotted Lanternfish','Myctophum punctatum'],['Lebbeid, Polar','Polar Lebbeid','Lebbeus polaris'],['Lebbeid, Spiny','Spiny Lebbeid','Lebbeus groenlandicus'],['Lobster, American','American Lobster','Homarus americanus'],['Lobster, Ridged Slipper','Ridged Slipper Lobster','Scyllarides nodifer'],['Lookdown','Lookdown','Selene vomer'],['Lumpfish','Lumpfish','Cyclopterus lumpus'],['Mackerel, Atlantic','Atlantic Mackerel','Scomber scombrus'],['Mackerel, Chub','Chub Mackerel','Scomber colias'],['Marlin-Spike','Marlin-Spike','Nezumia bairdii'],['Menhaden, Atlantic','Atlantic Menhaden','Brevoortia tyrannus'],['Moonfish, Atlantic','Atlantic Moonfish','Selene setapinnis'],['Moonsnail, Northern','Northern Moonsnail','Euspira heros'],['Mussel, Blue','Blue Mussel','Mytilus edulis'],['Octopus, Common','Common Octopus','Octopus vulgaris'],['Octopus, Spoonarm','Spoonarm Octopus','Bathypolypus arcticus'],['Pearlsides','Pearlsides','Maurolicus muelleri'],['Pearlsides, Weitzmans','Weitzmans Pearlsides','Maurolicus weitzmani'],['Pigfish','Pigfish','Orthopristis chrysoptera'],['Pilotfish','Pilotfish','Naucrates ductor'],['Pipefish, Northern','Northern Pipefish','Syngnathus fuscus'],['Plaice, American','American Plaice','Hippoglossoides platessoides'],['Pollock','Pollock','Pollachius virens'],['Pout, Ocean','Ocean Pout','Zoarces americanus'],['Puffer, Northern','Northern Puffer','Sphoeroides maculatus'],['Quahog, False','False Quahog','Pitar morrhuanus'],['Quahog, Northern','Northern Quahog','Mercenaria mercenaria'],['Quahog, Ocean','Ocean Quahog','Arctica islandica'],['Redfish, Acadian','Acadian Redfish','Sebastes fasciatus'],['Rockling, Fourbeard','Fourbeard Rockling','Enchelyopus cimbrius'],['Rockling, Threebeard','Threebeard Rockling','Gaidropsarus ensis'],['Rosefish, Blackbelly','Blackbelly Rosefish','Helicolenus dactylopterus'],['Rudderfish, Banded','Banded Rudderfish','Seriola zonata'],['Runner, Blue','Blue Runner','Caranx crysos'],['Runner, Rainbow','Rainbow Runner','Elagatis bipinnulata'],['Salmon, Atlantic','Atlantic Salmon','Salmo salar'],['Sandlance, American','American Sandlance','Ammodytes americanus'],['Sandlance, Northern','Northern Sandlance','Ammodytes dubius'],['Saury, Atlantic','Atlantic Saury','Scomberesox saurus'],['Scad, Bigeye','Bigeye Scad','Selar crumenophthalmus'],['Scad, Mackerel','Mackerel Scad','Decapterus macarellus'],['Scad, Rough','Rough Scad','Trachurus lathami'],['Scad, Round','Round Scad','Decapterus punctatus'],['Scallop, Iceland','Iceland Scallop','Chlamys islandica'],['Scallop, Sea','Sea Scallop','Placopecten magellanicus'],['Sculpin, Longhorn','Longhorn Sculpin','Myoxocephalus octodecemspinosus'],['Sculpin, Moustache','Moustache Sculpin','Triglops murrayi'],['Sculpin, Shorthorn','Shorthorn Sculpin','Myoxocephalus scorpius'],['Scup','Scup','Stenotomus chrysops'],['Sea Raven','Sea Raven','Hemitripterus americanus'],['Sea star, Northern','Northern Sea star','Asterias rubens'],['Sea Urchin, Green','Green Sea Urchin','Strongylocentrotus droebachiensis'],['Searobin, Armored','Armored Searobin','Peristedion miniatum'],['Searobin, Northern','Northern Searobin','Prionotus carolinus'],['Searobin, Spiny','Spiny Searobin','Prionotus alatus'],['Searobin, Striped','Striped Searobin','Prionotus evolans'],['Seasnail, Gelationous','Gelationous Seasnail','Liparis fabricii'],['Seasnail, Gulf','Gulf Seasnail','Liparis coheni'],['Seasnail, Striped','Striped Seasnail','Liparis liparis'],['Shad, American','American Shad','Alosa sapidissima'],['Shad, Hickory','Hickory Shad','Alosa mediocris'],['Shanny, Daubed','Daubed Shanny','Leptoclinus maculatus'],['Shanny, Radiated','Radiated Shanny','Ulvaria subbifurcata'],['shark eye','shark eye','Neverita duplicata'],['Shark, Basking','Basking Shark','Cetorhinus maximus'],['Shark, Blue','Blue Shark','Prionace glauca'],['Sheepshead','Sheepshead','Archosargus probatocephalus'],['Shrimp, Aesop','Aesop Shrimp','Pandalus montagui'],['Shrimp, Friendly Blade','Friendly Blade Shrimp','Spirontocaris lilljeborgii'],['Shrimp, Northern','Northern Shrimp','Pandalus borealis'],['Shrimp, Norwegian','Norwegian Shrimp','Pontophilus norvegicus'],['Shrimp, Parrot','Parrot Shrimp','Spirontocaris spinus'],['Shrimp, Pink Glass','Pink Glass Shrimp','Pasiphaea multidentata'],['Shrimp, Punctate Blade','Punctate Blade Shrimp','Spirontocaris phippsii'],['Shrimp, Sevenspine Bay','Sevenspine Bay Shrimp','Crangon septemspinosa'],['Silver Rag','Silver Rag','Ariomma bondi'],['Silverside, Atlantic','Atlantic Silverside','Menidia menidia'],['Skate, Barndoor','Barndoor Skate','Dipturus laevis'],['Skate, Clearnose','Clearnose Skate','Raja eglanteria'],['Skate, Little','Little Skate','Leucoraja erinacea'],['Skate, Rosette','Rosette Skate','Leucoraja garmani'],['Skate, Smooth','Smooth Skate','Malacoraja senta'],['Skate, Thorny','Thorny Skate','Amblyraja radiata'],['Skate, Winter','Winter Skate','Leucoraja ocellata'],['Smelt, Rainbow','Rainbow Smelt','Osmerus mordax'],['Snakeblenny','Snakeblenny','Lumpenus lampretaeformis'],['Snapper, Vermilion','Vermilion Snapper','Rhomboplites aurorubens'],['Snipefish, Longspine','Longspine Snipefish','Macroramphosus scolopax'],['Squid, Atlantic Brief','Atlantic Brief Squid','Lolliguncula brevis'],['Squid, Longfin','Longfin Squid','Loligo pealeii'],['Squid, Northern Shortfin','Northern Shortfin Squid','Illex illecebrosus'],['Stickleback, Fourspine','Fourspine Stickleback','Apeltes quadracus'],['Stickleback, Threespine','Threespine Stickleback','Gasterosteus aculeatus'],['Sturgeon, Atlantic','Atlantic Sturgeon','Acipenser oxyrinchus oxyrinchus'],['Sturgeon, Atlantic','Atlantic Sturgeon','Acipenser oxyrinchus'],['Surfclam, Atlantic','Atlantic Surfclam','Spisula solidissima'],['Tautog','Tautog','Tautoga onitis'],['Tilefish','Tilefish','Lopholatilus chamaeleonticeps'],['Toadfish, Oyster','Oyster Toadfish','Opsanus tau'],['Tomcod, Atlantic','Atlantic Tomcod','Microgadus tomcod'],['Tonguefish, Blackcheek','Blackcheek Tonguefish','Symphurus plagiusa'],['Tonguefish, Offshore','Offshore Tonguefish','Symphurus civitatium'],['Tonguefish, Spottedfin','Spottedfin Tonguefish','Symphurus diomedeanus'],['Torpedo, Atlantic','Atlantic Torpedo','Torpedo nobiliana'],['Triggerfish, Gray','Gray Triggerfish','Balistes capriscus'],['Uncl, Anchovy','Anchovy Uncl','Engraulidae'],['Uncl, Barnacle','Barnacle Uncl','Balanus'],['Uncl, Barracudina','Barracudina Uncl','Paralepididae'],['Uncl, Batfish','Batfish Uncl','Ogcocephalidae'],['Uncl, Boarfish','Boarfish Uncl','Caproidae'],['Uncl, Bobtail','Bobtail Uncl','Sepiolidae'],['Uncl, Butterfish','Butterfish Uncl','Stromateidae'],['Uncl, Calico Crab','Calico Crab Uncl','Ovalipes'],['Uncl, Cancer Crab','Cancer Crab Uncl','Cancridae'],['Uncl, Cardinalfish','Cardinalfish Uncl','Apogonidae'],['Uncl, Conger Eel','Conger Eel Uncl','Congridae'],['Uncl, Eel','Eel Uncl','Anguilliformes'],['Uncl, Eelpout','Eelpout Uncl','Zoarcidae'],['Uncl, Flounder','Flounder Uncl','Pleuronectiformes'],['Uncl, Greeneye','Greeneye Uncl','Chlorophthalmidae'],['Uncl, Grenadier','Grenadier Uncl','Macrouridae'],['Uncl, Hake','Hake Uncl','Gadidae'],['Uncl, Hatchetfish','Hatchetfish Uncl','Sternoptychidae'],['Uncl, Hermit Crab','Hermit Crab Uncl','Paguroidea'],['Uncl, Herring','Herring Uncl','Clupeidae'],['Uncl, Lanternfish','Lanternfish Uncl','Myctophidae'],['Uncl, Lightfish','Lightfish Uncl','Gonostomatidae'],['Uncl, Ling','Ling Uncl','Urophycis'],['Uncl, Lizardfish','Lizardfish Uncl','Synodontidae'],['Uncl, Mantis Shrimp','Mantis Shrimp Uncl','Stomatopoda'],['Uncl, Mora','Mora Uncl','Moridae'],['Uncl, Octopus','Octopus Uncl','Octopoda'],['Uncl, Sand Dollar','Sand Dollar Uncl','Clypeasteroida'],['Uncl, Sculpin','Sculpin Uncl','Cottidae'],['Uncl, Searobin','Searobin Uncl','Triglidae'],['Uncl, Shrimp','Shrimp Uncl','Euphausiacea'],['Uncl, Shrimp','Shrimp Uncl','Decapoda'],['Uncl, Skate','Skate Uncl','Raja'],['Uncl, Slickhead','Slickhead Uncl','Alepocephalidae'],['Uncl, Snake Eel','Snake Eel Uncl','Ophichthidae'],['Uncl, Snapper','Snapper Uncl','Lutjanidae'],['Uncl, Spider Crab','Spider Crab Uncl','Majidae'],['Uncl, Squid','Squid Uncl','Loliginidae'],['Uncl, Swimming Crab','Swimming Crab Uncl','Portunidae'],['Uncl, Tonguefish','Tonguefish Uncl','Symphurus'],['Uncl, Whiting','Whiting Uncl','Merluccius'],['Unclassified, fish','fish Unclassified','Unclassified fish'],['Unknown','Unknown','Unknown'],['Viperfish','Viperfish','Chauliodus sloani'],['water haul','water haul','Water haul'],['Waved Astarte','Waved Astarte','Astarte undata'],['Whelk, Channeled','Channeled Whelk','Busycotypus canaliculatus'],['Whelk, Knobbed','Knobbed Whelk','Busycon carica'],['Whelk, Stimpson','Stimpson Whelk','Colus stimpsoni'],['Whelk, Ten-Ridged','Ten-Ridged Whelk','Neptunea lyrata decemcostata'],['Whelk, Waved','Waved Whelk','Buccinum undatum'],['Windowpane','Windowpane','Scophthalmus aquosus'],['Wolffish, Atlantic','Atlantic Wolffish','Anarhichas lupus'],['Wrymouth','Wrymouth','Cryptacanthodes maculatus']], {choices: 1000, emptyClass: 'empty', partialSearch: true, tokens: [','], selector: GmbisAutocompleter.commonnameSelector});
	GmbisAutocompleter.acScientificName = new Autocompleter.Dropdown('scientificname', 'scientificnameList', [['Acipenser oxyrinchus','Atlantic Sturgeon'],['Acipenser oxyrinchus oxyrinchus','Atlantic Sturgeon'],['Alepocephalidae','Slickhead Uncl'],['Alosa aestivalis','Blueback Herring'],['Alosa mediocris','Hickory Shad'],['Alosa pseudoharengus','Alewife'],['Alosa sapidissima','American Shad'],['Aluterus schoepfii','Orange Filefish'],['Amblyraja radiata','Thorny Skate'],['Ammodytes americanus','American Sandlance'],['Ammodytes dubius','Northern Sandlance'],['Anarhichas lupus','Atlantic Wolffish'],['Anchoa hepsetus','Striped Anchovy'],['Anchoa mitchilli','Bay Anchovy'],['Anguilla rostrata','American Eel'],['Anguilliformes','Eel Uncl'],['Antigonia capros','Deepbody Boarfish'],['Antimora rostrata','Blue Hake'],['Apeltes quadracus','Fourspine Stickleback'],['Apogonidae','Cardinalfish Uncl'],['Archosargus probatocephalus','Sheepshead'],['Arctica islandica','Ocean Quahog'],['Arctozenus risso','White Barracudina'],['Argentina silus','Atlantic Argentine'],['Argentina striata','Striated Argentine'],['Argyropelecus aculeatus','Silver Hatchetfish'],['Ariomma bondi','Silver Rag'],['Ariomma regulus','Spotted Driftfish'],['Aspidophoroides monopterygius','Alligatorfish'],['Astarte castanea','Smooth Astarte'],['Astarte undata','Waved Astarte'],['Asterias rubens','Northern Sea star'],['Balanus','Barnacle Uncl'],['Balistes capriscus','Gray Triggerfish'],['Bathynectes longispina','Bathyal Swimming Crab'],['Bathypolypus arcticus','Spoonarm Octopus'],['Brevoortia tyrannus','Atlantic Menhaden'],['Brosme brosme','Cusk'],['Buccinum undatum','Waved Whelk'],['Busycon carica','Knobbed Whelk'],['Busycotypus canaliculatus','Channeled Whelk'],['Caelorinchus caelorhincus carminatus','Longnose Grenadier'],['Cancer borealis','Jonah Crab'],['Cancer irroratus','Atlantic Rock Crab'],['Cancridae','Cancer Crab Uncl'],['Caproidae','Boarfish Uncl'],['Carangoides bartholomaei','Yellow Jack'],['Caranx crysos','Blue Runner'],['Carcinus maenas','Green Crab'],['Caudina arenata','Rat-tail Cucumber'],['Centropristis ocyurus','Bank Sea Bass'],['Centropristis striata','Black Sea Bass'],['Centroscyllium fabricii','Black Dogfish'],['Ceratoscopelus maderensis','Horned Lanternfish'],['Cetorhinus maximus','Basking Shark'],['Chaceon quinquedens','Red Deepsea Crab'],['Chauliodus sloani','Viperfish'],['Chaunax stigmaeus','Redeye Gaper'],['Chionoecetes opilio','Snow Crab'],['Chlamys islandica','Iceland Scallop'],['Chlorophthalmidae','Greeneye Uncl'],['Chlorophthalmus agassizi','Shortnose Greeneye'],['Citharichthys arctifrons','Gulf Stream Flounder'],['Clapper Arctica islandica','Ocean Quahog Clapper'],['Clapper Chlamys islandica','Iceland Scallop Clapper'],['Clapper Placopecten magellanic','Sea Scallop Clapper'],['Clapper Spisula solidissima','Atlantic Surfclam Clapper'],['Clupea harengus','Atlantic Herring'],['Clupeidae','Herring Uncl'],['Clypeasteroida','Sand Dollar Uncl'],['Colus stimpsoni','Stimpson Whelk'],['Conger oceanicus','Conger Eel'],['Congridae','Conger Eel Uncl'],['Cookeolus japonicus','Bulleye'],['Cottidae','Sculpin Uncl'],['Crangon septemspinosa','Sevenspine Bay Shrimp'],['Cryptacanthodes maculatus','Wrymouth'],['Cubiceps pauciradiatus','Bigeye Cigarfish'],['Cucumaria frondosa','Sea Cucumber'],['Cyclocardia borealis','Northern Cyclocardia'],['Cyclopterus lumpus','Lumpfish'],['Dactylopterus volitans','Flying Gurnard'],['Decapoda','Shrimp Uncl'],['Decapterus macarellus','Mackerel Scad'],['Decapterus punctatus','Round Scad'],['Diaphus dumerilii','Headlightfish'],['Dibranchus atlanticus','Atlantic Batfish'],['Dichelopandalus leptocerus','Bristled Longbeak'],['Dipturus laevis','Barndoor Skate'],['Egg Mops Loligo pealeii','Longfin Squid Egg mops'],['Elagatis bipinnulata','Rainbow Runner'],['Enchelyopus cimbrius','Fourbeard Rockling'],['Engraulidae','Anchovy Uncl'],['Engraulis eurystole','Silver Anchovy'],['Etropus microstomus','Smallmouth Flounder'],['Etrumeus teres','Round Herring'],['Eualus fabricii','Arctic Eualid'],['Eumicrotremus spinosus','Atlantic Spiny Lumpsucker'],['Euphausiacea','Shrimp Uncl'],['Euspira heros','Northern Moonsnail'],['Fistularia petimba','Red Cornetfish'],['Fistularia tabacaria','Bluespotted Cornetfish'],['Foetorepus agassizii','Spotfin Dragonet'],['Gadidae','Hake Uncl'],['Gadus morhua','Atlantic Cod'],['Gaidropsarus ensis','Threebeard Rockling'],['Gasterosteus aculeatus','Threespine Stickleback'],['Glyptocephalus cynoglossus','Witch Flounder'],['Gonostomatidae','Lightfish Uncl'],['Helicolenus dactylopterus','Blackbelly Rosefish'],['Hemitripterus americanus','Sea Raven'],['Hippoglossina oblonga','Fourspot Flounder'],['Hippoglossoides platessoides','American Plaice'],['Hippoglossus hippoglossus','Atlantic Halibut'],['Homarus americanus','American Lobster'],['Hyas araneus','Toad Crab'],['Hyperoglyphe perciformis','Barrelfish'],['Hyporhamphus unifasciatus','Silverstripe Halfbeak'],['Illex illecebrosus','Northern Shortfin Squid'],['Lebbeus groenlandicus','Spiny Lebbeid'],['Lebbeus polaris','Polar Lebbeid'],['Lepophidium profundorum','Fawn Cusk-Eel'],['Leptoclinus maculatus','Daubed Shanny'],['Leucoraja erinacea','Little Skate'],['Leucoraja garmani','Rosette Skate'],['Leucoraja ocellata','Winter Skate'],['Limanda ferruginea','Yellowtail Flounder'],['Limulus polyphemus','Horseshoe Crab'],['Liparis atlanticus','Atlantic Seasnail'],['Liparis coheni','Gulf Seasnail'],['Liparis fabricii','Gelationous Seasnail'],['Liparis inquilinus','Inquiline Snailfish'],['Liparis liparis','Striped Seasnail'],['Lithodes maja','Northern Stone Crab'],['Loliginidae','Squid Uncl'],['Loligo pealeii','Longfin Squid'],['Lolliguncula brevis','Atlantic Brief Squid'],['Lophius americanus','Goosefish'],['Lopholatilus chamaeleonticeps','Tilefish'],['Lumpenus lampretaeformis','Snakeblenny'],['Lutjanidae','Snapper Uncl'],['Lycenchelys verrillii','Wolf Eelpout'],['Lycodes reticulatus','Arctic Eelpout'],['Macroramphosus scolopax','Longspine Snipefish'],['Macrouridae','Grenadier Uncl'],['Macrourus berglax','Roughhead Grenadier'],['Majidae','Spider Crab Uncl'],['Malacocephalus occidentalis','Western Softhead Grenadier'],['Malacoraja senta','Smooth Skate'],['Mallotus villosus','Capelin'],['Maurolicus muelleri','Pearlsides'],['Maurolicus weitzmani','Weitzmans Pearlsides'],['Melanogrammus aeglefinus','Haddock'],['Melanostigma atlanticum','Atlantic Soft Pout'],['Menidia menidia','Atlantic Silverside'],['Menticirrhus saxatilis','Northern Kingfish'],['Mercenaria mercenaria','Northern Quahog'],['Merluccius','Whiting Uncl'],['Merluccius albidus','Offshore Hake'],['Merluccius bilinearis','Silver Hake'],['Microgadus tomcod','Atlantic Tomcod'],['Micropogonias undulatus','Atlantic Croaker'],['Modiolus modiolus','Northern Horsemussel'],['Monolene sessilicauda','Deepwater Flounder'],['Moridae','Mora Uncl'],['Morone saxatilis','Striped Bass'],['Mustelus canis','Smooth Dogfish'],['Myctophidae','Lanternfish Uncl'],['Myctophum punctatum','Spotted Lanternfish'],['Myoxocephalus aenaeus','Grubby'],['Myoxocephalus octodecemspinosus','Longhorn Sculpin'],['Myoxocephalus scorpius','Shorthorn Sculpin'],['Mytilus edulis','Blue Mussel'],['Myxine glutinosa','Atlantic Hagfish'],['Naucrates ductor','Pilotfish'],['Nemichthys scolopaceus','Slender Snipe Eel'],['Neptunea lyrata decemcostata','Ten-Ridged Whelk'],['Neverita duplicata','shark eye'],['Nezumia bairdii','Marlin-Spike'],['Octopoda','Octopus Uncl'],['Octopus vulgaris','Common Octopus'],['Ogcocephalidae','Batfish Uncl'],['Ogcocephalus corniger','Longnose Batfish'],['Ogcocephalus nasutus','Shortnose Batfish'],['Ophichthidae','Snake Eel Uncl'],['Ophichthus cruentifer','Margined Snake Eel'],['Ophidiidae','Cusk Eel'],['Ophidion grayi','Blotched Cusk-Eel'],['Ophidion marginatum','Striped Cusk-Eel'],['Ophidion selenops','Mooneye Cusk-Eel'],['Opsanus tau','Oyster Toadfish'],['Orthopristis chrysoptera','Pigfish'],['Osmerus mordax','Rainbow Smelt'],['Ovalipes','Calico Crab Uncl'],['Ovalipes ocellatus','Lady Crab'],['Ovalipes stephensoni','Coarsehand Lady Crab'],['Paguroidea','Hermit Crab Uncl'],['Pandalus borealis','Northern Shrimp'],['Pandalus montagui','Aesop Shrimp'],['Paralepididae','Barracudina Uncl'],['Paralichthys dentatus','Summer Flounder'],['Parasudis truculenta','Longnose Greeneye'],['Pasiphaea multidentata','Pink Glass Shrimp'],['Peprilus triacanthus','Butterfish'],['Peristedion miniatum','Armored Searobin'],['Petromyzon marinus','Sea Lamprey'],['Pholis gunnellus','Rock Gunnel'],['Phycis chesteri','Longfin Hake'],['Pitar morrhuanus','False Quahog'],['Placopecten magellanicus','Sea Scallop'],['Pleuronectiformes','Flounder Uncl'],['Pollachius virens','Pollock'],['Polymixia lowei','Beardfish'],['Polymixia nobilis','Stout Beardfish'],['Pomatomus saltatrix','Bluefish'],['Pontophilus norvegicus','Norwegian Shrimp'],['Portunidae','Swimming Crab Uncl'],['Priacanthus arenatus','Bigeye'],['Prionace glauca','Blue Shark'],['Prionotus alatus','Spiny Searobin'],['Prionotus carolinus','Northern Searobin'],['Prionotus evolans','Striped Searobin'],['Pristigenys alta','Short Bigeye'],['Pseudopleuronectes americanus','Winter Flounder'],['Raja','Skate Uncl'],['Raja eglanteria','Clearnose Skate'],['Reinhardtius hippoglossoides','Greenland Halibut'],['Rhomboplites aurorubens','Vermilion Snapper'],['Salmo salar','Atlantic Salmon'],['Sarda sarda','Atlantic Bonito'],['Scomber colias','Chub Mackerel'],['Scomber scombrus','Atlantic Mackerel'],['Scomberesox saurus','Atlantic Saury'],['Scophthalmus aquosus','Windowpane'],['Scyliorhinus retifer','Chain Dogfish'],['Scyllarides nodifer','Ridged Slipper Lobster'],['Sebastes fasciatus','Acadian Redfish'],['Selar crumenophthalmus','Bigeye Scad'],['Selene setapinnis','Atlantic Moonfish'],['Selene vomer','Lookdown'],['Semirossia tenera','Lesser Shining Bobtail'],['Sepiolidae','Bobtail Uncl'],['Seriola dumerili','Greater Amberjack'],['Seriola zonata','Banded Rudderfish'],['Simenchelys parasitica','Snubnose Eel'],['Sphoeroides maculatus','Northern Puffer'],['Sphyraena','Barracuda Uncl'],['Spirontocaris lilljeborgii','Friendly Blade Shrimp'],['Spirontocaris phippsii','Punctate Blade Shrimp'],['Spirontocaris spinus','Parrot Shrimp'],['Spisula solidissima','Atlantic Surfclam'],['Squalus acanthias','Spiny Dogfish'],['Stenotomus chrysops','Scup'],['Stephanolepis hispida','Planehead Filefish'],['Sternoptychidae','Hatchetfish Uncl'],['Stoloteuthis leucoptera','Shield Bobtail'],['Stomatopoda','Mantis Shrimp Uncl'],['Stomias boa','Boa Dragonfish'],['Stromateidae','Butterfish Uncl'],['Strongylocentrotus droebachiensis','Green Sea Urchin'],['Symphurus','Tonguefish Uncl'],['Symphurus civitatium','Offshore Tonguefish'],['Symphurus diomedeanus','Spottedfin Tonguefish'],['Symphurus plagiusa','Blackcheek Tonguefish'],['Synagrops bellus','Blackmouth Bass'],['Syngnathus fuscus','Northern Pipefish'],['Synodontidae','Lizardfish Uncl'],['Tautoga onitis','Tautog'],['Tautogolabrus adspersus','Cunner'],['Torpedo nobiliana','Atlantic Torpedo'],['Trachurus lathami','Rough Scad'],['Trichiurus lepturus','Atlantic Cutlassfish'],['Triglidae','Searobin Uncl'],['Triglops murrayi','Moustache Sculpin'],['Ulvaria subbifurcata','Radiated Shanny'],['Unclassified fish','fish Unclassified'],['Unknown','Unknown'],['Urophycis','Ling Uncl'],['Urophycis chuss','Red Hake'],['Urophycis regia','Spotted Hake'],['Urophycis tenuis','White Hake'],['Water haul','water haul'],['Zenopsis conchifera','Buckler Dory'],['Zoarces americanus','Ocean Pout'],['Zoarcidae','Eelpout Uncl']], {choices: 1000, emptyClass: 'empty', partialSearch: true, tokens: [','], selector: GmbisAutocompleter.scientificnameSelector});
	GmbisAutocompleter.acRegion = new Autocompleter.Dropdown('physioregion', 'physioregionList', ['Bay of Fundy','Browns Bank','Central Gulf of Maine','Continental Slope','Eastern Coastal Shelf','Georges Bank','Georges Basin','Great South Channel','Jordan Basin','Northern Coastal Shelf','Scotian Shelf','Southern Coastal Shelf','Western New England Seamount','Wilkinson Basin'], {choices: 100, emptyClass: 'empty', partialSearch: true, tokens: [',']});
	var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
	GmbisAutocompleter.acStartMonth = [new Autocompleter.Dropdown('startmonth_0', 'startmonthList_0', months, {choices: 12, emptyClass: 'empty', partialSearch: true})];
	GmbisAutocompleter.acEndMonth = [new Autocompleter.Dropdown('endmonth_0', 'endmonthList_0', months, {choices: 12, emptyClass: 'empty', partialSearch: true})];
	var years = ['1963','1964','1965','1966','1967','1968','1969','1970','1971','1972','1973','1974','1975','1976','1977','1978','1979','1980','1981','1982','1983','1984','1985','1986','1987','1988','1989','1990','1991','1992','1993','1994','1995','1996','1997','1998','1999','2000','2001','2002','2003','2004','2005','2006'];
	GmbisAutocompleter.acStartYear = [new Autocompleter.Dropdown('startyear_0', 'startyearList_0', years, {choices: 200, emptyClass: 'empty'})];
	GmbisAutocompleter.acEndYear = [new Autocompleter.Dropdown('endyear_0', 'endyearList_0', years, {choices: 200, emptyClass: 'empty'})];

	Event.observe(window, 'resize', positionResultsTable);
}

function positionResultsTable() {
	htmlTableContainer = $('QueryResultContainer');
	
	if (htmlTableContainer) {
		var tableWidth = htmlTableContainer.getWidth();
		var bodyWidth = $(document.body).getWidth();
	
		if (tableWidth != 0 && bodyWidth != 0 && tableWidth < bodyWidth) {
			Element.setStyle(htmlTableContainer, {
				marginLeft: Math.round((bodyWidth - tableWidth) / 2)
			});
		}
	}
}

function doSearch() {
	StatusBox.showSpinner();
	Response.starttime = new Date();
	Response.query = new Query.Basic(Query.Format.TEXT, Query.Fieldset.VIEW_TEXT);
	Query.send(Response.query, '/gmbis/data.php', Response.showData, Response.showError);
}

function doCriteria() {
	expandtab('queryTab');
}

function doClear() {
	GmbisAutoCompleter.acCommonName.showEmptyText(null, true);
	GmbisAutoCompleter.acScientificName.showEmptyText(null, true);
	GmbisAutoCompleter.acRegion.showEmptyText(null, true);
	GmbisAutoCompleter.acStartMonth.showEmptyText(null, true);
	GmbisAutoCompleter.acEndMonth.showEmptyText(null, true);
	GmbisAutoCompleter.acStartYear.showEmptyText(null, true);
	GmbisAutoCompleter.acEndYear.showEmptyText(null, true);
}

function addTab(ulid) {
	var tablist = document.getElementById(ulid);
	var tablistitems = tablist.getElementsByTagName('li');
	var template = tablistitems[0];
	var newTab = template.cloneNode(true);
	var tabnumber = tablistitems.length + 1;

	newTab.removeAttribute('class');
	newLink = newTab.getElementsByTagName('a')[0]
	newLink.id = 'tab' + tabnumber;
	newLink.setAttribute('rel', 'tabQuery');
	newLink.innerHTML = 'Search ' + tabnumber;
	tablist.appendChild(newTab);
	
	expandtab(newLink.id);
	initializetabcontent('gmbistab');
}

function toggleDataDesc(sender) {
	var details = sender.next('div');
	if (details) {
		if (details.visible()) {
			details.hide();
			sender.innerHTML = "more &raquo;";
		} else {
			details.show();
			sender.innerHTML = "&laquo; less";
		}
	}
}

var StatusBox = {
	showSpinner: function() {
		$(document.body).setStyle({cursor: 'wait'});
		var loadingDataMsg = $('loadingDataMsg');
		Modalbox.show($('errorContainer'), {title: '', height: 175, verticalCenterWithin: $('errorContainer').up() });
		loadingDataMsg.setStyle({top: Math.round((175 - loadingDataMsg.getHeight()) / 2)});
		Modalbox.deactivate();
	},
	
	showErrorMsg: function() {
		$(document.body).setStyle({cursor: 'default'});
		$('loadingDataMsg').hide();
		var genericErrorMsg = $('genericErrorMsg');
		genericErrorMsg.show();
		genericErrorMsg.setStyle({top: Math.round((175 - genericErrorMsg.getHeight()) / 2)});
		Modalbox.activate();
		Modalbox.show($('errorContainer'), { title: 'Could not retrieve data...', height: 175, afterHide: _revertToSpinner, verticalCenterWithin: $('errorContainer').up() });
	},
	
	hide: function() {
		$(document.body).setStyle({cursor: 'default'});
		Modalbox.hide();
	},
	
	_revertToSpinner: function() {
		$('loadingDataMsg').show();
		$('genericErrorMsg').hide();
	}
}

var Response = {
	showData: function(transport) {
		if (!transport.responseXML || !transport.responseXML.getElementsByTagName("gmbisresponse") 
				|| transport.responseXML.getElementsByTagName("gmbisresponse").length == 0) {
			Response.showError();
			return;
		}
	
		StatusBox.hide();

		//document.getElementById('StatusBox').className = 'generic_hide';
		var mapPath = transport.responseXML.getElementsByTagName('img')[0].getAttribute('src');
		$('map').setAttribute('src', mapPath);
		$('mapDownloadLink').setAttribute('href', mapPath);
		var htmlTableContainer = $('QueryResultContainer');
		var resultTable = htmlTableContainer.down();
		
		if (resultTable) {
			htmlTableContainer.removeChild(resultTable);
		}
		
		var recordCount = transport.responseXML.getElementsByTagName('rowcount')[0].textContent;

		if (recordCount > 0) {
			switch (Response.query.format) {
				case Query.Format.TEXT:
					resultTable = transport.responseXML.getElementsByTagName('data')[0].firstChild;
					var preTag = document.createElement('pre');
					preTag.appendChild(document.createTextNode(resultTable.data));
					htmlTableContainer.appendChild(preTag);
					break;
				case Query.Format.HTML:
					resultTable = transport.responseXML.getElementsByTagName('data')[0].firstChild;
                    htmlTableContainer.innerHTML = resultTable.data;
					//xmlToXHTML(resultTable, htmlTableContainer);
					break;
			}
			
			var rowLimitElementCollection = transport.responseXML.getElementsByTagName('rowlimit');

			if (rowLimitElementCollection.length > 0) {
				$('recordCountMessage').hide();
				$('maxLimitMessage').show();
				$('recordLimit').innerHTML = rowLimitElementCollection[0].textContent;
				$('recordsDisplayed').innerHTML = rowLimitElementCollection[0].textContent;
			} else {
				$('maxLimitMessage').hide();
				$('recordCountMessage').removeClassName('noResults');
				$('recordCountMessage').show();
				$('recordCount').innerHTML = recordCount;
			}

			positionResultsTable();

			$(htmlTableContainer).show();
			$('map').show();
			$($('downloadTab').parentNode).show();
		} else {
			$('maxLimitMessage').hide();
			$('recordCountMessage').addClassName('noResults');
			$('recordCountMessage').show();
			$('recordCount').innerHTML = 'no';
			$(htmlTableContainer).hide();
			$('map').hide();
		}

		Response.endtime = new Date();
		var responseSeconds = (Response.endtime.getTime() - Response.starttime.getTime()) / 1000;
		//$('responseTime').innerHTML = responseSeconds;
		
		$($('viewTab').parentNode).show();
		expandtab('viewTab');
	},
	
	showError: function(transport) {
		StatusBox.showErrorMsg();
	}
}

var TimeRange = {
	add: function() {
		var rangeID = +this.id.replace('addTimeRange_', '');
		var rangeRow = $('timeRanges').rows[rangeID];
		var newRangeRow = rangeRow.cloneNode(true);
		renameElements(newRangeRow, rangeID);
	},
	
	renameElements: function(newRangeRow, lastRangeID) {
		
	}
}

var GmbisAutocompleter = {
	commonnameSelector: function(instance, getAllChoices) {
		// {0} is the common name with the most general term first, and the least general terms followed after a comma
		//     ('Lobster, American'). This is the text that is sorted and is used to autocomplete from.
		// {1} is the canonical common name ('American Lobster'). This is the text inserted into the text box. It is
		//     not displayed in the dropdown list.
		// {2} is the scientific name. It is displayed italicized and in parentheses after the common name in the
		//     dropdown list.
		
		// Giving a span element a classname of 'informal' means that the text it encapsulates is not inserted
		// into the text box.
		var elementFormat = '<span style="display: none;">{1}</span><span class="informal">{0}</span><span class="informal"> (<i>{2}</i>)</span>'
		return instance.arraySelector(instance, getAllChoices, elementFormat);
	},
	
	scientificnameSelector: function(instance, getAllChoices) {
		// {0} is the scientific name. It is displayed italicized. This is the text that is sorted and is used to autocomplete from.
		// {1} is the canonical common name ('American Lobster'). It is displayed parentheses after the scientific name in
		//     the dropdown list.
		
		// Giving a span element a classname of 'informal' means that the text it encapsulates is not inserted
		// into the text box.
		var elementFormat = '<span><i>{0}</i></span><span class="informal"> ({1})</span>'
		return instance.arraySelector(instance, getAllChoices, elementFormat);
	}
}

Autocompleter.Dropdown = Class.create();

// These can be thought of as the "instance" methods of Autocompleter.Dropdown
Autocompleter.Dropdown.prototype = Object.extend(new Autocompleter.Base(), {
	initialize: function(element, update, array, options) {
		this.baseInitialize(element, update, options);
		this.options.array = array;
		this.addDropdownButton();
		this.showEmptyText(null, false);
		this.element.observe('blur', this.showEmptyText.bind(this));
		this.element.observe('focus', this.hideEmptyText.bind(this));
	},

	// Set default options, then override with an user-defined options.
	setOptions: function(options) {
		this.options = Object.extend({
			choices: 10,
			partialSearch: true,
			partialChars: 2,
			ignoreCase: true,
			fullSearch: false,
			selector: this.arraySelector,
			buttonClass: 'dropbutton',
			buttonHoverClass: 'dropbuttonHover'
		}, options || {});
	},

	addDropdownButton: function() {
		var dropButton = $(document.createElement('input'));
		dropButton.type = 'text';
		dropButton.setAttribute('readonly', 'true');
		dropButton.value = '';
		dropButton.className = this.options.buttonClass;
		dropButton.setStyle({ float: 'left' });
		
		dropButton.observe('mouseover', this.onDropButtonMouseOver.bindAsEventListener(this));
		dropButton.observe('mouseout', this.onDropButtonMouseOut.bindAsEventListener(this));
		dropButton.observe('click', this.onDropButtonClick.bindAsEventListener(this));
		
		var container = $(document.createElement('span'));

		var nextElement = this.element.next();
		if (nextElement) {
			this.element.parentNode.insertBefore(container, nextElement);
		} else {
			this.element.parentNode.appendChild(container);
		}
		
		container.appendChild(this.element);
		container.appendChild(dropButton);

		var containerWidth = this.element.getWidth() + dropButton.getWidth();
		container.setStyle({ width: containerWidth + 'px', position: 'relative', float: 'left' });
		this.element.setStyle({ float: 'left' });
	},
	
	onDropButtonClick: function() {
		if (this.active) {
			// needed to make click events working
			setTimeout(this.hide.bind(this), 250);
			this.active = false;
			this.hasFocus = false;
			this.showEmptyText(null, false);
		} else {
			this.hideEmptyText(null, false);
			this.isManualOpen = true;
			this.hasFocus = true;
			this.updateChoices(this.options.selector(this, true));
		}
	},
	
	onDropButtonMouseOver: function(event) {
		Event.element(event).className = this.options.buttonHoverClass;
		Event.stop(event);
	},
	
	onDropButtonMouseOut: function(event) {
		Event.element(event).className = this.options.buttonClass;
		Event.stop(event);
	},

	getUpdatedChoices: function() {
		this.updateChoices(this.options.selector(this));
	},

	// This method always assumes that the first element in a given instance.options.array element
	// is the search field.
	// PARAMETERS:
	//     instance       The instance of the Autocompleter.Local object that this select will
	//                    operate on.
	//     elementFormat  The HTML markup to use to format the list item. For now, see calling 
	//                    functions for examples or examine the code.
	arraySelector: function(instance, getAllChoices, elementFormat) {
		var ret       = []; // Beginning matches
		var partial   = []; // Inside matches
		var entry     = instance.getToken();
		var count     = 0;

		for (var i = 0; i < instance.options.array.length &&  
		ret.length < instance.options.choices; i++) {

		var dataItem = typeof(instance.options.array[i]) == 'string' ? [instance.options.array[i]] : instance.options.array[i].clone();
			
		if (getAllChoices) {
			var listItemHtml = elementFormat ? instance.parseFormatString(dataItem, elementFormat) : dataItem[0];
			ret.push("<li>" + listItemHtml + "</li>");
		} else {
			var searchText = dataItem[0];
			var foundPos = searchText.toLowerCase().indexOf(entry.toLowerCase())

			while (foundPos != -1) {
				if (foundPos == 0 && searchText.length != entry.length) {
				dataItem[0] = "<strong>" + searchText.substr(0, entry.length) + "</strong>" + searchText.substr(entry.length);
					
				var listItemHtml = elementFormat ? instance.parseFormatString(dataItem, elementFormat) : dataItem[0];
				ret.push("<li>" + listItemHtml + "</li>");
				break;
				} else if (entry.length >= instance.options.partialChars && 
				instance.options.partialSearch && foundPos != -1) {
					if (instance.options.fullSearch || /\s/.test(searchText.substr(foundPos-1,1))) {
						dataItem[0] = searchText.substr(0, foundPos) + 
								"<strong>" +  searchText.substr(foundPos, entry.length) + "</strong>" + 
								searchText.substr(foundPos + entry.length)

						var listItemHtml = elementFormat ? instance.parseFormatString(dataItem, elementFormat) : dataItem[0];
						partial.push("<li>" + listItemHtml + "</li>");
						break;
					}
				}

				foundPos = instance.options.ignoreCase ? 
				searchText.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) : 
				searchText.indexOf(entry, foundPos + 1);
			}
		}
		}
		if (partial.length)
		ret = ret.concat(partial.slice(0, instance.options.choices - ret.length))
		return "<ul>" + ret.join('') + "</ul>";
	},

	updateElement: function(selectedElement) {
		if (this.options.updateElement) {
			this.options.updateElement(selectedElement);
			return;
		}
		var value = '';
		if (this.options.select) {
			var nodes = document.getElementsByClassName(this.options.select, selectedElement) || [];
			if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
		} else
			value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
		
		var lastTokenPos = this.findLastToken();

		if (this.isManualOpen && this.element.value != '' && lastTokenPos < trim(this.element.value).length -1 && this.options.tokens.length > 0) {
			this.element.value = trim(this.element.value) + this.options.tokens[0] + ' ';
			lastTokenPos = this.element.value.length - 2;
		}
				
		if (lastTokenPos != -1) {
			var newValue = this.element.value.substr(0, lastTokenPos + 1);
			var whitespace = this.element.value.substr(lastTokenPos + 1).match(/^\s+/);
			if (whitespace)
				newValue += whitespace[0];
			this.element.value = newValue + value;
		} else {
			this.element.value = value;
		}
		this.element.focus();
		
		if (this.options.afterUpdateElement)
			this.options.afterUpdateElement(this.element, selectedElement);
		
		this.isManualOpen = false;
		this.hideEmptyText(null, true);
	},
	
	parseFormatString: function(dataItem, elementFormat) {
		if (dataItem[0]) elementFormat = elementFormat.replace(/\{0\}/g, dataItem[0]);
		if (dataItem[1]) elementFormat = elementFormat.replace(/\{1\}/g, dataItem[1]);
		if (dataItem[2]) elementFormat = elementFormat.replace(/\{2\}/g, dataItem[2]);
		
		return elementFormat;
	},
	
	showEmptyText_old: function(event, ignoreRelated) {
		if (! (this.element.readAttribute('emptytext') || this.options.emptyClass))
			return;
		
		var targetInputs;
		
		if (ignoreRelated) {
			targetInputs = [this.element];
		} else {
			targetInputs = this.getRelatedInputs();
			targetInputs.push(this.element);
		}
		
		var empty = this.element.value == '' || this.element.hasClassName(this.options.emptyClass);
		for (var i = 0; i < targetInputs.length; i++) {
			empty = empty && targetInputs[i].hasClassName(this.options.emptyClass);
			if (!empty) break;
		}
		
		if (empty) {  // if all of the target inputs are empty, display the emptytext and add the emptyclass
			for (var i=0; i < targetInputs.length; i++) {
				var emptyText = targetInputs[i].readAttribute('emptytext');
				targetInputs[i].value = emptyText ? emptyText : '';
				targetInputs[i].addClassName(this.options.emptyClass);
			}
		}
	},
	
	// We know coming into this function that this.element.hasClassName(this.options.emptyClass) == false
	showEmptyText: function(event, ignoreRelated) {
		if (!this.element.readAttribute('emptytext') || !this.options.emptyClass)
			return;
		
		var inputsToChange;
		
		if (ignoreRelated) {
			inputsToChange = [this.element];
			inputsToCheck = [];
		} else {
			inputsToChange = this.getRelatedInputs('rel');
			inputsToCheck  = this.getRelatedInputs('rev');
			inputsToChange.push(this.element);
			inputsToCheck.push(this.element);
		}
		
		// Find out if any elements in inputsToCheck have data entered.
		var empty = true;
		for (var i = 0; i < inputsToCheck.length && empty; i++) {
			empty = inputsToCheck[i].value == '' || inputsToCheck[i].hasClassName(this.options.emptyClass);
		}
		
		// If all of the inputs to check are empty, display the emptytext and add the emptyclass for the
		// elements in inputsToChange.
		if (empty) {
			for (var i=0; i < inputsToChange.length; i++) {
				if (inputsToChange[i].value == '') {
					var emptyText = inputsToChange[i].readAttribute('emptytext');
					inputsToChange[i].value = emptyText ? emptyText : '';
					inputsToChange[i].addClassName(this.options.emptyClass);
				}
			}
		}
	},

	hideEmptyText: function(event, ignoreRelated) {
		if (!this.element.readAttribute('emptytext') || !this.options.emptyClass)
			return;
		
		var inputsToChange;
		
		if (ignoreRelated) {
			inputsToChange = [this.element];
		} else {
			inputsToChange = this.getRelatedInputs('rel');
			inputsToChange.push(this.element);
		}
		
		for (var i=0; i < inputsToChange.length; i++) {
			if (inputsToChange[i].hasClassName(this.options.emptyClass)) {
				inputsToChange[i].value = '';
				inputsToChange[i].removeClassName(this.options.emptyClass);
			}
		}
	},
	
	hideEmptyText_old: function(event, ignoreRelated) {
		if (! (this.element.readAttribute('emptytext') || this.options.emptyClass))
			return;
		
		var targetInputs;
		
		if (ignoreRelated) {
			targetInputs = [this.element];
		} else {
			targetInputs = this.getRelatedInputs();
			targetInputs.push(this.element);
		}
		
		if (this.element.hasClassName(this.options.emptyClass)) {
			for (var i=0; i < targetInputs.length; i++) {
				targetInputs[i].value = '';
				targetInputs[i].removeClassName(this.options.emptyClass);
			}
		}
	},

	/*
	  Returns an array of the elements with the ids listed in the specified attribute of
	  this object's text input element. The specified attributed should be 'rel' or 'rev'.
	*/
	getRelatedInputs: function(tag) {
		var relatedInputList = this.element.readAttribute(tag);
		var relatedInputs = relatedInputList ? relatedInputList.split(' ') : [];
		relatedInputs = $(relatedInputs).collect(function(elementID){return $(elementID)});		
		return relatedInputs;
	}	
});

function trim(text) {
	return text.replace(/^\s+|\s+$/g, '');
}


function sendTestData() {
	var myQuery = new Query.Basic('tabQuery');
	Query.send(myQuery, '/gmbis/testReceive.php', function(transport){
		alert(transport.responseText);
	});
}


/*
	// Performs a binary search on the array to minimize delay.
	// UNCOMPLETED
	// CAVEAT: Will only match the begining of a string, not the beginning of word boundaries
	//         unless substantial modifications are made
	binarySelector: function(instance, italicizeElem1) {
		var ret       = []; // Beginning matches
		var partial   = []; // Inside matches
		var entry     = instance.getToken();
		var count     = 0;
		
		var left = -1;
		var right = instance.options.array.length;
		var mid;
		
		while(right - left > 1) {
			mid = (left + right) >>> 1;  // '>>>' operator does an unsigned right bit shift
			
			if (instance.options.array[mid][0] < entry)
				left = mid;
			else
				right = mid;
		}
		
		if (instance.options.partialSearch && this[right].slice(0,text.length) != text)
			return -(right + 1);
		else if (this[right] != text)
			return -(right + 1);
			
		return right[0];
	}
*/

// mid calculation from
// http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html
/*
Array.prototype.binarySearch = function(item, allowPartialMatch) {
  var low  = 0;
  var high = this.length - 1,
  var mid;

  while(low <= high) {
	mid = (left + right) >>> 1;   // '>>>' operator does an unsigned right bit shift
	if (this[mid] < item)
	  low = mid - 1 ;
	else if (this[mid] > item)
	  high = mid - 1;
	else
	  return mid;
  }
  return -(low + 1);
}
*/