function do_table(parent,width,height,border,table_id)
  {
  //creates a table with the attributes specified in the parameters. Width and height are in cells, not pixels.
  //returns the table for further modification.

  //The height of the table (ie how many <TR> tags) is determined by parameter "height".
  //The width of the table (ie how many <TD> tags per <TR>) is determined by parameter "width".

    var newtable=document.createElement('table'); 		//create a table
    parent.appendChild(newtable);				//attach it to the DOM.

    var newtbody=document.createElement("tbody");		//create a tbody for the table
    newtable.appendChild(newtbody);				//attach the new tbody to the new table
  
    newtable.setAttribute('border',border);			//give the table a border
    newtable.setAttribute('id',table_id);			//give the table an id for later identification 
    newtable.setAttribute('name',table_id);			//give the table a name for later identification 
    
    for(i=0; i<height; i++)					//insert the rows and cells
      {
      var newrow = newtable.insertRow(i);
      for(j=0; j<width; j++)
         {
         var newcell=newrow.insertCell(j);
         //newcell.innerHTML="cell"+i+j;
         }
      }
  return newtable;
  }

function round_to(number,decimals)
{			//rounds a number to a specified number of decimal places)
var output_number=new String();output_number="";
var stringed_number=new String();stringed_number=String(number);
var output_length=stringed_number.indexOf(".")+decimals;
round=new Array();
if(stringed_number.indexOf(".")!=-1)
  {
  round[output_length+1]=0;
  if(parseInt(stringed_number.charAt(output_length+1))>=5){round[output_length+1]=1;}
  for(i=output_length;i>=0;i--)
    {
    if(stringed_number.charAt(i)!=".")
      {
        if(round[i+1]==1&&stringed_number.charAt(i)!="9"){output_number=parseInt(stringed_number.charAt(i))+1+output_number;round[i]=0;}	//If rounding up and not a 9, add 1. Don't need to round next digit.
        if(round[i+1]==1&&stringed_number.charAt(i)=="9")	// If rounding up and a 9, change to zero. Round next digit...
          {
          if(i==0){output_number="10"+output_number;}		// Unless this is the very first digit, in which case it must turn into a 10. (or 99.99 will be rounded to 00.00)
          else{output_number="0"+output_number;round[i]=1;}
          }	
        if(round[i+1]==0){output_number=String(stringed_number.charAt(i))+output_number;round[i]=0;}	// No rounding necessary.
      }
    else	// Handling the decimal point
      {
      round[i]=round[i+1];
      output_number="."+output_number;
      }
    }
  }
else{output_number=number;}	// If the number contains no decimal.

return output_number;
}

function tidy_table(table)
{ 		//clears all the spacing and junk from a table, making it easier to put images into.
    table.cellPadding=0; table.cellSpacing=0; 
}

function getindex(range)
{
// generates a random integer between 1 and the specified 'range' value (inclusive), using the current time (minutes*seconds) as a seed.
var now=new Date();
var seed=now.getSeconds()*now.getMinutes();
var rand=Math.random(seed)*range;
rand=Math.round(rand);			//round up
if(rand==range){rand=0;}		//might as well start at one rather than zero.
rand++;
return rand;
}