// Returns the size of the screen for most browsers
function getScreenSize(getWidth) {
  var myWidth = 600, myHeight = 600;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  return (getWidth) ? myWidth : myHeight;
}

// This function will disable the ability to select text for an element
function disableSelection(element) {
  if (element) {
    element.onselectstart = function() {
        return false;
    };
    //element.unselectable = "on";
    element.style.MozUserSelect = "none";
    //element.style.cursor = "default";
  }
}

// This function can be used when prototype library is not used
function getElement(psID) {
   if(document.all) {
      return document.all[psID];
   } else {
      return document.getElementById(psID);
   }
}

/* This script will properly call an init() function on window.onload
   This is actually a problem as browsers have a number of different conventions
   on when to call this init function

   WARNING: the init() function that is called is NOT located in this file
*/
// Dean Edwards/Matthias Miller/John Resig

// Should combine this functionality with below methodology - must remove 
// references to this function
function addLoadEvent(func) {
  if (func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
  }
}

function init_singleton() {
   // quit if this function has already been called
   if (arguments.callee.done) return;

   // flag this function so we don't do the same thing twice
   arguments.callee.done = true;

   // kill the timer
   if (_timer) clearInterval(_timer);

   // call init()
// SPS: uncomment when find way to all init using addLoadEvent
//init();
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
   document.addEventListener("DOMContentLoaded", init_singleton, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
   document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
   var script = document.getElementById("__ie_onload");
   script.onreadystatechange = function() {
      if (this.readyState == "complete") {
         init_singleton(); // call the onload handler
      }
   };
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
   var _timer = setInterval(function() {
      if (/loaded|complete/.test(document.readyState)) {
         init_singleton(); // call the onload handler
      }
   }, 10);
}

/* for other browsers */
window.onload = init_singleton;
