var facade;
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.getAvailableHeight = function(){
  var h = 0;
  if (window.innerHeight) {
    /*
    if (window.scrollY> 0){
    h=window.innerHeight+window.scrollY;
    }else{
    h=window.innerHeight;
    }
    */
    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.getAvailableWidth = function(){
  var w = 0;
    if (window.innerWidth) {
    /*
    if (window.scrollX > 0) {
      w = window.innerWidth + window.scrollX;
    } else {
      w = window.innerWidth;
    }
    */
    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.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.getElmClass=function(elm){
var cName=false;
if (elm.nodeType){
if (elm.getAttribute){
cName=elm.getAttribute('class');
}else if (elm.className){
cName=elm.className;
}else if (elm.style.className){
cName=elm.style.className;
}}
return cName;
}
Facade.prototype.getElmHeight=function(testElm){
var h=0;
//var msg='h='+h+"\n";
if (typeof testElm.clientHeight !='undefined'){
//msg+='testElm.clientHeight="'+testElm.clientHeight+"\"\n";
h=testElm.clientHeight;
}else if (typeof testElm.style !='undefined' && typeof testElm.style.height !='undefined'){
//msg+='testElm.style.height="'+testElm.style.height+"\"\n";
h=parseInt(testElm.style.height);
}else if (typeof testElm.style !='undefined' && typeof testElm.style.pixelHeight !='undefined'){
//msg+='testElm.style.pixelHeight="'+testElm.style.pixelHeight+"\"\n";
h=testElm.style.pixelHeight;
}else{
//alert('cannot find element height');
}
//msg+='h='+h+"\n";
//alert(msg);
return h;
}
Facade.prototype.getElmWidth=function(testElm){
var w=0;
//var msg='w="'+w+"\"\n";
if (typeof testElm.clientWidth !='undefined'){
//msg+='testElm.offsetWidth="'+testElm.offsetWidth+"\"\n";
w=testElm.clientWidth;
}else if (typeof testElm.style !='undefined' && typeof testElm.style.width !='undefined'){
//msg+='testElm.style.width="'+testElm.style.width+"\"\n";
w=parseInt(testElm.style.width);
}else if (typeof testElm.style !='undefined' && typeof testElm.style.pixelWidth !='undefined'){
//msg+='testElm.style.pixelWidth="'+testElm.style.pixelWidth+"\"\n";
w=testElm.style.pixelWidth;
}
//msg+='w="'+w+"\"\n";
//alert(msg);
return w;
}
Facade.prototype.getElmX=function(elm){
var x=0;
if (elm.style.left !='undefined'){
x=parseInt(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=parseInt(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.getScrollX=function(){
var scroll=0;
if (typeof window.pageXOffset !='undefined'){
scroll=window.pageXOffset;
}else if (typeof document.documentElement.scrollLeft !='undefined'){
scroll=document.documentElement.scrollLeft;
}
return scroll;
}
Facade.prototype.getScrollY=function(){
var scroll=0;
if (typeof window.pageYOffset !='undefined'){
scroll=window.pageYOffset;
}else if (typeof document.documentElement.scrollTop !='undefined'){
scroll=document.documentElement.scrollTop;
}
return scroll;
}
Facade.prototype.hideElm=function(elm){
var newElm=(!elm.nodeType) ? this.getElm(elm) : elm;
if (newElm){
if (typeof newElm.style !='undefined' && typeof newElm.nodeType !='undefined'){
newElm.style.visibility='hidden';
newElm.style.display='none';
}else{
messenger.sendErr('Facade.hideElm("'+elm+'") :: unable to style node because .style==undefined');
}}else{
messenger.sendErr('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){
  // make sure the x/y precentages are within the limits
  var xp = (xPercent < 0) ? 0 : (xPercent > 100) ? 100 : xPercent;
  var yp = (yPercent < 0) ? 0 : (yPercent > 100) ? 100 : yPercent;
  
  // get the internal window size
  var browserX = this.getAvailableWidth();
  var browserY = this.getAvailableHeight();
  //msg = 'Browser X: ' + browserX + "\n" + 'Browser Y: ' + browserY + "\n";
  
  // get the size of the element we're trying to position
  var elmW = this.getElmWidth(elm);
  var elmH = this.getElmHeight(elm);
  //msg += 'Elm Width: ' + elmW + "\n" + 'Elm Height: ' + elmH + "\n";
  
  // determine the position of this element in the current available screen dimensions
  var newX = (xp > 0) ? Math.floor((browserX * (xp / 100))) : 0;
  var newY = (yp > 0) ? Math.floor((browserY * (yp / 100))) : 0;
  
  // now adjust the x/y location to compensate for the dimensions of the element
  newX -= Math.floor(elmW / 2);
  newY -= Math.floor(elmH / 2);
  
  // determine how much has been scrolled
  var scrollX = this.getScrollX();
  var scrollY = this.getScrollY();
  //msg += 'Scrolled X: ' + scrollX + "\n" + 'Scrolled Y: ' + scrollY + "\n";
  
  // adjust for the scrolling
  newX += scrollX;
  newY += scrollY;
  
  if (typeof elm.style != 'undefined') {
    elm.style.left = newX + 'px';
    elm.style.top = newY + 'px';
  }
  
  //alert(msg);
}
Facade.prototype.showElm=function(elm, displayType, visTyp){
var dVal=(!displayType) ? 'block' : displayType;
var vVal=(!visTyp) ? 'visible' : visTyp;
var newElm=(!elm.nodeType) ? this.getElm(elm) : elm;
if (newElm.nodeType){
if (typeof newElm.style !='undefined'){
newElm.style.visibility='visible';
try{newElm.style.display=dVal;}catch(e){newElm.style.display='block';}}else{
messenger.sendErr('Facade.showElm("'+elm+'") :: unable to style node because .style==undefined');
}}else{
messenger.sendErr('Facade.showElm("'+elm+'") :: could not get node');
}}
function loadFacade(){
facade=new Facade();
}
if (window.addEventListener){
window.addEventListener('load', loadFacade, false);
}else if (window.attachEvent){
window.attachEvent('onload', loadFacade);
}else if (window.onload){
window.onload=loadFacade();
}
