﻿
/// <reference path="BxJsLib.js" />
/// <reference path="BxUser.js" />
/// <reference path="BxGuestbook.js" />
/// <reference path="BxComment.js" />
/// <reference path="BxProduct.js" />

//常用公共部分，请不要轻易修改删除
//#region 常用公共部分，请不要轻易修改删除
//站点配置
var siteConfig = { defaultLang: "cn", //默认语言版本
    langWords: { searchErrorMessage: { cn: "请输入搜索关键词", en: ""} }
}
//添加动态插件
Bx.Environment.addPlugin("share",  "Bx.Plugin.Others.Share","/js/plugins/share.js" );
Bx.Environment.addPlugin("weather", "Bx.Plugin.Others.Weather", "/plugins/weather/js.js");
Bx.Environment.addPlugin("siteapi", "Bx.Plugin.Others.SiteAPI", "/js/plugins/siteapi.js");
function webLoadParentPage(parentPageUrl)
{
    /// <summary>自动加载父层页面</summary>
    if (window == window.parent)
    {
        window.parent.location = parentPageUrl;
    }
}



function replaceParamVal(paramName, replaceWith)
{
    var oUrl = this.location.href.toString();
    var nUrl = "";
    if (Bx.Pub.GetUrlParam("ordermode") == "")
    {
        if (oUrl.indexOf("?") > 0)
        {
            nUrl = oUrl + ("&" + paramName + "=" + replaceWith);
        }
        else
        {
            nUrl = oUrl + ("?" + paramName + "=" + replaceWith);
        }
    }
    else
    {
        var re = eval('/(' + paramName + '=)([^&]*)/gi');

        nUrl = oUrl.replace(re, paramName + '=' + replaceWith);

    }
    this.location.href = nUrl;


}

