var addListener = function(elm, type, func) {
    if(elm == null) {
        return false;
    }
    if(elm.addEventListener) {
        elm.addEventListener(type, func, false);
    } else if(elm.attachEvent) {
        elm.attachEvent('on' + type, func);
    } else {
        return false;
    }
    return true;
};

function _bindPopupForAnchor (anchor, type) {
    var openWindow = function(e) {
        if (type == "news" || type == "school") {
            var win = window.open(anchor.href, type,
                    "width=680,height=500,scrollbars=yes");
        } else {
            var win = window.open(anchor.href, type);
        }

        if (e.preventDefault) {
            e.preventDefault();
        }
        try {
            if (event.returnValue != null) {
                event.returnValue = false;
            }
        } catch(err) {}
        win.focus();
        return false;
    };
    addListener(anchor, "click", openWindow);
}

function bindPopup() {
    var links = document.getElementById("newslist");
    if (links != null) {
        var anchors = links.getElementsByTagName("a");
        for (var i in anchors) {
            _bindPopupForAnchor(anchors[i], "news");
        }
    }

    var links = document.getElementById("schoollist");
    if (links != null) {
        var anchors = links.getElementsByTagName("a");
        for (var i in anchors) {
            _bindPopupForAnchor(anchors[i], "school");
        }
    }

    var links = document.getElementById("information");
    if (links != null) {
        for (var i = 0; i < links.childNodes.length; i++) {
            var child = links.childNodes[i];
            if (child.id == "detail") {
                var anchors = child.getElementsByTagName("a");
                for (var anchor in anchors) {
                    _bindPopupForAnchor(anchors[anchor], "outlink");
                }
            }
        }
    }
}
try {
    Event.domReady.add(bindPopup);
} catch (e) {
    addListener(window, "load", bindPopup);
}
