﻿//初始化页面
function PageLoad() {
    // getLoginUserInfo_Menu();//加载用户菜单
    LoadBanner(); //加载横幅

    //GetBanner("ILBanner", "Index_Content", 1, 193, 124);//底部广告
    //GetBanner("IFBanner", "Index_Footer", 1, 960, 80);//左侧广告
}
//控制搜索框的事件
//定义是否是点击了搜索框

var searchover = true;
function ShowTips_Home(istrue) { IsFirst = false; if (istrue) { $("SearchTips").style.display = "block"; } else { $("SearchTips").style.display = "none"; } }

//当鼠标移入弹出层时 显示弹出层
function OpenSearchTips_Home() { if (!IsFirst) $("SearchTips").style.display = "block"; }
//初始化IsFirst
function UpdateIsFirst_Home() { IsFirst = true; }

function SearchTipsover() {
    searchover = false;
    $("SearchTips").style.display = "block";
}

function SearchTipsout() {
    searchover = true;
    $("SearchTips").style.display = "none";
}

//加载横幅
function LoadBanner() {
    //    try {
    //        //获取横幅
    //        var banner = new Banner();
    //        var list = banner.Get("HeaderBanner");
    //        for (var i = 0; i < list.length; i++) {
    //            var Alink = $CE("A");
    //            Alink.href = list[i].Url;
    //            Alink.innerHTML = list[i].Title;
    //            //Alink.target = "_blank";
    //            $("HeaderBanner_" + (i + 1)).title = list[i].Description;
    //            $("HeaderBanner_" + (i + 1)).onclick = function() {
    //                window.location.href = $(this.id.replace("HeaderBanner_", "Banner_")).getElementsByTagName("A").item(0).href;
    //            }
    //            $("HeaderBanner_" + (i + 1)).style.backgroundImage = "url('" + list[i].ImageUrl + "')";
    //            var li = $CE("LI");
    //            li.id = "Banner_" + (i + 1);
    //            if (i == 0)
    //                li.className = "sli";
    //            li.appendChild(Alink);
    //            li.onmousemove = function() {
    //                for (var i = 1; i < 4; i++) {
    //                    $("HeaderBanner_" + (i)).style.display = "none";
    //                    $("Banner_" + (i)).className = "";
    //                }
    //                $("HeaderBanner_" + (this.id.split('_')[1])).style.display = "block";
    //                this.className = "sli";
    //            }
    //            $("HeaderBannerTitle").appendChild(li);
    //        }
    //    } catch (e) { }   
    te = setTimeout(function() { SwitchBanner(1, "false") }, SwitchTime);
}

function ShowBanner(obj) {
    window.location.href = $(obj.id.replace("HeaderBanner_", "Banner_")).getElementsByTagName("A").item(0).href;
}

//广告切换
var SwitchTime = 5000;
var te;
function SwitchBanner(id, co) {
    if (co == "true") {
        clearTimeout(te);
    }
    try {
        id++;
        if (id > 3)
            id = 1;
        for (var i = 1; i < 4; i++) {
            $("HeaderBanner_" + (i)).style.display = "none";
            $("Banner_" + (i)).className = "";
        }
        $("HeaderBanner_" + (id)).style.display = "block";
        $("Banner_" + (id)).className = "sli";
    } catch (e) { }
    te = setTimeout(function() { SwitchBanner(id, "false") }, SwitchTime);
}
//FAQ栏目切换
function FQAConvert(model) {
    $("faqfaq").style.display = "none"; $("faqseller").style.display = "none"; $("faqbuyer").style.display = "none"; $("faqtrade").style.display = "none";
    $("faqmfaq").className = "faq_fMenu faq_Menu"; $("faqmseller").className = " faq_Menu"; $("faqmbuyer").className = "faq_Menu"; $("faqmtrade").className = "faq_Menu";
    $("faq" + model).style.display = "block";
    if (model == "faq")
        $("faqm" + model).className = "faq_sfMenu faq_fMenu faq_Menu";
    else
        $("faqm" + model).className = ((model != "seller") ? "faq_sMenu" : "faq_sMenu faq_Menulb") + " faq_Menu";
}
//最新更新滚动
function UpdateTrade(ul, pos) {
    try {
        var TIME = 7000; //7妙滚动下一批数据
        ul[0].onmousemove = function() { this.nodevalue = true; this.onmouseout = function() { this.nodevalue = false; } }
        ul[1].onmousemove = ul[0].onmousemove;

        if (pos == 0 && arguments[2] == undefined) { setTimeout(function() { UpdateTrade(ul, -1, 0) }, TIME); return; }
        if (!ul[0].nodevalue && !ul[1].nodevalue) pos = pos - 1;
        ul.item(0).getElementsByTagName("li").item(0).style.marginTop = (pos) + "px";
        ul.item(1).getElementsByTagName("li").item(0).style.marginTop = (pos) + "px";

        //$("updatetime").innerHTML = 
        if ((pos % 110) != 0)
            setTimeout(function() { UpdateTrade(ul, pos) }, 10);
        else {
            if (pos == -550) {//550
                pos = 0;
                var li1 = ul[0].getElementsByTagName("LI");
                var li2 = ul[1].getElementsByTagName("LI");
                var count = 0;
                for (var i = 0; i < 30; i++) {
                    if (count == 25)
                        break;
                    if (i == 0) {
                        try { li1[0].style.marginTop = "0px"; } catch (e) { }
                        try { li2[0].style.marginTop = "0px"; } catch (e) { }
                    }
                    try { ul[0].appendChild(li1[0]); } catch (e) { }
                    try { ul[1].appendChild(li2[0]); } catch (e) { }

                    count++;
                }
            }
            setTimeout(function() { UpdateTrade(ul, pos, 0) }, TIME);
        }
    }
    catch (e) { }
}

