﻿var isComplete = false;
function InitPage() {
    initPos();
    if (Ext.isIE) {
        StartforIE();
    } else DoInit();
}

function StartforIE() {
    if (document.readyState != "complete") {
        window.setTimeout("InitPage()", 500);
    } else {
        DoInit();
    }
}

function DoInit() {
    InitFundData();
    LoadCompanyData();
    __loadbackAd();
}

function initPos() {
    __InitPos("当前位置：<a href='/Index.html'>首页</a> >> 每日开放式基金净值");
}

function isPopupsLoaded() {
    return typeof (Popups) != 'undefined';
}

function isOpenwindowLoaded() {
    return typeof (openwindow) == 'function';
}

function __loadCookie() {
    __JavascriptLoader("/js/Cookie.js", new Function());
}
 function LoadCompanyData() {
     __JavascriptLoader("http://hqqd.fund123.cn/funddata.js", new Function());
 }
function __loadPopups(fncallBack) {
    if (typeof (Popups) == 'undefined') {
        __JavascriptLoader("/js/Popups.js", fncallBack);
    }
}

function __loadQuickHelp() {
    SetCookieEx("SHelp", "1", 10);
    __JavascriptLoader("/JS/QuickHelp.js", ShowHelp);
}

function __loadOpenWin(fncallBack) {
    __JavascriptLoader("/JS/openwindow.js", new Function());

    __JavascriptLoader("http://hqqd.fund123.cn/fundNameMap.js", fncallBack);
}

function __loadbackAd() {
    if (document.readyState && document.readyState != "complete") {
        window.setTimeout("__loadbackAd()", 500);
    } else {
        var date = new Date();
        if ((date.getHours() > 17 || (date.getHours() == 17 && date.getMinutes() >= 30))) {
            var isShowd = GetCookie("BAd");
            if (!isShowd) {
                ShowBackAd();
            }
            else {
                window.setTimeout("__loadFlayAd()", 3000);
            }

            SetCookieEx("BAd", "1", 1);
        }
        else {
            ShowBackAd();
        }
    }
}

function ShowBackAd() {
    try {
        var top = document.getElementById("top");
        var div = document.createElement("DIV");
        div.id = "dayBackAD";

        with (div.style) {
            height = "1px";
            width = "100%";
            zIndex = 9999;
            display = "none";
        }

        top.appendChild(div);
        __JavascriptLoader("http://gg.fund123.cn/Get.aspx?key=nv_back", backAdgo);
    }
    catch (e) { alert(e) }
}

function backAdgo() {
    var div = document.getElementById("dayBackAD");
    if (div.style.display == "none") {
        //3秒后才显示漂浮广告
        window.setTimeout("__loadFlayAd()", 3000);
    }
    else {
        div.style.height = '300px';
        window.timer = window.setInterval("closebackAd()", _time_);
    }
}

function closebackAd() {
    var top = document.getElementById("top");
    var div = document.getElementById("dayBackAD");
    div.style.display = "none";
    top.removeChild(div);
    window.clearInterval(window.timer);
}

function __loadNvBottomAd() {
    __JavascriptLoader("http://gg.fund123.cn/JSLoad.aspx?HtmlID=nv_bottom&key=nv_bottom", new Function());
}

