﻿//将png图片透明
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6. 
{
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])
    if ((version >= 5.5) && (document.body.filters)) {
        for (var j = 0; j < document.images.length; j++) {
            var img = document.images[j]
            var imgName = img.src.toUpperCase()
            if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
                var imgID = (img.id) ? "id='" + img.id + "' " : ""
                var imgClass = (img.className) ? "class='" + img.className + "' " : ""
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
                var imgStyle = "display:inline-block;" + img.style.cssText
                if (img.align == "left") imgStyle = "float:left;" + imgStyle
                if (img.align == "right") imgStyle = "float:right;" + imgStyle
                if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
                var strNewHTML = "<span " + imgID + imgClass + imgTitle
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
                img.outerHTML = strNewHTML
                j = j - 1
            }
        }
    }
}

function out(i) {
    var div = document.getElementById("d" + i);
    div.style.display = "none";
    //    $("#d"+i).fadeOut("slow");
//    $("#d" + i).slideUp("slow");
}

function over(i) {
    var div = document.getElementById("d" + i);
    div.style.display = "block";
    //    $("#d" + i).fadeIn("slow");
  //  $("#d" + i).slideDown("slow");
}


window.onload = function() {
    correctPNG();
}
//关键字输入框id，和语言版本id  L
function searchFunction(id,L) {
    var key = $("#" + id).val();
    if (key == "") {
        if (L == 1) {
            alert("关键字不能为空！");
        }
        else if (L == 2) {
        alert("Keyword is empty!"); 
        }
    }
    else {
        location.href = "Search.aspx?keyword=" + key;
    }
}
//仿百度搜索

var currentRow = -1;
var TotalRows = 0;
function kyup(event) {
    e = window.event || event;
    if (e.keyCode == 40 || e.which == 40||e.keyCode == 38 || e.which == 38) {
        return;
    }


    $.ajax({
        type: "GET",
        url: "baidu.ashx",
        data: "keywords=" + $("#keyword").val() + "&LTid=" + $("#LTidInput").val(),
        success: function(d) {
            if (d == "") {
                $("#result").hide();
            }
            else {
                currentRow = -1;
                var s = "<ul style=\" list-style-type:none; margin:0px;  padding:0px; width:110px; font-size:12px;\">";
                var l = d.split('|');
                for (var i = 0; i < l.length; i++) {
                    var ll = l[i].split(',');
                    s += "<li style=\" width:100%; height:25px;line-height:25px; text-align:center;\" id=\"l" + i + "\" title=\"" + ll[1] + "," + ll[2] + "\">" + ll[0] + "</li>";
                }
                s += "</ul>";
                $("#result").html(s);
                TotalRows = l.length;
                //控制结果的高度
                if (l.length > 7) {
                    $("#result").css({ height: "150px", overflow: "auto" });
                }
                else {
                    $("#result ul").css({ width: "110px" });
                    $("#result").css({ height: "auto", overflow: "hidden" });
                }
                $("#result").show();
                $("#result li")
                        .mouseover(function() {
                            $("#l" + currentRow).removeClass("l1").addClass("l2");
                            $(this).removeClass("l2").addClass("l1");
                            //$(this).addClass("l1");
                            //  $("#keyword").val($(this).html());
                            currentRow = parseInt($(this).attr("id").replace("l", ""));
                        })
                        .mouseout(function() { $(this).removeClass("l1"); $(this).addClass("l2"); })
                        .click(function() {
                            // $("#keyword").val($(this).html()); $("#result").html("").hide(); TotalRows = 0;
                            var PidandDTid = $(this).attr("title").split(',');
                            location.href = "showProduct.aspx?Pid=" + PidandDTid[0];
                        })
            }
        }
    })};
    document.onclick = function() { $("#result").html("").hide(); TotalRows = 0; };
    document.onkeydown = function(event) {
        e = window.event || event;
        if (e.keyCode == 40 || e.which == 40) {
            currentRow = currentRow + 1;
            //$("#keyword").blur();
        }
        else if (e.keyCode == 38 || e.which == 38) {
            if (currentRow > 0) {
                currentRow -= 1;
            }
           //$("#keyword").blur();
        }
        if (currentRow >= TotalRows) currentRow = TotalRows - 1;
        else {
            if (TotalRows != 0) {
                if (e.keyCode == 40 || e.which == 40) {
                    $("#l" + currentRow).removeClass("l2").addClass("l1");
                    $("#l" + (currentRow - 1)).removeClass("l1").addClass("l2");
                    if (document.getElementById("l" + currentRow).offsetTop > document.getElementById("result").scrollTop + parseInt(document.getElementById("result").style.height.replace("px", "")) - 25) {
                        //25为li的高度
                        document.getElementById("l" + currentRow).scrollIntoView(false);
                    }
                    //$("#keyword").val($("#l" + currentRow).html());
                    
                }
                else if (e.keyCode == 38 || e.which == 38) {
                    $("#l" + currentRow).removeClass("l2").addClass("l1");
                    $("#l" + (currentRow + 1)).removeClass("l1").addClass("l2");
                    if (document.getElementById("l" + currentRow).offsetTop < document.getElementById("result").scrollTop) {
                        document.getElementById("l" + currentRow).scrollIntoView(true);
                    }
                   // $("#keyword").val($("#l" + currentRow).html());
                   
                }
                else if (e.keyCode == 13 || e.which == 13) {
                    $("#l" + currentRow).click();
                }

            }
        }
    };



