
//===========================取系统参数=================================
var domGetSysSet;

function GetSysSet()
{//取系统参数
	IsGetSysSet = false;
	/**
	var page = '/jsp/hFredGameManager/jsData.jsp?license_id='+license_id+'&type=getSysSet';
	try{
		JsData.includePage(page,GetSysSet2);
	}catch(e){}
	*/
	//alert(rootPath);
	xmlBack(rootPath+'jsp/hFredGameManager/getsysset.jsp?license_id='+license_id+'&p='+(new Date()).getTime(),GetSysSet2);
	
}
/*
function GetSysSet()
{//取系统参数
	issale = 1;
	IsGetSysSet = true;
	fasecond = 0;
	return;
}
*/
function GetSysSet2(domData)
{//取系统参数
	if(!domData)return;
	var mod = "//row";
	var row = domData.selectNodes(mod);
	//alert(row.length);
	if(row.length>0)
	{
		issale = row.item(0).attributes.getNamedItem("issale").nodeValue;
		fasecond = row.item(0).attributes.getNamedItem("fasecond").nodeValue;
	}
	else
	{
		issale = 0;
		fasecond = 0
	}
	IsGetSysSet = true;
}
//===========================取系统参数END================================


//===========================取服务器时间=================================
var domGetServerTime;
function GetTimeComparetoServer()
{//取服务器时间
	IsGetLocalSubServerSecond = false;
	/*
	var page = '/jsp/hFredGameManager/jsData.jsp?license_id='+license_id+'&type=getServerTime';
	try{
		JsData.includePage(page,GetTimeComparetoServer2);
	}catch(e){}
	*/
	
	xmlBack(rootPath+'jsp/hFredGameManager/getservertime.jsp?p='+(new Date()).getTime(),GetTimeComparetoServer2);
}
function GetTimeComparetoServer2(domData)
{//取服务器时间
	if(!domData)return;
	
	var mod = "//row";
	var row = domData.selectNodes(mod);
	ServerTime = row.item(0).attributes.getNamedItem("servertime").nodeValue;
	var date = new Date();
	LocalSubServerSecond = Math.round((Date.parse(date)-Date.parse(ServerTime.replace(/-/g,"/")))/1000);
	LocalSubServerSecond = LocalSubServerSecond-1;
	GetActiveExpectInfo();//获取当前期信息
	IsGetLocalSubServerSecond = true;
	
}
//===========================取服务器时间END=================================


//===========================取当前期信息=================================

var domGetActiveExpectInfo;
function GetActiveExpectInfo()
{
	IsGetActiveExpectInfo = false;
	/*
	var page = '/jsp/hFredGameManager/jsData.jsp?license_id='+license_id+'&type=getActiveExpect&aheadTime='+aheadTime;
	try{
		JsData.includePage(page,GetActiveExpectInfo2);
	}catch(e){}
	*/
	xmlBack(rootPath+'jsp/hFredGameManager/'+license_id+'/touzhuexpect.xml?p='+(new Date()).getTime(),GetActiveExpectInfo2);
}
function GetActiveExpectInfo2(domData)
{
	if(!domData)return;
	
	var mod = "//row";
	var row = domData.selectNodes(mod);
	if(row.length>0)
	{
		for(var i=0;i<row.length;i++)
		{
			var dgendtime = row.item(i).attributes.getNamedItem("endtime").nodeValue;
			var date = Date.parse(ServerTime.replace(/-/g,"/"));
			//alert(ServerTime);
			
			var EndOverSecond = Math.round((date-Date.parse(dgendtime.replace(/-/g,"/")))/1000)+parseInt(fasecond);
			//var EndOverSecond = Math.round((date-Date.parse(dgendtime.replace(/-/g,"/")))/1000);
			//alert(row.item(i).attributes.getNamedItem("expect").nodeValue+"\r"+ServerTime+"\r"+dgendtime+"\r"+fasecond+"\r"+EndOverSecond);
			if(EndOverSecond<0)
			{
				ActiveExpect = row.item(i).attributes.getNamedItem("expect").nodeValue;
				ActiveExpectDgendtime = row.item(i).attributes.getNamedItem("endtime").nodeValue;
				break;
			}
		}
	}
	IsGetActiveExpectInfo = true;
}

//===========================取当前期信息END=================================


//===========================显示当前期信息=================================
var times_showActiveExpect = 0;
var times_ShowOpenCode = 0;
var times_ShowColdCode = 0;
var times_init = 0;

var o_TouzhuExpectType = null;
var o_expect_hidden = null;
var objactiveexpectdesc = null;
var objRemainSecond = null;

