// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// -----------------------------------------------------------------------------

// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
var hasProductInstall = DetectFlashVer(6, 0, 65);

// Version check based upon the values defined in globals
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

var g_lastPath = null;
var g_lastId = null;
var g_lastChannelId = null;
var g_isIE = (window.navigator.userAgent.indexOf("MSIE")>0);

var g_embed = false;

// for all star configuration
var g_allstar = true;
var g_allstarplayer = "http://ahl.neulion.com/allstarlive/console.html";

var g_gl_code = "UA-5069510-6";
var g_usesecure = true;
var g_highlightCatId = 31;
var g_vodCatId = 32;
var g_rightAdTimerNum = 5;			// unit second, if it is less than 0, the right ad will not be closed.

var g_playoff4_preview_view = 5;	// unit minutes
var g_playoff4_preview_wait = 10;	// unit minutes

var g_playoff4_desc_teamA_name = "Hershey Bears Team Pass";
var g_playoff4_desc_teamA_high = "Follow The Bears Through The Calder Cup Finals! ";
var g_playoff4_desc_teamA_detail = "All of the home and away games are at your fingertips in a customized Hershey video player as your Bears make a run at the Calder Cup.";
var g_playoff4_desc_teamA_price = "$40  For the Championship Round";

var g_playoff4_desc_teamB_name = "Manitoba Moose Team Pass";
var g_playoff4_desc_teamB_high = "Follow The Moose Through The Calder Cup Finals! ";
var g_playoff4_desc_teamB_detail = "All of the home and away games are at your fingertips in a customized Manitoba video player as your Moose make a run at the Calder Cup.";
var g_playoff4_desc_teamB_price = "$40  For the Championship Round";

var g_playoff4_desc_gamepass_name = "Calder Cup Finals Game Pass";
var g_playoff4_desc_gamepass_high = "Most Flexible!  ";
var g_playoff4_desc_gamepass_detail = "Don't miss a minute of Calder Cup Finals action, as the Hershey Bears and Manitoba Moose vie for the right to hoist the Calder Cup.  Select the game you want to watch, and choose either the home team or away team audio broadcast.";
var g_playoff4_desc_gamepass_price = "$8  Per Live Game";

var g_mainRegWin=null;
var g_mainRegSWin=null;
var g_mainGcBuyWin=null;
var g_mainGcWin=null;
var g_mainStarWin=null;
var g_allStarWin=null;
var g_feedbackWin=null;
var _console2 = new Console2();
var _util = new Util();
var g_x = null;
var g_y = null;
var g_volume = null;
var g_checkOk = false;
var g_promo_video = "";
//http://172.16.0.246:8080/storage/usl/cdn/ahl_monsters_T03_20090417.wmv?eid=102&pid=102&gid=102?nvb=20090430032607&nva=20090506032607&hash=0587238f6c92adb767258";//"http://smb.cdn.neulion.com/u/ahl/promo/calder_cup_promo.wmv";

//unit is msec, default is 60 seconds
var refreshLiveGameScoreTimeNum=60000;
var audioTimer;
var ffLoderTimer;

//The url which user use for registeration.
var currentRegUrl = "";
var currentRegWindow;

var serverStr = "server=" + getServer();
var consoleStr = "";

function getSecureUrl()
{
	var url = "https://" + document.location.host + document.location.pathname;
	url = url.substring(0,url.lastIndexOf("/")+1);
	return url;
}

function openRegPage(type)
{
	switch(type)
	{
		case "aa":
		case "eb":
		case "sp":
		case "ag":
		case "od":
		case "ma":
		case "na":
			var arr=[type,"","","","","","","","",getSecureUrl()];
			consoleProxy("openRegistration", arr);
			break;
		case "pg":
			consoleCallback("gotoLiveTab", "");
			break;
	}
}

