//改函数将从指定的 URL 装载 XML 文档，在装载完毕时，
//把该文档和 URL 传递给指定的处理函数。（任何 XML 文档都可以使用该函数）
function load() {
	var url = "images/homepage/hqsj.xml";
	var handler = fuzhi;
	// 如果它受支持，则采用标准的 2 级 DOM 技术
	if(document.implementation && document.implementation.createDocument){
		// 创建新的 Document 对象
		var xmldoc = document.implementation.createDocument("", "", null);
		// 设置装载完毕时发生的情况
		xmldoc.onload = function(){ handler(xmldoc); }
		// 告诉它装载什么 URL
		xmldoc.load(url);
	}else if(window.ActiveXObject){  // 否则，用Microsoft 公司专有的用于 Internet Explorer 的 API
		var xmldoc=new ActiveXObject("Microsoft.XMLDOM"); // 创建文档
		xmldoc.onreadystatechange = function() {  // 设置 onload
			if(xmldoc.readyState == 4) handler(xmldoc);
		}
		xmldoc.load(url);  // 开始装载
	}
}
// 显示2个主要行情的基本数据
function fuzhi(xmldoc){
	var ms=xmldoc.getElementsByTagName('Record');
	for(var i=0; i<ms.length; i++){
		var cs=ms[i].getElementsByTagName('Item');
		var f_10, f_199112, f_19, f_6, f_38, f_37, f_39;
		if(cs[0].getElementsByTagName('Value')[0].firstChild.data == '1A0001'){
			f_10 = f_199112 = f_19 = f_6 = f_38 = f_37 = f_39 = '';
			for(var j=0; j<cs.length; j++){
				if(cs[j].getAttribute('Id')=='10'){
					if(cs[j].getElementsByTagName('Value')[0].firstChild != null){
						f_10 = cs[j].getElementsByTagName('Value')[0].firstChild.data;
					}
				}
				if(cs[j].getAttribute('Id')=='199112'){
					if(cs[j].getElementsByTagName('Value')[0].firstChild != null){
						f_199112 = cs[j].getElementsByTagName('Value')[0].firstChild.data;
					}
				}
				if(cs[j].getAttribute('Id')=='19'){
					if(cs[j].getElementsByTagName('Value')[0].firstChild != null){
						f_19 = cs[j].getElementsByTagName('Value')[0].firstChild.data;
					}
				}
				if(cs[j].getAttribute('Id')=='6'){
					if(cs[j].getElementsByTagName('Value')[0].firstChild != null){
						f_6 = cs[j].getElementsByTagName('Value')[0].firstChild.data;
					}
				}
				if(cs[j].getAttribute('Id')=='38'){
					if(cs[j].getElementsByTagName('Value')[0].firstChild != null){
						f_38 = cs[j].getElementsByTagName('Value')[0].firstChild.data;
					}
				}
				if(cs[j].getAttribute('Id')=='37'){
					if(cs[j].getElementsByTagName('Value')[0].firstChild != null){
						f_37 = cs[j].getElementsByTagName('Value')[0].firstChild.data;
						if(f_37 < 0) f_37 = 0;
					}
				}
				if(cs[j].getAttribute('Id')=='39'){
					if(cs[j].getElementsByTagName('Value')[0].firstChild != null){
						f_39 = cs[j].getElementsByTagName('Value')[0].firstChild.data;
					}
				}
				if(f_10 > f_6){
					zs_1.innerHTML = '<font color=red>'+f_10+'</font>'; 
				}else{
					zs_1.innerHTML = '<font color=green>'+f_10+'</font>';
				}
				if(f_199112 > 0){
					zf_1.innerHTML = '<font color=red>'+f_199112+'%</font>'; 
				}else{
					zf_1.innerHTML = '<font color=green>'+f_199112+'%</font>';
				}
				je_1.innerHTML = '<font color=#000000>'+Math.round(f_19/1000000)/100+'亿</font>';
				sz_1.innerHTML = '<font color=red>'+f_38+'</font>';
				f_pp = (f_37-f_38-f_39 > 0)? f_37-f_38-f_39 : 0; 
				pp_1.innerHTML = '<font color=#000000>'+f_pp+'</font>';
				xd_1.innerHTML = '<font color=green>'+f_39+'</font>';
			}			
		}else if(cs[0].getElementsByTagName('Value')[0].firstChild.data == '399001'){
			f_10 = f_199112 = f_19 = f_6 = f_38 = f_37 = f_39 = '';
			for(var j=0; j<cs.length; j++){
				if(cs[j].getAttribute('Id')=='10'){
					if(cs[j].getElementsByTagName('Value')[0].firstChild != null){
						f_10 = cs[j].getElementsByTagName('Value')[0].firstChild.data;
					}
				}
				if(cs[j].getAttribute('Id')=='199112'){
					if(cs[j].getElementsByTagName('Value')[0].firstChild != null){
						f_199112 = cs[j].getElementsByTagName('Value')[0].firstChild.data;
					}
				}
				if(cs[j].getAttribute('Id')=='19'){
					if(cs[j].getElementsByTagName('Value')[0].firstChild != null){
						f_19 = cs[j].getElementsByTagName('Value')[0].firstChild.data;
					}
				}
				if(cs[j].getAttribute('Id')=='6'){
					if(cs[j].getElementsByTagName('Value')[0].firstChild != null){
						f_6 = cs[j].getElementsByTagName('Value')[0].firstChild.data;
					}
				}
				if(cs[j].getAttribute('Id')=='38'){
					if(cs[j].getElementsByTagName('Value')[0].firstChild != null){
						f_38 = cs[j].getElementsByTagName('Value')[0].firstChild.data;
					}
				}
				if(cs[j].getAttribute('Id')=='37'){
					if(cs[j].getElementsByTagName('Value')[0].firstChild != null){
						f_37 = cs[j].getElementsByTagName('Value')[0].firstChild.data;
						if(f_37 < 0) f_37 = 0;
					}
				}
				if(cs[j].getAttribute('Id')=='39'){
					if(cs[j].getElementsByTagName('Value')[0].firstChild != null){
						f_39 = cs[j].getElementsByTagName('Value')[0].firstChild.data;
					}
				}
				if(f_10 > f_6){
					zs_2.innerHTML = '<font color=red>'+f_10+'</font>'; 
				}else{
					zs_2.innerHTML = '<font color=green>'+f_10+'</font>';
				}
				if(f_199112 > 0){
					zf_2.innerHTML = '<font color=red>'+f_199112+'%</font>'; 
				}else{
					zf_2.innerHTML = '<font color=green>'+f_199112+'%</font>';
				}
				je_2.innerHTML = '<font color=#000000>'+Math.round(f_19/1000000)/100+'亿</font>';
				sz_2.innerHTML = '<font color=red>'+f_38+'</font>';
				f_pp = (f_37-f_38-f_39 > 0)? f_37-f_38-f_39 : 0; 
				pp_2.innerHTML = '<font color=#000000>'+f_pp+'</font>';
				xd_2.innerHTML = '<font color=green>'+f_39+'</font>';	
			}
		}
	}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3){
		if ((obj=MM_findObj(args[i]))!=null) { 
			v=args[i+2];
    		if (obj.style) { 
				obj=obj.style;
				v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
			}
    		obj.visibility=v; 
		}
	}
}
function set_tab(n){
	for(i=1; i<=4; i++){
		if(n==i){
			document.getElementById("current"+i+"").style.background = "url(images/homepage1/left_title04b.gif)";
			document.getElementById("current"+i+"").style.padding="2px 5px 3px 5px";
		}else{
			document.getElementById("current"+i+"").style.background = "url(images/homepage1/left_title04.gif)";
			document.getElementById("current"+i+"").style.padding="2px 5px 2px 5px";
		}
	}
}

