// Grays out disabled menu options
function grayout(e) { 
  for (var i=0, option; option = e.options[i]; i++) { 
    if (option.disabled) { 
      option.style.color = "graytext"; 
    }
    else 
    { 
      option.style.color = "menutext"; 
    } 
  } 
}

// Enables/disables sort options
function toggleOpts(which,e) {
  var val;
  for (var i=0, option; option = e.options[i]; i++) { 
    if (which=='bat') {
      if ((option.value=='stuff')||(option.value=='control')||(option.value=='movement')||(option.value=='pitching_ratings_misc_velocity')||(option.value=='pitching_ratings_misc_stamina')) {
        option.disabled='disabled';
      }
      else 
      {
        option.disabled='';
      }
    }
    if (which=='pit') {
      if ((option.value=='contact')||(option.value=='gap')||(option.value=='power')||(option.value=='eye')||(option.value=='strikeouts')||(option.value=='speed')||(option.value=='stealing')||(option.value=='baserunning')) {
        option.disabled='disabled';
      }
      else {
        option.disabled='';
      }
    }
  } 
}

// Correct sorts based on who is selected to display
function whoChange() {
    var whoElem=document.getElementById('whoFilt');
    var sort1=document.getElementById('sort1filter');
    var sort2=document.getElementById('sort2filter');
    var sort3=document.getElementById('sort3filter');
    var whoVal=whoElem[whoElem.selectedIndex].value;
    var sort1Val=sort1[sort1.selectedIndex].value;
    var sort2Val=sort1[sort2.selectedIndex].value;
    var sort3Val=sort1[sort3.selectedIndex].value;

    if ((whoVal!='batting')&&(whoVal!='pitching')&&(whoVal!='fielding')) {whoVal=parseInt(whoVal);}

    if ((whoVal=='batting')||(whoVal=='fielding')||((whoVal>1)&&(whoVal<=10))) {
      if ((sort1Val=='stuff')||(sort1Val=='control')||(sort1Val=='movement')||(sort1Val=='pitching_ratings_misc_velocity')||(sort1Val=='pitching_ratings_misc_stamina')) {
        sort1.value='contact';
      }
      if ((sort2Val=='stuff')||(sort2Val=='control')||(sort2Val=='movement')||(sort2Val=='pitching_ratings_misc_velocity')||(sort2Val=='pitching_ratings_misc_stamina')) {
        sort2.value='power';
      }
      if ((sort3Val=='stuff')||(sort3Val=='control')||(sort3Val=='movement')||(sort3Val=='pitching_ratings_misc_velocity')||(sort3Val=='pitching_ratings_misc_stamina')) {
        sort3.value='eye';
      }

      toggleOpts('bat',sort1);
      toggleOpts('bat',sort2);
      toggleOpts('bat',sort3);
    }

    if ((whoVal=='pitching')||(whoVal>10)) {
      if ((sort1Val=='contact')||(sort1Val=='gap')||(sort1Val=='power')||(sort1Val=='eye')||(sort1Val=='strikeouts')||(sort1Val=='speed')||(sort1Val=='stealing')||(sort1Val=='baserunning')) {
        sort1.value='stuff';
      }
      if ((sort2Val=='contact')||(sort2Val=='gap')||(sort2Val=='power')||(sort2Val=='eye')||(sort2Val=='strikeouts')||(sort2Val=='speed')||(sort2Val=='stealing')||(sort2Val=='baserunning')) {
        sort2.value='control';
      }
      if ((sort3Val=='contact')||(sort3Val=='gap')||(sort3Val=='power')||(sort3Val=='eye')||(sort3Val=='strikeouts')||(sort3Val=='speed')||(sort3Val=='stealing')||(sort3Val=='baserunning')) {
        sort3.value='movement';
      }
      toggleOpts('pit',sort1);
      toggleOpts('pit',sort2);
      toggleOpts('pit',sort3);
    }

    grayout(sort1);
    grayout(sort2);
    grayout(sort3);
}


