﻿
/// <reference path="BxJsLib.js" />
/// <reference path="BxUser.js" />
/// <reference path="BxGuestbook.js" />
/// <reference path="BxComment.js" />

//常用公共部分，请不要轻易修改删除
//#region 常用公共部分，请不要轻易修改删除
//站点配置
var siteConfig = { defaultLang: "cn" //默认语言版本
}
//添加动态插件
Bx.Environment.addPlugin("share",  "Bx.Plugin.Others.Share","/js/plugins/share.js" );

function imgError(imgObj, imgSrc)
{
    var src = imgSrc ? imgSrc : "/skins/default/images/nopic1.gif";
    $(imgObj).src = src;
}
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 = 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 ps = { vcastr_file: url, LogoText: "", BufferTime: 3, IsAutoPlay: (options.p("isAutoPlay", false) ? 1 : 0) };
            var options = options || {};
            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 });
        },
        resizeIframe: function (ifr, param)
        {
            /// <summary>重新调整iframe页面</summary>
            /// <param name="param">参数值,heightAdd:高度增加值</param>

            var ifr = ifr;
            if (ifr == null)
            {
                var f = $C("ifrAuto");
                if (f.length > 0)
                {
                    bxBatch(f, function (obj, index) { webHelper.resizeIframe(obj); });
                }
                else if (window.parent != window)
                {
                    window.parent.webHelper.resizeIframe();
                }
            }
            else
            {
                try
                {
                    var p = ifr.parentNode;
                    var ph = bxGetRuntimeStyle(p, "height");
                    p.style.height = p.offsetHeight + "px";
                    ifr.style.height = "1px";
                    ifr.style.height = bxGetBodyDocumentElement(ifr.contentWindow).scrollHeight + bxGetProperty(param, "heightAdd", 0) + "px";
                    p.style.height = ph;
                } catch (e) { }
            }
        },
        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>
            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; }
        }
    }
} ();
var lang = webHelper.getLang();
//#endregion



function webShare()
{
    /// <summary>返回网页共享操作类</summary>
    var share;
    bxPlugin.run("share", function ()
    {
        share = Bx.Plugin.Others.Share;
    });
    return share;

}