//搜索栏目切换按钮
function SearchMode(sender) {
    var li = sender.parentNode.getElementsByTagName("LI");
    for (var i = 0; i < li.length; i++) {
        li[i].className = "";
    }
    sender.className = "s_li";
    $("SearchBar").value = "Search " + sender.getElementsByTagName("A")[0].innerHTML + " Number of Keyword";
}


function ShowCategories(sender, id) {
    document.getElementById("c_list_sub_" + id).style.display = "block";
    var sub_div = document.getElementById("c_list_sub_" + id);
    sub_div.onmouseover = function() {
        sender.getElementsByTagName("a").item(0).className = "select";
    }
    sub_div.onmouseout = function() {
        sub_div.style.display = "none";
        sender.getElementsByTagName("a").item(0).className = "";
    }
    sender.onmouseout = function() {
        document.getElementById("c_list_sub_" + id).style.display = "none";
        sender.removeAttribute("class");
    }
}

function moreCategory(sender) {
    var isshow = false;
    if ($("moreCategory").innerHTML == "Less Categories &gt;&gt;&gt;") {
        $("moreCategory").innerHTML = "More Categories >>>";
        $("categorieslist").style.height = "519px";
        isshow = false;
    }
    else {
        $("moreCategory").innerHTML = "Less Categories >>>";
        $("categorieslist").style.height = "770px";
        isshow = true;
    }

    moreCategoryNext(sender.parentNode.nextSibling, isshow);
}
function moreCategoryNext(node, isshow) {
    if (!node || node.tagName != "LI")
        return;
    node.style.display = isshow ? "block" : "none";
    moreCategoryNext(node.nextSibling, isshow);
}


