var xmlHttp;
var catNames = new Array();

function showHint(field,box)
{
    box.setAttribute('autocomplete', 'off');
    str = box.value;
    if (str.length < 3)
    { 
        document.getElementById(field+"Hint").innerHTML=""
        return
    }
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    } 
    var url="/ajax_server.php"
    url=url+"?operation=search"
    url=url+"&field="+field
    url=url+"&search="+str
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=function () 
    {
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        { 
            document.getElementById(field+"Hint").innerHTML=trim(xmlHttp.responseText);
            if (document.getElementById(field+"Hint").innerHTML.length==0) {
                document.getElementById(field+"div").style.display="none";
            } else {
                document.getElementById(field+"div").style.display="block";
            }
        }
    }
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}

function GetXmlHttpObject()
{ 
    //XMLhttp variable will hold the XMLHttpRequest object
    var xmlhttp = false;            
    // If the user is using Mozilla/Firefox/Safari/etc
    if (window.XMLHttpRequest) {
        //Intiate the object
        xmlhttp = new XMLHttpRequest();
        //Set the mime type
        xmlhttp.overrideMimeType('text');
    } else if (window.ActiveXObject) {
        //Intiate the object
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlhttp
}

function trim(str)
{
   str = str.replace(/^\s*|\s*$/g,"");
   str = str.replace(/\n/g,"");
   return str;
}
