﻿Array.prototype.remove = function(index) {
    if (isNaN(index) || index > this.length || index < 0) { return false; }
    this.splice(index, 1);
}

String.prototype.remove = function(index, count) {
    if (typeof (count) != "number") count = 1;
    if (isNaN(index) || index > this.length || index < 0 || isNaN(count) || index + count > this.length || count < 0) { return this; }
    var t = this.substring(0, index);
    var e = this.substring(index + count);
    return t + e;
}

/*String.prototype.toString=function(){
var format=this;
var args=arguments;
format=format.replace(/\{(\d+)\}/ig, function($1,$2){return args[$2]});
return format;
}*/
String.prototype.len = function() {
    return this.replace(/[^\x00-\xff]/g, "**").length;
}

String.prototype.trim = function() {
    return this.replace(/(^\s+)|(\s+$)/g, "");
}
Date.prototype.toString = function() {
    if (arguments.length > 0) {
        var formatStr = arguments[0];
        var str = formatStr;
        str = str.replace(/yyyy|YYYY/, this.getFullYear());
        str = str.replace(/yy|YY/, (this.getFullYear() % 100) > 9 ? (this.getFullYear() % 100).toString() : "0" + (this.getFullYear() % 100));
        str = str.replace(/MM/, this.getMonth() + 1 > 9 ? (this.getMonth() + 1).toString() : "0" + (this.getMonth() + 1));
        str = str.replace(/M/g, (this.getMonth() + 1).toString());
        str = str.replace(/dd|DD/, this.getDate() > 9 ? this.getDate().toString() : "0" + this.getDate());
        str = str.replace(/d|D/g, this.getDate());
        str = str.replace(/hh|HH/, this.getHours() > 9 ? this.getHours().toString() : "0" + this.getHours());
        str = str.replace(/h|H/g, this.getHours());
        str = str.replace(/mm/, this.getMinutes() > 9 ? this.getMinutes().toString() : "0" + this.getMinutes());
        str = str.replace(/m/g, this.getMinutes());
        str = str.replace(/ss|SS/, this.getSeconds() > 9 ? this.getSeconds().toString() : "0" + this.getSeconds());
        str = str.replace(/s|S/g, this.getSeconds());
        return str;
    }
    else {
        return this.toLocaleString();
    }
}

Function.prototype.bind = function() {
    var __method = this, args = $A(arguments), object = args.shift();
    return function() {
        return __method.apply(object, args.concat($A(arguments)));
    }
}
var Form = {
    serialize: function(form) {
        var elements = Form.getElements($(form));
        var queryComponents = new Array();

        for (var i = 0; i < elements.length; i++) {
            var queryComponent = Form.Element.serialize(elements[i]);
            if (queryComponent)
                queryComponents.push(queryComponent);
        }

        return queryComponents.join('&');
    },

    getElements: function(form) {
        form = $(form);
        var elements = new Array();

        for (tagName in Form.Element.Serializers) {
            var tagElements = form.getElementsByTagName(tagName);
            for (var j = 0; j < tagElements.length; j++)
                elements.push(tagElements[j]);
        }
        return elements;
    },

    getInputs: function(form, typeName, name) {
        form = $(form);
        var inputs = form.getElementsByTagName('input');

        if (!typeName && !name)
            return inputs;

        var matchingInputs = new Array();
        for (var i = 0; i < inputs.length; i++) {
            var input = inputs[i];
            if ((typeName && input.type != typeName) ||
          (name && input.name != name))
                continue;
            matchingInputs.push(input);
        }

        return matchingInputs;
    },

    disable: function(form) {
        var elements = Form.getElements(form);
        for (var i = 0; i < elements.length; i++) {
            var element = elements[i];
            element.blur();
            element.disabled = 'true';
        }
    },

    enable: function(form) {
        var elements = Form.getElements(form);
        for (var i = 0; i < elements.length; i++) {
            var element = elements[i];
            element.disabled = '';
        }
    },

    findFirstElement: function(form) {
        return Form.getElements(form).find(function(element) {
            return element.type != 'hidden' && !element.disabled &&
        ['input', 'select', 'textarea'].include(element.tagName.toLowerCase());
        });
    },

    focusFirstElement: function(form) {
        Field.activate(Form.findFirstElement(form));
    },

    reset: function(form) {
        $(form).reset();
    }
}

Form.Element = {
    serialize: function(element) {
        element = $(element);
        var method = element.tagName.toLowerCase();
        var parameter = Form.Element.Serializers[method](element);

        if (parameter) {
            var key = encodeURIComponent(parameter[0]);
            if (key.length == 0) return;

            if (parameter[1].constructor != Array)
                parameter[1] = [parameter[1]];

            return parameter[1].map(function(value) {
                return key + '=' + encodeURIComponent(value);
            }).join('&');
        }
    },

    getValue: function(element) {
        element = $(element);
        var method = element.tagName.toLowerCase();
        var parameter = Form.Element.Serializers[method](element);

        if (parameter)
            return parameter[1];
    }
}

