﻿// JScript File with general functions and methods

// cross browser function to get reference to object
function getElement(id){    
	if(document.getElementById){
		getElement = function(id){ return document.getElementById(id); }
	}else if(document.all){
		getElement = function(id){ return document.all[id]; };
	}else if(document.layers){
		getElement = function(id){ return document.layers[id]; };
	}else{
		getElement = function() { return null; }
	}    
	// When we get here, the getElement function has been replaced.
	// So we return the result of the new function.
	return getElement(id);
}

function AddOnload(myfunc){
  if(window.addEventListener)
    window.addEventListener('load', myfunc, false);
  else if(window.attachEvent)
    window.attachEvent('onload', myfunc);
}

function getElementDimensions(obj) {
  var objLeft = objTop = objHeight = objWidth = 0;
  if (obj.offsetParent) {
    objLeft = obj.offsetLeft
    objTop = obj.offsetTop     
    objHeight = obj.offsetHeight
    objWidth = obj.offsetWidth      
    while (obj = obj.offsetParent) {
      objLeft += obj.offsetLeft
      objTop += obj.offsetTop
    }
  }
	return [objLeft,objTop,objHeight,objWidth];
}

function getWindowDimensions() {
  var winWidth = winHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    winWidth = window.innerWidth;
    winHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    winWidth = document.documentElement.clientWidth;
    winHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    winWidth = document.body.clientWidth;
    winHeight = document.body.clientHeight;
  }
  return [winWidth,winHeight];
}
