﻿var cur_sortcol = 1, str, globalsortcol, globaltype, globalcurday,globalheadcol, flag = 0, globalsortorder, typenum = 0;
var n=1;
var typeid=1;
var global_curtab=1;
var P_allnum = 0;
var info2 = new Array(); 


var cookieName = 'Eastmoney_Fund_Table'
var clicknum = 0;
var globalrowindex, globalcheckid;
function getCookie(name) {
    var cookieValue = "";
    var search = name + "=";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            cookieValue = unescape(document.cookie.substring(offset, end));
        }
    }
    return cookieValue;
}
function setCookie(vNameStr, vCode, vStatus) {
    var oTimeNow = new Date();
    oTimeNow.setMonth(oTimeNow.getMonth() + 12);
    var sExpirationDate = oTimeNow.toUTCString();
    var cookieStr;
    if (getCookie(vNameStr) == '' || getCookie(vNameStr) == '_') {
        cookieStr = vCode + '_';
    } else {
        if (vStatus == 1) {
            cookieStr = getCookie(vNameStr) + vCode + '_';
        } else {
            cookieStr = getCookie(vNameStr).replace(vCode + '_', '');
        }
    }
    var path = "/";
    var domain = "eastmoney.com";
    var secure = "";
    document.cookie = vNameStr + "=" + escape(cookieStr) +
            ((sExpirationDate) ? "; expires=" + sExpirationDate : "") +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            ((secure) ? "; secure" : "");
}

function getCurRowNum(elm, n) {
    var a = elm.parentNode.parentNode.rowIndex;
    var b = document.getElementById('oTable').rows[a];
    var c = document.getElementById('oTable').rows.length;
    for (var i = 0; i < c; i++) {
        var currow = document.getElementById('oTable').rows[i];
        currow.cells[1].innerHTML = "";
    }
    var h;
    b.style.backgroundColor == "" ? b.style.backgroundColor = "#D2E2FF" : b.style.backgroundColor = "";

    elm.checked == true ? h = 1 : h = 0;

    if (h == 1) 
    {
        if (clicknum > 0) {
            b.cells[1].innerHTML = "<input type=\"button\" name=\"comparebtn\" class=\"comparebtn\" onclick=\"javascript:open('http://fundacc2.eastmoney.com/fundcompare.aspx','','')\" />";
        }
        clicknum++;
        globalcheckid = b.cells[3].innerHTML;
        globalrowindex = a;
    }
    else {

        var tempmaxcode, tempmaxrowindex,tempminrowindex=c;
        if (globalcheckid == b.cells[3].innerHTML) {
        }
        else {
            globalrowindex = b.rowIndex;
        }
 
            b.cells[1].innerHTML = "";
            for (var m = 0; m < c; m++) 
            {
                if (document.getElementById(document.getElementById('oTable').rows[m].cells[3].innerHTML).checked == true)   //1,3,8,14
                {
                    if (Math.abs(globalrowindex - m) < tempminrowindex) {
                        tempminrowindex = globalrowindex - m;
                    }
                    else {}
                }
            }
            if (tempminrowindex > 0) {
                tempminrowindex = globalrowindex - tempminrowindex;
            }
            else {
                tempminrowindex = globalrowindex - tempminrowindex;
            }
            //tempminrowindex = globalrowindex - tempminrowindex;
            if (tempminrowindex >= 0) {
                tempmaxcode = document.getElementById('oTable').rows[tempminrowindex].cells[3].innerHTML;
                tempmaxrowindex = tempminrowindex;
                var rid = document.getElementById('oTable').rows[tempmaxrowindex];
                rid.cells[1].innerHTML = "<input type=\"button\" name=\"comparebtn\" class=\"comparebtn\" onclick=\"javascript:open('http://fundacc2.eastmoney.com/fundcompare.aspx','','')\" />";
                globalcheckid = tempmaxcode;
            }

          clicknum--;
          if (clicknum < 2) {
              for (var m = 0; m < c; m++) {
                  document.getElementById('oTable').rows[m].cells[1].innerHTML = "";
              }
          }
    }
    setCookie(cookieName, b.cells[n].innerHTML, h);
}

