//
// user-login.js
//
// requires :
//   trader.js
//   

var statisticsModuleInstance = new StatisticsModule();
statisticsModuleInstance.pageLoad();

function StatisticsModule () {

    this.URL_XML = "./";
    this.MENU_CONTAINER_ID = "menu";
    this.PAGE_CONTAINER_ID = "page";
    this.BLOCK_CONTAINER_ID = "block";
    
    this.pageLoad = function() {
        this.initVars();
    }
    
    this.initVars = function() {
        this.domain_id = null;
        this.plug_id = null;
    }
    
    this.target;
    
    this.fetchXmlData = function() {
        var xmlGet = this.generateGet();
        var xmlPost = this.generatePost();
        fetchXmlData(this.URL_XML, xmlGet, xmlPost);
        
        this.initVars();
    }
    
    this.module;
    this.method;
    
    this.generateGet = function() {
        var params = "";

        params = appendUrlParam(params, "m", this.module);
        params = appendUrlParam(params, "method", this.method);
        params = appendUrlParam(params, "target", this.target);
        
        if(this.from_time)
            params = appendUrlParam(params, "from_time", this.from_time);
        
        if(this.to_time)
            params = appendUrlParam(params, "to_time", this.to_time);

        if(this.domain_id)
            params = appendUrlParam(params, "domain_id", this.domain_id);
        
        if(this.plug_id)
            params = appendUrlParam(params, "plug_id", this.plug_id);

        return params;
    }
    
    this.generatePost = function() {
        var params = "";

        return params;
    }
    
    this.viewGlobalStats = function() {
        this.module = "stats-global";
        this.method = "ajax";
        this.target = this.BLOCK_CONTAINER_ID;
        this.fetchXmlData();
    }
    
    this.domain_id;
    this.plug_id;
    this.from_time;
    this.to_time;
    
    this.viewDomainStats = function(id) {
        this.domain_id = id;
        
        this.module = "stats-domain";
        this.method = "ajax";
        this.target = this.BLOCK_CONTAINER_ID;
        this.fetchXmlData();
    }
    
    this.changePeriod = function(from_time, to_time, module, id) {
        this.from_time = from_time;
        this.to_time = to_time;
        if(id)
            this.domain_id = id;
        
        this.module = module;
        this.method = "ajax";
        this.target = this.BLOCK_CONTAINER_ID;
        this.fetchXmlData();
    }
    
    this.viewPlugsStats = function() {
        this.module = "stats-plugs";
        this.method = "ajax";
        this.target = this.BLOCK_CONTAINER_ID;
        this.fetchXmlData();
    }
    
    this.viewPlugStats = function(id) {
        this.plug_id = id;
        this.module = "stats-plug";
        this.method = "ajax";
        this.target = this.BLOCK_CONTAINER_ID;
        this.fetchXmlData();
    }
}