//获取数据请求
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 = 30000;
	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;
	}
}