Form.Element.Serializers = {
    input: function(element) {
        switch (element.type.toLowerCase()) {
            case 'submit':
            case 'hidden':
            case 'password':
            case 'text':
                return Form.Element.Serializers.textarea(element);
            case 'checkbox':
            case 'radio':
                return Form.Element.Serializers.inputSelector(element);
        }
        return false;
    },

    inputSelector: function(element) {
        if (element.checked)
            return [element.name, element.value];
    },

    textarea: function(element) {
        return [element.name, element.value];
    },

    select: function(element) {
        return Form.Element.Serializers[element.type == 'select-one' ?
      'selectOne' : 'selectMany'](element);
    },

    selectOne: function(element) {
        var value = '', opt, index = element.selectedIndex;
        if (index >= 0) {
            opt = element.options[index];
            value = opt.value;
            if (!value && !('value' in opt))
                value = opt.text;
        }
        return [element.name, value];
    },

    selectMany: function(element) {
        var value = new Array();
        for (var i = 0; i < element.length; i++) {
            var opt = element.options[i];
            if (opt.selected) {
                var optValue = opt.value;
                if (!optValue && !('value' in opt))
                    optValue = opt.text;
                value.push(optValue);
            }
        }
        return [element.name, value];
    }
}

function $() {
    var elements = new Array();

    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        if (typeof element == 'string')
            element = document.getElementById(element);

        if (arguments.length == 1)
            return element;

        elements.push(element);
    }

    return elements;
}
var $A = Array.from = function(iterable) {
    if (!iterable) return [];
    if (iterable.toArray) {
        return iterable.toArray();
    } else {
        var results = [];
        for (var i = 0; i < iterable.length; i++)
            results.push(iterable[i]);
        return results;
    }
}

var $F = Form.Element.getValue;

function SetPathParam(name, value, url) {
    var re = new RegExp("^(http://[a-z0-9_.:]+)?/(\\w+)_(\\d+)(?:/|\\.html)?(\\?(?:.*))?$", "ig");
    var str = (typeof (url) == "string") ? url : self.location.href;
    var r = re.exec(str);
    if (r != null) {
        var host = (r[1] == null) ? "" : r[1]; //主机名(包括http://)
        var script = (r[2] == null) ? "" : r[2]; //脚本名
        var uid = (r[3] == null) ? "" : r[3]; //参数
        var params = (r[4] == null) ? "" : r[4]; //参数
        switch (script.toLowerCase()) {
            case "imagealbum":
            case "comiclist":
            case "animelist":
            case "myimagealbum":
                if (name.toLowerCase() == "id")
                    str = host + "/" + script + "_" + value + params;
                else
                    str = Func.SetParam(name, value, str);
                break;
            default:
                str = Func.SetParam(name, value, str);
                break;

        }
    }
    else {
        re = new RegExp("^(http://[a-z0-9_.:]+)?(/([a-z0-9_]+/)*)(comicinfo|comiclist|comicview|showarticle|articlelist|animeinfo|animelist|animeview|showalbum|albumlist)(/(.)+)?(/[^/]+.html.*)", "ig");
        var r = re.exec(str);
        //alert(str);
        if (r != null) {
            var host = (r[1] == null) ? "" : r[1]; //主机名(包括http://)
            var path = (r[2] == null) ? "" : r[2]; //路径
            var script = (r[4] == null) ? "" : r[4]; //脚本名
            var params = (r[5] == null) ? "" : r[5]; //参数
            var vscript = (r[7] == null) ? "" : r[7]; //最后的伪脚本名
            var findParam = false;
            var paramsArr;
            if (params.length == 0)
                params = "";
            paramsArr = params.split("/");
            for (var i = 1; i < paramsArr.length; i = i + 2) {
                if (i + 1 > paramsArr.length)
                    break;
                if (paramsArr[i].toLowerCase() == name.toLowerCase()) {
                    paramsArr[i + 1] = value;
                    findParam = true;
                    break;
                }
            }
            if (!findParam) {
                paramsArr.push(name);
                paramsArr.push(value);
            }
            params = "";
            for (var i = 1; i < paramsArr.length; i++) {
                params += "/" + paramsArr[i];
            }
            str = host + path + script + params + vscript;
        }
        else {
            str = Func.SetParam(name, value, str);
        }
    }
    return str;
}

function RemoveItem(select) {
    var len = select.options.length;
    for (var i = 0; i < len; i++) {
        select.remove(0);
    }
}

function SetDropDownListByValue(drop, value) {
    for (var i = 0; i < drop.options.length; i++) {
        if (drop.options[i].value == value) {
            drop.selectedIndex = i;
            break;
        }
    }
}