var webHelper = web = function ()
{
    /// <summary>网页助手</summary>

    return {
        showCommentPnl: function (canv, ownerId, options)
        {
            bxPlugin.run("comment", function ()
            {
                bxComment.showPnl(canv, ownerId, options);
            }, true);
        },
        getLang: function ()
        {
            /// <summary>返回当前页面语言</summary>
            var url = window.location.href.toLowerCase();
            if (url.indexOf("/cn/") >= 0) { return siteConfig.defaultLang; }
            else if (url.indexOf("/en/") >= 0) { return "en"; }
            else if (url.indexOf("/jp/") >= 0) { return "jp"; }
            else { return siteConfig.defaultLang; }
        },
        initTab: function (obj)
        {
            /// <summary>初始化选项卡控件</summary>
            /// <param name="obj">对象</param>

            bxPlugin.run("tab", function ()
            {
                if (obj) { bxtTab.init(obj); }
                else
                {
                    bxTab.initDefault();
                }
            }, true);
        },
        loadVideo: function (canv, url, imgsrc, options)
        {
            /// <summary>加载视频</summary>
            var options = $O(options);
            var ps = { vcastr_file: url, LogoText: "", BufferTime: 3, IsAutoPlay: (options.p("isAutoPlay", false) ? 1 : 0) };
            
            bxWriteFlash(canv, "/skins/default/flash/flvplayer2.swf", options.p("playerid", "flvplayer"), "100%", "100%", 9, { wmode: "transparent", allowFullScreen: true }, ps);
            //bxWriteFlash("divVideo", swf, "f29", "100%", "100%", "7", { wmode: transparent, allowfullscreen: true }, { vcastr_file: flvUrl, LogoText: "", BufferTime: 3, IsAutoPlay: 1 });
        },
        fixArticle: function (articleId)
        {
            /// <summary>修复文章显示页面相关</summary>
            var pnl = $("divArticle" + articleId);
            var spHits = $("spArticleHits" + articleId);
            if (spHits)
            {
                bxPlugin.run("article", function ()
                {
                    bxArt.getHits(articleId, function (hits)
                    {
                        spHits.innerHTML = hits;
                    });
                }, true);
            }
            var aPre = $("aArticlePre" + articleId);
            if (aPre && aPre.innerHTML.trim() == "") { aPre.html(webHelper.getWords("没有了", "no")); aPre.href = "#none"; }
            var aNext = $("aArticleNext" + articleId);
            if (aNext && aNext.innerHTML.trim() == "") { aNext.html(webHelper.getWords("没有了", "no")); aNext.href = "#none"; }
        },
        addUserFav: function (favId, groupname, callBack)
        {
            /// <summary>添加到用户收藏夹</summary>

            bxPageAPI("/api/apiuser.aspx", "adduserfav", ["favid", favId, "groupname", groupname], function (code, mes, response)
            {
                if (code == 0)
                {
                    if (callBack) { callBack(code, mes, response); }
                }
                else
                {
                    alert(mes);
                }
            }, { appid: "BxUserAPI" });
        },
        runUserLogined: function (callBack, useOpenMode)
        {
            /// <summary>检测用户是否登录，并自动执行绑定方法</summary>
            ///<param name="useOpenMode">true:未登录时使用弹窗登录模式，false:使用页面跳转登录模式，无(null)：不做自动登录处理</param>
            bxPlugin.run("user", function ()
            {
                bxUser.runLogined(callBack, useOpenMode);
            }, true);

        },
        setHome: function (obj, url)
        {
            /// <summary>设为首页</summary>
            /// <param name="obj">操作对象</param>
            /// <param name="url">地址</param>
            if (document.all)
            {
                document.body.style.behavior = 'url(#default#homepage)';
                document.body.setHomePage(document.URL);
            } else if (window.sidebar)
            {
                if (window.netscape)
                {
                    try
                    {
                        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                    } catch (e)
                    {//火狐浏览器
                        alert("该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config, 然后将项 signed.applets.codebase_principal_support 值该为true");
                    }
                }
                var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                prefs.setCharPref('browser.startup.homepage', document.URL);
            }
        },
        getWords: function (cn, en, jp)
        {
            var lang = webHelper.getLang();
            if (lang == "en") { return en; }
            else if (lang == "jp") { return jp; }
            else { return cn; }
        },
        getWord: function (key)
        {
            var lang = webHelper.getLang();
            var o = siteConfig.langWords[key];
            return o[lang] ? o[lang] : o[siteConfig.defaultLang];
        },
        emailSubscribe: function (email, categoryId, callBack)
        {
            /// <summary>邮件预订</summary>
            var ps = { email: email, categoryid: categoryId };
            bxPageAPI("/api/api.aspx", "emailSubscribe", ps, function (code, mes, response)
            {
                if (code == 0) { alert("预订成功"); }
                else { alert("提交错误：" + mes); }
                if (callBack) { callBack(code, mes, response); }
            });
        },
        autoShare: function ()
        {
            bxBatch($C("autoShare"), function (d, i)
            {
                if (d.__hasShare) { return; }
                var d2 = $E("span", { className: 'spLinkList' });
                d.innerHTML = "<span class='spText'>分享到：</span>";
                d.appendChild(d2);
                webShare().writeAll(d2);

                d.__hasShare = true;
            });
        },
        autoSetFen: function (obj)
        {
            /// <summary>自动设置评价分数</summary>
            var sps = obj ? [$(obj)] : $C("autoFen"); //alert(sps.length);
            bxBatch(sps, function (sp, i)
            {
                if (sp.hasSet) { return; }
                sp.hasSet = true;
                var v = bxParseInt(sp.p("v", 0), 0);
                var tab = $E("table", { className: "tabFen" });
                tab.addRow();
                for (var j = 1; j <= 5; j++)
                {
                    if (v >= j) { tab.addCell().className = "v2"; }
                    else if (v >= j - 0.5) { tab.addCell().className = "v1"; }
                    else { tab.addCell().className = "v0"; }
                }
                sp.appendChild(tab);
            });
        },
        createWeather: function (options)
        {
            /// <summary>创建天气插件</summary>
            bxPlugin.run("weather", function () { bxWeather.create(options); }, true);
        },
        showUser: function (userid, page)
        {
            /// <summary>打开指定用户的页面</summary>
            /// <param name="userid">用户ID或用户名</param>
            /// <param name="page">要打开的子页面</param>
            window.open("/user/" + userid + "/" + (page ? ("#target=" + encodeURIComponent(page)) : ""));
            return false;
        }
    }
} ();

function webSearch()
{
    /// <summary>网站文章搜索</summary>
    var txt = $("txtKeywords");
    var str = txt.value.trim();
    if (str == "" || str == txt.defaultValue)
    {
        alert( web.getWord("searchErrorMessage")); return false;
    }
    var url = "/" + webHelper.getLang() + "/search.html?k=" + encodeURI(str);
    window.top.location.href = url;
    return false;
}

function webShare()
{
    /// <summary>返回网页共享操作类</summary>
    var share;
    bxPlugin.run("share", function ()
    {
        share = Bx.Plugin.Others.Share;
    });
    return share;

}
//#endregion

