//window.top-> Index.aspx or Main.aspx

var m_sports;
var MaxMilliSec = 30000;
// when click change menu type exec SetMenuData need to show odds
var IsChangeMenuType = false;
var Tmpl_Initialed = false; // flag to record menu is template loaded ?
var ShowMenuFlag = true;  // for first load data
var arrURL = new Array();
var ForceMenuData = false; // Force to get menu data from Menu_data.aspx
var fFrame= getParent(window);
var isParlay = false;
var IsFun88 = false;
var IsM88 = false;
var IsALog = false;

if (fFrame.SiteMode == "2") 
{
	if (fFrame.Deposit_SiteMode == "2") IsFun88 = true;
	else if (fFrame.Deposit_SiteMode == "3") IsM88 = true;
	else if (fFrame.Deposit_SiteMode == "4") IsALog = true;
} 

function getParent(cFrame)
{
	var aFrame = cFrame;
	for (var i = 0; i < 4; i++) {
		if(aFrame.SiteMode != null) {
			return aFrame;
		} else {
			aFrame = aFrame.parent;
		}
	}
	return null;
}
arrURL["0_P"] = "SportsMixParlay.aspx";
arrURL["1_UnderOver"] = "UnderOver.aspx";
arrURL["1_T"] = "UnderOver.aspx";
arrURL["1_E"] = "UnderOver.aspx";
arrURL["1_L"] = "UnderOver.aspx";
arrURL["1_1X2"] = "1X2.aspx";
arrURL["1_CS"] = "CorrectScore.aspx";
arrURL["1_HTFT"] = "HTFT.aspx";
arrURL["1_FGLG"] = "FGLG.aspx";
arrURL["1_OETG"] = "OeTg.aspx";
arrURL["1_P"] = arrURL["0_P"];
arrURL["1_F"] = "Favorite.aspx";
arrURL["2_NBA"] = "NBA.aspx";
arrURL["2_T"] = "NBA.aspx";
arrURL["2_E"] = "NBA.aspx";
arrURL["2_L"] = "NBA.aspx";
arrURL["2_P"] = arrURL["0_P"];
arrURL["3_NBA"] = "NBA.aspx";
arrURL["3_E"] = "NBA.aspx";
arrURL["3_T"] = "NBA.aspx";
arrURL["3_L"] = "NBA.aspx";
arrURL["3_P"] = arrURL["0_P"];
arrURL["4_Tennis"] = "Tennis.aspx";
arrURL["4_E"] = "Tennis.aspx";
arrURL["4_T"] = "Tennis.aspx";
arrURL["4_L"] = "Tennis.aspx";
arrURL["4_P"] = arrURL["0_P"];
arrURL["5_Tennis"] = arrURL["4_Tennis"];
arrURL["5_T"] = arrURL["4_Tennis"];
arrURL["5_E"] = arrURL["4_Tennis"];
arrURL["5_L"] = arrURL["4_Tennis"];
arrURL["5_P"] = arrURL["0_P"];
arrURL["6_Tennis"] = arrURL["4_Tennis"];
arrURL["6_T"] = arrURL["4_Tennis"];
arrURL["6_E"] = arrURL["4_Tennis"];
arrURL["6_L"] = arrURL["4_Tennis"];
arrURL["6_P"] = arrURL["0_P"];
arrURL["7_Tennis"] = arrURL["4_Tennis"];
arrURL["7_T"] = arrURL["4_Tennis"];
arrURL["7_E"] = arrURL["4_Tennis"];
arrURL["7_L"] = arrURL["4_Tennis"];
arrURL["7_P"] = arrURL["0_P"];
arrURL["8_Baseball"] = "Baseball.aspx";
arrURL["8_E"] = "Baseball.aspx";
arrURL["8_T"] = "Baseball.aspx";
arrURL["8_L"] = "Baseball.aspx";
arrURL["8_P"] = arrURL["0_P"];
arrURL["9_Tennis"] = arrURL["4_Tennis"];
arrURL["9_T"] = arrURL["4_Tennis"];
arrURL["9_E"] = arrURL["4_Tennis"];
arrURL["9_L"] = arrURL["4_Tennis"];
arrURL["9_P"] = arrURL["0_P"];
arrURL["10_Tennis"] = arrURL["4_Tennis"];
arrURL["10_T"] = arrURL["4_Tennis"];
arrURL["10_E"] = arrURL["4_Tennis"];
arrURL["10_L"] = arrURL["4_Tennis"];
arrURL["10_P"] = arrURL["0_P"];
arrURL["11_Tennis"] = arrURL["4_Tennis"];
arrURL["11_T"] = arrURL["4_Tennis"];
arrURL["11_E"] = arrURL["4_Tennis"];
arrURL["11_L"] = arrURL["4_Tennis"];
arrURL["11_P"] = arrURL["0_P"];
arrURL["12_Tennis"] = arrURL["4_Tennis"];
arrURL["12_T"] = arrURL["4_Tennis"];
arrURL["12_E"] = arrURL["4_Tennis"];
arrURL["12_L"] = arrURL["4_Tennis"];
arrURL["12_P"] =arrURL["0_P"];
arrURL["13_Tennis"] = arrURL["4_Tennis"];
arrURL["13_T"] = arrURL["4_Tennis"];
arrURL["13_E"] = arrURL["4_Tennis"];
arrURL["13_L"] = arrURL["4_Tennis"];
arrURL["13_P"] = arrURL["0_P"];
arrURL["14_Tennis"] = arrURL["4_Tennis"];
arrURL["14_T"] = arrURL["4_Tennis"];
arrURL["14_E"] = arrURL["4_Tennis"];
arrURL["14_L"] = arrURL["4_Tennis"];
arrURL["14_P"] = arrURL["0_P"];
arrURL["15_Tennis"] = arrURL["4_Tennis"];
arrURL["15_T"] = arrURL["4_Tennis"];
arrURL["15_E"] = arrURL["4_Tennis"];
arrURL["15_L"] = arrURL["4_Tennis"];
arrURL["15_P"] = arrURL["0_P"];
arrURL["16_Tennis"] = arrURL["4_Tennis"];
arrURL["16_T"] = arrURL["4_Tennis"];
arrURL["16_E"] = arrURL["4_Tennis"];
arrURL["16_L"] = arrURL["4_Tennis"];
arrURL["16_P"] = arrURL["0_P"];
arrURL["17_Tennis"] = arrURL["4_Tennis"];
arrURL["17_T"] = arrURL["4_Tennis"];
arrURL["17_E"] = arrURL["4_Tennis"];
arrURL["17_L"] = arrURL["4_Tennis"];
arrURL["17_P"] = arrURL["0_P"];
arrURL["18_Tennis"] = arrURL["4_Tennis"];
arrURL["18_T"] = arrURL["4_Tennis"];
arrURL["18_E"] = arrURL["4_Tennis"];
arrURL["18_L"] = arrURL["4_Tennis"];
arrURL["18_P"] = arrURL["0_P"];
arrURL["19_Tennis"] = arrURL["4_Tennis"];
arrURL["19_T"] = arrURL["4_Tennis"];
arrURL["19_E"] = arrURL["4_Tennis"];
arrURL["19_L"] = arrURL["4_Tennis"];
arrURL["19_P"] = arrURL["0_P"];
arrURL["20_Tennis"] = arrURL["4_Tennis"];
arrURL["20_T"] = arrURL["4_Tennis"];
arrURL["20_E"] = arrURL["4_Tennis"];
arrURL["20_L"] = arrURL["4_Tennis"];
arrURL["20_P"] = arrURL["0_P"];
arrURL["21_Tennis"] = arrURL["4_Tennis"];
arrURL["21_T"] = arrURL["4_Tennis"];
arrURL["21_E"] = arrURL["4_Tennis"];
arrURL["21_L"] = arrURL["4_Tennis"];
arrURL["21_P"] = arrURL["0_P"];
arrURL["22_Tennis"] = arrURL["4_Tennis"];
arrURL["22_T"] = arrURL["4_Tennis"];
arrURL["22_E"] = arrURL["4_Tennis"];
arrURL["22_L"] = arrURL["4_Tennis"];
arrURL["22_P"] = arrURL["0_P"];
arrURL["23_Tennis"] = arrURL["4_Tennis"];
arrURL["23_T"] = arrURL["4_Tennis"];
arrURL["23_E"] = arrURL["4_Tennis"];
arrURL["23_L"] = arrURL["4_Tennis"];
arrURL["23_P"] = arrURL["0_P"];
arrURL["24_Tennis"] = arrURL["4_Tennis"];
arrURL["24_T"] = arrURL["4_Tennis"];
arrURL["24_E"] = arrURL["4_Tennis"];
arrURL["24_L"] = arrURL["4_Tennis"];
arrURL["24_P"] = arrURL["0_P"];
arrURL["25_Tennis"] = arrURL["4_Tennis"];
arrURL["25_T"] = arrURL["4_Tennis"];
arrURL["25_E"] = arrURL["4_Tennis"];
arrURL["25_L"] = arrURL["4_Tennis"];
arrURL["25_P"] = arrURL["0_P"];
arrURL["26_NBA"] = arrURL["3_NBA"];
arrURL["26_T"] = arrURL["3_NBA"];
arrURL["26_E"] = arrURL["3_NBA"];
arrURL["26_L"] = arrURL["3_NBA"];
arrURL["26_P"] = arrURL["0_P"];
arrURL["27_Cricket"] = 'Cricket.aspx';
arrURL["27_T"] = arrURL["27_Cricket"];
arrURL["27_E"] =arrURL["27_Cricket"];
arrURL["27_L"] =arrURL["27_Cricket"];
arrURL["27_P"] = arrURL["0_P"];
arrURL["28_Tennis"] = arrURL["4_Tennis"];
arrURL["28_T"] = arrURL["4_Tennis"];
arrURL["28_E"] = arrURL["4_Tennis"];
arrURL["28_L"] = arrURL["4_Tennis"];
arrURL["28_P"] = arrURL["0_P"];
arrURL["29_T"] = arrURL["4_Tennis"];
arrURL["29_E"] = arrURL["4_Tennis"];
arrURL["29_L"] = arrURL["4_Tennis"];
arrURL["29_P"] = arrURL["0_P"];
arrURL["30_T"] = arrURL["4_Tennis"];
arrURL["30_E"] = arrURL["4_Tennis"];
arrURL["30_L"] = arrURL["4_Tennis"];
arrURL["30_P"] = arrURL["0_P"];
arrURL["31_Tennis"] = arrURL["4_Tennis"];
arrURL["31_T"] = arrURL["4_Tennis"];
arrURL["31_E"] = arrURL["4_Tennis"];
arrURL["31_L"] = arrURL["4_Tennis"];
arrURL["31_P"] = arrURL["0_P"];
arrURL["99_Tennis"] = arrURL["4_Tennis"];
arrURL["99_T"] = arrURL["4_Tennis"];
arrURL["99_E"] = arrURL["4_Tennis"];
arrURL["99_L"] = arrURL["4_Tennis"];
arrURL["99_P"] = arrURL["0_P"];
arrURL["151_E"] = "Horse_Fixed.aspx";
arrURL["151_T"] = "Horse.aspx";
arrURL["201"] = "Financials.aspx";
arrURL["0_OT"] = "Outright.aspx";
arrURL["0_E"] = arrURL["0_OT"];
arrURL["0_T"] = arrURL["0_OT"];
//arrURL["0_L"] = "Live.aspx";