function ShowMessage(msg, url) {
    var rndID = "msgbox_" + String(Math.random()).replace(".", "_");
    var evt = "";
    if (url != "undefined") {
        if (url == -1 || url == "-1")
            evt = "history.back()";
        else if (typeof (url) == "string" && url.length > 0)
            evt = "location.href=\"" + url + "\"";
    }
    ModalDialog(rndID, "提示信息", msg, 3, evt);
}

function getScroll() {
    var t, l, w, h;
    if (document.documentElement && document.documentElement.scrollTop) {
        t = document.documentElement.scrollTop;
        l = document.documentElement.scrollLeft;
        w = document.documentElement.scrollWidth;
        h = document.documentElement.scrollHeight;
    }
    else if (document.body) {
        t = document.body.scrollTop;
        l = document.body.scrollLeft;
        w = document.body.scrollWidth;
        h = document.body.scrollHeight;
    }
    return { top: t, left: l, width: w, height: h };
}

function GetScrollPos() {
    var pos = { x: 0, y: 0 };
    if (typeof window.pageYOffset != 'undefined') {
        pos.x = window.pageXOffset;
        pos.y = window.pageYOffset
    }
    else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
        pos.x = document.documentElement.scrollLeft;
        pos.y = document.documentElement.scrollTop;
    }
    else if (typeof document.body != 'undefined') {
        pos.x = document.body.scrollLeft;
        pos.y = document.body.scrollTop;
    }
    return pos;

}

function SelectAll(ctlName) {
    var ctls = document.getElementsByName(ctlName);
    for (var i = 0; i < ctls.length; i++) {
        if (ctls[i].tagName) {
            if (ctls[i].tagName.toLowerCase() == "input")
                ctls[i].checked = true;
            else
                ctls[i].selected = true;
        }
    }
}

function UnSelectAll(ctlName) {
    var ctls = document.getElementsByName(ctlName);
    for (var i = 0; i < ctls.length; i++) {
        if (ctls[i].tagName) {
            if (ctls[i].tagName.toLowerCase() == "input")
                ctls[i].checked = !ctls[i].checked;
            else
                ctls[i].selected = !ctls[i].selected;
        }
    }
}


function GetDateByUtcString(utc) {
    var re = new RegExp("^(([0-9]{2,4})(-|/){1}([0-9]{1,2})(-|/){1}([0-9]{1,2}))[a-zA-Z]+([0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}).+$");
    //re.pa=;
    var r = re.exec(utc);
    var date = r[4] + "/" + r[6] + "/" + r[2];
    var time = r[7];
    //alert(date+" "+time);
    return new Date(date + " " + time);
}

function FixImgWidth(panel) {
    if (panel == null || panel == "")
        panel = document.body;
    if (typeof (panel) == "string")
        panel = $(panel);
    if (panel == null)
        return;
    var imgs = panel.getElementsByTagName("img");
    if (imgs.length > 0) {
        for (var j = 0; j < imgs.length; j++) {
            imgs[j].style.display = "none";
            imgs[j].onload = function() {
                this.style.display = "block";
                if (this.offsetWidth > this.getAttribute("fixWidth")) {
                    if (Browser.isIE)
                    //this.style.width="90%";
                        this.style.width = String(this.getAttribute("fixWidth") - 3) + "px";
                    else
                        this.style.width = "100%";
                    this.removeAttribute("height");
                    this.style.height = "auto";
                }
            }
        }
        for (var j = 0; j < imgs.length; j++) {
            imgs[j].style.display = "none";
        }
        //if (Browser.isIE){
        var parentNode = imgs[0].parentNode;
        var panelWidth = parentNode.offsetWidth;
        while (panelWidth <= 0 && parentNode != null) {
            parentNode = parentNode.parentNode;
            panelWidth = parentNode.offsetWidth;
        }
        if (parentNode == null)
            parentNode = panel;
        var tmp = document.createElement("div");
        tmp.style.width = panelWidth + "px";
        tmp.style.height = "1000px";
        parentNode.appendChild(tmp);
        var fix = parentNode.offsetWidth - panelWidth;
        if (fix < 0) fix = 0;
        while (parentNode.scrollWidth != parentNode.offsetWidth) {
            panelWidth -= Math.abs(parentNode.scrollWidth - parentNode.offsetWidth);
            tmp.style.width = panelWidth + "px";
        }
        //alert(parentNode.offsetWidth+" "+panelWidth);
        //alert(fix);
        parentNode.removeChild(tmp);
        panelWidth -= fix;
        if (panelWidth <= 0) panelWidth = 100;
        if (panelWidth > panel.offsetWidth) panelWidth = panel.offsetWidth;
        for (var j = 0; j < imgs.length; j++) {
            if (Browser.isOpera) imgs[j].style.display = "block";
            imgs[j].setAttribute("fixWidth", panelWidth);
        }
        return panelWidth;
        //}
        //alert(parentNode.scrollWidth+" "+parentNode.offsetWidth);
    }
}

