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))){
			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){
	 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 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 ImgSpan = document.getElementById('Image'+i);
		if(ImgSpan){
			if(Number(difference)<0){
				ImgSpan.src="../images/decrease.gif";
			}else if(Number(difference)>0){
				ImgSpan.src="../images/increase.gif";
			}else {
				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;
		}
	}
}

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";
	}
}
function showHK(){
	var topup = document.getElementById("topup");
	topup.src="stocksList.php?market=HK&news=yes";
}
function showSZ(){
    var topup = document.getElementById("topup");
	topup.src="stocksList.php?market=SZ&news=yes";
}
function showSH(){
	
    var topup = document.getElementById("topup");
	topup.src ="stocksList.php?market=SH&news=yes";
}