function consoleProxy(action, value)
{
	switch(action)
	{
		case "openRegistration":
			var url=value[9]+"secure/registerform?is_modal=yes";
			if (value.length == 12)
			{
				url=value[9]+"secure/registerplayoff?is_modal=yes";
				url+="&type="+value[10];
				url+="&round="+value[12];
			}
			url+="&pt="+value[0];
			if(value[1]!="")url+="&date="+value[1];
			if(value[2]!="")url+="&time="+value[2];
			if(value[3]!="")url+="&home="+value[3];
			if(value[4]!="")url+="&away="+value[4];
			if(value[5]!="")url+="&owner="+value[5];
			if(value[6]!="")url+="&tenantid="+value[6];
			if(value[7]!="")url+="&pid="+value[7];
			if(value[8]!="")url+="&pname="+value[8];
				
			g_mainRegWin = window.open(url,"registration_","scrollbars=yes,menubar=no,height=768,width=1024,top=0,left=0,resizable=no,toolbar=no,location=no,status=yes");
			if(g_mainRegWin!=null)
				g_mainRegWin.focus();
			checkRegWindowClosed();
			currentRegUrl = url;
			currentRegWindow = g_mainRegWin;
			break;
		case "openSimpleRegister":
			var url=getSecureUrl()+"secure/simpleregform?is_modal=yes";
			g_mainRegSWin = window.open(url,"simpleregister_","scrollbars=yes,menubar=no,height=768,width=1024,top=0,left=0,resizable=no,toolbar=no,location=no,status=yes");
			if(g_mainRegSWin!=null)
				g_mainRegSWin.focus();
			checkRegSWindowClosed();
			currentRegUrl = url;
			currentRegWindow = g_mainRegSWin;
			break;
		case "openGiftCardBuy":
			var url=value[0]+"secure/giftcardbuy?fromConsole=true"
				
			g_mainGcBuyWin = window.open(url,"gcbuywin_","scrollbars=yes,menubar=no,height=768,width=1024,top=0,left=0,resizable=no,toolbar=no,location=no,status=yes");
			if(g_mainGcBuyWin!=null)
			{
				g_mainGcBuyWin.focus();
			}
			checkGcBuyWindowClosed();
			currentRegUrl = url;
			currentRegWindow = g_mainGcBuyWin;
			break;
		case "openGiftCard":
			var url=value[0]+"secure/giftcard?is_modal=yes"
				
			g_mainGcWin = window.open(url,"gcwin_","scrollbars=yes,menubar=no,height=768,width=1024,top=0,left=0,resizable=no,toolbar=no,location=no,status=yes");
			if(g_mainGcWin!=null)
				g_mainGcWin.focus();
			checkGcWindowClosed();
			currentRegUrl = url;
			currentRegWindow = g_mainGcWin;
			break;
		case "openFeedback":				
			g_feedbackWin = window.open("feedback.htm","feedback_","scrollbars=yes,menubar=no,height=540,width=710,top=0,left=0,resizable=no,toolbar=no,location=no,status=yes");
			if(g_feedbackWin!=null)
				g_feedbackWin.focus();
			currentRegUrl = url;
			currentRegWindow = g_feedbackWin;
			break;
		case "openAllStar":
			var url=value[0]+"secure/allstarbuy?is_modal=yes"
			g_mainStarWin = window.open(url,"starwin_","scrollbars=yes,menubar=no,height=768,width=1024,top=0,left=0,resizable=no,toolbar=no,location=no,status=yes");
			if(g_mainStarWin!=null)
				g_mainStarWin.focus();
			checkSatrWindowClosed();
			currentRegUrl = url;
			currentRegWindow = g_mainStarWin;
			break;					
		case "detectPlugins":
			var fit = true;
			var isMac = (navigator.platform.indexOf("Mac") == 0);
			if (!g_isIE && !isMac)
			{
				var fileName = navigator.mimeTypes["application/x-mplayer2"].enabledPlugin.filename;
				if (fileName != "np-mswmp.dll") fit = false;
			}
			return fit;
			break;
		case "changeBg":
			if(value != 'default' && value != null)
			{
				document.getElementById("leftBg").style.backgroundImage = "url(images/bg_left_finals_team" + value + ".jpg)";
				document.getElementById("rightBg").style.backgroundImage = "url(images/bg_right_finals_team" + value + ".jpg)";
			}else
			{
				document.getElementById("leftBg").style.backgroundImage = "url(images/bg_left_finals.jpg)";
				document.getElementById("rightBg").style.backgroundImage = "url(images/bg_right_finals.jpg)";
			}
			break;
		case "resetRegPage":
			if(currentRegUrl != "" && currentRegWindow != null)
			{
				alert("You can not bought the service because you have not logged in.");
				window.currentRegWindow.location.href = currentRegUrl;
			}
			break;
	}
}

