var s;
var l;
var c = 0;
var type1
var m_type = 1;
var rowcount = 0;
var response = "";
var CategoryID = 2;
function on_complete() {
    if (response == null || response == "") {
        s = 2;
        document.getElementById("dv1").style.display = "none";
    }
    else {
        var offset1 = document.getElementById("keyword");
        var offset2 = document.getElementById("dv1");
        var width = offset1.offsetWidth;
        var left = offset1.offsetLeft + 112; //zb(offset1);
        var top = Yb(offset1) + offset1.offsetHeight;
        var name1 = "";
        offset2.style.borser = "black 1px  solid";
        offset2.style.left = (left - 18) + "px";
        offset2.style.top = (top - 75) + "px";
        offset2.style.width = width + "px";
        l = rowcount;
        s = 1;
        c = l;
        offset2.style.display = "block";
        offset2.innerHTML = response;
    }
}


function ChangeMenu(index) {
    CategoryID = index;
}
var js;
var file = "";
function createScript_1() {
    if (CategoryID == 1)     //公司
    {
        file = "http://searchui.search.mainone.com/py/ms_com.php?kw=" + document.getElementById("keyword").value;
    }
    if (CategoryID == 2)     //商机
    {
        file = "http://searchui.search.mainone.com/py/ms_bus.php?kw=" + document.getElementById("keyword").value;
    }
    if (CategoryID == 3)     //产品
    {
        file = "http://searchui.search.mainone.com/py/ms_pro.php?kw=" + document.getElementById("keyword").value;
    }
    var html_doc = document.getElementsByTagName('head')[0];
    js = document.createElement('script');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', file);
    html_doc.appendChild(js);
    js.onreadystatechange = function() {
        var state = js.readyState;
        if (state == "loaded" || state == "interactive" || state == "complete") {
            writeSearchContent();
        }
    }
    js.onload = function() {
        writeSearchContent();
    }
    return false;
}

function writeSearchContent() {
    var keyword = "";
    keyword = document.getElementById("keyword").value;
    if (keyword == "" || keyword.indexOf("请输入") >= 0) { return; }
    var strJosn = null;
    if (!window.str_Josn) return;
    if (typeof (str_Josn) != "undifined" && str_Josn != null)
    { strJosn = str_Josn; }
    if (strJosn != null || strJosn != "") {
        response = strJosn[1];
        rowcount = strJosn[2];
        on_complete();
        //document.getElementsByTagName("head")[0].removeChild(element);
        try {
            // document.getElementsByTagName("head")[0].removeChild(js);
        }
        finally { js = null; }
    }
}
window.onload = function() {
    createScript_1();
}

function mouse_over(arg) {
    arg.style.color = '#ffffff';
    arg.style.background = '#2f75d5';
    arg.style.border = 'solid 1px #1c63cb';
}
function call_mouse() {
}
function mouse_out(arg) {
    arg.style.color = '#343434';
    arg.style.background = '#ffffff';
}
function mouse_down(arg) { //页着智能提示
    document.getElementById("keyword").value = arg.cells[0].innerHTML;
    OnSearch();
}
function zb(s) {
    return kb(s, "offsetLeft")
}
function Yb(s) {
    return kb(s, "offsetTop")
}
function kb(s, na) {
    var wb = 0;
    while (s) {
        wb += s[na];
        s = s.offsetParent
    }
    return wb
}
function call1() {
    if (document.getElementById("dv1") != null)
        document.getElementById("dv1").style.display = "none";
}

function call2() {
    if (CategoryID != 1 && CategoryID != 2 && CategoryID != 3) { return; }
    var keyword = "";
    keyword = document.getElementById("keyword").value;
    if (keyword == "" || keyword.indexOf("请输入") >= 0) {
        document.getElementById("dv1").style.display = "none";
        return;
    }
    createScript_1();
}
function call_server(event) {
    if (CategoryID != 1 && CategoryID != 2 && CategoryID != 3) { return; }
    _e = event;
    var e = _e.keyCode ? _e.keyCode : _e.which;
    if ((e != 40) && (e != 38) && (e != 13))           //38-Up键;40-Down键;13-Enter回车键
    {
        var keyword = "";
        keyword = document.getElementById("keyword").value;
        if (keyword != "" && keyword.indexOf("请输入") < 0) {
            createScript_1();
        }
        if (keyword == "" || keyword.indexOf("请输入") >= 0) {
            document.getElementById("dv1").style.display = "none";
        }
    }
    else {
        var sgtable = document.getElementById("sg_table");
        type1 = 1;
        if (e == 40 && s == 1) {
            if (c == l) {
                //alert(l);	    
                //alert(sgtable.rows[0]);
                sgtable.rows[0].style.background = "#2F75D5";
                sgtable.rows[0].style.color = "#ffffff";
                sgtable.rows[0].style.border = "solid 1px #1c63cb";
                c = 0;
            }
            else if (c == l - 1) {
                sgtable.rows[c].style.color = "#343434";
                sgtable.rows[c].style.background = "#ffffff";
                c = 0;
                sgtable.rows[c].style.background = "#2F75D5"
                sgtable.rows[c].style.color = "#ffffff";
                sgtable.rows[c].style.border = "solid 1px #1c63cb";
            }
            else {
                sgtable.rows[c].style.color = "#343434";
                sgtable.rows[c].style.background = "#ffffff";

                c++;
                sgtable.rows[c].style.background = "#2F75D5";
                sgtable.rows[c].style.color = "#ffffff";
                sgtable.rows[c].style.border = "solid 1px #1c63cb";
                document.getElementById("keyword").value = sgtable.rows[c].cells[0].innerHTML;
            }
        }
        if (e == 38 && s == 1) {
            if (c == l) {
                sgtable.rows[l - 1].style.background = "#2F75D5";
                sgtable.rows[l - 1].style.color = "#ffffff";
                sgtable.rows[l - 1].style.border = "solid 1px #1c63cb";
                c = l - 1;
            }
            else if (c == 0) {
                sgtable.rows[c].style.color = "#343434";
                sgtable.rows[c].style.background = "#ffffff";
                c = l - 1;
                sgtable.rows[c].style.background = "#2F75D5";
                sgtable.rows[c].style.color = "#ffffff";
                sgtable.rows[c].style.border = "solid 1px #1c63cb";
            }
            else {
                sgtable.rows[c].style.background = "#ffffff";
                sgtable.rows[c].style.color = "#343434";
                c--;
                sgtable.rows[c].style.background = "#2F75D5";
                sgtable.rows[c].style.color = "#ffffff";
                sgtable.rows[c].style.border = "solid 1px #1c63cb";
            }
            document.getElementById("keyword").value = sgtable.rows[c].cells[0].innerHTML;
        }
        if (e == 13 && s == 1 && c != l) {
            document.getElementById("keyword").value = sgtable.rows[c].cells[0].innerHTML;
            document.getElementById("dv1").style.display = "none";
            type1 = 0;
            event.returnValue = "ture";
        }
    }
}

function show(obj) {
    document.getElementById("id_item").className = "itemhover";
    obj.style.position = "relative";
    obj.getElementsByTagName("a")[0].style.backgroundColor = "#ffffff";
    document.getElementById("lmitem").style.display = "block";
}
function show1(obj) {
    document.getElementById("id_item").className = "";
    document.getElementById("lmitem").style.display = "none";
    obj.getElementsByTagName("a")[0].style.backgroundColor = "";
}
