// masterSpeech.js
var noTalkVar;
// This will be called after anything is listened to to first see if it's part of the master script.
// The master speech is all caps to be able to be distinguished.
function processMasterFirst(responseField, processThisFunctionNext, callingMethod)
{
	response = document.getElementById(responseField).value;
	// Make sure every character is upper case or a space
	if (allUpperCase(response))
	{
		if (response.indexOf("RELOAD") != -1 || response.indexOf("REFRESH") != -1)
		{
			history.go(0);
		}
		else if (response.indexOf("BACK") != -1)
		{
			history.back();
		}
		else if (response.indexOf("HELP") != -1)
		{
			window.location="Help.jsp";
		}
		else if (response.indexOf("HINT") != -1)
		{
			var hintNum = "hint";
			if (response.indexOf("1") != -1)
			{
				hintNum += "1";
			}
			else if (response.indexOf("2") != -1)
			{
				hintNum += "2";
			}
			else if (response.indexOf("3") != -1)
			{
				hintNum += "3";
			}
			hintToDisplay = document.getElementById(hintNum);
			if (hintToDisplay != null && hintToDisplay.style.visibility == "hidden")
			{
				hintToDisplay.style.visibility = "visible"; 
				eval(callingMethod + ".initialtimeout = 60000");
				eval(callingMethod + ".start()");
			}
			else if (hintToDisplay != null && hintToDisplay.style.visibility == "visible")
			{
				hintToDisplay.style.visibility = "hidden"; 
				eval(callingMethod + ".initialtimeout = 10000");
				eval(callingMethod + ".start()");
			}
			else
			{
				noTalkVar = callingMethod + ".start()";
				hintNotFound.start();
			}
		}
		else if (response.indexOf("WELCOME") != -1 || response.indexOf("MAPS") != -1 || response.indexOf("MAIN") != -1 || response.indexOf("HOME") != -1)
		{
			window.location="index.jsp";
		}
		else if (response.indexOf("BROWSE") != -1)
		{
			window.location="Browse";
		}
		else if (response.indexOf("OVERVIEW") != -1)
		{
			window.location="Overview.jsp";
		}
		else if (response.indexOf("FIND") != -1 || response.indexOf("VIEW") != -1)
		{
			if (response.indexOf("ABBREVIATION") != -1)
			{
				window.location="FindByAbbreviation.jsp";
			}
			else if (response.indexOf("AROUND BUILDING") != -1 || response.indexOf("WITHIN DISTANCE") != -1)
			{
				window.location="FindWithinDistance.jsp";
			}
			else if (response.indexOf("CATEGOR") != -1)
			{
				window.location="FindByCategory.jsp";
			}
			else if (response.indexOf("NAME") != -1 || response.indexOf("BUILDING") != -1)
			{
				window.location="FindByName.jsp";
			}
			else if (response.indexOf("DIRECTIONS") != -1)
			{
				window.location="GetDirections.jsp";
			}
			else
			{
				eval(processThisFunctionNext);
			}
		}
		else if (response.indexOf("ABBREVIATION") != -1)
		{
			window.location="FindByAbbreviation.jsp";
		}
		else if (response.indexOf("WITHIN DISTANCE") != -1)
		{
			window.location="FindWithinDistance.jsp";
		}
		else if (response.indexOf("CATEGORY") != -1)
		{
			window.location="FindByCategory.jsp";
		}
		else if (response.indexOf("NAME") != -1)
		{
			window.location="FindByName.jsp";
		}
		else if (response.indexOf("DIRECTIONS") != -1)
		{
			window.location="GetDirections.jsp";
		}
		else if (response.indexOf("HELP") != -1)
		{
			window.location="Help.jsp";
		}
		else if (response.indexOf("TURN OFF") != -1)
		{
			window.location="turnOffVoice.jsp?return=" + window.location;
		}
		else if (response.indexOf("CONTACT") != -1)
		{
			window.location="Contact.jsp";
		}
		else
		{
			eval(processThisFunctionNext);

		}
	}
	else
	{
		eval(processThisFunctionNext);
	}
}

function allUpperCase(response)
{
	for (i = 0; i < response.length; i++)
	{
		theChar = response.charAt(i);
		if ( (theChar < 'A' || theChar > 'Z') && (theChar < '0' || theChar > '9') && theChar != ' ')
		{
			return false;
		}
	}
	return true;
}

function noTalk()
{
	eval(noTalkVar);
}