//#region 页面操作
var webPages = function ()
{
    return {
        comm: function ()
        {
            var config = {
                leftTitles: ["我的跑维", "跑维活动", "跑维影院", "跑维投票", "跑维俱乐部", "跑维论坛"]
            }
            return {
                init: function ()
                {
                    if ($("divTopUserInfo"))
                    {
                        addReady(function ()
                        {
                            webUserGetInfo("divTopUserInfo", function (code, mes, respone)
                            {
                                var fff = arguments.callee;
                                if (code == 0 && window.isPhotoPage != null)
                                {
                                    $("divTopUserInfo").html(respone.get("htmltext").replaceAll("<br />", " "));

                                }

                                var divTopQuickLog = $("divTopQuickLog");
                                if (divTopQuickLog)
                                {
                                    divTopQuickLog.getByClass("aLogSubmit").onclick = function ()
                                    {
                                        var a = this;
                                        var ps = { h: divTopQuickLog.getByClass("txtAddHour").value.trim(), d: divTopQuickLog.getByClass("txtDistance").value.trim(), t: divTopQuickLog.getByClass("txtTimespan").value.trim() };
                                        var m = "";
                                        if (!/^\d{1,2}$/.test(ps.h) || (ps.h = bxPub.parseInt(ps.h)) < 0 || ps.h > 23)
                                        {
                                            m += "请正确输入几点\n";
                                        }
                                        if (!/^\d{1,3}(\.\d{1,3})?$/.test(ps.d)) { m += "请正确输入距离\n"; }
                                        if (!/^\d{1,3}(:\d{1,2})?$/.test(ps.t)) { m += "请正确输入用时分钟，格式为“分”或“分:秒”"; }
                                        if (m.length > 0) { alert(m); return false; }
                                        a.disabled = true;
                                        web.runUserLogined(function ()
                                        {
                                            bxPageAPI("/api/api.aspx", "topQuickAddLog", ps, function (code, mes, response)
                                            {
                                                a.disabled = false;
                                                if (code == 0)
                                                {
                                                    if (confirm("提交成功,点“确定”转到我的训练记录"))
                                                    {
                                                        window.top.location.href = "/html/user/index.aspx#target=%2Fhtml%2Fuser%2Fpblog%2Fpbcalendar.aspx";
                                                    } else
                                                    {
                                                        webUserGetInfo("divTopUserInfo", fff); fff = null;
                                                    }
                                                }
                                                else if (code == 2)
                                                {
                                                    alert("请先登录");

                                                }
                                                else { alert(mes); }

                                            });
                                        }, true);

                                        return false;
                                    }
                                }
                            });
                        });
                    }
                    if ($("divTopCart")) { pdtCart.getCount(function (code, mes, response) { if (code == 0) { $("divTopCart").html(response.get("count")); } }); }

                    bxBatch($C("divLeftTitle"), function (d, i)
                    {
                        var sp = $T("span", d)[0], n = sp.p("title");
                        var index = config.leftTitles.indexOf(n);
                        if (index >= 0) { sp.css("background-position-y", index * -20 + "px") }
                        else { sp.css("background", "none"); sp.innerHTML = n; }
                    });
                    addOnload(function ()
                    {
                        bxSys.runJsFile(Bx.Environment.GetWebSiteUrl("/api/api.aspx?method=getFloatWindow&mode=normal"), function ()
                        {
                        }, true);
                    });
                    bxPlugin.addLazyloadTextarea();
                    webHelper.autoShare();
                    if ($("divRightTop")) { webRightTop.init(); }

                }
            }

        } (),
        index: function ()
        {
            var config = { userId: 0, topicId: 0, colors: ["#FCAF5D", "#38B978", "#01AEF0", "#A963A9", "#F36324", "#8AC640"], scrollTimespan: 1000, scrollDuration: 1000, hdCity: "", hdClub: "", hdType: "", nextHdListPageIndex: 1, hdTimer: 0, hdTimeSpan: 10000, hdYear: new Date().getFullYear(), hdMonth: new Date().getMonth() + 1, hdByDate: false }
            return {
                init: function ()
                {
                    var thisObj = this;
                    bxPageAPI("/api/api.aspx", "initIndexPage", {}, function (code, mes, response)
                    {
                        if (code == 0)
                        {
                            var xml = response.get("focusxml");
                            var divEventScroll = $("divEventScroll");
                            divEventScroll.innerHTML = response.get("htmlevent");
                            bxBatch($C("divTime", divEventScroll, "div"), function (d, i)
                            {
                                var dt = new Date(d.innerHTML);
                                d.innerHTML = bxPub.timeToSpan(dt);
                            });
                            bxBatch($T("a", divEventScroll), function (a, i) { a.target = "_blank"; });
                            var ul = $T("ul", divEventScroll)[0];
                            if (!ul) { return; }

                            var tweener = null;
                            function scroll()
                            {
                                var li = $(ul.lastChild); if (li == null) { return; }
                                tweener = bxMotion.tween(ul, { top: { to: li.offsetHeight} }, { duration: config.scrollDuration, onEnd: function ()
                                {
                                    ul.css("top", "0px");
                                    li.css("opacity", 0);
                                    ul.insertBefore(li, ul.firstChild);
                                    bxMotion.fade(li, { to: 1, onEnd: function ()
                                    {
                                        setTimeout(scroll, config.scrollTimespan);
                                    }
                                    });


                                }
                                });
                                tweener.play();
                            }
                            scroll();
                            var pauseTimer = 0;
                            ul.onmouseover = function () { clearTimeout(pauseTimer); tweener.pause(); }
                            ul.onmouseout = function () { pauseTimer = setTimeout(tweener.resume, 100); }
                            bxPlugin.initImagesPlayer("divFocus", 1, eval("(" + xml + ")"), {}, function ()
                            {
                                this.play();
                            });

                        }
                        else
                        {
                            alert(mes);
                        }
                    });
                    var lis = $T("li", $("ulVideoList")), aBtnVcs = $C("aBtnVideoCategory");
                    bxBatch(aBtnVcs, function (a, i)
                    {
                        a.onmouseover = function ()
                        {
                            var pId = a.p("pid");
                            lis.each(function (li, j)
                            {
                                if (li.p("pid") == pId && li.p("tj") == "")
                                {
                                    li.css("display", "inline");
                                } else { li.css("display", "none"); }
                            });
                            bxBatch(aBtnVcs, function (a2, k)
                            {
                                if (a2 != a) { bxStyle.removeClassName(a2, "selected"); }
                                else { bxStyle.addClassName(a2, "selected"); }
                            });
                        }
                    });
                    bxBatch(lis, function (li, i)
                    {
                        li.onmouseover = function ()
                        {
                            for (var j = 0; j < lis.length; j++)
                            {
                                lis[j].className = i == j ? "selected" : "";
                            }
                            var aLink = $("aLink");
                            aLink.href = "/html/video/v-" + li.p("vid") + ".html";
                            $T("img", aLink)[0].src = li.p("imageurl");
                        }
                    });
                    lis[0].onmouseover();
                    this.initVote();


                    $("btnLeftSearch").onclick = function ()
                    {
                        var url = "/html/huodong/search_s_0_" + $("selLeftTime").value + ".html";
                        window.top.location.href = url;
                    }

                    //#region 初始化活动
                    var txtHdSearchCity = $("txtHdSearchCity"), txtHdSearchClub = $("txtHdSearchClub"), ulHdSearchClub = $("ulHdSearchClub"), ulHdSearchCity = $("ulHdSearchCity"), btnHdSearchPersonal = $("btnHdSearchPersonal"), btnHdSearchBisai = $("btnHdSearchBisai"), txtHdYear = $("txtHdYear"), ulHdYearList = $("ulHdYearList"), divHdMonth = $("divHdMonth"), chkHdByDate = $("chkHdByDate");
                    bxTextSetRemark(txtHdSearchCity, "城 市", true);
                    bxTextSetRemark(txtHdSearchClub, "俱乐部", true);
                    txtHdSearchClub.onfocus = function () { ulHdSearchClub.css("visibility", "visible"); }
                    txtHdSearchClub.onblur = function ()
                    {
                        setTimeout(function ()
                        {
                            ulHdSearchClub.css("visibility", "hidden");
                            var txt = txtHdSearchClub.value.trim();
                            txt = (txt == txtHdSearchClub.defaultValue ? "" : txt);
                            if (txt != config.hdClub) { config.hdClub = txt; webPages.index.getHdList(1); }
                        }, 200);
                    }
                    $T("li", ulHdSearchClub).each(function (li, i) { li.onclick = function () { txtHdSearchClub.value = this.innerHTML; } });
                    txtHdSearchCity.onfocus = function () { ulHdSearchCity.css("visibility", "visible"); }
                    txtHdSearchCity.onblur = function ()
                    {
                        setTimeout(function ()
                        {
                            ulHdSearchCity.css("visibility", "hidden");
                            var txt = txtHdSearchCity.value.trim();
                            txt = (txt == txtHdSearchCity.defaultValue ? "" : txt);
                            if (txt != config.hdCity) { config.hdCity = txt; webPages.index.getHdList(1); }
                        }, 200);
                    }
                    txtHdSearchClub.onclick = function ()
                    {
                        bxStyle.addClassName(this, "selected");
                        bxStyle.removeClassName(btnHdSearchPersonal, "selected");
                        bxStyle.removeClassName(btnHdSearchBisai, "selected");
                        config.hdType = "club";
                    }
                    $T("li", ulHdSearchCity).each(function (li, i) { li.onclick = function () { txtHdSearchCity.value = this.innerHTML; } });
                    btnHdSearchPersonal.onclick = function ()
                    {
                        bxStyle.addClassName(this, "selected");
                        bxStyle.removeClassName(btnHdSearchBisai, "selected");
                        bxStyle.removeClassName(txtHdSearchClub, "selected");
                        config.hdType = "personal";
                        txtHdSearchClub.value = txtHdSearchClub.defaultValue;
                        thisObj.getHdList(1);
                    }
                    btnHdSearchBisai.onclick = function ()
                    {
                        bxStyle.addClassName(this, "selected");
                        bxStyle.removeClassName(btnHdSearchPersonal, "selected");
                        bxStyle.removeClassName(txtHdSearchClub, "selected");
                        config.hdType = "bisai";
                        txtHdSearchClub.value = txtHdSearchClub.defaultValue;
                        thisObj.getHdList(1);
                    }
                    txtHdYear.value = config.hdYear + "年";
                    txtHdYear.onfocus = function (evt) { ulHdYearList.css("visibility", "visible"); }
                    txtHdYear.onblur = function ()
                    {
                        setTimeout(function ()
                        {
                            ulHdYearList.css("visibility", "hidden");
                            var txt = txtHdYear.value.trim();
                            //txt = (txt == txtHdYear.defaultValue ? "" : txt);
                            if (bxPub.parseInt(txt, 0) != config.hdYear) { config.hdYear = bxPub.parseInt(txt, 2010); config.hdByDate = chkHdByDate.checked = true; webPages.index.getHdList(1); }
                            else
                            {
                                if (!config.hdByDate) { config.hdByDate = chkHdByDate.checked = true; thisObj.getHdList(1); }
                            }
                        }, 200);
                    }
                    $T("li", ulHdYearList).each(function (li, i) { li.onclick = function () { txtHdYear.value = this.innerHTML + "年"; } });
                    chkHdByDate.checked = config.hdByDate;
                    divHdMonth.css("background-position", "left -" + (config.hdMonth - 1) * 40 + "px");
                    $("aMonthPrev").onclick = function ()
                    {
                        config.hdMonth--;
                        if (config.hdMonth < 1) { config.hdMonth = 12; config.hdYear--; txtHdYear.value = config.hdYear + "年"; }
                        divHdMonth.css("background-position", "left -" + (config.hdMonth - 1) * 40 + "px");
                        config.hdByDate = chkHdByDate.checked = true;
                        if (config.hdByDate) { thisObj.getHdList(1); }
                        return false;
                    }
                    $("aMonthNext").onclick = function ()
                    {
                        config.hdMonth++;
                        if (config.hdMonth > 12) { config.hdMonth = 1; config.hdYear++; txtHdYear.value = config.hdYear + "年"; }
                        divHdMonth.css("background-position", "left -" + (config.hdMonth - 1) * 40 + "px");
                        config.hdByDate = chkHdByDate.checked = true;
                        if (config.hdByDate) { thisObj.getHdList(1); }
                        return false;
                    }
                    divHdMonth.onclick = function () { if (!config.hdByDate) { config.hdByDate = chkHdByDate.checked = true; thisObj.getHdList(1); } }
                    chkHdByDate.onchange = chkHdByDate.onclick = function () { config.hdByDate = chkHdByDate.checked; thisObj.getHdList(1); }
                    this.getHdList(1);
                    //#endregion
                },
                initVote: function ()
                {
                    var chks = [], maxSelected = 0;
                    bxPageAPI("/api/api.aspx", "runffInitIndexPageVote", {}, function (code, mes, response)
                    {
                        var canv = $("divVote");
                        if (code == 0)
                        {
                            canv.html(response.get("htmltext"));
                            var totalCount = response.getInt("totalcount");
                            $("spVoteCount").html(totalCount);
                            config.topicId = response.getInt("topicid");
                            maxSelected = bxPub.parseInt(response.get("maxcount"), 0);
                            bxBatch($T("tr", canv), function (tr, i)
                            {
                                var v = bxPub.parseInt(tr.p("v", 0), 0);
                                var percent = Math.floor(v * 1000 / totalCount) / 10;
                                if (isNaN(percent)) { percent = 0; }
                                percent += "%";
                                var bar = tr.getByClass("spBar");
                                bar.css("width", percent);
                                if (i < config.colors.length)
                                {
                                    bar.css("background-color", config.colors[i]);
                                }
                                tr.getByClass("td3").innerHTML = v;
                                tr.getByClass("td5").innerHTML = "(" + percent + ")";
                                SysAddEvent(tr, "onclick", function (evt)
                                {
                                    var t = bxSys.getEventSrc(evt);
                                    var chk = t.tagName == "input" ? t : $T("input", tr)[0];
                                    //bxSys.preventDefault(evt); bxSys.cancelBubble(evt);
                                    if (t != chk)
                                    {
                                        chk.checked = !chk.checked;
                                    }
                                    if (getSelectedCount() > maxSelected)
                                    {
                                        chk.checked = false;
                                        alert("最多只能选择 " + maxSelected + " 项"); return false;
                                    }
                                });

                                chks = $N("chkAnswer");
                            });
                            $('btnVote').onclick = webPages.index.vote;
                            function getSelectedCount()
                            {
                                var i = 0;
                                chks.each(function (c) { if (c.checked) { i++; } });
                                return i;
                            }
                        }

                        else
                        {
                            alert(mes);
                        }
                    });
                },
                vote: function ()
                {
                    var ps = { topicid: config.topicId, isnotice: $("chkIsNotice").checked, answerids: [] }
                    bxBatch($N("chkAnswer"), function (chk, i)
                    {
                        if (chk.checked) { ps.answerids.push(bxPub.parseInt(chk.value, 0)); }
                    });
                    ps.answerids = ps.answerids.join(",");
                    var url = "/html/vote/topic-" + config.topicId + ".html";
                    bxPageAPI(url, "vote", ps, function (code, mes, response)
                    {
                        if (code == 0)
                        {
                            alert("投票成功，感谢您的支持和参与");
                            window.top.location.href = url;
                        }
                        else if (code == 2)
                        {
                            alert("请先登录");
                            bxUser.runLogined(webPages.index.vote, true);
                        }
                        else { alert(mes); }
                    });
                },
                getHdList: function (pageIndex)
                {
                    var divHdList = $("divHdList");
                    if (divHdList.onmouseover == null)
                    {
                        divHdList.onmouseover = function () { clearTimeout(config.hdTimer); }
                        divHdList.onmouseout = function () { if (config.nextHdListPageIndex > 0) { config.hdTimer = setTimeout(function () { webPages.index.getHdList(pageIndex + 1); }, config.hdTimeSpan); } }
                    }
                    //divHdList.html("<div class='loading'></div>");
                    bxPageAPI("", "getHdList", { pageIndex: pageIndex, city: config.hdCity, club: config.hdClub, hdtype: config.hdType, year: config.hdYear, month: config.hdMonth, bydate: config.hdByDate }, function (code, mes, response)
                    {
                        if (code == 0)
                        {
                            divHdList.html(response.get("htmltext"));
                            $C("trItem").each(function (tr, i)
                            {
                                bxSys.addEvent($T("a", tr)[0], "onclick", function (evt) { bxSys.cancelBubble(evt); });
                                tr.onclick = function () { window.open($T("a", this)[0].href); }
                                web.autoSetFen();
                            });
                            var totalPage = bxPub.parseInt(response.get("totalpage"), 0);
                            clearTimeout(config.hdTimer);
                            if (totalPage > 1)
                            {
                                config.nextHdListPageIndex = (pageIndex >= totalPage) ? 1 : (pageIndex + 1);
                                config.hdTimer = setTimeout(function () { webPages.index.getHdList(config.nextHdListPageIndex); }, config.hdTimeSpan);
                            } else { config.nextHdListPageIndex = 0; }
                        }
                        else { divHdList.innerHTML = mes; }
                    });
                }
            }
        } (),
        userIndex: function ()
        {
            var config = { userId: 0, isSelf: false }

            return {
                init: function (options)
                {
                    bxPub.extend(config, options);
                    webRightTop.init({ userId: config.userId, isOtherHome: !config.isSelf });
                    var ifrTarget = $("ifrTarget");
                    this.setTarget(getTarget());
                    setTimeout(function ()
                    {
                        var t1 = new Date();
                        bxPub.resizeIframe();
                        var bd = bxGetBodyDocumentElement(ifrTarget.contentWindow);
                        //bxDebugger.appendLine(ifrTarget.parentNode.offsetHeight);
                        setTimeout(arguments.callee, 1000);
                        var t2 = new Date();
                        //bxDebugger.appendLine((t2 - t1));
                    }, 200);
                    ifrTarget.onload = function ()
                    {
                        var wnd = ifrTarget.contentWindow; //alert(wnd._tabBack);
                        var pnl = $("divUserIndex");
                        if (wnd._pnlClass) { pnl.className = "divHA divUserIndex " + wnd._pnlClass; }
                        else { pnl.className = "divHA divUserIndex"; }
                        window.top.location.hash = "#target=" + encodeURIComponent(wnd.location.pathname + wnd.location.search + wnd.location.hash);
                        //alert(encodeURIComponent(wnd.location.pathname + wnd.location.search + wnd.location.hash);
                    }
                },
                setTarget: function (target)
                {
                    window.top.location.hash = "#target=" + encodeURIComponent(target);
                    var ifrTarget = $("ifrTarget");
                    ifrTarget.src = target;
                    return false;
                },
                setPnlClass: function (newClassname)
                {
                    var wnd = ifr.contentWindow;
                    var pnl = $("divUserIndex");
                    if (newClassname && newClassname.length > 0) { pnl.className = "divHA divUserIndex " + newClassname; }
                    else { pnl.className = "divHA divUserIndex"; }
                },
                getVisitUser: function ()
                {
                    bxPageAPI("", "getVisitUser", {}, function (code, mes, response)
                    {
                        if (code == 0)
                        {
                            $("spVisitCount").html(response.get("totalcount"));
                            $("divVisitorList").html(response.get("htmltext"));
                            //$("divFriendList").html(response.get("htmltext"));
                        }
                        else { alert(mes); }
                    });
                }
            }
            function getTarget()
            {
                var str = window.top.location.hash;
                if (str.length > 1)
                {
                    var qs = new bxQueryString(str.substr(1), false);
                    str = qs.getValue('target');
                }
                else { str = ""; }
                return str.length > 0 ? decodeURIComponent(str) : "userindex.aspx";
            }

        } (),
        yuepao: function ()
        {
            var config = { userId: 0 }
            return {
                init: function (userId, pageType)
                {
                    config.userId = userId;
                    if (pageType == "list")
                    {
                        bxBatch($T("tr", $("tabHdList")), function (tr, i)
                        {
                            if (i >= 1)
                            {
                                tr.onclick = function ()
                                {
                                    tr.getByClass("aName").click();
                                }
                            }
                        });
                    }
                    else if (pageType == "detail")
                    {

                    }
                }
            }
        } (),
        map: {
            config: { zoom: 17 },
            init: function (lat, lng, address, message)
            {
                var config = this.config;
                config.lat = lat;
                config.lng = lng;
                config.address = address;
                config.message = message;
                config.canv = $("divMap");
                addOnload(function ()
                {
                    if (lat == "" || lng == "")
                    {
                        bxPlugin.run("map", function ()
                        {
                            mapHelper.getFromAddress(address, function (latLng)
                            {

                                if (latLng)
                                {
                                    config.lat = latLng.lat();
                                    config.lng = latLng.lng();
                                    webPages.map.loadMap();
                                }
                            });
                        });
                    } else
                    {
                        webPages.map.loadMap();
                    }
                });
                SysAddEvent(window, "onunload", GUnload);
            },
            loadMap: function ()
            {
                var map = new GMap2(this.config.canv);
                var config = this.config;
                // Palo Alto, CA
                var latLng = new GLatLng(config.lat, config.lng);
                map.setCenter(latLng, config.zoom);
                map.enableScrollWheelZoom();
                map.addControl(new GLargeMapControl3D());
                map.enableContinuousZoom();
                // Add GHierarchicalMapTypeControl
                map.addMapType(G_PHYSICAL_MAP);
                var hControl = new GHierarchicalMapTypeControl();
                hControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", false);
                map.addControl(hControl);
                var marker = new GMarker(latLng);
                GEvent.addListener(marker, "click", function ()
                {
                    marker.openInfoWindowHtml(config.message);
                });
                map.addOverlay(marker); //添加标记
                map.openInfoWindowHtml(map.getCenter(),
                           config.message); //信息窗口
                // Add ContextMenuControl to the map
                map.addControl(new ContextMenuControl());
            }
        },
        videoDetail: function ()
        {
            var config = {}
            return {
                init: function (videoInfo)
                {
                    var url = videoInfo.url;
                    if (url.indexOf('.flv') > 0)
                    {
                        //$("divPlayer").css("height", "260px");
                        webHelper.loadVideo("divPlayer", url, videoInfo.imageurl, {});
                    } else
                    {
                        bxWriteFlash("divPlayer", url, "f2", "100%", "100%", 8, { AllowFullScreen: true });
                    }
                    webHelper.showCommentPnl("divCommentPnl", videoInfo.id, { appcode: "Video" });
                    bxPageAPI("/api/api.aspx", "runffInitVideoDetail", { vid: videoInfo.id }, function (code, mes, response)
                    {
                        if (code == 0)
                        {
                            $("spCommentCount").html(response.get("commentcount"));
                            $("fav").getByClass("count").html(response.get("favcount"));
                            $("up").getByClass("count").html(response.get("dingcount"));
                            $("down").getByClass("count").html(response.get("caicount"));
                            $("spHits").html(response.get("hits"));
                        }
                        else { alert(mes); }
                    });
                    $("fav").onclick = function ()
                    {
                        webHelper.addUserFav(videoInfo.id, "video", function () { alert("收藏成功"); });
                    }
                    $("up").onclick = function ()
                    {
                        bxPageAPI("/api/api.aspx", "runffVideoDing", { vid: videoInfo.id }, function (code, mes, response)
                        {
                            if (code == 0)
                            {
                                $("up").getByClass("count").html(response.get("newcount"));
                            }
                            else
                            {
                                alert(mes);
                            }
                        });
                    }
                    $("down").onclick = function ()
                    {
                        bxPageAPI("/api/api.aspx", "runffVideoCai", { vid: videoInfo.id }, function (code, mes, response)
                        {
                            if (code == 0)
                            {
                                $("cai").getByClass("count").html(response.get("newcount"));
                            }
                            else
                            {
                                alert(mes);
                            }
                        });
                    }
                    $("send").onclick = function ()
                    {
                        webShare().toAll(this);
                    }
                    $("share").onclick = function ()
                    {
                        SetClipboardText(window.top.location.href);
                        alert("网址已经复制到剪粘板");
                    }
                }
            }
        } (),
        quickPart: function ()
        {
            var config = {}
            return {
                init: function (canv)
                {

                }
            }
        } (),
        topicVoteList: function ()
        {
            return {
                init: function ()
                {
                    $C("aVote").each(function (a, i)
                    {
                        a.onclick = function ()
                        {
                            this.disabled = true;
                            var li = $($P(this, "li"));
                            bxPageAPI("", "voteinlist", { id: bxPub.parseInt(li.p("aid"), 0) }, function (code, mes, response)
                            {
                                if (code == 0)
                                {
                                    li.getByClass("spCount").html(response.get("newcount"));
                                }
                                else { alert(mes); a.disabled = false; }

                            });
                            return false;
                        }

                    });

                }
            }
        } (),
        topicVoteDetail: function ()
        {
            return {
                init: function (aId)
                {
                    web.showCommentPnl("divCommentPnl", aId, { appcode: "Article" });
                    var spVote = $("spVote");
                    spVote.onclick = function ()
                    {
                        bxPageAPI("", "voteinlist", { id: aId }, function (code, mes, response)
                        {
                            if (code == 0)
                            {
                                spVote.html(response.get("newcount"));
                            }
                            else { alert(mes); }

                        });
                    }
                }
            }
        } ()
    }
} ();
//#endregion