function initialMenu() {
	
	var frameId = "Menu_tmpl";
	var url = "Menu_tmpl.aspx";

	if (fFrame.hash_TmplLoaded[frameId] == null) {
		fFrame.document.getElementById(frameId).contentWindow.location.href = url;
		fFrame.hash_TmplLoaded[frameId] = true;
		Tmpl_Initialed = false;
		window.setTimeout(initialMenu, 200);
		return;
	}

	if (fFrame.document.getElementById(frameId).contentWindow.document.getElementById("tmplEnd") == null) {
		Tmpl_Initialed = false;
		window.setTimeout(initialMenu, 200);
		return;
	}
	
	var imgsrc=fFrame.document.getElementById(frameId).contentWindow.imgSrc;
	m_sports=fFrame.document.getElementById(frameId).contentWindow.M;
	document.getElementById("MenuContainer").innerHTML = fFrame.document.getElementById(frameId).contentWindow.document.body.innerHTML;
   
    var menuTitle=document.getElementById('subnav_head');
	menuTitle.style.display='none';

	//m_mouseover(window.top.LastSelectedMenu,imgsrc);
    SetMenuData(m_sports,imgsrc);
    	setInterval("AutoRefreshMenuData()",MaxMilliSec);
	Tmpl_Initialed = true;

	ifrmaeresizt();
	menuTitle.style.display=''; 
}


function AutoRefreshMenuData() {
//alert('AutoRefreshMenuData  --> IsChangeMenuType :'+IsChangeMenuType);

	var objMAC=document.getElementById('hidForce');
	objMAC.value = ForceMenuData;
	var objM_Type=document.getElementById('hidMenuType');
	objM_Type.value=fFrame.LastSelectedMenu;
	document.frmMenuData.submit();
}

//------------------ Switch Menu Type---------------------------
function m_mouseover(m_type,imgsrc) {
	var objMenu;
	if (m_type == 0) {

		objMenu = document.getElementById('menu_all');
		if(objMenu!=null)
	    {
		    objMenu.className = 'current';
        }
        objMenu = document.getElementById('subnav_head');
		if(objMenu!=null)
	    {
		    objMenu.className = 'item';
        }
        
//		objMenu = document.getElementById('img_menu_oln');
//		objMenu.src = imgsrc + 'menu_olympic_2.gif';
		objMenu = document.getElementById('menu_wp');

		if(objMenu!=null)
	    {
	        objMenu.className = '';
		}
	} 	
	else if(m_type == 1)
    {

		objMenu = document.getElementById('img_menu_oln');
		objMenu.src = imgsrc + 'menu_olympic_1.gif';
		objMenu = document.getElementById('menu_all');
		objMenu.className = 'subnav_all1';
	}
    else if(m_type == 2)
    {
    
    	objMenu = document.getElementById('menu_all');
    	if(objMenu!=null)
	    {
		    objMenu.className = '';
        }
		objMenu = document.getElementById('menu_wp');
		if(objMenu!=null)
	    {
		    objMenu.className = 'current';
		}
		objMenu = document.getElementById('subnav_head');
		if(objMenu!=null)
	    {
		    objMenu.className = 'item2';
        }
    }
}

function m_onmouseout(imgsrc) {
	var objMenu;

	if (fFrame.LastSelectedMenu == 0) {
		objMenu = document.getElementById('menu_all');
		if(objMenu!=null)
	    {
		    objMenu.className = 'current';
        }
        objMenu = document.getElementById('subnav_head');
		if(objMenu!=null)
	    {
		    objMenu.className = 'item';
        }
		objMenu = document.getElementById('menu_wp');
		if(objMenu!=null)
	    {
		    objMenu.className = '';
		}

	} 
	else if(fFrame.LastSelectedMenu == 1)
	{

		objMenu = document.getElementById('img_menu_oln');
		objMenu.src = imgsrc + 'menu_olympic_1.gif';

		objMenu = document.getElementById('menu_all');
		objMenu.className = 'subnav_all1';
	}
	else if(fFrame.LastSelectedMenu == 2)
    {
    	objMenu = document.getElementById('menu_all');
        if(objMenu!=null)
	    {
		    objMenu.className = '';
        }
    	objMenu = document.getElementById('menu_wp');
    	if(objMenu!=null)
	    {
		    objMenu.className = 'current';
		}
		objMenu = document.getElementById('subnav_head');
		if(objMenu!=null)
	    {
		    objMenu.className = 'item2';
        }
    }
}

