/**
 * $Author: bcrowe $
 * $LastChangedDate: 2006-02-01 10:34:13 +0000 (Wed, 01 Feb 2006) $
 * $LastChangedRevision: 876 $
 * $LastChangedBy: bcrowe $
 * $HeadURL: svn+ssh://svn/var/svn/worldres/worldres.com/tags/release-1.0.255.0/scripts/showMatches.js $
 */

  shimmyShim(document.getElementById('Matches'));
 
  var MatchesShown = false;

  var selectedMatch = 1;

  function showMatches(matchString, key, width)
  {
    
    if (navigator.userAgent.indexOf("Safari") != -1)
    {
      return false;
    }

    document.getElementById("Matches").style.display = "none";

    if(key == 40||key==39) selectedMatch++;
    if(key == 38||key==37) selectedMatch--;
    if(selectedMatch > MatchesShown) selectedMatch = MatchesShown;
    if(selectedMatch < 1) selectedMatch = 1;
    matchString = matchString.toLowerCase();
    numCities = CityList.length;
    matchHTML = "<table border=0 cellpadding=0 cellspacing=0 width="+width+" bgcolor=white>\n";
    numMatches = 0;
    moreMatches = false;
    shimHeight = 0;

    for(i = 0; i < numCities; i++ )
    {
      if(matchString == CityList[i].substring(0, matchString.length).toLowerCase())
      {
        if(numMatches == 10)
        {
          moreMatches = true;
          break;
        }

        numMatches++;

        if(numMatches == selectedMatch) 
        {
          linkClass = "TXT_selectedMatch";
          cellClass = "BG_selectedMatch";
          if(key == 13 || key == 9) return setKeyWords(CityList[i]);
        }
        else
        {
          linkClass = "TXT_unSelectedMatch";
          cellClass = "BG_unSelectedMatch";
        }

        matchHTML += " <tr>\n";
        matchHTML += "  <td height=18 class='"+cellClass+"' onMouseDown='setKeyWords(\"" + CityList[i] + "\");'><a class='"+linkClass+"' onMouseDown='setKeyWords(\"" + CityList[i] + "\");' href='javascript: void(0)'>" + CityList[i] + "</a></td>\n";
        matchHTML += " </tr>\n";
        shimHeight += 18;
      }
    }

    if(moreMatches)
    {
      matchHTML += " <tr>\n";
      matchHTML += "  <td height=18>More Matches found, please refine your search...</td>\n";
      matchHTML += " </tr>\n";
      shimHeight += 18;
    }

    matchHTML += "</table>\n";
    if(numMatches > 0)
    {
      document.getElementById("MatchesHTML").innerHTML = matchHTML;
      document.getElementById("Matches").style.display = "block";
      MatchesShown = numMatches;

      if (navigator.userAgent.indexOf("MSIE") != -1)
      {
        document.getElementById('shimMatches').style.height = shimHeight;
      }

      return true;
    }
    else
    {
      return false;
    }
  }

  function setKeyWords(keyWords)
  {
    document.hotSearch.cityText.value = keyWords;
    hideMatches();
    return false;
  }

  function hideMatches()
  {
    document.getElementById("Matches").style.display = "none";
    MatchesShown = false;
  }
