﻿// JScript File

var AC_FL_RunContent = 0;
var fimName = 'fim';
var casinoMode = null;
var fimDir;

if(typeof xmlstring !== 'undefined')
{
    fimDir = xmlstring;
}
 
function getFim(swfId)
{
  if (window[swfId]) {
		return window[swfId];
	}
	return document[swfId];
}
 
function launchCasinoFreePlay(module) 
{   
    if(clientParams.indexOf("&livenetworkid=") > -1)
    {
        clientParams = clientParams.substring(0, clientParams.indexOf("&livenetworkid="));
        getFim(fimName).setClientParams(clientParams); 
    }
    setFreePlayCookie();    
    openFreePlayClient(module);
}
 
function launchCasinoFreePlayLive(module, networkId)
{
    if(networkId!=undefined)
    {
        if(clientParams.indexOf("&livenetworkid=") > -1)
        {
            clientParams = clientParams.substring(0, clientParams.indexOf("&livenetworkid="));
        }
        clientParams = clientParams+"&livenetworkid="+networkId;
        getFim(fimName).setClientParams(clientParams); 
    }       
    setFreePlayCookie();    
    openFreePlayClient(module);
}

function launchCasino(module) 
{    
    if(clientParams.indexOf("&livenetworkid=") > -1)
    {
        clientParams = clientParams.substring(0, clientParams.indexOf("&livenetworkid="));
        getFim(fimName).setClientParams(clientParams); 
    }
    logActivity(module, 0);
    setRealPlayCookie();
    openRealPlayClient(module);
}

function launchCasinoLive(module,networkId)
{
    if(networkId!=undefined)
    {
        if(clientParams.indexOf("&livenetworkid=") > -1)
        {
            clientParams = clientParams.substring(0, clientParams.indexOf("&livenetworkid="));
        }
        clientParams = clientParams+"&livenetworkid="+networkId;
        getFim(fimName).setClientParams(clientParams); 
    }
    logActivity(module, networkId);
    setRealPlayCookie();
    openRealPlayClient(module);
}

function setFreePlayCookie()
{
    var exdate=new Date();        
    var currenthours = exdate.getHours();      
    currenthours += 3;               
    exdate.setHours(currenthours);
    document.cookie = "casinoGameMode=freePlay;expires="+exdate.toGMTString()+";path=/";
}

function setRealPlayCookie()
{
    var exdate=new Date();        
    var currenthours = exdate.getHours();      
    currenthours += 3;               
    exdate.setHours(currenthours);   
    document.cookie = "casinoGameMode=real;expires="+exdate.toGMTString()+";path=/";
}

function openFreePlayClient(module)
{
    if(getFim(fimName).isSessionActive("casino") == true)
    {
        getFim(fimName).close("casino", false);    
    }
    getFim(fimName).launchClient("casino", module, "offline");
}

function openRealPlayClient(module)
{
    getFim(fimName).launchClient("casino", module, "real");
}

function logActivity(gameCode, liveNetwork)
{
    var xmlhttp = new ajaxRequest();
    if(xmlhttp != null)
    {
        var trackingURL = "/Tracker/CasinoLogActivity.aspx?GameCode=" + gameCode + "&LiveNetworkId=" + liveNetwork
        xmlhttp.open("POST", trackingURL, true); 
        xmlhttp.send("");
    }
}

function ajaxRequest()
{
    if (window.XMLHttpRequest)
    {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    { 
        // code for IE6, IE5
        return  new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {
        return null;
    }
}
