/*
function:	导航我的设置基金股票提示
author:		xgcgh@yahoo.com.cn
date:		2008-11-03
*/
var v_fund_name =o('fund').value
var v_stock_name = o('stock').value
var display_ceng1;obj_value='',hang=0
function select2(stockcode){o(obj_value).value=stockcode}
function TrBgOn1(TrBgid,hang_){
if(hang>0&&hang<(max_hang+1)) TrBgOff(eval(o("tr"+hang)))
TrBgid.style.backgroundColor="#A2D1FF"
hang=hang_}
function TrBgOff(TrBgid){TrBgid.style.backgroundColor="#FFFFFF"}
function onkey(e){
display2(o(obj_value))
e = window.event||e;   
var code = e.keyCode || e.which;   
if(o("Layer").style.display=='block'){
	if(code==38){hang--}
	if(code==40){hang++}
	if(hang<0){hang=0}
	if(hang>max_hang){hang=max_hang}
	if(hang>0&&hang<(max_hang+1)){TrBgOn1(o("tr"+hang),hang)}
	if(code==13){
	if(hang>0&&hang<(max_hang+1)){select2(o("trs"+hang).innerHTML)}
	fundAdd(obj_value)
	o("Layer").style.display='none'}}
}
function xx(e){return event.x ? event.x : pageX}
function yy(e){return event.y ? event.y : pageY}
function display2(aa){
obj_value = aa.id
num=10
y=228
if(GetCookie('iden')){num=-17;if(isFF)num=-15}
y=(obj_value=='fund')?503:228;x=131;
//if(isIE){y=(obj_value=='fund')?462:228;x=131}
//else if(isFF){y=(obj_value=='fund')?462:228;x=131}
//if(isIE6){y-=3}
r = ( obj_value =='fund' )?fund_code:gp_code
//y = y+num
//alert(x+" "+y);
o("Layer").style.top=x+"px"
o("Layer").style.left=y+"px"
var val = aa.value
if(val!=''){
select_stock=new Array()
n=0
for(i=0;i<r.length;i++){
if(r[i][0].indexOf(val)!=-1||r[i][1].indexOf(val)==0||r[i][1].indexOf(val.toUpperCase())==0||r[i][2].indexOf(val)==0)
{n=n+1
select_stock.push(r[i])
if(n>12){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='17' align='center' style='background-color:#F1F1F3'><td width=50>代码</td><td width=50>拼音</td><td width=70>简称</td></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]+"')\" 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 style=\"position:absolute; visibility:inherit;border:0; top:0px; left:0px; width:200px; height:300px; z-index:-1; filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';\"></iframe>
o("Layer").innerHTML=str
if(o("Layer").style.display=='none'){o("Layer").style.display="block";hang=0}
}
else{o("Layer").style.display="none"}}}
function o(id){return document.getElementById(id)}
function getCode(code,t,mod){
	if( t=='fund' )	{
		for(i=0;i<fund_code.length;i++){
		if(fund_code[i][0].indexOf(code)==0||fund_code[i][1].indexOf(code)==0
			||fund_code[i][1].indexOf(code.toUpperCase())==0||fund_code[i][2].indexOf(code)==0)	return mod?fund_code[i][0]:fund_code[i][2]
		}
	}
	else{
	for(i=0;i<gp_code.length;i++)
	if(gp_code[i][0].indexOf(code)==0||gp_code[i][1].indexOf(code)==0||gp_code[i][1].indexOf(code.toUpperCase())==0
		||gp_code[i][2].indexOf(code)==0)	return mod?gp_code[i][0]:gp_code[i][2]
	}
	return 
}
function fundAdd(t){
var add_num=o('mySite').getElementsByTagName('li').length
if( add_num >=20 ){alert('定制个数不能超出最大值20个，您选的个数为'+add_num);return}
var code = o(t).value
if( !code ){alert('添加的内容不能为空!');return}
hz=0
if( code.charCodeAt(0)<255 && !/^[0-9]{6}$/.exec(code) ){alert('添加代码不正确...');return}
if( code.charCodeAt(0)>255 ) hz=1
var tt = getCode(code,t,hz)
if( !tt ){alert('添加的代码不存在!');return}
if( hz ){tmp=code;code=tt;tt=tmp}
if( t == 'fund'){
	ids='1'+code
	tname = '基金'
	hre='http://fund.zhicheng.com/fund_data/index/'+code+'.html'
}else{
	tname = '股票'
	ids='2'+code
	hre='http://stock.zhicheng.com/stock/realstock.php?code='+code
}
if( typeof(code_arrs[ids]) == 'object' ){alert('您添加的'+tname+'已经存在...');return}
var con = o('mySite').innerHTML;
o('mySite').innerHTML='<li id='+ids+'><a href='+hre+' target=_blank>'+tt+'</a>&nbsp;<a href="javascript:void(0)" onclick="dLink('+ids+',1)" title="删除"><img src="i/icon5.gif"/></a>'+con
add_num++
code_arrs[ids]=[ids+'^^'+tt]
try{
	setCookie({store:"cookie"},'code_str',ss(code_arrs))
}catch(e){}
setCookie('code_str',ss(code_arrs))
o(t).value=''
sDivCls(0)
o(obj_value).focus()
parentIf()}
function cValue(o){if( o.value.length>6 ) o.value=''}
function dLink(v,t){
	if( !confirm('您确定要删除吗?') ) return false
	if(t==1){add_num--;delete(code_arrs[v]);setCookie({store:"cookie"},'code_str',ss(code_arrs));setCookie('code_str',ss(code_arrs))}
	else{add_num2--;site_arrs[v]=null;delete(site_arrs[v]);setCookie({store:"cookie"},'site_str',ss(site_arrs));setCookie('site_str',ss(site_arrs))}
	obj=o(v);obj.parentNode.removeChild(obj);parentIf();
}
function blur(o){if(!display_ceng1)o('Layer').style.display='none'}
function sDivCls(t){
if(t){n='';display_ceng1=true}
else {
	n='none';display_ceng1=false;
	//if(!o('fund').value) o('fund').value=v_fund_name
	//if(!o('stock').value) o('stock').value=v_stock_name
}
o('Layer').style.display=n
}
function getLottery(str){
	add_num=0
	var arr=eval(str),temp_arrs=[]
	for( key in code_arrs ){if( key.indexOf('otter')==-1){temp_arrs[key]=code_arrs[key];add_num++}}
	//alert(ss(temp_arrs));
	code_arrs = temp_arrs;
	for(i in arr){
		if(add_num >=20) break;add_num ++
		code_arrs[arr[i]['number']]=[arr[i]['number']]
	}
	setCookie({store:"cookie"},'code_str',ss(code_arrs));
	setCookie('code_str',ss(code_arrs));mySite();parentIf()
}
function getFund(str){
	add_num=0
	var arr=eval(str),temp_arrs=[]
	for( key in code_arrs){if( key.substr(0,1)!=1){temp_arrs[key]=code_arrs[key];add_num++}}
	code_arrs = temp_arrs
	for(i in arr){
		if(add_num >=20) break;add_num ++
		code_arrs['1'+arr[i]['number']]=['1'+arr[i]['number']+'^^'+arr[i]['name']]
	}
	setCookie({store:"cookie"},'code_str',ss(code_arrs));
	setCookie('code_str',ss(code_arrs));mySite();parentIf()
}
//regEvent(o('link'),"onkeyup",keyC)
regEvent(o('stock'),"onkeyup",onkey)
regEvent(o('fund'),"onkeyup",onkey)