<%!
private String numberPlayBack( String textToPlay )
{
	if( textToPlay == null )
		return "";

	String textToPlayLC = textToPlay.trim().toLowerCase();
	String fractionToPlay = null;
	String fractionText = null;
	String alphaNumToPlay = null;

	if(textToPlayLC.endsWith ("1/2"))
	  {
		fractionToPlay = "half.ulaw";
		fractionText = "and a half";
	  }
	else if (textToPlayLC.endsWith ("1/3"))
	  {
		fractionToPlay = "third.ulaw";
		fractionText = "and a third";
	  }
	else if (textToPlayLC.endsWith ("1/4"))
	  {
		fractionToPlay = "quarter.ulaw";
		fractionText = "and a quarter";
	  }
	
	if ( fractionToPlay != null )	// if there is a fractional portion
	  {								// remove it from play string
	    int x = textToPlayLC.indexOf(" 1");
		if ( x != -1 )
			alphaNumToPlay = textToPlayLC.substring( 0, x );
		else
			alphaNumToPlay = "";
	  }
	else							// else play the whole string as alphaNum
		alphaNumToPlay = textToPlayLC;


	String audioToPlay = "";
	boolean risingFlag = false;
	int textLen = alphaNumToPlay.length();

	if((textLen == 2 &&
		( Character.isDigit( alphaNumToPlay.charAt( 0 ) ) == true ) &&
		( Character.isDigit( alphaNumToPlay.charAt( 1 ) ) == true )) ||
		(textLen > 2 &&
			( Character.isDigit( alphaNumToPlay.charAt( 0 ) ) == true ) &&
			( Character.isDigit( alphaNumToPlay.charAt( 1 ) ) == true ) &&
			( Character.isDigit( alphaNumToPlay.charAt( 2 ) ) == false )))
	  {	// Play the 2 digit ulaw file
		audioToPlay = "<audio src=\"../../prompts/" + alphaNumToPlay.substring(0,2)
			+ ".ulaw\">" + alphaNumToPlay.substring(0,2) + "</audio>";;
		alphaNumToPlay = alphaNumToPlay.substring(2);
	  }
	else if((textLen > 2) &&
		( Character.isDigit( alphaNumToPlay.charAt( 0 ) ) == true ) &&
		( Character.isDigit( alphaNumToPlay.charAt( 1 ) ) == true ) &&
		( Character.isDigit( alphaNumToPlay.charAt( 2 ) ) == true ))
			risingFlag = true;

	String letterPromptClose;
	textLen = alphaNumToPlay.length();

	for( int i = 0; i < textLen; i++ )
	{
		if(risingFlag)
		  {
			letterPromptClose = "-rising.ulaw\">";
			risingFlag = false;
		  }
		else if( i == ( textLen - 1 ) )
		  {
			letterPromptClose = "-falling.ulaw\">";
		  }
		else
		  {
			letterPromptClose = "-neutral.ulaw\">";
		  }

		char ch = alphaNumToPlay.charAt( i );
		if( ch == '\'')
		{
			audioToPlay =
				audioToPlay +
				"<audio src=\"../../prompts/apostrophe.ulaw\">" +
				"apostrophe</audio>";
		}
		else if( ch == '-')
		{
			audioToPlay =
				audioToPlay +
				"<audio src=\"../../prompts/hyphen.ulaw\">" +
				"hyphen</audio>";
		}
		else if( ( ( '0' <= ch ) && ( ch <= '9' ) ) ||
			( ( 'a' <= ch ) && ( ch <= 'z' ) ) )
		{
			audioToPlay =
				audioToPlay +
				"<audio src=\"../../prompts/" +
				ch +
				letterPromptClose +
				ch +
				"</audio>";
		}
	}
	if( fractionToPlay != null)
	  {
		audioToPlay = audioToPlay + "<audio src=\"../../prompts/" + fractionToPlay +
			"\">" + fractionText + "</audio>";
	  }
	return audioToPlay;
}
%>
