
var mode='';var stat='';

stat = window.external.ScreenMode;
if(stat == 'beforePlay')
	stat = 'enter';
else
	stat = 'exit';

if(window.external.IsPurchased)
	mode = "purchased";
else 
	mode = "demo";

// Interface to the page.
function playGame(){window.external.PlayGame();}
function closeLauncher(){window.external.Close();}

function onPlayPress(funcName){window.external.OnPlayPress = funcName;}
function onBuyPress(funcName){window.external.OnBuyPress = funcName;}
function onGetMoreGamesPress(funcName){window.external.OnGetMoreGamesPress = funcName;}

function getBuyUrl(){return window.external.BuyUrl;}
function setBuyUrl(url){window.external.BuyUrl = url;}
function getBuyUrlParameters(){return window.external.BuyUrlParameters;}
function setBuyUrlParameters(params){window.external.BuyUrlParameters = params;}

function GameCenterUrl(){return window.external.GameCenterUrl;}
function SysId(){return window.external.SysId;}
function installedGamesbarChannelId(){return window.external.InstalledGamesbarChannelId;}
function isGamesbarInstalled(){return window.external.IsGamesbarInstalled;}
function timeSinceLastGamePlayed(){return window.external.TimeSinceLastGamePlayed;}
function timesPlayedDuringPurchase(){return window.external.TimesPlayedDuringPurchase;}
function timesPlayedDuringTrial(){return window.external.TimesPlayedDuringTrial;}
function instalationDate(){return window.external.InstallationDate;}
function channelId(){return window.external.ChannelId;}
function gameName(){return window.external.GameName;}
function timesLauncherOpenTrialEnd(){return window.external.TimesOpenLauncherTrialEnded;}
function getSku(){return window.external.SKU;}
function isInternetConnected(){return window.external.IsInternetConnected;}
function getMode() { return mode;}
function getStat() { return stat;}
function getUsesLeft() { return (window.external.TotalTrialTime - window.external.TrialTimeUsed);}
function getMaxUsage() { return window.external.TotalTrialTime;}
function getRest() { return window.external.RestrictionType;}
function getBaseUrl(){ return window.external.BaseUrl; }
function OpenEnterKeyDlg(title){ return window.external.EnterKey(title); }
function MoveTo(x, y){ window.external.MoveTo(x, y); }
function MinimizeLauncher(){ window.external.Minimize(); }

function showInfo()
{
myWindow.document.write( '<html><head></head><body><table border="1">'+
		'<tr bgcolor="#C0C0C0">' + gameName() + ' Information' +
		'<td>' +
			'<table border="1">' +
			'<tr><td bgcolor="#FFFFCC">Mode</td><td bgcolor="#CCFFFF">' + getMode() + '</td></tr>' +
			'<tr><td bgcolor="#FFFFCC">Stat</td><td bgcolor="#CCFFFF">' + getStat() + '</td></tr>' +
			'<tr><td bgcolor="#FFFFCC">Max Usage</td><td bgcolor="#CCFFFF">' + getMaxUsage() + '</td></tr>' +
			'<tr><td bgcolor="#FFFFCC">Uses Left</td><td bgcolor="#CCFFFF">' + getUsesLeft() + '</td></tr>' +
			'<tr><td bgcolor="#FFFFCC">Times Launcher Opened After Trial Ended</td><td bgcolor="#CCFFFF">' + timesLauncherOpenTrialEnd() + '</td></tr>' +
			'<tr><td bgcolor="#FFFFCC">InternetConnected</td><td bgcolor="#CCFFFF">' + isInternetConnected() + '</td></tr>' +
			'<tr><td bgcolor="#FFFFCC">Base Url</td><td bgcolor="#CCFFFF">' + getBaseUrl() + '</td></tr>' +
			'<tr><td bgcolor="#FFFFCC">SKU</td><td bgcolor="#CCFFFF">' + getSku() + '</td></tr>' +
			'<tr><td bgcolor="#FFFFCC">SysID</td><td bgcolor="#CCFFFF">' + SysId() + '</td></tr>' +
			'<tr><td bgcolor="#FFFFCC">Game Center Url</td><td bgcolor="#CCFFFF">' + GameCenterUrl() + '</td></tr>' +
			'<tr><td bgcolor="#FFFFCC">Channel Id</td><td bgcolor="#CCFFFF">' + channelId() + '</td></tr>' +
			'<tr><td bgcolor="#FFFFCC">Installation Date</td><td bgcolor="#CCFFFF">' + instalationDate() + '</td></tr>' +
			'<tr><td bgcolor="#FFFFCC">Times Played During Trial</td><td bgcolor="#CCFFFF">' + timesPlayedDuringTrial() + '</td></tr>' +
			'<tr><td bgcolor="#FFFFCC">Times Played During Purchase</td><td bgcolor="#CCFFFF">' + timesPlayedDuringPurchase() + '</td></tr>' +
			'<tr><td bgcolor="#FFFFCC">Time Since Last Game Played [format: days hh:MM:ss]</td><td bgcolor="#CCFFFF">' + timeSinceLastGamePlayed() + '</td></tr>' +
			'<tr><td bgcolor="#FFFFCC">Is Gamesbar Installed</td><td bgcolor="#CCFFFF">' + isGamesbarInstalled() + '</td></tr>' +
			'<tr><td bgcolor="#FFFFCC">Installed Gamesbar Config Url</td><td bgcolor="#CCFFFF">' + installedGamesbarChannelId() + '</td></tr>' +
			'</table>' +
		'</td>'+
	   '</tr></table>'+
	   '<span id="MyGames"></span></body></html>'
	);
}

