<!--  // Hide this just in case this file is read as HTML

// *****************************************************************
// MISC.JS
// Includes miscellaneous routines
// *****************************************************************
// assert(cond, func, str): programmer assert
// arraycopy(src, srcPos, dest, destPos, length): copies part of array src into array dest
// arrayappend(array1, array2): returns a new array of elements in array1 followed by elements in array2
// arrayfind(array, value): return index in array that some value is at
// arraylookup(array, value, compareFn): like arrayfind, but with own comparator
// isArray(obj): return true if obj is an array (best guess)
// getProperties(obj): returns a string, separated by newlines, of all properties of obj
// randomInt(low, high): returns a random integer between low and high inclusive
// setStatus(str): sets status message
// toHexString(num): returns hexadecimal equivalent string of num
// trim(str): returns str with leading and trailing spaces removed
// ObjectWrapper(value): wrap anything into an object
// *****************************************************************

function assert(cond, func, str)
{
	// used to indicate programmer errors - things that should never happen
	// if cond is false, then gives an error message with str
	// func should be a string to indicate where the error occured
	if (!cond)
		alert ("Programmer error in " + func + ": " + str);
	return (false);
}

function arraycopy(src, srcPos, dest, destPos, length)
{
      // copies length elements starting from srcPos in array src to
      // the length elements in array dest starting from destPos
      //
      // the last argument, the length, is optional.
      // if omitted, the src arrray will be copied to the end of the array

      if (arguments.length < 5)
            length = src.length - srcPos;

      var end = length + srcPos;    // end of src array

      // go through and copy the array
      for (var i = srcPos, j = destPos; i < end; i++, j++)
            dest[j] = src[i];
}

function arrayappend(array1, array2)
{
    var newarray = new Array();
    var i;

    if (array1)
    {
        for (i = 0; i < array1.length; i++)
        {
            newarray[newarray.length] = array1[i];
        }
    }
    if (array2)
    {
        for (i = 0; i < array2.length; i++)
        {
            newarray[newarray.length] = array2[i];
        }
    }
    return newarray;
}

function arrayfind(array, value)
{
	// return first index in array to contain value or -1 if not found
	for (var i = 0; i < array.length; i++)
	{
		if (array[i] == value)
			return (i);
	}
	return (-1);
}

function arraylookup(array, value, compareFn)
{
	// return first index in array to contain value or -1 if not found
        // compareFn is used to compare each element with value
        // compareFn should return true if two elements are the same
	for (var i = 0; i < array.length; i++)
	{
		if (compareFn(array[i], value))
			return (i);
	}
	return (-1);
}

function isArray(obj)
{
	// how to tell if obj is an array? check if it has a member called join
	return (obj.join);
}

function getProperties(obj)
{
      // returns all the properties of obj

      var result = "";

      for (var i in obj)
            result += i + "\n";

      return (result);
}

function randomInt(low, high)
{
	return(low + Math.floor((high - low + 1) * Math.random()));
}

function setStatus(str)
{
      // sets the status message at the bottom of the window to str

      window.status = str;
      return true;    // must return true for onMouseOver events
}

function toHexString(num)
{
      // returns the hexadecimal equivalent string of num
      var hexTable = "0123456789abcdef";

      if (num < 16)
            return hexTable.charAt(num);

      return (toHexString(Math.floor(num/16)) + hexTable.charAt(num % 16));
}

function trim(str)
{
      // returns str with leading and trailing spaces removed

      var i, j;

      if (str == null)
            return null;

      // find leading spaces
      for (i = 0; i < str.length; i++)
      {
            if (str.charAt(i) != " ")
                  break;      // exit if not a space
      }

      if (i == str.length)
            return "";  // str is all spaces

      // find trailing spaces
      for (j = str.length - 1; j >= 0; j--)
      {
            if (str.charAt(j) != " ")
                  break;      // exit if not a space
      }

      // return the new string without leading and trailing spaces
      return (str.substring (i, j+1));
}

function ObjectWrapper(value)
{
	this.value = value;
}

// Stop hiding -->

