/*****************************************************
** File:        resize_iframe.js  version 1.6
** Author:      nat
** Modified:    02/21/06
** Copyright:   I-Next Ltd
** Description: Resizes Iframe onLoad and onClick
** Note:        The Iframe requires a NAME attribute
*****************************************************/
/* ident @(#)resize_iframe.js	1.6 */

var iFrameFixed = 0;


function checkBrowser( b ) {
  browserInfo = navigator.userAgent.toLowerCase();;
  versionLocation = browserInfo.indexOf( b ) + 1;
  theBrowser = b;
  return versionLocation;
}

function getParentScrollWidth()
{
   var w = window.pageXOffset ||
           parent.document.body.scrollLeft ||
           parent.document.documentElement.scrollLeft;

   return w ? w : 0;
}

function resizeIFrame(){
	
  if ( iFrameFixed == 0 ){
    if ( ( navigator.appVersion.match(/macintosh/i) != null ) && ( document.all ) ){ // If IE on MAC
      alert('Please use an alternative browser as Internet Explorer\non the Mac is no longer supported by Microsoft!');
      return;
    }
    // Get the parent iframes
    var iframes = parent.document.getElementsByTagName('iframe');
    // Go through them
    for ( var i = 0; i < iframes.length; i ++ ){
      // If the iframe name matches this one
      if ( iframes[i].name == self.name ){
        // Get the content width and height
        var ht1 = document.body.scrollHeight;
        var ht2 = document.body.offsetHeight;
        var wd1 = document.documentElement.scrollWidth;
        var wd2 = document.documentElement.clientWidth;
        // If the iframe is not the same as the content height
        if ( iframes[i].clientHeight != (( ht1 > ht2 )? ht1 : ht2 ) ){
          // Resize the iframe to the content size
          iframes[i].style.height = 10 + (( ht1 > ht2 )? ht1 : ht2 );
        }

        // browser sniff:
        if ( checkBrowser( "opera" ) != 0 ) { // Opera browser
          iframes[i].style.width = document.body.width;  // doesn't work
        } else if ( checkBrowser( "firefox" ) != 0 ) { // Firefox browser
          // need to behave differently for 1.0.x an 1.5.x
          var version = browserInfo.substring(versionLocation + theBrowser.length, browserInfo.length);
          
	  version = version.substring(0,3); // extract 1.0 or 1.5 etc
          if ( version >= 1.5  ) {
            iframes[i].style.width = document.body.scrollWidth;
          }
          else {
            // pre-version 1.5
            iframes[i].style.width = ( wd1 > wd2 )? wd1 : wd2;
          }
        } else if ( checkBrowser( "msie") != 0) { // IE
          iframes[i].style.width = document.body.scrollWidth;
	  //iframes[i].style.width = document.body.clientWidth;
        } else if ( checkBrowser( "safari") != 0) { // safari
          iframes[i].style.width = document.body.scrollWidth;
        } else {
          iframes[i].style.width = document.body.scrollWidth;
        }
      }
    }
  }
}

function setIFrame( w, h ){
  // Get the parent iframes
  var iframes = parent.document.getElementsByTagName('iframe');
  // Go through them
  for ( var i = 0; i < iframes.length; i ++ ){
    // If the iframe name matches this one
    if ( iframes[i].name == self.name ){
      // If it's not an empty string then set the width
      if ( w != '' ){ iframes[i].style.width = w; }
      // If it's not an empty string then set the height
      if ( h != '' ){ iframes[i].style.height = h; }
    }
  }
  // Flag the iframe as fixed size
  iFrameFixed = 1;
}

window.onload = function (){
  document.onmouseup = function(){ setTimeout( 'resizeIFrame();', 10 ); }
  resizeIFrame();
  setTimeout( 'resizeIFrame();', 50 );
  // Scroll to the top of the parent page
  top.document.body.scrollTop = 0;
}

