﻿
var sign = 0;
var count = 0;

$(document).ready(
   function () {
       var signA = 0;

       $("#showSearchResult").hide();
       $(".showSearchResult_loading").css("display", "none");
       $(".searchbox_text").click(function () {
           $(this).fadeOut(300);
           $("#txtSearchTerms").focus();
       });

       $("input#txtSearchTerms,input#btnSearch,div#showSearchResult,.searchbox_text").click(
            function () {
                signA = 1
            }
           );

       $(document).click(
            function () {
                if (signA == 1) {
                    signA = 0;
                }
                else {
                    $("#txtSearchTerms").val("");
                    $("#showSearchResult").fadeOut(100);
                    $("#showSearchResult_remove").fadeOut(100);
                    $(".searchbox_text").fadeIn(300);
                }
            }
           );


   });


function onfocusValue() {
    if ($("#txtSearchTerms").val("") != null)
        //$("#txtSearchTerms").val("");
		$(".searchbox_text").fadeOut(300);
		
}

function onblurValue() {
   
    if (sign == 1 || count == 0){
       //$("#txtSearchTerms").val(searchstore());
		$(".searchbox_text").fadeIn(300);
		$("#txtSearchTerms").val("");
		}
      
}


function findProducts() {
    if ($("#txtSearchTerms").val().length >= 3) {
        jQuery.ajax({
            url: "/AddonsByOsShop/AjaxPages/getSearchProducts.aspx?" + new Date().getTime(), //加入时间 url欺骗 重新运行ajax
            type: "Get",
            data: 'txtSearchTerm=' + $("#txtSearchTerms").val(),
            beforeSend: function () {
                $(".showSearchResult_loading").css("display", "block");
            },
            success: function (data, statue) {

                var dataProduct = data + "";
                var strItem = new Array();
                var str = new Array();
                strItem = dataProduct.split("<!>"); //每个商品之间用 <!> 分割
                if (strItem.length > 1) {
                    $("#showSearchResult").empty(); //清空一起的div
                    count++; sign = 0;
                    $("#showSearchResult").append("<div class='showSearchResult_tips'><a>" + searchtips() +"</a></div>");
                    for (var i = 0; i < strItem.length - 1; i++) {
                        var re = new RegExp();
                        re = new RegExp($("#txtSearchTerms").val(), "gi"); //第二个参数,表示匹配时不分大小写

                        str = strItem[i].toString().split("|"); //商品的各个属性用 | 号隔开
                        var send = "<div class='showSearchResultBox'>" + "<div class='showSearchResult_left'>" + "<a href='" + str[3] + "'>" + "<img src=" + str[1] + "></img>" + "</a>" + "<b>" + "<a href='" + str[3] + "'>" + str[0].replace(re, "<font color='#e44097'>" + $("#txtSearchTerms").val() + "</font>") + "</a>" + "</b>" + "<p>" + str[2] + "</p>" + "</div>" + "<div class='showSearchResult_right'>" + "<p>" + str[4].replace(re, "<font color='#e44097'>" + $("#txtSearchTerms").val() + "</font>") + "</p>" + "</div>" + "</div>" + "<div class='clear'></div>";
                        $("#showSearchResult").append(send); //显示各个商品
                    }
                    $("#showSearchResult").fadeIn(200);
                    $("#showSearchResult_remove").fadeIn(200);
                    $(".showSearchResult_loading").css("display", "none");
                
                }
                else {
                    sign = 1;
                    $("#showSearchResult").hide();
                    $("#showSearchResult_remove").hide();
                    $(".showSearchResult_loading").css("display", "none");
                }


            }

        });
    }
    else {
        sign = 1;
        $("#showSearchResult").hide();
        $("#showSearchResult_remove").hide();
        $(".showSearchResult_loading").css("display", "none");
    }



}
