  var RequestTracker = function() {
    this.enabled = false;
    this.startDate = null;
    this.processName;
    this.moduleName;
    this.ready = false;
    this.requestStates = [];
    this.backLinkActive = false;
  };
  RequestTracker.prototype.initStartDate = function() {
    if (this.startDate == null) {
      this.startDate = new Date();
    }
  };
  RequestTracker.prototype.setEnabled = function(enabled) {
    this.enabled = enabled;
  };
  RequestTracker.prototype.selectProcess = function(processName) {
    this.processName = processName;
  };
  RequestTracker.prototype.selectModule = function(moduleName) {
    this.moduleName = RequestTracker.mapping.modules[moduleName];
  };
  RequestTracker.prototype.setRequestReady = function(ready) {
    this.ready = ready;
  };
  RequestTracker.prototype.clearStates = function() {
    this.requestStates = [];
  };
  RequestTracker.prototype.selectState = function(stateName) {
    this.requestStates[this.requestStates.length] = RequestTracker.mapping.modules[stateName];
  };
  RequestTracker.prototype.trackBackLink = function(backLinkActive) {
    this.backLinkActive = backLinkActive;
  };
  RequestTracker.prototype.handleBackLink = function() {
    if (this.backLinkActive) {
      this.sendRequestStates();
    }
  };
  RequestTracker.prototype.sendRequestStates = function() {
    var mapping = RequestTracker.mapping;

    if (this.enabled && this.processName) {
      var endDate = new Date();
      var duration = endDate - this.startDate;

      var queryStr = 'f__;;h__;;i__;;j__;;k__;;l__;;m__;;n__;;o__;;p__;;';
      queryStr += mapping.overallDuration + '__' + Math.round(duration / 1000) + ';;';
      queryStr += mapping.mode + '__' + ((this.ready) ? '1' : '0') + ';;'
      queryStr += mapping.abortModule + '__' + ((this.moduleName) ? this.moduleName : mapping.modules['step_checkList']) + ';;';
      queryStr += mapping.finishedModules + '__' + this.requestStates.sort().join(',');

      openVocatusPopUp(this.processName, queryStr);

      this.enabled = false;
      this.processName = '';
    }
  };
  RequestTracker.mapping = {
    modules: {
      step_aco: 1,
      step_dlo: 2,
      step_rfa: 3,
      step_rfi: 4,
      step_rfo: 5,
      step_tda: 6,
      step_vco: 7,
      step_asu: 8,
      step_sfi: 9,
      step_customerComment: 10,
      step_testdriveVehicle: 11,
      step_testdriveDate: 12,
      step_tradeIn: 13,
      step_informationMaterial: 14,
      step_checkList: 15
    },
    overallDuration: 'g',
    mode: 'q',
    abortModule: 'r',
    finishedModules: 's'
  };
  RequestTracker.initialize = function() {
    tracker = new RequestTracker();
  };
  RequestTracker.terminate = function() {
    if (tracker) {
      tracker.sendRequestStates();
    }
  };

  var tracker = new RequestTracker();

  if (window.addEventListener) {
    window.addEventListener("unload", RequestTracker.terminate, false);
    // window.addEventListener("load", RequestTracker.initialize, true);
  } else if (window.attachEvent) {
    window.attachEvent("onunload", RequestTracker.terminate);
    // window.attachEvent("onload", RequestTracker.initialize);
  }

