var soundflag=true;

function hide(id)
{
	var line = document.getElementById(id);
	line.style.display = "none";
	hide_count ++;
	
	var hider =  document.getElementById('hider');
	hider.innerText = hide_count;
}

function createTable_mx()
{		
	var timeZone = document.getElementById("TimeZone"); 
	timeZone.innerText = GetTimeZone(getLangIndex(lang));	//获取时区设置
	
	var div = document.getElementById("left");
	div.innerHTML = list;
	
	var table = BulidTable();
	div = document.getElementById("center");
	div.innerHTML = table;	
	
	var hider = document.getElementById("hider");
	hider.innerText = allCount - showCount;		
	hide_count  = allCount - showCount;
	
	//显示广告
	showAd();
	
	change();
}

function createTable_mx1()
{		
	var timeZone = document.getElementById("TimeZone"); 
	timeZone.innerText = GetTimeZone(getLangIndex(lang));	//获取时区设置
	
	var div = document.getElementById("left");
	div.innerHTML = list;
	
	var table = BulidTable();
	div = document.getElementById("center");
	div.innerHTML = table;	
	
	var hider = document.getElementById("hider");
	hider.innerText = allCount - showCount;		
	hide_count  = allCount - showCount;		
	
	//显示广告
	showAd();
}

function createTable()
{		
	var timeZone = document.getElementById("TimeZone"); 
	timeZone.innerText = GetTimeZone(getLangIndex(lang));	//获取时区设置
	
	BulidTable();

	var hider = document.getElementById("hider");
	hider.innerText = allCount - showCount;		
	hide_count  = allCount - showCount;	
	
	//显示广告
	showAd();
	
	change();
	
}

function createTable1()
{		
	var timeZone = document.getElementById("TimeZone"); 
	timeZone.innerText = GetTimeZone(getLangIndex(lang));	//获取时区设置
	
	BulidTable();
	
	var hider = document.getElementById("hider");
	hider.innerText = allCount - showCount;		
	hide_count  = allCount - showCount;	
	
	//显示广告
	showAd();

}

function getLangIndex(len)
{
	if (len == "big" )
	{
		return 0
	}
	else if (len == "gb" )
	{
		return 1
	}
	else if (len == "en" )
	{
		return 2
	}
	else if (len == "vn" )
	{
		return 3
	}
	else if (len == "th" )
	{
		return 4
	}
}

function createTable_log()
{
	var div = document.getElementById("aa");
	div.innerHTML = table;
}

function history(m,e,p,oid1,oid2,oid3,type,pageType)
{	
	var path;
	if ( typeof(rq_dt) != 'undefined')
	{		
		path = "log_" + lang + ".shtml?m=" + m + "&p=" + p + "&oid1=" + oid1 + "&oid2=" + oid2 + "&oid3=" + oid3 + "&type=" + type + "&e=" + e + "&path=History/" + rq_dt;	
	}
	else if(typeof(rq_num) != 'undefined')
	{
		path = "log_" + lang + ".shtml?m=" + m + "&p=" + p + "&oid1=" + oid1 + "&oid2=" + oid2 + "&oid3=" + oid3 + "&type=" + type + "&e=" + e + "&path=early/" + rq_num;	
	}
	else
	{
		path = "log_" + lang + ".shtml?m=" + m + "&p=" + p + "&oid1=" + oid1 + "&oid2=" + oid2 + "&oid3=" + oid3 + "&type=" + type + "&e=" + e + "&path=" + his_page;
	}

	window.open(path,"","height=450px,width=480px,toolbar=no,scrollbars=yes,menubar=no");		
}

function provider(pId,pageType)
{
	var pathStr = pageType + "_" + lang + ".shtml"
	if ( typeof(rq_dt) != 'undefined')
	{
		if(pathStr.indexOf('?') > -1)
		{
			pathStr += "&dt=" + rq_dt;
		}
		else
		{
			pathStr += "?dt=" + rq_dt;
		}
	}
	
	if ( typeof(rq_num) != 'undefined')
	{
		if(pathStr.indexOf('?') > -1)
		{
			pathStr += "&num=" + rq_num;
		}
		else
		{
			pathStr += "?num=" + rq_num;
		}
	}
	
	if ( typeof(pId) != 'undefined' )
	{
		if(pathStr.indexOf('?') > -1)
		{
			pathStr += "&pId=" + pId;
		}
		else
		{
			pathStr += "?pId=" + pId;
		}
		
	}
	setCookie( path + '@matchsID1',null);	
	
	document.location.href = pathStr;
}	

