if(window.name == null || window.name == "")
	window.name = "homewindow";

if(!gameWin)
	var gameWin= null;

function openGamePage(gameType,provider) 
	{
		//alert("game: "+gameType+", provider: "+provider);
		if (gameWin != null && !gameWin.closed)
		{
			gameWin.focus();
			gameWin.alert("Spilvinduet er allerede åbent");
		}	
		else 
		{
			if(provider == null)
			{
				openGamewindow(gameType,'spbd');	
			}
			else
			{
				openGamewindow(gameType,provider);	
			}
		}
	}
//openGamePage

function openGamewindow(gameType,provider)
{
	if((gameType.indexOf("Bingo") != -1)&& (provider != 'obs'))
	{
		openBingoGameWindow(gameType);
	}
	else
	{
		var w = window.screen.availWidth;
		var h = window.screen.availHeight;
		if(h > 800) {
			h=750;
		}//f	or higher resolutions
		if(w > 800) {
			w = w-25;
		} else {
			w = w-10;
		}//for higher resolutions
		//var windowDimensionsString  =provider == 'obs'?",width=767,height=567" : ",width=750,height=550";
		var windowDimensionsString  = ",width=750,height=550";
		var windowScreenLocation    = ",left="+(w-750)/2+",top="+(h-550)/2;
		var features = 	windowDimensionsString +
						windowScreenLocation + 
						",scrollbars=yes" +
						",toolbar=no" +
						",menubar=no,resizable=yes,fullscreen=7";
		//modified on 05-nov-2004
		/*	if(location.href.indexOf("index.html") != -1)
			{
				window.name	=  "slotgames";
				location.href="/commonapp/play/game_page.jsp?gameType="+gameType;
				return;
			}
		gameWin=window.open("/commonapp/play/game_page.jsp?gameType="+gameType+"&provider="+provider, "slotgames", features);
		//gameWin=window.open("../../play/game_page.jsp?gameType="+gameType, "slotgames", 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=760,height=630,left = 260,top = 212');*/

		// 3/23/2009 added the below code to restrict the multiple game windows
		var windowName  =       window.name;
		if(windowName!= null && windowName=="slotgames")
		{				
			location.href="/commonapp/play/game_page.jsp?gameType="+gameType+"&provider="+provider;
			return;
		}
		else
		{
			gameWin=window.open("/commonapp/play/game_page.jsp?gameType="+gameType+"&provider="+provider, "slotgames", features);
		}
	}
}

function openWin(gameName,gameType,configId)
{
	try{allGameWindowOnLoad();}catch (e){}
	var windowname =gameName;
	while (windowname.indexOf(' ')!=-1){windowname=windowname.replace(' ','');}
 allowResize = "yes";
 // Start at top left
 LeftPosition = 100;
 TopPosition = 0;
 // Go almost full-screen for Flash Bingo
 myHeight = (screen.height) ? (screen.height-145) : 455;
 myWidth = myHeight * 1.3475;
 // Set the left and top window position to zero if logic above has produced a value less than zero
 if (LeftPosition < 0) { LeftPosition = 0;}
 if (TopPosition < 0) { TopPosition = 0;}
 // Configure other window properties
 winProps = "left="+LeftPosition+",top="+TopPosition+",width="+myWidth+",height="+myHeight+",location=0,scrollbars=0,menubar=0,toolbar=0,resizable=" + allowResize;
 binWin = window.open("/commonapp/launchGame.jsp?gameName="+gameName+"&gameType="+gameType+"&configId="+configId, windowname, winProps);
 binWin.focus();
}

function openWinPullTab(winName,stockroot_url)
{
	allowResize = "yes";
	// Start at top left
	LeftPosition = 100;
	TopPosition = 0;
	// Go almost full-screen for Flash Bingo
	myHeight = (screen.height) ? (screen.height-145) : 455;
	myWidth = myHeight * 1.3475;
	// Set the left and top window position to zero if logic above has produced a value less than zero
	if (LeftPosition < 0) {	LeftPosition = 0;}
	if (TopPosition < 0) {	TopPosition = 0;}
	// Configure other window properties
	//alert(myHeight+"   "+myWidth);
	winProps = "left="+LeftPosition+",top="+TopPosition+",width=480,height=635,location=0,scrollbars=0,menubar=0,toolbar=0,resizable=" + allowResize;			
	binWin = window.open("", winName, winProps);
	//var actionURL = stockroot_url+"/bingo/flashbingolauncher.jsp";
	try
	{	document.forms[winName].target = winName;
		//document.forms[winName].action = actionURL;
		document.forms[winName].submit();

	}
	catch(e)
	{
		alert(e);
	}
	binWin.focus();
}

