function ABTestEngine() {
  this.A_PAGE_COOKIE_VALUE = "showA";
  this.B_PAGE_COOKIE_VALUE = "7469B";
  this.ABE_VISITOR_COOKIE_NAME = "abe_vc";
  this.url = "";
  this.bPagePercentage = "";
  this.aBFileName = "";
  this.aBTestCookieName = "";
  this.coremetricsTag = "";
  this.xmlhttp = null;
  this.aBCookieLife = "";
  this.applyToFirstTimeVisitorsOnly = false;

  this.init = function(bPagePercentage, aBTestCookieName, aBCookieLife, isServletPage, applyToFirstTimeVisitorsOnly) {
    this.bPagePercentage = bPagePercentage;
    this.aBFileName = "/staticABTesting/" + aBTestCookieName + "/";
    this.aBTestCookieName = aBTestCookieName;
    this.url = window.location.href;
    this.aBCookieLife = aBCookieLife;
    this.applyToFirstTimeVisitorsOnly = applyToFirstTimeVisitorsOnly;
    this.isServletPage = isServletPage;

    if (document.cookie) {
      this._doABTest();
    } else {
      this.coremetricsTag = "_CookiesOFF";
      this._renderCoremetricsTag();
    }
  };

  this._doABTest = function() {
    var abCookieValue = AbeCookie_getValue(this.aBTestCookieName) || null;
    if (abCookieValue == null) {
      this._startABTest();
    } else if (abCookieValue == this.B_PAGE_COOKIE_VALUE) {
      this.pageToDisplay = "b";
    }
    this._setPageToDisplay();
  };

  this._startABTest = function() {
    if (this.applyToFirstTimeVisitorsOnly) {
      // Test applies to first-time visitors only.
      var abeVisitorCount = AbeCookie_getValue(this.ABE_VISITOR_COOKIE_NAME) || null;
      if (abeVisitorCount == null || parseInt(abeVisitorCount) == 1) {
        // Surfer is a first-time visitor.
        this._setABTestCookie();
      }
    } else {
      // Test applies to everyone.
      this._setABTestCookie();
    }
  };

  this._setABTestCookie = function() {
    var baker = new AbeCookie();
    var cookieLife = this.aBCookieLife * 1;
    var cookieValue = (parseInt((Math.random() * 100) + 1) < (this.bPagePercentage * 1))? this.B_PAGE_COOKIE_VALUE : this.A_PAGE_COOKIE_VALUE;
    baker.bake(this.aBTestCookieName, cookieValue, cookieLife, '/');
    if(cookieValue == this.B_PAGE_COOKIE_VALUE) {
      this.pageToDisplay = "b";
    }
  };

  this._fetchBPageContent = function() {
    var fileLocation = this.aBFileName + this.pageToDisplay + ".shtml";
    if (window.XMLHttpRequest) {
      // For all new browsers.
      this.xmlhttp = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
      // IE5 and IE6.
      this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    if (this.xmlhttp != null) {
      var abtest = this;
      abtest.xmlhttp.onreadystatechange = function() {
        var RESPONSE_STATUS_OK = 200;
        var XMLHTTP_REQUEST_COMPLETE = 4;

        if (abtest.xmlhttp.readyState == XMLHTTP_REQUEST_COMPLETE) {
          if (abtest.xmlhttp.status != RESPONSE_STATUS_OK) {
            // Error fetching b-page content.
            abtest.coremetricsTag = "_Error";
          } else {
             var aContentElement = document.getElementById("bContent") || null;
             if (aContentElement != null) {
               aContentElement.innerHTML = abtest.xmlhttp.responseText;
             }
          }
          abtest._renderCoremetricsTag();
        }
      };
      abtest.xmlhttp.open("GET", fileLocation, true);
      abtest.xmlhttp.send(null);
    }
  };

  this._setPageToDisplay = function() {
    if(this.url.indexOf("show") != -1) {
      var internalOverride = this.url.indexOf("show_");
      this.pageToDisplay = this.url.substring((internalOverride + 5), (internalOverride + 6));
    }

    this.coremetricsTag = "";
    if (this.pageToDisplay == "b") {
      this.coremetricsTag = "_B";
      this._fetchBPageContent();
    } else {
      this._renderCoremetricsTag();
    }
  };

  this._renderCoremetricsTag = function() {
    if(!this.isServletPage) {
      // This is a static page.
      if (this._isSupressPageViewTagChange()) {
        return;
      }
      var cmUrl = window.location.pathname;
      cmCreatePageviewTag(cmUrl + this.coremetricsTag);
    }
  };

  /**
   * Override this function to supress alteration of pageview tag.
   */
  this._isSupressPageViewTagChange = function() {
    return false;
  };
}
