﻿var xmlHttp

function showHint(str, max) {
    if (str.length == 0) {
        document.getElementById('txtHint').innerHTML = '';
        document.getElementById('txtHint').className = 'one';
        return;
    }

    xmlHttp = GetXmlHttpObject();

    if (xmlHttp == null) {
        alert("Your browser does not support AJAX!");
        return;
    }

    document.getElementById('txtHint').className = 'two';
    
    var url = "/suggest.aspx";
    url = url + "?q=" + str + '&max=' + max;
    // url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange = stateChanged;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}
function stateChanged() {
    if (xmlHttp.readyState == 4) {
        document.getElementById("txtHint").innerHTML = xmlHttp.responseText;
    }
}
function GetXmlHttpObject() {
    var xmlHttp = null;
    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 hideHint() {
    document.getElementById('txtHint').innerHTML = '';
    document.getElementById('txtHint').className = 'one';
}
function setValue(newvalue) {
    var st;
    // var cbo = document.getElementById('cboStates');
    var filter = document.getElementById('cmdFilter');
    
    st = newvalue.substring(newvalue.length - 2, newvalue.length);
    //alert(st);

    document.getElementById('txtMake').value = newvalue;
    // document.getElementById('txtMake').value = newvalue.substring(0, newvalue.length - 4);
    // if (cbo != null) { document.getElementById('cboStates').value = st;}
    
    hideHint();
    document.getElementById('txtMake').focus;

    if (filter != null) {document.forms[0].submit();}
}