function ABTesting() {
  
};

ABTesting.prototype.setCookie = function(c_name, value, exdays)
{
  var exdate = new Date();
  exdate.setDate(exdate.getDate() + exdays);
  var c_value = encodeURIComponent(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
  document.cookie = c_name + "=" + c_value;
};


ABTesting.prototype.getCookie = function(c_name)
{
  var ARRcookies = document.cookie.split(";");
  var i;
  for (i = 0; i < ARRcookies.length; i++)
  {
    var idxEquals = ARRcookies[i].indexOf("=");
    var x = ARRcookies[i].substr(0, idxEquals);
    var y = ARRcookies[i].substr(idxEquals + 1);
    x = x.replace(/^\s+|\s+$/g, "");
    if (x == c_name)
    {
      return decodeURIComponent(y);
    }
  }
  return null;
};

ABTesting.prototype.installTest = function(variants)
{
  var cookieName = "experiment_assignment";
  var cookie = this.getCookie(cookieName);
  try
  {
    if (cookie != null && cookie != "")
    {
      var n = parseInt(cookie);
      if (n != Number.NaN)
      {
//        alert ("Parsed cookie: " + n + " Variants " + variants);
        return n % variants;
      }
    }
  }
  catch (x)
  {
//    alert("Error " + x)
    // ignored ..
  }

  var randomNumber=Math.floor(Math.random()*120);

  this.setCookie(cookieName, randomNumber, 60);
  return randomNumber % variants;
};