function PlayGame(sku)
{
    alert(sku);
    Odyssey.LaunchGame(sku);
}

function showOtherGamesInfo()
{
	var Odyssey = new ActiveXObject('Odyssey.OdysseyActiveX.1');
	if( Odyssey != null)
	{
		myWindow.document.write( "no. of installed games: " + Odyssey.NumberOfInstalledGames + "<br><br>")
		myWindow.document.write( "<table border=1 cellpadding=4 cellspacing=0 style=\"border-style:solid;border-color:Navy;border-width=2;\">" )
		myWindow.document.write( "<tr style=\"background-color:#c0c0c0;color:#E0FF00\">" )
		myWindow.document.write( "<td>SKU</td>" )
		myWindow.document.write( "<td>Max Usage</td>" )
		myWindow.document.write( "<td>Usage Available</td>" )
		myWindow.document.write( "<td>Usage Unit</td>" )
		myWindow.document.write( "<td>Registered</td>" )
		myWindow.document.write( "<td>Install Date</td>" )
		myWindow.document.write( "<td>Last Play Date</td>" )
		myWindow.document.write( "</tr>" )

		sku = Odyssey.FirstGameSKU + "";
		while(Odyssey.HasMoreGames)
		{
		  url = ""
		  
	   //   if(Odyssey.DistributionChannel(sku) == channel)
		  {
			  url = sku 
			  MaxUsage = (Odyssey.MaximumUsageUnits(sku)) 
			  AvailableUsage = Math.max(0,Odyssey.AvailableUsageUnits(sku))
			  UsageUnit = Odyssey.UsageUnitType(sku)
			  Registered = Odyssey.IsRegistered(sku) 
			  LastPlayDate = Odyssey.LastPlayDate(sku)
			  InstallDate = Odyssey.InstallDate(sku)
		  }
			
		  if ( url != "" )
		  {
		  
			myWindow.document.write( "<tr>" )
			myWindow.document.write( "<td>" + sku + "</td>" )
			myWindow.document.write( "<td>" + MaxUsage + "</td>" )
			myWindow.document.write( "<td>" + AvailableUsage + "</td>" )
			myWindow.document.write( "<td>" + UsageUnit + "</td>" )
			myWindow.document.write( "<td>" + Registered + "</td>" )
			myWindow.document.write( "<td>" + InstallDate + "</td>" )
			myWindow.document.write( "<td>" + LastPlayDate + "</td>" )
		//	myWindow.document.write( "<td><a href=\"PlayGame('" + sku + "')\">Play</a></td>" )
			myWindow.document.write( "</tr>" )
		  } 
		  
		  sku = Odyssey.NextGameSKU + ""; 
		}
		
	   myWindow.document.write( "</table>" )	
	}
}
if(window.external.ShowDebugInfo)
{
	myWindow = window.open("", "Information", 'width=680,height=680,scrollbars=yes');
    showInfo();
	showOtherGamesInfo();
}
