var ResizeIframe = {   
  wrapperId : &quot;tinc_content&quot;,
                
  /**
   * Resizes an iframe sId including oDoc to oDoc's content size.
   * Can be called top-down, i.e. from the including iframe (or it's parents) or bottom-up, i.e. from the included document.
   * In the latter case the iframe element is retrieved programmatically.
   * 
   * @param oDoc  Included page's document object
   * @param sId   ID of including iframe
   */               
  resize : function ( oDoc, sId ) 
  {
    try
    {
      if ( typeof oDoc == &quot;undefined&quot; ) return;
  
      if ( typeof sId != &quot;undefined&quot; ) 
      {
        var iframe = oDoc.getElementById( sId );
        var iframeDoc = iframe.contentWindow.document;
      } else {
        var iframeDoc = oDoc;
        var iframeWindow = iframeDoc.parentWindow || iframeDoc.defaultView;
        var iframe = iframeWindow.frameElement;
      }
      var wrapper = iframeDoc.getElementById( this.wrapperId );

      // make sure we only resize once
      if ( iframeDoc.isIntegrated == true ) { return; }
      
      // switch on transparency for iframe
      iframeDoc.body.style.backgroundColor = &quot;transparent&quot;;
      iframe.allowTransparency = &quot;true&quot;;
            
      iframeDoc.body.style.padding = &quot;0px&quot;;
      iframeDoc.body.style.border = &quot;none&quot;;
      
      var tabs = iframeDoc.getElementsByTagName( &quot;table&quot; )
      if ( tabs[0] &amp;&amp; tabs[0].className == &quot;dborder&quot; )
     	{		
      	wrapper.setAttribute( &quot;wfx:overridewidth&quot;, &quot;true&quot; );
      } else if ( iframeDoc.forms[0] &amp;&amp; iframeDoc.forms[0].elements[&quot;formname&quot;] ) 
      {
      	wrapper.setAttribute( &quot;wfx:overridewidth&quot;, &quot;true&quot; );
      } 
      
      if ( window.addEventListener )
      {   
      	var gcs = iframeDoc.defaultView.getComputedStyle( iframeDoc.body, null);
        var v_margin = parseInt( gcs.getPropertyValue( &quot;margin-top&quot; ) ) + parseInt( gcs.getPropertyValue( &quot;margin-bottom&quot; ) );
        var h_margin = parseInt( gcs.getPropertyValue( &quot;margin-left&quot; ) ) + parseInt( gcs.getPropertyValue( &quot;margin-right&quot; ) );
        var wrapper_width = wrapper.offsetWidth;
        
        var flex = wrapper.getAttribute( &quot;wfx:overridewidth&quot; );
        if ( flex == &quot;true&quot; )
        {
        	wrapper.style.width = &quot;100%&quot;;
        } else {
        	iframe.style.width = wrapper_width + h_margin + &quot;px&quot;;
        }
        
        // Setting the top padding of the wrapper avoids wrong calculation of the height due to collapsing margins behavior
        wrapper.style.paddingTop = &quot;1px&quot;;
        
        height = wrapper.offsetHeight + v_margin ;
      } 
      else if ( window.attachEvent ) 
      {        
        iframeDoc.body.style.margin = &quot;0px&quot;;
        var wrapper_width = wrapper.offsetWidth;
        
        var flex = wrapper.getAttribute( &quot;wfx:overridewidth&quot; );
        if ( flex == &quot;true&quot; )
        {
        	wrapper.style.width = &quot;100%&quot;;
        } else {
        	iframe.style.width = wrapper_width + &quot;px&quot;;
        }
        
        height = wrapper.offsetHeight;
      }

      if ( iframe.scrolling != &quot;yes&quot; ) { height += 20; }
      
      iframe.style.height = height + &quot;px&quot;;
      iframeDoc.isIntegrated = true; 
    } catch ( ex )
    {
      return; 
    }
    
    WfxExtrasProcessor.process( oDoc, sId );
  }
}

var WfxExtrasProcessor = {
  process : function ( oDoc, sId)
  {    
    if ( typeof oDoc == &quot;undefined&quot; ) return;
  
    if ( typeof sId != &quot;undefined&quot; ) 
    {
      var iframe = oDoc.getElementById( sId );
      var iframeDoc = iframe.contentWindow.document;
    } else {
      var iframeDoc = oDoc;
      var iframeWindow = iframeDoc.parentWindow || iframeDoc.defaultView;
      var iframe = iframeWindow.frameElement;
    }
    
    // let non-tinc links load in the parent document. this might need some adjustment
    var links = iframeDoc.getElementsByTagName( &quot;a&quot; );
    for ( var i = 0; i &lt; links.length; i++ )
    {
      if ( links[i].href.indexOf( &quot;/tinc&quot; ) == -1 ) links[i].target = &quot;_parent&quot;;
    }
    
    // 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( &quot;input&quot; );
    for ( var i = 0; i &lt; inputs.length; i++ )
    {
      var input = inputs[i];
      if ( input.getAttribute(&quot;redirection&quot;) != null &amp;&amp; input.getAttribute(&quot;redirection&quot;) != '' ) 
        input.form.target = &quot;_parent&quot;;
    }
  }
}
    
    
