aux = {
  strip: function(text) {
    return text.replace(/^\s+|\s+$/g, '');
  },

  encodeBase64: function(text) {
    var chars =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_ ";
    var c1, c2, c3, e1, e2, e3, e4;
    var result = "";
    var i = 0;
    while (i < text.length) {
      c1 = text.charCodeAt(i++);
      c2 = text.charCodeAt(i++);
      c3 = text.charCodeAt(i++);
      e1 = c1 >> 2;
      e2 = ((c1 & 3) << 4) | (c2 >> 4);
      e3 = ((c2 & 15) << 2) | (c3 >> 6);
      e4 = c3 & 63;
      if (isNaN(c2)) {
        e3 = e4 = 64;
      } else if (isNaN(c3)) {
        e4 = 64;
      }
      result = result + chars.charAt(e1) + chars.charAt(e2) +
          chars.charAt(e3) + chars.charAt(e4);
    }
    return this.strip(result);
  },

  getCookie: function(cookie_name) {
    var cookies = document.cookie.split(';');
    for (i = 0; i < cookies.length; i++) {
      var cookie = cookies[i].split('=');
      var name = this.strip(cookie[0]);
      if (name == cookie_name && cookie.length > 1) {
        return unescape(this.strip(cookie[1]));
      }
    }
    return null;
  },

  getNumber: function(element_id) {
    var rc = '';
    var rc_span = document.getElementById(element_id);
    if (rc_span != null) {
      rc = parseInt(rc_span.innerText);
      if (isNaN(rc)) {
        rc = '';
      }
    }
    return rc;
  },

  setCookie: function(cookieName, cookieValue, nDays) {
    var today = new Date();
    var expire = new Date();
    if (nDays == null || nDays == 0) nDays = 1;
    expire.setTime(today.getTime() + 3600000 * 24 * nDays);
    document.cookie = cookieName + "=" + escape(cookieValue) +
        ";path=/;expires=" + expire.toGMTString();
  }
};

omc = {
  setUid: function() {
    randuid = sha1Hash(Date() + this._sessionId());
    aux.setCookie(this._uidCookie(), randuid, 3650);
    return randuid;
  },

  _sessionCookie: function() {
    return this.sessionCookie || 'session_id';
  },

  _q: function() {
    return this.query || window.location.search;
  },

  _p: function() {
    return this.path || window.location.pathname;
  },

  _uidCookie: function() {
    return this.uidCookie || '_omc_uid';
  },

  _cId: function() {
    return this.cId || '';
  },

  _sessionId: function() {
    return aux.getCookie(this._sessionCookie());
  },

  _visitorHandle: function() {
    return this.visitorHandle ||
        aux.getCookie(this._uidCookie()) || this.setUid();
  },

  _resultCount: function() {
    return this.resultCount || aux.getNumber('result_count');
  },

  trackPageview: function() {
    document.write(unescape("%3C") +
        "img src='http://www.ses-astra.com/resources/img/omc/t.gif?l=" + this._cId() +
        "&s=" + this._sessionId() +
        "&d=" + aux.encodeBase64(window.location.host) +
        "&p=" + aux.encodeBase64(this._p()) +
        "&q=" + aux.encodeBase64(this._q()) +
        "&r=" + aux.encodeBase64(document.referrer) +
        "&rc=" + this._resultCount() +
        "&vh=" + this._visitorHandle() + "'" +
        unescape("/%3E"));
    return true;
  }
};
