function setRows(numRows)
{
	var base = '/buildit/';
	var numHeaderRows = 3;
	var entriesTable = document.getElementById("entries");
	var currentNumRows = (entriesTable.rows.length - numHeaderRows)/2;
	
	if (isNaN(numRows)) {
		return;
	}
	
	if (numRows < 1) {
		numRows = 1;
	}
	else if (numRows > 40) {
		numRows = 40;
	}
	
	if (numRows < currentNumRows) {
		numRowsToDelete = currentNumRows - numRows;
		index = numHeaderRows + numRows*2;
		for (i = 0; i < numRowsToDelete*2; i++) {
			entriesTable.deleteRow(index);
		}
	}
	else if (numRows > currentNumRows) {
		numRowsToAdd = numRows - currentNumRows;
		for (i = 0; i < numRowsToAdd; i++) {
			rowNum = currentNumRows + i + 1;
			
			newRow = entriesTable.insertRow(-1);
			cell = document.createElement("td");
			cell.colSpan = 17;
			spacer = document.createElement("img");
			spacer.src = base + "images/spacer.gif";
			spacer.width = 1;
			spacer.height = 4;
			cell.appendChild(spacer);
			newRow.appendChild(cell);

			newRow = entriesTable.insertRow(-1);
			cell = document.createElement("td");
			cell.appendChild(document.createTextNode(rowNum));
			newRow.appendChild(cell);
			newRow.appendChild(document.createElement("td"));

			cell = document.createElement("td");
			textInput = document.createElement("input");
			textInput.type = "text";
			textInput.name = "first_name_" + rowNum;
			textInput.id = "first_name_" + rowNum;
			textInput.size = 12;
			textInput.onfocus = setRowHighlight;
			textInput.onblur = clearRowHighlight;
			cell.appendChild(textInput);
			newRow.appendChild(cell);
			newRow.appendChild(document.createElement("td"));
			
			cell = document.createElement("td");
			textInput = document.createElement("input");
			textInput.type = "text";
			textInput.name = "last_name_" + rowNum;
			textInput.id = "last_name_" + rowNum;
			textInput.size = 12;
			textInput.onfocus = setRowHighlight;
			textInput.onblur = clearRowHighlight;
			cell.appendChild(textInput);
			newRow.appendChild(cell);
			newRow.appendChild(document.createElement("td"));
			
			cell = document.createElement("td");
			textInput = document.createElement("input");
			textInput.type = "text";
			textInput.name = "gears_" + rowNum;
			textInput.id = "gears_" + rowNum;
			textInput.size = 9;
			textInput.onfocus = setRowHighlight;
			textInput.onblur = clearRowHighlight;
			cell.appendChild(textInput);
			newRow.appendChild(cell);
			newRow.appendChild(document.createElement("td"));
			
			cell = document.createElement("td");
			textInput = document.createElement("input");
			textInput.type = "text";
			textInput.name = "gears_confidence_" + rowNum;
			textInput.id = "gears_confidence_" + rowNum;
			textInput.size = 9;
			textInput.onfocus = setRowHighlight;
			textInput.onblur = clearRowHighlight;
			cell.appendChild(textInput);
			newRow.appendChild(cell);
			newRow.appendChild(document.createElement("td"));
			
			cell = document.createElement("td");
			textInput = document.createElement("input");
			textInput.type = "text";
			textInput.name = "buoyancy_" + rowNum;
			textInput.id = "buoyancy_" + rowNum;
			textInput.size = 9;
			textInput.onfocus = setRowHighlight;
			textInput.onblur = clearRowHighlight;
			cell.appendChild(textInput);
			newRow.appendChild(cell);
			newRow.appendChild(document.createElement("td"));
			
			cell = document.createElement("td");
			textInput = document.createElement("input");
			textInput.type = "text";
			textInput.name = "buoyancy_confidence_" + rowNum;
			textInput.id = "buoyancy_confidence_" + rowNum;
			textInput.size = 9;
			textInput.onfocus = setRowHighlight;
			cell.appendChild(textInput);
			textInput.onblur = clearRowHighlight;
			newRow.appendChild(cell);
			newRow.appendChild(document.createElement("td"));
			
			cell = document.createElement("td");
			textInput = document.createElement("input");
			textInput.type = "text";
			textInput.name = "programming_" + rowNum;
			textInput.id = "programming_" + rowNum;
			textInput.size = 9;
			textInput.onfocus = setRowHighlight;
			textInput.onblur = clearRowHighlight;
			cell.appendChild(textInput);
			newRow.appendChild(cell);
			newRow.appendChild(document.createElement("td"));
			
			cell = document.createElement("td");
			textInput = document.createElement("input");
			textInput.type = "text";
			textInput.name = "programming_confidence_" + rowNum;
			textInput.id = "programming_confidence_" + rowNum;
			textInput.size = 9;
			textInput.onfocus = setRowHighlight;
			textInput.onblur = clearRowHighlight;
			cell.appendChild(textInput);
			newRow.appendChild(cell);
		}
	}
	document.getElementById("num_rows").value = numRows;
	document.getElementById("entry_form").style.display = "block";
	document.getElementById("teacher").focus();
}

