var xmlHttp=null;
var searchControl = "ctl00_PlaceHolderSearchArea_SearchBox_S622C1022_InputKeywords";
var searchSuggestionControl = "Select1";
var url = "/Documents/wordlist.txt";

function setsearchtext(text)
{
    document.getElementById(searchControl).value = text;
    document.getElementById(searchSuggestionControl).style.display = 'none';
}

function state_Change()
{
if (xmlHttp.readyState==4)
  {// 4 = "loaded"
  if (xmlHttp.status==200)
    {
    var word = document.getElementById(searchControl).value;
    if (word=="")
    {
        document.getElementById(searchSuggestionControl).style.display = 'none';
        return;
    }
    word = word.toLowerCase();
    
    var text = xmlHttp.responseText;
    var substring = "";
    var select1 = document.getElementById(searchSuggestionControl);
    select1.innerHTML = "";
    var lisatty = 0;

    for (var i = 0; i<text.length; i++)
    {
        if (text.charAt(i) == '\r')
        {
            // onko mätsi
            var s = substring.toLowerCase();
            if (s.indexOf(word,0) > -1)
            {            
                select1.innerHTML = select1.innerHTML + 
                    "<div onclick='javascript: setsearchtext(\""+ substring +"\");'>"+substring+"</div>";
                lisatty++;
                if (lisatty >= 10)
                    break;
            }
            substring = ""; 
        }
        else
        {
            if (text.charAt(i) != '\n')
                substring = substring + text.charAt(i);
        }
    }    
    if (select1.innerHTML != "")
        document.getElementById(searchSuggestionControl).style.display = 'block';
    else
        document.getElementById(searchSuggestionControl).style.display = 'none';
    }
  else
    {
    //alert("Problem retrieving XML data. Status:"+xmlHttp.status);
    }
  }
}


function showHint()
{
    var word = document.getElementById(searchControl).value;
    
    if (word=="")
    {
        document.getElementById(searchSuggestionControl).style.display = 'none';
        return;
    }
    word = word.toLowerCase();

    try
    {// Firefox, Opera 8.0+, Safari, IE7
      xmlHttp=new XMLHttpRequest();
    }
    catch(e)
    {// Old IE
      try
      {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e)
      {
        alert ("Your browser does not support XMLHTTP!");
        return;  
      }
    }
    
    xmlHttp.onreadystatechange=state_Change;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}