var omnitureProduction = true;

// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 10;
// 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_isIE = (window.navigator.userAgent.indexOf("MSIE")>0);

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 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;
}
function writeFlexPlayer(isProduction, team, isFrench)
{
	var serverStr = "server=" + location.href.substring(0, location.href.lastIndexOf("/")+1);
	var consoleStr = "console";
	var locImage = "";
	if(isProduction=="true")
	{
		serverStr = "server=http://video.";
		if(team!=null)
			serverStr += team + ".";
		serverStr += "nhl.com/videocenter/";
		consoleStr = "http://nhl.cdn.neulion.net/u/videocenter/console";
		locImage = "http://nhl.cdn.neulion.net/u/videocenter/";
	}
	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+"",
			"width", "100%",
			"height", "100%",
			"align", "middle",
			"id", "console",
			"quality", "high",
			"bgcolor", "#000000",
			"name", "console",
			"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;
		if(window.location.search.length>1)
		{
			flashVars[flashVars.length] = "qs=" + encodeURIComponent(window.location.search.substring(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] = "locimage="+locImage;
		if(isFrench)
			flashVars[flashVars.length] = "isfrench=true";
		flashVars[flashVars.length] = "referrer="+encodeURIComponent(document.referrer);
		flashVars[flashVars.length] = "nlwa=http://app2.neulion.com/videocenter/nhl/";
		if(!omnitureProduction)
			flashVars[flashVars.length] = "osca=nhlnhlleaguedev";
	
		// 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",
				"wmode", "transparent",
				"allowFullScreen", "true",
				"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 = 'This content requires the Adobe Flash Player. '
	   	+ '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
	    document.getElementById("nlFlexPlayerDiv").innerHTML = alternateContent;  // insert non-flash content
	  }
}
function iptvShowCompanions(playerX, playerY, companions)
{
	for(var i=0;i<companions.length;i++)
	{
		var adsize = companions[i][0];
		switch(adsize)
		{
		case "728x90":
			iptvShowCompanion("iptvTopAdDiv", playerX, playerY, companions[i], 728, 90);
			break;
		case "300x250":
			setAdMode(true);
			iptvShowCompanion("iptvAdDiv", playerX, playerY, companions[i], 300, 250);
			break;
		}
	}
}
function iptvShowCompanion(id, playerX, playerY, companion, w, h)
{
	var oDiv = document.getElementById(id);
	if("iframe"==companion[1] && companion[2]!=null)
	{
		oDiv.innerHTML = "<iframe width='"+w+"' height='"+h+"' frameborder='0' scrolling='no' src='"+companion[2]+"'></iframe>";
	}
	else if("img"==companion[1] && companion[2]!=null)
	{	
		var strAdHTML = "";
		if(companion[3]!=null && companion[3].length>0)
			strAdHTML = "<a href='"+companion[3]+"' target='_blank'>";
		
		strAdHTML += "<img src='"+companion[2]+"' border='0' />";

		if(companion[3]!=null && companion[3].length>0)
			strAdHTML += "</a>";
		
		oDiv.innerHTML = strAdHTML;
	}
}
function iptvHideCompanions(hide)
{
	setAdMode(false);
}
function launchSupport()
{
	var team="";  // Generic
	var host = location.hostname.split(".");
	if(host.length>=3)
	{
		switch(host[1])
		{
		case "ducks":
			team = "Anaheim Ducks";
			break;
		case "thrashers":
			team = "Atlanta Thrashers";
			break;
		case "bruins":
			team = "Boston Bruins";
			break;
		case "sabres":
			team = "Buffalo Sabres";
			break;
		case "flames":
			team = "Calgary Flames";
			break;
		case "hurricanes":
			team = "Carolina Hurricanes";
			break;
		case "blackhawks":
			team = "Chicago Blackhawks";
			break;
		case "avalanche":
			team = "Colorado Avalanche";
			break;
		case "bluejackets":
			team = "Columbus Blue Jackets";
			break;
		case "stars":
			team = "Dallas Stars";
			break;
		case "redwings":
			team = "Detroit Red Wings";
			break;
		case "oilers":
			team = "Edmonton Oilers";
			break;
		case "panthers":
			team = "Florida Panthers";
			break;
		case "kings":
			team = "Los Angeles Kings";
			break;
		case "wild":
			team = "Minnesota Wild";
			break;
		case "canadiens":
			team = "Montreal Canadiens";
			break;
		case "predators":
			team = "Nashville Predators";
			break;
		case "devils":
			team = "New Jersey Devils";
			break;
		case "islanders":
			team = "New York Islanders";
			break;
		case "rangers":
			team = "New York Rangers";
			break;
		case "senators":
			team = "Ottawa Senators";
			break;
		case "flyers":
			team = "Philadelphia Flyers";
			break;
		case "coyotes":
			team = "Phoenix Coyotes";
			break;
		case "penguins":
			team = "Pittsburgh Penguins";
			break;
		case "sharks":
			team = "San Jose Sharks";
			break;
		case "blues":
			team = "St. Louis Blues";
			break;
		case "lightning":
			team = "Tampa Bay Lightning";
			break;
		case "mapleleafs":
			team = "Toronto Maple Leafs";
			break;
		case "canucks":
			team = "Vancouver Canucks";
			break;
		case "capitals":
			team = "Washington Capitals";
			break;
		}
	}
	open(
			'http://gclsupport.nhl.com/link3/gcl/gcl-support.nsf?open&team=' + encodeURIComponent(team),
			'_blank',
			'width=1014,status=1,toolbar=1,location=1,menubar=1,directories=1,resizable=1,scrollbars=1'
		);
}