﻿  var DomainNames = new Array()
  
  function GetIFrame(name)
         {
             //var rfmNameASPX = "<%=htmIFrame.UniqueId%>";
             if (name) {
                 var rfmNameASPX = name;
                 var rfmNameHTML = rfmNameASPX
                 var intIndexOfMatch;
                 while (intIndexOfMatch != -1) {
                     rfmNameHTML = rfmNameHTML.replace("$", "_");
                     intIndexOfMatch = rfmNameHTML.indexOf("$");
                 }
                 var frmObject = document.getElementById(rfmNameHTML);

                 return frmObject;
             }
             else
                 return null;
         }  
         
         
         function getIframeDocument(iframeNode) {
         if(iframeNode)
         {
              if (iframeNode.contentDocument) 
              {
                return iframeNode.contentDocument
              }
              if (iframeNode.contentWindow) 
              {
                return iframeNode.contentWindow.document
              }
              return iframeNode.document
          }
          else 
          {
            return null;
          }
        }
        
         
         
        function SetDomain(DomainName)
        {
            try
            {
               document.domain  = DomainName;
               return true;
            } 
            catch(E)
            {
                return false;
            }
        }
        
         
    
function changeHeight(name, tableName)
{
    var lName = name;
    var DocDomainName = GetDocumentDomainName(name);
    if (SetDomain(DocDomainName)) 
      {     
          scroll(0,0);
          changeHeightReq(lName);
          changeWidth(lName, tableName);
      }
      
}

function changeWidth(name, tableName)
{
      var lName = name;
      var iframe = GetIFrame(name);
      if (iframe) {
          var iDocument = getIframeDocument(iframe);
          var src_width = GetIFrameContentWidth(iframe, tableName);
          var iframe_width = iframe.clientWidth;

          if (iframe_width != src_width) {

              iframe.width = src_width;
              window.setTimeout("changeHeightReq()", 10);
              //var hide =  (iframe.height < document.body.clientHeight);
              //HideNonIFrameObjects(hide);
          }
      }
}

function changeHeightReq(name)
{
      
      var lName = name;
      var iframe = GetIFrame(lName);
      if (iframe) {
          var iDocument = getIframeDocument(iframe);

          var src_height = GetIFrameContentHeight(iDocument);
          //var src_width = GetIFrameContentWidth(iframe);

          var iframe_height = iframe.clientHeight;
          //var iframe_width = iframe.clientWidth;


          if (iframe_height != src_height) {
              iframe.height = src_height;
              //iframe.width = src_width ;

              //////window.setTimeout("changeHeightReq('"+lName+"')", 10);
              //var hide =  (iframe.height < document.body.clientHeight - 300);
              //HideNonIFrameObjects(hide);
          } 
      }
}



function GetIFrameContentHeight(iDocument)
{
    var height;
    if(iDocument)
    {
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
        {
            height = iDocument.body.scrollHeight; //IE
        } else if(/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent))
        {        
            height = iDocument.documentElement.scrollHeight; //Opera
        }
            else
        {
            height = iDocument.getElementsByTagName("TABLE")[0].clientHeight; //FF
        }
       
        
    }
    
    return height;
}


function GetIFrameContentWidth(iDocument, tableName)
{
    var width;
    if(iDocument)
    {
        
        //width = document.getElementById('<% = iFrameTable.UniqueID.Replace("$","_") %>').clientWidth;
        width = document.getElementById(tableName).clientWidth;
        
    }
    
    return width - 5 ;
}

function SetDocumentDomainName(name, value) {
    DomainNames[name] = value;
    
}

function GetDocumentDomainName(name) {
    return DomainNames[name];
}
