String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
function isAlphameric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}
function verify_stockinputform_form()
{

	if(document.getElementById("IDStock").value=="")
	{
		alert("股票代号码不能为空");
		return false;
	}
	else if(!isAlphameric(document.getElementById("IDStock").value.trim())){
		alert("股票代号码无效");
		return false;
	}
	else if (document.stockinputform.cs_submit) document.stockinputform.cs_submit.disabled=true;
	location.href = './?IDStock='+document.stockinputform.IDStock.value;
	return true;
}
function $(objName){
	if(document.getElementById){
		return document.getElementById(objName);
	}else{
		return document.all.objName;
	}
};
function searchShareholding(idstock)
{
	//idstock=trim(idstock);
	 if(idstock=="")
	 {
	     alert("股票代号码不能为空");
		 return false;
	 }
	document.Shareholding_form.txt_stock_code.value=idstock;
	document.Shareholding_form.submit();
}
function StringToDate(DateStr)
{

     var converted = Date.parse(DateStr);
     var myDate = new Date(converted);
     if (isNaN(myDate))
     {
         //var delimCahar = DateStr.indexOf('/')!=-1?'/':'-';
         var arys= DateStr.split('-');
         myDate = new Date(arys[0],--arys[1],arys[2]);
     }
     return myDate;
}
function daysBetween(DateOne,DateTwo)
{
     var cha=((Date.parse(DateOne)- Date.parse(DateTwo))/86400000);
     return Math.abs(cha);
}

function showNew(whate,len)
{
	var now=Date();
	for(i=0;i<len;i++)
	{
    	if($(whate+i)){
			var whatelink=($(whate+i).href).split("/");
			var datestringh=whatelink[whatelink.length-2].substring(4,6)+"-"+whatelink[whatelink.length-1].substring(0,2);//eg.06-26
			var datestring=whatelink[whatelink.length-2].substring(0,4)+"/"+datestringh;
			var date = StringToDate(datestring);
			if(daysBetween(date,now)<4)
			$(whate+"New"+i).innerHTML="  <img src=\"images/in_new.gif\"/> ";
			$(whate+"date"+i).innerHTML=""+datestringh;
		}
	}
}
function index() {
	var count=10;
	showNew("dapan",10);
	showNew("heima",10);
	showNew("gegu",10);
	showNew("chuanwen",10);
	showNew("knows",10);
	showNew("stocknews",10);
}

var xmlHttp;
function fleshImg(){
	var img = document.getElementById('img0');
	if(img) img.src = 'http://baidu.hexun.com/stock/images/index_1_HSI001.png?'+Math.random();
	var img = document.getElementById('img1');
	if(img) img.src = 'http://baidu.hexun.com/stock/images/index_1_CCI001.png?'+Math.random();
	var img = document.getElementById('img2');
	if(img) img.src = 'http://baidu.hexun.com/stock/images/index_1_CEI001.png?'+Math.random();
	var img = document.getElementById('img3');
	if(img) img.src = 'http://baidu.hexun.com/stock/images/index_1_000001.png?'+Math.random();
}
function request(){
	try{
		 xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		 try{
			   xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		 }catch(e2){
			  xmlHttp=new XMLHttpRequest();
		 }
	}
	if(xmlHttp){
		var url = "i.php";
		xmlHttp.open("GET", url);
		xmlHttp.onreadystatechange = receive;
		xmlHttp.send(null);
    }
}
function receive(){
	if(xmlHttp.readyState==4 && xmlHttp.status==200){
		handle();
	}
}
function handle(){
	var response = xmlHttp.responseXML.documentElement;
	var numArray = response.getElementsByTagName("num");
	var differenceArray = response.getElementsByTagName("difference");
	var percentArray = response.getElementsByTagName("percent");
	var colorArray = response.getElementsByTagName("color");
	var closeArray = response.getElementsByTagName("close");
	var openArray = response.getElementsByTagName("open");
	var timeArray = response.getElementsByTagName("time");
	for(var i=0;i<numArray.length;i++){
		var color = colorArray.item(i).firstChild.data.toString();
		var num = numArray.item(i).firstChild.data.toString();
		var numSpan = document.getElementById('num'+i);
		if(numSpan){
			numSpan.style.color = color;
			numSpan.innerHTML = num;
		}
		var difference = differenceArray.item(i).firstChild.data.toString();
		//var HSSpan = document.getElementById('HS'+i);
		var ImgSpan = document.getElementById('Image'+i);
		if(ImgSpan){
			if(Number(difference)<0){
			//	HSSpan.src="../images/down.gif";
				ImgSpan.src="../images/decrease.gif";
			}else if(Number(difference)>0){
			//	HSSpan.src="../images/up.gif";
				ImgSpan.src="../images/increase.gif";
			}else {
			//	HSSpan.src="../images/flat.gif";
				ImgSpan.src="../images/steady.gif";
			}
		}
		var differenceSpan = document.getElementById('difference'+i);
		if(differenceSpan){
		differenceSpan.style.color = color;
		differenceSpan.innerHTML = difference;
		}
		var percent = percentArray.item(i).firstChild.data.toString();
		var percentSpan = document.getElementById('percent'+i);
		if(percentSpan){
		percentSpan.style.color = color;
		percentSpan.innerHTML = percent;
		}
		var close = closeArray.item(i).firstChild.data.toString();
		var closeSpan = document.getElementById('close'+i);
		if(closeSpan){
		closeSpan.innerHTML = close;
		}
		var open = openArray.item(i).firstChild.data.toString();
		var openSpan = document.getElementById('open'+i);
		if(openSpan){
		openSpan.innerHTML = open;
		}
		var time = timeArray.item(i).firstChild.data.toString();

		var timeSpan = document.getElementById('time'+i);
		if(timeSpan){
		timeSpan.innerHTML = time;
		}
	}
}
var t;
function setniuyueTime()
{
	var date = new Date();
    date=new Date(date.getTime()-43200000);//12*60*60*1000
	var year = date.getYear();
    if(year*1<2000)
    	year += 1900;
	nowtime.innerHTML=year+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日 "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
	t=setTimeout("setniuyueTime()",1000);
}
function setlocalTime()
{
	var date = new Date();
   //  if(city=="beijing")
    var year = date.getYear();
    if(year*1<2000)//navigator.userAgent.indexOf("Firefox")>0
    	year += 1900;
	nowtime.innerHTML=year+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日 "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
	t=setTimeout("setlocalTime()",1000);
}
function showtime(city)
{
	clearTimeout(t);
	if(city=="niuyue")
	{
	    setniuyueTime();
	}
	else
	{
	   setlocalTime();
	}
}
window.setInterval(request,1000*60*10);
window.setInterval(fleshImg,10000);

function checkFormTarget(){
    if(document.all.mailLogin){
		if(document.all.mailLogin.checked){
			document.all.form.target="_blank";
		}else{
			document.all.form.target="_parent";
		}
		return true;
	}
}


function show(a){

		for(var i=1;i<4;i++){
			document.getElementById(i).style.display="none";
		}
		document.getElementById(a).style.display="block";
	}

	function showTopDown(){
		var downFrame = document.getElementById("topdown");
		downFrame.src = "share/stock/showTopDown.php";

	}

	function showTopUp(){
		var upFrame = document.getElementById("topup");
		upFrame.src = "share/stock/showTopUp.php";
	}

function showZhiShu(a){
		var arr = a.split(",");
		for(var i=0;i<9;i++){
			document.getElementById("tu"+i).style.display="none";
		}

		for(var i=0;i<arr.length;i++){
			document.getElementById("tu"+arr[i]).style.display="block";
		}

	}
