﻿// JScript 文件
var TypeId;             //类型ID
var FundCompany;        //基金公司
var SearchDate;        //搜索时间            
var FTYPE;              //基金类型
var LinkUrl;            //链接页面
var SetTop;             //置顶我的基金
var SetBright;          //高亮我的基金
var StartTime;          //开始时间
var EndTime;            //结束时间
var FCODE;              //基金代码
var FirstChar           //汉字首字母值

var DateSelect;    //时间下拉列表
var TypeSelect;     //基金公司下拉列表
var CompanySelect   //基金类型下拉列表
var FirstCharHid;   //汉字首字母

var StartTimeText;  //开始时间
var EndTimeText;        //结束时间
var SearchCodeText;     //基金名称
var CodeText;           //基金代码
var FirstCharDiv;        //首字母列表Div
var DivTop;             //置顶和高亮          

var TypeId=21;

var LastDate="";   //前一天
var LastDateStr;
var ThisStr=1;
var ThisLink;  //当前选中的栏目链接

//不同栏目显示的不同文字
var smar=new Array(24);
for (i = 0; i < smar.length; i++)
{
   smar[i] ="";
}
smar[21]="        每日收盘后,下午4点左右开始动态更新当日开放式单位净值,至晚上9点左右绝大部分开放式基金净值数据更新。<br />16：00-21：00之间，您刷新数据页面，即可获取当时已经更新的净值数据。";
smar[1]="        本表需要对历史数据进行大量计算，净值数据晚一日更新。";
smar[2]="        本表需要对历史数据进行大量计算，净值数据晚一日更新。";
smar[3]="        本表需要对历史数据进行大量计算，比当前日期晚一日更新。";
smar[4]="        本表需要对历史数据进行大量计算，数据晚一日更新。";
smar[22]="        本表在每日晚当时基金净值数据更新后更新。";
smar[5]="        每月月初根据截至上月月末的基金数据进行月度评级。本表在每月月初更新当月评级数据。";
smar[6]="        基金投资风格计算基于基金投资组合，基金以季度为周期公布投资组合情况。本表在基金发布季度投资组合报告后开始动态更新。";
smar[7]="        在任基金经理数据每日更新。净值增长率数据截至当前计算日期。";
smar[8]="        本表需要对历史数据进行大量计算，数据晚一日更新。";
smar[9]="        本表显示最近五次分红公告的数据。基金发布分红公告后本表进行更新。";
smar[10]="       基金公司更新或新增网上交易平台后，我们将在第一时间更新相关数据。";
smar[11]="        每日收盘后，下午4点左右开始动态更新当日开放式单位净值，至晚上9点左右绝大部分开放式基金净值数据更新。<br />16：00-21：00之间，您刷新数据页面，即可获取当时已经更新的净值数据。";
smar[12]="        每日收盘后更新当日价格、折溢价数据。";
smar[13]="        基金公司发布最新货币基金收益信息后更新。";
smar[23]="        本表在每日晚当时基金净值数据更新后更新。";
smar[14]="        每月月初根据截至上月月末的基金数据进行月度评级。本表在每月月初更新当月评级数据。";
smar[15]="        基金公司发布最新基金组合公告后更新本表数据。";
smar[16]="        基金公司发布最新基金组合公告后更新本表数据。";
smar[17]="        基金公司发布最新基金组合公告后更新本表数据。";
smar[18]="        当日收盘后第二天更新本表数据。";
smar[19]="        基金发布分红公告后本表进行更新。";
smar[20]="        在任基金经理数据每日更新。净值增长率数据截至当前计算日期。";