function getCurRowNum2(elm, n) {
    var a = elm.parentNode.parentNode.rowIndex;
    var b = document.getElementById('oTable').rows[a];
    var h;
    if (b.cells[0].style.backgroundColor == "") {
        for (var i = 0; i < 18; i++) {
            b.cells[i].style.backgroundColor = "#D2E2FF";
        }
    } else {
        for (var i = 0; i < 18; i++) {
            b.cells[i].style.backgroundColor = "";
        }
    }
    elm.checked == true ? h = 1 : h = 0;
    setCookie(cookieName, b.cells[n].innerHTML, h);

}

var tabtitlename = "typetab_";
var contenttitlename = "marketData_1_";
var parenttabname = "markTypeTab", childtabname = "li";
function FundTypeSwitchTab(parentElm, childElm) {
    parenttabname = parentElm;
    childtabname = childElm;
    var lis = _$(parentElm).getElementsByTagName(childElm);
    for (var i = 0; i < lis.length; i++) {
       (function() {
           var index = lis[i].id.toString().substr(lis[i].id.toString().lastIndexOf("_") + 1, lis[i].id.toString().length);
           if (lis[i].attachEvent) {
               lis[i].attachEvent("onclick", function() { switchTab(index); });
           }
           else if (lis[i].addEventListener) {
               lis[i].addEventListener("click", function() { switchTab(index); }, false);
           }
           else {
               lis[i].onclick = switchTab(index);
           }
       })();
   }
}

function switchTab(m) {   
    re_LoadScroll();
    globaltype = m;
    globalsortorder = "desc";
    var lis = _$(parenttabname).getElementsByTagName(childtabname);
    for(var i=1; i<=lis.length; i++)
    {
        if (_$(tabtitlename + i))
        {
            _$(tabtitlename + i).className = "";
        }
        if (_$(contenttitlename + i))
        {
            _$(contenttitlename + i).className = "";
            _$(contenttitlename + i).style.display = "none";
            _$(contenttitlename + i).innerHTML = "";
        }
    }
    if (_$(tabtitlename + m)) {
        _$(tabtitlename + m).className = "at";
    }
    if (_$(contenttitlename + m)) {
        _$(contenttitlename + m).className = "makeDataBody";
        _$(contenttitlename + m).style.display = "block";
    }
    fundnumbytype(m);      
    MakeSortTable(7);  
}