function SwitchMenuType(m_type, imgsrc) {

	fFrame.LastSelectedSport =-1;
	//Load first/Last Selected Setting

	if(m_type!=fFrame.LastSelectedMenu)
	{
		IsChangeMenuType=true;
		fFrame.LastSelectedMenu = m_type;
		//Change imange
		m_mouseover(m_type,imgsrc);
	    //Exec AutoRefresh submit
	    AutoRefreshMenuData();
	}
	else
	{
		LoadMenuData('T');
	}
}

//----------------------------------------------------------------

//-------------------Live Control-------------------------------
function LoadLiveSportSetting() {
	if (!parent.mainFrame.PageLoaded) {
		window.setTimeout(LoadLiveSportSetting, 300);
		return;
	}

	var arr_ShowLive = parent.mainFrame.arr_ShowLive;
	var bAllChecked = true;
	for(var sSport in arr_ShowLive) {
		var chkbox = document.getElementById("chkLvSport_" + sSport);
		if (chkbox != null) {
			chkbox.checked = arr_ShowLive[sSport];
			if (!arr_ShowLive[sSport]) {
				bAllChecked = false;
			}
		}
	}

	var chkAll=document.getElementById("chkLvSpotrs_All");
	if(chkAll != null) {
		chkAll.checked = bAllChecked;
	}
}

//Live Sports click All
function LiveSportsClickAll() {
	var oChkAll = document.getElementById("chkLvSpotrs_All");
	oChkAll.checked = true;
	if (!refreshOddsPage("L", 0)) {
		parent.mainFrame.location.href = "Live.aspx?Game=" + fFrame.LastSelectedMenu;
		document.getElementById("chkLvSpotrs_All").checked = true;
		for (var i = 0; i < document.getElementsByName("chkLvSport").length; i++) {
			var oChkBox = document.getElementsByName("chkLvSport")[i];
			oChkBox.checked = true;
		}		
		return;
	}
	if (!parent.mainFrame.PageLoaded) {
		return;
	}

	var arrCkb = document.getElementsByName("chkLvSport");

	for (var i = 0; i < arrCkb.length; i++) {
		var oChkBox = arrCkb[i];
		oChkBox.checked = true;
		parent.mainFrame.showLiveSport(oChkBox.value, true, fFrame.LastSelectedMenu);
	}
}

//when click sport link on Live Menu
function LiveSportLinkClick(sporttype, isCkecked) {
	if (!parent.mainFrame.PageLoaded) {
		return;
	}

	document.getElementById("chkLvSpotrs_All").checked = false;
	var chkbox = document.getElementById("chkLvSport_"+sporttype);

	if (!isCkecked) {
		chkbox.checked = !chkbox.checked;
	}

	var bAllCheck = true;
	var arrCkb = document.getElementsByName("chkLvSport");
	for (var i = 0; i < arrCkb.length; i++) {
		if (!arrCkb[i].checked) {
			bAllCheck = false;
			break;
		}
	}
	document.getElementById("chkLvSpotrs_All").checked = bAllCheck;
	parent.mainFrame.showLiveSport(sporttype, chkbox.checked, fFrame.LastSelectedMenu);
}

//when click item on "HDP & OU" bar
function changeLiveDisplayMode(Mode) {
	if (parent.mainFrame.PageLoaded) {
		parent.mainFrame.changeDisplayMode(Mode);
	} else {
		parent.DisplayMode = Mode;
		parent.mainFrame.location.href = "Live.aspx?Game="+fFrame.LastSelectedMenu;
	}
}
//---------------------------------------------------------------------

function refreshOddsPage(Market, SportType, DispVer) {
    try {
		if (parent.mainFrame.document == null) return true;
	    if (parent.mainFrame.document.body == null) return true;
	    //if (parent.mainFrame.document.body.id != "OddsPage") return false;
	} catch(e) {
		return;
	}

	var aForm = parent.mainFrame.document.DataForm;
	if (aForm == null) {
		aForm = parent.mainFrame.document.DataForm_D;
	}
	if (aForm == null) return false;
	if (aForm.Market == null) return false;

	var sPageSport = aForm.Sport.value;
	if (sPageSport == null) return false;
	if (sPageSport != SportType) return false;
           
	var sPageMarket = aForm.Market.value;
	if ((Market != "L") && (Market != "F")) {
		if ((SportType != "0")) { 
			// all-outright and finance don't need to check market
			if (sPageMarket == null) return false;
			if (sPageMarket.toLowerCase() != Market.toLowerCase()) return false;
		}
	}

	if (SportType == "1") {
		if (Market == "F") {
			if (parent.mainFrame.document.body.id != "Favorite") return false;
		}

		if ((Market == "E") || (Market == "T")) {
		
			if (parent.mainFrame.document.body.id != "UnderOver") return false;

			// for soccer o/u change display mode
			if (parent.mainFrame.document.getElementById("disstyle").value != DispVer) {
				if (DispVer != "new") {
					parent.mainFrame.initialDisstyle(DispVer);
					parent.mainFrame.changeDisplayMode(DispVer, fFrame.DomainName);
					//return true;
				}
			}
		}

	} else if (SportType == "0") {
		if (Market == "L") {
			if (parent.mainFrame.document.body.id != "Live") {
				return false;
			}
		} else if (Market == "OT") {
			if (parent.mainFrame.document.body.id != "Outright") {
				return false;
			}
		} else if (isParlay) {
			if (parent.mainFrame.document.body.id == "Outright") {
				return false;
			}
			else if (parent.mainFrame.PAGE_MARKET != Market && Market != "P") {
				return false;
			}
		}
	}

	if (aForm.name == "DataForm") {
		parent.mainFrame.refreshData();
		return true;
	} else if (aForm.name == "DataForm_D") {
		parent.mainFrame.refreshAll();
		return true;
	}
	
	return false;
}

