var activeid="pretotal";



function SortData(obj)
{
	ClearTitle();
	var sortMode = "0";
	if (obj.getAttribute("order") != "") {	sortMode = obj.getAttribute("order"); }
	BindData(obj.title, sortMode);
	var title = obj.innerHTML;
	acitveid=obj.id;
	if (sortMode != "1") 
	{

		obj.setAttribute("order", "1"); 
		obj.innerHTML = title + "<img src='/images/arrowDown.gif' align='absmiddle' border='0' />";
	}
	else
	{
		obj.setAttribute("order", "0");
		obj.innerHTML = title + "<img src='/images/arrowUp.gif' align='absmiddle' border='0' />";
	}
	var height=GetCookie("currencyFundListHeight");
    document.getElementById("MyFundDiv").style.height=height;

}

function ClearTitle()
{
	var tableHeader = document.getElementById("tableHeader");
	var links = tableHeader.getElementsByTagName("A");
	for(var i=0; i<links.length; i++)
	{
		links[i].innerHTML = links[i].title.replace("上个交易日", "");
	}
}

function sortbyCode(x, y) { if(x[0] < y[0]) { return 1; } else { return -1; }}
function sortbyName(x, y) { return y[1].localeCompare(x[1]); }
function sortbyCRev(x, y) { if(x[2] < y[2]) { return 1; } else { return -1; }}
function sortbyCRev7(x, y) { if(x[3] < y[3]) { return 1; } else { return -1; }}
function sortbyPRev(x, y) { if(x[4] < y[4]) { return 1; } else { return -1; }}
function sortbyPRev7(x, y) { if(x[5] < y[5]) { return 1; } else { return -1; }}


function BindData(sort, sortMode)
{
   //2008-1-19 var netValues = eval(document.getElementById("d").innerHTML); 
	if (sort == "代码")
	{
		netValues.sort(sortbyCode);
	}
	if (sort == "名称")
	{
		netValues.sort(sortbyName);
	}
	if (sort == "日收益(元/万份)")
	{
		netValues.sort(sortbyCRev);
	}
	if (sort == "7日年化收益率(%)")
	{
		netValues.sort(sortbyCRev7);
	}
	if (sort == "上个交易日收益(元/万份)")
	{
		netValues.sort(sortbyPRev);
	}
	if (sort == "上个交易日7日年化收益率(%)")
	{
		netValues.sort(sortbyPRev7);
	}
	
	if (sortMode == "1")
	{
		netValues.reverse();
	}
	var tables = [];
	var tablesTemp = [];
	tables.push('<table id="tblContent" style="width:760px" >');

	var order = 1;
	for(var i=0;i<netValues.length;i++)
	{
		if(document.getElementById('qid').value=="") 
		{
			if ((sort == "crev" || sort == "crev7") && netValues[i][2] == 0)
			{
				PushTR(i, "--", netValues, tablesTemp);
			}
			else if ((sort == "prev" || sort == "prev7") && netValues[i][4] == 0)
			{
				PushTR(i, "--", netValues, tablesTemp);
			}
			else
			{
				PushTR(i, order, netValues, tables);
				order++;
			}
		}
		else if(document.getElementById('qid').value==netValues[i][0]) 
		{
			PushTR(i, order, netValues, tables);
			order++;	
			
		}	
	}
	tables.push(tablesTemp.join(''));
	tables.push('</table>');
	document.getElementById("MyFundDiv").innerHTML = tables.join('');
}