function fundnumbytype(type) {
    var tt = 0;
    var filterfundinfo2 = new Array();
    var temparray2 = fundinfos.split("_");
    if (type == 1)   // 全部
    {
        for (var i = 0; i < temparray2.length; i++) {
            var tempstr = temparray2[i].toString();
            var returntype = FilterType(tempstr.substr(0, tempstr.indexOf("|")), 1);
            if (returntype == "1" || returntype == "2" || returntype == "3" || returntype == "4" || returntype == "5") {
                filterfundinfo2[tt] = temparray2[i].split("|");
                tt++;
            }
        }
        if (type == globaltype) { info2 = filterfundinfo2; }
    }
    if (type == 2)   // 股票
    {
        for (var i = 0; i < temparray2.length; i++) {
            var tempstr = temparray2[i].toString();
            var returntype = FilterType(tempstr.substr(0, tempstr.indexOf("|")), 2);
            if (returntype == "1" || returntype == "2" || returntype == "3" || returntype == "4") {
                filterfundinfo2[tt] = temparray2[i].split("|");
                tt++;
            }
        }
        if (type == globaltype) { info2 = filterfundinfo2; }
    }
    if (type == 3)  // 混合
    {
        for (var i = 0; i < temparray2.length; i++) {
            var tempstr = temparray2[i].toString();
            var returntype = FilterType(tempstr.substr(0, tempstr.indexOf("|")), 2);
            if (returntype == "5" || returntype == "6" || returntype == "7") {
                filterfundinfo2[tt] = temparray2[i].split("|");
                tt++;
            }
        }
        if (type == globaltype) { info2 = filterfundinfo2; }
    }
    if (type == 4)  // 债券
    {
        for (var i = 0; i < temparray2.length; i++) {
            var tempstr = temparray2[i].toString();
            var returntype = FilterType(tempstr.substr(0, tempstr.indexOf("|")), 2);
            if (returntype == "8" || returntype == "9") {
                filterfundinfo2[tt] = temparray2[i].split("|");
                tt++;
            }
        }
        if (type == globaltype) { info2 = filterfundinfo2; }
    }
    if (type == 5)  // QDII
    {
        for (var i = 0; i < temparray2.length; i++) {
            var tempstr = temparray2[i].toString();
            var returntype = FilterType(tempstr.substr(0, tempstr.indexOf("|")), 3);
            if (returntype == "2") {
                filterfundinfo2[tt] = temparray2[i].split("|");
                tt++;
            }
        }
        if (type == globaltype) { info2 = filterfundinfo2; }
    }
    if (type == 6)  //  保本
    {
        for (var i = 0; i < temparray2.length; i++) {
            var tempstr = temparray2[i].toString();
            var returntype = FilterType(tempstr.substr(0, tempstr.indexOf("|")), 4);
            if (returntype == "4") {
                filterfundinfo2[tt] = temparray2[i].split("|");
                tt++;
            }
        }
        if (type == globaltype) { info2 = filterfundinfo2; }
    }
    if (type == 7)  // 指数
    {
        for (var i = 0; i < temparray2.length; i++) {
            var tempstr = temparray2[i].toString();
            var returntype = FilterType(tempstr.substr(0, tempstr.indexOf("|")), 2);
            if (returntype == "4") {
                filterfundinfo2[tt] = temparray2[i].split("|");
                tt++;
            }
        }
        if (type == globaltype) { info2 = filterfundinfo2; }
    }
    if (type == 8)  //ETF
    {
        for (var i = 0; i < temparray2.length; i++) {
            var tempstr = temparray2[i].toString();
            var returntype = FilterType(tempstr.substr(0, tempstr.indexOf("|")), 1);
            if (returntype == "2") {
                filterfundinfo2[tt] = temparray2[i].split("|");
                tt++;
            }
        }
        if (type == globaltype) { info2 = filterfundinfo2; }
    }
    if (type == 9)  //LOF
    {
        for (var i = 0; i < temparray2.length; i++) {
            var tempstr = temparray2[i].toString();
            var returntype = FilterType(tempstr.substr(0, tempstr.indexOf("|")), 1);
            if (returntype == "3") {
                filterfundinfo2[tt] = temparray2[i].split("|");
                tt++;
            }
        }
        if (type == globaltype) { info2 = filterfundinfo2; }
    }
    
    typenum = filterfundinfo2.length;
    return typenum;
}



function FilterType(str,colid)   // str格式1,1,1   colid表示要取的位置
{
    var arraytype = new Array();
    arraytype = str.toString().split(",");
    return arraytype[colid-1];
}

