<?xml version="1.0" encoding="utf-8"?>
<%@page contentType="application/voicexml+xml; charset=UTF-8"%>
<!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
    <!--<property name="timeout" value="15s"/>--> <!-- el tiempo que espera el sistema despues de cada 'prompt' a la espera de tener una respuesta del caller -->

    <!-- The maxage property specifies the maximum acceptable age, in seconds, of cached resource. The value is a time interval expressed as an
    unsigned number followed by s for time in seconds; ms for time in milliseconds.
    An unexpired cached file that does not exceed the maximum age will be used; a cached file that exceeds the maximum will be fetched again.-->
    <!-- These properties need to be removed once coding is finished
    <property name="scriptmaxage" value="0s"/>
    <property name="audiomaxstale" value="0s"/>-->
    <property name="datamaxage" value="0s"/>
    <property name="grammarmaxage" value="0s"/>

    <property name="bevocal.voice.name" value="bv_adam_en_us"/>
    <property name="bevocal.maxdialogerrors" value="5" />
    <property name="termchar" value=""/>

    <script src="../javascript/global.js"/>
    <script src="../javascript/json.js"/>
    <script src="../javascript/prompts.js"/>
    <script src="../javascript/configuration.js"/>

    <var name="random"/>

    <link event="repeat">
        <grammar srcexpr="context.paths.grammar + 'Global.gsl#REPEAT'"/>
    </link>

    <link event="mainMenu">
        <grammar srcexpr="context.paths.grammar + 'Global.gsl#MAINMENU'"/>
    </link>

    <link event="doneHere">
        <grammar srcexpr="context.paths.grammar + 'Global.gsl#DONEHERE'"/>
    </link>


    <catch event="repeat">
       <clear/>
       <reprompt/>
    </catch>

    <catch>
        <return eventexpr="_event"/>
    </catch>


    <form id="Init">
        <var name="subcontext"/>
        <block>
            <assign name="context" expr="subcontext"/>
            <assign name="context.vars.comingFrom" expr="'Init'"/>
            <goto next="#CreditCardType" />
        </block>
    </form>


    <form id="CreditCardType" >
        <var name="noinput_count" expr="0"/>
        <var name="nomatch_count" expr="0"/>
        <block>            
            <audio expr="promptPath('creditcardtype01')">
                <value expr="promptValue('creditcardtype01')"/>
            </audio>
        </block>
        <field name="choice">
            <grammar srcexpr="context.paths.grammar + 'CreditCardType.gsl#TYPE'" xml:lang="en-US"/>
            <filled>
                <assign name="context.vars.comingFrom" expr="'CreditCardType'"/>
                <assign name="context.vars.creditcardType" expr="choice"/>
                <goto next="#CreditCardNumber" />
            </filled>
        </field>

        <catch event="noinput">
                <var name="index" expr="(noinput_count == 0)?0:1"/>
                <assign name="noinput_count" expr="noinput_count+1"/>
                <audio expr="promptPath('noinput'+index)">
                    <value expr="promptValue('noinput'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('creditcardtype10')">
                    <value expr="promptValue('creditcardtype10')"/>
                </audio>
                <prompt>
                    <break time="500ms"/>
                </prompt>
                <audio expr="promptPath('creditcardtype01')">
                    <value expr="promptValue('creditcardtype01')"/>
                </audio>
        </catch>
        <catch event="nomatch">
                <var name="index" expr="(nomatch_count == 0)?0:1"/>
                <assign name="nomatch_count" expr="nomatch_count+1"/>
                <audio expr="promptPath('nomatch'+index)">
                    <value expr="promptValue('nomatch'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('creditcardtype10')">
                    <value expr="promptValue('creditcardtype10')"/>
                </audio>
                <prompt>
                    <break time="500ms"/>
                </prompt>
                <audio expr="promptPath('creditcardtype01')">
                    <value expr="promptValue('creditcardtype01')"/>
                </audio>
        </catch>
    </form>


    <form id="CreditCardNumber" >
        <var name="noinput_count" expr="0"/>
        <var name="nomatch_count" expr="0"/>
        <block>
            <audio expr="promptPath('creditcardnumber01')">
                <value expr="promptValue('creditcardnumber01')"/>
            </audio>
        </block>

        <field name="choice">
            <grammar src="builtin:grammar/digits?length=16"/>
            <filled>
                <assign name="context.vars.comingFrom" expr="'CreditCardNumber'"/>
                <assign name="context.vars.creditcardNumber" expr="choice"/>
                <log>CreditCardNumber : <value expr="context.vars.creditcardNumber"/> </log>                
                <goto next="#ConfirmCreditCardNumber" />
            </filled>
        </field>

        <catch event="noinput">
                <var name="index" expr="(noinput_count == 0)?0:1"/>
                <assign name="noinput_count" expr="noinput_count+1"/>
                <audio expr="promptPath('noinput'+index)">
                    <value expr="promptValue('noinput'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('creditcardnumber10')">
                    <value expr="promptValue('creditcardnumber10')"/>
                </audio>
        </catch>
        <catch event="nomatch">
                <var name="index" expr="(nomatch_count == 0)?0:1"/>
                <assign name="nomatch_count" expr="nomatch_count+1"/>
                <audio expr="promptPath('nomatch'+index)">
                    <value expr="promptValue('nomatch'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('creditcardnumber10')">
                    <value expr="promptValue('creditcardnumber10')"/>
                </audio>
        </catch>
    </form>


    <form id="ConfirmCreditCardNumber">
          <var name="noinput_count" expr="0"/>
          <var name="nomatch_count" expr="0"/>
          <var name="counter" expr="0"/>
          <block>
            <assign name="random" expr="randomize(2)"/>
            <audio expr="promptPath('thatwas'+ random)">
                <value expr="promptValue('thatwas'+ random)"/>
            </audio>
            <assign name="counter" expr="0"/>
            <foreach item="digit" array="stringToArray(context.vars.creditcardNumber)">                
                <audio expr="numberPromptPath(digit)">
                    <say-as type="number:ordinal"> <value expr="digit"/></say-as>
                </audio>
                <if cond="counter == 3 || counter == 7 || counter == 11">
                    <prompt>
                        <break time="500ms"/>
                    </prompt>
                </if>
                <assign name="counter" expr="counter+1"/>
            </foreach>
            <prompt>
                <break time="1s"/>
            </prompt>
            <assign name="random" expr="randomize(2)"/>
            <audio expr="promptPath('isright'+ random)">
                <value expr="promptValue('isright'+ random)"/>
            </audio>
          </block>
          <field name="choice">
               <grammar src="builtin:grammar/boolean?y=1;n=2"/>
                 <filled>
                    <assign name="context.vars.comingFrom" expr="'ConfirmCreditCardNumber'"/>
                    <if cond="choice==true">
                        <assign name="random" expr="randomize(3)"/>
                        <audio expr="promptPath('thanks' + random)">
                            <value expr="promptValue('thanks' + random)"/>
                        </audio>
                        <prompt>
                            <break time="1s"/>
                        </prompt>
                        <goto next="#ExpirationDate" />
                    <else/>
                        <assign name="random" expr="randomize(2)"/>
                        <audio expr="promptPath('mymistake'+ random)">
                            <value expr="promptValue('mymistake'+ random)"/>
                        </audio>
                        <prompt>
                            <break time="1s"/>
                        </prompt>
                        <goto next="#CreditCardNumber" />
                    </if>
                 </filled>
          </field>
          
          <catch event="noinput">
                <var name="index" expr="(noinput_count == 0)?0:1"/>
                <assign name="noinput_count" expr="noinput_count+1"/>
                <audio expr="promptPath('noinput'+index)">
                    <value expr="promptValue('noinput'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('ifthatwas')">
                    <value expr="promptValue('ifthatwas')"/>
                </audio>
                <assign name="counter" expr="0"/>
                <foreach item="digit" array="stringToArray(context.vars.creditcardNumber)">
                    <audio expr="numberPromptPath(digit)">
                        <say-as type="number:ordinal"> <value expr="digit"/></say-as>
                    </audio>
                    <if cond="counter == 3 || counter == 7 || counter == 11">
                        <prompt>
                            <break time="500ms"/>
                        </prompt>
                    </if>
                    <assign name="counter" expr="counter+1"/>
                </foreach>
                <audio expr="promptPath('sayyesorno')">
                    <value expr="promptValue('sayyesorno')"/>
                </audio>
          </catch>
          <catch event="nomatch">
                <var name="index" expr="(nomatch_count == 0)?0:1"/>
                <assign name="nomatch_count" expr="nomatch_count+1"/>
                <audio expr="promptPath('nomatch'+index)">
                    <value expr="promptValue('nomatch'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('ifthatwas')">
                    <value expr="promptValue('ifthatwas')"/>
                </audio>
                <assign name="counter" expr="0"/>
                <foreach item="digit" array="stringToArray(context.vars.creditcardNumber)">
                    <audio expr="numberPromptPath(digit)">
                        <say-as type="number:ordinal"> <value expr="digit"/></say-as>
                    </audio>
                    <if cond="counter == 3 || counter == 7 || counter == 11">
                        <prompt>
                            <break time="500ms"/>
                        </prompt>
                    </if>
                    <assign name="counter" expr="counter+1"/>
                </foreach>
                <audio expr="promptPath('sayyesorno')">
                    <value expr="promptValue('sayyesorno')"/>
                </audio>
          </catch>
    </form>


    <form id="ExpirationDate" >
        <var name="noinput_count" expr="0"/>
        <var name="nomatch_count" expr="0"/>
        <block>
            <if cond="context.vars.comingFrom != 'ExpirationDate'" >
                <audio expr="promptPath('expirationdate01')">
                    <value expr="promptValue('expirationdate01')"/>
                </audio>
            <else/>
                <audio expr="promptPath('expirationdate02')">
                    <value expr="promptValue('expirationdate02')"/>
                </audio>
            </if>            
        </block>

        <field name="choice">
            <grammar src="builtin:grammar/date"/>
            <filled>
                <assign name="context.vars.comingFrom" expr="'ExpirationDate'"/>
                <assign name="context.vars.expirationDate" expr="isValidExpDate(choice)"/>
                <log>ExpirationDate : <value expr="context.vars.expirationDate"/> </log>
                <if cond="context.vars.expirationDate == undefined"> <!-- Note: Play special prompt for invalid exp date then do clear grammar vars instead of goto same state-->
                    <goto next="#ExpirationDate" />
                <elseif cond="application.lastresult$.confidence &gt; confirmConfidence" />
                    <goto next="#Last3Digits" />
                <else/>
                    <goto next="#ConfirmExpirationDate" />
                </if>
            </filled>
        </field>

       <catch event="noinput">
                <var name="index" expr="(noinput_count == 0)?0:1"/>
                <assign name="noinput_count" expr="noinput_count+1"/>
                <audio expr="promptPath('noinput'+index)">
                    <value expr="promptValue('noinput'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('expirationdate10')">
                    <value expr="promptValue('expirationdate10')"/>
                </audio>
       </catch>
       <catch event="nomatch">
                <var name="index" expr="(nomatch_count == 0)?0:1"/>
                <assign name="nomatch_count" expr="nomatch_count+1"/>
                <audio expr="promptPath('nomatch'+index)">
                    <value expr="promptValue('nomatch'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('expirationdate10')">
                    <value expr="promptValue('expirationdate10')"/>
                </audio>
       </catch>
    </form>


    <form id="ConfirmExpirationDate">
          <var name="mm" expr="context.vars.expirationDate.substring(4,6)"/>
          <var name="yyyy" expr="context.vars.expirationDate.substring(0,4)"/>
          <var name="noinput_count" expr="0"/>
          <var name="nomatch_count" expr="0"/>
          <block>
                <assign name="random" expr="randomize(2)"/>
                <audio expr="promptPath('thatwas'+ random)">
                    <value expr="promptValue('thatwas'+ random)"/>
                </audio>
                <audio expr="datePromptPath(mm + '-m')">
                    <say-as type="date:m"> <value expr="mm"/></say-as>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="datePromptPath(yyyy + '-y')">
                    <say-as type="date:y"> <value expr="yyyy"/></say-as>
                </audio>
                <prompt>
                    <break time="1s"/>
                </prompt>
                <assign name="random" expr="randomize(2)"/>
                <audio expr="promptPath('isright'+ random)">
                    <value expr="promptValue('isright'+ random)"/>
                </audio>
          </block>
          <field name="choice">
               <grammar src="builtin:grammar/boolean?y=1;n=2"/>
                 <filled>
                   <assign name="context.vars.comingFrom" expr="'ConfirmExpirationDate'"/>
                   <if cond="choice==true">
                        <assign name="random" expr="randomize(3)"/>
                        <audio expr="promptPath('thanks' + random)">
                            <value expr="promptValue('thanks' + random)"/>
                        </audio>
                        <prompt>
                            <break time="1s"/>
                        </prompt>
                        <goto next="#Last3Digits" />
                   <else/>
                        <assign name="random" expr="randomize(2)"/>
                        <audio expr="promptPath('mymistake'+ random)">
                            <value expr="promptValue('mymistake'+ random)"/>
                        </audio>
                        <prompt>
                            <break time="1s"/>
                        </prompt>
                        <goto next="#ExpirationDate" />
                   </if>
                 </filled>
          </field>

          <catch event="noinput">
                <var name="index" expr="(noinput_count == 0)?0:1"/>
                <assign name="noinput_count" expr="noinput_count+1"/>
                <audio expr="promptPath('noinput'+index)">
                    <value expr="promptValue('noinput'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('ifthatwas')">
                    <value expr="promptValue('ifthatwas')"/>
                </audio>
                <audio expr="datePromptPath(mm + '-m')">
                    <say-as type="date:m"> <value expr="mm"/></say-as>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="datePromptPath(yyyy + '-y')">
                    <say-as type="date:y"> <value expr="yyyy"/></say-as>
                </audio>
                <audio expr="promptPath('sayyesorno')">
                    <value expr="promptValue('sayyesorno')"/>
                </audio>
           </catch>
           <catch event="nomatch">
                <var name="index" expr="(nomatch_count == 0)?0:1"/>
                <assign name="nomatch_count" expr="nomatch_count+1"/>
                <audio expr="promptPath('nomatch'+index)">
                    <value expr="promptValue('nomatch'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('ifthatwas')">
                    <value expr="promptValue('ifthatwas')"/>
                </audio>
                <audio expr="datePromptPath(mm + '-m')">
                    <say-as type="date:m"> <value expr="mm"/></say-as>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="datePromptPath(yyyy + '-y')">
                    <say-as type="date:y"> <value expr="yyyy"/></say-as>
                </audio>
                <audio expr="promptPath('sayyesorno')">
                    <value expr="promptValue('sayyesorno')"/>
                </audio>
           </catch>
    </form>


    <form id="Last3Digits" >
        <var name="noinput_count" expr="0"/>
        <var name="nomatch_count" expr="0"/>
        <block>
            <audio expr="promptPath('last3digits01')">
                <value expr="promptValue('last3digits01')"/>
            </audio>
        </block>
        <field name="choice">
            <grammar src="builtin:grammar/digits?length=3"/>
            <filled>
                <assign name="context.vars.comingFrom" expr="'Last3Digits'"/>
                <assign name="context.vars.last3Digits" expr="choice"/>
                <log>Last3Digits : <value expr="context.vars.last3Digits"/> </log>
                <goto next="#ConfirmLast3Digits" />
            </filled>
        </field>

        <catch event="noinput">
                <var name="index" expr="(noinput_count == 0)?0:1"/>
                <assign name="noinput_count" expr="noinput_count+1"/>
                <audio expr="promptPath('noinput'+index)">
                    <value expr="promptValue('noinput'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('last3digits10')">
                    <value expr="promptValue('last3digits10')"/>
                </audio>
        </catch>
        <catch event="nomatch">
                <var name="index" expr="(nomatch_count == 0)?0:1"/>
                <assign name="nomatch_count" expr="nomatch_count+1"/>
                <audio expr="promptPath('nomatch'+index)">
                    <value expr="promptValue('nomatch'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('last3digits10')">
                    <value expr="promptValue('last3digits10')"/>
                </audio>
        </catch>
    </form>


    <form id="ConfirmLast3Digits">
          <var name="noinput_count" expr="0"/>
          <var name="nomatch_count" expr="0"/>          
          <block>
            <assign name="random" expr="randomize(2)"/>
            <audio expr="promptPath('thatwas'+ random)">
                <value expr="promptValue('thatwas'+ random)"/>
            </audio>            
            <foreach item="digit" array="stringToArray(context.vars.last3Digits)">
                <audio expr="numberPromptPath(digit)">
                    <say-as type="number:ordinal"> <value expr="digit"/></say-as>
                </audio>                
            </foreach>
            <prompt>
                <break time="1s"/>
            </prompt>
            <assign name="random" expr="randomize(2)"/>
            <audio expr="promptPath('isright'+ random)">
                <value expr="promptValue('isright'+ random)"/>
            </audio>
          </block>
          <field name="choice">
               <grammar src="builtin:grammar/boolean?y=1;n=2"/>
                 <filled>
                   <assign name="context.vars.comingFrom" expr="'ConfirmLast3Digits'"/>
                   <if cond="choice==true">
                        <assign name="random" expr="randomize(3)"/>
                        <audio expr="promptPath('thanks' + random)">
                            <value expr="promptValue('thanks' + random)"/>
                        </audio>
                        <prompt>
                            <break time="1s"/>
                        </prompt>
                        <goto next="#DigitalSignature" />
                   <else/>
                        <assign name="random" expr="randomize(2)"/>
                        <audio expr="promptPath('mymistake'+ random)">
                            <value expr="promptValue('mymistake'+ random)"/>
                        </audio>
                        <prompt>
                            <break time="1s"/>
                        </prompt>
                        <goto next="#Last3Digits" />
                   </if>
                 </filled>
          </field>
          <catch event="noinput">
                <var name="index" expr="(noinput_count == 0)?0:1"/>
                <assign name="noinput_count" expr="noinput_count+1"/>
                <audio expr="promptPath('noinput'+index)">
                    <value expr="promptValue('noinput'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('ifthatwas')">
                    <value expr="promptValue('ifthatwas')"/>
                </audio>
                <foreach item="digit" array="stringToArray(context.vars.last3Digits)">
                    <audio expr="numberPromptPath(digit)">
                        <say-as type="number:ordinal"> <value expr="digit"/></say-as>
                    </audio>
                </foreach> 
                <audio expr="promptPath('sayyesorno')">
                    <value expr="promptValue('sayyesorno')"/>
                </audio>
          </catch>
          <catch event="nomatch">
                <var name="index" expr="(nomatch_count == 0)?0:1"/>
                <assign name="nomatch_count" expr="nomatch_count+1"/>
                <audio expr="promptPath('nomatch'+index)">
                    <value expr="promptValue('nomatch'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('ifthatwas')">
                    <value expr="promptValue('ifthatwas')"/>
                </audio>
                <foreach item="digit" array="stringToArray(context.vars.last3Digits)">
                    <audio expr="numberPromptPath(digit)">
                        <say-as type="number:ordinal"> <value expr="digit"/></say-as>
                    </audio>
                </foreach>
                <audio expr="promptPath('sayyesorno')">
                    <value expr="promptValue('sayyesorno')"/>
                </audio>
          </catch>
    </form>


    <form id="DigitalSignature" >
        <var name="noinput_count" expr="0"/>
        <var name="nomatch_count" expr="0"/>
        <script> function replaceAllSpaces(data){return data.replace(/ /g,'');}
        </script>
        <block>
            <if cond="context.vars.comingFrom != 'ConfirmDigitalSignature '" >
                <audio expr="promptPath('digitalsignature01')">
                    <value expr="promptValue('digitalsignature01')"/>
                </audio>
            <else/>
                <audio expr="promptPath('digitalsignature02')">
                    <value expr="promptValue('digitalsignature02')"/>
                </audio>
            </if>
        </block>

        <field name="choice">
            <grammar srcexpr="context.paths.grammar + 'DigitalSignature.gsl#DIGITALSIGNATURE'" type="application/x-nuance-gsl" xml:lang="en-US"/>
            <filled>
                <assign name="context.vars.comingFrom" expr="'DigitalSignature'"/>
                <assign name="context.vars.digitalSignature" expr="replaceAllSpaces(choice)"/>
                <log>DigitalSignature : <value expr="context.vars.digitalSignature"/> </log>
                <goto next="#ConfirmDiditalSignature" />
            </filled>
        </field>
        
        <catch event="noinput">
                <var name="index" expr="(noinput_count == 0)?0:1"/>
                <assign name="noinput_count" expr="noinput_count+1"/>
                <audio expr="promptPath('noinput'+index)">
                    <value expr="promptValue('noinput'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('digitalsignature10')">
                    <value expr="promptValue('digitalsignature10')"/>
                </audio>
          </catch>
          <catch event="nomatch">
                <var name="index" expr="(nomatch_count == 0)?0:1"/>
                <assign name="nomatch_count" expr="nomatch_count+1"/>
                <audio expr="promptPath('nomatch'+index)">
                    <value expr="promptValue('nomatch'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('digitalsignature10')">
                    <value expr="promptValue('digitalsignature10')"/>
                </audio>
          </catch>
    </form>


    <form id="ConfirmDiditalSignature">
          <var name="noinput_count" expr="0"/>
          <var name="nomatch_count" expr="0"/>
          <block>
            <assign name="random" expr="randomize(2)"/>
            <audio expr="promptPath('thatwas'+ random)">
                <value expr="promptValue('thatwas'+ random)"/>
            </audio>
            <foreach item="numLetter" array="stringToArray(context.vars.digitalSignature)">
                   <if cond="!isNaN(numLetter)">
                        <audio expr="numberPromptPath(numLetter)">
                            <say-as type="number:ordinal"> <value expr="numLetter"/></say-as>
                        </audio>                        
                   <else/>
                        <audio expr="letterPromptPath(numLetter)">
                            <value expr="promptValue(numLetter)"/>
                        </audio>
                   </if>
                   <prompt>
                        <break time="500ms"/>
                   </prompt>
            </foreach>
            <prompt>
                <break time="1s"/>
            </prompt>
            <assign name="random" expr="randomize(2)"/>
            <audio expr="promptPath('isright'+ random)">
                <value expr="promptValue('isright'+ random)"/>
            </audio>
          </block>
          <field name="choice">
               <grammar src="builtin:grammar/boolean?y=1;n=2"/>
                 <filled>
                   <assign name="context.vars.comingFrom" expr="'ConfirmDiditalSignature'"/>
                   <if cond="choice==true">
                        <assign name="random" expr="randomize(3)"/>
                        <audio expr="promptPath('thanks' + random)">
                            <value expr="promptValue('thanks' + random)"/>
                        </audio>
                        <prompt>
                            <break time="1s"/>
                        </prompt>
                        <goto next="#SubmitPayment" />
                   <else/>
                        <assign name="random" expr="randomize(2)"/>
                        <audio expr="promptPath('mymistake'+ random)">
                            <value expr="promptValue('mymistake'+ random)"/>
                        </audio>
                        <prompt>
                            <break time="1s"/>
                        </prompt>
                        <goto next="#DigitalSignature" />
                   </if>
                 </filled>
          </field>
          
          <catch event="noinput">
                <var name="index" expr="(noinput_count == 0)?0:1"/>
                <assign name="noinput_count" expr="noinput_count+1"/>
                <audio expr="promptPath('noinput'+index)">
                    <value expr="promptValue('noinput'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('ifthatwas')">
                    <value expr="promptValue('ifthatwas')"/>
                </audio>
                <foreach item="numLetter" array="stringToArray(context.vars.digitalSignature)">
                       <if cond="!isNaN(numLetter)">
                            <audio expr="numberPromptPath(numLetter)">
                                <say-as type="number:ordinal"> <value expr="numLetter"/></say-as>
                            </audio>                            
                       <else/>
                            <audio expr="letterPromptPath(numLetter)">
                                <value expr="promptValue(numLetter)"/>
                            </audio>
                       </if>
                       <prompt>
                            <break time="500ms"/>
                       </prompt>
                </foreach>
                <audio expr="promptPath('sayyesorno')">
                    <value expr="promptValue('sayyesorno')"/>
                </audio>
          </catch>
          <catch event="nomatch">
                <var name="index" expr="(nomatch_count == 0)?0:1"/>
                <assign name="nomatch_count" expr="nomatch_count+1"/>
                <audio expr="promptPath('nomatch'+index)">
                    <value expr="promptValue('nomatch'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('ifthatwas')">
                    <value expr="promptValue('ifthatwas')"/>
                </audio>
                <foreach item="numLetter" array="stringToArray(context.vars.digitalSignature)">
                       <if cond="!isNaN(numLetter)">
                            <audio expr="numberPromptPath(numLetter)">
                                <say-as type="number:ordinal"> <value expr="numLetter"/></say-as>
                            </audio>                            
                       <else/>
                            <audio expr="letterPromptPath(numLetter)">
                                <value expr="promptValue(numLetter)"/>
                            </audio>
                       </if>
                       <prompt>
                            <break time="500ms"/>
                       </prompt>
                </foreach>
                <audio expr="promptPath('sayyesorno')">
                    <value expr="promptValue('sayyesorno')"/>
                </audio>
          </catch>
    </form>


    <form id="SubmitPayment" >
       <block>
            <audio expr="promptPath('submitpayment01')">
                <value expr="promptValue('submitpayment01')"/>
            </audio>
            <prompt>
                <break time="1500ms"/>
            </prompt>
            
            <assign name="context.vars.comingFrom" expr="'SubmitPayment'"/>
            <var name="creditcardNumber" expr="context.vars.creditcardNumber"/>
            <var name="expirationDate" expr="context.vars.expirationDate"/>
            <var name="last3Digits" expr="context.vars.last3Digits"/>
            <var name="digitalSignature" expr="context.vars.digitalSignature"/>
            <var name="creditcardType" expr="context.vars.creditcardType"/>
            <var name="Show_id" expr="context.vars.Show_id"/>
            <var name="Show_price" expr="context.vars.Show_price"/>
            <var name="numTickets" expr="context.vars.numTickets"/>
            <var name="Capacity" expr="context.vars.Capacity"/>

            <data name="mydata" srcexpr="context.paths.data + 'SubmitPayment'" namelist="creditcardNumber expirationDate last3Digits digitalSignature creditcardType Show_id Show_price numTickets Capacity"/>
            <var name="result" expr="GetData(mydata)"/>
            <if cond="result == undefined">
              <goto next="#MaxTry" />
            <elseif cond="result.status == 'failure'"/>
              <goto next="#MaxTry" />
            <else/> <!--success-->
              <assign name="context.vars.totalAmount" expr="result.totalAmount"/>
              <assign name="context.vars.CCowner" expr="result.CCowner"/>
              <assign name="context.vars.moduleResult" expr="'success'"/>
              <audio expr="promptPath('submitpayment02')">
                <value expr="promptValue('submitpayment02')"/>
              </audio>
              <prompt>
                <say-as type="currency"><value expr="(context.vars.totalAmount)"/></say-as>
              </prompt>
              <audio expr="promptPath('submitpayment03')">
                <value expr="promptValue('submitpayment03')"/>
              </audio>
              <foreach item="name" array="separateNames(context.vars.CCowner)">
                    <audio expr="namePromptPath(name)">
                        <say-as type="name"> <value expr="name"/></say-as>
                    </audio>
                    <prompt>
                        <break time="250ms"/>
                    </prompt>
              </foreach>
              <prompt>
                <break time="1s"/>
              </prompt>
              <audio expr="promptPath('submitpayment04')">
                <value expr="promptValue('submitpayment04')"/>
              </audio>
              <prompt>
                <break time="2s"/>
              </prompt>
              <goto next="#ModuleReturn" />
            </if>
       </block>
    </form>


    <form id="MaxTry">
        <block>
            <assign name="context.vars.comingFrom" expr="'MaxTry'"/>
            <assign name="context.vars.tries" expr="context.vars.tries + 1"/>
            <if cond="context.vars.tries &gt;= maxTry">
                <assign name="context.vars.moduleResult" expr="'failure'"/>                
                <goto next="#ModuleReturn" />
            <else/>
                <goto next="#Retry" />
            </if>
        </block>
    </form>


    <form id="Retry">
          <var name="noinput_count" expr="0"/>
          <var name="nomatch_count" expr="0"/>
          <block>
            <audio expr="promptPath('retry01')">
                <value expr="promptValue('retry01')"/>
            </audio>
          </block>
          <field name="choice">
               <grammar src="builtin:grammar/boolean?y=1;n=2"/>
                 <filled>
                   <assign name="context.vars.comingFrom" expr="'Retry'"/>
                   <if cond="choice==true">
                      <audio expr="promptPath('sure')">
                           <value expr="promptValue('sure')"/>
                      </audio>
                      <prompt>
                           <break time="1s"/>
                      </prompt>
                      <goto next="#CreditCardType" />
                   <else/>
                      <assign name="context.vars.moduleResult" expr="'goodbye'"/>                      
                      <goto next="#ModuleReturn" />
                   </if>
                 </filled>
          </field>
          <catch event="noinput">
                <var name="index" expr="(noinput_count == 0)?0:1"/>
                <assign name="noinput_count" expr="noinput_count+1"/>
                <audio expr="promptPath('noinput'+index)">
                    <value expr="promptValue('noinput'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('retry10')">
                    <value expr="promptValue('retry10')"/>
                </audio>
          </catch>
          <catch event="nomatch">
                <var name="index" expr="(nomatch_count == 0)?0:1"/>
                <assign name="nomatch_count" expr="nomatch_count+1"/>
                <audio expr="promptPath('nomatch'+index)">
                    <value expr="promptValue('nomatch'+index)"/>
                </audio>
                <prompt>
                    <break time="250ms"/>
                </prompt>
                <audio expr="promptPath('retry10')">
                    <value expr="promptValue('retry10')"/>
                </audio>
          </catch>
    </form>


    <form id="ModuleReturn">        
        <var name="result" expr="context.vars.moduleResult"/>       
        <block>
            <assign name="context.vars.comingFrom" expr="'ModuleReturn'"/>
            <return namelist="result"/>
        </block>
    </form>
</vxml>
