Console.prevDivCount=0;
Console.prevDivStops=new Array(10,130,250,370);
Console.prevDivResetPos=530;

g_validateCreditCard=false;

Console.PREVIEW_BANDWIDTH = 200000;

function menuover(a)
{
	a.parentNode.parentNode.cells[0].firstChild.style.visibility = "visible";
}
function menuout(a)
{
	a.parentNode.parentNode.cells[0].firstChild.style.visibility = "hidden";
}

function navTabClick(x)
{
	if(!areAdsPlaying())
	{
		var tbl = document.getElementById("tabsTable");
		for(var i=0;i<tbl.rows[0].cells.length;i++)
			tbl.rows[0].cells[i].className = "tab1";
		if(x>=0 && x<tbl.rows[0].cells.length)
			tbl.rows[0].cells[x].className = "tab1_sel";
			
		tbl = document.getElementById("tabsTable_lg");
		for(var i=0;i<tbl.rows[0].cells.length;i++)
			tbl.rows[0].cells[i].className = "tab1";
		if(x>=0 && x<tbl.rows[0].cells.length)
			tbl.rows[0].cells[x].className = "tab1_sel";
		
		tbl = document.getElementById("tabsTable");
		if (Console.MODE_LARGE==_console.m_consoleMode)
		{
			tbl.rows[0].style.display = "none";
			tbl.rows[1].style.display = "";
		}
		else
		{
			tbl.rows[0].style.display = "";
			tbl.rows[1].style.display = "none";
		}
	}
}

function menuBrowseClick(id, component, componentName)
{
	var td=document.getElementById("cat_"+id);
	if (td!=null)
		navTabClick(td.getAttribute("tabNum"));
	else
		navTabClick(-1);
	if(componentName==null)
		componentName = "Browse";
	_console.showComponent(componentName);
	if(component==null)
		component = _browse;
	component.getCategory(id);
}

function menuClick(bShow)
{
	var tbl=document.getElementById("console_tblMenu");

	if (bShow==true || tbl.offsetLeft!=0)
		tbl.anim_destX=0;
	else
		tbl.anim_destX=-230;

	_animation.startAnimation(tbl);
}

function fpMenuItemClick(i)
{
	var strFunction="menuItemClick("+i+")";
	setTimeout(strFunction,0);
}
function menuItemClick(i)
{
	if(window._console)
	{
		navTabClick(-1);
		switch(i)
		{
		case 0:
			//_console.showComponent('Account');
			//_account.getAccount();
			accountModal();
			break;
		case 1:
			window.open('help.htm');
			break;
		case 2:
			window.open('about.htm');
			break;
		}
	}
}

function forumClick(x)
{
	var tr = document.getElementById("forum_ids");
	for(var i=0;i<tr.cells.length;i++)
	{
		if(tr.cells[i].getAttribute("forumid")==x)
		{
			tr.cells[i].className = "tab1_sel";
			tr.cells[i].firstChild.style.visibility = "visible";
		}
		else
		{
			tr.cells[i].className = "tab1";
			tr.cells[i].firstChild.style.visibility = "hidden";
		}
	}
	_forum.getForum(x);
}

function onStartAnimation(obj)
{
	if (obj.id=="console_tblMenu")
	{  
		if (!_util.isie)
		   document.getElementById("wmppane").style.visibility="hidden";
	}
}

function onStopAnimation(obj)
{
	if (obj.id=="console_tblMenu")
	{
		if (!_util.isie && obj.offsetLeft!=0)
		   document.getElementById("wmppane").style.visibility="visible";
	}
}

Console.MODE_REGULAR = 0;
Console.MODE_LARGE = 1;
Console.VIDEO_HIGHLIGHT_W = "whighlight";
Console.VIDEO_HIGHLIGHT_F = "fhighlight";

