//获取数据请求
CWQuoteRequest = new function(){
	this.scriptid ="CWQuoteRequest";
	this.url = "http://stockdata.stock.hexun.com/2008/DefaultDataOutput.aspx?ColumnId=5594";
	this.typeCode = "0";
	this.sortType = "7";

	this.CreateLink = function()
	{
		var request = this.url + "&";
		//request += "sortType=" + this.sortType + "&typeCode=" + this.typeCode + "&time=" + Common.Time();
		//不是行情数据 不需要加入时间参数 通过页面缓存提高速度
		request += "sortType=" + this.sortType + "&typeCode=" + this.typeCode;
		return request;
	}	
	this.Request = function()
	{
		Common.AppendDataArray(this.scriptid,this.CreateLink());
	}
	this.SetSorttype = function(st)
	{
		this.sortType = st;
		this.Request();
	}
}


//显示数据
CWListPage = new function(){
	this.dataArray;
	this.divName = "CWListDiv";
	this.columnArray = new Array();
	this.reloadTime = 300000;
	this.reload = true;
	this.setTimeObj;
	this.GetData = function(array,time)
	{
		this.currentColumn = CWQuoteRequest.sortType;
		this.dataArray = array;
		this.NewLoadDataFinish();
	}
	this.NewLoadDataFinish = function()
	{
		var columnName = this.GetColumnName(CWQuoteRequest.sortType);
		var hc = new Array();
		
		hc.push("<table width=\"125\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"box14\">");
		hc.push("<tr><td>排名</td><td>简称</td><td>"+ columnName +"</td></tr>");
		for(var i=0;i < this.dataArray.length;i++){
			hc.push("<tr>");
			hc.push("<td>" + (i+1) + "</td>");
			hc.push("<td><a href=\"http://stockdata.stock.hexun.com/" + this.dataArray[i][0] + ".shtml\" target=\"_blank\">" + this.dataArray[i][1] + "</a></td>");//名称
			if(this.dataArray[i][2] == null){
				hc.push("<td>--</td>");
			}else{
				var tmpValues = this.GetShowValues(this.dataArray[i][2]);
				hc.push("<td>" + tmpValues + "</td>");
			}
			hc.push("</tr>");
		}
		hc.push("</table>");
		Common.$(this.divName).innerHTML = hc.join('');
	}
	this.GetColumnName = function(st)
	{
		var cName = "";
		switch(st)
		{
			case "0":cName="流动资产";break;
			case "1":cName="流动负债";break;
			case "2":cName="长期负债";break;
			case "3":cName="负债合计";break;
			case "4":cName="股东权益";break;
			case "5":cName="资产合计";break;
			case "6":cName="净利润";break;
			case "7":cName="营业收入";break;
			case "8":cName="营业成本";break;
			case "9":cName="投资收益";break;
			default:cName="营业收入";break;
		}
		return cName;
	}
	this.GetShowValues = function(v)
	{
		//获得显示的值 万元 亿元
		var vw = v;
		var unit = "";
		var len = v.toFixed(0).length;
		
		if (len>=13)
		{
			vw = vw/1000000000000;
			unit = "万亿";
			return vw.toFixed(2) + unit;
		}
		
		if (len>=12)
		{
			vw = vw/100000000000;
			unit = "千亿";
			return vw.toFixed(2) + unit;
		}
		
		if (len>=11)
		{
			vw = vw/10000000000;
			unit = "百亿";
			return vw.toFixed(2) + unit;
		}
		
		if (len>=9)
		{
			vw = vw/100000000;
			unit = "亿";
			return vw.toFixed(2) + unit;
		}
		
		if (len>=8)
		{
			vw = vw/10000000;
			unit = "千万";
			return vw.toFixed(2) + unit;
		}
		
		if (len>=7)
		{
			vw = vw/1000000;
			unit = "百万";
			return vw.toFixed(2) + unit;
		}
		
		if (len>=5)
		{
			vw = vw/10000;
			unit = "万";
			return vw.toFixed(2) + unit;
		}
		
		return vw.toFixed(2) + unit;
	}
}

