﻿function OpenTCWindow()
{
	var url = "https://www.virgingames.com/bingo/info/terms.aspx";
	
	if (arguments.length > 0) {
		//arguments are key/value pairs, to be converted into representing querystring key/value pairs
		for (var i=0; i < arguments.length; i=i+2){
			url += arguments[i] + "=" + arguments[i+1] + "&";	
		}
		
		//remove trailing &
		url = url.substring(0, url.length-1);
	}
	
	var w = 618;
	var h = 500;
	var left = screen.availWidth/2-(w/2);
	var top = screen.availHeight/2-(h/2);
	window.open(url,"Bingo","width="+w+",height="+h+",left="+left+",top="+top+",scrollbars=yes,resizable=yes");
}
	
//Launches a Casino game. The game to open is passed in the 'arguments' as a key/value pair
function OpenLaunchWindow()
{	    
	var url = "/bingo/gamelaunch.aspx?";
	
	if (arguments.length > 0) {
		//arguments are key/value pairs, to be converted into representing querystring key/value pairs
		for (var i=0; i < arguments.length; i=i+2){
			url += arguments[i] + "=" + arguments[i+1] + "&";	
		}
		
		//remove trailing &
		url = url.substring(0, url.length-1);
	}
	
	var w = 520;
	var h = 210;
	var left = screen.availWidth/2-(w/2);
	var top = screen.availHeight/2-(h/2);
	
	//Note, this window must be called "gameWindow" as all wagerworks gameconsole/gamelaunch processes target that name
	var winHandle;
	winHandle = window.open(url,"gameWindow","status,width="+w+",height="+h+",left="+left+",top="+top+",scrollbars=no,resizable=yes");
	winHandle.focus();
}

///// Cookie Dealing - BEGIN
function createCookie(name,value,days) {
    var expires = "";
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	document.cookie = name + "=" + value + expires + "; path=/;"; //domain=" + document.domain + ";";
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
///// Cookie Dealing - END

//Internal function to launch a game from Flash
//If cookies created then refresh executes dynamic javascript created by uc\GameLaunch.ascx.cs - RefreshParentAndRedirect
function LaunchGameInternal(gameCode, target, cookieFlag, cookieGame)
{
    createCookie(cookieFlag, 1, 0);
    createCookie(cookieGame, gameCode + '-' + target, 0);
    RefreshMe();
}

// bingomenu timetable hide/show - start kf
function ShowInfo(infoCont, infoNav)
{
	showLyr(infoCont);  hideLyr(infoNav);
}
function HideInfo(infoCont, infoNav)
{
	hideLyr(infoCont);  showLyr(infoNav);
}
// bingomenu timetable hide/show - end

function goThenClose(loc)
{
    if (opener != null && !opener.closed)
	    opener.location.href=loc;
    else
	    opener = window.open(loc, "parent");
    	
    window.blur();
    self.setTimeout('self.close()', 1000); 
}

//If event is 'Enter' emulates a call to the element with 'buttonId'
function doClick(event, buttonId)
{
    //the purpose of this function is to allow the enter key to 
    //point to the correct button to click.
    var keynum = 0;
    if(event.keyCode) // IE
    {
      keynum = event.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
      keynum = event.which;
    }
    
    if (keynum == 13)
    {
        //Get the button the user wants to have clicked
        var btn = document.getElementById(buttonId);
        if (btn != null)
        { //If we find the button click it
            btn.click();
            return false;
        }
    }
    return true;
}