function updateShareLinksForHighlights(objItem)
{
	var arrTypes=new Array("goal", "hit", "save", "playergoal", "playersave", "game");
	if (_util.inArray(arrTypes, objItem.highlightType))
	{
		var input = document.getElementById("detailsShareLink");
		var v = location.href;
		v = v.substring(0, v.lastIndexOf("/"));
		switch(objItem.highlightType)
		{
		case "game":
			input.value = v + "/launch.htm?hlg="+objItem.gameSeason+","+objItem.gameType+","+objItem.gameId;
			break;
		case "goal":
		case "hit":
		case "save":
			input.value = v + "/launch.htm?hlg="+objItem.gameObjItem.gameSeason+","+objItem.gameObjItem.gameType+","+objItem.gameObjItem.gameId+"&event="+objItem.eventId;
			break;
		default:
			input.value = v + "/launch.htm?hlp="+objItem.playerId+"&event="+objItem.eventId;
		}		
		var input = document.getElementById("detailsShareEmbed");
		var str = "<iframe width=\"480\" height=\"360\" frameborder=\"0\" src=\"";
		var v = location.href;
		v = v.substring(0, v.lastIndexOf("/"));
		str += v;
		switch(objItem.highlightType)
		{
		case "game":
			str += "/embed?hlg="+objItem.gameSeason+","+objItem.gameType+","+objItem.gameId;
			break;
		case "goal":
		case "hit":
		case "save":
			str += "/embed?hlg="+objItem.gameObjItem.gameSeason+","+objItem.gameObjItem.gameType+","+objItem.gameObjItem.gameId+"&event="+objItem.eventId;
			break;
		default:
			str += "/embed?hlp="+objItem.playerId+"&event="+objItem.eventId;
		}		
		str += "\"></iframe>"
		input.value = str;
	}
}

function updateDetailsForHighlights(objItem)
{
	var tblDest=null;
	var arrTypes=new Array("goal", "hit", "save", "playergoal", "playersave", "game");
	if (_util.inArray(arrTypes, objItem.highlightType))
	{
		tblDest=_highlight.createDetailsGameTable(objItem.highlightType, objItem);
		updateShareLinksForHighlights(objItem);
	}
	
	if (tblDest!=null)
	{
		document.getElementById("content_Details").innerHTML="";
		document.getElementById("content_Details").appendChild(tblDest);
		document.getElementById("content_Similar").innerHTML ="";
		showDetailsTab(0);
	}
}
function __playCustomVideo(videoType, videoId, videoPath, videoFormats)
{
	var ret = null;
	if(Console.VIDEO_HIGHLIGHT_F==videoType || Console.VIDEO_HIGHLIGHT_W==videoType)
	{
		var objItem=null;
		
		if (videoId!=null)
		{
			objItem=m_objItems[videoId.getAttribute("objItem")];
			updateDetailsForHighlights(objItem)
			ret = new Object();
			ret.path = videoPath;
			ret.isLive = false;
			ret.autoDetect = true;
			ret.disableEncryptVideoPath = true;
			ret.trackString = "Highlight " + _highlight.formatCategoryText(objItem.highlightType) + ": ";
			switch(objItem.highlightType)
			{
			case "game":
				ret.trackString += "Game " + objItem.gameId + " - " + objItem.awayTeamName + " @ " + objItem.homeTeamName + " on " + objItem.gameDate;
				break;
			default:
				ret.trackString += objItem.eventId;
			}
			ret.trackId = objItem.eventId;
		}
	}
	return ret;
}
function __showCurrentVideoCustomInfo(lastVideo)
{
	if(Console.VIDEO_HIGHLIGHT_F==lastVideo.type || Console.VIDEO_HIGHLIGHT_W==lastVideo.type)
	{
		var objItem = m_objItems[lastVideo.id.getAttribute("objItem")];
		updateDetailsForHighlights(objItem);
	}
}

function __changeLayoutMode(mode)
{
	var player=document.getElementById("fplayer");
	if (player!=null && player.layoutChange!=null)
		player.layoutChange((mode==Console.MODE_LARGE)?true:false);
}

function __showComponent(name)
{
	hidePlayImg();
	var component = this.m_components[name];
	if(component!=null)
	{
		for(n in this.m_components)
		{
			document.getElementById("pane_" + n).style.display = "none";
		}
		component.display();
		document.getElementById("pane_" + name).style.display = "";
	}
	
	if (name=="Login")
	   navTabClick(-1);

	if (_console.bIsLockedDown==true)
		document.body.style.backgroundImage="url(../images/branding/login_mainbg.jpg)";
		
	_util.cancelEvt(window.event);
}