//var currentNum = 1;
//var liwidth = 71;
//var SetIntval;
//var fx = -1; //方向 -1向右，1向左
//function leftFun() {
//    clearInterval(SetIntval);
//    left();
//    SetIntval = setInterval(Intervalfun, 10000);
//}

//function rightFun() {
//    clearInterval(SetIntval);
//    right();
//    SetIntval = setInterval(Intervalfun, 10000);
//}

////向左
//function left() {
//     currentNum--;
//    if (currentNum < 3) {
//        if (currentNum <= 1) {
//            currentNum = 1;
//        }
//    }
//    else {
//        $("#imglist").animate({left: -(currentNum - 3) * liwidth + "px"}, 500);
//    }
//    $("#imglist ul li img").each(
//    function() {
//        $(this).css("border", "0px");
//    })
//    $("#imglist ul li img").eq(currentNum - 1).css("border", "1px solid #30508D");
//    changeSlide(currentNum);
//    displayText();
//}
////向右
//function right() {
//    var Totalcount = $("#pic div").size();
//    currentNum++;
//    if (currentNum >3) {
//        if (currentNum >= Totalcount) {
//            currentNum = Totalcount;
//        }
//        $("#imglist").animate({ left: -(currentNum - 3) * liwidth + "px" }, 500);
//    }
//    $("#imglist ul li img").each(
//    function() {
//      $(this).css("border", "0px");
//   })
//   $("#imglist ul li img").eq(currentNum - 1).css("border", "1px solid #30508D");
//   changeSlide(currentNum);
//   displayText();
//}
////文字的显示
//function displayText() {
//    var Totalcount = $("#pic div").size();
//    for (var t = 1; t <= Totalcount; t++) {
//        $("#div" + t).css("display", "none");
//    }
//    $("#div" + currentNum).css("display", "block");
//}
////小图片的事件
//function ImgClick(c) {
//    currentNum = c;
//    clearInterval(SetIntval);
//    $("#imglist ul li img").each(
//    function() {
//        $(this).css("border", "0px");
//    })
//    $("#imglist ul li img").eq(currentNum - 1).css("border", "1px solid #30508D");
//    changeSlide(currentNum);
//    displayText();
//    SetIntval = setInterval(Intervalfun, 10000);
//}

//滤镜
function changeSlide(i) {
    var transitions = new Array;
    transitions[0] = "progid:DXImageTransform.Microsoft.Fade(duration=1)";
    transitions[1] = "progid:DXImageTransform.Microsoft.Blinds(Duration=1,bands=20)";
    transitions[2] = "progid:DXImageTransform.Microsoft.Checkerboard(Duration=1,squaresX=20,squaresY=20)";
    transitions[3] = "progid:DXImageTransform.Microsoft.Strips(Duration=1,motion=rightdown)";
    transitions[4] = "progid:DXImageTransform.Microsoft.Barn(Duration=1,orientation=vertical)";
    transitions[5] = "progid:DXImageTransform.Microsoft.GradientWipe(duration=1)";
    transitions[6] = "progid:DXImageTransform.Microsoft.Iris(Duration=1,motion=out)";
    transitions[7] = "progid:DXImageTransform.Microsoft.Wheel(Duration=1,spokes=12)";
    transitions[8] = "progid:DXImageTransform.Microsoft.Pixelate(maxSquare=10,duration=1)";
    transitions[9] = "progid:DXImageTransform.Microsoft.RadialWipe(Duration=1,wipeStyle=clock)";
    transitions[10] = "progid:DXImageTransform.Microsoft.RandomBars(Duration=1,orientation=vertical)";
    transitions[11] = "progid:DXImageTransform.Microsoft.Slide(Duration=1,slideStyle=push)";
    transitions[12] = "progid:DXImageTransform.Microsoft.RandomDissolve(Duration=1,orientation=vertical)";
    transitions[13] = "progid:DXImageTransform.Microsoft.Spiral(Duration=1,gridSizeX=40,gridSizeY=40)";
    transitions[14] = "progid:DXImageTransform.Microsoft.Stretch(Duration=1,stretchStyle=push)";
    transitions[15] = "special case";
    var transition_count = 15;
    if (document.all) {
        var do_transition;
        do_transition = Math.floor(Math.random() * transition_count);
        document.getElementById("pic").style.filter = transitions[do_transition];
        document.getElementById("pic").filters[0].Apply();
    }
    if (document.all) {
        for (var j = 1; j <= $("#pic div").size(); j++) {
            if (j == i) {
                $("#pic div").eq(j-1).css("display", "block")
            }
            else {
                $("#pic div").eq(j-1).css("display", "none")
            }
         }
        document.getElementById("pic").filters[0].Play();
    }
    else {
        i = i- 1;
        $("#pic div").fadeOut(1500).parent().children().eq(i).fadeIn(1500);
       
    }
   
}


//打开新窗口
function openwindow(url,w,h) {
    window.open(url, "", "height="+h+",width="+w+",toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no,top=" + (screen.availHeight - h) / 2 + ",left=" + (screen.availWidth - w) / 2 + "");
}
//加入收藏夹
function AddFavorite(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