// 数据中心
function MakeSortTable(sortcol)   // sortcol 排序列
{
    changeOrderBg(sortcol);

    var info2part = new Array();

    str = "<table id=\"oTable\"><tbody>";

    var gh = 0;
    for (var gg = 0; gg < info2.length; gg++) {
        if (Trim(info2[gg][sortcol]) == "") {
            info2part[gh] = info2[gg];
            info2.splice(gg, 1);
            gg--;
            gh++;
        }
    }

    switch (sortcol) {
        case 1:
            if (globalsortorder == "desc")
                info2.sort(desc_col1);
            else
                info2.sort(asc_col1);
            break;
        case 3:
            if (globalsortorder == "desc")
                info2.sort(desc_col3);
            else
                info2.sort(asc_col3);
            break;
        case 4:
            if (globalsortorder == "desc")
                info2.sort(desc_col4);
            else
                info2.sort(asc_col4);
            break;
        case 5:
            if (globalsortorder == "desc")
                info2.sort(desc_col5);
            else
                info2.sort(asc_col5);
            break;
        case 6:
            if (globalsortorder == "desc")
                info2.sort(desc_col6);
            else
                info2.sort(asc_col6);
            break;
        case 7:
            if (globalsortorder == "desc")
                info2.sort(desc_col7);
            else
                info2.sort(asc_col7);
            break;
        case 8:
            if (globalsortorder == "desc")
                info2.sort(desc_col8);
            else
                info2.sort(asc_col8);
            break;
        case 9:
            if (globalsortorder == "desc")
                info2.sort(desc_col9);
            else
                info2.sort(asc_col9);
            break;
        case 10:
            if (globalsortorder == "desc")
                info2.sort(desc_col10);
            else
                info2.sort(asc_col10);
            break;
        case 11:
            if (globalsortorder == "desc")
                info2.sort(desc_col11);
            else
                info2.sort(asc_col11);
            break;
        case 12:
            if (globalsortorder == "desc")
                info2.sort(desc_col12);
            else
                info2.sort(asc_col12);
            break;
        case 13:
            if (globalsortorder == "desc")
                info2.sort(desc_col13);
            else
                info2.sort(asc_col13);
            break;
    }

    for (var gg = 0; gg < info2part.length; gg++) {
        info2.push(info2part[gg]);
    }

    P_allnum = info2.length;

    for (var hh = 0; hh < P_allnum; hh++) {
        str += "<tr onmouseout=\"this.className=''\" onmouseover=\"this.className='mcurrow'\">";
        str += "<td style=\"width:28px;\"><input type=\"checkbox\" id=\"" + info2[hh][1] + "\" name=\"checkcompare\" style=\"margin:0px;\" onclick=\"getCurRowNum(this,3)\" /></td>";
        str += "<td style=\"width:35px;\"></td>";
        str += "<td style=\"width:30px;\">" + (hh + 1) + "</td>";
        str += "<td style=\"width:60px;\">" + info2[hh][1] + "</td>";
        str += "<td style=\"width:90px;\"><span class=\"color039\"><a href=\"http://fund.eastmoney.com/" + info2[hh][1] + ".html\">" + info2[hh][2] + "</a></span></td>";
        str += "<td style=\"width:60px;\">" + datastyle1_1(info2[hh][3]) + "</td>";
        str += "<td style=\"width:60px;\">" + datastyle1_1(info2[hh][4]) + "</td>";
        str += "<td style=\"width:55px;\">" + datastyle1_2(info2[hh][7]) + "</td>";
        str += "<td style=\"width:55px;\">" + datastyle1_2(info2[hh][8]) + "</td>";
        str += "<td style=\"width:55px;\">" + datastyle1_2(info2[hh][9]) + "</td>";
        str += "<td style=\"width:55px;\">" + datastyle1_2(info2[hh][10]) + "</td>";
        str += "<td style=\"width:55px;\">" + datastyle1_2(info2[hh][11]) + "</td>";
        str += "<td style=\"width:55px;\">" + datastyle1_2(info2[hh][12]) + "</td>";
        str += "<td style=\"width:55px;\" class=\"lastcol\">" + datastyle1_2(info2[hh][13]) + "</td></td>";
        str += "</tr>";
    }
    str += "</tbody></table>";
    flag = 0;
    document.getElementById("marketData_1_" + globaltype).innerHTML = str;
    init_comparecookie();
}

