﻿//_ItemToBeDisabled is the ID of the top HTML element whose items inside needs to be disabled
function DisableThis(_ItemToBeDisabled, _WaitDivTag) {
  //debugger;
  // Detect modern browsers
  //if (document.getElementById)

  document.getElementById(_ItemToBeDisabled).bgColor = "#cccccc";

  var i, a, b;
  b = document.getElementById(_ItemToBeDisabled);
  for (i = 0; (a = b.getElementsByTagName("OPTION")[i]); i++) {
    a.disabled = true;
  };
  for (i = 0; (a = b.getElementsByTagName("SELECT")[i]); i++) {
    a.disabled = true;
  };

  div = document.createElement("div");
  img = document.createElement("img");

  _Height = document.getElementById(_ItemToBeDisabled).offsetHeight;
  _Width = document.getElementById(_ItemToBeDisabled).offsetWidth;

  //div.style.border = "solid 1px #000000";
  div.style.position = "absolute";
  div.style.width = String(_Width) + 'px';
  div.style.top = String(_Height + (_Height / 2)) + 'px';
  div.style.textAlign = "center";
  img.src = "Pics/ajax-loader.gif";

  div.appendChild(img);
  document.getElementById(_WaitDivTag).appendChild(div);

};

//--------------------------------
// Get browser's client area width
//--------------------------------
function GetWidth()
{
  // from http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
  var returnValue;

  // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
  if (typeof window.innerWidth != 'undefined')
  {
    returnValue = window.innerWidth
  }
  // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
  else if (typeof document.documentElement != 'undefined' && 
           typeof document.documentElement.clientWidth != 'undefined' && 
           document.documentElement.clientWidth != 0)
  {
    returnValue = document.documentElement.clientWidth
  }
  // older versions of IE
  else
  {
    returnValue = document.getElementsByTagName('body')[0].clientWidth
  }
  return returnValue;
};

//---------------------------------
// Get browser's client area height
//---------------------------------
function GetHeight() {
  // from http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
  var returnValue;

  // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
  if (typeof window.innerHeight != 'undefined') {
    returnValue = window.innerHeight
  }
  // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
  else if (typeof document.documentElement != 'undefined' &&
           typeof document.documentElement.clientHeight != 'undefined' &&
           document.documentElement.clientHeight != 0) {
    returnValue = document.documentElement.clientHeight
  }
  // older versions of IE
  else
  {
    returnValue = document.getElementsByTagName('body')[0].clientHeight
  }
  return returnValue;
};

//---------------------------------------------------------
// Toggle visibility of a given tag whose ID is p_ElementID
//---------------------------------------------------------
function ToggleElement(p_ElementID)
{
  if (document.getElementById(p_ElementID).style.display == 'block')
  {
    document.getElementById(p_ElementID).style.display = 'none';
  }
  else
  {
    document.getElementById(p_ElementID).style.display = 'block';
    document.getElementById(p_ElementID).style.zIndex = 1
  };
};

//---------------------------------------
// Detect which browser the user is using
//---------------------------------------
function sniffBrowsers()
{
  if (document.layers != undefined)
  {
    return 'ns4';  
  }
  else if (navigator.appName.indexOf('Microsoft') != -1)
  {
    // Internet Explorer
    return 'ie';
  }
  else if (navigator.appName.indexOf('Netscape') != -1)
  {
    // Netscape, Safari, Chrome
    return 'ns'
  }
  else if (navigator.appName.indexOf('Opera') != -1)
  {
    // Opera (you can use also navigator.userAgent.indexOf("Opera 5"))
    return 'op'
  }
}

//--------------------------
// Get element actual Height
//--------------------------
function getElementHeight(Elem)
{
  var thisBrowser = sniffBrowsers();
  if (document.getElementById)
  {
    var elem = document.getElementById(Elem);
  }
  else if (document.all)
  {
    var elem = document.all[Elem];
  }
  if (thisBrowser == 'op')
  {
    xPos = elem.style.pixelHeight;
  }
  else
  {
    xPos = elem.offsetHeight;
  }
  return xPos;
}

//-------------------------
// Get element actual Width
//-------------------------
function getElementWidth(Elem)
{
  var thisBrowser = sniffBrowsers();
  if (document.getElementById)
  {
    var elem = document.getElementById(Elem);
  }
  else if (document.all)
  {
    var elem = document.all[Elem];
  }
  if (thisBrowser == 'op')
  {
    xPos = elem.style.pixelWidth;
  }
  else
  {
    xPos = elem.offsetWidth;
  }
  return xPos;
}

