// www.lespassagers.org
// Fonctions utilitaires

// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
function addLoadEvent(func) {	
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
      window.onload = func;
  } 
  else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

// getPageWidth()
// Pour calculer la largeur de la page
function getPageWidth() {
	
	var xScroll;
	if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
		xScroll = document.body.scrollWidth;
	}
  else { // Explorer Mac... would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
	}
	
	var windowWidth;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
	}
  else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
	}
  else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
	}	
	
	// for small pages with total width less then width of the viewport
	if (xScroll < windowWidth) {	
		pageWidth = windowWidth;
	}
  else {
		pageWidth = xScroll;
	}
  
	return pageWidth;
}