function openWinGame(gameName,gameType,configId)
{
     var windowname =gameName;
     while (windowname.indexOf(' ')!=-1){windowname=windowname.replace(' ','');}
     if(gameName!="Keno")
     {
		var date = new Date();
		var random_num = Math.random();
		var trackurl ="https://as1.emv2.com/P?emv_client_id=34509&emv_conversionflag=n&emv_pagename=game_window_page&emv_currency="+currency+"&emv_text1=PLAYERID_"+playerid_js+"&emv_text2=USERNAME_"+username+"&emv_date1="+date+"&emv_random="+random_num+"";
		//alert("URL="+trackurl);
		var trackImgDeposit = new Image();
		trackImgDeposit.src=trackurl;
     }
      allowResize = "yes";
      // Start at top left
      LeftPosition = 100;
      TopPosition = 0;
      // Go almost full-screen for Flash Bingo
      myHeight = (screen.height) ? (screen.height-145) : 455;
      myWidth = myHeight * 1.3475;
      // Set the left and top window position to zero if logic above has produced a value less than zero
      if (LeftPosition < 0) { LeftPosition = 0;}
      if (TopPosition < 0) { TopPosition = 0;}
      // Configure other window properties
      winProps = "left="+LeftPosition+",top="+TopPosition+",width="+myWidth+",height="+myHeight+",location=0,scrollbars=0,menubar=0,toolbar=0,resizable=" + allowResize;
      binWin = window.open("/commonapp/launchGame.jsp?gameName="+gameName+"&gameType="+gameType+"&configId="+configId, windowname, winProps);
      binWin.focus();
}


//adding the below functions for g2 bingo

function openBingoGame(gameName,streamId)
{
	try
	{
		 allowResize = "yes";
		 // Start at top left
		 LeftPosition = 100;
		 TopPosition = 0;
		 // Go almost full-screen for Flash Bingo
		 myHeight = screen.height;
		 myWidth = screen.width;
		 // Set the left and top window position to zero if logic above has produced a value less than zero
		 if (LeftPosition < 0) { LeftPosition = 0;}
		 if (TopPosition < 0) { TopPosition = 0;}
		 // Configure other window properties
		 var scroll	=	0;	
		 if (myHeight < 864 || myWidth < 1152 )
		 {
			 scroll	=	1;
		 }
		 winProps = "left="+LeftPosition+",top="+TopPosition+",width=1000,height=740,location=0,scrollbars="+scroll+",menubar=0,toolbar=0,resizable=" + allowResize;
		 var bossWin = window.open("/commonapp/bingo_launcher.jsp?gameName="+gameName+"&streamId="+streamId,streamId, winProps);
		 bossWin.focus();		
	}
	catch (e)
	{
	}
}

function launchStream(streamName)
{
	try {
		eval(streamName+"()");

	}catch(e) {
		alert('Room is not available, try again later');
	}
}
var unfinishedGameWin;
function openUnfinishedGame(gameVariantName,deploymentUrl,gcName,gameSessionId)
{
	if (unfinishedGameWin != null && !unfinishedGameWin.closed)
	{
		unfinishedGameWin.focus();
		unfinishedGameWin.alert("The game window is already open");
		return;
	}	
	try
	{
		 allowResize = "yes";
		 // Start at top left
		 LeftPosition = 100;
		 TopPosition = 0;
		 // Go almost full-screen for Flash Bingo
		 myHeight = screen.height;
		 myWidth = screen.width;
		 // Set the left and top window position to zero if logic above has produced a value less than zero
		 if (LeftPosition < 0) { LeftPosition = 0;}
		 if (TopPosition < 0) { TopPosition = 0;}
		 // Configure other window properties
		 var scroll	=	0;	
		 if (myHeight < 630 || myWidth < 800 )
		 {
			 scroll	=	1;
		 }
		 winProps = "left="+LeftPosition+",top="+TopPosition+",width=800,height=630,location=0,scrollbars="+scroll+",menubar=0,toolbar=0,resizable=" + allowResize;
		 unfinishedGameWin = window.open("/commonapp/unfinished_game_launcher.jsp?gameVariantName="+gameVariantName+"&deploymentUrl="+deploymentUrl+"&gameName="+gcName+"&gameSessionId="+gameSessionId,"unfinishedgame", winProps);
		 unfinishedGameWin.focus();		
	}
	catch (e)
	{
		alert(e);
	}
}

/**
Added by PavanPinnu
It return the actual parent window of the sub window chain.
*/
function getMainParentWindow () {
	if (window.opener == null) {
		return window;
	}

	if (window.opener.name == 'homewindow') {
		return window.opener;
	}

	var win = window;
	do {
		win = win.opener;
	} while (win.name != 'homewindow');

	return win;
}


//end of g2 bingo