var offmode = "";

function off_menu(mod,svc,host,utype) {

  var cutype = utype;

  if (mod.indexOf("-") == 0) {
    mod = mod.substr(1);
    offmode = offmode.replace(mod,"");
  } else {
    if (offmode.indexOf(mod) == -1) {
      offmode = offmode + mod;
    }
  }

  if (utype == 'academic') {        // user clicked on Academic page link
     utype = top.orig_usertype;     //   restore the original user type (standard, LIS, etc.)
  }

  if (top.SessionID) {
     top.SessionID = '';
  }

  MF = top.MenuFrame.document;

  MF.open('text/html');
  MF.write('<HTML><BODY BGCOLOR="#000066" LINK="white" VLINK="white">');
  MF.write(top.get_node_val('version'));

  MF.write('<img src="/graphics/english/n_top.gif" BORDER="0" ALIGN=top><BR>')

  if (offmode.indexOf("news") != -1) {
     MF.write(top.menuEntry("#", 'n2_new2a', 'News', '', 'top.off_menu(\'-news\', \''+svc+'\',\'\',\'\');return false;'));
     MF.write(top.menuEntry(top.get_node_val('whatsnew'), 'mid_l2_whatsnew', 'News about STN on the Web', 'RFrame'));
     MF.write(top.menuEntry(top.get_node_val('n2_new2d'), 'mid_l2_STNews', 'News about STN', 'RFrame'));
  } else {
     MF.write(top.menuEntry("#", 'n2_new1', 'News', '', 'top.off_menu(\'news\', \''+svc+'\',\'\',\'\');return false;'));
  }

  if (offmode.indexOf("help") != -1) {
     MF.write(top.menuEntry("#", 'n2_hlp2a', 'Help', '', 'top.off_menu(\'-help\', \''+svc+'\',\'\',\'\');return false;'));
     MF.write(top.menuEntry(top.get_node_val('n1_about'), 'mid_l2_About', 'What is STN on the Web?', 'RFrame'));
     MF.write(top.menuEntry(top.get_node_val('n2_product1'), 'n1_cus2e', 'STN on the Web Documentation', 'RFrame'));
     MF.write(top.menuEntry(top.get_node_val('faq'), 'nl2_faq', 'STN on the Web Frequently Asked Questions', 'RFrame'));
     MF.write(top.menuEntry(top.get_node_val('n1_cus2f'), 'n1_cus2f', 'STN Training & Documentation', 'RFrame'));
     MF.write(top.menuEntry(top.get_node_val('n1_cus2j'), 'n1_cus2j', 'STN Hours of Operations', 'RFrame'));
     MF.write(top.menuEntry(top.get_node_val('n2_hlp2b'), 'mid_l2_STNcommands', 'Mastering STN commands', 'Help'));
     MF.write(top.menuEntry(top.get_node_val('n2_hlp2c'), 'mid_l2_dbinfo', 'STN Database Summary Sheets', 'RFrame'));
     MF.write(top.menuEntry(top.get_node_val('n1_cus2d'), 'n1_cus2d', 'STN Database Clusters', 'RFrame'));
     MF.write(top.menuEntry(top.get_node_val('n1_keepnshare'), 'n1_keepnshare', 'Archiving and Distribution of search results', 'RFrame'));
     MF.write(top.menuEntry(top.get_node_val('support'), 'n1_cus2k', 'Help desk and agents', 'RFrame'));
  } else {
     MF.write(top.menuEntry("#", 'n2_help1', 'Help', '', 'top.off_menu(\'help\', \''+svc+'\',\'\',\'\');return false;'));
  }


  MF.write(top.menuEntry(top.get_node_val('n1_struc'), 'n1_struc', 'Get structure editor plug-in', 'RFrame'));
  MF.write(top.menuEntry(top.get_node_val('n1_getseq'), 'n1_getseq', 'Get sequence plug-in', 'RFrame'));

  // Standard Login menu item
  if  (top.get_node_val('secure') == 'F') {    // force secure session
     if   (host != '') {
	MF.write(top.menuEntry('https://'+host+'/?SECURE=1&SERVICE=STN&USERTYPE='+utype, 'n1_login', 'Standard login page', '_top'));
     } else {
	MF.write(top.menuEntry('https://'+top.location.host+'/?SECURE=1&SERVICE=STN&USERTYPE='+utype, 'n1_login', 'Standard login page', '_top'));
     }
  } else {                                     // do not force secure session
     if   (host != '') {
	MF.write(top.menuEntry('http://'+host+'/?SECURE='+top.secure+'&SERVICE=STN&USERTYPE='+utype, 'n1_login', 'Standard login page', '_top'));
     } else {
	MF.write(top.menuEntry('http://'+top.location.host+'/?SECURE='+top.secure+'&SERVICE=STN&USERTYPE='+utype, 'n1_login', 'Standard login page', '_top'));
     }
  }

  if   (utype != 'LIS') {

     // Academic Login menu item

     if (top.get_node_val('academic') == 'Y') {
	MF.write(top.menuEntry('/html/english/index.html?SECURE='+top.secure+'&USERTYPE=academic&OUSERTYPE='+utype+' TARGET="_top"', 'n1_acade', 'Academic login page'));
     }

  }

  if  (top.get_node_val('secure') != 'F') {    // do not force secure session

     // Secure/Nonsecure Session menu item

     if   ((top.get_node_val('secure') == 'S' && top.secure == '0') ||   // default is secure, but currently non-secure
	   (top.get_node_val('secure') == 'N' && top.secure != '1')      // default is non-secure, and currently non-secure
	  ) {

	// currently non-secure - show Secure Session menu item

	if   (host != '') {
	   MF.write(top.menuEntry('https://'+host+'/?SECURE=1&SERVICE=STN&USERTYPE='+cutype+'&OUSERTYPE='+utype+' TARGET="_top"', 'n1_secur', 'Secure session'));
	} else {
	   MF.write(top.menuEntry('https://'+top.location.host+'/?SECURE=1&SERVICE=STN&USERTYPE='+cutype+'&OUSERTYPE='+utype+' TARGET="_top"', 'n1_secur', 'Secure session'));
	}

     } else {

	// currently secure - show Nonsecure Session menu item

	if   (host != '') {
	   MF.write(top.menuEntry('http://'+host+'/?SECURE=0&SERVICE=STN&USERTYPE='+cutype+'&OUSERTYPE='+utype+' TARGET="_top"', 'n1_nonsecure', 'Non-secure session'));
	} else {
	   MF.write(top.menuEntry('http://'+top.location.host+'/?SECURE=0&SERVICE=STN&USERTYPE='+cutype+'&OUSERTYPE='+utype+' TARGET="_top"', 'n1_nonsecure', 'Non-secure session'));
	}

     }
  }

  MF.write(top.menuEntry(top.get_node_val('mailto'), 'n1_feedb', 'Send feedback to STN'));

  MF.write('</BODY></HTML>');
  MF.close();
}


function get_node_val(key) {
   return (NODE_var[key] ? NODE_var[key] : '');
}

function menuEntry(reference, image, alt, target, onclick) {
  entry = '';
  if (reference) {
//jrb  allow override of target if reference contains TARGET=  ???
     if (target) {
	target = ' TARGET="' + target + '"';
     } else {
	target='';
     }
     if (onclick) {
	onclick = ' onClick="' + onclick + '"';
     } else {
	onclick='';
     }

     entry = '<A HREF=' + reference + target + onclick +'>' + '<IMG SRC="/graphics/english/' + image +'.gif" BORDER=0 ALIGN=top TITLE="' + alt +'"></A><BR>\n';
  }
  return entry;
}


function isIE() {
  if (navigator.appVersion.indexOf('MSIE') == -1) {
    return false;
  }
  return true;
}

function isMac() {
  if (navigator.appVersion.indexOf('Macintosh') == -1) {
    return false;
  }
  return true;
}

function isUnix() {
  if (navigator.appVersion.indexOf('X11') == -1) {
    return false;
  }
  return true;
}