function setRowHighlight(evt)
{
	if (!evt) evt = window.event;
	var target = evt.target?evt.target:evt.srcElement;
	var numHeaderRows = 3;
	var entriesTable = document.getElementById("entries");
	var rowNum = numHeaderRows + 2*parseInt(target.name.substr(target.name.lastIndexOf("_") + 1)) - 1;

	entriesTable.rows[rowNum].style.backgroundColor = "#DDDDDD";
}

function clearRowHighlight(evt)
{
	if (!evt) evt = window.event;
	var target = evt.target?evt.target:evt.srcElement;
	var numHeaderRows = 3;
	var entriesTable = document.getElementById("entries");
	var rowNum = numHeaderRows + 2*parseInt(target.name.substr(target.name.lastIndexOf("_") + 1)) - 1;

	entriesTable.rows[rowNum].style.backgroundColor = "#FFFFFF";
}

function checkFields()
{
	if (document.getElementById("section").value == "") {
		alert("Please enter the section.");
		return false;
	}
if (!document.getElementById("test_type_pre").checked && !document.getElementById("test_type_post").checked) {
		alert("Please select a test type (pre or post).");
		return false;
	}
	
	var numHeaderRows = 3;
	var entriesTable = document.getElementById("entries");
	var currentNumRows = (entriesTable.rows.length - numHeaderRows)/2;
	var error = "";
	var anyBlanks = false;
	for (i = 1; i < currentNumRows + 1; i++) {
		if (document.getElementById("first_name_" + i).value == "") {
			error = "The first name input in row " + i + " is blank. Please fill it in.";
			break;
		}
		if (document.getElementById("last_name_" + i).value == "") {
			error = "The last name input in row " + i + " is blank. Please fill it in.";
			break;
		}
		if (document.getElementById("gears_" + i).value.search(/[^ABCDabcd_, ]+/) > -1) {
			error = "The input field for gears in row " + i + " has inappropriate characters. Please correct.";
			break;
		}
		if (document.getElementById("buoyancy_" + i).value.search(/[^ABCDabcd_, ]+/) > -1) {
			error = "The input field for buoyancy in row " + i + " has inappropriate characters. Please correct.";
			break;
		}
		if (document.getElementById("programming_" + i).value.search(/[^ABCDabcd_, ]+/) > -1) {
			error = "The input field for programming in row " + i + " has inappropriate characters. Please correct.";
			break;
		}
		if (document.getElementById("gears_confidence_" + i).value.search(/[^12345_, ]+/) > -1) {
			error = "The input field for confidence levels in gears in row " + i + " has inappropriate characters. Please correct.";
			break;
		}
		if (document.getElementById("buoyancy_confidence_" + i).value.search(/[^12345_, ]+/) > -1) {
				error = "The input field for confidence levels in buoyancy in row " + i + " has inappropriate characters. Please correct.";
			break;
		}
		if (document.getElementById("programming_confidence_" + i).value.search(/[^12345_, ]+/) > -1) {
			error = "The input field for confidence levels in programming in row " + i + " has inappropriate characters. Please correct.";
			break;
		}
		if ((document.getElementById("gears_" + i).value == "") ||
			(document.getElementById("gears_confidence_" + i).value == "") ||
			(document.getElementById("buoyancy_" + i).value == "") ||
			(document.getElementById("buoyancy_confidence_" + i).value == "") ||
			(document.getElementById("programming_" + i).value == "") ||
			(document.getElementById("programming_confidence_" + i).value == "")) {
			anyBlanks = true;
		}
									 
	}
	if (error != "") {
		alert(error);
		return false;
	}
	if (anyBlanks) {
		return confirm("You have left some of the student responses blank.  Do you still wish to submit your data?");
	}
}
