﻿var publicnum = 1; //用于提示框计数 全局变量
var keyallcode;  //全局KEY兼容FF

var publicnum2 = 1; //用于提示框计数 全局变量
var keyallcode2;  //全局KEY兼容FF

var publicmailnum = 1; //用于提示框计数 全局变量
var keyallcode3;  //全局KEY兼容FF

function hidesearchdiv(objid)
{
       document.getElementById(objid).style.display = "none"; 
}



jQ("#autoSuggestionsList li").live('mouseover', function() {
    jQ("#autoSuggestionsList li").removeClass("Listhover1");
    jQ("#autoSuggestionsList li").removeClass("Listhover");
    jQ(this).addClass("Listhover");
    jQ("#hid").attr("value", (jQ.trim(jQ(this).children("span:nth-child(1)").html())));
    // jQ("#hindex").attr("value",publicnum);
});
jQ("#autoSuggestionsList li").live('mouseout', function() {
    jQ("#autoSuggestionsList li").removeClass("Listhover");
});

jQ("#autoSuggestionsList li").live('click', function() {

    jQ("#txtCode").attr("value", (jQ.trim(jQ("#hid").val())));
    document.getElementById("autoSuggestionsList").style.display = "none";
    publicnum = 1;
    if (jQ("#txtCode").val() == "") {
        return false;
    }
    else {
        //jQ(".search_go").click();
        return false;
    }
    //window.open('../Track3/LogAnalyzers/Loghome.aspx?stype=1&ztype=2&code='+jQ("#hid").val());

});


