var fsue =
{
    //private constant:
    FF                  : 0,      //firefox
    IE                  : 1,      //internet explorer

    FF_PAGE_OPEN        : '0100', //browser is firefox
    IE_PAGE_OPEN        : '0200', //browser is IE
    FF_ADD_ONS          : '0101', //FF and already installed add-ons
    FF_NO_ADD_ONS       : '0102', //FF and not yet installed add-ons
    IE_ADD_ONS          : '0201', //IE and already installed active-x
    IE_NO_ADD_ONS       : '0202', //IE and not yet installed active-x
    FF_BUTTON_INSTALL   : '0001', //clicked on the install button (FF)
    FF_BUTTON_START     : '0002', //clicked on start button (FF)
    IE_BUTTON_INSTALL   : '0003', //clicked on the install button (IE)
    IE_BUTTON_START     : '0004', //clicked on start button (IE)
    FF_INS_SUCCESS      : '0010', //firefox add-ons successfully installed
    FF_INS_FAIL         : '0020', //firefox add-ons install failed
    IE_INS_SUCCESS      : '0030', //ie add-ons successfully installed
    IE_INS_FAIL         : '0040', //ie add-ons install failed
    FF_OLS_DL_SUCCESS   : '0050', //successfully download ols, and launched (FF)
    FF_OLS_DL_FAIL      : '0060', //fail to download/launch (FF)
    IE_OLS_DL_SUCCESS   : '0070', //successfully download ols, and launched (IE)
    IE_OLS_DL_FAIL      : '0080', //fail to download/launch (IE)

    //private variables:
    date          : null,
    sessionvalue  : null,
    url           : 'https://olsstats.f-secure.com/stat.gif',
    action_header : '?laction=',
    isp_header    : '&lisp=',

    time          : function(){
        if(!this.date)
        {
            this.date = new Date();
        }
        return this.date;
    },

    getTimeDiff   : function(){
        if(!this.date)
        {
            this.date = new Date();
        }
        var now = new Date();
        return now.getTime() - this.date.getTime();
    },

    session       : function(){
        if(!this.sessionvalue)
        {
            this.sessionvalue = '&session=' + this.time().getTime() + '_' + Math.floor(Math.random()*1001);
        }
        return this.sessionvalue;
    },

    //private functions:
    send          : function(sPerformed, sIsp){
        var picSrc = this.url + this.action_header + sPerformed + escape(':') + this.getTimeDiff() + this.session()
                    + this.isp_header + escape(sIsp);
        this.openImage(picSrc);
    },

    openImage     : function(sUrl) {
        var pic = new Image();
        pic.src = sUrl;
        pic.onload = function(){};
    },

    //public functions:
    //@iBrowser : 0 - FF, 1 - IE
    pageOpened    : function(iBrowser, sIsp){
        switch(parseInt(iBrowser,10))
        {
            case this.FF:
                this.send(this.FF_PAGE_OPEN, sIsp);
                break;
            case this.IE:
                this.send(this.IE_PAGE_OPEN, sIsp);
                break;
            default:
                break;
        }
    },
    // @iBrowser : 0 - FF, 1 - IE
    // @iState : boolean (true if already installed)
    addOnsInstalled : function(iBrowser, iState, sIsp){
        switch(parseInt(iBrowser,10))
        {
            case this.FF:
                if(iState)
                {
                    this.send(this.FF_ADD_ONS, sIsp);
                }
                else
                {
                    this.send(this.FF_NO_ADD_ONS, sIsp);
                }
                break;
            case this.IE:
                if(iState)
                {
                    this.send(this.IE_ADD_ONS, sIsp);
                }
                else
                {
                    this.send(this.IE_NO_ADD_ONS, sIsp);
                }
                break;
            default:
                break;
        }
    },
    // @iBrowser : 0 - FF, 1 - IE
    buttonStart   : function(iBrowser,sIsp){
        switch(parseInt(iBrowser,10))
        {
            case this.FF:
                this.send(this.FF_BUTTON_START, sIsp);
                break;
            case this.IE:
                this.send(this.IE_BUTTON_START, sIsp);
                break;
            default:
                break;
        }
    },
    // @iBrowser : 0 - FF, 1 - IE
    buttonInstall : function(iBrowser, sIsp){
        switch(parseInt(iBrowser,10))
        {
            case this.FF:
                this.send(this.FF_BUTTON_INSTALL, sIsp);
                break;
            case this.IE:
                this.send(this.IE_BUTTON_INSTALL, sIsp);
                break;
            default:
                break;
        }
    },

    // @iBrowser : 0 - FF, 1 - IE
    // @iState : boolean (true if installation is successful)
    addOnsInstallSuccess  : function(iBrowser, iState, sIsp){
        switch(parseInt(iBrowser,10))
        {
            case this.FF:
                if(iState)
                {
                    this.send(this.FF_INS_SUCCESS, sIsp);
                }
                else
                {
                    this.send(this.FF_INS_FAIL, sIsp);
                }
                break;

            case this.IE:
                if(iState)
                {
                    this.send(this.IE_INS_SUCCESS, sIsp);
                }
                else
                {
                    this.send(this.IE_INS_FAIL, sIsp);
                }
                break;
            default:
                break;
        }
    },
    // @iBrowser : 0 - FF, 1 - IE
    // @iState : boolean (true if ols downloaded successfully)
    olsDownloadSuccess : function(iBrowser, iState, sIsp){
        switch(parseInt(iBrowser, 10))
        {
            case this.FF:
                if(iState)
                {
                    this.send(this.FF_OLS_DL_SUCCESS, sIsp);
                }
                else
                {
                    this.send(this.FF_OLS_DL_FAIL, sIsp);
                }
                break;
            case this.IE:
                if(iState)
                {
                    this.send(this.IE_OLS_DL_SUCCESS, sIsp);
                }
                else
                {
                    this.send(this.IE_OLS_DL_FAIL, sIsp);
                }
                break;
            default:
                break;
        }
    },
    //@iBrowser: 0- FF, 1 - IE
    //@sVersion: version of browser
    browser    : function(iBrowser, sVersion, sIsp){
        sVersion = sVersion || '';
        var sHeader  = '?lbrowser=';
        var sAppend  = '&version=';
        var sFF      = 'FF';
        var sIE      = 'IE';
        var picUrl   = '';
        switch(iBrowser)
        {
            case this.FF:
                picUrl = this.url + sHeader + sFF + sAppend + escape(sVersion) + this.session() + this.isp_header + escape(sIsp);
                break;
            case this.IE:
                picUrl = this.url + sHeader + sIE + sAppend + escape(sVersion) + this.session() + this.isp_header + escape(sIsp);
                break;
            default:
                break;
        }
        this.openImage(picUrl);
    }
};

function testFsue(){

var FF = 0;
var IE = 1;
var isp = 'F-Secure';
//FF
fsue.pageOpened(FF, isp);
fsue.addOnsInstalled(FF, true, isp);
fsue.addOnsInstalled(FF, false, isp);
fsue.buttonStart(FF, isp);
fsue.buttonInstall(FF, isp);
fsue.addOnsInstallSuccess(FF, true, isp);
fsue.addOnsInstallSuccess(FF, false, isp);
fsue.olsDownloadSuccess(FF, true, isp);
fsue.olsDownloadSuccess(FF, false, isp);
fsue.browser(FF, '3', isp);
//IE
fsue.pageOpened(IE, isp);
fsue.addOnsInstalled(IE, true, isp);
fsue.addOnsInstalled(IE, false, isp);
fsue.buttonStart(IE, isp);
fsue.buttonInstall(IE, isp);
fsue.addOnsInstallSuccess(IE, true, isp);
fsue.addOnsInstallSuccess(IE, false, isp);
fsue.olsDownloadSuccess(IE, true, isp);
fsue.olsDownloadSuccess(IE, false, isp);
fsue.browser(IE, '3', isp);

}