var currentMap = "", currentAgents = "", currentRegion = "";

function showMap(mapName, default_agents) {
  var instructions = document.getElementById('instructions');

  if (mapName != currentMap) {
    instructions.style.display = "block";

    document.getElementById('region_title').firstChild.nodeValue = "\xa0";
    document.getElementById('intdlrs').style.display = "none";

    if (currentAgents != "")
      for (var x = 0, ags = currentAgents.split(" "), agel; x < ags.length; x++)
        if (agel = document.getElementById('agent_' + ags[x])) agel.style.display = "none";
    currentAgents = "";

    if (currentRegion != "") {
      // document.getElementById('region_' + currentRegion).style.display = "none";
      document.getElementById('region_' + currentRegion).style.display = "none";
      currentRegion = "";
    }

    // if (currentMap != "") document.getElementById(currentMap).style.display = "none";
    if (currentMap != "") document.getElementById(currentMap).style.height = "0px";
    // document.getElementById(currentMap = mapName).style.display = "block";
    document.getElementById(currentMap = mapName).style.height = "386px";
  }

  if (default_agents) {
    showRegion('Area Manager(s)', default_agents, '');
    instructions.style.display = "block";
  }
}

function showRegion(title, agents, region) {
  document.getElementById('region_title').firstChild.nodeValue = title;

  if (agents != currentAgents) {
    document.getElementById('instructions').style.display = "none";

    if (currentAgents != "")
      for (var x = 0, ags = currentAgents.split(" "), agel; x < ags.length; x++)
        if (agel = document.getElementById('agent_' + ags[x])) agel.style.display = "none";

    for (var x = 0, ags = agents.split(" "), agel; x < ags.length; x++)
      if (agel = document.getElementById('agent_' + ags[x])) agel.style.display = "block";

    currentAgents = agents;
  }

  // if (currentRegion != "" && currentRegion != region)
    // document.getElementById('region_' + currentRegion).style.display = "none";
  if (currentRegion != "" && currentRegion != region)
    document.getElementById('region_' + currentRegion).style.display = "none";

  var regBlock, intdlrs = document.getElementById('intdlrs');

  if (region != "" && currentRegion != region) {
    if (regBlock = document.getElementById('region_' + region)) {
      // regBlock.style.display = intdlrs.style.display = "block";
      intdlrs.style.display = "block";
      regBlock.style.display = "block";
      currentRegion = region;
    } else {
      intdlrs.style.display = "none";
      currentRegion = "";
    }
  } // else intdlrs.style.display = "none";

  if (region == "") currentRegion = "";
}
