﻿/// <reference path="dyk-ui-config.js" />
/// <reference path="dyk-ui-global.js" />
/// <reference path="dyk-ui-base.js" />
/// <reference path="dyk-ui-history.js" />
/// <reference path="dyk-ui.quote.js" />

function getEleById(a) {
    return document.getElementById(a)
}
function switchTab(identify, index, count, cnon, cnout) {
    for (i = 0; i < count; i++) {
        var CurTabObj = document.getElementById("Tab_" + identify + "_" + i);
        var CurListObj = document.getElementById("List_" + identify + "_" + i);
        if (i != index) {
            CurTabObj.className = cnout;
            CurListObj.style.display = "none";
        }
    }
    document.getElementById("Tab_" + identify + "_" + index).className = cnon;
    document.getElementById("List_" + identify + "_" + index).style.display = "";
}

function addFavorite(sURL, sTitle) {
    try {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

var MiniSite = new Object();
MiniSite.Browser = {
    ie: /msie/.test(window.navigator.userAgent.toLowerCase()),
    moz: /gecko/.test(window.navigator.userAgent.toLowerCase()),
    opera: /opera/.test(window.navigator.userAgent.toLowerCase()),
    safari: /safari/.test(window.navigator.userAgent.toLowerCase())
};
MiniSite.JsLoader = {
    load: function (sUrl, charset, fCallback) {
        var _script = document.createElement('script');
        _script.setAttribute('charset', charset);
        _script.setAttribute('type', 'text/javascript');
        _script.setAttribute('src', sUrl);
        document.getElementsByTagName('head')[0].appendChild(_script);
        if (MiniSite.Browser.ie) {
            _script.onreadystatechange = function () {
                if (this.readyState == 'loaded' || this.readyState == 'complete') {
                    setTimeout(function () { try { fCallback(); } catch (e) { } }, 50);
                }
            };
        }
        else if (MiniSite.Browser.moz) {
            _script.onload = function () {
                setTimeout(function () { try { fCallback(); } catch (e) { } }, 50);
            };
        }
        else {
            setTimeout(function () { try { fCallback(); } catch (e) { } }, 50);
        }
    }
};


String.prototype.LTrim = function () { return LTrim(this); }
function LTrim(str) {
    var i;
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) != " " && str.charAt(i) != " ") break;
    }
    str = str.substring(i, str.length);
    return str;
}
function check() {

    var s_doc = document.getElementById("keyword") || {};
    var s_key = s_doc.value;
    s_key = strip_tags(s_key.LTrim()).replace(/&nbsp;/gi, '').replace(/(^\s*)|(\s*$)/g, '');
    s_key = s_key.replace(/(\/)|(\\)|(\")|(\')/g, '');
    if (s_key == (s_doc.label || "") || s_key == "") {
        alert("请输入搜索关键字!");
        document.getElementById("keyword").value = "";
        document.getElementById("keyword").focus();
        return false;
    }
    document.getElementById("keyword").value = s_key;

    if (location.href.toLowerCase().indexOf('http://search.xunlei.com/') < 0) {
        getEleById("searchForm").target = "_blank";
    } else {
        getEleById("searchForm").target = "_self";
    }
    return true;

}
function strip_tags(html) {

    //PROCESS STRING
    if (arguments.length < 3) {
        html = html.replace(/<\/?(?!\!)[^>]*>/gi, '');
    } else {
        var allowed = arguments[1];
        var specified = eval("[" + arguments[2] + "]");
        if (allowed) {
            var regex = '</?(?!(' + specified.join('|') + '))\b[^>]*>';
            html = html.replace(new RegExp(regex, 'gi'), '');
        } else {
            var regex = '</?(' + specified.join('|') + ')\b[^>]*>';
            html = html.replace(new RegExp(regex, 'gi'), '');
        }
    }

    //CHANGE NAME TO CLEAN JUST BECAUSE 
    var clean_string = html;

    //RETURN THE CLEAN STRING
    return clean_string;
}


var LAZY = function () {
    function a() {
        if (f) return "";
        b()
    }
    function b() {
        var e = {},
		g = {};
        e.Top = document.body.scrollTop + document.documentElement.scrollTop;
        e.Left = document.documentElement.scrollLeft;
        g.Top = e.Top + document.documentElement.clientHeight;
        g.Left = e.Left + document.documentElement.clientWidth;
        for (var j in h) {
            if (h[j]) {
                var l = h[j],
			        m = document.getElementById(j),
			        k = m.clientWidth,
			        o = m.clientHeight,
			        n = d(m);
                if (n.Top >= e.Top && n.Top <= g.Top && n.Left >= e.Left && n.Left <= g.Left || n.Top + o >= e.Top && n.Top <= g.Top && n.Left + k >= e.Left && n.Left <= g.Left) {
                    (function (p, q) {
                        setTimeout(function () {

                            //图片加载失败
                            p.onerror = function () {

                                if (p.src && p.src.indexOf(DouYaoKanUI.引用.图片库.默认背景文件) == -1) {
                                    p.src = DouYaoKanUI.引用.图片库.默认背景文件;
                                }
                            }
                            p.src = q;
                        },
					100)
                    })(m, l.src);
                    delete h[j]
                }
            }
        }
    }
    function d(e) {
        for (var g = { Top: 0, Left: 0 }; e; ) {
            g.Top += e.offsetTop;
            g.Left += e.offsetLeft;
            e = e.offsetParent
        }
        return g
    }
    var f = null,
	h = {};
    return {
        init: function () {
            for (var e = 0; e < document.images.length; e++) {
                var g = document.images[e],
				j = {};
                j.id = g.id;
                j.src = g.getAttribute("_src");
                if (j.src && !j.id) {
                    j.id = "lazy-image-" + (e + 1); //Math.random()
                    g.id = j.id
                }
                j.id && j.src && LAZY.push(j)
            }

            g = document.body.getElementsByTagName("iframe");
            for (e = 0; e < g.length; e++) {
                j = {};
                j.id = g[e].id;
                j.src = g[e].getAttribute("_src");
                if (j.src && !j.id) {
                    j.id = "lazy-iframe-" + (e + 1); //Math.random()
                    g[e].id = j.id
                }
                j.id && j.src && LAZY.push(j)
            }
        },
        push: function (e) {
            h[e.id] = e
        },
        run: function () {
            var e = window;
            if (e.addEventListener) e.addEventListener("scroll", a, false);
            else if (e.attachEvent) e.attachEvent("onscroll", a);
            else e.onscroll = a;
            b()
        }
    }
} ();