function lanuchRegistration(url)
{
	g_mainRegWin = window.open(url,"registration_","scrollbars=yes,menubar=no,height=768,width=1024,top=0,left=0,resizable=no,toolbar=no,location=no,status=yes");
	if(g_mainRegWin!=null)
		g_mainRegWin.focus();
	checkRegWindowClosed();
}

function lanuchAllStar()
{
	//window.location.href = g_allstarplayer;
	g_allStarWin = window.open(g_allstarplayer,"starwin_","scrollbars=yes,menubar=no,height=768,width=1024,top=0,left=0,resizable=no,toolbar=no,location=no,status=yes");
	if(g_mainStarWin!=null)
		g_mainStarWin.focus();
	checkSatrWindowClosed();
}

function checkRegWindowClosed()
{
	if (window.g_mainRegWin==null)
		return;
	
	if (!window.g_mainRegWin.closed)
		setTimeout("checkRegWindowClosed()", 1000);
	else{
		consoleCallback("updateGames", "");
		currentRegUrl = "";
		currentRegWindow = null;
	}
}

function checkRegSWindowClosed()
{
	if (window.g_mainRegSWin==null)
		return;
	
	if (!window.g_mainRegSWin.closed)
		setTimeout("checkRegSWindowClosed()", 1000);
	else{
		consoleCallback("updateGames", "");
		currentRegUrl = "";
		currentRegWindow = null;
	}
}

function checkGcBuyWindowClosed()
{
	if (window.g_mainGcBuyWin==null)
		return;
	
	if (!window.g_mainGcBuyWin.closed)
		setTimeout("checkGcBuyWindowClosed()", 1000);
	else
		consoleCallback("updateGames", "");
}

function checkGcWindowClosed()
{
	if (window.g_mainGcWin==null)
		return;
	
	if (!window.g_mainGcWin.closed)
		setTimeout("checkGcWindowClosed()", 1000);
	else
		consoleCallback("updateGames", "");
}

function checkSatrWindowClosed()
{
	if (window.g_mainStarWin==null)
		return;
	
	if (!window.g_mainStarWin.closed)
		setTimeout("checkSatrWindowClosed()", 1000);
	else{
		consoleCallback("updateGames", "");
	}
}

// transfer the companion image url/link into swf application
function consoleCallback(action, value)
{
	// alert("action " + action + ", value " + value);
	var swfConsole = document.getElementById("console");
	if (swfConsole && swfConsole.consoleCallback) swfConsole.consoleCallback(action, value);
}

function mouseoutofSwf()
{
	consoleCallback("mouseOut", "");
}

function playWMV(path, x, y, volume)
{
	playCdnWMV(path, x, y, volume, true);
}

function playFactWMV(path,x, y, volume)
{
	playCdnWMV(path, x, y, volume, false);
}

