// Default minimum height for account iframe and div
// The same value should be in styles for div and iframe
var MIN_HEIGHT = 415;

// This function is called when account iframe is reload.
// It get height of iframe content and set iframe and div to this value.
function setHeightForAccountIframe() {

  var iframe = document.getElementById("display-frame");
  var iframeDiv = document.getElementById("accountIframe");

  if (iframe == null || iframeDiv == null) {
    return;
  }

  var test1 = displayIframe.document.body.scrollHeight;
  var test2 = displayIframe.document.body.offsetHeight
  // use bigger one
  height = test1 > test2 ? test1 : test2;

  // add something at the end of iframe
  // Firefox shows scrollbars sometimes, so we need higher iframe than content.
  height *= 1.05;

  // check if iframe has minimum size.
  if (height < MIN_HEIGHT) {
    height = MIN_HEIGHT;
  }

  // set height of iframe and div
  iframeDiv.style.height = height + "px";
  iframe.style.height = height + "px";
}


// Add an eventListener to browsers that can do it somehow.
// Originally by the amazing Scott Andrew.
function addEventLstnr(obj, evType, fn){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
  } else if (obj.attachEvent){
  var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
  return false;
  }
}