function GoToListData(TypeId)
{
        //根据不同TypeID绑定最新时间 
        GetUrlInfo("GetDate.aspx?typeid="+TypeId); 
    document.getElementById("TypeId").value=TypeId;
    GetParamValue();//取得参数
    
    if (TypeId!="")
    {    

        document.getElementById("LinkUrl").value="ListData"+TypeId+".aspx";
        param="TypeId="+TypeId;
        
        //重置下拉列表
        CompanySelect.options[0].selected=true;   
        DateSelect.options[0].selected=true;     
        TypeSelect.options[0].selected=true;
        document.getElementById("setviewall").checked=false;

        //清空时间选择框
        StartTimeText.value="";
        EndTimeText.value="";
        SearchCodeText.value="";
        CodeText.value="";
        
        
        //改变链接文本显示样式
        ChangeCss(TypeId);
        
        //根把不同类型隐藏相应下拉列表
        if (TypeId==3)
        {
            TypeSelect.style.display="none";
        }
        else
        {
            TypeSelect.style.display="";
        }
        
        //是否隐藏字母链接列表
        if (TypeId==7)
        {
            FirstCharDiv.style.display="";
        }
        else
        {
            FirstCharDiv.style.display="none";
        }                  
        
        //是否隐藏置顶高亮功能
        if (TypeId==2 || TypeId==3 || TypeId==4 || TypeId==22)
        {
            DivTop.style.display="none";
        }
        else
        {
            DivTop.style.display="";
        } 
        
        //是否隐藏显示扩展字段功能
        if (TypeId==1 || TypeId==2 || TypeId==3 || TypeId==4)
        {
             document.getElementById("viewallcolumn").style.display="";
        }
        else
        {
             document.getElementById("viewallcolumn").style.display="none";
        } 
        
        if (TypeId==22)
        {
            document.getElementById("fcompany").style.display="none";
            document.getElementById("ftype").style.display="none";
        }
        else
        {
            document.getElementById("fcompany").style.display="";
            document.getElementById("ftype").style.display="";
        }
        
        if (TypeId==10)
        {
            document.getElementById("divall").style.display="none";
        }
        else if(ThisStr==1)
        {
             document.getElementById("divall").style.display="";
        }
        document.getElementById("datasm").innerHTML=smar[TypeId];
        //window.frames["ListData"].location="ListData"+TypeId+".aspx?"+param;
    }
    else
    {
        alert("请选择查询类型!");
    }
    return;
}

//连接条件
function GoToListDataResult()
{

     GetParamValue();//取得参数
    
        if (TypeId!="")
        {
            //类型是否为空
            param="TypeId="+TypeId;
            //公司是否为空
            if (FundCompany!=""&&FundCompany!="所有公司")
            {
                param+="&company="+FundCompany;
            }
            //时间是否为空
            if (SearchDate!="")
            {
                param+="&date="+SearchDate;
            }
            //基金类型是否为空
             if (FTYPE!="")
            {
                param+="&ftype="+FTYPE;
            }
            //是否置顶我的基金
            if (SetTop!="")
            {
                param+="&settop="+SetTop;
            }
            
            //是否高亮我的基金
            if (SetBright!="")
            {
                param+="&setbright="+SetBright;
            }
            
            //开始时间是否为空
            if (StartTime!="")
            {
                param+="&starttime="+StartTime;
            }
            
            //结束时间是否为空
            if (EndTime!="")
            {
                param+="&endtime="+EndTime;
            }
            //汉字首字母是否为空
            if (FirstChar!="")
            {
                param+="&firstchar="+FirstChar;
            }
                       
            if (FCODE!="")
            {
                param+="&fcode="+FCODE;
            }
            
            if (TypeId==21)
            {
                param+="&LastDate="+LastDate;
            }
            DisplayWait();

            window.frames["ListData"].location=LinkUrl+"?"+param;
        }
        else
        {
            alert("请选择查询类型!");
        }
        
        return;
}

//显示载入层
function DisplayWait()
{
    document.all("divWait").style.display="";
}