function GetFilename(path, noExt) {
    if (typeof (noExt) != "boolean") {
        noExt = false;
    }
    path = path.replace(/\\/g, "/");
    path = path.substring(path.lastIndexOf("/") + 1);
    if (noExt) {
        path = path.substring(0, path.lastIndexOf("."));
    }
    return path;
}

function cancelEvent(evt) {
    evt.cancelBubble = false;
    evt.returnValue = false;
}

function AddFavorite(url, title) {
    url = (url) ? url : location.href;
    title = (title) ? title : document.title;
    if (Browser.isIE) {
        window.external.addFavorite(url, title);
    }
    else if (window.sidebar) {
        window.sidebar.addPanel(title, url, false);
    }
    else {
        alert("你的浏览器不支持该功能，请手动添加收藏。\r\n添加方法：展开浏览器的“书签”菜单，点击“(将该页)加入书签”。")
    }
}

function ShowPopPic(obj) {
    //try {
    //alert(obj.offsetWidth + " " + obj.parentNode.offsetWidth);
    if (obj == null) return;
    if (obj.offsetWidth <= obj.parentNode.offsetWidth && obj.offsetHeight <= obj.parentNode.offsetHeight)
        return;
    if (!Page.Inited) return;
    var a = $("popPicBox");
    if (a == null) {
        a = document.createElement("a");
        a.className = "FloatPic";
        a.id = "popPicBox";
        a.style.position = 'absolute';
        document.body.appendChild(a);
        var img = document.createElement('img');
        a.appendChild(img);
        a.firstChild.onload = function(e) {
            if ($("popPicBox").getAttribute("hide") == "1") return;
            $("popPicBox").style.display = "block";
        };
    }
   
    if (typeof (obj.parentNode.href) == 'undefined')
        a.href = 'javascript:void(null)';
    else
        a.href = obj.parentNode.href;
    a.target = obj.parentNode.target;
    a.style.display = "none";
    a.setAttribute("hide", "0");
    a.title = obj.parentNode.title;
    var pos = Func.GetObjPos(obj);
    a.style.top = (pos.y - 1) + 'px';
    a.style.left = (pos.x - 1) + 'px';
    a.style.display = "none";
    a.onmouseout = function(e) {
        $("popPicBox").setAttribute("hide", "1");
        $("popPicBox").style.display = "none";
    }
    if (a.firstChild.src == obj.src)
        a.style.display = "block";
    else
        a.firstChild.src = obj.src;
    //}
    //catch(e){alert("sdf")}
}

function GetCurrentStyle(obj, prop) {
    if (obj.currentStyle) {
        return obj.currentStyle[prop];
    }
    else if (window.getComputedStyle) {
        prop = prop.replace(/([A-Z])/g, "-$1");
        prop = prop.toLowerCase();
        return window.getComputedStyle(obj, "").getPropertyValue(prop);
    }
    return null;
}


function ShowPopDiv(obj, callback) {
    //alert(typeof(callback));
    //try{
    if (obj == null) return;
    if (isIE && document.readyState != "complete") return;
    var div = $("popDiv");
    if (div == null) {
        div = document.createElement('div');
        div.className = 'FloatDiv';
        div.style.position = 'absolute';
        div.id = "popDiv";
        div.style.display = "none";
        div.style.overflow = "auto";
        div.setAttribute("callback", callback);
        div.setAttribute("interval", 0);
        div.onmouseover = function() { clearTimeout($("popDiv").getAttribute("interval")); };
        div.onmouseout = function(e) {
            e = (e) ? e : window.event;
            var obj = $("popDiv");
            var pos = Func.GetObjPos(obj);
            var scroll = getScroll();
            var x = e.clientX + scroll.left;
            var y = e.clientY + scroll.top;
            //alert(x+" "+pos.x+" "+(pos.x+pos.width)+" "+y+" "+pos.y+" "+(pos.y+pos.height));
            if (x >= pos.x && x <= (pos.x + pos.width) && y >= pos.y && y <= (pos.y + pos.height))
                return;
            //alert(typeof(obj.getAttribute("callback")));
            if (isIE)
                obj.setAttribute("interval", setTimeout(function() { $("popDiv").style.display = "none"; if (typeof (obj.getAttribute("callback")) == "function") { obj.getAttribute("callback")(); } }, 1000));

            //obj.style.display="none";
            //if (typeof(obj.getAttribute("callback"))=="function")
            //  obj.getAttribute("callback")();
        }
        document.body.appendChild(div);
    }
    div.style.height = "auto";
    var pos = Func.GetObjPos(obj);
    //for (t in obj.currentStyle)
    //    alert(t+"="+eval("obj.currentStyle."+t));
    //alert(GetCurrentStyle(obj,"height"));
    div.style.top = (pos.y - 1) + 'px';
    div.style.left = (pos.x - 1) + 'px';
    div.style.width = (pos.width - (Int.Parse(GetCurrentStyle(obj, "paddingLeft")) + Int.Parse(GetCurrentStyle(obj, "paddingRight")))) + "px";
    div.style.display = "block";
    div.style.paddingTop = GetCurrentStyle(obj, "paddingTop");
    div.style.paddingLeft = GetCurrentStyle(obj, "paddingLeft");
    div.style.paddingRight = GetCurrentStyle(obj, "paddingRight");
    div.style.paddingBottom = GetCurrentStyle(obj, "paddingBottom");
    div.innerHTML = obj.innerHTML;
    if (div.offsetHeight <= obj.offsetHeight) {
        div.style.display = "none";
        return;
    }
    pos = Func.GetObjPos(div);
    var scroll = getScroll();
    //alert(getScroll().top);
    //alert(page.windowHeight);
    if (pos.y + pos.height > scroll.top + Page.windowHeight) {
        div.style.height = (scroll.top + Page.windowHeight - pos.y - (Int.Parse(GetCurrentStyle(obj, "paddingTop")) + Int.Parse(GetCurrentStyle(obj, "paddingBottom"))) - Int.Parse(GetCurrentStyle(div, "borderTopWidth")) - Int.Parse(GetCurrentStyle(div, "borderBottomWidth"))) + "px";
    }
    //alert(typeof(callback));
    if (typeof (callback) == "function")
        callback(div);
    //}
    //catch(e){}
}

