﻿
///Returns the kind of Browser the user is currently using.
function getBrowserType()
{
  var browserName = navigator.appName;
  return browserName;
}

/// <summary>
///   Used to create a fixed GridView header and allow scrolling of the contents.
///   The code checks the client browser. 
///   If it is MSIE, then the div tag above the gridview is assigned the scrollblock class to provide scrolling.
///   For Firefox, the body will automatically inherit the class from the DataTable body CSS tag.
/// </summary>
/// <param name="gridID" type="String">
///   The Client-side ID of the GridView control
/// </param>
function FreezeGridViewHeader(gridID)
{
   var grid = document.getElementById(gridID);
   if (grid != null && grid != 'undefined')
   {
         if (grid.parentNode != null)
         {
            var div = null;
            //Find wrapper div output by GridView
            div = grid.parentNode;
            if (div.tagName == "DIV")
            {
               if (getBrowserType() == 'Microsoft Internet Explorer')
                   div.className = 'scrollblock';
               else
                   div.className = 'scrollblockForFireFox';
            }
         }

      //Find DOM TBODY element and remove first TR tag from 
      //it and add to a THEAD element instead so CSS styles
      //can be applied properly in FireFox
      
      if (getBrowserType() == 'Netscape')
      {
         var tags = grid.getElementsByTagName('TBODY');
         if (tags != null)
         {
            var tbody = tags[0];
            var trs = tbody.getElementsByTagName('TR');
            if (trs != null)
            {
              var headTR = tbody.removeChild(trs[0]);
              var head = document.createElement('THEAD');
              head.appendChild(headTR);
              grid.insertBefore(head, grid.firstChild);
            }
            if (grid.clientHeight > 400)
               tbody.style.height = '400px';
         }
      }
   }
}

/// <summary>
///   Used to create a fixed Table header and allow scrolling of the contents.
///   The code checks the client browser. 
///   If it is MSIE, then the div tag above the Table is assigned the scrollblock class to provide scrolling.
///   For Firefox, the body will automatically inherit the class from the DataTable body CSS tag.
/// </summary>
/// <param name="tableID" type="String">
///   The Client-side ID of the Table
/// </param>
function FreezeDataTableHeader(tableID)
{
   var grid = document.getElementById(tableID);
   if (grid != null && grid != 'undefined')
   {
      if (grid.parentNode != null)
      {
         var div = null;
         //Find wrapper div output by GridView
         div = grid.parentNode;
         if (div.tagName == "DIV")
         {
             if (getBrowserType() == 'Microsoft Internet Explorer')
                 div.className = 'scrollblock';
             else
                 div.className = 'scrollblockForFireFox';
         }
      }
      
      //Find DOM TBODY element and remove first TR tag from 
      //it and add to a THEAD element instead so CSS styles
      //can be applied properly in FireFox
      if (getBrowserType() == 'Netscape')
      {
         var tags = grid.getElementsByTagName('TBODY');
         if (tags != null)
         {
            var tbody = tags[0];
            if (grid.clientHeight > 400)
               tbody.style.height = '400px';
         }
      }
   }
}