function __showDetails(type, pid)
{
	this.m_details.showDetails(type, pid);
	showDetailsTab(0);
}

function tabClick(tblContent_id, index)
{
	var table = document.getElementById(tblContent_id);
	for(var i=0;i<table.rows.length;i++)
		table.rows[i].style.display = "none";
	table.rows[index].style.display = "";
}

function __tabSearchClick(tabNum)
{
	tabClick('tabContents_Search', tabNum)
}

function onPasteRegToken(event)
{
	var strClipboard=window.clipboardData.getData("Text");
	if (strClipboard!=null)
	{
		var str1=strClipboard.substring(0,4);
		var str2=strClipboard.substring(5,9);
		var str3=strClipboard.substring(10,14);
		if (str1!="")
			document.getElementById("txtToken1").value=str1;
		if (str2!="")
			document.getElementById("txtToken2").value=str2;
		if (str3!="")	
			document.getElementById("txtToken3").value=str3;
	}
	event.returnValue = false;
}
function showDetailsTab(iTabIndex)
{
	if(!areAdsPlaying())
	{
		for (var i=0; i<3; i++)
			document.getElementById("detailstab_"+i).className="detailstab";
	
		document.getElementById("detailstab_"+iTabIndex).className="detailstab_sel";
		
		document.getElementById("pane_Details").style.display="none";
		document.getElementById("pane_Similar").style.display="none";
		document.getElementById("pane_ShareVideo").style.display="none";
		
		switch(iTabIndex)
		{
			case 0:
				document.getElementById("pane_Details").style.display="";
				break;
			case 1:
				document.getElementById("pane_Similar").style.display="";
				break;
			case 2:
				document.getElementById("pane_ShareVideo").style.display="";
				break;
		}
	}
}

var g_lastOrderId=null;
var g_mainOrderWin=null;

function checkOrderWindowClosed()
{
	if (window.g_mainOrderWin==null)
		return;
	
	if (!window.g_mainOrderWin.closed)
		setTimeout("checkOrderWindowClosed()", 1000);
	else
		orderModalCallback(null);
}

function orderModal(programId)
{
	var args=new Array();
	args[0]=window;
	args[1]=programId;
	g_lastOrderId=programId;
	// _util.showModal("secure/orderform",args,null,orderModalCallback,600,450,null,true);

	g_mainOrderWin = window.open("secure/orderform?id="+programId, "MODALORDER", "width=700,height=550,resizable=1,scrollbars=1,alwaysRaised=yes,dependent=yes");
    g_mainOrderWin.focus();
	/// Firefox:  _util.showModal("secure/orderform?id="+programId,args,null,orderModalCallback,600,450,null,true);

	setTimeout("checkOrderWindowClosed()", 3000);
}

function orderModalCallback(ret)
{
	var args=new Object();
	_console.showDetails(Console.VIDEO_VOD,g_lastOrderId);
	// alert("Order Modal CB");
}

function accountModal(programId)
{
	var args=new Array();
	args[0]=window;
	_util.showModal("accountmodal.jsp",args,null,accountModalCallback,600,500,null,true);
}

function accountModalCallback(ret)
{
}