var webRightTop = function ()
{
    var config = { userId: 0, canv: $(), isOtherHome: false }
    var tags = { txtSsWordsAdd: $() }
    return {
        init: function (options)
        {
            bxPub.extend(config, options);
            config.canv = $("divRightTop");
            bxPageAPI("/api/api.aspx", "initRightTop", { userId: config.userId, isOtherHome: config.isOtherHome }, function (code, mes, response)
            {
                if (code == 0)
                {
                    config.canv.html(response.get("htmltext"));
                    var txtSsWordsAdd = $("txtSsWordsAdd");
                    var spWordCount = $("spWordCount");
                    bxTextAreaAutoHeight(txtSsWordsAdd, 30);
                    bxTextSetRemark(txtSsWordsAdd, "说点什么吧...", true);
                    bxTextShowWordCount(txtSsWordsAdd, { objShow: spWordCount, maxCount: 200, autoHide: true });
                    var btnAdd = $("btnSsWordSubmit");
                    btnAdd.onclick = function ()
                    {
                        webHelper.runUserLogined(function ()
                        {
                            var ff = arguments.callee;
                            var ps = { content: $("txtSsWordsAdd").value.trim() };
                            if (ps.content == "" || ps.content == txtSsWordsAdd.defaultValue)
                            {
                                alert("请填写内容"); return false;
                            }
                            btnAdd.disabled = true;
                            bxPageAPI("/api/api.aspx", "runffAddShuoshuo", ps, function (code, mes, response)
                            {
                                if (code == 0)
                                {
                                    txtSsWordsAdd.value = "";
                                    txtSsWordsAdd.blur();
                                    webRightTop.getRecentShuoshuo();
                                    alert("发表成功");
                                }
                                else { alert(mes); }
                                btnAdd.disabled = false;
                            });
                        }, true);
                    }
                    var userId = bxPub.parseInt(response.get("userid"), 0);
                    if (userId > 0)
                    {
                        $("imgPhoto").onclick = function ()
                        {
                            var ifr = $("ifrTarget"); if (ifr) { ifr.src = "BaseInfo.aspx"; }
                            else
                            {
                                web.showUser(userId);
                            }
                        }

                    } else
                    {
                        $("imgPhoto").onclick = function ()
                        { webShowLogin(null, function () { window.location.reload(); }); }
                    }
                    webRightTop.getRecentShuoshuo();

                }
                else { config.canv.html(mes); }
            });

        },
        getRecentShuoshuo: function ()
        {
            bxPageAPI("/api/api.aspx", "runffGetRecentShuoshuo", {}, function (code, mes, response)
            {
                if (code == 0) { $("divSsRecent").html(response.get("htmltext")); }
                else { alert(mes); }
            });
        }
    }
} ();