document.domain = "hexun.com"

/*财务评估新版Iframe显示*/
var FinanceEvaluate = new function()
{
	this.scriptid = "divPingguSCRIPT";
	
	this.code = "";
	
	this.divID = "divPinggu";
	
	this.url = "http://pinggu.stock.hexun.com/rest/StockIframeDisplayJS.aspx";
	
	this.IsHideIframe = function(flag)
	{
		if(flag) Common.$(this.divID).style.display = "block";
		else Common.$(this.divID).style.display = "none";
	}
	
	this.CreateLink = function()
	{
	   var request = this.url + "?";
		
	   if(this.code != "")
	   {
		  request += "code=" + this.code + "&";
	   }
	   
	   return request;
	}
	
	this.Request = function()
	{
		Common.AppendDataArray(this.scriptid,this.CreateLink());
	}
}

/*财务评估新版排行*/
var CWPGListPage = new function()
{
	this.scriptid = "divPingguRankSCRIPT";
	
	this.ftype = 1;
	
	this.divID = "divPingguRank";
	
	this.url = "http://pinggu.stock.hexun.com/rest/StocktotalTop5.ashx";
	
	this.GetDataFromTtype = function(type)
	{
		this.ftype = type;
		
		this.Request();
	}
	
	this.GetInfoFromType = function() 
	{
		var infos = [{name:"综合能力", index: 1, url : "http://pinggu.stock.hexun.com/stocktotal.aspx"},
					 {name:"盈利能力", index: 2, url : "http://pinggu.stock.hexun.com/StockProfit.aspx"},
					 {name:"偿债能力", index: 3, url : "http://pinggu.stock.hexun.com/StockDebt.aspx"},
					 {name:"成长能力", index: 4, url : "http://pinggu.stock.hexun.com/StockGrowth.aspx"},
					 {name:"资产经营", index: 5, url : "http://pinggu.stock.hexun.com/StockProperty.aspx"},
					 {name:"市场表现", index: 6, url : "http://pinggu.stock.hexun.com/StockShareholder.aspx"},
					 {name:"投资收益", index: 7, url : "http://pinggu.stock.hexun.com/StockInvest.aspx"}];
		
		for(var i = 0; i < infos.length; i++)
		{
			if(this.ftype == infos[i].index) return infos[i];
		}
		
		return infos[0];
	}
	
	this.GetData = function(dataArray, time)
	{
		if(dataArray.length == 0) return;
		
		var hc = new Array();
		
		var infos = this.GetInfoFromType();
		
		hc.push("<table width=\"125\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"box14\">");
		
		hc.push("<tr><td>排名</td><td>简称</td><td>" + infos.name + "</td></tr>");
		
		for(var i=0;i < dataArray.length;i++)
		{
			hc.push("<tr>");
			
			hc.push("<td>" + (i+1) + "</td>");
			
			hc.push("<td><a href=\"http://stockdata.stock.hexun.com/" + dataArray[i][1] + ".shtml\" target=\"_blank\">" + dataArray[i][0] + "</a></td>");//名称
			
			hc.push("<td><a href='" + infos.url + "?code=" + dataArray[i][1] + "' target=\"_blank\"><img src='/2008/img/cwpg2010.gif' border='0' /></a></td>");//名称	
			
			hc.push("</tr>");
		}
		
		hc.push("</table>");
		
		Common.$(this.divID).innerHTML = hc.join('');
	}
	
	this.CreateLink = function()
	{
	   var request = this.url + "?";
		
	   if(this.ftype != "")
	   {
		  request += "ftype=" + this.ftype;
	   }
	   
	   return request;
	}
	
	this.Request = function()
	{
		Common.AppendDataArray(this.scriptid,this.CreateLink());
	}
}

