var games = new Array();
var sessionId = "";
var socketPort = "";
var hostName = "";
var occasionId = "";
var showStandings = false;
var winObj = null;
var tableId = null;
var tournamentName = "";
var openNewLobby = false;
var redirectPageName;
var multitableTypeId;
var pokerTableNumber = -1;
var occurDate = -1;
var adFamilyId = -1;
var tournamentType = "";
 
function getSessionId(){
    return sessionId;
}

function getHostName(){
	return hostName;
}

function getPort(){
	return socketPort;
}

function getWObject(){
  return winObj;
}

function getOccasionId(){
	return occasionId;
}

function isShowStandings(){
	return showStandings;
}

function getTournamentName(){
	return tournamentName;
}

function getTableId(){
	return tableId;
}

function choiceOldGame(pageName, multitableType, sessId, userId) {
	if( setWindowName ){
		setWindowName();
	}
	
	var suffix = "&rnd=" + new Date().getTime();
	if ( ! multitableType || multitableType=='X' || multitableType == -1 || multitableType == 0 )
		window.open(pageName + '.ehtml?sp=1&sp=' + sessId + suffix, 'nlopMain' + userId);
	else
		window.open(pageName + '.ehtml?sp=' + multitableType + '&sp=1&sp=' + sessId + suffix, 'nlopMain' + userId);
}

function closeChoiceOldGame(userId) {
	window.close();
	window.open("LobbyPokerRoom.thtml", 'nlopMain' + userId);
}

function openTable( p_socketPort, p_sessionId, p_occasionId, p_showStandings, p_tournamentName,
					p_tableId, p_openNewLobby, p_redirectPageName, p_multitableTypeId, p_hostName,
					p_pokerTableNumber, p_occurDate, p_adFamilyId, p_tournamentType )
{
	try{
		openTableUnsafe( p_socketPort, p_sessionId, p_occasionId, p_showStandings, p_tournamentName,
					p_tableId, p_openNewLobby, p_redirectPageName, p_multitableTypeId, p_hostName,
					p_pokerTableNumber, p_occurDate, p_adFamilyId, p_tournamentType );
	}catch(e){
		if( typeof showPopupInstructions != 'undefined' ){
			showPopupInstructions();
		}
	}
}

function openTableUnsafeByParamsArray( p_paramsArray ){
	var p = p_paramsArray;
	openTableUnsafe( p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13] );
}

function openTableUnsafe( p_socketPort, p_sessionId, p_occasionId, p_showStandings, p_tournamentName,
					p_tableId, p_openNewLobby, p_redirectPageName, p_multitableTypeId, p_hostName,
					p_pokerTableNumber, p_occurDate, p_adFamilyId, p_tournamentType )
{
	if( !p_occurDate ){
		p_occurDate = -1;
	}

	if( setWindowName ){
		setWindowName();
	}
	
	openNewLobby = p_openNewLobby;
	socketPort = p_socketPort;
	sessionId = p_sessionId;
	occasionId = p_occasionId;
	showStandings = p_showStandings;
	tournamentName = p_tournamentName;
	tableId = p_tableId;
	redirectPageName = p_redirectPageName;
	multitableTypeId = p_multitableTypeId;
	hostName = p_hostName;
	pokerTableNumber = p_pokerTableNumber;
	occurDate = p_occurDate;
	adFamilyId = p_adFamilyId;
	tournamentType = p_tournamentType;

	winObj = new Object();
	winObj.port = socketPort;
	winObj.session = sessionId;
	winObj.occasionId = occasionId;
	winObj.showStandings = showStandings;
	winObj.tournamentName = tournamentName;
	winObj.tableId = tableId;
	winObj.redirectPageName = p_redirectPageName;
	winObj.multitableTypeId = p_multitableTypeId;
	winObj.hostName = hostName;
	winObj.pokerTableNumber = p_pokerTableNumber;
	winObj.occurDate = p_occurDate;
	winObj.adFamilyId = p_adFamilyId;
	winObj.tournamentType = p_tournamentType;

	var suffix = "&rnddelta=" + new Date().getTime();
	
	var dialogHeight = "700px";
	var dialogWidth = "950px";
	
	if( window.XMLHttpRequest && window.ActiveXObject ) {
		dialogHeight = "648px";
		dialogWidth = "944px";
	}
	
	// var gmwin = window.showModalDialog("GameBase.ehtml?sp=S" + socketPort + "&sp=S" + sessionId, window, 'dialogHeight: 645px; dialogWidth: 945px; resizable: 0; status: 0; help: 0;');
	var urla =	"poker/gamebase?sp=S" + socketPort + "&sp=S" + sessionId + "&sp=S" + hostName
				+ "&sp=l" + p_occurDate + "&sp=S" + tournamentName + "&sp=" + adFamilyId + "&sp=S" + tournamentType + suffix;
	var winParams = "dialogHeight: " + dialogHeight + "; dialogWidth: " + dialogWidth + "; center: 1; resizable: 0; status: 1; help: 0; scroll: 0";
	
	// alert ("Urla = " + urla );
	var gmwin = window.showModalDialog( urla, window, winParams );
}

 function activateTable(index){
	games[index].win.focus();

 }


function checkIsIEBrowser() {
    var agt = navigator.userAgent.toLowerCase();
    
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    var is_ie	= ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
		
	if( is_ie ){
		return true;
	} else {
		return false;
	}
}

function assertObject( obj ){
	return obj != null && typeof( obj ) != 'undefined';
}

function popupBanner(adId, width, height) {
	features = 'location=0,menubar=0,resizable=0,toolbar=0,status=0,fullscreen=0,directories=0,scrollbars=0';
	if ( width )
		features = features + ',width=' + width;
	if ( height )
		features = features + ',height=' + height;
	window.open( 'PopupBanner.ehtml?sp=' + adId, 'PopupBanner', features );	
}
