var Cookie={
	set:function(b,d,a,e,c){if(typeof a=="undefined"){a=new Date(new Date().getTime()+1000*3600*24*30)}document.cookie=b+"="+escape(d)+((a)?"; expires="+a.toGMTString():"")+((e)?"; path="+e:"; path=/")+((c)?";domain="+c:"")},
	get:function(b){var a=document.cookie.match(new RegExp("(^| )"+b+"=([^;]*)(;|$)"));if(a!=null){return unescape(a[2])}return""},
	clear:function(a,c,b){if(this.get(a)){document.cookie=a+"="+((c)?"; path="+c:"; path=/")+((b)?"; domain="+b:"")+";expires=Fri, 02-Jan-1970 00:00:00 GMT"}}
};
var GetDataController=function(f){
	var d={};
	var c=0;
	var e=f;
	var b=new Model("script","js_top_load_box");
	var a="http://hq.sinajs.cn/rn="+b.stringMark+"&list="+e.params.toString();
	b.stringUrl=a;
	b.intInterval=e.refash?-1:5000;
	b.processData=function(){
		d={};
		for(var h=0,g=e.keys.length;h<g;h++){
			var j=e.keys[h];
			if(window[j]==undefined){
				continue
			}
			d[j]=window[j]
		}
		if(c<5){c++}
	};
	b.updateView=function(){
		if(e.callback){e.callback(d)}
		if(c>=5){b.intInterval=10000}
	};
	b.start();
	this.ChangeData=function(i,h){
		e.params=i;
		e.keys=h;
		var g="http://hq.sinajs.cn/rn="+b.stringMark+"&list="+e.params.toString();
		b.stringUrl=g;b.start()
	},
	this.Stop=function(){b.stop()}
};
var imgTime=new Date().getTime();
var imgRefashTime=1;
var imgPathObj={
	activeKey:"hq_str_s_sh000001",
	hq_str_s_sh000001:"http://image.sinajs.cn/newchart/small/nsh000001.gif",
	hq_str_s_sz399001:"http://image.sinajs.cn/newchart/small/nsz399001.gif",
	hq_str_s_sh000300:"http://image.sinajs.cn/newchart/small/nsh000300.gif",
	hq_str_b_NKY:"http://image.sinajs.cn/newchart/v5/forex/min5_m/NIXI.gif",
	hq_str_hf_GC:"http://image.sinajs.cn/newchart/v5/futures/global/mins/GC.gif",
	hq_str_hf_CL:"http://image.sinajs.cn/newchart/v5/futures/global/mins/CL.gif"
};
var stock_Active=Cookie.get("stockimg");
if(stock_Active!=""){
	imgPathObj.activeKey=stock_Active
}
var ChangeImg=function(){
	function a(e,d,f){
		var c=typeof e=="string"?document.getElementById(e):e;
		var b=c.cloneNode(true);
		b._A=c;
		b._y=typeof f!="undefined"?f:new Function();
		b[document.all?"onreadystatechange":"onload"]=function(){if(document.all&&this.readyState!="loaded"&&this.readyState!="complete"){return}this._A.parentNode.replaceChild(this,this._A);
		b._y(this);
		b._y=null;
		this._A=null;
		this[document.all?"onreadystatechange":"onload"]=null
	};
	b.src=d
}
a("js_newchart_img",imgPathObj[imgPathObj.activeKey]+"?"+imgTime)};
var ChangeImgKey=function(a){
	imgPathObj.activeKey=a;
	Cookie.set("stockimg",a);
	for(var c in imgPathObj){
		var b=document.getElementById(c);
		if(b){b.className=b.className.substr(0,3)}
	}
	document.getElementById(imgPathObj.activeKey).className+=" cur";
	ChangeImg()
};
ChangeImg();
var pageInit=function(){
	GetDataController({
					  params:["s_sh000001","s_sz399001","s_sh000300","b_NKY","hf_GC","hf_CL","sh000001"],
					  keys:["hq_str_s_sh000001","hq_str_s_sz399001","hq_str_s_sh000300","hq_str_hf_GC","hq_str_hf_CL","hq_str_sh000001"],
					  callback:function(m){
						  var f=document.getElementById("js_top_datatable");
						  var g="";
						  var h=new Date().getTime();
						  if((imgTime+1000*60*imgRefashTime)<h){imgTime=h;ChangeImg()};
						  tl=0;
						  for(var j in m){
							  tl++;
							  ts=tl%2;
							  var e=m[j].split(",");
							  var d=Number(e[2]).toFixed(2),c=e[3];
							  if(d>0){
								  d=(Number(e[2])>0?"+":"")+d;
								  c=(Number(e[3])>0?"+":"")+c+"%";
							  }else{
								  if(d==0){d="-";c="-"
							  }
						   }
						   if(j!="hq_str_hf_GC"&&j!="hq_str_hf_CL"&&j!="hq_str_sh000001"){
							   g+="<dl class='li"+ts+"' id='"+j+"' onclick=\"ChangeImgKey('"+j+"');\">";
							   g+="<dt>"+e[0]+"</a></dt>";
							   g+='<dd class="'+(Number(e[2])>0?"red":"green")+'">'+Number(e[1]).toFixed(2)+"</dd>";
							   g+='<dd class="'+(Number(e[2])>0?"red":"green")+'">'+d+"</dd>";
							   g+='<dd class="'+(Number(e[3])>0?"red":"green")+'">'+c+"</dd>";
							   g+="</dl>"
							}else{
								if(j=="hq_str_hf_GC"){
									var k=(e[1]/e[0]*100).toFixed(2);
									var i="";
									if(Number(e[7])>Number(e[0])){i="-"}
									else{if(Number(e[7])<Number(e[0])){i="+"}}
									var a=i=="+"?"red":"green";
									g+="<dl class='li"+ts+"' id='"+j+"' onclick=\"ChangeImgKey('"+j+"');\">";
									g+="<dt>\u9ec4\u91d1</a></dt>";
									g+='<dd class="'+a+'">'+Number(e[0]).toFixed(2)+"</dd>";
									g+='<dd class="'+a+'">'+i+Number(e[1]).toFixed(2)+"</dd>";
									g+='<dd class="'+a+'">'+i+k+"%</dd>";
									g+="</dl>"
								}else{
									if(j=="hq_str_hf_CL"){
										var k=(e[1]/e[0]*100).toFixed(2);
										var b="";
										if(Number(e[7])>Number(e[0])){b="-"}
										else{if(Number(e[7])<Number(e[0])){b="+"}}
										var a=b=="+"?"red":"green";
										g+="<dl class='li"+ts+"' id='"+j+"' onclick=\"ChangeImgKey('"+j+"');\">";
										g+="<dt>\u539f\u6cb9</a></dt>";
										g+='<dd class="'+a+'">'+Number(e[0]).toFixed(2)+"</dd>";
										g+='<dd class="'+a+'">'+b+Number(e[1]).toFixed(2)+"</dd>";
										g+='<dd class="'+a+'">'+b+k+"%</dd>";
										g+="</dl>"
									}else{
										if(j=="hq_str_sh000001"){
											document.getElementById("update_time").innerHTML=e[e.length-2]+" \u6570\u636e"
										}
									}
								}
							}
						}
						f.innerHTML="";
						f.innerHTML=g;
						document.getElementById(imgPathObj.activeKey).className+=" cur"
					}
				}
			)
};
pageInit();
var searchController;
var getCustomData=function(g,f){
	var li=6,tabboxhead='<table id="my_stock" cellspacing="1" cellpadding="0" border="0" width="100%"><tr class="tl"><th scope="col">\u6211\u7684\u81ea\u9009\u80a1</th><th scope="col">\u5f53\u524d\u4ef7</th><th scope="col">\u6da8\u8dcc\u5e45</th><th scope="col">\u6628\u6536</th><th scope="col">\u4eca\u5f00</th><th scope="col">\u6700\u9ad8/\u6700\u4f4e\u4ef7</th><th scope="col">\u4e70\u5165/\u5356\u51fa\u4ef7</th><th scope="col">\u5220</th></tr>';
	c+=tabboxhead;
	var b=[];
	for(var d=0,a=g.length;d<a;++d){
		var h="hq_str_"+g[d];
		b.push(h)
	}
	if(f){
		if(searchController){
			searchController.Stop()
		}
		searchController=undefined
	}
	if(searchController==undefined){
		if(b.length>0){
			searchController=new GetDataController({
												   params:g,
												   keys:b,
												   callback:function(v){
													   var p=document.getElementById("my_stock_list");
													   p.innerHTML="";
													   var q="";
													   q+=tabboxhead;
													   lis=li;
													   for(var s in v){
														   lis--;
														   if(v[s]!=""){
															   var n=v[s].split(",");
															   var k=(n[3]-n[2]);
															   var i=(k/Number(n[2])*100).toFixed(2);
															   var u=k>0?"red":"green";
															   if(k==0){u=""}var o="",m="",l="",j="";
															   if(n[1]>n[2]){o="green",m="red"}
															   else{
																   if(n[1]<n[2]){m="green",o="red"}
																}
																if(n[7]>n[6]){l="green",j="red"}
																else{
																	if(n[7]<n[6]){j="green",l="red"}
																}
																q+='<tr><td class="name"><a title="\u70b9\u51fb\u67e5\u770b\u8be6\u60c5" href="http://finance.sina.com.cn/realstock/company/'+s.substr(7,8)+'/nc.shtml" target="_blank">'+n[0]+"</a></td>";
																q+='<td class="'+u+'">'+((n[3]==0)?"-":n[3])+"</td>";
																q+='<td class="'+u+'">'+((n[3]==0)?"-":i+"%")+"</td>";
																//q+='<td class="'+u+'">'+((n[3]==0)?"-":k.toFixed(2))+"</td>";
																q+='<td class="'+o+'">'+n[2]+"</td>";
																q+='<td class="'+m+'">'+((n[3]==0)?"-":n[1])+"</td>";
																q+='<td><span class="red">'+((n[4]==0)?"-":n[4])+'</span>/<span class="green">'+((n[5]==0)?"-":n[5])+"</span></td>";
																q+='<td><span class="'+l+'">'+((n[6]==0)?"-":n[6])+'</span>/<span class="'+j+'">'+((n[7]==0)?"-":n[7])+"</span></td>";
																q+='<td><a href="javascript://" onclick="deleteMystock(this,\''+s.replace("hq_str_","")+'\');"><img alt="\u5220\u9664" src="stock/delete_s.gif"/></a></td></tr>'
															}else{
																var r=s.replace("hq_str_","");
																alert(r+"\u5df2\u6458\u724c\uff01");
																deleteStockCookie(r)
															}
														}
														if(lis>0)
															for(i=0;i<lis;i++)
																q+="<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
																q+="</table>";
																p.innerHTML=q
													}})}else{var e=document.getElementById("my_stock_list");e.innerHTML="";var c="";c+=tabboxhead;for(i=0;i<li;i++)c+="<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";c+="</table>";e.innerHTML=c}}else{searchController.ChangeData(g,b)}};var defaulf_Stock=["sz000002","sh600036","sh601318","sh601899"],clearStock=Cookie.get("nostock");var loadMystock=function(){var a=Cookie.get("stockdata");if(a!==""){getCustomData(a.split(","))}else{if(clearStock==""){Cookie.set("stockdata",defaulf_Stock);getCustomData(defaulf_Stock)}}};var onPress=function(a){if(a.keyCode==13){addMystock()}};var addMystock=function(d){var f=Cookie.get("stockdata"),v=document.getElementById("morlist").getElementsByTagName("tr");if(!d)d=(v.length>1?v[1].id.split(",")[3]:document.getElementById("stock_inp").value);var e=d;var b=e.indexOf("sh")||e.indexOf("sz");if(b==-1&&e.length!==8){alert("\u60a8\u6dfb\u52a0\u7684\u80a1\u7968\u4ee3\u7801\u4e0d\u6b63\u786e\uff01");return}if(f!=""){data=f.split(",")}else{data=[]}if(e==""){alert("\u8bf7\u8f93\u5165\u60a8\u8981\u6dfb\u52a0\u7684\u80a1\u7968\u4ee3\u7801\uff01");return}else{for(var c=0;c<data.length;c++){if(data[c]==e){alert("\u60a8\u5df2\u7ecf\u6dfb\u52a0\u8fc7\u6b64\u80a1\u7968\u3002");return}}if(data.length>5){document.getElementById("stock_inp").blur();alert("\u5bf9\u4e0d\u8d77\uff0c\u6700\u591a\u53ea\u80fd\u6dfb\u52a06\u4e2a\u81ea\u9009\u80a1\uff0c\u8bf7\u60a8\u5220\u9664\u73b0\u6709\u7684\u80a1\u7968\u518d\u6dfb\u52a0\uff01");return}}for(var c=0,a=data.length;c<a;c++){var d=data[c];if(data[c]==e){getCustomData(data);return}}data.push(e);Cookie.set("stockdata",data);getCustomData(data)};var deleteStockCookie=function(f){var e=Cookie.get("stockdata");if(e!=""){data=e.split(",")}else{data=[]}var b=-1;for(var c=0,a=data.length;c<a;c++){var d=data[c];if(data[c]==f){b=c;break}}if(b>-1){data.splice(b,1);Cookie.set("stockdata",data);getCustomData(data,true)}};var deleteMystock=function(e,g){var f=Cookie.get("stockdata");if(f!=""){data=f.split(",")}else{data=[]}if(data.length==1){Cookie.clear("stockdata");getCustomData([],true);return}var b=-1;for(var c=0,a=data.length;c<a;c++){var d=data[c];if(data[c]==g){b=c;break}}if(b>-1){data.splice(b,1);Cookie.set("stockdata",data);Cookie.set("nostock",1);getCustomData(data,true)}};loadMystock();