function ShowOdds(Market, SportType, DispVer) {
    if(fFrame.M88flag){
		parent.mainFrame.location.href ="UnderOver.aspx?Market=t";
		fFrame.M88flag=false;
	}

	if(Market == '') {
		Market = fFrame.LastSelectedMArket;
	}
	else if (Market =='F') {
	    isParlay = false;
	}

	//switch World cup or All Sport
	var aForm = parent.mainFrame.document.DataForm;
	if (aForm == null) {
		aForm = parent.mainFrame.document.DataForm_D;
	}
	//12bet first load haven't aForm.then set sGame default value 0 .sGame value 0 mean all sport
	var sGame ;
	if(aForm==null )
	{
		sGame="0"
	}
	else
	{
		if(aForm.Game==null)
		{
			sGame="0"
		}
		else
		{
			sGame=aForm.Game.value;
		}
	}
	if(sGame == fFrame.LastSelectedMenu)
	{
		if ((m_sports[SportType][Market] <= 0) && (m_sports[SportType]['OT'] > 0)) {
				Market='OT';
		}
		if (refreshOddsPage(Market, SportType, DispVer)) {
			return;
		}
	}else{
		if ((m_sports[SportType][Market] <= 0) && (m_sports[SportType]['OT'] > 0)) {
					Market='OT';
		}
	}

	try {
		parent.mainFrame.document.body.id;
	} catch(e) {
		//CrossParlay by Sport 
		if (Market=='P'){
			parent.mainFrame.location.href = arrURL["0_P"] + "?Sport=" + SportType + "&Market=" + fFrame.LastSelectedMArket + "&DispVer=" + DispVer+"&Game="+fFrame.LastSelectedMenu;
		}
		//CrossParlay by Today or Early
		else if(SportType=='P') {
			parent.mainFrame.location.href = arrURL["0_P"]+"?Sport=0&Market=" + fFrame.LastSelectedMArket + "&Game="+fFrame.LastSelectedMenu;
		}
		//Outright by Sport
		else if (Market=='OT') {
			parent.mainFrame.location.href = arrURL["0_OT"] + "?Sport=" + SportType + "&Market=" + Market.toLowerCase() + "&DispVer=" + DispVer+"&Game="+fFrame.LastSelectedMenu;
		//Outright by Today or Early
		} else if(SportType=='OT') {
			parent.mainFrame.location.href = arrURL["0_OT"]+"?Sport=0&Market=" + Market.toLowerCase() + "&Game="+fFrame.LastSelectedMenu;
		}
	    else if (SportType == '151') { // horse
	        if (Market=='E')
	        {
			    parent.mainFrame.location.href = arrURL["151_E"] + "?RM=E";
			    //alert(arrURL["151_E"] + "?RM=E");
			}
			else
			{
			    parent.mainFrame.location.href = arrURL["151_T"] + "?RM=T";
			    //alert(arrURL["151_T"] + "?RM=T");
			}
		}
		else if (SportType == '201') { //Finance
			if (Market=='' || Market=='T') {
			    if(m_sports[SportType]['BETS']!='') {
			        var FinanceAsset = m_sports[SportType]['BETS'].split(",")[0];
			        parent.mainFrame.location.href = arrURL["201"] + "?Market=" + FinanceAsset;
			    }
			} else {
			    parent.mainFrame.location.href = arrURL["201"]+"?Market="+Market;
			}
		} else {
			//If no hdp/ou ,when click sport need show outright odds
			if ((m_sports[SportType][Market] <= 0) && (m_sports[SportType]['OT'] > 0)) {
				parent.mainFrame.location.href = arrURL["0_OT"] + "?Sport=" + SportType + "&Market=" + Market.toLowerCase() + "&DispVer=" + DispVer+"&Game="+fFrame.LastSelectedMenu;
				return;
			}
			parent.mainFrame.location.href = arrURL[SportType + "_" + Market] + "?Sport=" + SportType + "&Market=" + Market.toLowerCase() + "&DispVer=" + DispVer + "&Game="+  fFrame.LastSelectedMenu;
		}
		return;
	}
	
	if (SportType == -1) {
		for (var i=1; i <= 31; i++){
			if (m_sports[i][Market] > 0) {
				SportType = i;
				return;
			}
		}
	} else if (SportType == '151') { // horse
	    if (Market=='E')
	    {
		    parent.mainFrame.location.href = arrURL["151_E"] + "?RM=E";
		}
		else
		{
		    parent.mainFrame.location.href = arrURL["151_T"] + "?RM=T";
        }
	} else if (SportType == '201') { // Finance
		if (Market == '' || Market == 'T') {
			if (m_sports[SportType]['BETS'] != '') {
				var FinanceAsset = m_sports[SportType]['BETS'].split(",")[0];
				parent.mainFrame.location.href = arrURL["201"]+"?Market="+FinanceAsset;
			}
		} else {
			parent.mainFrame.location.href = arrURL["201"] + "?Market=" + Market;
		}
	} else {
		//CrossParlay by Sport
		if(isParlay || Market=='P') {
			parent.mainFrame.location.href = arrURL["0_P"] + "?Sport=" + SportType + "&Market=" + fFrame.LastSelectedMArket + "&DispVer=" + DispVer+"&Game="+fFrame.LastSelectedMenu;
		}
		//Outright by Sport
		else if(Market == 'OT') {
			parent.mainFrame.location.href = arrURL["0_OT"] + "?Sport=" + SportType + "&Market=" + Market.toLowerCase() + "&DispVer=" + DispVer+"&Game="+fFrame.LastSelectedMenu;
		} else {
			parent.mainFrame.location.href = arrURL[SportType + "_" + Market] + "?Sport=" + SportType + "&Market=" + Market.toLowerCase() + "&DispVer=" + DispVer + "&Game="+fFrame.LastSelectedMenu;
		}
	}
}


function SwitchSport(market,sport,isCkecked,IsAutoRefresh){
//alert('market='+market);
    if(market=='')
    {
        market=fFrame.LastSelectedMArket;
    }
	
	try
	{
    	parent.mainFrame.document.body.id;
    	
    	if (market == 'P')
		    isParlay = true;
	    else if ((sport != 0) || (market =='OT') || (parent.mainFrame.document.body.id == "Outright") || (parent.mainFrame.document.body.id == ""))
            isParlay = false;
	    else
		    isParlay = true;
	}
	catch (e)
	{
	    isParlay = false;
	}
		
	//Open Selected Sport
	if (CheckCountAndSetOtherItem(market, sport)) {
		if ((market != 'L') && (market != "OT" && sport != "0" && market != "P")){
			document.getElementById(sport+'_body').style.display = '';
			if (IsFun88) document.getElementById('HAD_T' + sport).className = 'subnavon';
		}else if ((market != 'L') && (market == "OT" && sport == "0")) {
		  if (IsFun88) document.getElementById('HAD_TOT').className = 'subnavon';
        }
		//keep last selected sport item
		fFrame.LastSelectedSport = sport;

	//Close All
	} else {
	    if(sport!=151){  ////If the sport for the Horse, and also count of zero display Horse.aspx
			sport=-1;
		}
	}

	// Close non-selected sports
	this.CloseSports(market,sport);
	//if close all , need to get last selected sport to show odds
	if (sport != 151){
		sport = fFrame.LastSelectedSport;
	}
	//for first load and auto refresh
	if (IsAutoRefresh) {
		return;
	}

	if (market == 'L') {
		if ((fFrame.LastSelectedMArket == "L") || (m_sports["0"]["TotalLive"] == 0)) {
		    fFrame.LastSelectedSport = -1;
			return;
		}


	} else {
		this.ShowOdds(market, sport, fFrame.DisplayMode);
	}
}

function CloseSports(market,sport)
{
    //Scott
	for (var i = 1; i <= 31; i++) {
		if (i != sport) {
			document.getElementById(i+'_body').style.display = 'none';
			if (IsFun88) document.getElementById('HAD_T' + i).className = 'subnav';
		}
	}
	//Close other sport
	if (sport != 99) {
		document.getElementById('99_body').style.display = 'none';
		if (IsFun88) document.getElementById('HAD_T99').className = 'subnav';
	}
	//Close  Finance and  horse
	if (sport != 151) {
		document.getElementById('151_body').style.display = 'none';
		if (IsFun88) document.getElementById('HAD_T151').className = 'subnav';
	}
	if (sport != 201) {
		document.getElementById('201_body').style.display = 'none';
		if (IsFun88) document.getElementById('HAD_T201').className = 'subnav';
	}
	if (IsFun88 && market != 'OT') document.getElementById('HAD_TOT').className = 'subnav';
}