function CopyUrl() {
    if (copy_clip(top.location.href)) {
        alert("URL地址复制成功,请粘贴到你的QQ/MSN上推荐给你的好友吧*^_^*");
    }
    else {
        alert("复制失败,可能是您的浏览器不支持该操作,请手动复制.");
    }
}

function copy_clip(meintext) {
    if (window.clipboardData) {
        window.clipboardData.clearData();
        return window.clipboardData.setData("Text", meintext);
    }
    /*else {
    try{
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
    var divholder = document.createElement('div');
    divholder.id = flashcopier;
    document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="/images/clipboard.swf" FlashVars="clipboard='+encodeURIComponent(meintext)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
    return true;
    }
    catch(e){}
    }*/
    else if (navigator.userAgent.indexOf("Opera") != -1) {
        window.location = meintext;
    }
    else if (window.netscape) {
        try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        }
        catch (e) {
            alert("你使用的FF浏览器,复制功能被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
            return false;
        }
        var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
        if (!clip) return;
        var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
        if (!trans) return;
        trans.addDataFlavor('text/unicode');
        var str = new Object();
        var len = new Object();
        var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
        var copytext = meintext;
        str.data = copytext;
        trans.setTransferData("text/unicode", str, copytext.length * 2);
        var clipid = Components.interfaces.nsIClipboard;
        if (!clip) return false;
        clip.setData(trans, null, clipid.kGlobalClipboard);
        return true;
    }
    return false;
}

//载入JS文件
function loadJs(file, callback) {
    var scriptList = document.getElementsByTagName("SCRIPT");
    for (var i = 0; i < scriptList.length; i++) {
        if (scriptList[i].src == file)
            return;
    }
    var script = document.createElement('script');
    if (file.indexOf("?") > 0)
        file += "&randnum=" + Math.random();
    else
        file += "?randnum=" + Math.random();
    script.src = file;
    script.language = 'javascript';
    script.type = 'text/javascript';
    if (typeof (callback) == "function") {
        //alert(callback);
        script.onreadystatechange = function() {
            if (this.readyState == "loaded") {
                callback();
            }
        }
    }
    else {
        alert(typeof (callback));
    }
    var head = document.getElementsByTagName('HEAD').item(0);
    head.appendChild(script);
}



function getLastChild(node) {
    node = node.lastChild;
    while (node != null && node.nodeType != 1)
        node = node.previousSibling;
    return node;
}

function getFirstChild(node) {
    node = node.firstChild;
    while (node != null && node.nodeType != 1)
        node = node.nextSibling;
    return node;
}

