﻿

function loadfoot(footlist) {
    var list = document.getElementById(footlist).getElementsByTagName('a');
    var newOuterHtml = "";
    var innerText = "";
    var flag = true;
    var flag2 = true; 
    for (var i = 0; i < list.length; i++) {
        if (flag2) {
            if (len(list[i].innerHTML + innerText) + 2 < 402) {
                if (flag) {
                    if (len(list[i].innerHTML + innerText) + 2 > (400 / 3)) {
                        newOuterHtml += "<a href=\"/About/WebLinksList.html\" target=\"_blank\" >更多»</a><br/>";
                        innerText += "更多»";
                        flag = false;
                    }
                }
                innerText += list[i].innerHTML + "| ";
                newOuterHtml += getOuterHTML(list[i]) + "| ";
            }
            else {
                flag2 = false;
                newOuterHtml += "<a href=\"javascript:showorhide('" + footlist + "');\"><img src=\"/images/ico_1.gif\" /></a><br/><b id=\"show\" style=\"display:none\">";
            }
        }
        else {
            newOuterHtml += getOuterHTML(list[i]) + "| ";
        }
    }
    newOuterHtml = newOuterHtml.substring(0, newOuterHtml.length - 2);
    newOuterHtml += "</b>";
    document.getElementById(footlist).innerHTML = newOuterHtml;
    list.innerHTML = list.innerHTML;
}

function showorhide(footlist) {
    var curP = document.getElementById('show');
    var curImage = document.getElementById(footlist).getElementsByTagName('img')[0];
    if (curP.style.display == "") {
        curP.style.display = "none";
        curImage.src = "/images/ico_1.gif";
    }
    else {
        curP.style.display = "";
        curImage.src = "/images/ico_111.gif";
    }
}

function len(s) {
    var l = 0;
    var a = s.split("");
    for (var i = 0; i < a.length; i++) {
        if (a[i].charCodeAt(0) < 299) {
            l++;
        } else {
            l += 2;
        }
    }
    return l;
}

function getOuterHTML(element) {
    var attributes = element.attributes;
    var outerHTML = "";
    outerHTML += "<" + element.tagName;
    for (var i = 0; i < attributes.length; i++) {
        if (attributes[i].name == "href" || attributes[i].name == "title"||attributes[i].name=="target") {
            outerHTML += " " + attributes[i].name;
            outerHTML += "=\"" + attributes[i].value + "\"";
        }
    }
    outerHTML += " >" + element.innerHTML + "</" + element.tagName + ">";
    return outerHTML;
}

