$(document).ready(function(){
      var tool;     //The selected tool
      var version;  //The selected tool version
      var lasttool; //The previously selected tool
      
      $('select#tool').selectmenu({
        style:'popup',
        // use select callback
        select: function(event, options) {
          tool = options.value;
          $('select#'+tool).val("none");  //This resets the version selectbox to "Select a version".  Otherwise the last version selected shows and the ".change(function(){..." does not fire.  
          if (tool == "cgs") { 
            $('select#'+tool).selectmenu({maxHeight: 150}).parent("fieldset").hide();       //Without this, the version selectbox won't show
            $('select#'+lasttool).selectmenu({maxHeight: 150}).parent("fieldset").hide();   //Hide the last tool version selected
            $('select#'+tool).parent("fieldset").show();  //This shows the version selectbox
             $("#cgs").change(function(){
               version = $(this).val();
               document.getElementById("val_scenarios").innerHTML=(tool + " - " + version);
               lasttool = tool;   //Must keep track to hide later, if needed
             });
          } else if (tool == "dpss"){
            $('select#'+tool).selectmenu({maxHeight: 150}).parent("fieldset").hide();
            $('select#'+lasttool).selectmenu({maxHeight: 150}).parent("fieldset").hide();
            $('select#'+tool).parent("fieldset").show();
            $("#dpss").change(function(){
               version = $(this).val();
               document.getElementById("val_scenarios").innerHTML=(tool + " - " + version);
               $('select#'+tool).selectmenu({maxHeight: 150}).parent("fieldset").show();
               lasttool = tool;
             });            
          } else if (tool == "elt5500"){
            $('select#'+tool).selectmenu({maxHeight: 150}).parent("fieldset").hide();
            $('select#'+lasttool).selectmenu({maxHeight: 150}).parent("fieldset").hide();
            $('select#'+tool).parent("fieldset").show();
            $("#elt5500").change(function(){
               version = $(this).val();
               document.getElementById("val_scenarios").innerHTML=(tool + " - " + version);
               $('select#'+tool).selectmenu({maxHeight: 150}).parent("fieldset").show();
               lasttool = tool;
             });  
          } else if (tool == "iapioneer"){  
            $('select#'+tool).selectmenu({maxHeight: 150}).parent("fieldset").hide();
            $('select#'+lasttool).selectmenu({maxHeight: 150}).parent("fieldset").hide();
            $('select#'+tool).parent("fieldset").show();
            $("#iapioneer").change(function(){
               version = $(this).val();
               document.getElementById("val_scenarios").innerHTML=(tool + " - " + version);
               $('select#'+tool).selectmenu({maxHeight: 150}).parent("fieldset").show();
               lasttool = tool;
             });   
          } else {
           // $('select#none').parent("fieldset").hide();
            $('select#'+lasttool).parent("fieldset").hide();
            document.getElementById("val_scenarios").innerHTML=(tool + " - " + version + " - " + lasttool);
          } 
        }
      });
    
    });