﻿var _StatSent = false;

function SendPageStats(ClientID, MachineID, DistributionSource, Profile, ServerID, Version, Language, InstallDate, AdditionalInfoXML) {

    var statsURL = BuildStatsURL("http://stats.avg.com/services/_utmh.gif?", ClientID, MachineID, DistributionSource, Profile, ServerID, Version, Language, InstallDate, AdditionalInfoXML);    
    SendStat(statsURL);
}

function SendSearchStats(ClientID, MachineID, DistributionSource, Profile, ServerID, Version, Language, InstallDate, AdditionalInfoXML) {
    var statsURL = BuildStatsURL("http://stats.avg.com/services/_utms.gif?", ClientID, MachineID, DistributionSource, Profile, ServerID, Version, Language, InstallDate, AdditionalInfoXML);
    SendStat(statsURL);
}

function BuildStatsURL(BaseStatURL, ClientID, MachineID, DistributionSource, Profile, ServerID, Version, Language, InstallDate, AdditionalInfoXML) {
    var referrerURL = escape(document.referrer);
    var currentPageURL = escape(location.href);    

    var statsURL = BaseStatURL + 
                   "ClientID=" + ClientID +
                   "&MachineID=" + MachineID +
                   "&DistributionSource=" + DistributionSource +
                   "&Profile=" + Profile +
                   "&ServerID=" + ServerID +
                   "&Version=" + Version +
                   "&Language=" + Language +
                   "&InstallDate=" + InstallDate +
                   "&AdditionalInfoXML=" + AdditionalInfoXML +
                   "&CurrentPageURL=" + currentPageURL +
                   "&ReferrerURL=" + referrerURL +
                   "&rand=" + Math.random();
    return statsURL;
}

function SendStat(url) {
    if (_StatSent)
        return;
    var maxUrlLen = 2000;
    url = url.length > maxUrlLen ? url.substr(0, maxUrlLen - 1) : url;
    try {
        if (navigator.userAgent.indexOf("MSIE") > -1) {
            var ifr = document.getElementById("statsFrm");
            ifr.setAttribute("src", url);            
        }
        else {
            var statImg = new Image();            
            statImg.src = url;
        }
    }
    catch (e) { }

    _StatSent = true;
}
