<!------- hide the script from old browsers (key JavaScripts)
// functions for the dichotomous key activities
// written by Dan Jacobs, Maryland Sea Grant
var key_type, gif, gwidth,ght,image,step,answer,question,ok_url;

// answers

function insect(which) {
  key_type = "insect";
  if (which == "Insect #1") { answer = "housefly"; }
  else if (which == "Insect #2") { answer = "ladybug"; }
  else if (which == "Insect #3") { answer = "grasshopper"; }
  else if (which == "Insect #4") { answer = "dragonfly"; }
  else { alert("Invalid selection. Try again!"); return; }
  step = "1";
  image = answer + ".gif";
  if (answer == "grasshopper") { image = "ghopper.gif"; }
  if (answer == "dragonfly") { image = "dragnfly.gif"; }
  gwidth=100; ght=75;
  id_it();
  return;
}

function cb(which) {
  key_type = "Chesapeake Bay organism";
  if (which == "#1") { answer = "Isopod"; ok_url = "isopod"; }
  else if (which == "#2") { answer = "White Anemone"; ok_url = "anemone"; }
  else if (which == "#3") { answer = "Atlantic Ribbed Mussel"; ok_url = "armussel"}
  else if (which == "#4") { answer = "Bryozoan"; ok_url = "bryozoan"; }
  else if (which == "#5") { answer = "Limpet Nudibranch"; ok_url = "nudibrch"; }
  else if (which == "#6") { answer = "Barnacle"; ok_url = "barnacle"; }
  else if (which == "#7") { answer = "Whip Mud Worm"; ok_url = "wmworm";}
  else if (which == "#8") { answer = "Entoprocts"; ok_url = "entoproc";}
  else { alert("Invalid selection. Try again!"); return; }
  step = "1";
  image = ok_url + ".jpg";
  gwidth=500; ght=348;
  id_it();
  return;
}

// start up functions

function check_browser(what) {
  // make sure the browser is one this works with this
  // browswer_name and browser_version come from edunit.js
  msg = "This interactive key works with ";
  msg += "Netscape and Microsoft Internet Explorer version 4.0 or later.";
  //msg += "\n\n\n";
  msg += "  ";
  msg += "It may not work with " + browser_name + " " + browser_version + ".";
  msg += "\n\n\n";
  msg += "Would you like to try the interactive key?\n\n\n";

  answer = "true";
 
  if (!okMouse) {  // okMouse - version 4 or greater
    answer = confirm(msg); 
  }
  if (answer) { start_it(what); }
}

function start_it(what) {
  // menubar = yes to allow printing
  winopt = "toolbar=no,location=no,directories=no,menubar=yes,resizable=yes";
  if (what  == "insect") { 
    winopt = "width=550,height=330," + winopt; // insect window
    url = "ikey.htm";
  }
  else { url = "cbkey.htm"; }
  myWin=window.open(url,"dummy",winopt);
}

function start_it_old(what) { 
  s1 = "</SCR"; s2 = "IPT>"; // fixes MIE bug
  winopt = "toolbar=no,location=no,directories=no,menubar=no,resizable=no";
  str = "<HTML>\n<HEAD>\n<TITLE>What is this " +what+ "?</TITLE>\n";
  str += "<SCRIPT SRC='key_it.js'>\n"+s1+s2+"\n</HEAD>\n";
  if (what  == "insect") { 
    winopt = "width=500,height=250," + winopt; // insect window
    str += "<FRAMESET ROWS='70%,*'>\n ";
    page = "\"ikey.htm\"";
  }
  else {
    str += "<FRAMESET COLS='85%,*'>\n ";
    page = "\"cbkey.htm\"";
  }
  str += "<FRAME noresize SRC='blank.htm' name='keyit'>\n";
  str += "<FRAME scrolling=no noresize SRC="+page+" name='buttons'>\n";
  str += "</FRAMESET>\n</HTML>\n";
  myWin=window.open("", "dummy",winopt);
  myWin.document.write(str);
}

// key functions

function oops() {
  alert("\n\nAre you sure?\n\n\nLook at the " + key_type + " again.\n");
}

