<?xml version="1.0" encoding="UTF-8"?>
<vxml version = "2.1" >

<link next="#MainMenu">
        <grammar type="text/gsl">[main back return]</grammar>
</link> 

  <var name ="personname" expr="new Array('tank','doris','keith')"/>
  
  <script>
    storyID =0;
    story = new Array(
    "You're welcome!",
    "Doris locked, that's why I had to knock! ",
    "Keith me and find out.");
    function tellName(number)
    {
    return personname[number];
    }
    function tellStory(number){
    return story[number];
    }
  </script>
  
  <form id="MainMenu">
    <block>
      <prompt bargein="false">
        Hi dear friend. This is a system telling knock knock jokes.  A typical knock knock joke is like this:
        
        Jack says: Knock Knock!
        Tom says: Who's there?
        Jack says: Police. 
        Tom says: Police who?
        Jack says: Police let us in; it's cold out here!
        
        So, would you like to have a try?
</prompt>
    </block>

    <field name="YesOrNo">

      <grammar type="text/gsl">
        <![CDATA[[
              [no negtive] {<YesOrNo "quit">}
              [continue yes sure (of course) try] {<YesOrNo "continue">}
            ]]]>
        </grammar>

        <noinput>
        <prompt>
            I did't hear anything. Please say yes to play and say no to quit.
          </prompt>
        <reprompt/>
        </noinput>

        <nomatch>
        <prompt>
            I did't recognize that.  Please try again.
        </prompt>
          <reprompt/>
        </nomatch>   
       
    </field>
<filled>
      <if cond="YesOrNo == 'quit'">
      <goto next="#F2"/>
      <elseif cond="YesOrNo == 'continue'"/>
      <goto next="#F3"/>
      </if>
</filled>
  </form>


  <form id="F2">
	<block>
    <prompt>
	I'm sorry to hear that. I'll improve myself in the future. See you later!
    </prompt>
	</block>
  </form>

  <form id="F3">
    <field name="BackToMain">
      <grammar type="text/gsl">
        <![CDATA[
    ;Match one of the enclosed terms
    [
      ;Each line is recognized as a separate term
      ;Terms are separated by a space
      
      ;kenny
     
      ;Match either terrance or phillip
      ;Square brackets are the same as OR
      
      ;Parentheses require all of the enclosed terms to be matched
      [who there hello]{<BackToMain "continue">}
      (who's there){<BackToMain "continue">}
      [negtive quit] {<BackToMain "quit">}
    ]
  ]]>
      </grammar> 
    <prompt>
	knock knock!
    </prompt>
        <nomatch>
          I said knock knock, it's your turn now. You can say who' there.
        </nomatch> 
      <noinput>
        I am sorry, I didn't hear anything.  I said knock knock.
      </noinput>
    </field>
        <filled>
          <if cond="BackToMain == 'quit'">
            <goto next="#F2"/>
            <elseif cond="BackToMain == 'continue'"/>
            <goto next="#F4"/>
          </if>
        <!-- no way this will get hit -->
        </filled>
  </form>


<form id="F4">
    <field name="BackToMain">
      <grammar type="text/gsl">
        <![CDATA[
    ;Match one of the enclosed terms
    [
      ;Each line is recognized as a separate term
      ;Terms are separated by a space
      
      ;kenny
     
      ;Match either terrance or phillip
      ;Square brackets are the same as OR
      
     
      ;Parentheses require all of the enclosed terms to be matched
      (doris who){<BackToMain "doris">}
      (keith who){<BackToMain "keith">}
      (tank who){<BackToMain "tank">}
      [negtive quit] {<BackToMain "quit">}
    ]
  ]]>
      </grammar> 

    <prompt>
      <value expr="tellName(storyID)"/>
    </prompt>
      <noinput>
        I am sorry, I didn't hear anything. I said <value expr="tellName(storyID)"/>.
      </noinput>
        <nomatch>
          I can't recognize you. Say <value expr="tellName(storyID)"/> who please.
        </nomatch>   
    </field>
        <filled>
          <if cond="BackToMain == 'quit'">
            <goto next="#F2"/>
            <elseif cond="BackToMain == tellName(storyID)"/>
            <goto next="#F5"/>
            <else/>
            <prompt>
              Wrong answer, say again please!
            </prompt>
            <goto next="#F4"/>
          </if>
        </filled>

  </form>

<form id="F5">
    <field name="BackToMain">
      <grammar type="text/gsl">
        <![CDATA[
    ;Match one of the enclosed terms
    [
      ;Each line is recognized as a separate term
      ;Terms are separated by a space
     
     
      ;Match either terrance or phillip
      ;Square brackets are the same as OR
       [no negtive quit] {<BackToMain "quit">}
       [more yes] {<BackToMain "continue">}
       
       (more jokes) {<BackToMain "continue">}
      ;Parentheses require all of the enclosed terms to be matched
    ]
  ]]>
      </grammar> 
    <prompt>
      <value expr="tellStory(storyID)"/>
    </prompt>
      <prompt bargein="false">Interesting, isn't it? I have more jokes to tell. Do you wanna try that again?</prompt>
        <noinput>
          <prompt>Sorry I can't hear. Say yes to hear more jokes, say no to quit.</prompt>
        </noinput>
      <nomatch>
        Sorry, I can't understand. Say yes to hear more jokes, say no to quit.
        </nomatch>
    </field>
        <filled>
          <script>
            storyID=storyID+1;
            storyID = storyID%3;
          </script>
          <if cond="BackToMain == 'quit'">
            <goto next="#F2"/>
            <elseif cond="BackToMain == 'continue'"/>
            <goto next="#F3"/>
          </if>
        </filled>
  </form>
</vxml>