function changeOrderBg(sortcol) {
    var otbHead = document.getElementById("otbhead");
    var temprowid, currow, curcol;
    if (globalsortcol != null) 
    {
        if (sortcol != globalsortcol) {
            temprowid = getOrderRow(globalsortcol);
            currow = otbHead.rows[temprowid];
            cur = getHeadCol(globalsortcol);
            curcol = currow.cells[cur];
            curcol.style.backgroundImage = "";
        }
        else 
        { 
        }
    }
    else {
        globalsortcol = sortcol;
    }
    
    temprowid = getOrderRow(sortcol);
    currow = otbHead.rows[temprowid];
    cur = getHeadCol(sortcol);
    curcol = currow.cells[cur];

    if (sortcol == globalsortcol) {
        if (globalsortorder == "desc") {
            globalsortorder = "asc";
            curcol.style.backgroundImage = "url(images/up.gif)";
            curcol.style.backgroundRepeat = "no-repeat";
            curcol.style.backgroundPosition = "100% 50%";
        }
        else {
            globalsortorder = "desc";
            curcol.style.backgroundImage = "url(images/down.gif)";
            curcol.style.backgroundRepeat = "no-repeat";
            curcol.style.backgroundPosition = "100% 50%";
        }
    }
    else 
    {
        globalsortcol = sortcol;
        if (globalsortorder == "desc") {
            globalsortorder = "asc";
            curcol.style.backgroundImage = "url(images/up.gif)";
            curcol.style.backgroundRepeat = "no-repeat";
            curcol.style.backgroundPosition = "100% 50%";
        } else {
            globalsortorder = "desc";
            curcol.style.backgroundImage = "url(images/down.gif)";
            curcol.style.backgroundRepeat = "no-repeat";
            curcol.style.backgroundPosition = "100% 50%";
        }
    }
}

function getOrderRow(tempsortcol) {
    if (tempsortcol == 1 || tempsortcol == 3 || tempsortcol == 4) {
        return 0;
    }
    else {
        return 1;
    }
}

function getHeadCol(sortcol) {
    var headcol;
    switch(sortcol)
    {
        case 1:
            headcol = 3;
            break;
        case 3:
            headcol = 5;
            break;
        case 4:
            headcol = 6;
            break;
        case 7:
            headcol = 0;
            break;
        case 8:
            headcol = 1;
            break;
        case 9:
            headcol = 2;
            break;
        case 10:
            headcol = 3;
            break;
        case 11:
            headcol = 4;
            break;
        case 12:
            headcol = 5;
            break;
        case 13:
            headcol = 6;
            break;
    }
    return headcol;
}

// 以下排序方法start
function desc_col1(x, y) {
        return Number(x[1]) - Number(y[1]);
    }
    function asc_col1(x, y) {
        return Number(y[1]) - Number(x[1]);
    }
function desc_col3(x, y) {
        return parseFloat(y[3]) - parseFloat(x[3]);
    }
    function asc_col3(x, y) {
        return parseFloat(x[3]) - parseFloat(y[3]);
    }
function desc_col4(x, y) {
        return parseFloat(y[4]) - parseFloat(x[4]);
    }
    function asc_col4(x, y) {
        return parseFloat(x[4]) - parseFloat(y[4]);
    }
function desc_col5(x, y) {
        return parseFloat(y[5]) - parseFloat(x[5]);
    }
    function asc_col5(x, y) {
        return parseFloat(x[5]) - parseFloat(y[5]);
    }
function desc_col6(x, y) {
        return parseFloat(y[6]) - parseFloat(x[6]);
    }
    function asc_col6(x, y) {
        return parseFloat(x[6]) - parseFloat(y[6]);
    }
function desc_col7(x, y) {
        return parseFloat(y[7]) - parseFloat(x[7]);
    }
    function asc_col7(x, y) {
        return parseFloat(x[7]) - parseFloat(y[7]);
    }
function desc_col8(x, y) {
        return parseFloat(y[8]) - parseFloat(x[8]);
    }
    function asc_col8(x, y) {
        return parseFloat(x[8]) - parseFloat(y[8]);
    }
function desc_col9(x, y) {
        return parseFloat(y[9]) - parseFloat(x[9]);
    }
    function asc_col9(x, y) {
        return parseFloat(x[9]) - parseFloat(y[9]);
    }
