﻿        
        var iframeID = document.getElementById("iframe");   // Iframe name
        var windowWidth = 0;
        var windowHeight = 0;                
        var previousIframeWidth = 0;
        var previousIframeHeight = 0;                
        var iframeWidth = 0;
        var iframeHeight = 0;
        
        var postbackTimer;
        var postbackCounter;
        var postbackTimeOut;
        var postbackWaitTime = 1.5; // Set the time before postback here
        var doingPostback;
        
        var isPostback = document.getElementById("HiddenFieldIsPostBack").value;
        
        var stopCounterLoop = false;
        var HfFrameDimensions = document.getElementById("HFFrameDimensions").value;

       
        var isPageLoaded = false;
        
        
        
        function PageLoaded()
        {            
            isPageLoaded = true;  
            windowWidth = GetWidth();     
            windowHeight = GetHeight();
            
            PostbackStatus();           
        }        
              
     
        function GetWindowDimensions()
        {        
            if(isPageLoaded == true && isPostback == "Yes")
            {    
                 windowWidth = GetWidth();     
                 windowHeight = GetHeight(); 
            }
        }        

        
        
        function SetIframeSize()
        {
            if(iframeID && isPageLoaded == true)
            {               
            
                iframeWidth = (windowWidth - 40);                
                iframeHeight = (windowHeight - 175);                                        
                                                              
          
                iframeID.width = iframeWidth;
                iframeID.height = iframeHeight; 
      
                
                postbackCounter = 0.0;
      
            }
        }
        
        function TimedCount()
        {
        if(stopCounterLoop == false)
        {
        
            postbackCounter = postbackCounter +0.100;
            postbackTimeOut = setTimeout("TimedCount()",100);       
            doingPostback = true;
         
         
            if(postbackCounter > postbackWaitTime)
            {             
                                 
                StopCount();
                postbackCounter = 0.0;
                
                
                windowWidth = GetWidth();     
                windowHeight = GetHeight();
 
                
                                          
                // Find out if the new frame dimensions are already what the Iframe is. 
                var frameDimensions = (windowWidth - 40) + '-' + (windowHeight - 175);
                
                
               // Checks if the previous framedimensions were the same, if not then don't post back 
               if(HfFrameDimensions != frameDimensions)
               { 
                    // reset Iframeheight to be able to calculate new window dimensions
                    iframeID.width = 0;
                    iframeID.height = 0;
                    
                    // Calculate and set new Iframeheight
                    SetIframeSize();
                    
                    // Save the new dimensions into hidden field           
                    HfFrameDimensions = iframeID.width + '-' + iframeID.height;  
                    
                    alert("The size of your browser window has changed. \nThe map will now be adapted according to the new size of your browser window and return to the start position.");  
                    //alert("Størrelsen på dit browservindue har ændret sig. Kortet vil nu blive tilpasset efter den nye størrelse og sat tilbage til startpositionen.");  
                    
                    __doPostBack('callPostBackIframeSize',iframeID.width  + "," + iframeID.height + "," + HfFrameDimensions);
                }
                else{
                stopCounterLoop = true;
                }        
                
            }  
          }      
        }
        
        function StartTimer()
        {
            postbackCounter = 0.0;
            
            if(postbackTimeOut)
            {
                StopCount();
            }

            // If stopCounterLoop is true then dont start the timer
            if(stopCounterLoop == false)
            {
                    TimedCount();
            }
            else{
             stopCounterLoop = false;
            }
                    
        }
    

      function GetWidth()  
      {  
              var width = 0;
              width = document.body.clientWidth;   
              return width;                          
      }       

      function GetHeight()
      {
              var height = 0;          
              height = document.documentElement.clientHeight;
              return height;
      }
      
      
//      function GetDimensions()
//      {
//      
//        if (window.innerWidth)
//        {    //if browser supports window.innerWidth
//             windowWidth = window.innerWidth; 
//             windowHeight = window.innerHeight;
//             
//             pageXOffset = window.pageXOffset;  //	Returns the x coordinate of the DSOC
//             pageYOffset = window.pageYOffset; //	Returns the y coordinate of the DSOC
//             
//         }
//        else if (document.all) //else if browser supports document.all (IE 4+)
//        {        
//            windowWidth = 0;
//            windowHeight = 0;
//            
//        
//            windowWidth = document.body.clientWidth;
//            windowHeight = document.body.clientHeight;
//            
//            var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body

//            var dsocleft=document.all? iebody.scrollWidth : pageXOffset
//            
//            if(dsocleft > windowWidth)
//                windowWidth = dsocleft - windowWidth;
//            
//            
//            var dsoctop=document.all? iebody.scrollHeight : pageYOffset        
//            
//            if(dsoctop > windowHeight)
//                windowHeight = dsoctop - windowHeight;   
//            
//        }    

//      }
        
            
        function PostbackIframe()
        {
            alert("localpage");
            __doPostBack("callPostBackIframeSize", "" + iframeID.width + "," + iframeID.height);
        }    
            
            
 
      
        function PostbackStatus()
        {
            doingPostback = false;              
            if(isPostback == "No")
            {                   
                SetIframeSize();                
   
               __doPostBack('callPostBackIframeSize',iframeID.width + "," + iframeID.height + "," + HfFrameDimensions);
            }         
        }
        
        function StopCount()
        {
            clearTimeout(postbackTimeOut);
        }




