//获取A股行情数据请求
HSQuoteRequest = new function(){
	this.scriptid ="HSQuoteRequest";
	this.url = "http://quote.stock.hexun.com/rest1/sd_new_quote.aspx?type=2&count=10";
	this.market = "1";
	this.sorttype = "3";
	this.updown = "up";

	this.CreateLink = function()
	{
		var request = this.url + "&";
		request += "sorttype=" + this.sorttype + "&market=" + this.market + "&updown=" + this.updown + "&time=" + Common.Time();
		return request;
	}	
	this.Request = function()
	{
		Common.AppendDataArray(this.scriptid,this.CreateLink());
	}
	this.SetSorttype = function(st)
	{
		if(st=="6")
		{
			this.sorttype = "2";
			this.updown = "up";
		}
		else if (st=="7")
		{
			this.sorttype = "2";
			this.updown = "down";
		}
		else
		{
			this.sorttype = st;
			this.updown = "up";
		}
		this.Request();
	}
	this.SetMarket = function(market,id,num,count)
	{
		for(i=1;i<=count;i++)
		{
			Common.$("tagname_" + id + i).className = "labelb";
		}
		
		Common.$("tagname_" + id + num).className = "labela";
		
		this.market = market;
		this.Request();
	}
}


//显示数据
HSQuotePage = new function(){
	this.dataArray;
	this.currentColumn;
	this.divName = "HSQuoteDiv";
	this.columnArray = new Array();
	this.reloadTime = 30000;
	this.reload = true;
	this.setTimeObj;
	this.GetData = function(array,total,time)
	{
		this.currentColumn = HSQuoteRequest.sorttype;
		this.dataArray = array;
		this.NewLoadDataFinish();
	}
	this.NewLoadDataFinish = function()
	{
		var columnIndex = Number(HSQuoteRequest.sorttype);
		var columnName = this.GetColumnName(HSQuoteRequest.sorttype);
		
		var qUrl = "http://quote.hexun.com/stock/SS_Ashare.html";
		
		if (HSQuoteRequest.market=="1")
			qUrl = "http://quote.hexun.com/stock/SH_Ashare.html";
		
		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><a href=\""+ qUrl +"\" target=\"_blank\">"+ columnName +"</a></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] == 0 && this.dataArray[i][8] == 0 && this.dataArray[i][9]==0){
				hc.push("<td>--</td>");
			}else{
			  var tmpV = this.GetShowValues(this.dataArray[i][columnIndex]);
				hc.push("<td>" + tmpV + "</td>");
			}
			hc.push("</tr>");
		}
		hc.push("</table>");
		Common.$(this.divName).innerHTML = hc.join('');
	}
	this.GetColumnName = function(st)
	{
		var cName = "";
		switch(st)
		{
			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;
			case "10":cName="换手率";break;
			case "11":cName="振幅";break;
			case "12":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;
	}
}