function desc_col10(x, y) {
        return parseFloat(y[10]) - parseFloat(x[10]);
    }
    function asc_col10(x, y) {
        return parseFloat(x[10]) - parseFloat(y[10]);
    }
function desc_col11(x, y) {
        return parseFloat(y[11]) - parseFloat(x[11]);
    }
    function asc_col11(x, y) {
        return parseFloat(x[11]) - parseFloat(y[11]);
    }
function desc_col12(x, y) {
        return parseFloat(y[12]) - parseFloat(x[12]);
    }
    function asc_col12(x, y) {
        return parseFloat(x[12]) - parseFloat(y[12]);
    }
function desc_col13(x, y) {
        return parseFloat(y[13]) - parseFloat(x[13]);
    }
    function asc_col13(x, y) {
        return parseFloat(x[13]) - parseFloat(y[13]);
    }

function datastyle1_1(value) {
    var value_tmp = "";
    if (value != "") {
        value = FormatNumber(value, 4);
        value1 = parseFloat(value);
        if (value1 < 0) { value_tmp = "<span style=\"color:#009900\">" + value + "</span>"; }
        if (value1 == 0) { value_tmp = "<span style=\"color:#000000\">0.0000</span>"; }
        if (value1 > 0) { value_tmp = "<span style=\"color:#ff0000\">" + value + "</span>"; }
        return value_tmp;
    }
    else {
        value_tmp = "---";
        return value_tmp;
    }
}
function datastyle1_2(value) {
    var value_tmp = "";
    if (value != "") {
        value = FormatNumber(value, 2);
        value1 = parseFloat(value);
        if (value1 < 0) { value_tmp = "<span style=\"color:#009900\">" + value + "%</span>"; }
        if (value1 == 0) { value_tmp = "<span style=\"color:#000000\">0.00%</span>"; }
        if (value1 > 0) { value_tmp = "<span style=\"color:#ff0000\">" + value + "%</span>"; }
        return value_tmp;
    }
    else {
        value_tmp = "---";
        return value_tmp;
    }
}

function datastyle1(value) {
    var value_tmp = "";
    if (value != "") {
        value = FormatNumber(value, 2);
        value1 = parseFloat(value);
        if (value1 < 0) { value_tmp = "<span style=\"color:#009900\">" + value + "</span>"; }
        if (value1 == 0) { value_tmp = "<span style=\"color:#000000\">0.00</span>"; }
        if (value1 > 0) { value_tmp = "<span style=\"color:#ff0000\">" + value + "</span>"; }
        return value_tmp;
    }
    else {
        value_tmp = "---";
        return value_tmp;
    }
}
function datastyle2(value) {
    var value_tmp = "";
    if (value != "") {
        value = parseInt(value);
        if (value ==0) { value_tmp = "---"; }
        if (value ==1) { value_tmp = "低"; }
        if (value ==2) { value_tmp = "偏低"; }
        if (value ==3) { value_tmp = "中"; }
        if (value ==4) { value_tmp = "高"; }
        return value_tmp;
    }
    else {
        value_tmp = "---";
        return value_tmp;
    }
}
function datastyle3(value) {
    var value_tmp = "";
    if (value != "") {
        value = parseInt(value);
        if (value ==0) { value_tmp = "---"; }
        if (value ==1) { value_tmp = "★"; }
        if (value ==2) { value_tmp = "★★"; }
        if (value ==3) { value_tmp = "★★★"; }
        if (value ==4) { value_tmp = "★★★★"; }
        if (value ==5) { value_tmp = "★★★★★"; }
        return value_tmp;
    }
    else {
        value_tmp = "---";
        return value_tmp;
    }
}
function datastyle4(value) {   // http://fund.eastmoney.com/images/lipper_rates_0.gif
    var value_tmp = "";
    if (value != "") {
        value = parseInt(value);
        if (value == 0) { value_tmp = "<img src=\"http://fund.eastmoney.com/images/lipper_rates_0.gif\">"; }
        if (value == 1) { value_tmp = "<img src=\"http://fund.eastmoney.com/images/lipper_rates_1.gif\">"; }
        if (value == 2) { value_tmp = "<img src=\"http://fund.eastmoney.com/images/lipper_rates_2.gif\">"; }
        if (value == 3) { value_tmp = "<img src=\"http://fund.eastmoney.com/images/lipper_rates_3.gif\">"; }
        if (value == 4) { value_tmp = "<img src=\"http://fund.eastmoney.com/images/lipper_rates_4.gif\">"; }
        if (value == 5) { value_tmp = "<img src=\"http://fund.eastmoney.com/images/lipper_rates_5.gif\">"; }
        return value_tmp;
    }
    else {
        value_tmp = "<img src=\"http://fund.eastmoney.com/images/lipper_rates_0.gif\">";
        return value_tmp;
    }
}

