var dsMembers = new Spry.Data.XMLDataSet("members.xml", "members/member", {sortOnLoad: "name", sortOrderOnLoad: "ascending"});
function multiSort() {
  var sortArray = new Array(2);
  sortArray[0] = "geo";
  sortArray[1] = "name";
  dsMembers.sort(sortArray);
}
var sortField = "name";
var sortOrder = "ascending";
var savedSelectionString = "&nbsp;All Members";
function fixSelectionString() {
  document.getElementById('selectionString').innerHTML = savedSelectionString;
  fixGraphic();
}
function sortName() {
  savedSelectionString = document.getElementById('selectionString').innerHTML;
  if (sortField == "name") 
    if (sortOrder == "ascending") {
      document['nameSort'].src = "descending.gif";
      sortOrder = "descending";
    }
    else {
      document['nameSort'].src = "ascending.gif";
      sortOrder = "ascending";
    }
  else {
    sortField = "name";
    document['nameSort'].src = "ascending.gif";
    sortOrder = "ascending";
  }
  document['geoSort'].src = "unsorted.gif";
  document.getElementById('selectionString').innerHTML = savedSelectionString;
}
function sortGeo() {
  savedSelectionString = document.getElementById('selectionString').innerHTML;
  if (sortField == "geo") 
    if (sortOrder == "ascending") {
      document['geoSort'].src = "descending.gif";
      sortOrder = "descending";
    }
    else {
      document['geoSort'].src = "ascending.gif";
      sortOrder = "ascending";
    }
  else {
    sortField = "geo";
    document['geoSort'].src = "ascending.gif";
    sortOrder = "ascending";
  }
  document['nameSort'].src = "unsorted.gif";
}
var geoString = "";
var filterGeo = function(dataSet, row, rowNumber)
{
  if (row["geo"].search(geoString) != -1)
    return row;
  return null;
}
function fixGraphic() {
  if (sortField == "name") {
    if (sortOrder == "ascending") {
      document['nameSort'].src = "ascending.gif";
      document['geoSort'].src = "unsorted.gif";
    }
    else{
      document['nameSort'].src = "descending.gif";
      document['geoSort'].src = "unsorted.gif";
    }
  }
  else {
    if (sortOrder == "ascending") {
      document['geoSort'].src = "ascending.gif";
      document['nameSort'].src = "unsorted.gif";
    }
    else {
      document['geoSort'].src = "descending.gif";
      document['nameSort'].src = "unsorted.gif";
    }
  }
}
function selectGeo(str) {
  geoString = str;
  dsMembers.filter(filterGeo);
  fixGraphic();
}
var nameString = "";
var filterName = function(dataSet, row, rowNumber)
{
  if (row["name"].search(nameString) != -1)
    return row;
  return null;
}
function selectName(str) {
  nameString = str;
  dsMembers.filter(filterName);
  fixGraphic();
}
function selectALL() {
  dsMembers.filter(null);
  fixGraphic();
}
function showSelection(str) {
  switch (str)
  {
  case 'A':
    selectName(/^A/);
    document.getElementById('selectionString').innerHTML = '&nbsp;A';
    break;
  case 'B':
    selectName(/^B/);
    document.getElementById('selectionString').innerHTML = '&nbsp;B';
    break;
  case 'C':
    selectName(/^C/);
    document.getElementById('selectionString').innerHTML = '&nbsp;C';
    break;
  case 'D':
    selectName(/^D/);
    document.getElementById('selectionString').innerHTML = '&nbsp;D';
    break;
  case 'E':
    selectName(/^E/);
    document.getElementById('selectionString').innerHTML = '&nbsp;E';
    break;
  case 'F':
    selectName(/^F/);
    document.getElementById('selectionString').innerHTML = '&nbsp;F';
    break;
  case 'G':
    selectName(/^G/);
    document.getElementById('selectionString').innerHTML = '&nbsp;G';
    break;
  case 'H':
    selectName(/^H/);
    document.getElementById('selectionString').innerHTML = '&nbsp;H';
    break;
  case 'I':
    selectName(/^I/);
    document.getElementById('selectionString').innerHTML = '&nbsp;I';
    break;
  case 'J':
    selectName(/^J/);
    document.getElementById('selectionString').innerHTML = '&nbsp;J';
    break;
  case 'K':
    selectName(/^K/);
    document.getElementById('selectionString').innerHTML = '&nbsp;K';
    break;
  case 'L':
    selectName(/^L/);
    document.getElementById('selectionString').innerHTML = '&nbsp;L';
    break;
  case 'M':
    selectName(/^M/);
    document.getElementById('selectionString').innerHTML = '&nbsp;M';
    break;
  case 'N':
    selectName(/^N/);
    document.getElementById('selectionString').innerHTML = '&nbsp;N';
    break;
  case 'O':
    selectName(/^O/);
    document.getElementById('selectionString').innerHTML = '&nbsp;O';
    break;
  case 'P':
    selectName(/^P/);
    document.getElementById('selectionString').innerHTML = '&nbsp;P';
    break;
  case 'Q':
    selectName(/^Q/);
    document.getElementById('selectionString').innerHTML = '&nbsp;Q';
    break;
  case 'R':
    selectName(/^R/);
    document.getElementById('selectionString').innerHTML = '&nbsp;R';
    break;
  case 'S':
    selectName(/^S/);
    document.getElementById('selectionString').innerHTML = '&nbsp;S';
    break;
  case 'T':
    selectName(/^T/);
    document.getElementById('selectionString').innerHTML = '&nbsp;T';
    break;
  case 'U':
    selectName(/^U/);
    document.getElementById('selectionString').innerHTML = '&nbsp;U';
    break;
  case 'V':
    selectName(/^V/);
    document.getElementById('selectionString').innerHTML = '&nbsp;V';
    break;
  case 'W':
    selectName(/^W/);
    document.getElementById('selectionString').innerHTML = '&nbsp;W';
    break;
  case 'X':
    selectName(/^X/);
    document.getElementById('selectionString').innerHTML = '&nbsp;X';
    break;
  case 'Y':
    selectName(/^Y/);
    document.getElementById('selectionString').innerHTML = '&nbsp;Y';
    break;
  case 'Z':
    selectName(/^Z/);
    document.getElementById('selectionString').innerHTML = '&nbsp;Z';
    break;
  case 'AL':
    selectGeo(/^AL/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Alabama";
    break;
  case 'AK':
    selectGeo(/^AK/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Alaska";
    break;
  case 'AZ':
    selectGeo(/^AZ/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Arizona";
    break;
  case 'AR':
    selectGeo(/^AR/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Arkansas";
    break;
  case 'CA':
    selectGeo(/^CA/);
    document.getElementById('selectionString').innerHTML = "&nbsp;California";
    break;
  case 'CO':
    selectGeo(/^CO/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Colorado";
    break;
  case 'CT':
    selectGeo(/^CT/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Connecticut";
    break;
  case 'DE':
    selectGeo(/^DE/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Deleware";
    break;
  case 'DC':
    selectGeo(/^DC/);
    document.getElementById('selectionString').innerHTML = "&nbsp;District of Columbia";
    break;
  case 'FL':
    selectGeo(/^FL/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Florida";
    break;
  case 'GA':
    selectGeo(/^GA/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Georgia";
    break;
  case 'HI':
    selectGeo(/^HI/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Hawaii";
    break;
  case 'ID':
    selectGeo(/^ID/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Idaho";
    break;
  case 'IL':
    selectGeo(/^IL/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Illinois";
    break;
  case 'IN':
    selectGeo(/^IN/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Indiana";
    break;
  case 'IA':
    selectGeo(/^IA/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Iowa";
    break;
  case 'KS':
    selectGeo(/^KS/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Kansas";
    break;
  case 'KY':
    selectGeo(/^KY/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Kentucky";
    break;
  case 'LA':
    selectGeo(/^LA/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Louisiana";
    break;
  case 'ME':
    selectGeo(/^ME/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Maine";
    break;
  case 'MD':
    selectGeo(/^MD/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Maryland";
    break;
  case 'MA':
    selectGeo(/^MA/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Massachusetts";
    break;
  case 'MI':
    selectGeo(/^MI/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Michigan";
    break;
  case 'MN':
    selectGeo(/^MN/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Minnesota";
    break;
  case 'MS':
    selectGeo(/^MS/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Mississippi";
    break;
  case 'MO':
    selectGeo(/^MO/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Missouri";
    break;
  case 'MT':
    selectGeo(/^MT/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Montana";
    break;
  case 'NE':
    selectGeo(/^NE/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Nebraska";
    break;
  case 'NV':
    selectGeo(/^NV/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Nevada";
    break;
  case 'NH':
    selectGeo(/^NH/);
    document.getElementById('selectionString').innerHTML = "&nbsp;New Hampshire";
    break;
  case 'NJ':
    selectGeo(/^NJ/);
    document.getElementById('selectionString').innerHTML = "&nbsp;New Jersey";
    break;
  case 'NM':
    selectGeo(/^NM/);
    document.getElementById('selectionString').innerHTML = "&nbsp;New Mexico";
    break;
  case 'NY':
    selectGeo(/^NY/);
    document.getElementById('selectionString').innerHTML = "&nbsp;New York";
    break;
  case 'NC':
    selectGeo(/^NC/);
    document.getElementById('selectionString').innerHTML = "&nbsp;North Carolina";
    break;
  case 'ND':
    selectGeo(/^ND/);
    document.getElementById('selectionString').innerHTML = "&nbsp;North Dakota";
    break;
  case 'OH':
    selectGeo(/^OH/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Ohio";
    break;
  case 'OK':
    selectGeo(/^OK/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Oklahoma";
    break;
  case 'OR':
    selectGeo(/^OR/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Oregon";
    break;
  case 'PA':
    selectGeo(/^PA/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Pennsylvania";
    break;
  case 'RI':
    selectGeo(/^RI/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Rhode Island";
    break;
  case 'SC':
    selectGeo(/^SC/);
    document.getElementById('selectionString').innerHTML = "&nbsp;South Carolina";
    break;
  case 'SD':
    selectGeo(/^SD/);
    document.getElementById('selectionString').innerHTML = "&nbsp;South Dakota";
    break;
  case 'TN':
    selectGeo(/^TN/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Tennessee";
    break;
  case 'TX':
    selectGeo(/^TX/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Texas";
    break;
  case 'UT':
    selectGeo(/^UT/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Utah";
    break;
  case 'VT':
    selectGeo(/^VT/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Vermont";
    break;
  case 'VA':
    selectGeo(/^VA/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Virginia";
    break;
  case 'WA':
    selectGeo(/^WA/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Washington";
    break;
  case 'WV':
    selectGeo(/^WV/);
    document.getElementById('selectionString').innerHTML = "&nbsp;West Virginia";
    break;
  case 'WI':
    selectGeo(/^WI/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Wisconsin";
    break;
  case 'WY':
    selectGeo(/^WY/);
    document.getElementById('selectionString').innerHTML = "&nbsp;Wyoming";
    break;
  case 'zz':
    selectGeo(/^zz/);
    document.getElementById('selectionString').innerHTML = "&nbsp;International";
    break;
  default:
    document.getElementById('selectionString').innerHTML = "&nbsp;All Members";
  }
}
