
//  This file is the sole property of MediaZam.  Any use of of this complete file
//  or use of any incomplete portion of this file MUST be licensed.  Any unlicensed
//  use of this file violates federal law.

/// LOCAL VARIABLES
var LOG_BASE_PAGE = 'http://www.voicezam.com/Zamtistics/LogZamtistic.aspx';
var PLAYER_PORTAL = null;
var PLAYER_OWNERID = null;
var PLAYER_CLIENTID = null;

/// GLOBAL SETTINGS FUNCTIONS
function setPortal(portal) { PLAYER_PORTAL = portal; }
function setClientId(clientId) { PLAYER_CLIENTID = clientId; }
function setAgentId(agentId) { PLAYER_OWNERID = agentId; }

/// LOG THE ZAMTISTIC
function createReadZamtistic(readName, demoName, comment)
{
    createZamtistic(readName, demoName, comment, false);
}

function createDemoZamtistic(demoName, comment)
{
    createZamtistic(null, demoName, comment, false);
}

function createReadDownloadZamtistic(readName, demoName, comment, downloadBytes)
{
    createZamtistic(readName, demoName, comment, true, downloadBytes);
}

function createDemoDownloadZamtistic(demoName, comment, downloadBytes)
{
    createZamtistic(null, demoName, comment, true, downloadBytes);
}

function createZamtistic(readName, demoName, comment, isDownload, downloadBytes)
{
    // Make sure the clientId is filled in
    if (PLAYER_CLIENTID == null && demoName != null && PLAYER_CLIENTID != '' && demoName != '')
        return;
        
    // Make sure the "isDownload" is set
    if (isDownload == null) isDownload = false;
    isDownload = !(!isDownload);

    var iFrame = document.createElement("IFRAME");
    iFrame.id = 'frame' + Math.random()*10;
    iFrame.src = LOG_BASE_PAGE + '?'
        + (readName != null ? 'r=' + escape(readName) + '&' : '')
        + 'p=' + (PLAYER_PORTAL != null ? escape(PLAYER_PORTAL) : window.location.hostname)
        + '&d=' + demoName
        + '&c=' + PLAYER_CLIENTID
        + (PLAYER_OWNERID != null ? '&o=' + PLAYER_OWNERID + '&' : '')
        + (isDownload ? '&t=1' + (downloadBytes != null ? '&b=' + downloadBytes : '') : '')
        + (comment == null ? '' : '&com=' + escape(comment));
    iFrame.style.width = '1px';
    iFrame.style.height = '1px';
    iFrame.style.position = 'absolute';
    iFrame.style.zIndex = -99999;
    iFrame.style.top = '0px';
    iFrame.style.left = '0px';
    iFrame.style.visibility = 'hidden';
    document.body.appendChild(iFrame);
    
    window.setTimeout('removeFrame("' + iFrame.id + '")', 10000);
}

function removeFrame(frameId)
{
    var frameWindow = document.getElementById(frameId);
    if (frameWindow != null)
        document.body.removeChild(frameWindow);
}