﻿

function IFundRankTable(FundRankArray, Key, Codes){
    var tables = [];	
	var Temp = [];
	var ShowCodeArray = Codes.split(';');
	tables.push('<table class="f_result" cellpadding="0" cellspacing="1" style="margin:0 auto;width:950px;">');
    tables.push('<colgroup>');
	tables.push('<col style="width: 30px;"></col>');
	tables.push('<col style="width: 158px;"></col>');	
	tables.push('<col style="width: 83px;"></col>');
	tables.push('<col style="width: 83px;"></col>');
	//tables.push('<col style="width: 73px;"></col>');	
//	tables.push('<col style="width: 20px;"></col>');
//	tables.push('<col style="width: 48px;"></col>');
	tables.push('<col style="width: 20px;"></col>');
	tables.push('<col style="width: 48px;"></col>');
	tables.push('<col style="width: 20px;"></col>');
	tables.push('<col style="width: 48px;"></col>');
	tables.push('<col style="width: 20px;"></col>');
	tables.push('<col style="width: 48px;"></col>');
	tables.push('<col style="width: 20px;"></col>');
	tables.push('<col style="width: 48px;"></col>');
	tables.push('<col style="width: 20px;"></col>');
	tables.push('<col style="width: 48px;"></col>');
	tables.push('<col style="width: 20px;"></col>');
	tables.push('<col style="width: 48px;"></col>');
	tables.push('<col style="width: 20px;"></col>');
	tables.push('<col style="width: 48px;"></col>');
	tables.push('</colgroup><tbody>');
	
	var order = 1;
	for(var i=0;i<FundRankArray.length;i++)
	{	
	    if(Codes != "0" && !ShowCodeArray.exists(FundRankArray[i]["Code"]))
	        continue;
		if(Key == "TwoStar" && FundRankArray[i]["TwoStar"] == "-1"){
		    Temp.push(PushTR("--", FundRankArray[i]));
		}
		else if(Key == "ThreeStar" && FundRankArray[i]["ThreeStar"] == "-1"){
		    Temp.push(PushTR("--", FundRankArray[i]));
		}
		else if(Key == "FiveStar" && FundRankArray[i]["FiveStar"] == "-1"){
		    Temp.push(PushTR("--", FundRankArray[i]));
		}
		else if (Key == "WeeklyYield" && FundRankArray[i]["WeeklyYield"] == -1985)
		{
			Temp.push(PushTR("--", FundRankArray[i]));
		}
		else if (Key == "YieldFor1Month"  && FundRankArray[i]["YieldFor1Month"] == -1985)
		{
			Temp.push(PushTR("--", FundRankArray[i]));
		}
		else if (Key == "YieldFor3Month"  && FundRankArray[i]["YieldFor3Month"] == -1985)
		{
			Temp.push(PushTR("--", FundRankArray[i]));
		}
		else if (Key == "YieldForHalfYear"  && FundRankArray[i]["YieldForHalfYear"] == -1985)
		{
			Temp.push(PushTR("--", FundRankArray[i]));
		}	
		else if (Key == "YieldFor1Year"  && FundRankArray[i]["YieldFor1Year"] == -1985)
		{
			Temp.push(PushTR("--", FundRankArray[i]));
		}
		else if (Key == "YieldFor2Year"  && FundRankArray[i]["YieldFor2Year"] == -1985)
		{
			Temp.push(PushTR("--", FundRankArray[i]));
		}		
		else if (Key == "YieldFor3Year"  && FundRankArray[i]["YieldFor3Year"] == -1985)
		{
			Temp.push(PushTR("--", FundRankArray[i]));
		}
		else if (Key == "YieldForThisYear"  && FundRankArray[i]["YieldForThisYear"] == -1985)
		{
			Temp.push(PushTR("--", FundRankArray[i]));
		}
		else
		{
			tables.push(PushTR(order, FundRankArray[i]));
			order++;
		}
	}
	tables.push(Temp.join(''));
	tables.push('</tbody></table>');
	return tables.join('');
}