function playCdnWMV(path, x, y, volume, cdn)
{
	if (cdn)
	{
		var result = null;
		try
		{
			var args = "";
			var pos = path.indexOf("?");
			if(pos>0)
			{
				var path1 = path.substring(0,pos);
				var path2 = "";
				var nvs = path.substr(pos + 1).split("&");
				if(nvs.length>0)
				{
					for(var i=0;i<nvs.length;i++)
					{
						var pair = nvs[i].split("=");
						if (pair.length > 1 && pair[0]!="islive" && pair[0] != "swfname")
							path2 += "&" + nvs[i];
						else
							args += "&" + nvs[i];
					}
				}	
				path2 = (path2 == "" ? "" : path2.substr(1));
				if (path2 != "") 
				{
					path1 += "?" + path2;
					path1 = encodeURIComponent(path1);
				}
				args = "path=" + path1 + args;
			}
			else
				args = "path=" + path;	
			
			var xml = _console2.getComponentContentSynch("cdnauth", args, false);
			//if return code is fail, means the cdnauth fail, so we need to
			//make the player will not play the video
			var retCode = _util.selectSingleNodeText(xml, "/result/code");
			if ( retCode == "authed" )
			{
				result = _util.selectSingleNodeText(xml, "/result/data/authedPath");
			}else
			{
				result = null;
			}			
		}
		catch (e)
		{
		}
		if (result==null) return;
		
		g_lastPath = result;
	}
	else
		g_lastPath = path;
		
	g_x = x;
	g_y = y;
	g_volume = volume;

	if(g_isIE || g_checkOk)
	{
		nowPlayWM();
		return;
	}
	
	consoleCallback("checkPlugin", "");
}

function nowPlayWMP()
{
	g_checkOk = true;
	nowPlayWM();
}

function nowPlayWM()
{
	var wmp = document.getElementById("wmppane");
	var wmppaneDiv = document.getElementById("wmppaneDiv");
	//wmp.style.left = g_x + "px";
	//wmp.style.top = g_y + "px";
	wmppaneDiv.style.display = "";

	if(g_isIE)
	{
		if (getCookie("wmvReady") == "false")
		{
			setTimeout("nowPlayWM()", 1000);
			return;				
		}
		wmp = getPlayer();
		wmp.url = g_lastPath;
		wmp.settings.volume = g_volume;
	}
	else
	{	
		wmp.style.width = "480px";
		wmp.style.height = "360px";
		wmp.contentWindow.writeWMP(g_lastPath,360,null,null,null,null,null,null,false);	
	}	
	if (audioTimer) window.clearTimeout(audioTimer);
	audioTimer = window.setTimeout("switchAudio()", 300);
}

function switchAudio()
{
	var wmp = getPlayer();
	if (wmp.controls && wmp.controls.audioLanguageCount>0)
	{
		//alert(wmp.controls.audioLanguageCount);
		wmpProxy("switchAudio", 1);
		window.clearTimeout(audioTimer);
	}
	else
		audioTimer = window.setTimeout("switchAudio()", 300);
}

function getEncryptedVideoPath(islive, path) {
    var result = "";
    try {
        var args = "islive=" + islive + "&path=" + encodeURIComponent(path);
        //alert("getEncryptedVideoPath " + args + ", path " + path);
        var xml = _console2.getComponentContentSynch("cdnauth", args, false);
        var retCode = _util.selectSingleNodeText(xml, "/result/code");
        if (retCode == "authed") {
            result = _util.selectSingleNodeText(xml, "/result/data/authedPath");
        } else {
            result = "";
        } 
    }
    catch (e) {
    }
    //alert("result " + result);
    return result;
}