function SetMenuBaseItem(market,sport) {
	var spObj = null;
	var spObj_head = null;
	if(market=='L') {
		spObj = document.getElementById(market + '_' + sport);
	    spObj_head = document.getElementById(market+'_' + sport + '_head');
	} else {
		spObj = document.getElementById(sport + '_body');
		spObj_head = document.getElementById(sport + '_head');
	}


	if (spObj != null) {//maggie add  Early haven't Finance and Horse Race
	//Sport Link
		
		if(!CheckCountAndSetOtherItem(market,sport)){
			if(sport != 151){  //If the sport for the Horse, and also count of zero displayed 
				spObj_head.style.display='none';
				spObj.style.display='none';
			}
  
		} else {
			spObj_head.style.display='';
			spObj.style.display='';
			
			if(market=='L')
			{
				document.getElementById(market+'_'+sport+'_Cnt').innerHTML=m_sports[sport][market];
			}	
			else 
			{
			         
				if(sport == 151 || sport == 201) {  //maggie Finance and Horse Race haven't outright
				    if(sport == 151)
				    {
				        var iSiteMode = fFrame.SiteMode;
				        var topHorse = null;

				        if (iSiteMode != 2)
				        {
				            topHorse = fFrame.topFrame.document.getElementById("topHorse");
                        }
                        
						if(!fFrame.CanSeeHorseTote && !fFrame.CanSeeHorseOpenTote){  //if can not bet horse  then none displayed;
							spObj_head.style.display='none';
							spObj.style.display='none';
							document.getElementById('img_'+sport+'_nolive').style.display='none';
							document.getElementById('img_'+sport+'_live').style.display='none';
							
							if(topHorse!=null)
							{
							    topHorse.className ='fun_icon07';
							}
                           
						}
						else
						{
						    //alert('market='+market);
						    if (market=='E')
						    {
						        spObj_head.style.display='';
							    spObj.style.display='';
                                //alert('game count=' + m_sports[sport]['E']);								
								if(m_sports[sport]['T'] <= 0)   //In the Early Menu,if today have horse game , horse img still need to change to red at top menu
								{
									if(topHorse!=null)
							        {
							            topHorse.className ='fun_icon07';
							        }
								}else{
									if(topHorse!=null)
							        {
							            topHorse.className ='fun_icon08';
							        }
								}
							    if(m_sports[sport]['E']<=0)
							    {
						            document.getElementById(sport+'_Cnt').innerHTML='';
						            document.getElementById('img_'+sport+'_nolive').style.display='none';
						            document.getElementById('img_'+sport+'_nolive').style.display='none';
						            document.getElementById(sport+'_head').style.display='none';							        
						        }
                                else
                                {
                                    document.getElementById(sport+'_Cnt').innerHTML=m_sports[sport]['E'];
                                    document.getElementById('img_'+sport+'_nolive').style.display='none';
						            document.getElementById('img_'+sport+'_live').style.display='none';
    						        document.getElementById(sport+'_head').style.display='';
                                }
						    }
						    else
						    {
						        spObj_head.style.display='';
							    spObj.style.display='';

							    if(m_sports[sport]['T']<=0)
							    {
						            document.getElementById(sport+'_Cnt').innerHTML='';
						            document.getElementById('img_'+sport+'_nolive').style.display='';
						            document.getElementById('img_'+sport+'_live').style.display='none';
							        if(topHorse!=null)
							        {
							            topHorse.className ='fun_icon07';
							        }
						        }
                                else
                                {
                                    document.getElementById(sport+'_Cnt').innerHTML=m_sports[sport]['T'];
                                    document.getElementById('img_'+sport+'_nolive').style.display='none';
						            document.getElementById('img_'+sport+'_live').style.display='';
    						       
							        if(topHorse!=null)
							        {
							            topHorse.className ='fun_icon08';
							        }
                                }
                            }
                            //If LastSelectedMenu is 2 representatives is world cup,then horse racing not display
							if(fFrame.LastSelectedMenu !=0)
							{
								spObj_head.style.display='none';
								spObj.style.display='none';
							}
						}
					}
					else if(sport == 201)//Finance By Scott
					{
					    document.getElementById(sport+'_Cnt').innerHTML='';//parseInt(m_sports[sport]['T'],10);
                        var FinanceMenuBody = document.getElementById('201_body');
                        var Financeitems = FinanceMenuBody.getElementsByTagName('tr');
                     
                        for(i=0;i < Financeitems.length;i++)
                        {   
                            Financeitems[i].style.display='none';
                        }
                        
                        var FinanceOpenAssets=m_sports[sport]['BETS'].split(",");
                        /*for(j=0;j < FinanceOpenAssets.length;j++) //Finance Nobody
                        {   
                            if(document.getElementById(sport+'_'+FinanceOpenAssets[j])!=null)
                            document.getElementById(sport+'_'+FinanceOpenAssets[j]).style.display='block';
                        }*/
				    }
				}else{
					//Today and Early's Sport Count=Hdp/ou+Outright
					document.getElementById(sport+'_Cnt').innerHTML=parseInt(m_sports[sport][market],10)+parseInt(m_sports[sport]['OT'],10);
				}
			}
			
			
			
			if(sport=='201')
		    {return;}
			//HDP/OU
			if(market!='L') {
				spObj = document.getElementById(sport+'_A');
				if (m_sports[sport][market] <= 0) {
					spObj.style.display='none';
				} else {
					spObj.style.display='';
					document.getElementById(sport+'_A_Cnt').innerHTML=m_sports[sport][market];
				}
			}

			// set Live Img only for Today
			if(market!='L') {
				if(m_sports[sport]["L"]==0 || market=='E')
				{
				    if(sport!=151)
				    {
				        spObj=	document.getElementById('img_'+sport+'_LV');
					    spObj.style.display='none';
					}
				}
				else
				{
				    spObj=	document.getElementById('img_'+sport+'_LV');
					spObj.style.display='';
				}
			}


			//set TV Img for Live and Today

			    // Horse have no TV icon
		    if(sport=='151')
		    {return;}
		    if(market=='L')
			{
			
			    spObj=	document.getElementById('img_'+market+'_'+sport+'_TV');
			}
			else
			{
			    spObj=	document.getElementById('img_'+sport+'_TV');

			}
			
			if (m_sports[sport]["TV"] == 0 || market=='E' || IsM88 || IsALog || IsFun88)
			{
		        spObj.style.display='none';	
			} else {
				spObj.style.display = '';
			}

		}
	}
}