function showActiveExpect()
{
	if (!IsGetSysSet || !IsGetLocalSubServerSecond || !IsGetActiveExpectInfo || !ActiveExpectDgendtime)
	{
		setTimeout("showActiveExpect()",1000);
		return;
	}
	MinusSeconds();
	if(WinOnLoaded)
	{//初始化
		if(tradetopLoad)
		{
			ShowOpenCode();
		}
		
	}
	WinOnLoaded = false;

	times_showActiveExpect++;
	if (times_showActiveExpect%120==0)
	{
		GetSysSet();
		times_showActiveExpect=1;
	}

	times_ShowOpenCode++;
	if (times_ShowOpenCode%60==0)
	{
		if(tradetopLoad)
		{
			ShowOpenCode();
		}
		times_ShowOpenCode=1;
	}
	if(o_TouzhuExpectType==null)
		o_TouzhuExpectType = $('TouzhuExpectType');
	var TouzhuExpectType = o_TouzhuExpectType.value
	//alert(TouzhuExpectType);
	var FirstTourzhuExpect;
	
	if(o_expect_hidden==null)
		o_expect_hidden = bottom.document.all("expect_hidden");
	
	if(o_expect_hidden!=null)
	{
		var o_expect_hidden_0 = bottom.document.all("expect_hidden")[0];
	
		if(o_expect_hidden_0!=null)
		{
			FirstTourzhuExpect = o_expect_hidden_0.value;
		}
		else
		{
			FirstTourzhuExpect = o_expect_hidden.value;
		}
	}
	if(FirstTourzhuExpect!=null)
	{
		if(TouzhuExpectType==1 && FirstTourzhuExpect!=ActiveExpect)
		{
		//	alert(1);
			SelectTouzhuExpectType(1);
		}
	}
	if(objactiveexpectdesc==null)
		objactiveexpectdesc = tradetop.document.all("activeexpectdesc");
	if(objRemainSecond==null)
		objRemainSecond = tradetop.document.all("RemainSecond");
	
	if(issale==0)
	{
		ExpectStateInfo = "因系统原因，暂停销售。";
		ExpectIsSale = false;
		objactiveexpectdesc.innerHTML = "<span class=STYLE5>&nbsp;&nbsp;因系统原因，暂停销售。</span>";
		objRemainSecond.innerHTML = "";
		setTimeout("showActiveExpect()",1000);
		return;
	}	
	
	if(DgEndRemainSecond>0)
	{//售卖中，截止倒计时
		SetActiveShow(ActiveExpect);//显示当前期期号
		ExpectStateInfo = "开售中";
		ExpectIsSale = true;
		if(DgEndRemainSecond>1800)
		{
			objactiveexpectdesc.innerHTML = "开售中";
		}
		else
		{
			
			objactiveexpectdesc.innerHTML = "<span class=STYLE5>离截止投注还有 </span>";
			objRemainSecond.innerHTML = DgEndRemainSecondMsg;
		}
		setTimeout("showActiveExpect()",1000);
		return;
	}
	else
	{
		ExpectStateInfo = "等待开售";
		ExpectIsSale = false;
		objactiveexpectdesc.innerHTML = "等待开售";
		objRemainSecond.innerHTML = "";
		FirstLoadTouzhuExpect = true;
		
		clear_expectbeishu();
		GetTimeComparetoServer();
	}
	setTimeout("showActiveExpect()",1000);
	return;
}
//===========================显示当前期信息END=================================


//--1.
function MinusSeconds()
{//计算离各时间还有多少秒
	var date = new Date();
	DgEndRemainSecond = Math.round((Date.parse(ActiveExpectDgendtime.replace(/-/g,"/"))-Date.parse(date))/1000+LocalSubServerSecond)-parseInt(fasecond);
	var m = Math.floor(DgEndRemainSecond/60);
	if (m<10)
	{
		m = "0"+m;
	}
	var s = DgEndRemainSecond%60;
	if(s<10)
	{
		s = "0"+s;
	}
	DgEndRemainSecondMsg = m+":"+s;
}

var o_activeexpectshow = null;
function SetActiveShow(expect)
{//显示当前期期号和当天剩余期数
	//alert(expect);
	if(o_activeexpectshow==null)
		o_activeexpectshow = tradetop.document.all("activeexpectshow");
	if(o_activeexpectshow!=null)
	{
		o_activeexpectshow.innerHTML = "第<font color='red'><b><span id='buyExpectShow'>"+expect+"</span></b></font>期";
	}
}


function DateAdd(interval,number,date){ 
// date 可以是时间对象也可以是字符串，如果是后者，形式必须为: yyyy-mm-dd hh:mm:ss 其中分隔符不定。"2006年12月29日 16点01分23秒" 也是合法的
    number = parseInt(number);
    if (typeof(date)=="string"){
        date = date.split(/\D/);
        --date[1];
        eval("var date = new Date("+date.join(",")+")");
    }
    if (typeof(date)=="object"){
        var date = date
    }
    switch(interval){
        case "y": date.setFullYear(date.getFullYear()+number); break;
        case "m": date.setMonth(date.getMonth()+number); break;
        case "d": date.setDate(date.getDate()+number); break;
        case "w": date.setDate(date.getDate()+7*number); break;
        case "h": date.setHours(date.getHour()+number); break;
        case "n": date.setMinutes(date.getMinutes()+number); break;
        case "s": date.setSeconds(date.getSeconds()+number); break;
        case "l": date.setMilliseconds(date.getMilliseconds()+number); break;
    } 
    return date;
}