function keyDown(e) {
    var currKey = 0, e = e || event;
    currKey = e.keyCode || e.which || e.charCode;
    keyallcode = currKey; //用于全局
    keyallcode2 = currKey; //用于全局
    keyallcode3 = currKey; //用于全局
    if (document.activeElement.id == "txtCode") {
        var objs = document.getElementById("autoSuggestionsList").childNodes;
        var tempid = 0; //存放兼容FF的子结点数量   
        for (var iloop = 0; iloop < objs.length; iloop++) {
            var tempobjs = objs[iloop];
            if ("LI" == tempobjs.nodeName)//因为Firefox会把空格与换行与当成一个节点处理 
            {
                tempid += 1; //加工取得子结点的个数
            }
        }
        var nocontent = (jQ.trim(jQ("#autoSuggestionsList li:nth-child(1)").html())); //取“未找到符合条件的结果”的文字

        if (currKey == 40 && tempid > 0 && nocontent !== "未找到符合条件的结果") //向下 如果没有子结点就不显示提示框
        {
            document.getElementById("autoSuggestionsList").style.display = "block";
            publicnum += 1;
            if (tempid < publicnum) {
                publicnum = 1;
            }
            jQ("#autoSuggestionsList li").removeClass("Listhover");
            jQ("#autoSuggestionsList li").removeClass("Listhover1");
            jQ("#autoSuggestionsList li:nth-child(" + publicnum + ")").addClass("Listhover");

            jQ("#hid").attr("value", (jQ.trim(jQ("#autoSuggestionsList li:nth-child(" + publicnum + ")").children("span:nth-child(1)").html())));
            jQ("#txtCode").attr("value", (jQ.trim(jQ("#hid").val())));
            jQ("#hindex").attr("value", publicnum);
        }
        else if (currKey == 38 && tempid > 0 && nocontent !== "未找到符合条件的结果") //向上
        {

            document.getElementById("autoSuggestionsList").style.display = "block";
            publicnum -= 1;
            if (publicnum < 1) {
                publicnum = tempid;
            }
            jQ("#autoSuggestionsList li").removeClass("Listhover");
            jQ("#autoSuggestionsList li").removeClass("Listhover1");
            jQ("#autoSuggestionsList li:nth-child(" + publicnum + ")").addClass("Listhover");

            jQ("#hid").attr("value", (jQ.trim(jQ("#autoSuggestionsList li:nth-child(" + publicnum + ")").children("span:nth-child(1)").html())));
            jQ("#txtCode").attr("value", (jQ.trim(jQ("#hid").val())));
            jQ("#hindex").attr("value", publicnum);

        }
        else if (currKey == 13 && tempid > 0 && nocontent !== "未找到符合条件的结果") //回车
        {
            if (publicnum == 1 && document.getElementById("autoSuggestionsList").style.display == "block") //默认点回车选1个结果
            {
                jQ("#txtCode").attr("value", (jQ.trim(jQ("#autoSuggestionsList li:nth-child(1)").children("span:nth-child(1)").html())));
                jQ("#hid").attr("value", (jQ.trim(jQ("#txtCode").val())));
            }
            else {
                jQ("#txtCode").attr("value", (jQ.trim(jQ("#hid").val())));
            }
            publicnum = 1; //使其跳到第一个
            jQ("#autoSuggestionsList li").removeClass("Listhover");
            jQ("#autoSuggestionsList li").removeClass("Listhover1");
            jQ("#autoSuggestionsList li:nth-child(1)").addClass("Listhover");
             document.getElementById("autoSuggestionsList").style.display = "none";
            if (jQ("#txtCode").val() == "") {
                return false;
            }
            else {
                jQ(".searchstockbtn").click();
                return false;
            }

        }
    }
    else if (document.activeElement.id == "stockcode") {
        var objs2 = document.getElementById("autoSuggestionsList2").childNodes;
        var tempid2 = 0; //存放兼容FF的子结点数量   
        for (var iloop2 = 0; iloop2 < objs2.length; iloop2++) {
            var tempobjs2 = objs2[iloop2];
            if ("LI" == tempobjs2.nodeName)//因为Firefox会把空格与换行与当成一个节点处理 
            {
                tempid2 += 1; //加工取得子结点的个数
            }
        }
        var nocontent2 = (jQ.trim(jQ("#autoSuggestionsList2 li:nth-child(1)").html())); //取“未找到符合条件的结果”的文字

        if (currKey == 40 && tempid2 > 0 && nocontent2 !== "未找到符合条件的结果") //向下 如果没有子结点就不显示提示框
        {
            document.getElementById("autoSuggestionsList2").style.display = "block";
            publicnum2 += 1;
            if (tempid2 < publicnum2) {
                publicnum2 = 1;
            }
            jQ("#autoSuggestionsList2 li").removeClass("Listhover");
            jQ("#autoSuggestionsList2 li").removeClass("Listhover1");
            jQ("#autoSuggestionsList2 li:nth-child(" + publicnum2 + ")").addClass("Listhover");

            jQ("#hid2").attr("value", (jQ.trim(jQ("#autoSuggestionsList2 li:nth-child(" + publicnum2 + ")").children("span:nth-child(1)").html())));
            jQ("#stockcode").attr("value", (jQ.trim(jQ("#hid2").val())));
            try {
                jQ("#hstockname2").attr("value", (jQ.trim(jQ("#autoSuggestionsList2 li:nth-child(" + publicnum2 + ")").children("span:nth-child(2)").html())));
            }
            catch (e)
			          { }
            jQ("#hindex2").attr("value", publicnum2);
        }
        else if (currKey == 38 && tempid2 > 0 && nocontent2 !== "未找到符合条件的结果") //向上
        {
            document.getElementById("autoSuggestionsList2").style.display = "block";
            publicnum2 -= 1;
            if (publicnum2 < 1) {
                publicnum2 = tempid2;
            }
            jQ("#autoSuggestionsList2 li").removeClass("Listhover");
            jQ("#autoSuggestionsList2 li").removeClass("Listhover1");
            jQ("#autoSuggestionsList2 li:nth-child(" + publicnum2 + ")").addClass("Listhover");

            jQ("#hid2").attr("value", (jQ.trim(jQ("#autoSuggestionsList2 li:nth-child(" + publicnum2 + ")").children("span:nth-child(1)").html())));
            jQ("#stockcode").attr("value", (jQ.trim(jQ("#hid2").val())));
            try {
                jQ("#hstockname2").attr("value", (jQ.trim(jQ("#autoSuggestionsList2 li:nth-child(" + publicnum2 + ")").children("span:nth-child(2)").html())));
            }
            catch (e)
			              { }
            jQ("#hindex2").attr("value", publicnum2);

        }
        else if (currKey == 13 && tempid2 > 0 && nocontent !== "未找到符合条件的结果") //回车
        {
            if (publicnum2 == 1 && document.getElementById("autoSuggestionsList2").style.display == "block") //默认点回车选1个结果
            {
                jQ("#stockcode").attr("value", (jQ.trim(jQ("#autoSuggestionsList2 li:nth-child(1)").children("span:nth-child(1)").html())));
                try {
                    jQ("#stockname").attr("value", (jQ.trim(jQ("#autoSuggestionsList2 li:nth-child(1)").children("span:nth-child(2)").html())));
                }
                catch (e)
			            { }
                jQ("#hid2").attr("value", (jQ.trim(jQ("#stockcode").val())));
            }
            else {
                jQ("#stockcode").attr("value", (jQ.trim(jQ("#hid2").val())));
                try {
                    jQ("#stockname").attr("value", (jQ.trim(jQ("#hstockname2").val())));
                }
                catch (e)
			             { }
            }

            try {
                jQ('#aLinkOfStock').html("<a href='../Track3/LogAnalyzers/Loghome.aspx?ztype=2&code=" + jQ.trim(jQ("#hid2").val()) + "' target='_blank'>" + jQ.trim(jQ("#stockname").val()) + "[" + jQ.trim(jQ("#hid2").val()) + "]</a>");

                lookup23((jQ.trim(jQ("#stockcode").val())));
            }
            catch (e) { }

            publicnum2 = 1; //使其跳到第一个
            jQ("#autoSuggestionsList2 li").removeClass("Listhover");
            jQ("#autoSuggestionsList2 li").removeClass("Listhover1");
            jQ("#autoSuggestionsList2 li:nth-child(1)").addClass("Listhover");
            document.getElementById("autoSuggestionsList2").style.display = "none";
            return false;
        }
    }
    else if (document.activeElement.id == "emailBox") {
        var tempid3 = 0; //存放兼容FF的子结点数量   
        tempid3 = document.getElementById("autoSuggestionsList3").getElementsByTagName("li").length;

        // tempid=tempid+1;
        var nocontent3 = (jQ.trim(jQ("#autoSuggestionsList3 li:nth-child(1)").html())); //取“未找到符合条件的结果”的文字

        if (currKey == 40 && tempid3 > 0 && nocontent3 !== "未找到符合条件的结果") //向下 如果没有子结点就不显示提示框
        {

            document.getElementById("autoSuggestionsList3").style.display="block";
            
            publicmailnum += 1;
            if (tempid3 < publicmailnum) {
                publicmailnum = 1;
            }
            jQ("#autoSuggestionsList3 li").removeClass("Listhover");
            jQ("#autoSuggestionsList3 li").removeClass("Listhover1");
            jQ("#autoSuggestionsList3 li:nth-child(" + publicmailnum + ")").addClass("Listhover");

            jQ("#hid3").attr("value", (jQ.trim(jQ("#autoSuggestionsList3 li:nth-child(" + publicmailnum + ")").html())));
            jQ("#emailBox").attr("value", (jQ.trim(jQ("#hid3").val())));
            jQ("#hindex3").attr("value", publicmailnum); 
        }
        else if (currKey == 38 && tempid3 > 0 && nocontent3 !== "未找到符合条件的结果") //向上
        {
            document.getElementById("autoSuggestionsList3").style.display = "block";

            publicmailnum -= 1;
            if (publicmailnum < 1) {
                publicmailnum = tempid3;
            }
            jQ("#autoSuggestionsList3 li").removeClass("Listhover");
            jQ("#autoSuggestionsList3 li").removeClass("Listhover1");
            jQ("#autoSuggestionsList3 li:nth-child(" + publicmailnum + ")").addClass("Listhover");

            jQ("#hid3").attr("value", (jQ.trim(jQ("#autoSuggestionsList3 li:nth-child(" + publicmailnum + ")").html())));
            jQ("#emailBox").attr("value", (jQ.trim(jQ("#hid3").val())));
            jQ("#hindex3").attr("value", publicmailnum);

        }
        else if (currKey == 13 && tempid3 > 0 && nocontent3 !== "未找到符合条件的结果") //回车
        {
            jQ("#emailBox").focus();
            if (publicmailnum == 1 && document.getElementById("autoSuggestionsList3").style.display == "block") //默认点回车选1个结果
            {
                jQ("#emailBox").attr("value", (jQ.trim(jQ("#autoSuggestionsList3 li:nth-child(1)").html())));
                jQ("#hid3").attr("value", (jQ.trim(jQ("#emailBox").val())));
            }
            else {
                jQ("#emailBox").attr("value", (jQ.trim(jQ("#hid3").val())));
            }
            //使用其跳到其它焦点
            jQ("#hid3").focus();
            //使用焦点文字右边
            jQ("#emailBox").focus(function() { jQ("#emailBox").val(jQ("#hid3").val()); });
            jQ("#emailBox").focus();

            publicmailnum = 1; //使其跳到第一个
            jQ("#autoSuggestionsList3 li").removeClass("Listhover");
            jQ("#autoSuggestionsList3 li").removeClass("Listhover1");
            jQ("#autoSuggestionsList3 li:nth-child(1)").addClass("Listhover");
            document.getElementById("autoSuggestionsList3").style.display = "none";

            return false;




        }
    }
}
document.onkeydown = keyDown; //绑定事件