function PushTR(i, order, netValues, tables)
{
	var percentColor,disValueColor,percent,disValue,predictRatio;
	percent = netValues[i][5];
//	percentColor = "";
	if (percent)
	{
		if (percent > 0)
		{
			percentColor = "style='color:red'";
		}
		else if (percent < 0)
		{
			percentColor = "style='color:green'";
		}
	}
	
	disValue = netValues[i][4];
	disValueColor = "";    
	if (disValue)
	{
		if (disValue > 0)
		{
			disValueColor = "style='color:red'";
		}
		else if (disValue < 0)
		{
			disValueColor = "style='color:green'";
		}
	}
	var predictColor='';
	predictRatio=netValues[i][14];
	if(predictRatio!="-") 
	{
		if(predictRatio>0) predictColor="style='color:red'";
		else predictColor="style='color:green'";
	}

	tables.push('<tr style="cursor:pointer;" type="code" code="'+netValues[i][0]+'" onmouseout="changebg(this)" onmouseover="changebg1(this)">');
	tables.push("<td width='40px' title='序号'>"+order+"</td>");
	tables.push('<td width="70px" title="基金代码"><a target="_blank" href="/crfund-'+netValues[i][0]+'.html">' +netValues[i][0]+'</a></td>');
	tables.push('<td width="110px" title="基金名称"><a target="_blank" href="/crfund-'+netValues[i][0]+'.html">' +netValues[i][1]+'</td>');
	tables.push("<td width='115px' title='日收益(元/万份)'>" +(netValues[i][2] == 0 ? "--" : FormatNumber(netValues[i][2],4))+"</td>");
	tables.push("<td width='115px' title='7日年化收益率(%)'>" +(netValues[i][2] == 0 ? "--" : FormatNumber(netValues[i][3],4))+"</td>");
	tables.push("<td width='115px' title='上个交易日日收益(元/万份)' style='color: #666'>" +(netValues[i][4] == 0 ? "--" : FormatNumber(netValues[i][4],4))+"</td>");
	tables.push("<td width='115px' title='上个交易日7日年化收益率(%)' style='color: #666'>" +(netValues[i][5] == 0 ? "--" : FormatNumber(netValues[i][5],4))+"</td>");
	tables.push('<td width="80px"><a target="_blank" href="/crfund-'+netValues[i][0]+'.html">');
	tables.push('走势图</a>&nbsp;');
	tables.push('</td>');	
	tables.push("</tr>");
}


var isLock = true;
function LockTitle(bool)
{
	isLock = bool;
	var divLock = document.getElementById("MyFundDiv");
	if (bool)
	{
		divLock.style.overflow = "auto";
	}
	else
	{
		divLock.style.overflow = "";
	}
}

function ResizeNetValueList(size)
{
	var divLock = null;
	if (document.getElementById)
	{
		divLock = document.getElementById("MyFundDiv");
	}
	else
	{
		eval('MyFundDiv = MyFundDiv;');
	}
	if (size == 1985)
	{
		divLock.style.height = "auto";
	}
	else if (size == -1985)
	{
		divLock.style.height = "266px";
	}
	else
	{
		var height = parseInt(divLock.style.height.replace("px", ""));
		height = height + size;
		if (height > 100)
		{
			divLock.style.height = height + "px";
		}
		SetCookie("currencyFundListHeight", divLock.style.height);
	}

}


function ChangeMode(text, value)
{
	if (text)
	{
		saveText = text;
		saveValue = value;
	}
	else
	{
		if (saveText)
		{
			text = saveText;
			value = saveValue;
		}
		else
		{
			text = "全部基金";
			value = "0";
		}
	}
	
	var iframe = document.getElementsByTagName("iframe")[0]; 
	SortListTableVarMode(text,value);
	
}




function CombineArray(source, codes)
{
    var returnAry = [];
    for( var j=0; j<codes.length; ++j )
    {  
        for( var i=0; i<source.length; ++i )
        {
            if( codes[j] == source[i] )
            {
               returnAry.push(codes[j]);
            } 
        }
    }  
   
    return returnAry;
}

function ResizeIframe()
{
	return ;
}

function ClearActiveID()
{
	/*
	var nav = document.getElementById("inav");
	var all = nav.childNodes[1].childNodes[0];
	var active = document.getElementById("active");
	active.id="";
	all.id="active";
	*/
}

function FormatNumber(srcStr,nAfterDot)
{
　var srcStr,nAfterDot;
　var resultStr,nTen;
　srcStr = ""+srcStr+"";
　strLen = srcStr.length;
　dotPos = srcStr.indexOf(".",0);
　if (dotPos == -1)
　{
　　resultStr = srcStr+".";
　　for (i=0;i<nAfterDot;i++){
　　　resultStr = resultStr+"0";
　　}
　　return resultStr;
　}
　else
　{
　　if ((strLen - dotPos - 1) >= nAfterDot)
　　{
　　　nAfter = dotPos + nAfterDot + 1;
　　　nTen =1;
　　　for(j=0;j<nAfterDot;j++){
　　　　nTen = nTen*10;
　　　}
　　　resultStr = Math.round(parseFloat(srcStr)*nTen)/nTen;
　　　return resultStr;
　　}
　　else
　　{
　　　resultStr = srcStr;
　　　for (i=0;i<(nAfterDot - strLen + dotPos + 1);i++){
　　　　　resultStr = resultStr+"0";
　　　}
　　　return resultStr;
　　}
　}
} 