//调用广告
function GetBanner(TagID, PaddingID, BannerCount, width, height) {
    var xmlDoc = undefined;
    if (GetBrowserInfo().is_saf) {
        var ajax = new Ajax();
        ajax.GetXML("/XML/IBD_Banner.xml", function() {
            xmlDoc = arguments[0];
        }, true);
    } else {
        xmlDoc = CreateXMLDOMObject("/XML/IBD_Banner.xml", false);
    }
    var cNodes = xmlDoc.getElementsByTagName("rowbanner");
    var paddingCount = 0;
    for (var r = 0; r < cNodes.length; r++) { //刷选记录
        if (cNodes[r].getAttribute("PaddingID") == PaddingID) {
            paddingCount++; //统计数量
        }
    }
    /////////////////
    var my_array = new Array();
    var bannerHTML = ""; //生成后的广告
    my_array = getArrayItems(paddingCount, BannerCount);
    for (var m = 0; m < paddingCount; m++) {
        for (var r = 0; r < cNodes.length; r++) {
            if (cNodes[r].getAttribute("PaddingID") == PaddingID && cNodes[r].getAttribute("SequenceNumbers") == my_array[m]) {
                if (cNodes[r].getAttribute("Url") == "" || cNodes[r].getAttribute("Url") == null || cNodes[r].getAttribute("Url") == "#") //判断有没有url属性
                {
                    bannerHTML += "<img src=\"" + "/files/Images/Banner/" + cNodes[r].getAttribute("ImageUrl") + "\" width=\"" + width + "\" height=\"" + height + "\" class=\"styleBlock\" alt=\"" + cNodes[r].getAttribute("Title") + "\" title=\"" + cNodes[r].getAttribute("Description") + "\" />";
                } else { //有url 属性
                    bannerHTML += "<a href=\"" + cNodes[r].getAttribute("Url") + "\" target=\"_blank\" rel=\"nofollow\"><img src=\"" + "/files/Images/Banner/" + cNodes[r].getAttribute("ImageUrl") + "\" width=\"" + width + "\" height=\"" + height + "\" class=\"styleBlock\" alt=\"" + cNodes[r].getAttribute("Title") + "\" title=\"" + cNodes[r].getAttribute("Description") + "\" /></a>";
                }
            }
        }

    }
    document.getElementById(TagID).innerHTML = bannerHTML;
}

//随机返回num个不重复项 
function getArrayItems(arrlength, num) {
    //新建一个数组,将传入的数组复制过来,用于运算,而不要直接操作传入的数组; 
    var temp_array = new Array();

    var my_array = new Array();
    for (i = 0; i < arrlength; i++) {
        my_array[i] = +i;
    }
    for (var index in my_array) {
        temp_array.push(my_array[index]);
    }
    //取出的数值项,保存在此数组 
    var return_array = new Array();
    for (var i = 0; i < num; i++) {
        //判断如果数组还有可以取出的元素,以防下标越界 
        if (temp_array.length > 0) {
            //在数组中产生一个随机索引 
            var arrIndex = Math.floor(Math.random() * temp_array.length);
            //将此随机索引的对应的数组元素值复制出来 
            return_array[i] = temp_array[arrIndex];
            //然后删掉此索引的数组元素,这时候temp_array变为新的数组 
            temp_array.splice(arrIndex, 1);
        } else {
            //数组中数据项取完后,退出循环,比如数组本来只有10项,但要求取出20项. 
            break;
        }
    }
    return return_array;
}

function getLoginUserInfo_Menu() {
    setTimeout(function() {
        var parament = "?" + Math.random();
        var ajax = new Ajax(); //创建Ajax对象
        ajax.GetRequest("GetLoginUserInfo_Menu", "/Handle/userinfo.ashx", parament, function() {
            var strvalue = (arguments[0]);
            if (strvalue.length > 0) {
                document.getElementById("IndexMenu").innerHTML = strvalue;
            }
        }, false);
    }, 100);
}


