// W3 Teck Window Disabler Class

// this class will allow the disabling of most of a browser window
// what it does is place a div over the entire browser window setting an
// opaque background. This div is absolutely positioned with a z-index of 1000 (default)
// this effectively disables most controls and actions on an HTML page

// note that this disabling effect may not be perfect. Some browsers render some elements
// in a way that makes them imposible to cover in this manner
// flash and select fields are two of these types of elements
// if the page contains these types of elements then it is necessary to disable them
// in another way - for instance select fields can be disabled using its disabled property

// initialize (instantiate) disabler class
//    disabler = new w3tWindowDisabler();
// set opacity of disabler (set as a percentage from 0 to 100 percent opaque) - default is 50
//    disabler.opacity = 50;
// set z-index of disabler - default is 1000
//    disabler.zIndex = 1000;
// set color of disabler - default is #000000 (black)
//    disabler.color = '#000000';  // use only valid color values
// disable window
//    disabler.disable();
// enable window
//    disabler.enabler();

function w3tWindowDisabler() {
  // set defaults
  this.id = 'w3tWindowDisabler';
  this.opacity = 50;
  this.zIndex = 1000;
  this.color = '#000000';
  this.disable = function() {
    if (!document.getElementById(this.id)) {
      var b = document.getElementsByTagName('body')[0];
      var newdiv = document.createElement('div');
      var divIdName = this.id;
      newdiv.setAttribute('id',divIdName);
      b.appendChild(newdiv);
      div = document.getElementById(divIdName)
      windowSize = this.getWindowSize();
      with (div.style) {
        display = 'block';
        width = windowSize[0]+'px';
				minWidth = '100%';
        height = windowSize[1]+'px';
        position = 'absolute';
        top = '0';
        left = '0';
        backgroundColor = this.color;
        zIndex = this.zIndex;
      }
      if (typeof div.style.opacity == "string") {
        div.style.opacity = this.opacity/100;
      } else {
        div.style.filter = "alpha(opacity='"+this.opacity+"')";
      }
    } // else browser is already disabled or this div already exists
  } // end function disable
  
  this.enable = function () {
    if (document.getElementById(this.id)) {
      var b = document.getElementsByTagName('body')[0];
      var olddiv = document.getElementById(this.id);
      b.removeChild(olddiv);
    } // else div does not exist
  } // end function enable
  
  this.getWindowSize = function() {
    var WindowWidth = 0, WindowHeight = 0;
    if (typeof(window.innerWidth) != 'undefined') {
        WindowWidth = window.innerWidth;
        WindowHeight = window.innerHeight;
    }
    if (typeof(document.documentElement) != 'undefined' 
							 && typeof(document.documentElement.clientWidth) != 'undefined' 
							 && document.documentElement.clientWidth != 0) {
      if (document.documentElement.clientWidth > WindowWidth) {
        WindowWidth = document.documentElement.clientWidth;
      }
      if (document.documentElement.clientHeight > WindowHeight) {
        WindowHeight = document.documentElement.clientHeight;
      }
    }
    if (typeof(document.body) != 'undefined' 
							 && typeof(document.body.clientWidth) != 'undefined' 
							 && document.body.clientWidth != 0) {
      if (document.body.clientWidth > WindowWidth) {
        WindowWidth = document.body.clientWidth;
      }
      if (document.body.clientHeight > WindowHeight) {
        WindowHeight = document.body.clientHeight;
      }
    }
		if (document.getElementsByTagName('body')[0].clientWidth > WindowWidth) {
			WindowWidth = document.getElementsByTagName('body')[0].clientWidth;
		}
		if (document.getElementsByTagName('body')[0].clientHeight > WindowHeight) {
			WindowHeight = document.getElementsByTagName('body')[0].clientHeight;
		}
		n = document.getElementsByTagName('body')[0];
		divs = n.getElementsByTagName('div');
		for (i=0; i<divs.length; i++) {
			cWidth = divs[i].clientWidth;
			if (cWidth > WindowWidth) {
				WindowWidth = cWidth;
			}
			if (divs[i].clientHeight > WindowHeight) {
				WindowHeight = divs[i].clientHeight;
			}
		}
    return [WindowWidth, WindowHeight];
  }  // end function getWindowSize
  
} // end Class