//取得参数值
function GetParamValue()
{
    DateSelect=document.getElementById(controlname2);    //时间下拉列表
    TypeSelect=document.getElementById(controlname3);     //基金公司下拉列表
    CompanySelect=document.getElementById(controlname1);   //基金类型下拉列表
    
    StartTimeText=document.getElementById("starttime")
    EndTimeText=document.getElementById("endtime");
    SearchCodeText=document.getElementById("searchcode");
    CodeText=document.getElementById("fcode");
    FirstCharHid=document.getElementById("firstchar");
    FirstCharDiv=document.getElementById("firstchardiv");
    
    DivTop=document.getElementById("divtop");

    TypeId=document.getElementById("TypeId").value;//类型ID
    FundCompany=document.getElementById(controlname1).value;//基金公司
    SearchDate=document.getElementById(controlname2).value; //搜索时间
    
    //得到搜索时间的前一天
    if (LastDateStr!="")
    {
        if (TypeId==21) 
        {
                var arrnum=DateSelect.options.length;;
                for (i = 0; i < arrnum; i++)
                { 
                    if(i==arrnum-1)
                    {
                            LastDate=LastDateStr;    
                    }
                    else
                    {   
                          if (DateSelect.options[i].value==SearchDate)
                          {
                             LastDate=DateSelect.options[i+1].value;
                             break;
                             
                          }
                    }    
                }
                
        } 
    }   
    FTYPE=document.getElementById(controlname3).value; //基金类型
    StartTime=document.getElementById("starttime").value;
    EndTime=document.getElementById("endtime").value;
    FCODE=document.getElementById("fcode").value;
    FirstChar=FirstCharHid.value;               //汉字首字母字符
    

    LinkUrl=document.getElementById("LinkUrl").value; //链接页面
    
    if (TypeId>=15&&TypeId<=17)
    {
        document.getElementById("tzzh").style.display="";
    }
    else
    {
        document.getElementById("tzzh").style.display="none";
    }
    
    //
    if (TypeId==23)
    {
        document.getElementById("exponentcode").style.display="";
        document.getElementById("scode").style.display="none";
    }
    else
    {
        document.getElementById("exponentcode").style.display="none";
        document.getElementById("scode").style.display="";
    }
    var obj=document.getElementsByName("settop");
        for(var i=0;i<obj.length;i++)
        {
            if(obj[i].checked)
            {
                SetTop=1;
            }
            else
            {
                SetTop=0;
            }
        }
    obj=document.getElementsByName("setbright");
     for(var i=0;i<obj.length;i++)
        {
            if(obj[i].checked)
            {
                SetBright=1;
            }
            else
            {
                SetBright=0;
            }
        }
}

//提示未登录用户(注册|登录)后设置自己收藏的基金
function AlertUserSet()
{
    alert("请注册登录后,设置自己收藏的基金!");
}

//判断用户是否登录
function CheckUserLogin()
{
    var http = new ActiveXObject("Microsoft.XMLHTTP");
    if(http!=null)
    {
        http.onreadystatechange=function()
        {
             if (http.readyState == 4)
		    {
                if (http.status == 200 && http.responseText)
			    {
			        //处理返回数据
			        if(http.responseText=="1")
			        {
                        GoToListDataResult();   
    			    }
    			    else
    			    {
    			        AlertUserSet();
    			    }
    			   
			    }
		    }
        };
        
        url="../user/CheckUserLogin.aspx";
	    http.open("GET",url , true);
        http.send(null);
    }
}

//得到指定页面返回的信息

function GetUrlInfo(url)
{
    var http = new ActiveXObject("Microsoft.XMLHTTP");
    if(http!=null)
    {
        http.onreadystatechange=function()
        {
             if (http.readyState == 4)
		    {
                if (http.status == 200 && http.responseText)
			    {
			        //处理返回数据
			        SetDateSelect(http.responseText);
			        //转入页面
			        GoToListDataResult();
			    }
		    }
        };
	    http.open("GET",url , true);
        http.send(null);
    }
}