function goToPlayed()
{
	if (pId != null)
	{
		document.location.href = "played2_" + lang + ".shtml?pId=" + pId;
	}
}

function goToDefault()
{
	if (pId != null)
	{
		document.location.href = "default2_" + lang + ".shtml?pId=" + pId;
	}
}

function CetPkStr1(i)
{
	if (i > 40)
		return "";
	return RQ_ARR1[i];
}

function RetPkStr1(value)
{
	for (var i = 0; i < RQ_ARR1.length; i++ )
	{
		if ( value == RQ_ARR1[i] )
		{
			return i / 4;
		}
	}
	
	return "";
}

function CetPkStr2(i)
{
	if (i > 40)
		return "";
	return RQ_ARR2[i];
}

function RetPkStr2(value)
{
	for (var i = 0; i < RQ_ARR2.length; i++ )
	{
		if ( value ==  RQ_ARR2[i] )
		{
			return i / 4;
		}
	}
	
	return "";
}

function jingjian()
{	
	setCookie( path + "@matchsID","Simple");
	document.location.href = document.location.href;
}

function show()
{
	var tmp_str = (document.location.href.split('?'))[0];
	
	if ( tmp_str.indexOf("2") > 0 )
	{
		setCookie( path + "@matchsID1","All");
	}
	else
	{
		setCookie( path + "@matchsID","All");
	}	
	
	var page = document.location.href;
	var index = page.indexOf('?');
	if(index > -1 )
	{
		page = page.substr(0,index);
	}
	
	if ( typeof(rq_dt) != 'undefined' && rq_dt !="")
	{
		
		if(page.indexOf('?') > -1)
		{
			page += "&dt=" + rq_dt;
		}
		else
		{
			page += "?dt=" + rq_dt;
		}
		
	}
	else if ( typeof(rq_num) != 'undefined' && rq_num !="")
	{
		
		if(page.indexOf('?') > -1)
		{
			page += "&num=" + rq_num;
		}
		else
		{
			page += "?num=" + rq_num;
		}
		
	}	
	
	if ( typeof(pId) != 'undefined' )
	{
		if(page.indexOf('?') > -1)
		{
			page += "&pId=" + pId;
		}
		else
		{
			page += "?pId=" + pId;
		}	
		
	}
	document.location.href = page;	
}

/* 选择赛事 */
function selectMatch(flag,page)
{
	document.getElementById("Selframe").src = "tournament_" + lang + ".shtml?path=" + flag + "&page=" + page;
	document.getElementById("SelList_div").style.display = "";		
	
	var obj = document.getElementById("SelList_div");
	obj.style.top = (getElementPos("saishi").y + 20) + "px";
	obj.style.left =((document.body.clientWidth / 2) - 250 )+"px";	
}

/* 选择公司 */
function selectProvider(page)
{
	document.getElementById("Selframe").src = "provider_" + lang + ".shtml?page=" + page;
	document.getElementById("SelList_div").style.display = "";
	
	var obj = document.getElementById("SelList_div");
	obj.style.top = (getElementPos("saishi").y + 20) + "px";
	obj.style.left = ((document.body.clientWidth / 2) - 250 )+"px";	
}

function fun(pId)
{
	var path = document.location.href;
	saveListState();
	if(path.indexOf("&") > 0)
	{
		document.location.href = path.split("&")[0] + "&pId="+ pId;
	}
	else
	{
		document.location.href = path.split("?")[0] + "?pId="+ pId;
	}
}

function updateMatchs(value,page)
{	
	var path = page + "_" + lang + ".shtml" ;
	
	if (typeof(rq_dt) != 'undefined')
	{
		if(path.indexOf('?') > -1)
		{
			path += "&dt=" + rq_dt;
		}
		else
		{
			path += "?dt=" + rq_dt;
		}		
	}
	else if (typeof(rq_num) != 'undefined' )
	{		
		if(path.indexOf('?') > -1)
		{
			path += "&num=" + rq_num;
		}
		else
		{
			path += "?num=" + rq_num;
		}
	}
	
	if (typeof(pId) != 'undefined' )
	{
		if(path.indexOf('?') > -1)
		{
			path += "&pId=" + pId;
		}
		else
		{
			path += "?pId=" + pId;
		}	
	}

	document.location.href = path;
}

