
HN.widget.AdvancedDialog = function () {
    var $D = YAHOO.util.Dom, $E = YAHOO.util.Event, $C = YAHOO.util.Connect, _4 = YAHOO.env.ua.ie, _5, _6, _7, _8, _9, _a, _b, d, _d = true, _e, _f, _10 = {sw:"760px", sm:"-240px", mw:"500px", mm:"-200px", lw:"760px", lm:"-245px"}, _11, _12, _13, _14;
    function _obj() {
        _14 = {customevents:{onStart:function (_15, _16) {
            _6.innerHTML = HN.cst.MSG.SUBMITING_DIV;
            _fix();
        }}, success:function (o) {
            try {
                var res = eval("(" + o.responseText + ")");
            }
            catch (e) {
                var res = {"status":0, "msg":HN.cst.MSG.ASYNC_DATA_ERROR};
            }
            if (res.status == 1) {
                if (_d) {
                    window.location.reload();
                    return;
                }
                if (_13) {
                    _13.fire({msg:res.msg});
                }
                _hide();
            } else {
                if (res.status == 0) {
                    _hide();
                    HN.cst.CMNFUNCS.setAlertDialog(res.msg);
                } else {
                    _hide();
                }
            }
        }, failure:function (o) {
            _hide();
            alert(HN.cst.MSG.ASYNC_FAILURE);
        }};
    }
    function _size(str) {
        if (str) {
            if (_f != str) {
                _f = str;
                $D.setStyle(_5, "width", _10[_f + "w"]);
                $D.setStyle(_7, "width", _10[_f + "w"]);
                $D.setStyle(_5, "margin-left", _10[_f + "m"]);
            }
        } else {
            switch (_f) {
              case "s":
                _size("s");
                break;
              case "m":
                _size("m");
                break;
              case "l":
                _size("l");
                break;
              default:
                _size("s");
                break;
            }
        }
    }
    function _fix() {
        _7.style.height = _5.offsetHeight + "px";
    }
    function _hide() {
        $D.setStyle(_5, "visibility", "hidden");
        $D.setStyle(_5, "z-index", "-1");
        if (_4 == 6) {
            _e.style.zIndex = "-1";
        }
        window.clearInterval(_11);
        if (_4) {
            _5.style.filter = "opacity(alpha=100)";
        } else {
            $D.setStyle(_5, "opacity", 1);
        }
        if (_8 && $D.inDocument(_8)) {
            _5.removeChild(_8);
        }
        _9 = null;
        _12 = null;
        _13 = null;
    }
    function _fadeout(num) {
        if (!_b || !d || d != num) {
            d = num || 1;
            _b = new YAHOO.util.Anim(_5, {opacity:{to:0}}, d, YAHOO.util.Easing.easeOut);
            _b.onComplete.subscribe(function () {
                _hide();
            });
        }
        _b.animate();
    }
    function _form() {
        var arr = _6.getElementsByTagName("form");
        if (arr.length) {
            return _9 = arr[0];
        } else {
            return;
        }
    }
    function _post(el) {
        $E.on(el, "submit", function (e) {
            $E.stopEvent(e);
            if (_12) {
                _12.fire();
            }
            $C.setForm(this);
            _obj();
            $C.asyncRequest(this.method, this.action + "&t=json", _14);
        });
    }
    function _close(el, _20) {
        if (_20) {
            $E.on(el, "click", function (e) {
                $E.stopEvent(e);
                window.location.reload();
            });
        } else {
            $E.on(el, "click", function (e) {
                $E.stopEvent(e);
                _fadeout(0.3);
            });
        }
    }
    return {setContent:function (str) {
        _6.innerHTML = str;
        _fix();
    }, getContent:function () {
        return _6;
    }, setSize:function (str) {
        _size(str);
    }, findY:function (el) {
        var y = 0;
        if (el.offsetParent) {
            while (el.offsetParent) {
                y += el.offsetTop;
                el = el.offsetParent;
            }
        }
        return y;
    }, setY:function (num) {
        _5.style.top = num + "px";
    }, getForm:function (str) {
        if (_9 && $D.inDocument(_9)) {
            return _9;
        } else {
            if (str) {
                _9 = $D.get(str);
                return _9;
            } else {
                return _form();
            }
        }
    }, setPost:function (b) {
        if (YAHOO.lang.isBoolean(b)) {
            if (b) {
                _d = true;
            } else {
                _d = false;
            }
        } else {
            if (YAHOO.lang.isString(b)) {
                $E.on(b, "click", function (e) {
                    $E.stopEvent(e);
                    if (_12) {
                        _12.fire();
                    }
                    _9.submit();
                });
            }
        }
        if (_9) {
            _post(_9);
        } else {
            _post(_form());
        }
    }, post:function () {
        if (_12) {
            _12.fire();
        }
        _9.submit();
    }, subscribePostBefore:function (fn, _2c) {
        if (!_12) {
            _12 = new YAHOO.util.CustomEvent("beforePost");
        }
        if (_2c) {
            _12.subscribe(fn, _2c, true);
        } else {
            _12.subscribe(fn);
        }
    }, subscribePostAfter:function (fn, _2e) {
        if (!_13) {
            _13 = new YAHOO.util.CustomEvent("afterPost");
        }
        if (_2e) {
            _13.subscribe(fn, _2e, true);
        } else {
            _13.subscribe(fn);
        }
    }, setClose:function (el, _30) {
        if ($D.get(el)) {
            _close(el, _30);
        } else {
            if (_8) {
                _5.insertBefore(_8, _7);
            } else {
                var _31 = document.createTextNode("\u5173\u95ed");
                var a = document.createElement("a");
                $D.addClass(a, "close");
                a.setAttribute("title", "\u5173\u95ed");
                a.setAttribute("href", "#");
                a.appendChild(_31);
                _8 = document.createElement("p");
                $D.addClass(_8, "dialog-close");
                _8.appendChild(a);
                _5.insertBefore(_8, _7);
                _close(a, _30);
            }
        }
    }, show:function (str) {
        _size();
        if (str) {
            _6.innerHTML = str;
        }
        _fix();
        if (_4 == 6) {
            if (!_e) {
                _e = document.createElement("<iframe frameborder=\"0\" style=\"position:absolute; top:0; left:0; z-index:0; display:block; width:0; height:0; filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)\" srcolling=\"no\" id=\"modal-shim\" src=\"javascript:false;\"></iframe>");
                document.body.appendChild(_e);
            } else {
                _e.style.zIndex = "0";
            }
            _e.style.height = $D.getDocumentHeight() + "px";
            _e.style.width = $D.getDocumentWidth() + "px";
        }
        $D.setStyle(_5, "visibility", "visible");
        $D.setStyle(_5, "z-index", "1");
        _11 = window.setInterval(_fix, 100);
    }, hide:function (num) {
        if (num) {
            _fadeout(num);
        } else {
            _hide();
        }
    }, init:function () {
        if (_a) {
            return;
        }
        if (!(_5 = $D.get("dialog-advanced"))) {
            _5 = document.createElement("div");
            $D.addClass(_5, "dialog-advanced");
            document.body.appendChild(_5);
        } else {
            _5.innerHTML = "";
        }
        _6 = document.createElement("div");
        $D.addClass(_6, "dialog-content");
        _5.appendChild(_6);
        _7 = document.createElement("div");
        $D.addClass(_7, "underlay");
        _5.appendChild(_7);
        _a = true;
    }};
}();
HN.widget.Anim = function () {
    var $D = YAHOO.util.Dom;
    return {lookme:function (el) {
        var obj = {}, bg, bd;
        bg = $D.getStyle(el, "background-color") || "#fff";
        obj.backgroundColor = {from:"#fff9d7", to:bg};
        if (bd = $D.getStyle(el, "border-top-color")) {
            obj.borderColor = {from:"#e2c822", to:bd};
        }
        var _3a = new YAHOO.util.ColorAnim(el, obj, 1, YAHOO.util.Easing.easeIn);
        _3a.animate();
    }};
}();
HN.widget.Reqs = function () {
    var $D = YAHOO.util.Dom, $E = YAHOO.util.Event, $C = YAHOO.util.Connect, _3e, url, _40, _41, _42;
    function _parse() {
        if (url = _3e.getAttribute("req:url")) {
            if (!(_40 = _3e.getAttribute("req:data"))) {
                _40 = null;
            }
            if (!(_41 = _3e.getAttribute("req:method"))) {
                _41 = "post";
            }
            return true;
        } else {
            return false;
        }
    }
    function _after() {
        var _43 = $D.getAncestorByTagName(_3e, "li");
        _43.innerHTML = _42;
        $D.addClass(_43, "done");
        HN.widget.Anim.lookme(_43);
        var _44 = $D.getAncestorByClassName(_43, "sect");
        var str = _44.getAttribute("id");
        var num;
        if (num = $D.get(str + "-num")) {
            var n = num.innerHTML;
            if (n > 1) {
                num.innerHTML = n - 1;
            } else {
                var _48 = $D.getAncestorByTagName(num, "li");
                _48.parentNode.removeChild(_48);
            }
        }
        var arr = _44.getElementsByTagName("h3");
        if (arr.length) {
            var _4a = arr[0];
            var _4b = _44.getAttribute("req:type");
            var str = _4a.innerHTML;
            try {
                var n = str.match(/(\d+)/)[1];
            }
            catch (ex) {
                var n = 0;
            }
            if (n > 1) {
                _4a.innerHTML = str.replace(/(\d+)/, n - 1);
            } else {
                if (!_4b) {
                    _4b = "\u8bf7\u6c42";
                }
                _4a.innerHTML = "\u4f60\u5df2\u5904\u7406\u5b8c\u6240\u6709" + _4b;
            }
        }
    }
    function _post() {
        $C.asyncRequest(_41, url + "&t=json", {success:function (o) {
            try {
                var res = eval("(" + o.responseText + ")");
            }
            catch (e) {
                var res = {"status":0, "msg":HN.cst.MSG.ASYNC_DATA_ERROR};
            }
            if (res.status == 1) {
                _42 = res.msg;
                _after();
            } else {
                if (res.status == 0) {
                    HN.cst.CMNFUNCS.setAlertDialog(res.msg);
                } else {
                    alert(res);
                }
            }
        }, failure:function (o) {
            alert(HN.cst.MSG.ASYNC_FAILURE);
        }}, _40);
    }
    function _run() {
        if (_parse()) {
            _post();
        }
    }
    return {run:function (el, str) {
        _3e = el;
        _42 = str;
        _after();
    }, init:function () {
        $E.on("content", "click", function (e) {
            var _52 = $E.getTarget(e);
            if (_52.tagName.toLowerCase() == "button" && $D.hasClass(_52, "req")) {
                _3e = _52;
                _run();
            }
        });
    }};
}();
HN.widget.Complexlink = function () {
    var el, url, _55, cfg = {}, f = function () {
    }, $HD = HN.widget.AdvancedDialog;
    function mk(_59, _5a) {
        el = _59;
        if (_5a) {
            if (cfg[_5a].f) {
                f = cfg[_5a].f;
            } else {
                f = function () {
                };
            }
            var _5b = el.getAttribute("href");
            if (_5b.substring(_5b.length - 1, _5b.length) == "#") {
                url = el.getAttribute("rel");
            } else {
                url = _5b;
            }
            if (cfg[_5a].t == 0) {
                YAHOO.util.Connect.asyncRequest("GET", url + "&t=json", {success:rspShowDialog, failure:rspFailure});
            } else {
                if (cfg[_5a].t == 1) {
                    var d = HN.util.getToPost(url, cfg[_5a].i);
                    var _5d = YAHOO.util.Connect.asyncRequest("POST", d.action, {success:function (o) {
                        var _5f = eval("(" + o.responseText + ")");
                        if (_5f.status == 1) {
                            f(el);
                        } else {
                            if (_5f.status == 0) {
                                HN.cst.CMNFUNCS.setAlertDialog(_5f.msg);
                            }
                        }
                    }, failure:rspFailure}, d.postdata);
                }
            }
        }
    }
    function rspShowDialog(o) {
        eval("getDialog(" + o.responseText + ")");
    }
    function rspHideDialog(o) {
        var _62 = eval("(" + o.responseText + ")");
        if (_62.status == 1) {
            if (_62.html) {
                $HD.setContent(_62.html);
            }
            f(el);
            $HD.hide(0.3);
        } else {
            if (_62.status == 0) {
                if (_62.html) {
                    $HD.setContent(_62.html);
                } else {
                    $HD.hide();
                    HN.cst.CMNFUNCS.setAlertDialog(_62.msg);
                }
            }
        }
    }
    function rspFailure(o) {
        alert("\u7f51\u7edc\u6709\u95ee\u9898\uff0c\u8bf7\u7a0d\u540e\u91cd\u8bd5");
    }
    function getDialog(_64) {
        if (_64.html) {
        	$HD.addClass("dialog-2");
            $HD.setSize("s");
            $HD.setContent(_64.html);
            $HD.setY(YAHOO.util.Dom.getDocumentScrollTop() + 125);
            $HD.show();
            var _65 = _55.getElementsByTagName("form");
            if (_65.length) {
                _65 = _65[0];
                YAHOO.util.Event.on(_65, "submit", function (e) {
                    YAHOO.util.Connect.setForm(_65);
                    var _67 = YAHOO.util.Connect.asyncRequest(_65.method, _65.action, {success:rspHideDialog, failure:rspFailure});
                    if (YAHOO.util.Connect.isCallInProgress(_67)) {
                        $HD.setContent(HN.cst.MSG.SUBMITING_DIV);
                    }
                    YAHOO.util.Event.stopEvent(e);
                });
            }
            $HD.setClose("dialog-end");
        }
    }
    return {register:function (_68, _69) {
        cfg[_68] = _69;
    }, init:function () {
        $HD.init();
        _55 = $HD.getContent();
        YAHOO.util.Event.on(document, "click", function (e) {
            if (e.button != 0) {
                return;
            }
            var _6b = YAHOO.util.Event.getTarget(e);
            if (_6b.tagName.toLowerCase() == "img") {
                _6b = YAHOO.util.Dom.getAncestorBy(_6b);
            }
            if (_6b.tagName.toLowerCase() == "a" && YAHOO.util.Dom.hasClass(_6b, "complexlink")) {
                var _6c = "";
                for (var itm in cfg) {
                    if (YAHOO.util.Dom.hasClass(_6b, itm)) {
                        _6c = itm;
                        break;
                    }
                }
                mk(_6b, _6c);
                YAHOO.util.Event.stopEvent(e);
            }
        });
    }};
}();
HN.widget.Complexlink.register("poke-send", {t:0});
HN.widget.Complexlink.register("poke-reply", {t:0, f:function (el) {
    if (elParent = YAHOO.util.Dom.getAncestorByTagName(el, "li")) {
        elParent.parentNode.removeChild(elParent);
    }
}});
HN.widget.Complexlink.register("poke-ignore", {t:1, i:{r:"user"}, f:function (el) {
    if (elParent = YAHOO.util.Dom.getAncestorByTagName(el, "li")) {
        elParent.parentNode.removeChild(elParent);
    }
}});
HN.widget.Complexlink.register("friend-add", {t:0, f:function (el) {
    if (elParent = YAHOO.util.Dom.getAncestorByTagName(el, "li")) {
        elParent.innerHTML = "\u597d\u53cb\u8bf7\u6c42\u5df2\u53d1\u9001";
    }
}});
HN.widget.Complexlink.register("friend-remove", {t:0, f:function (el) {
    if (elPeople = YAHOO.util.Dom.getAncestorByClassName(el, "people")) {
        if (elParent = YAHOO.util.Dom.getAncestorByTagName(elPeople, "li")) {
            elParent.parentNode.removeChild(elParent);
        }
    } else {
        window.location.reload();
    }
}});
HN.widget.Complexlink.register("friend-confirm", {t:1, i:{r:"user"}, f:function (el) {
    if (elParent = YAHOO.util.Dom.getAncestorByTagName(el, "li")) {
        window.location.reload();
    }
}});
HN.widget.Selectbox = function () {
    var el, _74;
    function setAll(b) {
        function byMethed(el) {
            return el.getAttribute("type") == "checkbox";
        }
        if (b) {
            YAHOO.util.Dom.getElementsBy(byMethed, "input", _74, setTrue);
        } else {
            YAHOO.util.Dom.getElementsBy(byMethed, "input", _74, setFalse);
        }
    }
    function setTrue(el) {
        el.checked = true;
    }
    function setFalse(el) {
        el.checked = false;
    }
    return {init:function (_79) {
        el = YAHOO.util.Dom.get(_79);
        if (el) {
            _74 = el.getElementsByTagName("table")[0];
            YAHOO.util.Event.on(_74, "click", function (e) {
                if (e.button != 0) {
                    return;
                }
                var _7b = YAHOO.util.Event.getTarget(e);
                if (_7b.tagName.toLowerCase() == "input") {
                    return;
                }
                var _7c = YAHOO.util.Dom.getAncestorByTagName(_7b, "tr");
                if (_7c) {
                    var _7d = _7c.getElementsByTagName("input")[0];
                    if (_7d.checked) {
                        setFalse(_7d);
                    } else {
                        setTrue(_7d);
                    }
                }
            });
            var _7e = YAHOO.util.Dom.get("selectall"), _7f = YAHOO.env.ua.ie ? "propertychange" : "change";
            YAHOO.util.Event.on(_7e, _7f, function () {
                if (this.checked) {
                    setAll(true);
                } else {
                    setAll(false);
                }
            });
        }
    }};
}();
HN.widget.SectionToggle = function () {
    var $D = YAHOO.util.Dom, $E = YAHOO.util.Event, set, _83, c, _85, sl = [];
    function _collapse(i) {
        $D.addClass(_83[i], "collapse");
        if (_83[i].getAttribute("sect:link")) {
            sl[i].innerHTML = _83[i].getAttribute("sect:link");
        } else {
            sl[i].innerHTML = "\u663e\u793a";
        }
    }
    function _expand(i) {
        $D.removeClass(_83[i], "collapse");
        sl[i].innerHTML = "\u9690\u85cf";
    }
    function _all(f) {
        for (var i = 0; i < c; i++) {
            f(i);
        }
    }
    function _run() {
        _all(function (i) {
            if (i == _85) {
                _expand(i);
            } else {
                _collapse(i);
            }
        });
    }
    return {init:function (str, num) {
        if (str) {
            set = $D.get(str);
        } else {
            set = $D.getElementsByClassName("sect-set")[0];
        }
        if (!set) {
            return;
        }
        _83 = $D.getChildrenBy(set, function (el) {
            return $D.hasClass(el, "sect");
        });
        if (!(c = _83.length)) {
            return;
        }
        if (window.location.href.indexOf("#") != -1) {
            var a = window.location.href.split("#", 2);
            if (a[1]) {
                window.scrollTo(0, 0);
                _all(function (i) {
                    if (_83[i].getAttribute("id") == a[1]) {
                        _85 = i;
                    }
                });
            }
        }
        if (isNaN(_85)) {
            if (num) {
                _85 = num;
            } else {
                _85 = 0;
            }
        }
        _all(function (i) {
            var h = _83[i].getElementsByTagName("h3")[0];
            if (h) {
                $D.setStyle(h, "cursor", "pointer");
                var b = document.createElement("a");
                b.setAttribute("href", "#");
                var c = document.createElement("div");
                $D.addClass(c, "sect-link");
                c.appendChild(b);
                _83[i].appendChild(c);
                sl[i] = b;
                $E.on([h, sl[i]], "click", function (e) {
                    $E.stopEvent(e);
                    if ($D.hasClass(_83[i], "collapse")) {
                        _expand(i);
                    } else {
                        _collapse(i);
                    }
                });
            }
        });
        _run();
    }};
}();
HN.app.Invite = function () {
    var $D = YAHOO.util.Dom, $E = YAHOO.util.Event;
    return {hide:function () {
        var _98 = new HN.widget.LinkPost(function (el) {
            return $D.hasClass(el, "invite-hide");
        }, null, {hd:"", bd:HN.cst.MSG.CONFORM_HIDE_INVITE, ft:HN.cst.MSG.HIDE_INVITE_FOOTER}, "invite-list");
        _98.afterPost.subscribe(function () {
            HN.cst.CMNFUNCS.yFadeRemove(this.link, "tr");
        });
    }, reInvite:function () {
        $E.on("invite-list", "click", function (e) {
            var t = $E.getTarget(e), nn = t.nodeName.toLowerCase();
            if (nn != "a") {
                return;
            }
            if ($D.hasClass(t, "invite-reinvite")) {
                var _9d = $D.getAncestorByTagName(t, "tr").getElementsByTagName("th")[0].innerHTML;
                HN.app.Core.openPreview(_9d);
                $E.stopEvent(e);
            }
        });
    }};
}();