function Trim(str) {
    var result;
    result = str.replace(/(^\s+)|(\s+$)/g, "");
    return result;
}

function FormatNumber(srcStr, nAfterDot) {  // 1.50447872
    srcStr = Trim(srcStr);
    if (srcStr != "") {
        var srcStr, nAfterDot;
        var resultStr, nTen;
        strLen = srcStr.length;  // 10
        dotPos = srcStr.indexOf(".");  // 1
        if (dotPos == -1) {
            if (srcStr == 0) {
                resultStr = srcStr + "0.";
                for (i = 0; i < nAfterDot; i++) {
                    resultStr = resultStr + "0";
                }
                return resultStr;
            } else {
                resultStr = srcStr + ".";
                for (i = 0; i < nAfterDot; i++) {
                    resultStr = resultStr + "0";
                }
                return resultStr;
            }
        }
        else {
            if ((strLen - dotPos - 1) >= nAfterDot) {  // 小数点后位数大于或等于nAfterDot
                nTen = 1;
                for (j = 0; j < nAfterDot; j++) {
                    nTen = nTen * 10;
                }
                resultStr = Math.round(parseFloat(srcStr) * nTen) / nTen;  //1.5
                var dotPos2 = resultStr.toString().indexOf(".");  //1
                var strLen1 = resultStr.toString().length; // 3
                if (dotPos2 != -1) {
                    for (i = 0; i < (nAfterDot - strLen1 + dotPos2 + 1); i++) {
                        resultStr = resultStr.toString() + "0";
                    }
                }
                else {
                    resultStr = resultStr.toString() + ".";
                    for (i = 0; i < nAfterDot; i++) {
                        resultStr = resultStr.toString() + "0";
                    }
                }
               return resultStr;
            }
            else {   // 小数点后位数小于nAfterDot
                resultStr = srcStr;
                for (i = 0; i < (nAfterDot - strLen + dotPos + 1); i++) {
                    resultStr = resultStr + "0";
                }
                return resultStr;
            }
        }
    }
    else {
        return resultStr = "<span style=\"color:#000000\">---</span>";
    }
}

function init_comparecookie() {
    var temppagerowindex;
    if (getCookie(cookieName) != '') {
        var vCodeStr = getCookie(cookieName);
        var c = document.getElementById("oTable");
        for (a = 0; a < c.rows.length; a++) {
            var vStr = vCodeStr.indexOf(c.rows[a].cells[3].innerHTML);
            if (vStr != -1) {
                clicknum += 1;
                c.rows[a].style.backgroundColor = "#D2E2FF";
                document.getElementById(c.rows[a].cells[3].innerHTML).checked = true;
                //if (c.rows[a].cells[3].innerHTML == globalcheckid) {temppagerowindex = c.rows[a].rowIndex;}
            }
        }
        var temppagemaxcode, temppagerowindex
        for (var m = 0; m < c.rows.length; m++) {
            if (document.getElementById(c.rows[m].cells[3].innerHTML).checked == true) {
                temppagerowindex = m;
            }
        }

        if (temppagerowindex != null) {
            if (clicknum > 1) {
                var rid0 = c.rows[temppagerowindex];
                rid0.cells[1].innerHTML = "<input type=\"button\" name=\"comparebtn\" class=\"comparebtn\" onclick=\"javascript:open('http://fundacc2.eastmoney.com/fundcompare.aspx','','')\" />";
            }
        }
    }
}