function updateProviders(value,page)
{
	var path = page + "_" + lang + ".shtml";	
	
	if (typeof(rq_dt) != 'undefined' )
	{		
		if(path.indexOf('?') > -1)
		{
			path += "&dt=" + rq_dt;
		}
		else
		{
			path += "?dt=" + rq_dt;
		}		
	}
	else if (typeof(rq_num) != 'undefined' )
	{
		if(path.indexOf('?') > -1)
		{
			path += "&num=" + rq_num;
		}
		else
		{
			path += "?num=" + rq_num;
		}
	}
	document.location.href = path;
}

function changLanguage(change_lang)
{
	document.location.href = document.location.href.replace(lang,change_lang);
}

function getCookie(name)
{
  var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
  if(arr != null) return unescape(arr[2]); return null;
}

function goToHistory()
{
	var dt = getDatetime(1);
	var path = "";	
	if ( typeof(pId) != 'undefined' )
	{	
		path = "result2_" + lang + ".shtml?dt=" + dt + "&pId=" + pId;		
	}
	else
	{
		path = "result_" + lang + ".shtml?dt=" + dt;
	}
	document.location.href = path;
}

function goToAll()
{
	var path = document.location.href;
	path = path.substr(0,path.indexOf("2")) + "_" + lang + ".shtml";
	if ( typeof(rq_dt) != 'undefined' )
	{	
		path += "?dt=" + rq_dt;		
	}
	else if( typeof(rq_num) != 'undefined' )
	{
		path += "?num=" + rq_num;	
	}
	
	document.location.href = path;
}

function goToEarly()
{
	var path= "";	
	if ( typeof(pId) != 'undefined' )
	{	
		path = "early2_" + lang + ".shtml?num=1" + "&pId=" + pId;		
	}
	else
	{
		path= "early_" + lang + ".shtml?num=1";	
	}
	document.location.href = path;
}

function showList(obj)
{
	var flag;
	for(var i=0;i<obj.parentNode.childNodes.length;i++)
	{
		var item = obj.parentNode.childNodes[i];
		if(item.nodeName == "DD")
		{			
			if(item.style.display=='none')
			{						
				item.style.display='block';
				flag = "0";
			}
			else
			{					
				item.style.display='none';
				flag = "1";
			}
		}
	}
	
	if(flag == "1")
	{	
		obj.firstChild.innerText = "+";
	}
	else
	{
		obj.firstChild.innerText = "-";
	}
}

function saveListState()
{
	var listOdds = document.getElementById("listOdds");
	var openItems = "";
	for(var i = 0; i < listOdds.childNodes.length; i++ )
	{
		
		var item = listOdds.childNodes[i];
		if(item.childNodes.length > 1)
		{
			if(item.childNodes[1].style.display == "block")
			{
				openItems += item.firstChild.innerText.charAt(1) + ",";
			}
		}
	}
	
	if(openItems.length > 0)
	{
		openItems = openItems.substr(0,openItems.length -1);
	}	
	
	setCookie("liststate",openItems);
}

function playPkSound()
{
	if (soundflag)
	{
		var pk = document.getElementById("pk");
		
		pk.innerHTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' WIDTH='1' HEIGHT='1'><param name='movie' value='/images/s2.swf'><param name='quality' value='high'><param name='wmode' value='transparent'><embed src='/images/s2.swf' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='1' height='1'></embed></object>";
	}
		
}

function ShowSound(obj)
{	
	if(soundflag)
	{
		soundflag = false;		
			
	}
	else
	{
		soundflag = true;	
		
	}		
}

function updateTimeZone()
{
	this.location.reload();
}

function showAd()  //showType显示的类型 top、right、left之前用'_'隔开
{
	if ( typeof(ad_top) != 'undefined' )
	{
		var obj = document.getElementById("pageTop");
		obj.innerHTML = ad_top;
	}
	
	if ( typeof(ad_right) != 'undefined' )
	{
		var obj = document.getElementById("pageRight");
		obj.innerHTML = ad_right;
	}
	
	if ( typeof(ad_left) != 'undefined' )
	{
		var obj = document.getElementById("pageLeft");
		obj.innerHTML = ad_left;
	}
}
