﻿var display_ceng1;

function select2(stockcode){
  getElement("StockCode").value=stockcode;
}

function TrBgOn1(TrBgid,hang_){
  if(hang>0&&hang<(max_hang+1))TrBgOff(eval(getElement("tr"+hang)));	
  TrBgid.style.backgroundColor="#A2D1FF";
  hang=hang_;
  select2(select_stock[hang-1][0]);
}
function TrBgOn2(TrBgid,hang_){
  if(hang>0&&hang<(max_hang+1))TrBgOff(eval(getElement("tr"+hang)));	
  TrBgid.style.backgroundColor="#A2D1FF";
  hang=hang_;
  select2(select_stock[hang-1][0]);
}

function TrBgOff(TrBgid){	
  TrBgid.style.backgroundColor="#FFFFFF";
}

function onkeyupdown()
{
   var event = window.event;
   if(getElement("Layer2").style.display=='block')
   {
   	if(event.keyCode==38){hang--;}
    if(event.keyCode==40){hang++;}
    if(hang<0){hang=0;}
    if(hang>max_hang){hang=max_hang;}
    if(hang>0&&hang<(max_hang+1) && (event.keyCode==38 || event.keyCode==40)){TrBgOn2(eval(getElement("tr"+hang)),hang);}
    if(event.keyCode==13)
    {
    	if(hang>0&&hang<(max_hang+1)){select2(eval(getElement("trs"+hang).innerHTML));}
	    getElement("Layer2").style.display='none';
	  }
   }
}

function display2(aa){
if(aa.value!=''){
select_stock=new Array()
n=0;
for(i=0;i<r.length;i++)
{
if(r[i][0].indexOf(aa.value)==0||r[i][1].indexOf(aa.value)==0||r[i][2].indexOf(aa.value)==0)
{n=n+1;
select_stock.push(r[i])
if(n>9){break;}
}
}
max_hang=select_stock.length;
	if(select_stock.length>0){
	str="<table width='100%' border='0' cellspacing='0' cellpadding='0' id='tanchukuang'>";
	str=str+"<tr height='20' align='center' style='background-color:#F1F1F3'>";
	str=str+"<td width=50>代码</td>";
	str=str+"<td width=50>拼音</td>";
	str=str+"<td width=70>简称</td>";
	str=str+"</tr>";
	for(i=0;i<max_hang;i++)
	{
	str=str+"<tr id=tr"+(i+1)+" align='center' onMouseOver='TrBgOn1(this,"+(i+1)+");' onMouseOut='TrBgOff(this);' onclick=\"select2('"+select_stock[i][0]+"')\" onmousedown=\"select2('"+select_stock[i][0]+"')\" class='hand1'>";
	str=str+"<td><div id=trs"+(i+1)+">"+select_stock[i][0]+"</div></td>";
	str=str+"<td>"+select_stock[i][1]+"</td>";
	str=str+"<td>"+select_stock[i][2]+"</td>";
	str=str+"</tr>";
	}
	str=str+"</table><iframe src=\"javascript:false\" style=\"position:absolute; visibility:inherit;border:0; top:0px; left:0px; width:200px; height:200px; z-index:-1; filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';\"></iframe>";
	
	getElement("Layer2").innerHTML=str;
	if(getElement("Layer2").style.display=='none'){
	getElement("Layer2").style.display="block";
	hang=0;}
	}
	else
	{getElement("Layer2").style.display="none";}
}
}

