/**
 *  Global Calls
 */
(function()
{
    /**
     *  Fix IE background image flicker
     *  http://www.mister-pixel.com/
     */
    try
    {
        document.execCommand('BackgroundImageCache', false, true);
    }
    catch(e)
    {}
})();

function openGame(name) {
    var loc;
    loc = "/games/" + name;
    rev = "width:75% height:90% overlayOpacity:90 enableDrag:false hideFlash:true outsideClickCloses:false "; //http://randomous.com/tools/floatbox/options.php
    fb.loadAnchor(loc, rev);
    DisableCheckAuthenticationTimeout();
}


function setCookie(name,value,days) {
    if (days) {
	    var date = new Date();
	    date.setTime(date.getTime()+(days*24*60*60*1000));
	    var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(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;
}

/* Setting focus to first field in swf*/
function setFocusOnFlash() {
    var fl = document.getElementById( 'flash' );
    if ( fl ) { fl.focus(); }
}


//Global variable for check authenticate session timeout
var checkTimeout = true;
var authenticateTimeoutRedirectUrl = "";
var startCheckTime = new Date().getTime();
var lastCheckTime = startCheckTime;

function EnableCheckAuthenticationTimeout()
{
    checkTimeout = true;
    CheckAuthenticationTimeout();
    //alert("enable");
}

function DisableCheckAuthenticationTimeout()
{
    checkTimeout = false;
    //alert("disable");
}

function CheckAuthenticationTimeout()
{
    if (checkTimeout == true) 
    {
        //assigning minutes left to session timeout to Label
        var timeout = getCookie("Timeout");
        //alert(timeout); 
        var currentTime = new Date().getTime();
        timeout = timeout - ((currentTime - lastCheckTime)/1000/60); 
        lastCheckTime = currentTime;
        setCookie("Timeout", timeout);
            
        //alert(timeout); 
        
        //if session is larger than 0
        if (timeout > 1)
        {            
            //call the function again after 1 minute delay
            window.setTimeout("CheckAuthenticationTimeout()", 60000);
        }
        else
        {
            //show message box
            window.location = authenticateTimeoutRedirectUrl;  
        }
    }

}