function PushTR(order, netValues)
{
    var tables = [];
	var weeklyYieldColor, yieldFor1MonthColor, yieldFor3MonthColor, yieldForHalfYearColor, yieldFor1YearColor, yieldForThisYearColor,yf2c,yf3c;
	weeklyYieldColor = returnColor(netValues["WeeklyYield"]);
	yieldFor1MonthColor = returnColor(netValues["YieldFor1Month"]);
	yieldFor3MonthColor = returnColor(netValues["YieldFor3Month"]);
	yieldForHalfYearColor = returnColor(netValues["YieldForHalfYear"]);
	yieldFor1YearColor = returnColor(netValues["YieldFor1Year"]);
	yieldForThisYearColor = returnColor(netValues["YieldForThisYear"]);
	yf2c = returnColor(netValues["YieldFor2Year"]);
	yf3c = returnColor(netValues["YieldFor3Year"]);
	
	tables.push('<tr bgColor="'+GetFavoriteColor(netValues["Code"])+'" style="cursor:pointer;" onmouseout="changebg(this)" onmouseover="changebg1(this)">');
	tables.push("<td title='序号' >"+order+"</td>");
	tables.push('<td title="基金名称" ><a class="pa" target="_blank" href="http://fund.fund123.cn/html/' + netValues["Code"] + '">' + netValues["Name"] + '</a><span class="bar">[<a target="_blank" href="http://bbs.fund123.cn/' + netValues["Code"] + '.aspx"  onclick="StatClickRate(\'基金吧\')">吧</a>]</span></td>');
	tables.push("<td title='基金评级二年'>" + GetStar(netValues["TwoStar"]) + "</td>");
	tables.push("<td title='基金评级三年'>" + GetStar(netValues["ThreeStar"]) + "</td>");
	//tables.push("<td title='基金评级五年'>" + GetStar(netValues["FiveStar"]) + "</td>");		
//	tables.push("<td title='最近一周排名'>" +(netValues["WeeklyYieldOrder"] == -1985 ? "--" : netValues["WeeklyYieldOrder"])+"</td>");	
//	tables.push("<td title='最近一周回报' "+weeklyYieldColor+">" +(netValues["WeeklyYield"] == -1985 ? "--" : (FormatNumber(netValues["WeeklyYield"], 2)) )  +"</td>");
	tables.push("<td title='最近一月排名'>" +(netValues["YieldFor1MonthOrder"] == -1985 ? "--" : netValues["YieldFor1MonthOrder"])+"</td>");	
	tables.push("<td title='最近一月回报' "+yieldFor1MonthColor+">" +(netValues["YieldFor1Month"] == -1985 ? "--" : (FormatNumber(netValues["YieldFor1Month"], 2)) )+"</td>");
	tables.push("<td title='最近一季排名'>" +(netValues["YieldFor3MonthOrder"] == -1985 ? "--" : netValues["YieldFor3MonthOrder"])+"</td>");	
    tables.push("<td title='最近一季回报' "+yieldFor3MonthColor+">" +(netValues["YieldFor3Month"] == -1985 ? "--" : (FormatNumber(netValues["YieldFor3Month"], 2)))+"</td>");
	tables.push("<td title='最近半年排名'>" +(netValues["YieldForHalfYearOrder"] == -1985 ? "--" : netValues["YieldForHalfYearOrder"])+"</td>");	
    tables.push("<td title='最近半年回报' "+yieldForHalfYearColor+">" +(netValues["YieldForHalfYear"] == -1985 ? "--" : (FormatNumber(netValues["YieldForHalfYear"], 2))) +"</td>");
	tables.push("<td title='最近一年排名'>" +(netValues["YieldFor1YearOrder"] == -1985 ? "--" : netValues["YieldFor1YearOrder"])+"</td>");	
    tables.push("<td title='最近一年回报' "+yieldFor1YearColor+">" +(netValues["YieldFor1Year"] == -1985 ? "--" : (FormatNumber(netValues["YieldFor1Year"], 2))) +"</td>");
    tables.push("<td title='最近二年排名'>" +(netValues["YieldFor2YearOrder"] == -1985 ? "--" : netValues["YieldFor2YearOrder"])+"</td>");	
    tables.push("<td title='最近二年回报' "+yf2c+">" +(netValues["YieldFor2Year"] == -1985 ? "--" : (FormatNumber(netValues["YieldFor2Year"], 2))) +"</td>");
	tables.push("<td title='最近三年排名'>" +(netValues["YieldFor3YearOrder"] == -1985 ? "--" : netValues["YieldFor3YearOrder"])+"</td>");	
    tables.push("<td title='最近三年回报' "+yf3c+">" +(netValues["YieldFor3Year"] == -1985 ? "--" : (FormatNumber(netValues["YieldFor3Year"], 2)))+"</td>");
	tables.push("<td title='今年以来排名'>" +(netValues["YieldForThisYearOrder"] == -1985 ? "--" : netValues["YieldForThisYearOrder"])+"</td>");	
    tables.push("<td title='今年以来回报' "+yieldForThisYearColor+">" +(netValues["YieldForThisYear"] == -1985 ? "--" : (FormatNumber(netValues["YieldForThisYear"], 2)))+"</td>");
	tables.push("</tr>");
	return tables.join('');
}

function GetStar(value){
    if(value == "-1")
        return "--";
    return "<img src=/Images/yh" + value +".gif />";
}

var tb = new TableBase("tb", "Content", IFundRankTable);
