/*****************************************************
 * Utils.js
 * 04.14.2003
 * Eddie Lim <elim@eecs.harvard.edu>
 * www.netsymbiosis.com
 *****************************************************/

function checkArgs(args, argc)
{
	if(args != null && typeof(args.length == "number") && args.length >= argc)
	{
		return true;
	}
	return false;
}

function debug(str)
{
	_debugPane.appendText("*** " + str);
}

function errorHandler(msg, url, line)
{
	_exceptionPane.appendText("******************************************************");
	_exceptionPane.appendText("error message: " + msg);
	_exceptionPane.appendText("URL: " + url);
	_exceptionPane.appendText("line number: " + line);
	_exceptionPane.appendText("browser info: " + navigator.userAgent);
	_exceptionPane.appendText("******************************************************\n");
	return true;
}

function getRandom(min, max)
{
	var range = max - min;
	var rand = Math.random(range);
	return Math.floor(min + rand * range);
}

/*******************************************************
 * from youngpup.net
 *******************************************************/
function fixE(e)
{
	// IE's global event model is incompatible with DOM2, but it still works.
	if (typeof e == 'undefined') e = window.event;
	if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
	if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
	return e;
}

/*******************************************************
 * viewport utilities below from 13thparallel.org
 *******************************************************/
getViewportWidth = function() {
	var width = 0;
	if( document.documentElement && document.documentElement.clientWidth ) {
		width = document.documentElement.clientWidth;
	}
	else if( document.body && document.body.clientWidth ) {
		width = document.body.clientWidth;
	}
	else if( window.innerWidth ) {
		width = window.innerWidth - 18;
	}
	return width;
};

getViewportHeight = function() {
  var height = 0;
  if( document.documentElement && 
  document.documentElement.clientHeight ) {
    height = document.documentElement.clientHeight;
  }
  else if( document.body && 
  document.body.clientHeight ) {
    height = document.body.clientHeight;
  }
  else if( window.innerHeight ) {
    height = window.innerHeight - 18;
  }
  return height;
};

getViewportScrollX = function() {
	var scrollX = 0;
	if( document.documentElement && document.documentElement.scrollLeft ) {
		scrollX = document.documentElement.scrollLeft;
	}
	else if( document.body && document.body.scrollLeft ) {
		scrollX = document.body.scrollLeft;
	}
	else if( window.pageXOffset ) {
		scrollX = window.pageXOffset;
	}
	else if( window.scrollX ) {
		scrollX = window.scrollX;
	}
	return scrollX;
};

getViewportScrollY = function() {
  var scrollY = 0;
  if( document.documentElement && document.documentElement.scrollTop ) {
    scrollY = document.documentElement.scrollTop;
  }
  else if( document.body && 
  document.body.scrollTop ) {
    scrollY = document.body.scrollTop;
  }
  else if( window.pageYOffset ) {
    scrollY = window.pageYOffset;
  }
  else if( window.scrollY ) {
    scrollY = window.scrollY;
  }
  return scrollY;
};
