// this stuff is currently working only on IE - Hugo
// here we define global variable
var ajaxdestination="";
function getdata(what,where) 
{ // get data from source (what)
    try 
    {  
        //if IE (6)...
        xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest():
              new ActiveXObject("Microsoft.XMLHTTP");
          //if IE 7
          //if Mozila...
          //if Safari...
    }
    catch (e) { /* NOT IE, change this logic ASAP */ }
    document.getElementById(where).innerHTML ="<center>Suggesting...</center>";
    // destination DIV id, must be stored in global variable (ajaxdestination)
    ajaxdestination=where;
    xmlhttp.onreadystatechange = triggered; // when request finished, call the function to put result to destination DIV
    xmlhttp.open("GET", what);
    xmlhttp.send(null);
    return false;
}
function triggered() 
{ 
    // put data returned by requested URL to selected DIV
    if (xmlhttp.readyState == 4) if (xmlhttp.status == 200) 
    {
        var pTag = '<p onclick="$(\'#inputSearch\').val($(this).text())" ONMOUSEOUT="this.className=\'\'" ONMOUSEOVER="this.className=\'selectedSmartInputItem\'">';
        var elements = xmlhttp.responseText.split("|");
        var text = "";
        // trim
        for (i=0; i<elements.length; i++){
            elements[i] = elements[i].replace(/^\s+|\s+$/g, '');
        }
        // remove duplicated elements
        for (i=0; i<elements.length; i++){
           for (j = i + 1; j<elements.length; j++){
               if (elements[i] == elements[j]){
                   elements[j] = "";
               }
           }
        }
        for (i=0; i<elements.length; i++){
            if (elements[i] != ""){
                text = text + pTag + elements[i] + "</p>";
            }
        }
        $("#" + ajaxdestination).html(text);
    }
}