function wmpProxy(action, value)
{
	var wmppane = document.getElementById("wmppane");
	var wmppaneDiv = document.getElementById("wmppaneDiv");
	var wmp = getPlayer();
	switch(action)
	{
	case "fullscreen":
		wmp.fullScreen = true;
		break;
	case "playerhide":
		if(g_isIE)
			document.getElementById("wmppaneDiv").style.display = "none";
		else
		{	
			//wmppane.style.left = "0px";
			//wmppane.style.top = "0px";
			wmppaneDiv.style.width = "1px";
			wmppaneDiv.style.height = "1px";
			wmppane.style.width = "1px";
			wmppane.style.height = "1px";
		}
		break;
	case "switchAudio":    					// home: 1, away: 2
		//alert(value);
        if (wmp.controls && wmp.controls.audioLanguageCount>1)
        {
            var lang1 = wmp.controls.getAudioLanguageID(1);
            var lang2 = wmp.controls.getAudioLanguageID(2);
            var asc = (lang1 < lang2);
            var val = parseInt(value);
            val = (asc ? val : (val % 2) + 1);
			wmp.controls.currentAudioLanguageIndex = val;
        }
        
        //var val = parseInt(value);
        //wmp.settings.balance = (val == 2 ? -100 : 100);	        		
		break;
	case "stop":
		wmp.controls.stop();
		break;
	case "fastReverse":
		wmp.controls.fastReverse();
		break;
	case "fastForward":
		wmp.controls.fastForward();
		break;
	case "pause":
		wmp.controls.pause();
		break;
	case "play":
		wmp.controls.play();
		break;
	case "setvolume":
		wmp.settings.volume = parseInt(value);
		break;
	case "getvolume":
		return wmp.settings.volume;
		break;
	case "shareshow":
		wmppaneDiv.style.display = "none";
		break;
	case "sharehide":
		wmppaneDiv.style.display = "";
		break;
	case "position":
		//var p = document.getElementById("wmppane");
		//p.style.left = value[0] + "px";
		//p.style.top = value[1] + "px";
		break;
	case "seek":
		value = parseInt(value);
		wmp.controls.currentposition = value;
		break;
	case "getcurtime":
		return "" + Math.floor(wmp.controls.currentPosition);
		break;
	case "gettoltime":
		return (wmp.currentMedia ? "" + Math.floor(wmp.currentMedia.duration) : "0");
		break;
	case "refreshtime":
		return (wmp.currentMedia ? ["" + Math.floor(wmp.controls.currentPosition), "" + Math.floor(wmp.currentMedia.duration)] : ["0", "0"]);
		break;
	case "getDownloadProgress":
		return "" + Math.floor(wmp.network.downloadProgress);
		break;		
	case "ecm":
		wmp.enableContextMenu = true;
		break;
	case "hide":
		if(g_isIE)
			wmp.controls.stop();
		else
			wmppane.contentWindow.writeWMP("");
		wmppaneDiv.style.display = "none";
	}
}

function wmpCallback(action, value)
{
	var swfConsole = document.getElementById("console");
	if (!value) value = "";
	try{
		if (swfConsole && swfConsole.wmpCallback) swfConsole.wmpCallback(action, value);
	}catch(e){}
}

function getPlayer()
{
	var wmp = null;
	if (g_isIE)
	 	wmp = document.getElementById("wmppane").contentWindow.document.getElementById("wmpMain");
	else
		wmp = document.getElementById("wmppane").contentWindow.document.getElementById("wmpMain-ff");
	return wmp;
}

function Console2()
{	
	this.getComponentContent = function(url, params, callback, bNoPrefixURL)
	{
		if(bNoPrefixURL!=true)
		   url="servlets/"+url;
		   
		var args=this.getArgsString(params);
		var requester=null;
		if(_util.isie)
			requester = new ActiveXObject("Microsoft.XMLHTTP");
		else
			requester = new XMLHttpRequest();
			
		requester.open("POST", url, true);
		requester.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

		requester.onreadystatechange=function() 
			{
				if (requester.readyState==4) 
				{
					var iStatus=requester.status;
					if (iStatus>=200 && iStatus<300)
					{
						// Success
						if(requester.getResponseHeader("Content-Type").indexOf("text/xml")==0)
							callback(requester.responseXML.documentElement)
						else
							callback(requester.responseText);
					}
					else
						callback("ERROR - Code="+requester.status);
				}
			}
		
		requester.send(args);
	}

	this.getComponentContentSynch = function(url, params, bNoPrefixURL)
	{
		if(bNoPrefixURL!=true)
		   url="servlets/"+url;
		   
		var args=this.getArgsString(params);

		var requester=null;
		if(_util.isie)
			requester = new ActiveXObject("Microsoft.XMLHTTP");
		else
			requester = new XMLHttpRequest();
			
		requester.open("POST", url, false);
		requester.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

		requester.send(args);
	
		var iStatus=requester.status;
		if (iStatus>=200 && iStatus<300)
		{
			// Success
			if(requester.getResponseHeader("Content-Type").indexOf("text/xml")==0 || requester.getResponseHeader("Content-Type").indexOf("application/xml")==0)
				return requester.responseXML.documentElement;
			else
				return requester.responseText;
		}
		else
			return "ERROR - Code="+requester.status;
	}			

	// Converts an object of arguments to string
	// Args can be of type Objects (with arrays inside a key), or strings
	// Returns an encoded/escaped url string for the args
	this.getArgsString = function(params)
	{
		var args = "";
		if(typeof(params)=="object")
		{
			var argArray = new Array();
			for(n in params)
			{
				if((params[n] != null) && (typeof(params[n])=="object"))
				{ 
					for(var i=0; i<params[n].length; i++)
						argArray[argArray.length] = n + "=" + encodeURIComponent(params[n][i]);
				}
				else					
					argArray[argArray.length] = n + "=" + encodeURIComponent(params[n]);
			}
			args = argArray.join("&");
		}
		else
			args = params;
		
		return args;
	}
}

