function dosuggest(mytext,event) {
    var keyNum = 0;
    if(window.event){
        // IE
        keyNum = event.keyCode;
    }else if(event.which){            
        // Netscape/Firefox/Opera
        keyNum = event.which;
    }else{
        return true;
    }
    if(mytext.value.length >= 3 && keyNum != 40 && keyNum != 38 && keyNum != 37 && keyNum != 39){
        //alert("hey");
        doajax("/autofill.php?text=" + mytext.value,"afdiv");
        //alert("hey2");
        //pause(50000);
        
        
    }else if(mytext.value.length < 3 && document.getElementById('afdiv').style.display == ""){
        document.getElementById('afdiv').style.display = "none";
    }
    //alert(keyNum);
    //if(keyNum == 13) {
        // Enter Key pressed, then start search, else do nothing.
        //document.jform.cat.value= thecat;
        //document.jform.quantity.value = document.jform.elements["itm" + thecat + "qty"].value;
        //verifyjform();
        //return false;
    if(document.getElementById('afdiv').style.display == ''){
        if(keyNum == 40){
            //down key
            if(optsel + 1 < optarray.length){
                deselectoption(mytext,optsel);
                optsel++;
                selectoption(mytext,optsel);
            }
        }else if(keyNum == 38){
            //up key
            if(optsel > -1){
                if(optsel == 0){
                    deselectoption(mytext,0);
                    optsel = -1;
                    mytext.value = origtext;
                }else{
                    deselectoption(mytext,optsel);
                    optsel--;
                    selectoption(mytext,optsel);
                }
            }
        }else{
           origtext = mytext.value;
           return true; 
        }
    }else{
        origtext = mytext.value;
        return true;
    }
}
function catchtab(mytext,event){
    var keyNum = 0;
    if(window.event){
        // IE
        keyNum = event.keyCode;
    }else if(event.which){            
        // Netscape/Firefox/Opera
        keyNum = event.which;
    }else{
        return true;
    }
    //alert(keyNum);
    if(keyNum == 9 && mytext.value.length >= 3){
        //this.focus();
        return false;
    }else{
        return true;
    }
}
function deselectoption(mytext,whichone){
    if(whichone > -1){
        document.getElementById("optdiv" + whichone).style.backgroundColor = "#ececfc";
    }
}
function selectoption(mytext,whichone){
    document.getElementById("optdiv" + whichone).style.backgroundColor = "#aaaaaa";
    mytext.value = optarray[whichone];
}
function checkopts(){
    if(optsel > -1){
        if(urlarray[optsel] != ""){
            //alert(urlarray[optsel]);
            window.location.href = urlarray[optsel];
            return false;
        }else{
            return true;
        }
    }
}
document.onmousedown = mymousedown;

function mymousedown(myevent){
    var ev = (!myevent)?window.event:myevent;
    cursorx = ev.clientX;
    cursory = ev.clientY;
    if(document.getElementById('afdiv').style.display == ''){
        theloc = getY('afdiv');
        topleftx = theloc.x;
        toprightx = topleftx + document.getElementById('afdiv').offsetWidth;
        topy = theloc.y - document.getElementById('keyword').offsetHeight;
        bottomy = topy + document.getElementById('afdiv').offsetHeight;
        if(cursorx < topleftx || cursorx > toprightx || cursory < topy || cursory > bottomy){
            document.getElementById('afdiv').style.display = 'none';
        }
    }
}
optsel = -1;
optarray = new Array();
urlarray = new Array();
origtext = '';
