
// provides access to querystring collection
function Widgets_QueryString(){var aQS;var sQS = window.location.search.toString();sQS = sQS.substring(1, sQS.length);if (sQS != null && sQS != ""){aQS = sQS.split("&");for (var i = 0; i < aQS.length; i++){aQS[i] = aQS[i].split("=");}}else{aQS = new Array(0);}this.Get = function (sKey){sKey = escape(sKey);for (var i = 0; i < aQS.length; i++){if (aQS[i][0] == sKey){return unescape(aQS[i][1]);}}return null;};this.Count = aQS.length;};
function Widgets_Request(){this.QueryString = new Widgets_QueryString;};
var Request = new Widgets_Request();

// deprecated syntax support
function CasinoGameOpenDemo() { CasinoGameOpen(arguments[0], -1); }
function CasinoGameOpenLogin() { CasinoGameOpen(arguments[0], 1); }
function OnGameClicked() { CasinoGameOpen(arguments[0]); }
function OnPlayClicked() { CasinoGameOpen(arguments[0],arguments[1]); }

// game launch
function CasinoGameOpen(nCasinoGameId, nAccountId, sGameCode)
{
   var LaunchForm = document.forms["LaunchForm"];
   var LobbyForm = document.forms["LobbyForm"];
   if (LaunchForm == null){alert("Launch Form not found"); return;}
   if (LobbyForm == null){alert("Lobby Form not found"); return;}
   
   if (nAccountId != null) LaunchForm["AccountId"].value = nAccountId;
   
   // verify login
   var token = LaunchForm["Token"].value;
   var nAccountId = LaunchForm["AccountId"].value;
   if (nAccountId == "1" && token == "") return;
   
   LaunchForm["CasinoGameId"].value = nCasinoGameId;
   if (LaunchForm["GameCode"] != null) LaunchForm["GameCode"].value = sGameCode;
   
   var wWindow = popupGame();
   if (wWindow == null)
   {
      alert("Unable to open game window. You may have a pop-up blocker enabled.");
      return;
   }
   try 
   {
      wWindow.moveTo(0,0);
   } 
   catch(e){}
   try 
   {
      wWindow.resizeTo(screen.width,screen.height);
      wWindow.focus();
   } 
   catch(e){}
   LaunchForm.submit();
}

// lobby functions
function OnLanguageClicked(Language)
{
   var LobbyForm = document.forms["LobbyForm"];
	LobbyForm["lang"].value = Language;
	LobbyForm.submit();
}

function OnCategoryClicked(CategoryId, IsContest, TabCode)
{
   var LobbyForm = document.forms["LobbyForm"];
   LobbyForm["catid"].value = CategoryId;
   LobbyForm["tabcode"].value = TabCode;
   LobbyForm.submit();
}

function RefreshLobby()
{
   document.forms["LobbyForm"].submit();
}

function OnLobbyLoad()
{
   if (document.location.search != null && document.location.search.length > 2)
   {
      if (Request.QueryString.Get("CasinoGameId") != null) 
      CasinoGameOpen(Request.QueryString.Get("CasinoGameId"));
      if (Request.QueryString.Get("GameCode") != null)
      CasinoGameOpen(0,null,Request.QueryString.Get("GameCode"));
      RefreshLobby();
   }
}

// contest functions
function OnRegisterClicked(TournamentId, Round, Bracket, Fee)
{
	if (confirm("This will debit " + Fee + " from your account"))
	{
	   var LobbyForm = document.forms["LobbyForm"];
		LobbyForm["tournamentid"].value = TournamentId;
		LobbyForm["round"].value = Round;
		LobbyForm["bracket"].value = Bracket;
		LobbyForm["action"].value = "REGISTER";
		LobbyForm.submit();
	}
	
}

function OnScoreboardClicked(TournamentId, Round, Bracket)
{
   var LobbyForm = document.forms["LobbyForm"];
	LobbyForm["tournamentid"].value = TournamentId;
	LobbyForm["round"].value = Round;
	LobbyForm["bracket"].value = Bracket;
	LobbyForm["action"].value = "SCOREBOARD";
	LobbyForm.submit();
}

function OnBackClicked()
{
   var LobbyForm = document.forms["LobbyForm"];
	LobbyForm["round"].value = "";
	LobbyForm["bracket"].value = "";
   LobbyForm["action"].value = "";
	LobbyForm.submit();
}

function Logout()
{
   var LobbyForm = document.forms["LobbyForm"];
   LobbyForm["token"].value = "";
	LobbyForm["action"].value = "LOGOUT";
	LobbyForm.submit();
}

function popupNews(url, width, height)
{
   var settings="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+width+",height="+height;
   winpops=window.open(url,"",settings);
}

function popupGame()
{
   var settings="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+screen.width+",height="+screen.height;
   return window.open("","casinogamingflashwindow",settings);
}
