// this array variable is declared globally and works in two functions: resetWhite() and validateEntry(that). (For some reason the para variable doesn't work when I declare it up here, so I have to declare it locally inside each of resetWhite() and validateEntry(that)..<scratches head>.).
	var arraySpans = document.getElementsByTagName('span');

	function resetWhite()
	{
		var para = document.getElementById('version');
		para.style.backgroundColor = "#FFFFFF";
		document.body.style.backgroundColor = "#FFFFFF";
		
		for (var i=0; i < arraySpans.length; i++)
			{			arraySpans[i].style.backgroundColor = "#FFFFFF";	
			}	
							
	}
	
	function focusRed() 
	{
		var myElement = document.forms[0].elements[0];		
		myElement.focus();
	}
		
		// this next function takes the input from validateEntry() and converts it into 
	// hexadecimal form. This procedure is overly complex and backwards.
	// I should just test for 0-255 and then convert to hex 
	// or learn how to call colors in the browser with rgb() equivalents. D'oh.
		function convertNumber(inNum)
	{
		var myNum = inNum;
		var myDigit1;
		var myDigit2;
		myDigit1 = Math.floor(myNum/16);
		if (myDigit1>15) {myDigit1="Z"}	// This 'Z' will trip up the RegEx causing the alert (the input was  16 * 16 or greater). I don't recall why it's a separate if; or why no 'break' statement is needed.
		if (myDigit1>14) {myDigit1="F"}
		else if (myDigit1>13) {myDigit1="E"}
		else if (myDigit1>12) {myDigit1="D"}
		else if (myDigit1>11) {myDigit1="C"}
		else if (myDigit1>10) {myDigit1="B"}
		else if (myDigit1>9) {myDigit1="A"}

		myDigit2 = myNum%16;
		if (myDigit2>15) {myDigit2="Z"}
		if (myDigit2>14) {myDigit2="F"}
		else if (myDigit2>13) {myDigit2="E"}
		else if (myDigit2>12) {myDigit2="D"}
		else if (myDigit2>11) {myDigit2="C"}
		else if (myDigit2>10) {myDigit2="B"}
		else if (myDigit2>9) {myDigit2="A"}

		return "" + myDigit1 + myDigit2;
	}
	
	
		// this next function receives from the Form element, sends out to convertNumber() to
	// get a hexadecimal representation, and then tests that against a regular expression.
	// If it passes muster, the function instructs the various document elements to change color.
	function validateEntry(that)
	{	
		// the regExp says there must be 0 or 1 characters at the start that are
		// between 0 and 9 or a thru f, and exactly one such character at the end.
		// Thus it demands one or two characters made up of legitimate hex numbers.
		var myRegExp = /^[^G-Zg-z_\W]?[^G-Zg-z_\W]$/
		var redEntry = convertNumber(that.red.value);	
		if (redEntry.search(myRegExp) == -1)
		{
			alert("Your Red value must be an integer between 0 and 255. Please reset your Red value.")
			that.red.select()				
			return;
		}
		var greenEntry = convertNumber(that.green.value);			
		if (greenEntry.search(myRegExp) == -1)
		{
			alert("Your Green value must be an integer between 0 and 255. Please reset your Green value.")
			that.green.select()			
			return;
		}
		var blueEntry = convertNumber(that.blue.value);			
		if (blueEntry.search(myRegExp) == -1)
		{
			alert("Your Blue value must be an integer between 0 and 255. Please reset your Blue value.")
			that.blue.select()			
			return;
		}
	// Everybody happy now, so we put together a hex color representation and set appropriate 
	// elements to it.
		var myColor = "#" + redEntry + greenEntry + blueEntry;
				
		document.body.style.backgroundColor = myColor;
		
		var para = document.getElementById('version');
		para.style.backgroundColor = myColor;
							

		for (var i=0; i<arraySpans.length; i++)
			{			arraySpans[i].style.backgroundColor = myColor;	
			}							

	}