function srcMarquee() {
    this.ID = document.getElementById(arguments[0]);
    if (!this.ID) { this.ID = -1; return; }
    this.Direction = this.Width = this.Height = this.DelayTime = this.WaitTime = this.Correct = this.CTL = this.StartID = this.Stop = this.MouseOver = 0;
    this.Step = 1;
    this.Timer = 10;
    this.DirectionArray = { "top": 0, "bottom": 1, "left": 2, "right": 3 };
    if (typeof arguments[1] == "number") this.Direction = arguments[1];
    if (typeof arguments[2] == "number") this.Step = arguments[2];
    if (typeof arguments[3] == "number") this.Width = arguments[3];
    if (typeof arguments[4] == "number") this.Height = arguments[4];
    if (typeof arguments[5] == "number") this.Timer = arguments[5];
    if (typeof arguments[6] == "number") this.DelayTime = arguments[6];
    if (typeof arguments[7] == "number") this.WaitTime = arguments[7];
    if (typeof arguments[8] == "number") this.ScrollStep = arguments[8];
    this.ID.style.overflow = this.ID.style.overflowX = this.ID.style.overflowY = "hidden";
    this.ID.noWrap = true;
    this.IsNotOpera = (navigator.userAgent.toLowerCase().indexOf("opera") == -1);
    if (arguments.length >= 5) this.Start();
}
srcMarquee.prototype.Start = function() {
    if (this.ID == -1) return;
    if (this.WaitTime < 7000) this.WaitTime = 7000;
    if (this.Timer < 20) this.Timer = 20;
    if (this.Width == 0) this.Width = parseInt(this.ID.style.width);
    if (this.Height == 0) this.Height = parseInt(this.ID.style.height);
    if (typeof this.Direction == "string") this.Direction = this.DirectionArray[this.Direction.toString().toLowerCase()];
    this.HalfWidth = Math.round(this.Width / 2);
    this.BakStep = this.Step;
    this.ID.style.width = this.Width;
    this.ID.style.height = this.Height;
    if (typeof this.ScrollStep != "number") this.ScrollStep = this.Direction > 1 ? this.Width : this.Height;
    var msobj = this;
    var timer = this.Timer;
    var delaytime = this.DelayTime;
    var waittime = this.WaitTime;
    msobj.StartID = function() { msobj.Scroll(); }
    msobj.Continue = function() {
        if (msobj.MouseOver == 1) {
            setTimeout(msobj.Continue, delaytime);
        }
        else {
            clearInterval(msobj.TimerID);
            msobj.CTL = msobj.Stop = 0;
            msobj.TimerID = setInterval(msobj.StartID, timer);
        }
    }
    msobj.Pause = function() {
        msobj.Stop = 1;
        clearInterval(msobj.TimerID);
        setTimeout(msobj.Continue, delaytime);
    }
    msobj.Begin = function() {
        msobj.ClientScroll = msobj.Direction > 1 ? msobj.ID.scrollWidth : msobj.ID.scrollHeight;
        if ((msobj.Direction <= 1 && msobj.ClientScroll < msobj.Height) || (msobj.Direction > 1 && msobj.ClientScroll < msobj.Width)) return;
        msobj.ID.innerHTML += msobj.ID.innerHTML;
        msobj.TimerID = setInterval(msobj.StartID, timer);
        if (msobj.ScrollStep < 0) return;
        msobj.ID.onmousemove = function(event) {
            if (msobj.ScrollStep == 0 && msobj.Direction > 1) {
                var event = event || window.event;
                if (window.event) {
                    if (msobj.IsNotOpera) { msobj.EventLeft = event.srcElement.id == msobj.ID.id ? event.offsetX - msobj.ID.scrollLeft : event.srcElement.offsetLeft - msobj.ID.scrollLeft + event.offsetX; }
                    else { msobj.ScrollStep = null; return; }
                }
                else { msobj.EventLeft = event.layerX - msobj.ID.scrollLeft; }
                msobj.Direction = msobj.EventLeft > msobj.HalfWidth ? 3 : 2;
                msobj.AbsCenter = Math.abs(msobj.HalfWidth - msobj.EventLeft);
                msobj.Step = Math.round(msobj.AbsCenter * (msobj.BakStep * 2) / msobj.HalfWidth);
            }
        }
        msobj.ID.onmouseover = function() {
            if (msobj.ScrollStep == 0) return;
            msobj.MouseOver = 1;
            clearInterval(msobj.TimerID);
        }
        msobj.ID.onmouseout = function() {
            if (msobj.ScrollStep == 0) {
                if (msobj.Step == 0) msobj.Step = 1;
                return;
            }
            msobj.MouseOver = 0;
            if (msobj.Stop == 0) {
                clearInterval(msobj.TimerID);
                msobj.TimerID = setInterval(msobj.StartID, timer);
            }
        }
    }
    setTimeout(msobj.Begin, waittime);
};
srcMarquee.prototype.Scroll = function() {
    switch (this.Direction) {
        case 0:
            this.CTL += this.Step;
            if (this.CTL >= this.ScrollStep && this.DelayTime > 0) {
                this.ID.scrollTop += this.ScrollStep + this.Step - this.CTL;
                this.Pause();
                return;
            }
            else {
                if (this.ID.scrollTop >= this.ClientScroll) { this.ID.scrollTop -= this.ClientScroll; }
                this.ID.scrollTop += this.Step;
            }
            break;
        case 1:
            this.CTL += this.Step;
            if (this.CTL >= this.ScrollStep && this.DelayTime > 0) {
                this.ID.scrollTop -= this.ScrollStep + this.Step - this.CTL;
                this.Pause();
                return;
            }
            else {
                if (this.ID.scrollTop <= 0) { this.ID.scrollTop += this.ClientScroll; }
                this.ID.scrollTop -= this.Step;
            }
            break;
        case 2:
            this.CTL += this.Step;
            if (this.CTL >= this.ScrollStep && this.DelayTime > 0) {
                this.ID.scrollLeft += this.ScrollStep + this.Step - this.CTL;
                this.Pause();
                return;
            }
            else {
                if (this.ID.scrollLeft >= this.ClientScroll) { this.ID.scrollLeft -= this.ClientScroll; }
                this.ID.scrollLeft += this.Step;
            }
            break;
        case 3:
            this.CTL += this.Step;
            if (this.CTL >= this.ScrollStep && this.DelayTime > 0) {
                this.ID.scrollLeft -= this.ScrollStep + this.Step - this.CTL;
                this.Pause();
                return;
            }
            else {
                if (this.ID.scrollLeft <= 0) { this.ID.scrollLeft += this.ClientScroll; }
                this.ID.scrollLeft -= this.Step;
            }
            break;
    }
};

