function Facade() {
}

Facade.prototype.changeElmClass = function(elm, cName) {
  if (elm.nodeType) {
    if (elm.setAttribute) {
      elm.setAttribute('class', cName);
    } else if (elm.className) {
      elm.className = cName;
    } else if (elm.style.className) {
      elm.style.className = cName;
    }
  }
}

Facade.prototype.getAvailableWidth = function() {
  var w = 0;

  if (window.innerWidth) {
    if (window.scrollX > 0) {
      w = window.innerWidth + window.scrollX;
    } else {
      w = window.innerWidth;
    }
  } else if (document.documentElement && document.documentElement.clientWidth) {
    w = document.documentElement.clientWidth;
  } else if (document.body) {
    w = document.body.clientWidth;
  }

  return w;
}

Facade.prototype.getAvailableHeight = function() {
  var h = 0;

  if (window.innerHeight) {
    if (window.scrollY > 0) {
      h = window.innerHeight + window.scrollY;
    } else {
      h = window.innerHeight;
    }
  } else if (document.documentElement && document.documentElement.clientHeight) {
    h = document.documentElement.clientHeight;
  } else if (document.body) {
    h = document.body.clientHeight;
  }

  return h;
}

Facade.prototype.getElm = function(elmId) {
  var elm;
  if (document.getElementById) {
    elm = document.getElementById(elmId);
  } else if (document.all) {
    elm = document.all[elmId];
  }
  return (typeof elm == 'object') ? elm : false;
}

Facade.prototype.getElmHeight = function(elm) {
  var h = 0;

  if (elm.offsetHeight) {
    h = elm.offsetHeight;
  } else if (elm.style.height != 'undefined') {
    h = elm.style.height;
  } else if (elm.style.pixelHeight) {
    h = elm.style.pixelHeight;
  }

  return h;
}

Facade.prototype.getElmWidth = function(elm) {
  var w = 0;

  if (elm.offsetWidth) {
    w = elm.offsetWidth;
  } else if (elm.style.width != 'undefined') {
    w = elm.style.width;
  } else if (elm.style.pixelWidth) {
    w = elm.style.pixelWidth;
  }

  return w;
}

Facade.prototype.getElmX = function(elm) {
  var x = 0;

  if (elm.style.left != 'undefined') {
    x = elm.style.left;
  } else if (elm.offsetLeft && elm.offsetParent) {
    x = elm.offsetLeft;
    var curParent = elm.offsetParent;
    while (typeof curParent != 'undefined') {
      x += curParent.offsetLeft;
    }
  }

  return x;
}

Facade.prototype.getElmY = function(elm) {
  var y = 0;

  if (elm.style.top != 'undefined') {
    y = elm.style.top;
  } else if (elm.offsetTop && elm.offsetParent) {
    y = elm.offsetTop;
    var curParent = elm.offsetParent;
    while (typeof curParent != 'undefined') {
      y += curParent.offsetTop;
    }
  }

  return y;
}

Facade.prototype.getTotalHeight = function() {
  var y;
  var test1 = document.body.scrollHeight;
  var test2 = document.body.offsetHeight
  if (test1 > test2) { // all but Explorer Mac
    y = document.body.scrollHeight;
  }
  else { // Explorer Mac;
    // would also work in Explorer 6 Strict, Mozilla and Safari
    y = document.body.offsetHeight;
  }
  return y;
}

Facade.prototype.hideElm = function(elm) {
  var newElm = (!elm.nodeType) ? this.getElm(elm) : elm;
  if (newElm.nodeType) {
    if (typeof newElm.style != 'undefined') {
      newElm.style.visibility = 'hidden';
      newElm.style.display = 'none';
    } else {
      alert('Facade.hideElm("'+elm+'") :: unable to style node because .style == undefined');
    }
  } else {
    alert('Facade.hideElm("'+elm+'") :: could not get node');
  }
}

Facade.prototype.killElm = function(elm) {
  if (elm.nodeType) {
    var parent = elm.parentNode;
    parent.removeChild(elm);
    elm = null;
  }
}

Facade.prototype.positionElmPercent = function(elm, xPercent, yPercent) {
  var xp = (xPercent < 0) ? 0 : (xPercent > 100) ? 100 : xPercent;
  var yp = (yPercent < 0) ? 0 : (yPercent > 100) ? 100 : yPercent;

  var browserX = this.getAvailableWidth();
  //var browserY = this.getAvailableHeight();
  var browserY = this.getTotalHeight();
  var elmW = this.getElmWidth(elm);
  var elmH = this.getElmHeight(elm);

  var newX = (xp > 0) ? Math.floor((browserX * (xp / 100) - Math.floor(elmW / 2))) : 0;
  var newY = (yp > 0) ? Math.floor((browserY * (yp / 100) - Math.floor(elmH / 2))) : 0;

  // if the new locations put the element out of the current view then they need to be adjusted
  if (newX + elmW > browserX) {
    newX = Math.floor(browserX - elmW);
  }if (newY + elmH > browserY) {
    newY = Math.floor(browserY - elmH);
  }

  if (elm.style) {
    elm.style.left = newX + 'px';
    elm.style.top = newY + 'px';
  }
}

Facade.prototype.showElm = function(elm) {
  var newElm = (!elm.nodeType) ? this.getElm(elm) : elm;
  if (newElm.nodeType) {
    if (typeof newElm.style != 'undefined') {
      newElm.style.visibility = 'visible';

      // TR's can be tricky
      if (newElm.nodeName == 'TR') {
        try {
          newElm.style.display = 'table-row';
        } catch (e) {
          newElm.style.display = 'block';
        }
      } else {
        newElm.style.display = 'block';
      }
    }
  }
}