var ResizeIframe = {    
  wrapperId : "tinc_content",
                
  resize : function ( oDoc, sId ) 
  {
    // retrieve iframe's content size and resize vertically
    var iframeDoc = oDoc.getElementById( sId ).contentWindow.document;
    if ( iframeDoc == null ) return;
    if ( window.addEventListener )
    {
      var pv = iframeDoc.defaultView.getComputedStyle( iframeDoc.body, "" ).getPropertyValue;
      var height = iframeDoc.body.clientHeight
                    + parseInt( iframeDoc.defaultView.getComputedStyle( iframeDoc.body, "" ).getPropertyValue( "margin-top" ) )
                    + parseInt( iframeDoc.defaultView.getComputedStyle( iframeDoc.body, "" ).getPropertyValue( "margin-bottom" ) )
                    + parseInt( iframeDoc.defaultView.getComputedStyle( iframeDoc.body, "" ).getPropertyValue( "padding-top" ) )
                    + parseInt( iframeDoc.defaultView.getComputedStyle( iframeDoc.body, "" ).getPropertyValue( "padding-bottom" ) );
    } else if ( window.attachEvent ) {
      var wrapper = iframeDoc.getElementById( this.wrapperId );
      if ( wrapper == null ) return;
      wrapper.style.height = "0px"; 
      var height = wrapper.offsetHeight 
                  + wrapper.offsetTop 
                  + parseInt( iframeDoc.body.currentStyle.marginTop ) 
                  + parseInt( iframeDoc.body.currentStyle.marginBottom )
                  + parseInt( iframeDoc.body.currentStyle.paddingTop ) 
                  + parseInt( iframeDoc.body.currentStyle.paddingBottom );
    }
    oDoc.getElementById( sId ).setAttribute("height", height);    
    // in case the height is also set as a style property
    oDoc.getElementById( sId ).style.height = height + "px";   
    // seems to fix a Gecko bug, sometimes the iframe was cut at the bottom when resizing smaller
    oDoc.getElementById( sId ).style.display = "block";
    
    // let non-tinc links load in the parent document. this might need some adjustment
    var links = iframeDoc.getElementsByTagName( "a" );
    for ( var i = 0; i < links.length; i++ )
    {
      if ( links[i].href.indexOf( "/tinc" ) == -1 ) links[i].target = "_parent";
    }
    
    // Special case: WebElements forms might do redirection to another page after submission. That's indicated by a non-empty
    // 'redirectionEnabled' attribute of a submit button. 
    var inputs = iframeDoc.getElementsByTagName( "input" );
    for ( var i = 0; i < inputs.length; i++ )
    {
      var input = inputs[i];
      if ( input.getAttribute("redirection") != null && input.getAttribute("redirection") != '' ) 
        input.form.target = "_parent";
    }
  }
};