function keydowncode() {
    if (keyallcode == 13 || keyallcode == 40 || keyallcode == 38 || keyallcode == 37 || keyallcode == 39) {
    }
    else {

        try {
            if ((jQ.trim(jQ("#txtCode").val())).length == 0 || !testValidateValue()) {
                publicnum = 1;
                document.getElementById("autoSuggestionsList").style.display = "none";
            }
            else {

                document.getElementById("autoSuggestionsList").style.display = "block";

                jQ.ajax(
              {

                  type: "GET",
                  url: "/Public/StockSearch.aspx",
                  data: "QS=" + encodeURI((jQ.trim(jQ("#txtCode").val()))),
                  dataType: "html",
                  success:
                function(msg) {
                    jQ("#autoSuggestionsList").html(msg);
                    publicnum = 1;
                }
              }
            )
            }
        }
        catch (e) { }
    }
}
function lostfocus() {
    //jQ("#autoSuggestionsList").hide(1500); //加长时间，让click处理操作
    setTimeout('hidesearchdiv("autoSuggestionsList")',1500);
   // document.getElementById("autoSuggestionsList").style.display = "none";
    publicnum = 1;
}
function changefocus() {
    //if(keyallcode==13||keyallcode==40||keyallcode==38)
    jQ("#hid").attr("value", jQ("#txtCode").val());
}