function set_tab3(num){
	for(var i=1; i<=2; i++){
		if(i == num){
			document.getElementById("cjTab"+i).className = "gsTab_s";
			document.getElementById("caijin_tab"+i).style.display = "block";
		}else{
			document.getElementById("cjTab"+i).className = "gsTab";
			document.getElementById("caijin_tab"+i).style.display = "none";
		}
	}
}

function set_tab2(num){
	for(var i=1; i<=2; i++){
		if(i == num){
			document.getElementById("arTab"+i).className = "gsTab_s";
			document.getElementById("gushi_tab"+i).style.display = "block";
		}else{
			document.getElementById("arTab"+i).className = "gsTab";
			document.getElementById("gushi_tab"+i).style.display = "none";
		}
	}
}

// 友情链接跳转菜单
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  window.open(""+selObj.options[selObj.selectedIndex].value+"","","");
}
/*
// 首页打开后的弹出图客
function openpopup(){
	oWindow = window.open("http://www.10jqka.com.cn/ad_mar/sjcgtz/index.html","432","293");
	if(oWindow){
		oWindow.blur(); // 失去交点
	}
}
*/

// 用cookie控制首页弹出或展开窗口的次数
function get_cookie(Name) {
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) { // if cookie exists
			offset += search.length
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset);
			// set index of end of cookie value
			if (end == -1)
			end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}