function getPageUrl()
{
	var url = window.location.href;
	var i = url.indexOf("?");
	if(i>0)
		url = window.location.href.substring(0,i);
	return url.substring(0,url.lastIndexOf("/")+1);
}

function getServer()
{	
	//var server = "http://172.16.0.253:8200/iptvpcp-ahl/";
	//var server = "http://127.0.0.1:8060/iptvpcp-ahl/";
	//var server = "http://172.16.0.222:8060/iptvpcp-ahl/";
	//var server = "http://neulion.net.cn:8060/iptvpcp-ahl/";
	var server = location.href.substring(0, location.href.lastIndexOf("/")+1);
	return server;
}


function getProductServer() {
    return "server=http://ahl.neulion.com/team/";
}

function getProductConsole() {
    return "http://172.16.0.222:8060/iptvpcp-ahl/";
}

function writeFlexPlayer(locProgramImage,isProduction, embed, isDebug, playoff4a, playoff4b)
{
	consoleStr = "console";
	if(embed)
		consoleStr = "embed";
	if(isProduction)
	{
	    serverStr = getProductServer();
		// the first part should be replaced with the cdn url
	    consoleStr = getProductConsole() + consoleStr;
	}
	if (isDebug) consoleStr = "console-debug";
	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+"&refreshLiveGameScoreTimeNum="+refreshLiveGameScoreTimeNum+"",
			"width", "100%",
			"height", "100%",
			"align", "middle",
			"id", "console",
			"quality", "high",
			"bgcolor", "#000000",
			"name", "console",
			"scaleMode", "exactFit",
			"allowScriptAccess","always",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
		);
	} else if (hasRequestedVersion) {
	
		var flashVars = new Array();
		if(g_isIE)
			flashVars[flashVars.length] = "isie=true";
		flashVars[flashVars.length] = serverStr;
		flashVars[flashVars.length] = "vodid=" + g_vodCatId;
		flashVars[flashVars.length] = "hlsid=" + g_highlightCatId;
		flashVars[flashVars.length] = "promo_video=" + g_promo_video;
		flashVars[flashVars.length] = "rightAdTimerNum=" + g_rightAdTimerNum;
		
		if (playoff4a && playoff4b)
		{
			var playoff4 = playoff4a + "," + playoff4b + "," + g_playoff4_preview_view + "," + g_playoff4_preview_wait;
			flashVars[flashVars.length] = "playoff4=" + encodeURIComponent(playoff4);
		}
		if(g_allstar)
			flashVars[flashVars.length] = "allstar=true";
		if(g_usesecure)
			flashVars[flashVars.length] = "usesecure=true";
		if(window.location.search.length>1)
		{
			var nvs = window.location.search.substring(1).split("&");
			if(nvs.length>0)
				for(var i=0;i<nvs.length;i++)
					flashVars[flashVars.length] = nvs[i];
		}
		flashVars[flashVars.length] = "referrer="+encodeURIComponent(document.referrer);
		flashVars[flashVars.length] = "refreshLiveGameScoreTimeNum=" + refreshLiveGameScoreTimeNum;
		flashVars[flashVars.length] = "locProgramImage=" + locProgramImage;
		
		if(g_playoff4_desc_teamA_name != null && g_playoff4_desc_teamA_name != "")
			flashVars[flashVars.length] = "playoff4_desc_teamA_name="+g_playoff4_desc_teamA_name;
		if(g_playoff4_desc_teamA_high != null && g_playoff4_desc_teamA_high != "")
			flashVars[flashVars.length] = "playoff4_desc_teamA_high="+g_playoff4_desc_teamA_high;
		if(g_playoff4_desc_teamA_detail != null && g_playoff4_desc_teamA_detail != "")
			flashVars[flashVars.length] = "playoff4_desc_teamA_detail="+g_playoff4_desc_teamA_detail;
		if(g_playoff4_desc_teamA_price != null && g_playoff4_desc_teamA_price != "")
			flashVars[flashVars.length] = "playoff4_desc_teamA_price="+g_playoff4_desc_teamA_price;
		
		if(g_playoff4_desc_teamB_name != null && g_playoff4_desc_teamB_name != "")
			flashVars[flashVars.length] = "playoff4_desc_teamB_name="+g_playoff4_desc_teamB_name;
		if(g_playoff4_desc_teamB_high != null && g_playoff4_desc_teamB_high != "")
			flashVars[flashVars.length] = "playoff4_desc_teamB_high="+g_playoff4_desc_teamB_high;
		if(g_playoff4_desc_teamB_detail != null && g_playoff4_desc_teamB_detail != "")
			flashVars[flashVars.length] = "playoff4_desc_teamB_detail="+g_playoff4_desc_teamB_detail;
		if(g_playoff4_desc_teamB_price != null && g_playoff4_desc_teamB_price != "")
			flashVars[flashVars.length] = "playoff4_desc_teamB_price="+g_playoff4_desc_teamB_price;

		if(g_playoff4_desc_gamepass_name != null && g_playoff4_desc_gamepass_name != "")
			flashVars[flashVars.length] = "playoff4_desc_gamepass_name="+g_playoff4_desc_gamepass_name;
		if(g_playoff4_desc_gamepass_high != null && g_playoff4_desc_gamepass_high != "")
			flashVars[flashVars.length] = "playoff4_desc_gamepass_high="+g_playoff4_desc_gamepass_high;
		if(g_playoff4_desc_gamepass_detail != null && g_playoff4_desc_gamepass_detail != "")
			flashVars[flashVars.length] = "playoff4_desc_gamepass_detail="+g_playoff4_desc_gamepass_detail;
		if(g_playoff4_desc_gamepass_price != null && g_playoff4_desc_gamepass_price != "")
			flashVars[flashVars.length] = "playoff4_desc_gamepass_price="+g_playoff4_desc_gamepass_price;

		// if we've detected an acceptable version
		// embed the Flash Content SWF when all tests are passed
		AC_FL_RunContent(
				"flashVars", flashVars.join("&"),
				"src", consoleStr,
				"width", "100%",
				"height", "100%",
				"align", "middle",
				"id", "console",
				"quality", "high",
				"bgcolor", "#000000",
				"name", "console",
				"scaleMode", "exactFit",
				"wmode", "transparent", //"opaque",
				"allowScriptAccess","always",
				"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 = 'Alternate HTML content should be placed here. '
	  	+ '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
	  }
}

