function AdfLoopbackUtils() {
}
AdfLoopbackUtils._addCookie = function(name, value) {
  var d = new Date;
  d.setTime(d.getTime() + 3E4);
  var expires = "; expires\x3d" + d.toUTCString();
  document.cookie = name + "\x3d" + (value != null ? value : "") + expires + "; path\x3d/"
};
AdfLoopbackUtils._addParam = function(queryString, paramName, cookieName, value, isCookie) {
  try {
    if(isCookie) {
      AdfLoopbackUtils._addCookie(cookieName, value)
    }else {
      var hasValue = value != null && value !== "";
      if(hasValue) {
        if(queryString == null || queryString === "") {
          queryString = "?"
        }else {
          queryString += "\x26"
        }
        queryString = queryString + paramName + "\x3d" + value
      }
    }
  }catch(e) {
  }
  return queryString
};
AdfLoopbackUtils._addQS = function(pname, pvalue) {
  if(!AdfLoopbackUtils._internalParams[pname]) {
    AdfLoopbackUtils._queryParamNames.push(pname);
    AdfLoopbackUtils._queryParamValues.push(pvalue)
  }
};
AdfLoopbackUtils._replaceCallback = function(p0, pname, p2, pvalue) {
  AdfLoopbackUtils._addQS(pname, pvalue)
};
AdfLoopbackUtils._cookiesEnabled = function() {
  return navigator && navigator.cookieEnabled
};
AdfLoopbackUtils._findWithBinarySearch = function(feature, minVal, maxVal, unit) {
  if(maxVal <= minVal) {
    return minVal
  }
  var median = Math.ceil((maxVal + minVal) / 2);
  while(true) {
    if(minVal == median || maxVal == median) {
      return minVal
    }
    if(window.matchMedia("( min-" + feature + ": " + median + unit + ")").matches) {
      minVal = median
    }else {
      maxVal = median
    }
    median = Math.ceil((maxVal + minVal) / 2)
  }
};
AdfLoopbackUtils._getTouchFeature = function() {
  var touchCapability = "none";
  if(navigator.maxTouchPoints) {
    touchCapability = navigator.maxTouchPoints > 1 ? "multiple" : "single"
  }
  return touchCapability
};
AdfLoopbackUtils._addFontSizeParam = function(query, mediaFontSizeParam, mediaFontSizeCookieParam, cookiesEnabled) {
  var fontSize = "16";
  try {
    fontSize = window.getComputedStyle(document.createElement("div")).fontSize || window.getComputedStyle(document.documentElement).fontSize;
    fontSize = fontSize.substring(0, fontSize.indexOf("px"))
  }catch(e) {
    fontsize = "16"
  }
  query = AdfLoopbackUtils._addParam(query, mediaFontSizeParam, mediaFontSizeCookieParam, fontSize, cookiesEnabled);
  return query
};
AdfLoopbackUtils._addMediaTypeParam = function(query, mediaTypeParam, mediaTypeCookieParam, cookiesEnabled) {
  var mediaTypes = ["screen", "print", "handheld", "aural", "braille", "embossed", "tv", "projection", "tty"];
  var agentMediaType = "all";
  try {
    for(var mt = 0;mt < mediaTypes.length;mt++) {
      var mediaQuery = mediaTypes[mt];
      if(window.matchMedia(mediaQuery).matches) {
        agentMediaType = mediaTypes[mt];
        break
      }
    }
  }catch(e) {
    agentMediaType = "all"
  }
  query = AdfLoopbackUtils._addParam(query, mediaTypeParam, mediaTypeCookieParam, agentMediaType, cookiesEnabled);
  return query
};
AdfLoopbackUtils._addMediaFeatures = function(query, cookiesEnabled, mediaFontSizeParam, mediaTypeParam, mediaFeatureWidthParam, mediaFeatureHeightParam, mediaFeatureDeviceWidthParam, mediaFeatureDeviceHeightParam, mediaFeatureColorParam, mediaFeatureColorIndexParam, mediaFeatureMonochromeParam, mediaFeatureResolutionParam, mediaFeatureGridParam, mediaFeatureScanParam, mediaFeatureOrientationParam, mediaFontSizeCookieParam, mediaTypeCookieParam, mediaFeatureWidthCookieParam, mediaFeatureHeightCookieParam, 
mediaFeatureDeviceWidthCookieParam, mediaFeatureDeviceHeightCookieParam, mediaFeatureColorCookieParam, mediaFeatureColorIndexCookieParam, mediaFeatureMonochromeCookieParam, mediaFeatureResolutionCookieParam, mediaFeatureGridCookieParam, mediaFeatureScanCookieParam, mediaFeatureOrientationCookieParam) {
  query = AdfLoopbackUtils._addFontSizeParam(query, mediaFontSizeParam, mediaFontSizeCookieParam, cookiesEnabled);
  query = AdfLoopbackUtils._addMediaTypeParam(query, mediaTypeParam, mediaTypeCookieParam, cookiesEnabled);
  query = AdfLoopbackUtils._addParam(query, mediaFeatureWidthParam, mediaFeatureWidthCookieParam, window.innerWidth, cookiesEnabled);
  query = AdfLoopbackUtils._addParam(query, mediaFeatureHeightParam, mediaFeatureHeightCookieParam, window.innerHeight, cookiesEnabled);
  query = AdfLoopbackUtils._addParam(query, mediaFeatureDeviceWidthParam, mediaFeatureDeviceWidthCookieParam, screen.width, cookiesEnabled);
  query = AdfLoopbackUtils._addParam(query, mediaFeatureDeviceHeightParam, mediaFeatureDeviceHeightCookieParam, screen.height, cookiesEnabled);
  var mediaFeatureColor = AdfLoopbackUtils._findWithBinarySearch("color", 0, 50, "");
  query = AdfLoopbackUtils._addParam(query, mediaFeatureColorParam, mediaFeatureColorCookieParam, mediaFeatureColor, cookiesEnabled);
  var mediaFeatureColorIndex = AdfLoopbackUtils._findWithBinarySearch("color-index", 0, 50, "");
  query = AdfLoopbackUtils._addParam(query, mediaFeatureColorIndexParam, mediaFeatureColorIndexCookieParam, mediaFeatureColorIndex, cookiesEnabled);
  var mediaFeatureMonochrome = AdfLoopbackUtils._findWithBinarySearch("monochrome", 0, 20, "");
  query = AdfLoopbackUtils._addParam(query, mediaFeatureMonochromeParam, mediaFeatureMonochromeCookieParam, mediaFeatureMonochrome, cookiesEnabled);
  var mediaFeatureResolution = AdfLoopbackUtils._findWithBinarySearch("resolution", 0, 1E3, "dpi");
  query = AdfLoopbackUtils._addParam(query, mediaFeatureResolutionParam, mediaFeatureResolutionCookieParam, mediaFeatureResolution, cookiesEnabled);
  var mediaFeatureGrid = window.matchMedia("(grid)").matches;
  query = AdfLoopbackUtils._addParam(query, mediaFeatureGridParam, mediaFeatureGridCookieParam, mediaFeatureGrid ? 1 : 0, cookiesEnabled);
  var mediaFeatureScan = window.matchMedia("(scan: progressive)").matches;
  query = AdfLoopbackUtils._addParam(query, mediaFeatureScanParam, mediaFeatureScanCookieParam, mediaFeatureScan ? 1 : 0, cookiesEnabled);
  var mediaFeatureOrientation = window.matchMedia("(orientation: portrait)").matches ? 1 : 0;
  query = AdfLoopbackUtils._addParam(query, mediaFeatureOrientationParam, mediaFeatureOrientationCookieParam, mediaFeatureOrientation, cookiesEnabled);
  return query
};
AdfLoopbackUtils.runLoopback = function(viewIdLength, loopbackIdParam, loopbackId, windowModeIdParam, clientWindowIdParam, pageIdParam, pageIdValue, windowId, jsessionId, adfHashMarker, useCookies, loopbackIdCookieParam, windowModeCookieParam, clientWindowIdCookieParam, pageIdCookieParam, redirectIdCookieParam, pprNavigationOptionSet, internalParamsObj, noLoopbackViewId, mediaFontSizeParam, mediaTypeParam, mediaFeatureWidthParam, mediaFeatureHeightParam, mediaFeatureDeviceWidthParam, mediaFeatureDeviceHeightParam, 
mediaFeatureColorParam, mediaFeatureColorIndexParam, mediaFeatureMonochromeParam, mediaFeatureResolutionParam, mediaFeatureGridParam, mediaFeatureScanParam, mediaFeatureOrientationParam, touchCapabilityParam, mediaFontSizeCookieParam, mediaTypeCookieParam, mediaFeatureWidthCookieParam, mediaFeatureHeightCookieParam, mediaFeatureDeviceWidthCookieParam, mediaFeatureDeviceHeightCookieParam, mediaFeatureColorCookieParam, mediaFeatureColorIndexCookieParam, mediaFeatureMonochromeCookieParam, mediaFeatureResolutionCookieParam, 
mediaFeatureGridCookieParam, mediaFeatureScanCookieParam, mediaFeatureOrientationCookieParam, touchCapabilityCookieParam) {
  AdfLoopbackUtils._queryParamNames = [];
  AdfLoopbackUtils._queryParamValues = [];
  AdfLoopbackUtils._internalParams = internalParamsObj;
  var page_id = pageIdValue === "" ? null : pageIdValue;
  var id = null;
  var query = null;
  var anchor = null;
  var href = document.location.href;
  var hashIndex = href.indexOf("#");
  var hash = hashIndex > 0 ? href.substring(hashIndex + 1) : null;
  href = hashIndex > 0 ? href.substring(0, hashIndex) : href;
  var oldUri = href;
  var cookiesEnabled = useCookies ? AdfLoopbackUtils._cookiesEnabled() : useCookies;
  var st = null;
  try {
    st = window.history.state
  }catch(e) {
  }
  if(page_id == null && st != null) {
    page_id = st[pageIdParam]
  }
  if(hashIndex > 0) {
    if(hash.indexOf(adfHashMarker) == 0) {
      var adfHash = decodeURIComponent(hash.substring(adfHashMarker.length));
      var state = adfHash.split("@");
      var len = state.length;
      if(len >= 1 && page_id == null) {
        page_id = state[0]
      }
      if(len >= 2) {
        id = state[1]
      }
      if(len >= 3) {
        query = state[2]
      }
      if(len >= 4) {
        anchor = state[3]
      }
    }else {
      anchor = decodeURIComponent(hash);
      if(pprNavigationOptionSet && (anchor.indexOf("/") >= 0 || anchor.indexOf("@") >= 0)) {
        var astate = anchor.split("@");
        var alen = astate.length;
        if(alen >= 1) {
          id = astate[0]
        }
        if(alen >= 2) {
          query = astate[1]
        }
        anchor = null
      }
    }
  }
  var queryIndex = href.indexOf("?");
  if(queryIndex > 0) {
    query = query || id && id.length > 0 ? query : href.substring(queryIndex);
    href = href.substring(0, queryIndex)
  }
  if(query != null && query.length > 0) {
    query.replace(/([^?=&]+)(=([^&]*))?/g, AdfLoopbackUtils._replaceCallback);
    query = null;
    var queryParamNames = AdfLoopbackUtils._queryParamNames;
    var queryParamValues = AdfLoopbackUtils._queryParamValues;
    if(queryParamNames.length > 0) {
      query = "";
      for(var i = 0;i < queryParamNames.length;i++) {
        var n = queryParamNames[i];
        var v = queryParamValues[i];
        query = query + (i == 0 ? "?" : "\x26") + n + "\x3d" + (v == null ? "" : v)
      }
    }
  }
  var windowMode = 0;
  if(query && query.indexOf("_rtrnId") >= 0) {
    windowMode = 1;
    cookiesEnabled = false;
    var parentWindowName = window.parent ? window.parent.name : null;
    if(/^ADFDialog\d+['$']/.test(parentWindowName)) {
      var parentWindowNameTokens = parentWindowName.split("$");
      window.name = parentWindowNameTokens[1]
    }
  }
  var jsessionIndex = href.indexOf(";");
  if(jsessionIndex > 0) {
    href = href.substring(0, jsessionIndex)
  }
  var sess = jsessionId;
  if(!sess && !AdfLoopbackUtils._cookiesEnabled()) {
    window.location.replace(href.substring(0, href.length - viewIdLength) + noLoopbackViewId)
  }else {
    if(id && id.length > 0) {
      href = href.substring(0, href.length - viewIdLength) + id
    }
    query = AdfLoopbackUtils._addParam(query, loopbackIdParam, loopbackIdCookieParam, loopbackId, cookiesEnabled);
    if(cookiesEnabled) {
      AdfLoopbackUtils._addCookie(redirectIdCookieParam, "")
    }
    var serverWindowId = windowId;
    var clientWindowId = window.name;
    var vwid = new RegExp("^[\\w]+$");
    if(!vwid.test(clientWindowId)) {
      clientWindowId = null
    }
    if(windowMode != 1 && !clientWindowId) {
      windowMode = 2
    }
    query = AdfLoopbackUtils._addParam(query, windowModeIdParam, windowModeCookieParam, windowMode, cookiesEnabled);
    if(!clientWindowId) {
      clientWindowId = serverWindowId;
      window.name = clientWindowId
    }
    AdfLoopbackUtils._saveWindowId(clientWindowIdParam);
    query = AdfLoopbackUtils._addParam(query, clientWindowIdParam, clientWindowIdCookieParam, clientWindowId, cookiesEnabled);
    if(sess) {
      if(sess.indexOf(";") == 0) {
        href += sess
      }else {
        if(sess.indexOf("?") == 0) {
          if(query == null || query.length == 0) {
            query = "?"
          }else {
            query += "\x26"
          }
          query += sess.substr(1)
        }
      }
    }
    query = AdfLoopbackUtils._addParam(query, pageIdParam, pageIdCookieParam, page_id, cookiesEnabled);
    query = AdfLoopbackUtils._addMediaFeatures(query, cookiesEnabled, mediaFontSizeParam, mediaTypeParam, mediaFeatureWidthParam, mediaFeatureHeightParam, mediaFeatureDeviceWidthParam, mediaFeatureDeviceHeightParam, mediaFeatureColorParam, mediaFeatureColorIndexParam, mediaFeatureMonochromeParam, mediaFeatureResolutionParam, mediaFeatureGridParam, mediaFeatureScanParam, mediaFeatureOrientationParam, mediaFontSizeCookieParam, mediaTypeCookieParam, mediaFeatureWidthCookieParam, mediaFeatureHeightCookieParam, 
    mediaFeatureDeviceWidthCookieParam, mediaFeatureDeviceHeightCookieParam, mediaFeatureColorCookieParam, mediaFeatureColorIndexCookieParam, mediaFeatureMonochromeCookieParam, mediaFeatureResolutionCookieParam, mediaFeatureGridCookieParam, mediaFeatureScanCookieParam, mediaFeatureOrientationCookieParam);
    if(touchCapabilityParam != "") {
      var touchFeature = AdfLoopbackUtils._getTouchFeature();
      query = AdfLoopbackUtils._addParam(query, touchCapabilityParam, touchCapabilityCookieParam, touchFeature, cookiesEnabled)
    }
    var newHref = href + (query == null ? "" : query);
    var newHash = anchor != null && anchor.length > 0 ? encodeURIComponent(anchor) : null;
    var loc = window.location;
    var isOldFirebug = false;
    if(window.console != null && window.console.firebug != null) {
      var ver = parseFloat(window.console.firebug);
      isOldFirebug = !isNaN(ver) && ver < 1.9
    }
    if(newHref == oldUri && (newHash != null || isOldFirebug)) {
      if(hash != newHash) {
        loc.replace(newHash == null ? "#" + adfHashMarker : "#" + newHash)
      }
      loc.reload(true)
    }else {
      loc.replace(newHash == null ? newHref : newHref + "#" + newHash)
    }
  }
};
AdfLoopbackUtils.runRedirect = function(url, cookieTemplate) {
  var c = cookieTemplate;
  var d = new Date;
  d.setTime(d.getTime() + 3E4);
  c = c.replace(/\$exp\$/g, d.toUTCString());
  var cookies = c.split("$$");
  for(i = 0;i < cookies.length;i++) {
    document.cookie = cookies[i]
  }
  var loc = document.location;
  var oldUrl = loc.href;
  var oldHash = null;
  var hashIndex = oldUrl.indexOf("#");
  if(hashIndex >= 0) {
    oldUrl = oldUrl.substring(0, hashIndex);
    oldHash = oldUrl.substring(hashIndex)
  }
  var newUrl = url;
  var newHash = null;
  hashIndex = newUrl.indexOf("#");
  if(hashIndex >= 0) {
    newUrl = newUrl.substring(0, hashIndex);
    newHash = newUrl.substring(hashIndex)
  }
  if(newUrl == oldUrl && newHash != null) {
    if(oldHash != newHash) {
      loc.replace(newHash)
    }
    loc.reload(true)
  }else {
    loc.replace(url)
  }
};
AdfLoopbackUtils._saveWindowId = function(clientWindowIdParam) {
  if(window !== parent) {
    return
  }
  try {
    var id = window.name;
    if(id && id.length > 0) {
      sessionStorage.setItem(clientWindowIdParam, id)
    }
  }catch(e) {
  }
};
AdfLoopbackUtils.appendBodyStyle = function(extraStyle) {
  if(extraStyle) {
    var body = document.body;
    var oldStyle = body.style.cssText;
    body.style.cssText = oldStyle + ";" + extraStyle
  }
};
