﻿///////////////////////////////////////////////////////////////////////////////
// Put here ONLY common functions for ALL THE WEBSITES
// Only functions that are reused in MyAccount, Bingo, Casino, Poker
// If javascript specific MyAccount functions, please put them in 'main.js'
///////////////////////////////////////////////////////////////////////////////

function RefreshMe()
{
    try
    {
         document.forms[0].submit();
    }
    catch(err)
    {
    }
}

//Reloads the browser window with the url specified. If url is string empty reloads the same window
function WindowReload(url)
{
    try
    {
        if (url == '')
        {
           window.location.reload();
        }
        else
        {
           window.location = url;
        }
    }
    catch(err)
    {
    }
}


function RefreshVPoints()
{
    try
    {
        document.forms[0].submit();
    }
    catch(err)
    {
    }
}

function ShowPanelMessage(panelId, messageId, message)
{
      document.getElementById(panelId).style.display="block";
      var msgHolder = document.getElementById(messageId).innerHTML = message;
}


/* Applies the 'inputOnFocus' style to elements (the style as defined in CSS file is only for input, textbox...) */
function OnFocus(id)
{
   if (!Sys.UI.DomElement.containsCssClass($get(id), "inputOnFocus"))
   {
       Sys.UI.DomElement.addCssClass($get(id), "inputOnFocus");
   }
}       

function OnBlur(id)
{
   if (Sys.UI.DomElement.containsCssClass($get(id), "inputOnFocus"))
   {
       Sys.UI.DomElement.removeCssClass($get(id), "inputOnFocus");
   }
}

function SetFocus(id)
{
    $find(id)._onFocus();
}

//* resize login iframe on login - start

function ReSizeLoginIframe()
	{
		AutosizeIFrame('ctl00_iLogin', 280); //270
	}

function CalcIFrameHeight(iFrameId){
	
	try {	    
	    //iframe internal page height
		var iframeHeight = document.getElementById(iFrameId).contentWindow.document.body.scrollHeight;
        
        document.getElementById(iFrameId).height = iframeHeight;
     }
	catch (e) { }
}

function AutosizeIFrame(iFrameId, minHeight)
{
    var iFrameObject = document.getElementById(iFrameId);
    if (iFrameObject != null)
    {        
        //var contentHeight= GetContentHeight(iFrameObject);
        //iFrameObject.height = (contentHeight < minHeight ? minHeight : contentHeight);
        iFrameObject.height= minHeight;
        //alert("AutosizeIFrame: " + iFrameObject.height);
    }
}
    
function GetContentHeight(iFrameObject)
{
    var contentHeight = 1;
    
    if (navigator.appName != "Microsoft Internet Explorer" && !window.opera && !document.mimeType && document.all && document.getElementById)           
        contentHeight = iFrameObject.contentWindow.document.body.offsetHeight;
    else if(document.getElementById)
        contentHeight = iFrameObject.contentWindow.document.body.scrollHeight;
    
    return contentHeight;
}

//Checks if the key pressed is Enter key
function IsEnterKey(e)
{
    var keynum = 0;
    if(e.keyCode) // IE
    {
      keynum = e.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
      keynum = e.which;
    }
    return keynum == 13;
}

//* resize login iframe on login - end

//Generates the code to display a Flash passing the absolute path
function DisplayFlashAbsolute(path, width, height, backgroundColor, flashVars, areaId)
{
    var so = new VgmSWFObject(path, areaId, width, height, "9", backgroundColor);
    so.addParam("salign", "lt");   
    so.addParam("scale", "noscale");                     
    so.addParam("wmode", "transparent");
    if (flashVars != "")
    {
       so.addParam("FlashVars", flashVars);
    }
    so.write(areaId);
 }

//Generates the code to display a Flash file contained in /MyAccount/swf/
function DisplayFlash(path, width, height, backgroundColor, flashVars, areaId)
{
    DisplayFlashAbsolute("/MyAccount/swf/" + path, width, height, backgroundColor, flashVars, areaId);
 }
 
 

//Opens a window with the specified Width x Height
var openWindowRef;  //Global reference to know if window is already open

function OpenWindow(theURL, theWidth, theHeight)
{
    openWindowRef=  OpenWindow(theURL, theWidth, theHeight, "_blank");

    return openWindowRef;
}

function OpenWindow(theURL, theWidth, theHeight, target)
{
    //if (openWindowRef && !openWindowRef.closed) { openWindowRef.close() }

    var availHeight = screen.availHeight - 50; //discounting Windows taskbar
    var winWidth = (screen.availWidth >= theWidth ) ? theWidth : screen.availWidth;
    var winHeight = (availHeight >= theHeight) ? theHeight : availHeight;
    var winLeft = (screen.availWidth-winWidth)/2;

    var winSettings ='height='+winHeight+',width='+winWidth+',top=0,left='+winLeft+',toolbar=no,location=no,scrollbars=yes,resizable=yes,titlebar=no';

    openWindowRef = window.open(theURL, target, winSettings);

    if(openWindowRef)
    {
      openWindowRef.focus();
    }
    else
    {
        alert('We have detected that your popup blocker prevented us from launching Virgin Games window. Please enable your browser to allow this site to launch popups');
    }

    return openWindowRef;
}

function OpenFixedSizeWindow(theURL, theWidth, theHeight)
{
    openWindowRef = OpenFixedSizeWindow(theURL, theWidth, theHeight, "_blank");

    return openWindowRef;
}

function OpenFixedSizeWindow(theURL, theWidth, theHeight, target) {
    
    
    var availHeight = screen.availHeight - 50; //discounting Windows taskbar
    var winWidth = (screen.availWidth >= theWidth) ? theWidth : screen.availWidth;
    var winHeight = (availHeight >= theHeight) ? theHeight : availHeight;
    var winLeft = (screen.availWidth - winWidth) / 2;

    var winSettings = 'height=' + winHeight + ',width=' + winWidth + ',top=30,left=' + winLeft + ',toolbar=no,location=no,scrollbars=no,resizable=no,titlebar=no,directories=no';

    openWindowRef = window.open(theURL, target, winSettings);

    if (openWindowRef) {
        openWindowRef.focus();
    }
    else {
        alert('We have detected that your popup blocker prevented us from launching Virgin Games window. Please enable your browser to allow this site to launch popups');
    }

    return openWindowRef;
}

function ToggleLayer(layerId)
{
   var layer= document.getElementById(layerId);
   
   if (layer.style.display == 'block')
   {
       hideLyr(layerId)
   }
   else
   {
       showLyr(layerId)
   }
}

/* When required to show/hide table rows works different than 'div' IE and FF have different behaviour
   showText: message to display to indicate show
   hideText: message to display to indicate hide
   linkShowHideId: text will be replaced for this link
   rowId: Row we whant 
*/
function ToggleTableRow(showText, hideText, linkShowHideId, rowId)
{
    var element = document.getElementById(rowId);
    var link= document.getElementById(linkShowHideId);
    
	if (element.style.display == 'block' || element.style.display == 'table-row') 
	{
	    element.style.display = 'none';
	    link.innerHTML = showText;
	}
	else 
	{
	    try{
           element.style.display = 'table-row';
        }
        catch(e)
        {
           element.style.display = 'block';
        }
		link.innerHTML = hideText;
	}
}