function getSessionId()
{
	var sid = "";
	if(document.cookie!=null && document.cookie.length>0)
	{
		var crumbs = document.cookie.split(";");
		for(var i=0;i<crumbs.length;i++)
		{
			var curCrumb = crumbs[i].split("=");
			if(curCrumb[0].indexOf("JSESSIONID")==0)
			{
				if(unescape(curCrumb[1])!="undefined")			
				{
					sid = unescape(curCrumb[1]);
					break;
				}
			}
		}
	}
	return sid;
}

var g_wmpExists = true;
function checkWMPExists()
{
	var wmppane = document.getElementById("wmppane");
	var wmppaneDiv = document.getElementById("wmppaneDiv");

	if (wmppaneDiv.style.display == 'NONE')
	{
		if (g_wmpExists)
		{
			g_wmpExists = false;
			consoleCallback("showPromoPic", "");
		}
	}else
	{
		var wmp = getPlayer();		
		
//		if ((wmp) && (wmp.controls))
//			alert(wmp.playState);
			
		if ((wmp) && (wmp.controls) &&
		     (wmp.playState == 1))
		{
			if (g_wmpExists)
			{
				g_wmpExists = false;
				consoleCallback("showPromoPic", "");
			}
		}else
		{
			g_wmpExists = true;
		}
	}
	
	window.setTimeout("checkWMPExists()", 4000);
}