//重新绑定时间下拉列表
function SetDateSelect(content)
{

    if(content.indexOf('|')>0)
    {
        //清空Select中全部Option
        var ln = DateSelect.options.length;
        while (ln--)
            {
              DateSelect.options[ln] = null;
            }
        var arr=content.split('|');
        //ID为21去除掉最后一个日期
            var arrnum
            if (TypeId==21)
            {
                arrnum=arr.length-2;
                LastDateStr=arr[5];
            }
            else
            {
                arrnum=arr.length-1
            }
            for (i = 0; i < arrnum; i++)
            { 
              DateSelect.add (new Option(arr[i], arr[i]));
            }
        
        if (TypeId>10 &&TypeId!=21 &&TypeId!=22)
        {
           var newdate=content.substring(0,4)+"-"+content.substring(4,6)+"-"+content.substring(6,8);
           var startdate=arr[2].substring(0,4)+"-"+arr[2].substring(4,6)+"-"+arr[2].substring(6,8);
            document.getElementById("endtime").value=newdate;
            document.getElementById("starttime").value=startdate;
            document.getElementById("fcode").value=arr[1];
            document.getElementById("searchcode").value=arr[3];
        }
                 
    }
}

//切换全景数据和历史数据显示
function ChangeList(val)
{
    if (val==1)
    {
        document.getElementById("alldata").style.display="";
        document.getElementById("historydata").style.display="none";
        document.getElementById("divall").style.display="";
        document.getElementById("divhistory").style.display="none";
        document.getElementById("la").className="dataf2";
        document.getElementById("lb").className="dataf1";
        ThisStr=val;
        GoToListData('21');
    }
    else
    {
        document.getElementById("alldata").style.display="none";
        document.getElementById("historydata").style.display="";
        document.getElementById("divall").style.display="none";
        document.getElementById("divhistory").style.display="";
        document.getElementById("lb").className="dataf2";
        document.getElementById("la").className="dataf1";
        ThisStr=val;
        GoToListData('11');
    }
    


}
//检查历史数据搜索条件
function CheckData()
{
         try
         {
            if (TypeId==23)
            {
                document.getElementById("fcode").value=document.getElementById("exponentcode").value;
                //document.getElementById("searchcode").value="test";
                GoToListDataResult();
                return
            }
            var code=document.getElementById("fcode");
            var stime=document.getElementById("starttime").value;
            var etime=document.getElementById("endtime").value;
            if (code.value!="" && SearchCodeText.value!="")
            {
                document.getElementById("fcode").value=Z.hideValue.value;
            }
            else
            {
                alert("请输入基金代码");
                document.getElementById("searchcode").focus();
                return;
            }
            if (stime=="")
            {
                alert("请输入开始时间");
                return;
            }
            if (etime=="")
            {
                alert("请输入结束时间");
                return;
            }
            GoToListDataResult();
        }
        catch(e)
        {
              alert("请输入基金代码!");
              document.getElementById("searchcode").focus();
              return;
        }
        finally 
        {

        }
}

//基金投资组合
function GoToZh(val)
{
    GoToListData(val);
}

//清空基金代码框
function CheckCode(codetext)
{
   if(codetext.value=="基金代码")
   {
        codetext.value="";
   }
}
//按首字线显示数据(基金经理)
function ToMana(val)
{
 FirstCharHid.value=val;
 GoToListDataResult();
// var tourl=location.href;
// 
// if (tourl.indexOf("firstchar")>0)
// {
//     tourl= tourl.substring(0,tourl.length - 1) + val;
// }
// else
// {
//    tourl+="&firstchar=" + val;
// }

 //window.parent.document.all("divWait").style.display="";
 //window.location=tourl;
}

//切换字母显示样式
var curMenu=null;
function cstyle(linkid)
{
    var xMenu;
    if(curMenu!==null)
        {
            curMenu.className="dataf1";
        }
        xMenu=document.getElementById(linkid);
        xMenu.className="dataf2";
        curMenu=document.getElementById(linkid);
}
//指数跳转
function GoToExponent(val)
{
   document.getElementById("fcode").value=val;
   GoToListDataResult();
}

//显示扩展字段
function ViewAllColumn()
{
    DisplayWait();
    window.frames["ListData"].document.getElementById("viewall").click();
}

//保存成Excel
function SaveExcel()
{
    window.frames["ListData"].document.getElementById("ToExcel").click();
}

//改变样式
function ChangeCss(TypeId)
{
    var link=document.getElementById("gdata" + TypeId);
    if (ThisLink!=null)
    {
        ThisLink.className="";
    }
    
        link.className="activelink";
        ThisLink=link;
}