var Dom = {
    extend: function(name, fn) {
        if (typeof (HTMLElement) != "undefined") {
            HTMLElement.prototype[name] = fn;
            //eval("HTMLElement.prototype." + name + "=fn");
        }
        else {
            //document.attachEvent("onreadystatechange", function() {
            Dom.IEExtend(document, name, fn);
            //});
        }
        document[name] = window[name] = fn;
    },
    IEExtend: function(element, name, fn) {
        if (document._getElementsByTagName)
            return;
        document._getElementsByTagName = document.getElementsByTagName;
        document.getElementsByTagName = function(tag) {
            var nodes = document._getElementsByTagName(tag);
            for (var i = 0; i < nodes.length; i++) {
                if (!nodes[i][name])
                    nodes[i][name] = fn;
            }
            return nodes;
        };
        if (document._getElementById)
            return;
        document._getElementById = document.getElementById;
        document.getElementById = function(id) {
            var node = document._getElementById(id);
            if (node != null && !node[name]) {
                //                if (!node._getElementsByTagName) {
                //                    node._getElementsByTagName = node.getElementsByTagName;
                //                    node.getElementsByTagName = function(tag) {
                //                        var nodes = this._getElementsByTagName(tag);
                //                        for (var i = 0; i < nodes.length; i++) {
                //                            if (!nodes[i][name])
                //                                nodes[i][name] = fn;
                //                        }
                //                        return nodes;
                //                    }
                //                }
                node[name] = fn;
                if (node.getElementsByTagName && !node._getElementsByTagName && node.tagName != "OBJECT") {
                    node._getElementsByTagName = node.getElementsByTagName;
                    node.getElementsByTagName = function(tag) {
                        var nodes = node._getElementsByTagName(tag);
                        for (var i = 0; i < nodes.length; i++) {
                            if (!nodes[i][name])
                                nodes[i][name] = fn;
                        }
                        return nodes;
                    };
                }

            }
            return node;
        };
        if (document._createElement)
            return;
        document._createElement = document.createElement;
        document.createElement = function(tag) {
            var node = document._createElement(tag);
            node._getElementsByTagName = node.getElementsByTagName;
            node.getElementsByTagName = node._getElementsByTagName;
            if (!node[name])
                node[name] = fn;
            return node;
        };
        if (element.nodeType == 1) {
            element[name] = fn;
            for (node in element.childNodes) {
                Dom.IEExtend(node, name, fn);
            }
        }
    }
}

Dom.extend("addEvent", function(sType, fHandler) {
    if (typeof (sType) != "string") return;
    if (document.attachEvent) {
        if (sType.indexOf("on") < 0)
            sType = "on" + sType;
        this.attachEvent(sType, fHandler);
    }
    else {
        var shortTypeName = sType.replace(/on/, "");
        fHandler._ieEmuEventHandler = function(e) {
            //window.event=e;
            return fHandler();
        }
        this.addEventListener(shortTypeName, fHandler._ieEmuEventHandler, false);
    }
});

if (typeof (XMLDocument) == "undefined")
    XMLDocument = {};
if (XMLDocument && XMLDocument.prototype && XMLDocument.prototype.__proto__ && !XMLDocument.selectNodes) {
    //让FireFox兼容IE的XMLDocument
    var ex;
    //alert(XMLDocument.selectNodes);
    XMLDocument.prototype.__proto__.__defineGetter__("xml", function() {
        try {
            return new XMLSerializer().serializeToString(this);
        }
        catch (ex) {
            var d = document.createElement("div");
            d.appendChild(this.cloneNode(true));
            return d.innerHTML;
        }
    });
    Element.prototype.__proto__.__defineGetter__("xml", function() {
        try {
            return new XMLSerializer().serializeToString(this);
        }
        catch (ex) {
            var d = document.createElement("div");
            d.appendChild(this.cloneNode(true));
            return d.innerHTML;
        }
    });
    XMLDocument.prototype.__proto__.__defineGetter__("text", function() {
        return this.firstChild.textContent;
    });
    Element.prototype.__proto__.__defineGetter__("text", function() {
        return this.textContent;
    });

    XMLDocument.prototype.selectSingleNode = Element.prototype.selectSingleNode = function(xpath) {
        var x = this.selectNodes(xpath);
        if (!x || x.length < 1) return null;
        return x[0];
    }
    XMLDocument.prototype.selectNodes = Element.prototype.selectNodes = function(xpath) {
        var xpe = new XPathEvaluator();
        var nsResolver = xpe.createNSResolver(this.ownerDocument == null ? this.documentElement : this.ownerDocument.documentElement);
        var result = xpe.evaluate(xpath, this, nsResolver, 0, null);
        var found = [];
        var res;
        while (res = result.iterateNext())
            found.push(res);
        return found;
    }
}

//for (o in document) {
//alert(o)
//}
//alert(document.lastModified);
//document.addEvent("onreadystatechange", function() { alert(document.readyState) });

