
/* ============================================================================== */

function resizeIframe (id) {

  /* Code inspired from :
     http://community.postnuke.com/module-Forum-viewtopic-topic-34010-start-15.htm
  */

  // Save scrollY, if content is playing with scrollTo
  var scrollY = getWindowScroll() ['scrollY'];

  // Safari test
  var userAgent_safari = 0;
  var regexp_safari    = new RegExp("Safari","g");
  if (navigator.userAgent.match(regexp_safari)) {
      userAgent_safari = 1;
  }

  // Go for resize
  if(document.getElementById && (navigator.userAgent.toLowerCase().indexOf('msie')==-1)) { // Mozilla, Opera & DOM
    var objFrame = document.getElementById(id);
    var objDoc = (window.frames && window.frames[id]) ? window.frames[id].document //IE5, Konqueror, Safari
      : (objFrame.contentWindow) ? objFrame.contentWindow.document                 //IE5.5+, Moz 1.0+, Opera
      : (objFrame.contentDocument) ? objFrame.contentDocument
      : (objFrame.document) ? objFrame.document 
      : null;
    var ComputedHeight = document.defaultView ? document.defaultView.getComputedStyle(objDoc.documentElement, '').getPropertyValue('height') : 0;
    var foo = objDoc.body.scrollHeight;
    objFrame.style.height = '100px';  // Mozilla+Safari Fix
    var h = objDoc.body.scrollHeight; // find height of internal page

    // as ->
    for(i=0 ; i<objDoc.body.getElementsByTagName('frame').length ; i++ ) { // Compute frames in iframe
	var max = objDoc.body.getElementsByTagName('frame')[i].contentDocument.body.scrollHeight;
	if(max > h) { h = max }
    }
    // -> as

    if (h==0) return; // Opera fix
    if( ! userAgent_safari ) { // Safari fix
	if (parseInt(ComputedHeight) > h) { h = parseInt(ComputedHeight); }
    }

    objFrame.style.height = h + 18 + 'px'; // +18 = +16 to compensate for scrollbars, plus 2px extra

  }
  else if(document.all) { 
    var objFrame = document.getElementById(id);
    var h = document.frames(id).document.body.scrollHeight;

    // as ->
    for(i=0 ; i<document.frames(id).document.body.getElementsByTagName('frame').length ; i++ ) { // Compute frames in iframe
      var max = document.frames(id).document.body.getElementsByTagName('frame')[i].contentWindow.document.body.scrollHeight;
      if(max > h ) { h = max }
    }
    // -> as

    objFrame.style.height = h + 18 + 'px'; // +18 = +16 to compensate for scrollbars, plus 2px extra
  }

  // Scroll where content wants
  window.scrollTo(0,scrollY);

} // function resizeIframe (id)