var g_disableEncryptVideoPath = false;
function getEncryptedVideoPath(type, path)
{
	var ret = path;
	if(!g_disableEncryptVideoPath)
	{
		ret = "";
		var args = new Object();
		args.type = type;
		args.path = path;
		var xml = _console.getComponentContentSynch("encryptvideopath", args, true);
		if(typeof(xml)!="string")
		{
			try
			{
				var newpath = _util.selectSingleNodeText(xml, "/result/path");
				if(newpath==null)
				{
					alert("Video Path Encryption: Invalid returned xml");
				}
				else
					ret = newpath;
			}
			catch(e)
			{
				alert("Video Path Encryption:  Invalid xml value: '"+xml+"'");
			}
		}
		
		if(ret.length==0)
			alert(getLocalizedString("invalid_video_url"));
	}
	return ret;
}
function trackAction(params, linkName)
{
}
function trackVideoStart(name, id, len)
{
	var params = new Object();
	params.events = "event6";
	if(len!=null)
	{
		params.events += ",event9";
		params.products = ";;;;event9="+len;
	}
	params.prop10 = name;
	params.eVar10 = id;
	trackAction(params,"Video Start");
}
function trackVideoEnd(name, id)
{
	var params = new Object();
	params.events = "event7";
	params.prop10 = name;
	params.eVar10 = id;
	trackAction(params,"Video End");
}
function trackVideoHalf(name, id)
{
	var params = new Object();
	params.events = "event8";
	params.prop10 = name;
	params.eVar10 = id;
	trackAction(params,"Video 50%");
}
function trackBrowse(trail)
{
	var params = new Object();
	params.prop1 = "TV";
	if(window.s!=null)
		params.hier1 = s.channel + "," + params.prop1;
	var max = 4;
	if(trail.length<max);
		max = trail.length;
	for(var i=0;i<max;i++)
	{
		params["prop"+(i+2)] = trail[i];
		params.hier1 += "," + trail[i];
	}
	trackAction(params,"Browse");
}
function trackSearch()
{
	var params = new Object();
	params.events = "event1";
	trackAction(params,"Search Results");
}

var bInit=false;
var g_iMenuOffset=0;
function menuMoveClick(idTable, bLeft)
{
	var menuTbl=document.getElementById(idTable);

	if (bInit==false)
	{	bInit=true;
		_animation.registerItem(menuTbl,12,null,null);
		g_iMenuOffset=menuTbl.rows[0].cells[0].offsetWidth+2;
		menuTbl.anim_destX=0;
	}

	if (bLeft)
	{
		if (menuTbl.offsetLeft<0)
			menuTbl.anim_destX+=g_iMenuOffset;
		else
			menuTbl.anim_destX=0;
		
		 _animation.startAnimation(menuTbl);
	}
	else
	{
		var max=(-1*menuTbl.offsetWidth + document.getElementById("menuTabDiv").offsetWidth);

		if (menuTbl.offsetLeft > max)
            menuTbl.anim_destX-=g_iMenuOffset;
        else
            menuTbl.anim_destX=max;

        _animation.startAnimation(menuTbl);
	}
}

function writeFlashObject(src,locale,fid,w,h,flashvars)
{
  if (flashvars==null)
	  flashvars="";

  // Check to see if a player with Flash Product Install is available and the version does not meet the requirements for playback
  if ( hasProductInstall && !hasRequestedVersion ) {
	// MMdoctitle is the stored document.title value used by the installation process to close the window that started the process
	// This is necessary in order to close browser windows that are still utilizing the older version of the player after installation has completed
	// DO NOT MODIFY THE FOLLOWING FOUR LINES
	// Location visited after installation is complete if installation is required
	var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
	var MMredirectURL = window.location;
    document.title = document.title.slice(0, 47) + " - Flash Player Installation";
    var MMdoctitle = document.title;

	AC_FL_RunContent(
		"src", "scripts/playerProductInstall",
		"FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+'&'+flashvars,
		"width", w,
		"height", h,
		"align", "middle",
		"id", fid,
		"quality", "high",
		"bgcolor", "#869ca7",
		"name", fid,
		"allowScriptAccess","sameDomain",
		"type", "application/x-shockwave-flash",
		"pluginspage", "http://www.adobe.com/go/getflashplayer"
	);
  } else if (hasRequestedVersion) {
	// if we've detected an acceptable version
	// embed the Flash Content SWF when all tests are passed
	
	if(locale!=null && locale!="en_US")
		src += "_"+locale;
	
	AC_FL_RunContent(
			"flashVars",flashvars,
			"src", src,
			"width", w,
			"height", h,
			"align", "middle",
			"id", fid,
			"quality", "high",
			"bgcolor", "#869ca7",
			"name", fid,
			"allowScriptAccess","sameDomain",
			"wmode","transparent",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
	);
  } else {  // flash is too old or we can't detect the plugin
    var alternateContent = 'This content requires the Adobe Flash Player. '
   	+ '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
    document.write(alternateContent);  // insert non-flash content
  }
}

// Callback for onClick in Flash Live Event
function liveEventCallback(isLive)
{
	if(window._console!=null && !areAdsPlaying())
	{
		navTabClick(-1);
		_console.showComponent("LiveEvent");
	}
}