function getCookieVal(offset)
{
	var endstr=document.cookie.indexOf(";",offset);	
	if(endstr==-1)
	endstr=document.cookie.length;	
	return unescape(document.cookie.substring(offset,endstr));	
}

function setCookie(name,value) 
{
	var expdate=new Date();	
	var argv=setCookie.arguments;	
	var argc=setCookie.arguments.length;	
	var expires=(argc>2)?argv[2]:null;	
	var path="/";	
	var domain=(argc>4)?argv[4]:null;	
	var secure=(argc>5)?argv[5]:false;	
	if(expires!=null)
		expdate.setTime(expdate.getTime()+(expires*1000));	
	document.cookie=name+"="+escape(value)+((expires==null)?"":("; expires="+expdate.toGMTString()))
	+((path==null)?"":("; path="+path))+((domain==null)?"":("; domain="+domain))
	+((secure==true)?"; secure":"");	
}


function setCookieFor30Days(name, value)
{
	setCookie(name, value, 3600*24*30);
}

function delCookie(name) 
{
	var exp=new Date();	
	exp.setTime(exp.getTime()-1);	
	var cval=getCookie(name);	
	document.cookie=name+"="+cval+"; expires="+exp.toGMTString();	
}

function getCookie(name) 
{
	var arg=name+"=";	
	var alen=arg.length;	
	var clen=document.cookie.length;	
	var i=0;	
	while(i<clen)
	{
		
		var j=i+alen;		
		if(document.cookie.substring(i,j)==arg)
			return getCookieVal(j);		
		i=document.cookie.indexOf(" ",i)+1;		
		if(i==0) break;		
	}
	return null;
}
function getNeulionFoot()
{
	var xml = _console2.getComponentContent("neulionxmlfoot", null, neulionFootCallback, false);
}
function neulionFootCallback(xml)
{
	var result = _util.selectNodes(xml, "/linktree/item", false);
	if (result==null) return;
	var arrLinks = new Array();
	for(var i=0; i < result.length; i++)
	{
		var item = new Object();
		item.title = _util.selectSingleNodeText(result[i], "title", false);
		item.href = _util.selectSingleNodeText(result[i], "href", false);
		arrLinks.push(item);
	}
	addNeulionFoot(arrLinks);
}
function addNeulionFoot(arr)
{
	var row = Math.floor(arr.length % 4 ? arr.length / 4 +1 : arr.length /4);
	for(var i=0;i < 4; i++)
	{
		var div = document.createElement("div");
		div.className = "footer-bucket";
		for(var j=0;j<row;j++)
		{
			if(arr[0] != null)
			{
				var str = "<a href='"+arr[0].href+"' target='_blank' class='footer-link'>"+arr[0].title+"</a><br />";
				div.innerHTML += str;
				arr.splice(0,1);
			}
		}
		document.getElementById("footer-casing").appendChild(div);
	}
	document.getElementById("footer-casing").innerHTML += "<div style='clear:both'></div>";
}