
function resizeFrames(){
  try{
    // Resizing Left Frame
    var frame = document.getElementById( 'bm_left_frame');
    var frameHeight;

    // calculating frame's height
    if(frame.contentDocument!=null){
      frameHeight = parseInt(frame.contentDocument.body.scrollHeight);
    } else if(frame.contentWindow!=null){
      frameHeight = parseInt(frame.contentWindow.document.body.scrollHeight);
    } else if(frame.document!=null){
      frameHeight = parseInt(frame.document.body.offsetHeight);
    } else {
      return true;
    }
    // stablishing height
    if(parseInt(document.body.scrollHeight)-125<frameHeight){
      frame.style.height = frameHeight+"px";
    } else {
      frame.style.height = (parseInt(document.body.scrollHeight)-125)+"px";
    }

    // Resizing Top Frame
    frame = document.getElementById( 'bm_top_frame');
    var body = document.getElementById( 'bm_body');
    var frameWidth;
    var clientWidth;

    // calculating frame's width
    if(frame.contentDocument!=null){
      frameWidth = parseInt(frame.contentDocument.body.scrollWidth);
    } else if(frame.contentWindow!=null){
      frameWidth = parseInt(frame.contentWindow.document.body.scrollWidth);
    } else if(frame.document!=null){
      frameWidth = parseInt(frame.document.body.offsetWidth);
    } else {
      return true;
    }
    // stablishing width
    clientWidth = parseInt(document.body.scrollWidth);
    if(clientWidth<frameWidth){
      frame.style.width = frameWidth+"px";
      body.style.width = (frameWidth-161)+"px";
    } else {
      frame.style.width = "100%";
      body.style.width = "100%";
    }
  }catch( err){}
}

// Resize an Iframe to fit the COMPLETE content area.
function resizeIFrame(frameName){
  try{
    var ifrm = document.getElementById(frameName);
    var leftIfrm = document.getElementById('bm_left_frame');
    var height;

    if(ifrm == null || leftIfrm == null){
      return;
    }

    if(ifrm.contentDocument!=null){
      try{
        ifrm.contentDocument.attachEvent('onunload', function () {top.document.getElementById(frameName).style.height='100%';});
      }catch(ex){
        try{ifrm.contentDocument.addEventListener('unload', function () {top.document.getElementById(frameName).style.height='100%';}, false);}catch(ex1){}
      }
      height = parseInt(ifrm.contentDocument.body.scrollHeight);
    } else if(ifrm.contentWindow!=null){
      try{
        ifrm.contentWindow.attachEvent('onunload', function () {top.document.getElementById(frameName).style.height='100%';});
      }catch(ex){
        try{ifrm.contentWindow.addEventListener('unload', function () {top.document.getElementById(frameName).style.height='100%';}, false);}catch(ex1){}
      }
      height = parseInt(ifrm.contentWindow.document.body.scrollHeight);
    } else if(ifrm.document!=null){
      try{
        ifrm.document.attachEvent('onunload', function () {top.document.getElementById(frameName).style.height='100%';});
      }catch(ex){
        try{ifrm.document.addEventListener('unload', function () {top.document.getElementById(frameName).style.height='100%';}, false);}catch(ex1){}
      }
      height = parseInt(ifrm.document.body.offsetHeight);
    } else {
      return true;
    }
    var IfrmHeight;
    // calculating left frame's height
    if(leftIfrm.contentDocument!=null){
      leftIfrmHeight = parseInt(leftIfrm.contentDocument.body.scrollHeight);
    } else if(leftIfrm.contentWindow!=null){
      leftIfrmHeight = parseInt(leftIfrm.contentWindow.document.body.scrollHeight);
    } else if(leftIfrm.document!=null){
      leftIfrmHeight = parseInt(leftIfrm.document.body.offsetHeight);
    } else {
      return true;
    }
    // stablishing height
    if(parseInt(document.body.scrollHeight)-125>leftIfrmHeight){
      leftIfrmHeight = (parseInt(document.body.scrollHeight)-125);
    }

    if( parseInt(leftIfrmHeight)>height){
      ifrm.style.height = leftIfrmHeight-16+"px";
    }  else {
      leftIfrm.style.height = (height+16)+"px";
    }

  }catch(err){ }
}