// 首页打开后的弹出广告窗口
function openpopup(){
	var iWidth=540; //模态窗口宽度
	var iHeight=380;//模态窗口高度
	var iTop=(window.screen.height-iHeight)/2;
	var iLeft=(window.screen.width-iWidth)/2;
	oWindow = window.open("http://www.10jqka.com.cn/ad_mar/tongzhi0311.html","","scrollbars=no,resizable=no,width="+iWidth+",height="+iHeight+",top="+iTop+",left="+iLeft+"");
}

function loadpopup(){
	if(get_cookie('popped')==''){
		//openpopup(); // 使用弹出窗口
		//tan_message(); // 使用弹出层（窗口）
		getMsg(); // 使用MSN消息框
		document.cookie="popped=yes";
	}
}

var intervalId = null;
function move(id,state)
{ 
	var page_height = 320;
	var obj = document.getElementById(id); 
	if(intervalId != null) 
	{
		window.clearInterval(intervalId); 
	}
	function change()
	{ 
		var h = parseInt(obj.offsetHeight); 
		if(state == "down")
		{
			if(h >= page_height)
			{
				return false;
			}
			else if(h < page_height * 0.8)
			{
				obj.style.height = h + 16;
			}
			else
			{
				obj.style.height = h + 2;
			}
		}
		else if(state == "out")
		{
			if(h <= 0)
			{
				return false;
			}
			else
			{
				obj.style.height = 0;
			}
			/*
			else if(h > page_height * 0.2)
			{
				obj.style.height = h - 16;
			}
			else
			{
				obj.style.height = h - 2;
			}
			*/
		}
	} 
	intervalId = window.setInterval(change, 7); 
}  

/* 首页打开后弹出层窗口 代码开始*/

var GW = screen.width;
var GH = screen.height;

function tan_message(){
	var iWidth=540; //模态窗口宽度
	var iHeight=380;//模态窗口高度
	var oMessage = document.createElement("div");
	oMessage.name = "pop_message";
	oMessage.id = "pop_message";
	document.body.appendChild(oMessage);

	var iMessage = document.getElementById("pop_message");
	iMessage.style.position = "absolute";
	iMessage.style.border = "1px solid #CCCCCC";
	iMessage.style.background ="#F6F6F6";
	var i=0;
	iMessage.style.left = (GW-i*i*4)/2+"px";
	iMessage.style.top = (GH/2-100-i*i)+"px";
	iMessage.style.width =     i*i*4 + "px";
	iMessage.style.height = i*i*2 + "px";

	iMessage.innerHTML = '<iframe width="'+iWidth+'" height="'+(iHeight-25)+'" src="http://www.10jqka.com.cn/ad_mar/tongzhi0311.html" marginwidth="0" hspace="0" frameborder="0" scrolling="no"></iframe><div style="font-size:12px;align:center"><a href="javascript:closeMessage(); ">关闭×</a></div>';

	popMessage(i);
}

function popMessage(i){
	var iMessage = document.getElementById("pop_message");
	iMessage.style.left = (GW-i*i*4)/2+"px";
	iMessage.style.top = (GH/2-100-i*i)+"px";
	iMessage.style.width =     i*i*4 + "px";
	iMessage.style.height = i*i*2+ "px";
	if(i<=10){
		i++;
		setTimeout("popMessage("+i+")",10);
	}
}

function closeMessage(i){
	var iMessage = document.getElementById("pop_message");
	iMessage.style.width = 0;
	iMessage.style.height = 0;
	iMessage.style.display = "none";
}

/* 首页打开后弹出层窗口 代码结束*/

function loadAdvPage(max){
	var cookie_num = get_cookie('AdvPage');
	if(cookie_num){
		cookie_num = parseInt(cookie_num);
	}else{
		cookie_num = 0;
	}
	if(cookie_num >= max){
		return false;
	}
	cookie_num = cookie_num + 1;
	document.cookie = "AdvPage="+cookie_num;
	move('mytd','down');
	window.setTimeout("move('mytd','out')", 9500);
}

// 设为首页
function set_homepage(item){
	item.style.behavior='url(#default#homepage)';item.setHomePage('http://www.zjchess.com/');
}
// 加入收藏夹
function into_favorite(){
	window.external.AddFavorite('http://www.zjchess.com/','浙江象棋网');
}