///
/// Quality Supplier专用JS
/// @author yanjiaonan add by 2011-11-25
///
/// elementId：节点ID
/// speed：速度
/// waitTimer：间隔滚动时间
/// startTimer：等待启动时间
function SupplierScroll(elementId, speed, waitTimer, startTimer) {
    var msObject;
    if (msObject == undefined) {
        /**************初始化**************/
        msObject = function() { };
        msObject.Element = document.getElementById(elementId);
        msObject.UlElement = msObject.Element.children[0];
        msObject.LiHeight = msObject.UlElement.children[0].offsetHeight;
        msObject.ScrollHeight = msObject.UlElement.offsetHeight;
        msObject.Speed = speed;
        msObject.WaitTimer = waitTimer;
        msObject.StartTimer = startTimer;
        msObject.IsRun = false;
        msObject.IsOnMouse = false;
        msObject.TimerID = 0;
        msObject.Step = msObject.Index = msObject.Count = 0;
        if (msObject.ScrollHeight < msObject.Element.offsetHeight) {
            return;
        }
        var temp = msObject.UlElement.cloneNode(true);
        msObject.Element.appendChild(temp);
        /**************初始化**************/
        ///定义滚动函数
        msObject.Scroll = function() {
            msObject.IsRun = true;
            msObject.Step++;
            msObject.Index++;
            msObject.Element.scrollTop = msObject.Step;
            ///如果滚动高度大于等于总高度，则重启滚动
            if (msObject.Step >= msObject.ScrollHeight) {
                msObject.ReStart();
                return;
            }
            ///如果滚动高度等于一个LI
            if (msObject.Index == msObject.LiHeight) {
                msObject.NextScroll();
                return;
            }
        };
        ///重启函数
        msObject.ReStart = function() {
            msObject.IsRun = false;
            msObject.Step = msObject.Index = msObject.Count = msObject.Element.scrollTop = 0;
            msObject.ClearTimer();
        };
        ///滚动下一个函数
        msObject.NextScroll = function() {
            msObject.IsRun = false;
            msObject.Count++;
            msObject.Index = 0;
            if (msObject.Count == 3) {
                msObject.Count = 0;
                msObject.ClearTimer();
            }
        };
        ///清除定时器，按指定时间等待下次滚动
        msObject.ClearTimer = function() {
            clearInterval(msObject.TimerID);
            setTimeout(function() {
                msObject.BeginScroll();
            }, msObject.WaitTimer);
        };
        ///开始启动滚动函数
        msObject.BeginScroll = function() {
            msObject.TimerID = setInterval(msObject.Scroll, msObject.Speed);
        };
        ///鼠标移上去停止函数
        msObject.Element.onmouseover = function() {
            if (msObject.IsRun && msObject.IsOnMouse == false) {
                msObject.IsOnMouse = true;
                clearInterval(msObject.TimerID);
            }
        };
        ///鼠标移出启动函数
        msObject.Element.onmouseout = function() {
            if (msObject.IsRun && msObject.IsOnMouse) {
                msObject.IsOnMouse = false;
                msObject.BeginScroll();
            }
        };
        ///按指定时间后启动滚动
        setTimeout(msObject.BeginScroll, msObject.StartTimer);
    } else {
        setTimeout(msObject.BeginScroll, msObject.StartTimer);
    }
}