function re_LoadScroll() {
    var scroll_title1 = document.getElementById("left_data");
    var scroll_title2 = document.getElementById("right_scroll_title");
    scroll_title1.style.position = 'relative';
    scroll_title1.style.top = "0px";
    scroll_title2.style.position = 'relative';
    scroll_title2.style.top = "0px";
    if (document.documentElement && document.documentElement.scrollTop) {
        document.documentElement.scrollTop = 0;
    } else if (document.body) {
        document.body.scrollTop = 0;
    }
}

/*
function getScroll() {
    var t, l, w, h, ch, oh;
    if (document.documentElement && document.documentElement.scrollTop) {
        t = document.documentElement.scrollTop;
        l = document.documentElement.scrollLeft;
        w = document.documentElement.scrollWidth;
        h = document.documentElement.scrollHeight;
        ch = document.documentElement.clientHeight;
        oh = document.documentElement.offsetHeight;
    } else if (document.body) {
        t = document.body.scrollTop;
        l = document.body.scrollLeft;
        w = document.body.scrollWidth;
        h = document.body.scrollHeight;
        ch = document.body.clientHeight;
        oh = document.body.offsetHeight;
    }
    // alert(t+"-"+l+"-"+w+"-"+h+"-"+ch+"-"+oh);
    return { t: t, l: l, w: w, h: h, ch: ch, oh: oh };
}

function getCurrPos(e) {
    var offset = e.offsetTop;
    if (e.offsetParent != null) {
        offset += getCurrPos(e.offsetParent);
    }
    return offset;
}
var initY11 = getCurrPos(document.getElementById("left_data"));
var initY12,initY21, initY22;
function checkGjcx() {
    var dropDiv2 = document.getElementById("right_title");
    if (dropDiv2.style.display == "block") {
        initY12 = dropDiv2.offsetHeight;
        initY22 = initY11 + initY12;
    }
    else {
        initY22 = initY11;
    }
    initY21 = initY11;
    // alert(initY21 +"-"+initY12);
}
function s() {
    checkGjcx();
    var scroll_title1 = document.getElementById("left_data");
    var scroll_title2 = document.getElementById("right_scroll_title");
    var scroll_list = document.getElementById("right_scroll_list");
    var s = getScroll();

    //alert(s.t + "-" + initY11 + "-" + scroll_list.offsetHeight);
    //alert(initY11+"-"+initY12+"-"+initY21+"-"+initY22);
    if (s.t >= initY21 && s.t < scroll_list.offsetHeight + initY21) {
        //alert("aaa");
        scroll_title1.style.position = 'relative';
        scroll_title1.style.top = (s.t - initY21) + "px";
    }
    if (s.t < initY21) {
        scroll_title1.style.position = 'relative';
        scroll_title1.style.top = "0px";
    }
    if (s.t >= initY22 && s.t < scroll_list.offsetHeight + initY22) {
        scroll_title2.style.position = 'relative';
        scroll_title2.style.top = (s.t - initY22-6) + "px";
    }
    if (s.t < initY22) {
        scroll_title2.style.position = 'relative';
        scroll_title2.style.top = "0px";
    }
}
window.onscroll = s;

function re_LoadScroll() {
    var scroll_title1 = document.getElementById("left_data");
    var scroll_title2 = document.getElementById("right_scroll_title");
    scroll_title1.style.position = 'relative';
    scroll_title1.style.top = "0px";
    scroll_title2.style.position = 'relative';
    scroll_title2.style.top = "0px";
    if (document.documentElement && document.documentElement.scrollTop) {
        document.documentElement.scrollTop = 0;
    } else if (document.body) {
        document.body.scrollTop = 0;
    }
}
 */