function ReaderUrl() {
    var hash = location.hash;
    if (hash) {
        hash = hash.replace(/#/g, '');
        if (hash.indexOf('tp') >= 0) {
            var v = hash.charAt(hash.length-1);
            var tp= AnalyzeType(v);
            onActive(document.getElementById(tp).parentNode); 
            InitMode('tp', GetTypeCodes(tp));
        }
    }
}

function AnalyzeType(v) {
    var fundType = ['stock', 'bond', 'mix', 'keep', 'eetf', 'eqdii', 'eetf', 'stock', 'innovate', 'all'];
    return fundType[v];
}
function GetTypeCodes (t) {
    switch (t) {
        case "fav":
            return userFavCodes;
            break;
        case "all":
            return "0";
            break;
        case "stock":
            return stockFund[1];
            break;
        case "bond":
            return bondFund[1];
            break;
        case "mix":
            return mixFund[1];
            break;
        case "keep":
            return keep[1];
            break;
        case "eetf":
            return etfFund[1];
            break;
        case "qdii":
            return QDIIFund[1];
            break;
        case "et":
            return etfFund[1];
            break;
        case "loft":
            return stockFund[1];
            break;
        case "innovate":
            return innovateFund[1];
            break;
    }
}
/*对联广告*/
function __loadFlayAd() {
    if (document.documentElement.clientWidth > 1107) {
        __JavascriptLoader("http://gg.fund123.cn/JSLoad.aspx?HtmlID=rlad&key=rlad", _FlayADScroll);
    }
}
function _FlayADScroll() {
    __JavascriptLoader("/NewJS/DuiLian.js", new Function());
}
function __loadNvtop2Ad() {
    __JavascriptLoader("http://gg.fund123.cn/JSLoad.aspx?HtmlID=fund123Ad&key=nv_top2", new Function());
}

//utitl
function ShowHelp() {
    var help = new HelpItem(document.getElementById("NetValueAdv").parentNode, document.getElementById("NetValueAdv"), "查看周、月、半年、年增长", -10, -120, 160, 3);
    QuickHelp.Add(help);
    QuickHelp.Init();
}

function onOverToolBar(e) {
    if (e.parentNode.id == "fine") {
        e.parentNode.id = "over";
    }
}

function onOutToolBar(e) {
    if (e.parentNode.id == "over") {
        e.parentNode.id = "fine";
    }
}

function RefreshList(text) {
    var container = document.getElementById("FundListContainer");
    container.NetValues = null;
    container.innerHTML = text;
    SortData(document.getElementById('linkPercent'), isAdvance);
    document.getElementById("Advance").disabled = false;
}

function AjaxGetFavCode() {
    $.get(
            '/AjaxHelper.aspx?' + Math.random(),
            { Type: 'Fav' },
            function (data) {
                $('#divUserFav').html(data);
                ReaderUrl();
                if (!(location.hash.length > 1))
                    __InitFav();
                window.setTimeout("CreateList();", 0);
            }
        );
}

var m_IsApply = false;
function __InitFav() {
    try {
        if (typeof (userFavCodes) != 'undefined'&&typeof(User)!=='undefined') {
            if (userFavCodes != "") {
                myFavs = userFavCodes
                InitMode('我关注的基金', userFavCodes);
                active = document.getElementById("all").parentNode;
                active.className = "";
                var e = document.getElementById("myfundlist").parentNode;
                e.className = "jt_4text";
                active = e;
                m_IsApply = true;
                ShowFundNumber(userFavCodes.split(';').length);
            }
        }
    }
    catch (e)
    { }
}

function queryHistory() {
    var date = Ext.get("ctl00_ContentPlaceHolder1_txt_History").dom;
    var dt = new Date();
    //判断是否到了出当日净值的时候,如果没有出就提示"该日净值还未出"  
    var selectDate = new Date(date.value.replace(/-/g, "/"));
    var Today = new Date();
    if (selectDate > Today) {
        alert(selectDate.toLocaleDateString() + "净值还未公布");
        return;
    }
    else if (selectDate.toDateString() == Today.toDateString()) {
        if (Today.getHours() < 16) {
            alert(selectDate.toLocaleDateString() + "净值还未公布");
            return;
        }
    }
    $('#mainList').hide();
    document.getElementById("loadingFrame").style.display = "";
    document.getElementById("frmLoadData").src = "/LatestData.aspx?date=" + date.value + "&t=" + dt.getTime();
}

//OFL.js
//Ver 1.1
var myFavs = "";
var OldSortDom = null;
var CreateOrder = 1;
var main_netValue;
var promotionJson;
var create_Index = 0;
var create_Count = 360;
var createwindowFlag = false;
var mCode = null;
var mFundName = null;
var mIsAdd = null;
var wittingHiddenTimer;
var tagBoxWidth = "243px"; //宽度
var tagBoxHeight = "320px"; //高度
var m_IsApply_first = true;
var isLock = true;
var activedRow;
var activedCell;
var activedCellIndex;

if (Ext.isIE6) {
    document.execCommand("BackgroundImageCache", false, true)
}

function sortbyCode(x, y) { if (parseFloat(x[0]) < parseFloat(y[0])) { return 1; } else { return -1; } }
function sortbyName(x, y) { return y[1].localeCompare(x[1]); }
function sortbyCNV(x, y) { if (parseFloat(x[2]) < parseFloat(y[2])) { return 1; } else { return -1; } }
function sortbyCTNV(x, y) { if (parseFloat(x[3]) < parseFloat(y[3])) { return 1; } else { return -1; } }
function sortbyPNV(x, y) { if (parseFloat(x[4]) < parseFloat(y[4])) { return 1; } else { return -1; } }
function sortbyPTNV(x, y) { if (parseFloat(x[5]) < parseFloat(y[5])) { return 1; } else { return -1; } }
function sortbyDisValue(x, y) { if (parseFloat(x[6]) < parseFloat(y[6])) { return 1; } else { return -1; } }
function sortbyPercent(x, y) { if (parseFloat(x[7]) < parseFloat(y[7])) { return 1; } else { return -1; } }

function parseHTML(el, html) {
    if (Ext.isIE) {
        el.innerHTML = "";
        el.insertAdjacentHTML("afterBegin", html);
    } else {
        el.innerHTML = html;
    }
}

//现在是分二次加载完
function CreateList(DataSource, ListName) {
    var Divs = [];
    var DivsTemp = [];
    var create_Count = main_netValue.length;
    //默认按增长率排序
//    main_netValue.sort(sortbyPercent);
    if (location.href.indexOf("?") != -1) {
        var queryString = location.href.substring(location.href.indexOf("?") + 1);
        var parameter = queryString.split("=")[1];
        ChangeTabByUrl(parameter);
    }

    if (m_IsApply) {
        for (var i = 0; i < create_Count; i++) {
            if (myFavs.indexOf(main_netValue[i][0]) != -1) {
                if (main_netValue[i][2] == 0 || main_netValue[i][4] == 0)
                    PushDiv(i, "--", main_netValue[i], DivsTemp, false);
                else {
                    PushDiv(i, CreateOrder, main_netValue[i], Divs, false);
                }
            }
            CreateOrder++;
        }
    } else {
        for (var i = 0; i < create_Count; i++) {
            if (main_netValue[i][2] == 0 || main_netValue[i][4] == 0)
                PushDiv(i, "--", main_netValue[i], DivsTemp, false);
            else {
                PushDiv(i, CreateOrder, main_netValue[i], Divs, false);
                CreateOrder++;
            }
        }
    }

    Divs.push(DivsTemp.join(''));
    parseHTML(document.getElementById("mainList"), Divs.join(''));
    document.getElementById("main_loading").style.display = "none";
    if (!m_IsApply) {
        ChangeMode();
        ShowFundNumber(main_netValue.length);
    }
    bindEvent();
}

//可以根据url里面的参数切换参数
function ChangeTabByUrl(tabName) {
    switch (tabName) {
        case 'my':
            if (typeof (User) == "undefined") {
                LoadDefault();
            } else {
                ChangeMode('我关注的', User.FavoriteFund);
                document.getElementById("all").parentNode.className = "";
                document.getElementById('myfundlist').parentNode.className = "jt_4text";
                m_IsApply_first = true;
                m_IsApply = true;
                ShowFundNumber(User.FavoriteFund.split(';').length);
            }
            break;
    }
}

function PushDiv(i, order, netValue, tables, isAdvance) {
    var percentColor, disValueColor, percent, disValue;
    percent = netValue[7];
    percentColor = "";
    if (percent) {
        if (percent > 0) {
            percentColor = "style='color:red'";
        }
        else if (percent < 0) {
            percentColor = "style='color:green'";
        }
    }
    disValue = netValue[6];
    disValueColor = "";
    if (disValue) {
        if (disValue > 0) {
            disValueColor = "style='color:red'";
        }
        else if (disValue < 0) {
            disValueColor = "style='color:green'";
        }
    }

    /*
      摘要:微博分享代码(内容:华宝兴业宝康消费品(240001) 2011-11-18 单位净值1.3080 累计净值4.0957 查询基金净值上数米基金网：http://www.fund123.cn/OpenFundList.html)
      编写:鲍芳荣
      日期:2011-11-22
    */
    var currentNetValueDate = document.getElementById("currDate").getAttribute("date");
    var shareContent = netValue[1] + "(" + netValue[0] + ") " + currentNetValueDate + " 单位净值" + netValue[2] + " 累计净值" + netValue[3] + " 查询基金净值上数米基金网：";

    tables.push(GetFavoriteColumn(netValue[0], netValue[1]));
    tables.push("<li class='jz02'>" + order + "</li>");
    tables.push("<li class='jz03'>" + netValue[0] + "</li>");
    //    tables.push('<li class="jz04"><a class="pa" target="_blank" href="http://fund.fund123.cn/html/' + netValue[0] + '" onclick="StatClickRate(\'基金名称\')">' + netValue[1] + '</a><span class="bar"><a href="javascript:shareOnWeibo(\'' + shareContent + '\')" title="分享到新浪微博"><img src="plugins/share/images/sinalogo1616.png" alt="分享到新浪微博" style="top:2px;position:relative;" /></a>&nbsp;[<a target="_blank" href="http://bbs.fund123.cn/' + netValue[0] + '.aspx"  onclick="StatClickRate(\'基金吧\')">吧</a>]</span></li>');
    tables.push('<li class="jz04"><a class="pa" target="_blank" href="http://fund.fund123.cn/html/' + netValue[0] + '" onclick="StatClickRate(\'基金名称\')">' + netValue[1] + '</a><span class="bar">[<a target="_blank" href="http://bbs.fund123.cn/' + netValue[0] + '.aspx"  onclick="StatClickRate(\'基金吧\')">吧</a>]</span></li>');
    tables.push("<li class='jz05'>" + (netValue[2] == 0 ? "--" : FormatNumber(netValue[2], 4)) + "</li>");
    tables.push("<li class='jz05'>" + (netValue[2] == 0 ? "--" : FormatNumber(netValue[3], 4)) + "</li>");
    tables.push("<li class='jz05' style='color: #666'>" + (netValue[4] == 0 ? '--' : FormatNumber(netValue[4], 4)) + "</li>");
    tables.push("<li class='jz05' style='color: #666'>" + (netValue[4] == 0 ? '--' : FormatNumber(netValue[5], 4)) + "</li>");
    tables.push("<li class='jz03' " + disValueColor + ">" + (netValue[2] == 0 || netValue[4] == 0 ? "--" : FormatNumber(netValue[6], 4)) + "</li>");
    tables.push("<li class='jz03' " + percentColor + ">" + (netValue[2] == 0 || netValue[4] == 0 ? "--" : (FormatNumber(netValue[7], 2) + "%")) + "</li>");

    var buyTip = "", buyHref = "";
    if (netValue[9] != "") {
        buyTip = "title='" + netValue[9] + "' class='tipCss'";
    }
    else {
        buyTip = "class='notipCss'";
    }

    if (netValue[10] != "") {
        buyHref = "http://fund.fund123.cn/Open/JJGG_C.aspx?code=" + netValue[0] + "&id=" + netValue[10];
    }
    if (buyHref != "") {
        tables.push("<li class='jz02'><div " + buyTip + ">" + "<a style='color:#333' target='_blank' href='" + buyHref + "'>" + (netValue[8] == 1 ? "开放" : netValue[8] == 0 ? "暂停" : "--") + "</a>" + "</div></li>");
        //        tables.push("<li class='jz02'><div "+ buyTip +">" + "<a target='_blank' href='" + buyHref + "'>" + (netValue[8] == 1 ? "开放" : netValue[8] == 0 ? "暂停" : "--") + "</a>" + "</div></li>" );
    }
    else {
        tables.push("<li class='jz02'><div style='color:#333' " + buyTip + ">" + (netValue[8] == 1 ? "开放" : netValue[8] == 0 ? "暂停" : "--") + "</div></li>");
    }

    var redeemTip = "", redeemHref = "";
    if (netValue[12] != "") {
        redeemTip = "title='" + netValue[12] + "' class='tipCss'";
    }
    else {
        redeemTip = "class='notipCss'";
    }

    if (netValue[13] != "") {
        redeemHref = "http://fund.fund123.cn/Open/JJGG_C.aspx?code=" + netValue[0] + "&id=" + netValue[13];
    }
    if (redeemHref != "") {
        tables.push("<li class='jz02'><div " + redeemTip + ">" + "<a style='color:#333' target='_blank' href='" + redeemHref + "'>" + (netValue[11] == 1 ? "开放" : netValue[11] == 0 ? "暂停" : "--") + "</a>" + "</div></li>");
        //      tables.push("<li class='jz02'><div "+ redeemTip +">" + "<a target='_blank' href='" + redeemHref + "'>" + (netValue[11] == 1 ? "开放" : netValue[11] == 0 ? "暂停" : "--" ) + "</a>" + "</div></li>");
    }
    else {
        tables.push("<li class='jz02'><div style='color:#333' " + redeemTip + ">" + (netValue[11] == 1 ? "开放" : netValue[11] == 0 ? "暂停" : "--") + "</div></li>");
    }

    tables.push('<li  class="jz06">');
    if (JudgeSale(netValue[0]))
        tables.push('<a style="text-decoration:underline;color:#FF0000;" target="_blank" href="http://mall.fund123.cn/buyfund/' + netValue[0] + '?xtag=nv_open" onclick="StatClickRate(\'购买\')">购买</a>&nbsp;');
    else
        tables.push('<span style="color:#00007F;"><a style="color:#00007F;" href="http://mall.fund123.cn/?tag=menu" target="_blank" onclick="StatClickRate(\'购买\')">购买</a></span>&nbsp;');

    //	tables.push('<a target="_blank" href="http://fx.fund123.cn/html/NetValueHistory'+netValue[0]+'.html">净值/走势</a>&nbsp;');
    tables.push('<a target="_blank" href="http://fx.fund123.cn/html/NetValueHistory' + netValue[0] + '.html" onclick="StatClickRate(\'走势图\')">走势图</a>&nbsp;');
//    tables.push('<a target="_blank" href="http://bbs.fund123.cn/' + netValue[0] + '.aspx"  onclick="StatClickRate(\'基金吧\')">基金吧</a>&nbsp;');
    //    tables.push('<a onmouseover="this.style.color=\'red\';" onmouseout="this.style.color=\'\';" name="'+netValue[1]+'" code="'+netValue[0]+'" xlst="fund3" onmouseup="OFLshowTagsearch(this, event, document);">更多..</a>');
    tables.push('</li>');
    tables.push("</ul></div>");

}

//判断是否可以购买
function JudgeSale(code) {
    if (CanBuyFundList) {
        for (i = 0; i < CanBuyFundList.length; i++) {
            if (CanBuyFundList[i] == code)
                return true;
        }
    }
    return false;
}

function write(msg) {
    var logs = document.getElementById("log");
    logs.innerHTML += msg + "<br />";
}

function genData(data) {
    var aryNv = data.split('_');
    main_netValue = [];
    for (var i = 0; i < aryNv.length; ++i) {
        main_netValue.push(aryNv[i].Trim().split('|'));
    }
}
String.prototype.Trim = function () { return this.replace(/(^\s*)|(\s*$)/g, ""); }

// for Sort start
function SortData(obj, isAdvance) {
    m_IsApply_first = false;
    if (obj == null) {
        if (OldSortDom == null) {
            OldSortDom = document.getElementById("InsPercent");
        }
        obj = OldSortDom;
        if (obj.getAttribute("order") != "") {
            sortMode = obj.getAttribute("order");
            if (sortMode == "1") sortMode = "0";
            else if (sortMode == "0") sortMode = "1";
        }
        document.getElementById("mainList").innerHTML = "";
        BindDataDiv(isAdvance, obj.getAttribute("tag"), sortMode);
        document.getElementById("loadingFrame").style.display = "none";
        window.parent.ChangeMode();
        $('#mainList').show();
        return;
    }

    ClearTitle();
    var sortMode = "0";
    if (obj.getAttribute("order") != "") { sortMode = obj.getAttribute("order"); }
    BindDataDiv(isAdvance, obj.getAttribute("tag"), sortMode);
    var title = obj.getAttribute("text");
    if (sortMode != "1") {
        obj.setAttribute("order", "1");
        if (obj.parentNode.getElementsByTagName("IMG").length > 0) {
            obj.parentNode.getElementsByTagName("IMG")[0].src = "/Image/arrowDown.gif";
        }
        else {
            obj.parentNode.innerHTML = obj.parentNode.innerHTML + "<img src='/Image/arrowDown.gif' align='absmiddle' border='0' />";
        }
    }
    else {
        obj.setAttribute("order", "0");
        if (obj.parentNode.getElementsByTagName("IMG").length > 0) {
            obj.parentNode.getElementsByTagName("IMG")[0].src = "/Image/arrowUp.gif";
        }
        else {
            obj.parentNode.innerHTML = obj.parentNode.innerHTML + "<img src='/Image/arrowUp.gif' align='absmiddle' border='0' />";
        }
    }
    OldSortDom = obj;
    window.parent.ChangeMode();
}

function ClearTitle() {
    var tableHeader = document.getElementById("tableHeader");
    var links = tableHeader.getElementsByTagName("A");
    var percentHref = null;
    for (var i = 0; i < links.length; i++) {
        if (links[i].parentNode.getElementsByTagName("IMG").length > 0) {
            if (links[i] && links[i].parentNode && links[i].parentNode.removeChild) {
                links[i].parentNode.removeChild(links[i].parentNode.getElementsByTagName("IMG")[0]);
            }
        }
    }
}
function BindDataDiv(isAdvance, sort, sortMode) {

    var netValues = main_netValue;
    if (sort == "代码") {
        netValues.sort(sortbyCode);
    }
    else if (sort == "名称") {
        netValues.sort(sortbyName);
    }
    else if (sort == "当天单位净值") {
        netValues.sort(sortbyCNV);
    }
    else if (sort == "当天累计净值") {
        netValues.sort(sortbyCTNV);
    }
    else if (sort == "单位净值") {
        netValues.sort(sortbyPNV);
    }
    else if (sort == "累计净值") {
        netValues.sort(sortbyPTNV);
    }
    else if (sort == "增长值") {
        netValues.sort(sortbyDisValue);
    }
    else if (sort == "增长率") {
        netValues.sort(sortbyPercent);
    }

    if (sortMode == "1") {
        netValues.reverse();
    }

    var tables = [];
    var tablesTemp = [];
    var order = 1;

    for (var i = 0; i < netValues.length; i++) {
        if ((sort == "当天单位净值" || sort == "当天累计净值") && netValues[i][2] == 0) {
            PushDiv(i, "--", netValues[i], tablesTemp, isAdvance);
        }
        else if ((sort == "增长值" || sort == "增长率") && (netValues[i][2] == 0 || netValues[i][4] == 0)) {
            PushDiv(i, "--", netValues[i], tablesTemp, isAdvance);
        }
        else if ((sort == "单位净值" || sort == "累计净值") && netValues[i][4] == 0) {
            PushDiv(i, "--", netValues[i], tablesTemp, isAdvance);
        }
        else {
            PushDiv(i, order, netValues[i], tables, isAdvance);
            order++;
        }
    }

    tables.push(tablesTemp.join(''));
    parseHTML(document.getElementById("mainList"), tables.join(''));
}
// for Sort end
function GetAttentionState(code) {
    if (typeof (userFavCodes) == 'undefined'||typeof(User)=='undefined')
        return false;
    else
        return userFavCodes.indexOf(code) != -1;
}

function GetFavoriteColumn(code, fundName, footer) {
    var isFavorite = GetAttentionState(code);
    var id = code;
    if (footer != undefined) {
        id += footer;
    }
    var str = "";
    if (isFavorite == true) {
        //str ='<div class="tab_jz" __bgColor="' + window.CONST_Grid_Favorite_Color + '" style="background-color:'+window.CONST_Grid_Favorite_Color+';" onmouseover="onovergrid(this, event);" onmouseout="onoutgrid(this, event);"><ul type="code" code="'+code+'">';    
        str = '<div class="tab_jz" __bgColor="' + window.CONST_Grid_Favorite_Color + '" style="background-color:' + window.CONST_Grid_Favorite_Color + ';" "><ul type="code" code="' + code + '">';
        str += "<li isFav='1' class='jz01' id='fav" + id + "' code='" + code + "' name='" + fundName + "'><input type='checkbox' onclick='return SetMyFavoriteFund(this)' checked></li>";
    }
    else {
        //str ='<div class="tab_jz" onmouseover="onovergrid(this, event);" onmouseout="onoutgrid(this, event);"><ul type="code" code="'+code+'">';    
        str = '<div class="tab_jz"><ul type="code" code="' + code + '">';
        str += "<li isFav='0' class='jz01' id='fav" + id + "' code='" + code + "' name='" + fundName + "'><input type='checkbox' onclick='return SetMyFavoriteFund(this)'></li>";
    }


    return str;
}

function SetMyFavoriteFund(obj, code, fundName) {
    obj = obj.parentNode;
    code = obj.getAttribute("code");
    fundName = obj.getAttribute("name");

    if (Ext.isIE && window.document.readyState != "complete") {
        window.setTimeout(SetMyFavoriteFund, 1000, obj, code, fundName);
        return;
    }

    var user = window.parent.User;

    if (!user || (typeof (user) == 'undefined' && typeof (user.Name) == 'undefined')) {
        //弹出统一登陆窗
        LoadDefault();
        return false;
    }
    else if (user.Name != "" && code != "") {
        var dom;
        if (("fav" + code) == obj.id) {
            if (document.getElementById(obj.id + "_Prom")) {
                dom = document.getElementById(obj.id + "_Prom");
            }
        }
        else if (("fav" + code) != obj.id) {
            if (document.getElementById("fav" + code)) {
                dom = document.getElementById("fav" + code);
            }
        }

        var isAdded = false;
        if (obj.getAttribute("isFav") != null && (obj.getAttribute("isFav") == "1" || obj.isFav == "1")) {
            obj.setAttribute("isFav", "0");
            obj.setAttribute("title", "添加到我关注的基金");
            isAdded = false;
            if (dom != null)
                dom.childNodes[0].checked = false;
        }
        else {
            var codess = userFavCodes.split(';');
            if (codess.length > 79) {
                alert('关注的基金不能超过80只。');
                return false;
            }
            obj.setAttribute("isFav", "1");
            obj.setAttribute("title", "取消我关注的基金");
            isAdded = true;
            if (dom != null)
                dom.childNodes[0].checked = true;
        }


        if (!createwindowFlag) {
            mCode = code;
            mFundName = fundName;
            mIsAdd = isAdded;
            __loadOpenWin(createWindow);
        }
        else {
            checkWindowAll(code, fundName, isAdded);
        }
    }
}

function createWindow() {
    openFavwindow();
    checkWindowAll(mCode, mFundName, mIsAdd);
}

function checkWindowAll(mCode, fundName, isAdded) {
    if (!showFavOpenWindowFlag) {
        autoFavwidth();
    }
    checkFavall(mCode, fundName, isAdded);
}

function delchooseMyFavoriteFund(code) {
    var eid = 'fav' + code;
    var pid = "fav" + code + "_Prom";
    var obj = document.getElementById(eid);
    var objProm = document.getElementById(pid);
    var chk;
    if (obj != null) {
        chk = obj.childNodes[0];
        chk.checked = false;
        obj.setAttribute("isFav", "0");
        obj.setAttribute("title", "添加到我关注的基金");
    }
    if (objProm != null) {
        chk = objProm.childNodes[0];
        chk.checked = false;
        objProm.setAttribute("isFav", "0");
        objProm.setAttribute("title", "添加到我关注的基金");
    }
}


function ResetMyFavoriteFund(code, isAdded) {
    var codes = window.parent.User.FavoriteFund.split(';');
    var newcodes = [];
    if (codes.length == 0) {
        newcodes.push(code);
    }
    else {
        var tag = false;
        for (i = 0; i < codes.length; i++) {
            if (codes[i] == code) {
                tag = true;
            }
            else {
                newcodes.push(codes[i]);
            }
        }
        if (isAdded == true && tag == false) {
            newcodes.push(code);
        }
    }
    window.parent.User.FavoriteFund = newcodes.join(';');
}

//tagsBall.js
function $$$(id) {
    return document.getElementById(id);
}

function OFLshowTagsearch(obj, e, doc) {
    var name = obj.getAttribute("name");
    var code = obj.getAttribute("code");
    var xsltname = obj.getAttribute("xlst");

    try {
        var box = $$$('tagShowBox');
        if (!box) {
            createTagShowBox();
            box = $$$('tagShowBox');
        }

        try { clearTimeout(wittingHiddenTimer); } catch (e) { }
        OFLmoveTagBox(e, doc);
        $$$('tagShowBoxBartitle').innerHTML = name;
        box.style.display = "block";

        var str_tip = "<iframe scrolling=\"no\" name=\"info\" marginwidth=\"0\" src=\"http://hqqd.fund123.cn/Show.html?" + code + "," + xsltname + "\" frameborder=\"0\" width=\"100%\" height=\"283px\"></iframe>";

        OFLoprGetdata(str_tip);
    } catch (e) { }
}

function OFLmoveTagBox(e, doc) {
    $$$('tagShowBox').style.left = (e.clientX - 220 + document.documentElement.scrollLeft) + "px";
    $$$('tagShowBox').style.top = (e.clientY + 0 + document.documentElement.scrollTop) + "px";
}

function OFLoprGetdata(doc) {
    if (doc) {
        $$$('tagShowBoxContent').innerHTML = doc;
    }
    else {
        $$$('tagShowBoxContent').innerHTML = "系统错误！";
    }
}

function DisplayOtherMode() {
    var otherMode = document.getElementById("otherMode");
    if (otherMode.style.display == "none") {
        otherMode.style.display = "";
    }
    else {
        otherMode.style.display = "none";
    }
}

function SortListTableVarMode(text, value) {
    if (m_IsApply_first && m_IsApply) {
        SortData(null, false);
    }
    var Div = document.getElementById("mainList");
    SortListByList(Div, text, value);
}

function SortListByList(Div, text, value) {
    var Len = 0;
    var AdCounts = 0;
    if (value == "0") {
        for (var j = 0; j < Div.childNodes.length; j++) {
            Div.childNodes[j].style.display = "";
            if (!Div.childNodes[j].id) {
                Len = Len + 1;
            }
        }

        var google_one = document.getElementById("g_cn_center_one");
        //添加google广告
        //添加google广告 150行插入
        if (google_one) {
            google_one.style.display = "";
        } else if (document.getElementById("mainList").childNodes.length > 150) {
            newDiv = document.createElement("DIV");
            newDiv.id = "g_cn_center_one";
            newDiv.className = "tab_jz";
            newDiv.style.cssText = "line-height:95px;height:95px;";
            document.getElementById("mainList").insertBefore(newDiv, document.getElementById("mainList").childNodes[150 + AdCounts]);
        }
        AdCounts++;

        //显示推广内容
        document.getElementById("Promotion_List").style.display = "";
    } else {
        //隐藏推广内容
        document.getElementById("Promotion_List").style.display = "none";
        var google_one = document.getElementById("g_cn_center_one");
        var google_two = document.getElementById("g_cn_center_two");
        var shumi_20100810_ad_one = document.getElementById("shumi_ad_one");
        var shumi_20100810_ad_two = document.getElementById("shumi_ad_two");
        var shumi_20100810_ad_three = document.getElementById("shumi_ad_three");
        var shumi_20100810_ad_four = document.getElementById("shumi_ad_four");
        if (google_one) google_one.style.display = "none";
        if (google_two) google_two.style.display = "none";
        if (shumi_20100810_ad_one) shumi_20100810_ad_one.style.display = "none";
        if (shumi_20100810_ad_two) shumi_20100810_ad_two.style.display = "none";
        if (shumi_20100810_ad_three) shumi_20100810_ad_three.style.display = "none";
        if (shumi_20100810_ad_four) shumi_20100810_ad_four.style.display = "none";

        var codes = value.split(";");
        for (var j = 0; j < Div.childNodes.length; j++) {
            var ul = Div.childNodes[j];
            if (Div.childNodes[j].childNodes.length > 0) {
                var code = Div.childNodes[j].childNodes[0].getAttribute("code");
                if (codes.indexOf(code) != -1) {
                    Div.childNodes[j].style.display = "";
                    Len = Len + 1;
                } else {
                    Div.childNodes[j].style.display = "none";
                }
            }
        }
    }
    ShowFundNumber(Len);
}

function changebg(obj) {
    if (obj.getAttribute("__bgColor") == window.parent.CONST_Grid_Favorite_Color) {
        return;
    }
    obj.style.backgroundColor = "#FFFFFF";
}

function changebg1(obj) {
    if (obj.getAttribute("__bgColor") != window.parent.CONST_Grid_Favorite_Color) {
        obj.setAttribute("__bgColor", window.parent.CONST_Grid_Over_Color);
        obj.style.backgroundColor = window.parent.CONST_Grid_Over_Color;
    }
}

function FormatNumber(srcStr, nAfterDot) {
    return parseFloat(srcStr).toFixed(nAfterDot);
}

function findParentElement(obj, tagName, isSelf) {
    var parentObj = obj;
    if (parentObj == null || parentObj.tagName == tagName) return parentObj;
    else return findParentElement(parentObj.parentNode, tagName);
}

function findChildElement(obj, tagName) {
    for (var i = 0; i < obj.childNodes.length; ++i) {
        var child = obj.childNodes[i];
        if (child && child.tagName && child.tagName == tagName) {
            return child;
        }
    }

    return null;
}

function onovergrid(obj, evt) {
    var srcTarget = null;
    if (Ext.isIE) {
        srcTarget = window.event.srcElement;
    } else {
        srcTarget = evt.target;
    }

    var DivBG = true;
    if (Ext.isIE) {
        if (ToChildElement(srcTarget, window.event.toElement)) {
            DivBG = false;
        }
    }

    srcTarget = findParentElement(srcTarget, "LI");
    if (srcTarget) {
        if (srcTarget.tagName == "LI") {
            var div = findParentElement(srcTarget, "DIV");
            if (DivBG && div && srcTarget.parentNode.getAttribute("type")) {
                changebg1(div);
            }
        }
    }
}

function onoutgrid(obj, evt) {
    var srcTarget = null;
    if (Ext.isIE) {
        srcTarget = window.event.srcElement;
    } else {
        srcTarget = evt.target;
    }
    var DivBG = true;
    if (Ext.isIE) {
        if (IsSomeParent(srcTarget, window.event.toElement)) {
            DivBG = false;
        }
    }

    if (Ext.isIE) {
        if (ToChildElement(srcTarget, window.event.toElement)) {
            return;
        }
    }
    srcTarget = findParentElement(srcTarget, "LI");
    if (srcTarget) {
        if (srcTarget.tagName == "LI") {
            var div = findParentElement(srcTarget, "DIV");
            if (DivBG && div && srcTarget.parentNode.getAttribute("type")) {
                changebg(div);
            }
        }
    }
}

function ToChildElement(parent, child) {
    if (parent == null || child == null) return false;
    for (var i = 0; i < parent.childNodes.length; i++) {
        if (child == parent.childNodes[i]) {
            return true;
        }
    }
    for (var i = 0; i < parent.childNodes.length; i++) {
        if (ToChildElement(parent.childNodes[i], child)) {
            return true;
        }
    }
    return false;
}

function IsSomeParent(one, two) {
    if (one == null || two == null) return false;
    if (one.parentNode == two.parentNode)
        return true;
    return false;
}

function ShowFundNumber(Num) {
    var Dom = document.getElementById("FundNumber");
    Dom.innerHTML = "<span style='COLOR: #666'>" + Num + "只</span>";
}

//导出数据仅做提示做用
function opf_popupdialog(width, height, src, title, drag) {
    PDClassInatance.Popup(width, height, src, title, drag);
}
function opf_LoadPopupDialog(width, height, src, title, drag) {
    if (window.PDClassInatance == undefined) {
        __CssLoader("http://inc.fund123.cn/Js/Class/PopupDialog/PopupDialog.css");
        if (drag)
            __JavascriptLoader("http://inc.fund123.cn/Js/Class/PopupDialog/Move.js");
        __JavascriptLoader("http://inc.fund123.cn/Js/Class/PopupDialog/PopupDialog.js", function () { opf_popupdialog(width, height, src, title, drag); });
    }
    else
        opf_popupdialog(width, height, src, title, drag);
}

function opf_LoadDefault() {
    opf_LoadPopupDialog(400, 150, "DownLoadTip.htm", "友情提示", false);
}

//推广
String.prototype.decode = function () {
    if (this == "")
        return "";
    var text = this;
    try {
        text = eval("(" + text + ")");
    } catch (e) {
        text = "";
    }
    return text;
}

function CreatePromotionList() {
    if (promotionJson && promotionJson.PromotionList) {
        var Len = promotionJson.PromotionList.length;
        var Promo = [];
        for (var i = 0; i < Len; i++) {
            PushPromDiv("推广", promotionJson.PromotionList[i], Promo, false);
        }
        Promo.push('<div class="tab_jz" style="background-color: rgb(231, 238, 247);height:5px;"><ul><li style="width: 897px;">&nbsp;</li></ul></div>');
        var dom = document.getElementById("Promotion_List");
        parseHTML(dom, Promo.join(''));
        if (!m_IsApply) {
            dom.style.display = "";
        }
    }
}

function PushPromDiv(order, netValue, tables, isAdvance) {
    var percentColor, disValueColor, percent, disValue;
    percent = netValue[7];
    percentColor = "";
    if (percent) {
        if (percent > 0) {
            percentColor = "style='color:red'";
        }
        else if (percent < 0) {
            percentColor = "style='color:green'";
        }
    }
    disValue = netValue[6];
    disValueColor = "";
    if (disValue) {
        if (disValue > 0) {
            disValueColor = "style='color:red'";
        }
        else if (disValue < 0) {
            disValueColor = "style='color:green'";
        }
    }

    tables.push(GetFavoriteColumn(netValue[0], netValue[1], "_Prom"));

    tables.push("<li class='jz02'>" + order + "</li>");
    tables.push("<li class='jz03'>" + netValue[0] + "</li>");
    tables.push('<li class="jz04"><a target="_blank" href="http://fund.fund123.cn/html/' + netValue[0] + '">' + netValue[1] + '</a>&nbsp;<a target="_blank" href="' + netValue[15] + '"><font color="red">(' + netValue[14] + ')</font></a></li>');
    tables.push("<li class='jz05'>" + (netValue[2] == 0 ? "--" : FormatNumber(netValue[2], 4)) + "</li>");
    tables.push("<li class='jz05'>" + (netValue[2] == 0 ? "--" : FormatNumber(netValue[3], 4)) + "</li>");
    tables.push("<li class='jz05' style='color: #666'>" + (netValue[4] == 0 ? '--' : FormatNumber(netValue[4], 4)) + "</li>");
    tables.push("<li class='jz05' style='color: #666'>" + (netValue[4] == 0 ? '--' : FormatNumber(netValue[5], 4)) + "</li>");
    tables.push("<li class='jz03' " + disValueColor + ">" + (netValue[2] == 0 || netValue[4] == 0 ? "--" : FormatNumber(netValue[6], 4)) + "</li>");
    tables.push("<li class='jz03' " + percentColor + ">" + (netValue[2] == 0 || netValue[4] == 0 ? "--" : (FormatNumber(netValue[7], 2) + "%")) + "</li>");

    var buyTip = "", buyHref = "";
    if (netValue[9] != "") {
        buyTip = "title='" + netValue[9] + "' class='tipCss'";
    }
    else {
        buyTip = "class='notipCss'";
    }

    if (netValue[10] != "") {
        buyHref = "http://fund.fund123.cn/Open/JJGG_C.aspx?code=" + netValue[0] + "&id=" + netValue[10];
    }
    if (buyHref != "") {
        tables.push("<li class='jz02'><div " + buyTip + ">" + "<a target='_blank' href='" + buyHref + "'>" + (netValue[8] == 1 ? "开放" : netValue[8] == 0 ? "暂停" : "--") + "</a>" + "</div></li>");
    }
    else {
        tables.push("<li class='jz02'><div " + buyTip + ">" + (netValue[8] == 1 ? "开放" : netValue[8] == 0 ? "暂停" : "--") + "</div></li>");
    }

    var redeemTip = "", redeemHref = "";
    if (netValue[12] != "") {
        redeemTip = "title='" + netValue[12] + "' class='tipCss'";
    }
    else {
        redeemTip = "class='notipCss'";
    }

    if (netValue[13] != "") {
        redeemHref = "http://fund.fund123.cn/Open/JJGG_C.aspx?code=" + netValue[0] + "&id=" + netValue[13];
    }
    if (redeemHref != "") {
        tables.push("<li class='jz02'><div " + redeemTip + ">" + "<a target='_blank' href='" + redeemHref + "'>" + (netValue[11] == 1 ? "开放" : netValue[11] == 0 ? "暂停" : "--") + "</a>" + "</div></li>");
    }
    else {
        tables.push("<li class='jz02'><div " + redeemTip + ">" + (netValue[11] == 1 ? "开放" : netValue[11] == 0 ? "暂停" : "--") + "</div></li>");
    }

    tables.push('<li  class="jz06"><a target="_blank" href="http://fx.fund123.cn/html/NetValueHistory' + netValue[0] + '.html">');
    tables.push('走势图</a>&nbsp;');
    tables.push('<a onmouseover="this.style.color=\'red\';" onmouseout="this.style.color=\'\';" name="' + netValue[1] + '" code="' + netValue[0] + '" xlst="fund3" onmouseup="OFLshowTagsearch(this, event, document);">更多..</a>');
    tables.push('</li>');
    tables.push("</ul></div>");

}

function getElementsbyClass(className, tag, parentElement) {
    parentElement = parentElement || document;
    tag = tag || '*';

    var tags = (tag == '*' && parentElement.all) ? parentElement.all : parentElement.getElementsByTagName(tag);
    var elements = new Array();
    className = className.replace(/\-/g, '\\-');
    var regex = new RegExp('(^|\\s)' + className + '(\\s|$)');
    var element;
    for (var i = 0, l = tags.length; i < l; i++) {
        element = tags[i];
        if (regex.test(element.className)) {
            elements.push(element);
        }
    }
    return elements;
}

function bindEvent() {
    var allRows = getElementsbyClass("tab_jz", "div", document.getElementById("mainList"));
    for (var i = 0; i < allRows.length; ++i) {
        var row = allRows[i];
        row.onmouseover = function (event) {
            onovergrid(this, event);
        };

        row.onmouseout = function (event) {
            onoutgrid(this, event);
        };
    }
}

function loadAd() {
    __JavascriptLoader("http://gg.fund123.cn/JSLoad.aspx?HtmlID=B5&key=B5");
    __JavascriptLoader("http://gg.fund123.cn/JSLoad.aspx?HtmlID=B1&key=B1");
}

function insertAdToList() {
    var one = document.getElementById("g_cn_center_one");
    if (one) {
        one.innerHTML = '<ul><li style="line-height:95px;height:95px;width:948px;"><iframe src="http://gg.fund123.cn/Get.aspx?key=B3" marginheight=0 marginwidth=0 frameborder=0 style="margin:0px; padding:2px 0px 0px 0px;width:897px;height:90px;" scrolling="no"></iframe></li></ul>';
    }
    //var two = document.getElementById("g_cn_center_two");
    //two.innerHTML = '<ul><li style="line-height:95px;height:95px;width:948px;"><iframe src="http://gg.fund123.cn/Get.aspx?key=B4" marginheight=0 marginwidth=0 frameborder=0 style="margin:0px; padding:2px 0px 0px 0px;width:897px;height:90px;" scrolling="no"></iframe></li></ul>';
    //    var shumi_ad_one=document.getElementById("shumi_ad_one");
    //    shumi_ad_one.innerHTML = '<ul><li style="line-height:95px;height:95px;width:948px;"><iframe src="http://gg.fund123.cn/Get.aspx?key=B2-1" marginheight=0 marginwidth=0 frameborder=0 style="margin:0px; padding:2px 0px 0px 0px;width:897px;height:90px;" scrolling="no"></iframe></li></ul>';
    //    var shumi_ad_two=document.getElementById("shumi_ad_two");
    //    shumi_ad_two.innerHTML = '<ul><li style="line-height:95px;height:95px;width:948px;"><iframe src="http://gg.fund123.cn/Get.aspx?key=B3-1" marginheight=0 marginwidth=0 frameborder=0 style="margin:0px; padding:2px 0px 0px 0px;width:897px;height:90px;" scrolling="no"></iframe></li></ul>';
    //    var shumi_ad_three=document.getElementById("shumi_ad_three");
    //    shumi_ad_three.innerHTML = '<ul><li style="line-height:95px;height:95px;width:948px;"><iframe src="http://gg.fund123.cn/Get.aspx?key=B4-1" marginheight=0 marginwidth=0 frameborder=0 style="margin:0px; padding:2px 0px 0px 0px;width:897px;height:90px;" scrolling="no"></iframe></li></ul>';
    //    var shumi_ad_four=document.getElementById("shumi_ad_four");
    //    shumi_ad_four.innerHTML = '<ul><li style="line-height:95px;height:95px;width:948px;"><iframe src="http://gg.fund123.cn/Get.aspx?key=B5-1" marginheight=0 marginwidth=0 frameborder=0 style="margin:0px; padding:2px 0px 0px 0px;width:897px;height:90px;" scrolling="no"></iframe></li></ul>';
}

//区域统计
function StatClickRate(ModuleName) {
    var tempimg = new Image();
    tempimg.src = "http://webstat.fund123.cn/Area.aspx?page=" + escape("每日净值") + "&area=" + escape(ModuleName);
}

