<scenario begin="first_screen">

    <screen type="Sum" sum="sum-orange"/>

    <!--  Start Vodafone screen -->
    <screen type="selector/button" title="Factura Vodafone" id="first_screen">
        <fields>
            <selector-field id="type" title="Type">
                <items type="static">
                    <item value="1" title="PERSOANA&lt;br&gt;FIZICA"/>
                    <item value="2" title="PERSOANA&lt;br&gt;JURIDICA"/>
                </items>
            </selector-field>
        </fields>
        <actions>
            <action type="Next" title="INAINTE">
                <if condition="type == 1"> 
                    <then>
                        <clear keys="type"/>
                        <goto target="input_pf_phone"/>
                    </then>
                        
                </if>
                <if condition="type == 2"> 
                    <then>
                        <clear keys="type"/>
                        <goto target="input_pj_phone"/>
                    </then>
                        
                </if>
            </action>
            <action type="Prev" title="INAPOI">
                <goto target="previos"/>
            </action>
            <action type="Exit" title="MENIU">
                <goto target="exit"/>
            </action>            
        </actions>
    </screen>
	
    <!--  Start Vodafone PF screen -->
    <screen type="numeric/info" title="INTRODUCETI NUMARUL DE TELEFON" id="input_pf_phone" sound="input_phone.mp3">
        <fields>
            <text-field id="id1" title="NUMARUL DE TELEFON" max-len="10" prefix="07" keyboard="Digital">
                <validator type="regex">
                    <rules>
                        <rule regex="^\d{10}$"/>
                    </rules>
                </validator>
            </text-field>            
        </fields>
        <actions>
            <action type="Next" title="INAINTE">
                <modify src-key="id1" t-key="^.*$" v-key="id2" t-key-title="^.*$" v-key-title="CONFIRMATI NUMARUL DE TELEFON"/>
                <goto target="pf_confirm"/>                
            </action>
            <action type="Prev" title="INAPOI">
                <goto target="first_screen"/>
            </action>
            <action type="Exit" title="MENIU">
                <goto target="exit"/>
            </action>
        </actions>
    </screen>
	
    <screen type="confirm/comunal" title="VERIFICARE NUMAR" id="pf_confirm" sound="validate_phone.mp3" message="&lt;html&gt;&lt;b&gt;&lt;center&gt;&lt;br&gt;Va rugam verificati datele introduse.&lt;br&gt;&lt;br&gt;Apasati CONFIRMARE pentru a avansa.&lt;br&gt;Apasati INAPOI pentru a corecta numarul.">
	<fields list="id1"/>
        <actions>
            <action type="Next" title="CONFIRMARE">
                <online-request type="default" function="" params="id1,id2">
                    <actions>
                        <action type="success">
                            <modify src-key="id1" t-value-title="^(\d{4})(\d{3})(\d{3})$" v-value-title="$1 $2 $3"/>
                            <modify src-key="disp1" t-key-title="^.*$" v-key-title="TOTAL DE PLATA" t-value-title="^(.*)$" v-value-title="$1 RON"/>
                            <modify src-key="id1" t-key-title="^.*$" v-key-title="NUMARUL DE TELEFON"/>
                            <goto target="pf_pay"/>
                        </action>
                        <action type="error">
                            <dialog type="Info" title="Error" message="Numarul/Codul nu a fost gasit" timeout="10" default="okay">
                                <actions>
                                    <action type="okay" title="OK">
                                        <goto target="input_pf_phone"/>
                                    </action>                                            
                                </actions>
                            </dialog>                            
                        </action>
                        <action type="exception">
                            <dialog type="Info" title="Error" message="Nu exista conexiune cu serverul" timeout="10" default="okay">
                                <actions>
                                    <action type="okay" title="OK">
                                        <cancel/>
                                    </action>                                            
                                </actions>
                            </dialog>
                        </action>
                    </actions>
                </online-request>                
            </action>
            <action type="Prev" title="INAPOI">
                <goto target="previos"/>	                
            </action>
            <action type="Exit" title="MENIU">
                <goto target="exit"/>
            </action>
        </actions>
    </screen>
	
	
    <screen type="Void"  id="pf_pay">
        
        <actions>
            <action type="Next" title="NEXT">
                <if condition="is-not-null #back">
                    <then>
                        <modify src-key="id1" t-value-title="^(\d{4})( )(\d{3})( )(\d{3})$" v-value-title="$1$3$5"/>
                        <clear keys="#back"/>
                        <goto target="input_pf_phone"/>
                    </then>
                    <else>
                        <set key="#back" value="1"/>
                        <goto target="pay"/>
                    </else>
                </if>
            </action>
        </actions>
    </screen>
	
	
    <!--  Start Vodafone PJ screen -->
    <screen type="group/comunal" title="INTRODUCETI NUMARUL DE TELEFON" id="input_pj_phone" sound="input_phone.mp3">
        <fields>
            <text-field id="id1" title="NUMARUL DE TELEFON" max-len="10" prefix="07" keyboard="Digital">
                <validator type="regex">
                    <rules>
                        <rule regex="^\d{10}$"/>
                    </rules>
                </validator>
                <formatter type="regex">
                    <rules default="**** *** ***" by-step="true"/>
                </formatter>
            </text-field>            
        </fields>
        <actions>
            <action type="Next" title="INAINTE">
                <goto target="input_code"/>                
            </action>
            <action type="Prev" title="INAPOI">
                <goto target="first_screen"/>
            </action>
            <action type="Exit" title="MENIU">
                <goto target="exit"/>
            </action>
        </actions>
    </screen>
	
	
    <screen type="group/comunal" title="INTRODUCETI CODUL DE ABONAT" id="input_code" sound="input_payment_indent.mp3">
        <fields>
            <text-field id="id2" title="Codul de Abonat" max-len="19" keyboard="Digital">
                <validator type="regex">
                    <rules>
                        <rule regex="^\d{6,19}$"/>
                    </rules>
                </validator>
                <formatter type="regex">
                    <rules default="*** *** *** *** ***" by-step="true"/>
                </formatter>
            </text-field>
        </fields>
        <actions>
            <action type="Next" title="INAINTE">
                <goto target="pj_confirm"/>                
            </action>
            <action type="Prev" title="INAPOI">
                <goto target="input_pj_phone"/>
            </action>
            <action type="Exit" title="MENIU">
                <goto target="exit"/>
            </action>
        </actions>
    </screen>
	
	
    <screen type="confirm/comunal" title="VERIFICARE DATE" id="pj_confirm" sound="validate_phone.mp3" message="&lt;html&gt;&lt;b&gt;&lt;center&gt;&lt;br&gt;Va rugam verificati datele introduse.&lt;br&gt;&lt;br&gt;Apasati CONFIRMARE pentru a avansa.&lt;br&gt;Apasati INAPOI pentru a corecta numarul.">
	<fields list="id1,id2"/>
        <actions>
            <action type="Next" title="CONFIRMARE">
                <online-request type="default" function="" params="id1,id2">
                    <actions>
                        <action type="success">
                            <modify src-key="id1" t-value-title="^(\d{4})(\d{3})(\d{3})$" v-value-title="$1 $2 $3"/>
                            <modify src-key="id2" t-value-title="^(\d{3})(\d{3})(\d{3})$" v-value-title="$1 $2 $3"/>
                            <modify src-key="disp1" t-key-title="^.*$" v-key-title="TOTAL DE PLATA" t-value-title="^(.*)$" v-value-title="$1 RON"/>
                            <modify src-key="id1" t-key-title="^.*$" v-key-title="NUMARUL DE TELEFON"/>
                            <modify src-key="id2" t-key-title="^.*$" v-key-title="CODUL DE ABONAT"/>
                            <goto target="pj_pay"/>
                        </action>
                        <action type="error">
                            <dialog type="Info" title="Error" message="Numarul/Codul nu a fost gasit" timeout="10" default="okay">
                                <actions>
                                    <action type="okay" title="OK">
                                        <goto target="input_pj_phone"/>
                                    </action>                                            
                                </actions>
                            </dialog>                            
                        </action>
                        <action type="exception">
                            <dialog type="Info" title="Error" message="Nu exista conexiune cu serverul" timeout="10" default="okay">
                                <actions>
                                    <action type="okay" title="OK">
                                        <cancel/>
                                    </action>                                            
                                </actions>
                            </dialog>
                        </action>
                    </actions>
                </online-request>                
            </action>
            <action type="Prev" title="INAPOI">
                <goto target="previos"/>	                
            </action>
            <action type="Exit" title="MENIU">
                <goto target="exit"/>
            </action>
        </actions>
    </screen>
	
	
    <screen type="Void"  id="pj_pay">
        
        <actions>
            <action type="Next" title="NEXT">
                <if condition="is-not-null #back">
                    <then>
                        <modify src-key="id1" t-value-title="^(\d{4})( )(\d{3})( )(\d{3})$" v-value-title="$1$3$5"/>
                        <modify src-key="id2" t-value-title="^(\d{3})( )(\d{3})( )(\d{3})$" v-value-title="$1$3$5"/>
                        <clear keys="#back"/>
                        <goto target="input_pj_phone"/>
                    </then>
                    <else>
                        <set key="#back" value="1"/>
                        <goto target="pay"/>
                    </else>
                </if>
            </action>
        </actions>
    </screen>
	
</scenario>