var Func = {
    GetPageWidth: function() {
        var xScroll;
        if (window.innerHeight && window.scrollMaxY) {
            xScroll = document.body.scrollWidth;
        }
        else if (document.body.scrollWidth > document.body.offsetWidth) {
            xScroll = document.body.scrollWidth;
        }
        else {
            xScroll = document.body.offsetWidth;
        }

        var winW;
        if (self.innerWidth) {
            winW = self.innerWidth;
        }
        else if (document.documentElement && document.documentElement.clientWidth) {
            winW = document.documentElement.clientWidth;
        }
        else if (document.body) {
            winW = document.body.clientWidth;
        }
        return (xScroll < winW) ? winW : xScroll;
    },
    GetPageHeight: function() {
        var yScroll;
        if (window.innerHeight && window.scrollMaxY) {
            yScroll = window.innerHeight + window.scrollMaxY;
        }
        else if (document.body.scrollHeight > document.body.offsetHeight) {
            yScroll = document.body.scrollHeight;
        }
        else {
            yScroll = document.body.offsetHeight;
        }

        var winH;
        if (self.innerHeight) {
            winH = self.innerHeight;
        }
        else if (document.documentElement && document.documentElement.clientHeight) {
            winH = document.documentElement.clientHeight;
        }
        else if (document.body) {
            winH = document.body.clientHeight;
        }
        return (yScroll < winH) ? winH : yScroll;
    },
    GetWindowWidth: function() {
        var winW;
        if (document.documentElement && document.documentElement.clientWidth) {
            winW = document.documentElement.clientWidth;
        }
        else if (document.body) {
            winW = document.body.clientWidth;
        }
        return winW;
    },
    GetWindowHeight: function() {
        var winH;
        if (document.documentElement && document.documentElement.clientHeight) {
            winH = document.documentElement.clientHeight;
        }
        else if (document.body) {
            winH = document.body.clientHeight;
        }
        return winH;
    },
    GetObjPos: function(element) {
        var coords = { x: 0, y: 0, width: element.offsetWidth, height: element.offsetHeight };
        if (Browser.isIE) {
            var scrollPos = GetScrollPos();
            coords.x = element.getBoundingClientRect().left + scrollPos.x;
            coords.y = element.getBoundingClientRect().top + scrollPos.y;
            //if (isIE7){//在IE7下面,通过上面方法得到的位置有2个相素的误差,原因未知
            //		        coords.x-=2;
            //		        coords.y-=2;
            //}
        }
        else {
            while (element) {
                coords.x += element.offsetLeft;
                coords.y += element.offsetTop;
                element = element.offsetParent;
                //alert(coords.y);
            }
        }
        return coords;
    },
    getCookie: function(cookie_name) {
        cookie_name += "=";
        var allcookies = document.cookie;
        //alert(allcookies);
        var cookie_pos = allcookies.indexOf(cookie_name);
        if (cookie_pos != -1) {
            cookie_pos += cookie_name.length;
            var cookie_end = allcookies.indexOf(";", cookie_pos);
            if (cookie_end == -1)
                cookie_end = allcookies.length;
            var value = unescape(allcookies.substring(cookie_pos, cookie_end));
            return value;
        }
        else
            return null;
    },
    setCookie: function(cookie_name, value, expires) {
        var exp = new Date();
        exp.setTime(exp.getTime() + expires * 1000);
        document.cookie = cookie_name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/"
    },
    SetParam: function(name, value, url) {
        var str = (typeof (url) == "string") ? url : self.location.href;
        var reg = new RegExp(name + "=([^&]*)", "i");
        if (reg.test(str))
            str = str.replace(reg, name + "=" + value);
        else {
            if (str.indexOf("?") >= 0) {
                str += "&" + name + "=" + value;
            }
            else
                str += "?" + name + "=" + value;
        }
        return str;
    }
}

var Int = {
    Parse: function(obj) {
        var num = parseInt(obj);
        if (isNaN(num))
            num = 0;
        return num;
    }
}

var Browser = {
    FullName: "Other",
    Name: "Other",
    Version: "0",
    Check: function() {
        re = /(MSIE|Firefox|Opera|Safari|Chrome)[ \/]+([0-9\.]+)/i;
        if (re.test(window.navigator.userAgent)) {
            var r = window.navigator.userAgent.match(re);
            Browser.Name = r[1];
            Browser.Version = r[2];
            if (Browser.Name == "Safari") {//Safari很有个性
                Browser.Version = window.navigator.userAgent.match(/(Version)[ \/]+([0-9\.]+)/i)[2];
            }
            Browser.FullName = Browser.Name + " " + Browser.Version;
        }
    },
    isIE: (window.navigator.userAgent.indexOf("MSIE") >= 0),
    isFirefox: (window.navigator.userAgent.indexOf("Firefox") >= 0),
    isOpera: (window.navigator.userAgent.indexOf("Opera") >= 0),
    isChrome: (window.navigator.userAgent.indexOf("Chrome") >= 0),
    isSafari: (window.navigator.userAgent.indexOf("Safari") >= 0 && window.navigator.userAgent.indexOf("Chrome") < 0)
}
Browser.Check();

isIE = Browser.isIE;
isIE6 = (isIE && Math.floor(Int.Parse(Browser.Version)) == 6);
isIE7 = (isIE && Math.floor(Int.Parse(Browser.Version)) == 7);
isIE8 = (isIE && Math.floor(Int.Parse(Browser.Version)) == 8);
isChrome = Browser.isChrome;
isFirefox = Browser.isFirefox;