function resizePortlet(frameName){
  try{
    var ifrm = document.getElementById(frameName);
    var height;

    if(ifrm == null){
      return;
    }

    if(ifrm.contentDocument!=null){
      try{
        ifrm.contentDocument.attachEvent('onunload', function () {top.document.getElementById(frameName).style.height='100%';});
      }catch(ex){
        try{ifrm.contentDocument.addEventListener('unload', function () {top.document.getElementById(frameName).style.height='100%';}, false);}catch(ex1){}
      }
      height = parseInt(ifrm.contentDocument.body.scrollHeight);
    } else if(ifrm.contentWindow!=null){
      try{
        ifrm.contentWindow.attachEvent('onunload', function () {top.document.getElementById(frameName).style.height='100%';});
      }catch(ex){
        try{ifrm.contentWindow.addEventListener('unload', function () {top.document.getElementById(frameName).style.height='100%';}, false);}catch(ex1){}
      }
      height = parseInt(ifrm.contentWindow.document.body.scrollHeight);
    } else if(ifrm.document!=null){
      try{
        ifrm.document.attachEvent('onunload', function () {top.document.getElementById(frameName).style.height='100%';});
      }catch(ex){
        try{ifrm.document.addEventListener('unload', function () {top.document.getElementById(frameName).style.height='100%';}, false);}catch(ex1){}
      }
      height = parseInt(ifrm.document.body.offsetHeight);
    } else {
      return true;
    }
    ifrm.style.height = height+"px";
    resizeFrames();

  }catch(err){ }
}


function loadExternal(url) {
  try{
    var bufferFrame = document.getElementById('bm_container');
    var bufferDocument;

    // Obtain Document object
    // for IE, NN, Moz
    if( bufferFrame.contentDocument!=null){
      bufferDocument = bufferFrame.contentDocument;
    } else if( bufferFrame.contentWindow!=null){
      bufferDocument = bufferFrame.contentWindow.document;
    } else if( bufferFrame.document!=null){
      bufferDocument = bufferFrame.document;
    }

    bufferDocument.location = url;
    alert('listo');
    var body = document.getElementById('bm_body');
    body.innerHTML = '<img src="/images/loading.gif" alt="">';
    return false;
  } catch( error){
    alert(error.message);
    return true; // other browsers follow link
  }
}

// called when documents loaded into iframe (from their body's onload attribute)
function displayExternal() {
  try{
    var bufferFrame = document.getElementById('bm_container');
    var bufferDocument;

    // Obtain Document object
    // for IE, NN, Moz
    if( bufferFrame.contentDocument!=null){
      bufferDocument = bufferFrame.contentDocument;
    } else if( bufferFrame.contentWindow!=null){
      bufferDocument = bufferFrame.contentWindow.document;
    } else if( bufferFrame.document!=null){
      bufferDocument = bufferFrame.document;
    }

    var body = document.getElementById('bm_body');
    body.innerHTML = bufferDocument.body.innerHTML;
  } catch( error){
    alert(error.message);
  }
}

function getStyle(oElm, strCssRule){
    var strValue = "";
    if(document.defaultView && document.defaultView.getComputedStyle){
        strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
    }
    else if(oElm.currentStyle){
        strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
            return p1.toUpperCase();
        });
        strValue = oElm.currentStyle[strCssRule];
    }
    return strValue;
}

function resizePIFrame( frameName){
  var ifrm = document.getElementById( frameName);
  var height;
  if(ifrm.contentDocument!=null){
    height = parseInt(ifrm.contentDocument.body.scrollHeight);
  } else if(ifrm.contentWindow!=null){
    height = parseInt(ifrm.contentWindow.document.body.scrollHeight);
  } else if(ifrm.document!=null){
    height = parseInt(ifrm.document.body.offsetHeight);
  } else {
    return true;
  }
  ifrm.height = height;
  ifrm.width = "100%";
}