function quotesearch(aa)
{
	if(aa!='')
	{
		select_stock=new Array()
		n=0;
		for(i=0;i<r.length;i++)
		{
			if(r[i][0].indexOf(aa)>-1||r[i][1].indexOf(aa)>-1||r[i][2].indexOf(aa)>-1)
			{
				n=n+1;
				select_stock.push(r[i])
			}
		}
		var maxhang=select_stock.length;
		if(select_stock.length>0)
		{
			str="<table width='1000' border='0' cellspacing='1' cellpadding='0' align='center' bgcolor='#CCCCCC'>";
			str=str+"<tr><td width=20% height=25 bgcolor=#efefef>&nbsp;</td><td colspan=3 bgcolor=#efefef>&nbsp;根据您输入的关键字'<font color=red><b>"+aa+"</b></font>'智能查询结果如下：(共<font color=red>"+maxhang+"</font>条  点击链接可查看实时行情)</td><td width=20% height=25 bgcolor=#efefef>&nbsp;</td></tr>";
			for(i=0;i<maxhang;i++)
			{
				str=str+"<tr><td width=20% height=20 bgcolor=#efefef>&nbsp;</td>";
				str=str+"<td width=20% height=22 bgcolor=#FFFFFF>&nbsp;股票代码：<a href=http://quote.eastmoney.com/"+select_stock[i][0]+".html class=link2 target=_blank>"+select_stock[i][0].replace(aa,'<font color=red><b>'+aa+'</b></font>')+"</a></td>";
				str=str+"<td width=20% height=20 bgcolor=#FFFFFF>&nbsp;股票名称：<a href=http://quote.eastmoney.com/"+select_stock[i][0]+".html class=link2 target=_blank>"+select_stock[i][2].replace(aa,'<font color=red><b>'+aa+'</b></font>')+"</a></td>";
				str=str+"<td width=20% height=20 bgcolor=#FFFFFF>&nbsp;拼音简称：<a href=http://quote.eastmoney.com/"+select_stock[i][0]+".html class=link2 target=_blank>"+select_stock[i][1].replace(aa,'<font color=red><b>'+aa+'</b></font>')+"</a></td>";
				str=str+"<td width=20% height=20 bgcolor=#efefef>&nbsp;</td></tr>";
			}
			if (maxhang<10)
			{
				for(j=0;j<10-maxhang;j++)
				{str=str+"<tr><td width=20% height=20 bgcolor=#efefef>&nbsp;</td><td width=20% height=20 bgcolor=#FFFFFF>&nbsp;</td><td width=20% height=20 bgcolor=#FFFFFF>&nbsp;</td><td width=20% height=20 bgcolor=#FFFFFF>&nbsp;</td><td width=20% height=20 bgcolor=#efefef>&nbsp;</td></tr>";}
			}
			str=str+"</table>";
		}
		else
		{
			str="<table width='1000' border='0' cellspacing='1' cellpadding='0' align='center' bgcolor='#CCCCCC'><tr><td width=20% height=30 bgcolor=#efefef>&nbsp;</td><td colspan=3 bgcolor=#efefef style='font-size:15px'>&nbsp;搜索结果如下：</font></td><td width=20% height=25 bgcolor=#efefef>&nbsp;</td></tr>";
			str=str+"<tr><td width=18% bgcolor=#efefef>&nbsp;</td><td width=64% bgcolor=#FFFFFF colspan=3 style=\"height:220px;text-align:center;\"><div style=\"padding-left:5px;font-size:14px;\">没有找到 <font color=red><b>"+aa+"</b></font> 相关的股票信息。请重新搜索或<a href=\"stocklist.html\" target=\"_blank\"><font color=red>点此显示所有股票</font></a></div></td><td width=18% bgcolor=#efefef>&nbsp;</td></tr>";
			str=str+"</table>";	
		}
		getElement("quotesearch").innerHTML=str;	
	}
}

function quotesearchno()
{
	getElement("quotesearch").innerHTML="<div style=\"height:220px;text-align:center;color:#f00;\">数据读取中，请稍候。</div>";
	str="<ul>";
	for(li=0;li<r.length;li++)
	{
		str=str+"<li><a href=\"http://quote.eastmoney.com/"+r[li][0]+".html\" target=\"_blank\">"+r[li][2]+"("+r[li][0]+")</a></li>";
	}
	str=str+"</ul>";
	getElement("quotesearch").innerHTML=str;	
}

function getElement(id) {
	return document.getElementById(id);
}