
// AJAX VARS 
var xmlHttp;
var elm;

// AJAX FUNCTIONS
function GetXmlHttpObject() {
    try {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
    } catch (e) {
      // Internet Explorer
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function suggestions(word) {
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    } 
    
    xmlHttp.onreadystatechange = function() {

        elm = document.getElementById("sugg");
        elm2 = document.getElementById("submit");
           
        if (xmlHttp.readyState < 4 && xmlHttp.readyState > 0) {
            
            elm.style.display = "inline";
            elm.innerHTML = "<div style=\"padding: 3px 7px 7px 7px;\">Finding suggestions<div style=\"text-align: right;\" id=\"submit\"><div style=\"padding: 10px 0 0 0;\"><input type=\"submit\" value=\"Search\" name=\"search\" class=\"formbutton\" /></div></div>";
        
        }
        
        if(xmlHttp.readyState == 4) {
            
            if (xmlHttp.responseText == "") {
                elm2.style.display = "inline";
                elm.style.display = "none";
            }
            else {
                elm2.style.display = "none";
                elm.style.display = "inline";
                elm.innerHTML = xmlHttp.responseText;
            }
            
            
        }
    }
    xmlHttp.open("GET","/ajax-files/suggestions.php?word=" + word, true);
    xmlHttp.send(null);
}