function id_it() {
  gif = "<IMG SRC=\"" + image +"\" ALT=\"[mystery "+key_type+"]\" ";
  gif += "HEIGHT=" + ght + "  WIDTH=" + gwidth+">";
  stitle = "What is this " + key_type + "?";
  html_top = "<HTML>\n<HEAD>\n<TITLE>" + stitle + "</TITLE>\n</HEAD>\n";
  //html_top += "<BODY BACKGROUND=\"key_back.gif\">";
  html_top += "<BODY BGCOLOR=\"#FFFFFF\" LINK=\"#663300\" ";
  html_top += "VLINK=\"#CC6600\" ALINK=\"#CC6600\">\n";

  newWin=open("","keyit");
  //newWin.location.href = "blank.htm";
  //newWin.document.close();
  //newWin.document.clear();
  //newWin.document.open();
  if (key_type == "insect") { next_table = insect_table(); }
  else { next_table = cb_table(); }
  html =html_top + start_table() + next_table + end_table();
  newWin.document.write(html);
  newWin.document.close();
  return
}

function do_it() {
  step = question;
  id_it();
}

function start_table() {
  s = "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=4 WIDTH=100%>\n";
  s += "<TR><TD ALIGN=TOP VALIGN=LEFT>\n";
  s += "<H2 ALIGN=CENTER>What is this "+ key_type + "?</H2>\n";
  s += "</TD></TR></TABLE>\n";
  return s
}

function end_table() {
  s = "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 ";
  s += "WIDTH=100%>\n";
  s += "<TR><TD ALIGN=RIGHT VALIGN=TOP>\n";
  s += "<FORM NAME=\"CLOSE\">\n";
  s +=  "<INPUT type=\"button\" value=\"Quit\" ";
  s +=  "onClick=\"top.window.close();\">\n";
  s += "</FORM>\n";
  s += "</TD></TR></TABLE>\n";
  s += "</BODY>\n</HTML>\n";
  return s
}

function insect_table() {
  s = "<CENTER>\n";
  s += "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=4>\n";
  s += "<TR>\n<TD ALIGN=CENTER VALIGN=MIDDLE>\n";
  s += "<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0>\n";
  s += "<TR><TD ALIGN=LEFT VALIGN=TOP>" + gif + "<BR>\n";
  s += "</TD></TR></TABLE>\n";
  s += "</TD><TD ALIGN=LEFT VALIGN=MIDDLE>\n";
  s += "<FORM>\n";
  if (step == "1") { 
    s += "<INPUT TYPE=\"Button\" VALUE=\"a\" ";
    if (answer == "housefly" || answer == "dragonfly") 
      { s += "onClick=\"top.oops()\">"; }
    else { question = "2"; s += "onClick=\"top.do_it()\">"; }
    s += "&nbsp;<B>wings covered by exoskeleton</B><BR>\n";
    s +="&nbsp;<BR>\n";
    s += "<INPUT TYPE=\"Button\" VALUE=\"b\" ";
    if (answer == "ladybug" || answer == "grasshopper") 
       { s += "onClick=\"top.oops()\">"; }
    else { question = "3"; s += "onClick=\"top.do_it()\">"; }
    s += "&nbsp;<B>wings not covered by exoskeleton</B><BR>\n";     
  }
  else if (step == "2") {
    question = "yes";
    s += "<INPUT TYPE=\"Button\" VALUE=\"a\" ";
    if (answer == "grasshopper") { s += "onClick=\"top.oops()\">"; }
    else { s += "onClick=\"top.do_it()\">"; }
    s += "&nbsp;<B>body has a round shape</B><BR>";
    s +="&nbsp;<BR>\n";
    s += "<INPUT TYPE=\"Button\" VALUE=\"b\" ";
    if (answer == "ladybug") { s += "onClick=\"top.oops()\">"; }
    else { s += "onClick=\"top.do_it()\">"; }
    s += "&nbsp;<B>body has an elongated shape</B><BR>";
  }
  else if (step == "3") { 
    question = "yes";
    s += "<INPUT TYPE=\"Button\" VALUE=\"a\" ";
    if (answer == "housefly") { s += "onClick=\"top.oops()\">"; }
    else { s += "onClick=\"top.do_it()\">"; }
    s += "&nbsp;<B>wings point out from the side of the body</B><BR>";
    s +="&nbsp;<BR>\n";
    s += "<INPUT TYPE=\"Button\" VALUE=\"b\" ";
    if (answer == "dragonfly") { s += "onClick=\"top.oops()\">"; }
    else { s += "onClick=\"top.do_it()\">"; }
    s += "&nbsp;<B>wings point to the posterior of the body</B><BR>";
  }
  else if (step == "yes") {
    ok_url = "http://ednhp.hartford.edu/WWW/cook/insectpages/" + answer + ".html";
    s += "<H3 ALIGN=CENTER>Congratulations!!!!</H3>";
    s += "<H4 ALIGN=CENTER>You successfully classified the " + answer +".";
    s += "</H4>Visit <A HREF=\""+ ok_url + "\">";
    s += "Miss Cook's First Grade Class</A> in Simsbury, CT, ";
    s += "to learn more about this insect ";
    s += "(remember to close the window ";
    s += "to return to <A HREF=\"blank.htm\" ";
    s += "onClick=\"top.window.close();return false\">";
    s += "Dichotomous Keys</A>).";
    s += "<BR><BR>";
  }
  else { s += "onClick=\"top.oops()\">"; }
  //if (step != "yes") { s += "</TD></TR></TABLE>"; }
  s += "</FORM>";
  s += "</TD></TR></TABLE>\n</CENTER>";
  return s
}