var webPages = function ()
{
    return {
        comm:
        {
            init: function ()
            {
                if ($("divTopUserInfo")) { addReady(function () { webUserGetInfo("divTopUserInfo"); }); }
                if ($("divTopCart")) { pdtCart.getCount(function (code, mes, response) { if (code == 0) { $("divTopCart").html(response.get("count")); } }); }

                var divIndexFocus = $("divIndexFocus"), divPdt3 = $("divIndexPdt3");
                document.body.insertBefore(divIndexFocus, document.body.childNodes[0]);
                divIndexFocus.css("display", "block");
                var f = function () { divIndexFocus.css("marginLeft", 0 - divIndexFocus.offsetWidth / 2 + "px"); }
                //SysAddEvent(window, "onresize", f);
                //f();
                var divMain = $C("divPageMain")[0];
                divMain.insertBefore(divPdt3, divMain.childNodes[0]);
                var player = $("ucPdtScroll3").player;
                $("divDown").onclick = function ()
                {
                    player.doScroll(3);
                }
                $("divUp").onclick = function ()
                {
                    player.doScroll(4);
                }
            }
        },
        index:
        {
            init: function ()
            {
                
            }
        },
        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());
            }
        },
        articleDown: {
            init: function (aId)
            {
                bxPageAPI("/api/api.aspx", "getArtDownContent", { articleid: aId }, function (code, mes, response)
                {
                    if (code == 0)
                    {
                        $("divArtContent").html(response.get("htmltext"));
                        var divLoginText = $("divLoginText");
                        if (divLoginText)
                        {
                            //divLoginText.html("<a href='/html/user/login2.html?ReturnUrl=" + encodeURIComponent(window.location.href) + "'>登录后查看更多信息&gt;&gt;</a>");
                            divLoginText.html("<a href='#none' onclick='webShowLogin(null,function(){webUserGetInfo();webPages.articleDown.init(" + aId + ")});return false;'>登录后查看更多信息&gt;&gt;</a>");
                        }
                    }
                    else
                    {
                        alert(mes);
                    }
                });
            }
        },
        partner: function ()
        {
            return {
                init: function ()
                {
                    var btnSearch = $("btnPartnerSearch");
                    btnSearch.onclick = function ()
                    {
                        webPages.partner.getList();
                    }
                    this.addPoint(430, 75, "北京市");
                    this.addPoint(530, 145, "上海市");
                     this.addPoint(350, 170, "湖南省");
                   this.addPoint(310, 175, "重庆市");
                    this.addPoint(380, 65, "内蒙古区");
                    this.addPoint(300, 110, "陕西省");
                    this.addPoint(480, 140, "安徽省");
                    this.addPoint(480, 100, "山东省");
                    this.addPoint(490, 60, "辽宁省");

                    webPages.partner.getList();
                },
                getList: function ()
                {
                    var canv = $("divSearchList");
                    bxPageAPI("/api/api.aspx", "getPartnerList", { city: $("selPartnerSearchCity").value, name: $("txtPartnerSearchName").value.trim() }, function (code, mes, response)
                    {
                        if (code == 0)
                        {
                            canv.html(response.get("htmltext"));
                        }
                        else { alert(mes); }
                    });
                },
                addPoint: function (x, y, name)
                {
                    var d = $E("div", { className: 'divPoint' });
                    d.html("<div class='divInfo'>" + name + "</div>");
                    d.css("left", x + "px").css("top", y + "px");
                    $("divMap").appendChild(d);
                    d.onmouseover = function ()
                    {
                        d.getByClass("divInfo").css("display", "block");
                    }
                    d.onmouseout = function ()
                    {
                        d.getByClass("divInfo").css("display", "none");
                    }
                    d.onclick = function ()
                    {
                        $("selPartnerSearchCity").value = d.getByClass("divInfo").html();
                        $("txtPartnerSearchName").value = "";
                        webPages.partner.getList();
                    }
                    if (bxNavigator.IsIE6)
                    {
                        bxIe6Png.fixBackground(d);
                    }
                }
            }
        } ()
    }
} ();
//#endregion


var webListImgView = function ()
{
    var tags = {
        imgBig: $("")
    }
    var hideTimer = 0;
    return {
        init: function ()
        {
            tags.imgBig = $E("img", { className: "imgListView", src: "/skins/default/images/blank.gif" });
            document.body.insertBefore(tags.imgBig, document.body.childNodes[0]);
            var bd = bxGetBodyDocumentElement();
            bxBatch($T("img", $C("divImgsListView")[0]), function (img, i)
            {
                img.onmouseover = function ()
                {
                    clearTimeout(hideTimer);
                    var xy = img.xy();
                    xy.x += 60;
                    xy.y += 60;
                    if (xy.x + 295 >= bd.clientWidth)
                    {
                        xy.x = xy.x - 295;
                    }
                    if (xy.y + 295 >= bd.clientHeight + bd.scrollTop)
                    {
                        xy.y = xy.y - 295;
                    }
                    tags.imgBig.css("left", xy.x + "px").css("top", xy.y + "px").css("display", "block");
                    tags.imgBig.src = this.p("src");
                    tags.imgBig.onclick = function () { $P(img, "a").click(); }
                }
                img.onmouseout = function ()
                {
                    hideTimer = setTimeout(function () { tags.imgBig.css("display", "none"); }, 200);
                    
                }
            });
            tags.imgBig.onmouseover = function ()
            {
                clearTimeout(hideTimer);
            }
            tags.imgBig.onmouseout = function ()
            {
                hideTimer = setTimeout(function () { tags.imgBig.css("display", "none"); }, 200);
            }
        }
    }
} ();

function fixLeftNavi()
{
    var liSel = $C("liNaviItemSelected");
    if (liSel.length == 0) { return; }
    liSel = liSel[0];
    if (bxStyle.CheckCssName(liSel, "liDepth2"))
    {
        $(liSel.parentNode).css("display", "block");
    }
}