function CheckCountAndSetOtherItem(market,sport)
{

	var TotalCount=0;
	if(market=='L' && sport=='OT') {
		return false;
	}

	//if is Outright-all link,needn't check
	if(sport=='OT' || sport=='P')	{
		return true;
	}

	if(market!='L')
	{
		// Soccer non hdp and ou bet type
		if (sport == 1){
			// 1X2
			spObj = document.getElementById('1_1X2');
			if (m_sports["1"]["1X2"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display = '';
				document.getElementById('1_1X2_Cnt').innerHTML = m_sports["1"]["1X2"];
				TotalCount += m_sports["1"]["1X2"];
			}

			// FGLG
			spObj = document.getElementById( '1_FGLG');
			if (m_sports["1"]["FGLG"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display = '';
				document.getElementById('1_FGLG_Cnt').innerHTML = m_sports["1"]["FGLG"];
				TotalCount += m_sports["1"]["FGLG"];
			}

			// HTFT
			spObj = document.getElementById( '1_HTFT');
			if (m_sports["1"]["HTFT"] <= 0){
					spObj.style.display='none';
			} else {
				spObj.style.display = '';
				document.getElementById( '1_HTFT_Cnt').innerHTML = m_sports["1"]["HTFT"];
				TotalCount += m_sports["1"]["HTFT"];
			}

			//OETG
			spObj=document.getElementById( '1_OETG');
			if (m_sports["1"]["OETG"] <= 0) {
					spObj.style.display = 'none';
			} else {
				spObj.style.display='';
				document.getElementById( '1_OETG_Cnt').innerHTML = m_sports["1"]["OETG"];
				TotalCount += m_sports["1"]["OETG"];
			}

			// CS
			spObj = document.getElementById( '1_CS');
			if (m_sports["1"]["CS"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display = '';
				document.getElementById('1_CS_Cnt').innerHTML = m_sports["1"]["CS"];
				TotalCount += m_sports["1"]["CS"];
			}

			// Parlay
			spObj = document.getElementById('1_P');
			if (m_sports["1"]["P"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display = '';
				document.getElementById( '1_P_Cnt').innerHTML = m_sports["1"]["P"];
				TotalCount += m_sports["1"]["P"];
			}
		}

		// Basketball non hdp and ou bet type
		else if (sport == 2) {
			// Parlay
			spObj = document.getElementById('2_P');
			if (m_sports["2"]["P"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display = '';
				document.getElementById('2_P_Cnt').innerHTML = m_sports["2"]["P"];
				TotalCount += m_sports["2"]["P"];
			}
		}

		// Football non hdp and ou bet type
		else if (sport == 3) {
			// Parlay
			spObj = document.getElementById('3_P');
			if (m_sports["3"]["P"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display = '';
				document.getElementById('3_P_Cnt').innerHTML = m_sports["3"]["P"];
				TotalCount+=m_sports["3"]["P"];
			}
		}

		// Hockey non hdp and ou bet type
		else if (sport == 4) {
			// Parlay
			spObj = document.getElementById('4_P');
			if (m_sports["4"]["P"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display='';
				document.getElementById('4_P_Cnt').innerHTML = m_sports["4"]["P"];
				TotalCount+=m_sports["4"]["P"];
			}
		}

		// Hockey non hdp and ou bet type
		else if (sport == 5) {
			// Parlay
			spObj = document.getElementById('5_P');
			if (m_sports["5"]["P"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display='';
				document.getElementById('5_P_Cnt').innerHTML=m_sports["5"]["P"];
				TotalCount+=m_sports["5"]["P"];
			}
		}

		// Volleyball non hdp and ou bet type
		else if (sport == 6) {
			// Parlay
			spObj = document.getElementById('6_P');
			if (m_sports["6"]["P"] <= 0) {
				spObj.style.display='none';
			} else {
				spObj.style.display='';
				document.getElementById('6_P_Cnt').innerHTML=m_sports["6"]["P"];
				TotalCount+=m_sports["6"]["P"];
			}
		}

		// Billiard non hdp and ou bet type
		else if (sport == 7) {
			// Parlay
			spObj = document.getElementById('7_P');
			if (m_sports["7"]["P"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display = '';
				document.getElementById('7_P_Cnt').innerHTML = m_sports["7"]["P"];
				TotalCount += m_sports["7"]["P"];
			}
		}

		// Baseball non hdp and ou bet type
		else if (sport == 8) {
			// Parlay
			spObj = document.getElementById('8_P');
			if (m_sports["8"]["P"] <= 0) {
				spObj.style.display='none';
			} else {
				spObj.style.display='';
				document.getElementById('8_P_Cnt').innerHTML = m_sports["8"]["P"];
				TotalCount += m_sports["8"]["P"];
			}
		}

		// Badminton non hdp and ou bet type
		else if (sport == 9) {
			// Parlay
			spObj = document.getElementById('9_P');
			if (m_sports["9"]["P"] <= 0) {
				spObj.style.display='none';
			} else {
				spObj.style.display='';
				document.getElementById('9_P_Cnt').innerHTML=m_sports["9"]["P"];
				TotalCount+=m_sports["9"]["P"];
			}
		}

		// Golf non hdp and ou bet type
		else if (sport == 10) {
			// Parlay
			spObj = document.getElementById('10_P');
			if (m_sports["10"]["P"] <= 0) {
				spObj.style.display='none';
			} else {
				spObj.style.display='';
				document.getElementById('10_P_Cnt').innerHTML=m_sports["10"]["P"];
				TotalCount+=m_sports["10"]["P"];
			}
		}

		// Motorsports non hdp and ou bet type
		else if (sport == 11) {
			// Parlay
			spObj=document.getElementById('11_P');
			if (m_sports["11"]["P"] <= 0) {
				spObj.style.display='none';
			} else {
				spObj.style.display='';
				document.getElementById('11_P_Cnt').innerHTML=m_sports["11"]["P"];
				TotalCount+=m_sports["11"]["P"];
			}
		}

		// Swimming non hdp and ou bet type
		else if (sport == 12) {
			// Parlay
			spObj=document.getElementById('12_P');
			if (m_sports["12"]["P"] <= 0) {
				spObj.style.display='none';
			} else {
				spObj.style.display='';
				document.getElementById('12_P_Cnt').innerHTML=m_sports["12"]["P"];
				TotalCount+=m_sports["12"]["P"];
			}
		}

		// Politics non hdp and ou bet type
		else if (sport == 13) {
			// Parlay
			spObj=document.getElementById('13_P');
			if (m_sports["13"]["P"] <= 0) {
				spObj.style.display='none';
			} else {
				spObj.style.display='';
				document.getElementById('13_P_Cnt').innerHTML=m_sports["13"]["P"];
				TotalCount+=m_sports["13"]["P"];
			}
		}

		// Water Polo non hdp and ou bet type
		else if (sport == 14) {
			// Parlay
			spObj=document.getElementById('14_P');
			if (m_sports["14"]["P"] <= 0) {
				spObj.style.display='none';
			} else {
				spObj.style.display='';
				document.getElementById('14_P_Cnt').innerHTML=m_sports["14"]["P"];
				TotalCount+=m_sports["14"]["P"];
			}
		}

		// Diving non hdp and ou bet type
		else if (sport == 15) {
			// Parlay
			spObj=document.getElementById('15_P');
			if (m_sports["15"]["P"] <= 0) {
				spObj.style.display='none';
			} else {
				spObj.style.display='';
				document.getElementById('15_P_Cnt').innerHTML=m_sports["15"]["P"];
				TotalCount+=m_sports["15"]["P"];
			}
		}

		// Boxing non hdp and ou bet type
		else if (sport == 16) {
			// Parlay
			spObj=document.getElementById('16_P');
			if (m_sports["16"]["P"] <= 0) {
				spObj.style.display='none';
			} else {
				spObj.style.display='';
				document.getElementById('16_P_Cnt').innerHTML=m_sports["16"]["P"];
				TotalCount+=m_sports["16"]["P"];
			}
		}

		// Archery non hdp and ou bet type
		else if (sport == 17) {
			// Parlay
			spObj=document.getElementById('17_P');
			if (m_sports["17"]["P"] <= 0) {
				spObj.style.display='none';
			} else {
				spObj.style.display='';
				document.getElementById('17_P_Cnt').innerHTML=m_sports["17"]["P"];
				TotalCount+=m_sports["17"]["P"];
			}
		}

		// Table Tennis non hdp and ou bet type
		else if (sport == 18) {
			// Parlay
			spObj=document.getElementById('18_P');
			if (m_sports["18"]["P"] <= 0) {
				spObj.style.display='none';
			} else {
				spObj.style.display='';
				document.getElementById('18_P_Cnt').innerHTML=m_sports["18"]["P"];
				TotalCount+=m_sports["18"]["P"];
			}
		}

		// Weightlifting non hdp and ou bet type
		else if (sport == 19) {
			// Parlay
			spObj=document.getElementById('19_P');
			if (m_sports["19"]["P"] <= 0) {
				spObj.style.display='none';
			} else {
				spObj.style.display='';
				document.getElementById('19_P_Cnt').innerHTML=m_sports["19"]["P"];
				TotalCount+=m_sports["19"]["P"];
			}
		}

		// Canoeing non hdp and ou bet type
		else if (sport == 20) {
			// Parlay
			spObj=document.getElementById('20_P');
			if (m_sports["20"]["P"] <= 0) {
				spObj.style.display='none';
			} else {
				spObj.style.display='';
				document.getElementById('20_P_Cnt').innerHTML=m_sports["20"]["P"];
				TotalCount+=m_sports["20"]["P"];
			}
		}

		// Gymnastics non hdp and ou bet type
		else if (sport == 21) {
			// Parlay
			spObj=document.getElementById('21_P');
			if (m_sports["21"]["P"] <= 0) {
				spObj.style.display='none';
			} else {
				spObj.style.display='';
				document.getElementById('21_P_Cnt').innerHTML=m_sports["21"]["P"];
				TotalCount+=m_sports["21"]["P"];
			}
		}

		// Athletics non hdp and ou bet type
		else if (sport == 22) {
			// Parlay
			spObj = document.getElementById('22_P');
			if (m_sports["22"]["P"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display = '';
				document.getElementById('22_P_Cnt').innerHTML = m_sports["22"]["P"];
				TotalCount += m_sports["22"]["P"];
			}
		}

		// Equestrian non hdp and ou bet type
		else if (sport == 23) {
			// Parlay
			spObj = document.getElementById('23_P');
			if (m_sports["23"]["P"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display='';
				document.getElementById('23_P_Cnt').innerHTML = m_sports["23"]["P"];
				TotalCount += m_sports["23"]["P"];
			}
		}

		// Handball non hdp and ou bet type
		else if (sport == 24) {
			// Parlay
			spObj = document.getElementById('24_P');
			if (m_sports["24"]["P"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display='';
				document.getElementById('24_P_Cnt').innerHTML = m_sports["24"]["P"];
				TotalCount += m_sports["24"]["P"];
			}
		}
		
		// Darats non hdp and ou bet type
		else if (sport == 25) {
			// Parlay
			spObj = document.getElementById('25_P');
			if (m_sports["25"]["P"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display='';
				document.getElementById('25_P_Cnt').innerHTML = m_sports["25"]["P"];
				TotalCount += m_sports["25"]["P"];
			}
		}

		// Rugby non hdp and ou bet type
		else if (sport == 26) {
			// Parlay
			spObj = document.getElementById('26_P');
			if (m_sports["26"]["P"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display='';
				document.getElementById('26_P_Cnt').innerHTML = m_sports["26"]["P"];
				TotalCount += m_sports["26"]["P"];
			}
		}
		
	    // Cricket non hdp and ou bet type
		else if (sport == 27) {
			// Parlay
			spObj = document.getElementById('27_P');
			if (m_sports["27"]["P"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display='';
				document.getElementById('27_P_Cnt').innerHTML = m_sports["27"]["P"];
				TotalCount += m_sports["27"]["P"];
			}
		}
		
	    // Field Hockey non hdp and ou bet type
		else if (sport == 28) {
			// Parlay
			spObj = document.getElementById('28_P');
			if (m_sports["28"]["P"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display='';
				document.getElementById('28_P_Cnt').innerHTML = m_sports["28"]["P"];
				TotalCount += m_sports["28"]["P"];
			}
		}
		else if (sport == 29) {
			// Parlay
			spObj = document.getElementById('29_P');
			if (m_sports["29"]["P"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display='';
				document.getElementById('29_P_Cnt').innerHTML = m_sports["29"]["P"];
				TotalCount += m_sports["29"]["P"];
			}
		}
		else if (sport == 30) {
			// Parlay
			spObj = document.getElementById('30_P');
			if (m_sports["30"]["P"] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display='';
				document.getElementById('30_P_Cnt').innerHTML = m_sports["30"]["P"];
				TotalCount += m_sports["30"]["P"];
			}
		}
		else if (sport == 31) {
			// Parlay
			spObj = document.getElementById('31_P');
			if (m_sports["31"]["P"] <= 0) {
				spObj.style.display='none';
			} else {
				spObj.style.display='';
				document.getElementById('31_P_Cnt').innerHTML = m_sports["31"]["P"];
				TotalCount+=m_sports["31"]["P"];
			}
		}
		// Other Sports non hdp and ou bet type
		else if (sport == 99) {
			// Parlay
			spObj = document.getElementById('99_P');
			if (m_sports["99"]["P"] <= 0) {
				spObj.style.display='none';
			} else {
				spObj.style.display='';
				document.getElementById('99_P_Cnt').innerHTML = m_sports["99"]["P"];
				TotalCount+=m_sports["99"]["P"];
			}
		}
		//Horse Always Display
        else if (sport == 151) {
             return true;
        }
        // all outright in one page 
        else if (sport == 0) {
            return true;
        }

		//Finance and Horse Race haven't outright
		if (sport != 151 && sport != 201) {
			//Outright by sport
			spObj = document.getElementById(sport+'_OT');
			if (m_sports[sport]['OT'] <= 0) {
				spObj.style.display = 'none';
			} else {
				spObj.style.display = '';
				document.getElementById(sport + '_OT_Cnt').innerHTML = m_sports[sport]['OT'];
				TotalCount += m_sports[sport]['OT'];
			}
		}
	}
	//add hdp/ou count
	TotalCount += m_sports[sport][market];

	if (TotalCount <= 0) {
		return false;
	}
	return true;
}

function SetMenuItem(market) {
	var spObj = null;
	var spObj_head = null;
	var objShowFavorite = null;
	var sLang = fFrame.UserLang;
	// My favorite menu
	if ((fFrame.IsLogin)&&(fFrame.SiteMode != 1)&&(!IsM88)&&(!IsALog))
	{
		if(document.getElementById('div_favorite') != null){
			objShowFavorite = document.getElementById('div_favorite');
			objShowFavorite.className = sLang + "_favoritemenu";
			objShowFavorite.style.display = '';
		}
	}
	
	//Sport 1-31
	for (var i = 1; i <= 31; i++) {
		this.SetMenuBaseItem(market,i);
	}

	// Sport 99
	this.SetMenuBaseItem(market, 99);

	// Horse Racet 151
	this.SetMenuBaseItem(market, 151);

	// Finance 201
	this.SetMenuBaseItem(market, 201);

	if (market != 'L'){
		//Outright
		spObj_head = document.getElementById('OT_head');
		if(m_sports["OT"][market] <= 0) {
			spObj_head.style.display='none';
		}	else{
			spObj_head.style.display='';
			document.getElementById('OT_Cnt').innerHTML = m_sports["OT"][market];
		}
		
		//CrossParlay
		if(document.getElementById('P_head') != undefined)
		{
			spObj_head = document.getElementById('P_head');
			if(m_sports["P"][market] <= 0) {
				spObj_head.style.display='none';
			}	else{
				spObj_head.style.display='';
				document.getElementById('P_Cnt').innerHTML = m_sports["P"][market];
			}
		}
	}
	else{
		// Set Live All Sports
		spObj_head=document.getElementById(market+'_A_head');
		if(m_sports["0"]["TotalLive"] <= 0) {
			spObj_head.style.display='none'
		} else {
			spObj_head.style.display='';
			document.getElementById(market+'_A_Cnt').innerHTML=m_sports["0"]["TotalLive"];

			//set Live All Sports TV Img
			spObj = document.getElementById('img_' + market + '_A_TV');
			if(m_sports["0"]["TV"] == 0) {
				spObj.style.display = 'none';
			}	else {
				if(IsM88 || IsALog  || IsFun88){  //Mansion88 Live  haven't  all image icon
					spObj.style.display = 'none';
				}else{
					spObj.style.display = '';
				}
			}
		}
	}
}

function SetLastSelectedSport(market, IsAutoRefresh) {
	//for Olympics show all early ot today
	if ( (fFrame.LastSelectedMenu == 1) && (fFrame.LastSelectedSport == -1) && (market != 'L') ) {
		this.CloseSports("T", -1);
		this.CloseSports("E", -1);
		if (!IsAutoRefresh) {
			parent.mainFrame.location.href = "Olympics.aspx?market=" + market;
		}
	}
	//Fist Load Menu , Set Default Selected Sport
	else if (fFrame.LastSelectedSport == -1) {
		for (var i = 1; i <= 31; i++) {	        
			if(m_sports[i][market] > 0 || m_sports[i]['OT'] > 0 || m_sports[i]['P'] > 0){
				if ((m_sports[i][market] <= 0) && (m_sports[i]['OT'] > 0)) IsAutoRefresh=false; // if no HDp,the go to Ourtight page
				SwitchSport(market, i, false, IsAutoRefresh);
				return;
			}

		}
	} else {
		SwitchSport(market,fFrame.LastSelectedSport,false,IsAutoRefresh);
	}
}

function LoadMenuData(market, IsAutoRefresh) {
	if (m_sports == null) {
		return;
	}

	market = GetBestMarket(market);

	//no any games
	if (market == null) {
		return;
	}

	this.SwitchMarket(market)

	this.CheckSwitchMenu(IsAutoRefresh);

	this.SetMenuItem(market);

	this.SetLastSelectedSport(market,IsAutoRefresh);
}

//if menu is hide , need to change img to show
function CheckSwitchMenu(IsAutoRefresh) {
	var objShowMenu = parent.document.getElementById('div_menu');
	if (objShowMenu != null) {
		var cname = objShowMenu.className;
		if (cname.indexOf('_showmenu') >= 0) {
			//if is autorefresh,still keep hide status
			if(IsAutoRefresh) {
				var objBody = document.getElementById('market_' + fFrame.LastSelectedMArket + '_body');
				objBody.style.display='none';
			} else {
				objShowMenu.className = cname.replace('_showmenu', '_hidemenu');
			}
		}
	}
}

function SwitchMarket(Market) {
	var objMarket;
	fFrame.LastSelectedMArket = Market;

	try {
	    if(parent.mainFrame.document.body == null)
	        return;
	        
		if(parent.mainFrame.document.body.id == "MixParlay")
			isParlay = true;
		else
			isParlay = false;
	}
	catch (e) {
		isParlay = false;
	}
	
	if (Market == 'L') {
		// set menu head
		objMarket = document.getElementById('market_L_head');
		objMarket.className = 'itemrdon';
		objMarket = document.getElementById('market_T_head');
		objMarket.className = 'itemrd';
		objMarket = document.getElementById('market_E_head');
		objMarket.className = 'itemrd';

		//set menu body
		objMarket = document.getElementById('market_L_body');
		objMarket.style.display = (ShowMenuFlag) ? "" : "none";
		objMarket = document.getElementById('market_body');
		objMarket.style.display = 'none';
	}

	if (Market == 'T') {
		// set menu head
		objMarket = document.getElementById('market_T_head');
		objMarket.className='itemrdon';
		objMarket = document.getElementById('market_E_head');
		objMarket.className='itemrd';
		objMarket = document.getElementById('market_L_head');
		objMarket.className='itemrd';
		//set menu body

		objMarket = document.getElementById('market_body');
		//objMarket.style.display = '';
		objMarket.style.display = (ShowMenuFlag) ? "" : "none";
		objMarket = document.getElementById('market_L_body');
		objMarket.style.display = 'none';
	}

	if (Market == 'E') {
		// set menu head
		objMarket = document.getElementById('market_E_head');
		objMarket.className = 'itemrdon';
		objMarket = document.getElementById('market_T_head');
		objMarket.className = 'itemrd';
		objMarket = document.getElementById('market_L_head');
		objMarket.className = 'itemrd';

		//set menu body
		objMarket = document.getElementById('market_body');
		//objMarket.style.display = '';
		objMarket.style.display = (ShowMenuFlag) ? "" : "none";
		objMarket = document.getElementById('market_L_body');
		objMarket.style.display = 'none';
	}
}

function GetBestMarket(Market) {
	var sMarket = Market;
	// Check Live Count and hide Live text
	if (m_sports["0"]["TotalLive"] == 0) {
		document.getElementById('market_L_text').style.display = 'none';
		document.getElementById('market_L_head_Cnt').innerHTML = '';
		if (sMarket == 'L') {
			sMarket = 'T';
		}
	} else {
		document.getElementById('market_L_text').style.display = '';
		document.getElementById('market_L_head_Cnt').innerHTML = m_sports["0"]["TotalLive"];
	}

	// Check Today Count and hide Today text
	if (m_sports["0"]["TotalToday"] == 0) {
		document.getElementById('market_T_text').style.display = 'none';
		if (sMarket == 'T') {
			sMarket = 'E';
		}
	} else {
		 document.getElementById('market_T_text').style.display = '';
	}

	// Check Early Count and hide Early text
	if (m_sports["0"]["TotalEarly"] == 0) {
		if (sMarket == 'E') {
			document.getElementById('market_E_text').style.display = 'none';
			// hide all market body
			document.getElementById('market_body').style.display = 'none';
			document.getElementById('market_L_body').style.display = 'none';
			sMarket = null;
		}
	} else {
		document.getElementById('market_E_text').style.display='';
	}
	
	return sMarket;
}

function SetMenuData(SportsArray, imgsrc) {
	if (SportsArray != null) {
		//SportsArray['201']['T']=0;
		m_sports = SportsArray;
	}
    
	if (!Tmpl_Initialed) {
		window.setTimeout("SetMenuData(null,'" + imgsrc + "')", 200);
		return;
	}

	//first Load Menu
	if (fFrame.LastSelectedMArket == null) {
		LoadMenuData('T',true);
	} else {
		if (IsChangeMenuType) {
			LoadMenuData('T');
			IsChangeMenuType = false;
		} else {
			LoadMenuData(fFrame.LastSelectedMArket, true);
		}
	}
	// Set LastSelectedMenu Img
	m_mouseover(fFrame.LastSelectedMenu,imgsrc);

}

function ifrmaeresizt(){
//	var ifrmH = parent.document.getElementById('ifmMenu');

//	ifrmH.height = document.body.scrollHeight + 10;
//document.getElementById("MenuContainer").style.height = window.top.document.getElementById('Menu_tmpl').contentWindow.document.body.scrollHeight;
document.getElementById("MenuContainer").style.display='inline';
}

// hide or show all menu body
function SwitchMenu(lang)
{
	var objBody
    if(fFrame.LastSelectedMArket=='L')
    {
	    objBody = document.getElementById("market_" + fFrame.LastSelectedMArket + "_body");
	}
	else
	{
	     objBody = document.getElementById("market_body");
	}
	var objShowMenu = document.getElementById('div_menu');
	if (ShowMenuFlag) {
		objShowMenu.className = lang + "_showmenu";
		objBody.style.display='none';
	} else {
		objShowMenu.className = lang + "_hidemenu";
		objBody.style.display = "";
	}
	ShowMenuFlag = !ShowMenuFlag;

}

function openMenu(lang) {
	var objBody
    if(fFrame.LastSelectedMArket=='L')
    {
	    objBody = document.getElementById("market_" + fFrame.LastSelectedMArket + "_body");
	}
	else
	{
	     objBody = document.getElementById("market_body");
	}
	var objShowMenu = document.getElementById('div_menu');
	//after login
	if(objShowMenu!=null) {
		objShowMenu.className = lang + "_hidemenu";
	}
	
	if (objBody != null)
	{
	    objBody.style.display = "";
	}
	ShowMenuFlag = true;
}
	
function hideMenu(lang) {
	var objBody
    if(fFrame.LastSelectedMArket=='L')
    {
	    objBody = document.getElementById("market_" + fFrame.LastSelectedMArket + "_body");
	}
	else
	{
	     objBody = document.getElementById("market_body");
	}
	var objShowMenu = document.getElementById('div_menu');

	//after login
	if(objShowMenu!=null) {
		objShowMenu.className = lang + "_showmenu";
	}
	
	if (objBody!=null)
	{
	    objBody.style.display = 'none';
	}
	ShowMenuFlag = false;
}

var popWindow = null;
function PopHorseFormGuide()
{
    if(!fFrame.IsLogin)
        return;
        
    wx=990;
    wy=450;
    x=(screen.width-wx)/2;
    y= x=(screen.height-wx)/2;
    
    if (!popWindow || popWindow.closed) {
        // store new window object in global variable
        popWindow =  window.open('http://icard.276868.com/','sub','toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes, location=yes, status=no,left='+x+',top='+y+',width='+wx+',height='+wy);

    } else {
        // window already exists, so bring it forward
        popWindow.focus()
    }
}

var HorseInfoPopWindow;
var HorseInfoUrl;
function PopHorseInfo(LeagueID,RaceNumber)
{
    HorseInfoUrl = 'HorseInfoPop.aspx?League=' + LeagueID + '&Race=' + RaceNumber;
    if (!HorseInfoPopWindow || HorseInfoPopWindow.closed) 
    {
        wx=610;
        wy=700;
        x=(screen.width-wx)/2;
        y= x=(screen.height-wx)/2;
    
        // store new window object in global variable
        HorseInfoPopWindow =  window.open(HorseInfoUrl ,'subInfo','left='+x+',top='+y+',width='+wx+',height='+wy);
        //popHorseInfoWindow.scrollbars.visible =true;
    } else {    
        // window already exists, so bring it forward
        if (!HorseInfoPopWindow.closed)
        {
            HorseInfoPopWindow.location.href = HorseInfoUrl;
            HorseInfoPopWindow.focus();
            HorseInfoPopWindow.document.focus;
        }
    }
}

function CloseHorseInfoPopWindow()
{
    try{
        if (HorseInfoPopWindow != null && HorseInfoPopWindow.open)
        { 
            HorseInfoPopWindow.close();
            HorseInfoPopWindow=null;
        }
        
	    if (window.top.StreamingFrame != null || window.top.StreamingFrame.open)
	    {
            window.top.StreamingFrame.close();
            window.top.StreamingFrame=null;
        }
    } catch(e) {
    }
}

function SetMenutest(){
	alert('SetMenutest');
	SwitchSport('','151');
}