function lookup23(vflag) {
    try {
        if (vflag.length > 0 && testValidateValue()) {
            //            var url ='../Public/QuestionOfStock.aspx';
            //            var pars = 'SCODE=' + vflag;
            //            var myAjax = new Ajax.Request(url,{method: 'get', parameters: pars, onSuccess: OnSuc} );
            //	        function OnSuc(originalRequest1222)
            //	        {
            //	           var Dom=originalRequest1222.responseText;
            //	           jQ('#divQuestionsOfStock').show();
            //	           jQ('#divQuestionsOfStock').html(Dom);
            //            }	

            //JSON
            var param = { SCODE: encodeURI(vflag) };
            jQ.ajax(
            {
                type: "GET",
                url: "/Public/QuestionOfStock.aspx",
                data: param,
                dataType: "html",
                success:
              function(msg) {
                document.getElementById("divQuestionsOfStock").style.display = "block";
                  jQ('#divQuestionsOfStock').html(msg);
              }
            }
            )
        }
    }
    catch (e) {
        //alert(e);
    }
}

//非法字符校验
function testValidateValue() {
    //alert('ok');
    var aa = /^(?:[\u4e00-\u9fa5]*\w*\s*)+$/;
    var name = jQ.trim(jQ("#txtCode").val());
    if (!aa.test(name)) {
        // document.getElementById("ischar").value="1";
        //alert('ok 1');
        return false;
    }
    else {
        // document.getElementById("ischar").value="0";
        //alert('ok 0');
        return true;
    }
}

function handlerFocus(tp) {
    //alert(tp);
    if (tp == 'ok') {
        //okFn();
        jQ('#txtCode').focus();
    }
    if (tp == 'cancel') {
        //cancelFn();
        jQ('#txtCode').focus();
    }
    if (tp == 'close') {
        //closeFn()
        jQ('#txtCode').focus();
    }
}
	