function cb_table() {
  s = "<CENTER>\n";
  s += "<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0>\n";
  s += "<TR><TD ALIGN=LEFT VALIGN=TOP>" + gif + "<BR>\n";
  s += "</TD></TR></TABLE>\n<BR>\n";
  s += "<FORM>\n";
  s += "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>\n";
  s += "<TR>\n<TD ALIGN=LEFT VALIGN=TOP>";
  if (step == "1") { 
    s += "<INPUT TYPE=\"Button\" VALUE=\"a\" ";
    if (answer == "Atlantic Ribbed Mussel" || answer == "Barnacle") 
      { question = "2"; s += "onClick=\"top.do_it()\">"; }
    else { s += "onClick=\"top.oops()\">"; }
    s += "&nbsp;<B>Has a shell</B><BR>\n";
    s += "</TD><TD ALIGN=LEFT VALIGN=TOP>\n";
    s += "&nbsp;&nbsp;&nbsp;<BR>\n";
    s += "</TD><TD ALIGN=LEFT VALIGN=TOP>\n";
    s += "<INPUT TYPE=\"Button\" VALUE=\"b\" ";
    if (answer == "Atlantic Ribbed Mussel" || answer == "Barnacle") 
       { s += "onClick=\"top.oops()\">"; }
    else { question = "3"; s += "onClick=\"top.do_it()\">"; }
    s += "&nbsp;<B>No shell</B><BR>\n";     
  }
  else if (step == "2") {
    question = "yes";
    s += "<INPUT TYPE=\"Button\" VALUE=\"a\" ";
    if (answer == "Atlantic Ribbed Mussel")  { s += "onClick=\"top.do_it()\">"; }
    else { s += "onClick=\"top.oops()\">"; }
    s += "&nbsp;<B>Mobile</B><BR>";
    s += "</TD><TD ALIGN=LEFT VALIGN=TOP>\n";
    s += "&nbsp;&nbsp;&nbsp;<BR>\n";
    s += "</TD><TD ALIGN=LEFT VALIGN=TOP>\n";
    s += "<INPUT TYPE=\"Button\" VALUE=\"b\" ";
    if (answer == "Barnacle")  { s += "onClick=\"top.do_it()\">"; }
    else { s += "onClick=\"top.oops()\">"; }
    s += "&nbsp;<B>Sessile</B><BR>";
  }
  else if (step == "3") { 
    question = "yes";
    s += "<INPUT TYPE=\"Button\" VALUE=\"a\" ";
    if (answer == "Bryozoan" || answer == "Entoprocts") 
      { question = "4"; s += "onClick=\"top.do_it()\">"; }
    else { s += "onClick=\"top.oops()\">"; }
    s += "&nbsp;<B>Lives as a colony</B><BR>";
    s += "</TD><TD ALIGN=LEFT VALIGN=TOP>\n";
    s += "&nbsp;&nbsp;&nbsp;<BR>\n";
    s += "</TD><TD ALIGN=LEFT VALIGN=TOP>\n";
    s += "<INPUT TYPE=\"Button\" VALUE=\"b\" ";
    if (answer == "Bryozoan" || answer == "Entoprocts") 
       { s += "onClick=\"top.oops()\">"; }
    else { question = "5"; s += "onClick=\"top.do_it()\">"; }
    s += "&nbsp;<B>Lives independently</B><BR>";
  }
  else if (step == "4") {
    question = "yes";
    s += "<INPUT TYPE=\"Button\" VALUE=\"a\" ";
    if (answer == "Bryozoan")  { s += "onClick=\"top.do_it()\">"; }
    else { s += "onClick=\"top.oops()\">"; }
    s += "&nbsp;<B>Individuals connected by compartments</B><BR>";
    s += "</TD><TD ALIGN=LEFT VALIGN=TOP>\n";
    s += "&nbsp;&nbsp;&nbsp;<BR>\n";
    s += "</TD><TD ALIGN=LEFT VALIGN=TOP>\n";
    s += "<INPUT TYPE=\"Button\" VALUE=\"b\" ";
    if (answer == "Entoprocts")  { s += "onClick=\"top.do_it()\">"; }
    else { s += "onClick=\"top.oops()\">"; }
    s += "&nbsp;<B>Individuals connected by stalks</B><BR>";
  }
  else if (step == "5") { 
    question = "yes";
    s += "<INPUT TYPE=\"Button\" VALUE=\"a\" ";
    if (answer == "White Anemone" || answer == "Whip Mud Worm") 
      { question = "6"; s += "onClick=\"top.do_it()\">"; }
    else { s += "onClick=\"top.oops()\">"; }
    s += "&nbsp;<B>Has tentacles</B><BR>";
    s += "</TD><TD ALIGN=LEFT VALIGN=TOP>\n";
    s += "&nbsp;&nbsp;&nbsp;<BR>\n";
    s += "</TD><TD ALIGN=LEFT VALIGN=TOP>\n";
    s += "<INPUT TYPE=\"Button\" VALUE=\"b\" ";
    if (answer == "White Anemone" || answer == "Whip Mud Worm") 
       { s += "onClick=\"top.oops()\">"; }
    else { question = "7"; s += "onClick=\"top.do_it()\">"; }
    s += "&nbsp;<B>No tentacles</B><BR>";
  }
  else if (step == "6") {
    question = "yes";
    s += "<INPUT TYPE=\"Button\" VALUE=\"a\" ";
    if (answer == "White Anemone")  { s += "onClick=\"top.do_it()\">"; }
    else { s += "onClick=\"top.oops()\">"; }
    s += "&nbsp;<B>Has more than 2 tentacles</B><BR>";
    s += "</TD><TD ALIGN=LEFT VALIGN=TOP>\n";
    s += "&nbsp;&nbsp;&nbsp;<BR>\n";
    s += "</TD><TD ALIGN=LEFT VALIGN=TOP>\n";
    s += "<INPUT TYPE=\"Button\" VALUE=\"b\" ";
    if (answer == "Whip Mud Worm")  { s += "onClick=\"top.do_it()\">"; }
    else { s += "onClick=\"top.oops()\">"; }
    s += "&nbsp;<B>Has 2 tentacles</B><BR>";
  }
  else if (step == "7") {
    question = "yes";
    s += "<INPUT TYPE=\"Button\" VALUE=\"a\" ";
    if (answer == "Isopod")  { s += "onClick=\"top.do_it()\">"; }
    else { s += "onClick=\"top.oops()\">"; }
    s += "&nbsp;<B>Segmented body</B><BR>";
    s += "</TD><TD ALIGN=LEFT VALIGN=TOP>\n";
    s += "&nbsp;&nbsp;&nbsp;<BR>\n";
    s += "</TD><TD ALIGN=LEFT VALIGN=TOP>\n";
    s += "<INPUT TYPE=\"Button\" VALUE=\"b\" ";
    if (answer == "Limpet Nudibranch")  { s += "onClick=\"top.do_it()\">"; }
    else { s += "onClick=\"top.oops()\">"; }
    s += "&nbsp;<B>Body not segmented</B><BR>";
  }
  else if (step == "yes") {
    ok_url = "index.htm#" + ok_url;
    s += "<H3 ALIGN=CENTER>Congratulations!!!!</H3>\n";
    s += "<H3>You successfully classified the " + answer +".</H3> ";
    s += "To learn more, return to <A HREF=\"+ok_url+\" ";
    s += "onClick=\"top.window.close();return false\">";
    s += "Dichotomous Keys</A>.</B>";
    s += "<BR><BR>";
  }
  else { s += "onClick=\"top.oops()\">"; }
  s += "</TD></TR></TABLE>\n";
  s += "</FORM>";
  s += "</CENTER>\n";
  return s
}

//close off comment to hide this script from old browsers----------->
