/* ----- */

ForexListPage = new function(){
	this.dataArray;
	this.currentColumn = "1";
	this.divName = "ForexListPage";
	this.columnArray = new Array();
	this.reloadTime = 60000;
	this.reload = true;
	this.setTimeObj;
	this.GetData = function(array,time)
	{
		this.dataArray = array;
		this.ShowTime(time);
		//this.ShowPage(StockListRequest.page,StockListRequest.totalpage);
		this.LoadDataFinish();
	}
	this.LoadDataFinish = function()
	{
		var hc = new Array();
		hc.push("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"dou_table\">");
		hc.push("<tr><td class=\"toptd\">币种/代码" + this.Arrow(0)+ "</td>");

		hc.push("<td class=\"toptd\"><a href=\"javascript:ForexListPage.DataSort(2)\">现价" + this.Arrow(2)+ "</a></td>");
		hc.push("<td class=\"toptd\"><a href=\"javascript:ForexListPage.DataSort(3)\">涨幅" + this.Arrow(3)+ "</a></td>");
		hc.push("<td class=\"toptd\"><a href=\"javascript:ForexListPage.DataSort(4)\">涨跌" + this.Arrow(4)+ "</a></td>");
		hc.push("<td class=\"toptd\"><a href=\"javascript:ForexListPage.DataSort(5)\">开盘" + this.Arrow(5)+ "</a></td>");
		hc.push("<td class=\"toptd\"><a href=\"javascript:ForexListPage.DataSort(6)\">最高" + this.Arrow(6)+ "</a></td>");
		hc.push("<td class=\"toptd\"><a href=\"javascript:ForexListPage.DataSort(7)\">最低" + this.Arrow(7)+ "</a></td>");
		hc.push("<td class=\"toptd\"><a href=\"javascript:ForexListPage.DataSort(8)\">振幅" + this.Arrow(8)+ "</a></td>");
		hc.push("<td class=\"toptd\"><a href=\"javascript:ForexListPage.DataSort(9)\">买价/卖价" + this.Arrow(9)+ "</a></td>");
		hc.push("<td class=\"toptd\">时间" + this.Arrow(10)+ "</td>");
		hc.push("<td class=\"toptdend\">走势图" + this.Arrow(11)+ "</td></tr>");
		
		for(var i=0;i < this.dataArray.length;i++){
			hc.push("<tr" + this.TrBgColor(i) + ">");
			hc.push("<td" + this.TdBgColor(i,0) + "><a href=\"http://quote.forex.hexun.com/" + this.dataArray[i][0] + ".shtml\" target=\"_blank\">" + this.dataArray[i][1] + "<br />" + this.dataArray[i][0] + "</a></td>");//币种/代码
			hc.push("<td" + this.TdBgColor(i,2) + ">" + this.dataArray[i][2].toFixed(4) + "</td>");//现价
			hc.push("<td" + this.TdBgColor(i,3) + ">" + Common.GetColor2DEC(this.dataArray[i][3],0) + "</td>");//涨幅
			hc.push("<td" + this.TdBgColor(i,4) + ">" + Common.GetColor4DEC(this.dataArray[i][4],0) + "</td>");//涨跌
			hc.push("<td" + this.TdBgColor(i,5) + ">" + this.dataArray[i][5].toFixed(4) + "</td>");//开盘
			hc.push("<td" + this.TdBgColor(i,6) + ">" + this.dataArray[i][6].toFixed(4) + "</td>");//最高
			hc.push("<td" + this.TdBgColor(i,7) + ">" + this.dataArray[i][7].toFixed(4) + "</td>");//最低
			hc.push("<td" + this.TdBgColor(i,8) + ">" + Common.GetColor2DEC(this.dataArray[i][8],0) + "</td>");//振幅
			hc.push("<td" + this.TdBgColor(i,9) + ">" + this.GetColor4DEC(this.dataArray[i][9],this.dataArray[i][5]) + "/" + this.GetColor4DEC(this.dataArray[i][10],this.dataArray[i][5]) + "</td>");//买价/卖价
			hc.push("<td>" + this.dataArray[i][11] + "</td>");//时间
			hc.push("<td class=\"tdend\"><a href=\"http://quote.forex.hexun.com/" + this.dataArray[i][0]+ ".shtml\" target=\"_blank\"><img src=\"/img/pic03.gif\" /></a></td></tr>");//走势图
		}
		
		hc.push("</table>");
		Common.$(this.divName).innerHTML = hc.join('');
		
		if(this.reload){
			clearTimeout(this.setTimeObj);
			this.setTimeObj = setTimeout(this.AutoReload,this.reloadTime);//按设置时间重读数据
		}
	}
	this.AutoReload = function(){
		ForexListRequest.Request();
	}
	this.ShowTime = function(time)
	{
		Common.$("topupdatetime").innerHTML = time;
		Common.$("updatetime").innerHTML = time;
	}
	this.ShowPage = function(page,total){
		Common.$("pagenum").innerHTML = page + "/" + total;
	}
	this.DataSort = function(column)
	{
		if(this.columnArray[column] == "down" || this.columnArray[column] == undefined)
		{
			this.columnArray[column] = "up";
			this.ArraySort(column,"up");
		}
		else
		{
			this.columnArray[column] = "down";
			this.ArraySort(column,"down");
		}
	}
	this.ArraySort = function(column,order)
	{
		if(order == "up"){
			this.dataArray.sort(function(a,b){ return b[column]-a[column]; });
		}
		if(order == "down"){
			this.dataArray.sort(function(a,b){ return a[column]-b[column]; });
		}
		this.currentColumn = column;
		this.LoadDataFinish();
	}
	this.TrBgColor = function(i)
	{
		if(i%2 == 0){
			return "";
		}else{
			return " bgcolor=\"#F7F7F7\"";
		}
		return "";
	}
	this.TdBgColor = function(i,column)
	{
		if(column == this.currentColumn){
			if(i%2 == 0){
				return " bgcolor=\"#FFF3EB\"";	
			}else{
				return " bgcolor=\"#F9ECE4\"";	
			}
		}
		return "";
	}
	this.Arrow = function(column)
	{
		if(column == this.currentColumn){
			if(this.columnArray[column] == "up"){
				return "<img src=\"/img/dot3.gif\" align=\"absmiddle\"/><img src=\"/img/dot2_2.gif\" align=\"absmiddle\" />";	
			}else{
				return "<img src=\"/img/dot1_1.gif\" align=\"absmiddle\"/><img src=\"/img/dot1_2.gif\" align=\"absmiddle\"/>";	
			}
		}
		return "";
	}
	
	this.GetColor4DEC = function(value,fiducial)
	{
		if(value == undefined){
			return "--";
		}
		if(value=="--")
		{
			return "--";
		}
		value=parseFloat(value);
		if(Number(value) == Number(fiducial)){
			return value.toFixed(4);
		}
		else if(Number(value) > Number(fiducial)){
			return "<span class=\"red\">" + value.toFixed(4) + "</span>";
		}
		else if(Number(value) < Number(fiducial)){
			return "<span class=\"green\">" + value.toFixed(4) + "</span>";
		}
		return value;
	}
}