var Page = {
    Inited: false,
    LoadEventList: new Array(),
    ReSizeEventList: new Array(),
    RegLoadEvent: function(func) {
        Page.LoadEventList.push(func);
    },
    RegReSizeEvent: function(func) {
        Page.ReSizeEventList.push(func);
    },
    Init: function() {
        window.addEvent("onload", Page.Load);
        window.addEvent("onresize", Page.ReSize);
    },
    Load: function() {
        Page.width = Func.GetPageWidth();
        Page.height = Func.GetPageHeight();
        Page.windowWidth = Func.GetWindowWidth();
        Page.windowHeight = Func.GetWindowHeight();
        if (typeof (Page_Load) == "function")
            Page_Load();
        for (var i = 0; i < Page.LoadEventList.length; i++) {
            //try{
            if (typeof (Page.LoadEventList[i]) == "function") {

                Page.LoadEventList[i]();
            }
            else
                eval(Page.LoadEventList[i]);
            //}
            //catch(e){
            //	continue;
            //}
        }
        Page.Inited = true;
    },
    ReSize: function() {
        if (Page.width != Func.GetPageWidth() || Page.height != Func.GetPageHeight() || Page.windowWidth != Func.GetWindowWidth() || Page.windowHeight != Func.GetWindowHeight()) {

            Page.width = Func.GetPageWidth();
            Page.height = Func.GetPageHeight();
            Page.windowWidth = Func.GetWindowWidth();
            Page.windowHeight = Func.GetWindowHeight();
            if (typeof (Page_ReSize) == "function")
                Page_ReSize();
            //alert(Page.ReSizeEventList);
            for (var i = 0; i < Page.ReSizeEventList.length; i++) {
                //try{
                if (typeof (Page.ReSizeEventList[i]) == "function") {

                    Page.ReSizeEventList[i]();
                }
                else
                    eval(Page.ReSizeEventList[i]);
                //}
                //catch(e){
                //	continue;
                //}
            }
        }
    },
    Url: self.location.href.substring(self.location.href.indexOf("?")),
    QueryString: self.location.search.remove(0, 1),
    Path: self.location.pathname,
    FileName: (self.location.pathname.substring(self.location.pathname.lastIndexOf("/")).indexOf(".") > 0) ? self.location.pathname.substring(self.location.pathname.lastIndexOf("/") + 1) : "",
    Request: function(paramName, url) {
        var query = Page.QueryString;
        if (url != undefined && url.indexOf("?") > 0)
            query = url.substring(url.indexOf("?") + 1);
        if (query.length == 0) return null;
        var reg = new RegExp("(^|&)" + paramName + "=([^&]*)(&|$)", "i");
        var r = query.match(reg);
        if (r != null)
            return decodeURI(r[2]);
        return null;
    },
    RunTime: {
        Variable: new Object()
    },
    WebRoot: "",
    windowWidth: 0,
    windowHeight: 0,
    width: 0,
    height: 0
}

request = Page.Request;

Page.Init();


(function() {
    if (window.google && google.gears) {
        return

    }
    var a = null;
    if (typeof GearsFactory != 'undefined') {
        a = new GearsFactory()
    }
    else {
        try {
            a = new ActiveXObject('Gears.Factory');
            if (a.getBuildInfo().indexOf('ie_mobile') != -1) {
                a.privateSetGlobalObject(this)
            }
        }
        catch (e) {
            if ((typeof navigator.mimeTypes != 'undefined') && navigator.mimeTypes["application/x-googlegears"]) {
                a = document.createElement("object");
                a.style.display = "none";
                a.width = 0;
                a.height = 0;
                a.type = "application/x-googlegears";
                document.documentElement.appendChild(a)
            }
        }
    }
    if (!a) {
        return
    }
    if (!window.google) {
        google = {};
    }
    if (!google.gears) {
        google.gears = {
            factory: a
        }
    }
})();

Page.RegLoadEvent(function() {
    if (!window.google || !google.gears)
        return;
    if (!Func.getCookie("desktopShrotcut")) {
        var a = google.gears.factory.create("beta.desktop");
        //a.createShortcut(escape(document.title.substring(0, document.title.indexOf("-")).trim()), location.host, { "48x48": "http://" + location.host + "/ico/ico_48x48.png" }, "国内首家提供高清在线动画，在线漫画的在线动漫网站。");
        a.createShortcut("Hei100 Comic", "/", { "48x48": "http://" + location.host + "/ico/ico_48x48.png" }, "国内首家提供高清在线动画，在线漫画的动漫网站。");
        Func.setCookie("desktopShrotcut", 1, 60 * 24 * 60 * 60);
    }
})

function CloseWin() {
    window.opener = null;
    //window.opener=top;     
    window.open("", "_self");
    window.close();
}