if (document.implementation && document.implementation.createDocument){
	var xdoc = document.implementation.createDocument("","",null);
	xdoc.onload=function(){
		make_option();
	}
}else if (window.ActiveXObject){
	var xdoc = new ActiveXObject("Microsoft.XMLDOM");
	xdoc.onreadystatechange=function(){
		if(xdoc.readyState==4){
			make_option();
		}
	}
}
var key = 0; // 初始化key的状态
var disp='none';
function ifselect(o,e){
	//alert(e.keyCode);
	disp='none';
	if(o.value.length>6){
		if((key == 1) && (e.keyCode==13)){ // 判断如果已经将代码放入input框中后，再按回车就将股票代码得到并返回下拉框状态
			var stock_arr = new Array();
			stock_arr = o.value.split(" ");
			o.value = stock_arr[0];
		}else{
			o.value='';
			document.getElementById("pannel").style.display='none';
			document.getElementById("code").focus();
			return;
		}
	}	
	if(o.value.length>1&&((e.keyCode==13)||(e.keyCode==40))){
		disp='block';
	}else{
		var pat=/^\w{6}$/;
		if(pat.test(o.value)){
			disp='block';			
		}
	}
	document.getElementById("pannel").style.display=disp;
	if(disp=='block'){
		xdoc.load("stock_info_query/?needle="+o.value);	
		document.getElementById("code_selector").focus();
	}
}

function make_option(){
	var rs=xdoc.getElementsByTagName('stock');
	var ocs=document.getElementById("code_selector");
	ocs.options.length=0;
	if(rs.length==0){
		disp='none';
		document.getElementById("pannel").style.display=disp;
		return;
	}
	var ds,c,n,op;
	for(var i=0; i<rs.length; i++){
		c=rs[i].attributes.getNamedItem("code").text;
		n=rs[i].attributes.getNamedItem("name").text;
		/*
		if(i==0) op=new Option(c+' '+n,c,false,true);
		else op=new Option(c+' '+n,c,false,false);
		*/
		// zyj修改上面的注销改成下面这两行，上面的方式，最后在input中只显示代码，下面的方式代码和名称都显示
		if(i==0) op=new Option(c+' '+n,c+' '+n,false,true);
		else op=new Option(c+' '+n,c+' '+n,false,false);
		ocs.options[i]=op;
	}
}
// 用回车将下拉框中的股票放到input中
function set_input(o,e){
	if(e.keyCode==13){
		key = 1; // 当第一次按下回车将下拉框中的代码放入input中时记录key的状态
		document.getElementById("code").value=o.value;
		document.getElementById("pannel").style.display='none';
		//document.getElementById("code").select();
		document.getElementById("code").focus();
		return;
	}
}
// 用双击鼠标将下拉框中的股票放到input中
function set_input2(o){
	document.getElementById("code").value=o.value;
	document.getElementById("pannel").style.display='none';
	//document.getElementById("code").select();
	document.getElementById("code").focus();
	return;
}

// 鼠标单击股票输入框时
function c_select(item){
	item.select();
}

// 将input中的股票提交
function step_gegu(type){
	var item = document.getElementById("code").value;
	var stock_arr = item.split(" ");
	var code = stock_arr[0];
	if(!code.match(/^\w{6}$/)){	
		alert("请输入规范的股票代码");
		return false;
	}else{
		if(type == 'zl'){
			window.open("/modules.php?name=news_gegu&stock="+code+"", "", "");
		}else if(type == 'xw'){
			window.open("/modules.php?name=news_gegu&op=block&type=1&stock="+code+"&news=1", "", "");
		}else if(type == 'gg'){
			window.open("/modules.php?name=news_gegu&op=block&type=2&stock="+code+"&news=1", "", "");
		}else if(type == 'pl'){
			window.open("/modules.php?name=news_gegu&op=block&type=0&stock="+code+"&news=1", "", "");
		}else if(type == 'hq'){
			window.open("http://jr.hztop.com/news/searchHQ.asp?lx=feshi&code="+code+"", "_blank", "width=210,height=390,toolbar=no,menubar=no,scrollbar=no,resizable=no,location=no,status=no,titlebar=no");
		}else{
			window.open("/modules.php?name=news_gegu&stock="+code+"", "", "");
		}
	}
}
function step_gegu_old(type){
	var item = document.getElementById("code").value;
	var stock_arr = item.split(" ");
	var code = stock_arr[0];
	if(!code.match(/^\w{6}$/)){	
		alert("请输入规范的股票代码");
		return false;
	}else{
		if(type == 'zl'){
			window.open("/modules.php?name=news_gegu&stock="+code+"", "", "");
		}else if(type == 'xw'){
			window.open("/modules.php?name=news_gegu&op=block&type=1&stock="+code+"&news=1", "", "");
		}else if(type == 'gg'){
			window.open("/modules.php?name=news_gegu&op=block&type=2&stock="+code+"&news=1", "", "");
		}else if(type == 'pl'){
			window.open("/modules.php?name=news_gegu&op=block&type=0&stock="+code+"&news=1", "", "");
		}else if(type == 'hq'){
			window.open("/news/searchHQ.asp?lx=feshi&code="+code+"", "_blank", "width=210,height=390,toolbar=no,menubar=no,scrollbar=no,resizable=no,location=no,status=no,titlebar=no");
		}else{
			window.open("/modules.php?name=news_gegu&stock="+code+"", "", "");
		}
	}
}
