<?xml version="1.0" encoding="utf-8"?>
<!--
//  Copyright (C) 2006 Microsoft Corporation.  All rights reserved.
//  The xml file that describes the finite state machine.
-->
<FiniteStateMachine>
	<FsmModule>
		<!-- Subscriber Dtmf Send Message -->

		<SubmitMessageManager id = "500" firstActivityId="1400">

			<!-- Directory search for submit message menu in directory access -->
			<DirectorySearchManager id="1400" firstActivityId="SelectSearchType" searchPurpose="sendMessage">

				<Menu id="SelectSearchType" minDtmfSize="0" maxDtmfSize="0" dtmfInputValue="option">
					<!-- To make sure that we prompt Composing only once -->
					<Prompt type="statement" condition="GlobalActivityManager:ContactsAccessEnabled OR GlobalActivityManager:DirectoryAccessEnabled" name="tuiComposingVoiceMessage"/>
					<Transition event="noKey" condition="GlobalActivityManager:DirectoryAccessEnabled" action="setSearchTargetToGlobalAddressList" refId="1302"/>
					<Transition event="noKey" condition="(NOT GlobalActivityManager:DirectoryAccessEnabled) AND GlobalActivityManager:ContactsAccessEnabled" action="setSearchTargetToContacts" refId="1301"/>
				</Menu>
				
				<!-- Contact Search Menu -->
				<!-- NOTE: dtmfStopTones=noKey forces the recognizer to honor interDigitTimeout before returning a partial match -->
				<Menu id="1301" minDtmfSize="1" maxDtmfSize="name" dtmfInputValue="name" interDigitTimeout="3" dtmfStopTones="noKey">
					<Condition value="newSearch">
						<Prompt type="statement" name="tuiPersonalContacts"/>
						<Prompt type="statement" name="tuiMessageLastFirstNoEmail"/>
						<Prompt condition="GlobalActivityManager:DirectoryAccessEnabled" type="statement" name="tuiToFindSomeoneInDirectory"/>
						<Prompt type="statement" name="tuiToCancelPressStar"/>
					</Condition>
					<Prompt condition="NOT newSearch" type="statement" name="tuiContinueName" />

					<Transition condition="newSearch" event="*" refId="out-502" action="null" />
					<Transition condition="NOT newSearch" event="*" refId="1301" action="startNewSearch" />
					<Transition event="00" condition="GlobalActivityManager:DirectoryAccessEnabled" refId="1302" action="changeSearchTarget" />
					<Transition event="anyKey" refId="1301" action="searchDirectory" heavyaction="true" />
					<Transition event="resultsLessThanAllowed" refId="1303" action="null"/>
					<Transition event="resultsMoreThanAllowed" refId="1301" action="continueSearch"/>
					<Transition event="noResultsMatched" refId="1326" action="null"/>
					<Transition event="invalidSearchKey" action="handleInvalidSearchKey" refId="1411" />

					<Transition event="adTransientError" action="null" refId="adTransientErrorPrompt" />
				</Menu>
				
				<!-- GAL Search Menu -->
				<!-- NOTE: dtmfStopTones=noKey forces the recognizer to honor interDigitTimeout before returning a partial match -->
				<Menu id="1302" minDtmfSize="1" maxDtmfSize="name" dtmfInputValue="name" interDigitTimeout="2" dtmfStopTones="noKey">
					<Condition value="newSearch">
						<!-- Directory Search -->
						<Prompt type="statement" name="tuiDirectorySearch"/>

						<!-- two different search modes -->
						<Condition value="(secondarySearchMode NE none) AND (primarySearchMode NE secondarySearchMode)">
							<!-- one of the search modes is email, use simplified name wording -->
							<Condition value="(primarySearchMode EQ emailAlias) OR (secondarySearchMode EQ emailAlias)">
								<Prompt condition="(currentSearchMode EQ lastNameFirstName)" type="statement" name="tuiMessageLastFirst" />
								<Prompt condition="(currentSearchMode EQ firstNameLastName)" type="statement" name="tuiMessageFirstLast" />
								<Prompt condition="(currentSearchMode EQ emailAlias)" type="statement" name="tuiMessageEmail" />
							</Condition>
							<!-- only two possible search modes, the different name orderings -->
							<Condition value="NOT((primarySearchMode EQ emailAlias) OR (secondarySearchMode EQ emailAlias))">
								<Prompt condition="(currentSearchMode EQ lastNameFirstName)" type="statement" name="tuiMessageLastFirstFirstLast" />
								<Prompt condition="(currentSearchMode EQ firstNameLastName)" type="statement" name="tuiMessageFirstLastLastFirst" />
							</Condition>              
						</Condition>
						<!-- only one search mode set, or both modes are the same -->
						<Condition value="(secondarySearchMode EQ none) OR (primarySearchMode EQ secondarySearchMode)">
							<Prompt condition="(currentSearchMode EQ lastNameFirstName)" type="statement" name="tuiMessageLastFirstNoEmail" />
							<Prompt condition="(currentSearchMode EQ firstNameLastName)" type="statement" name="tuiMessageFirstLastNoEmail" />
							<Prompt condition="(currentSearchMode EQ emailAlias)" type="statement" name="tuiMessageEmailNoName" />
						</Condition>
					</Condition>
					<Prompt condition = "NOT newSearch" type="statement" name="tuiContinueName" />
					<Prompt type="statement" name="tuiIfYouKnowExtension"/>
					<Prompt type="statement" condition="GlobalActivityManager:ContactsAccessEnabled" name="tuiToSendToContact"/>
					<Prompt condition="newSearch" type="statement" name="tuiToCancelPressStar"/>

					<Transition event="#" refId="1320" action="null" />
					<Transition condition="(secondarySearchMode NE none) AND (primarySearchMode NE secondarySearchMode)" event="##" refId="1302" action="changeSearchMode" />
					<Transition event="00" condition="GlobalActivityManager:ContactsAccessEnabled" refId="1301" action="changeSearchTarget" />
					<Transition condition="newSearch" event="*" refId="out-502" action="null" />
					<Transition condition="NOT newSearch" event="*" refId="1302" action="startNewSearch" />
					<Transition event="anyKey" refId="1302" action="searchDirectory" heavyaction="true" />
					<Transition event="resultsLessThanAllowed" refId="1303" action="null"/>
					<Transition event="resultsMoreThanAllowed" refId="1302" action="continueSearch"/>
					<Transition event="noResultsMatched" refId="1327" action="null"/>
					<Transition event="invalidSearchKey" action="handleInvalidSearchKey" refId="1412" />

					<Transition event="adTransientError" action="null" refId="adTransientErrorPrompt" />
				</Menu>
				
				<!-- play out the results -->
				<Menu id="1303" minDtmfSize="0" maxDtmfSize="0" dtmfInputValue="option">
					<Condition value="(promptindex EQ 1)">
						<Prompt type="statement" name="tuiForUserPress1">
							<Prompt type="name" name="userName"/>
						</Prompt>
					</Condition>
					<Condition value="(promptindex EQ 2)">
						<Prompt type="statement" name="tuiForUserPress2">
							<Prompt type="name" name="userName"/>
						</Prompt>
					</Condition>
					<Condition value="(promptindex EQ 3)">
						<Prompt type="statement" name="tuiForUserPress3">
							<Prompt type="name" name="userName"/>
						</Prompt>
					</Condition>
					<Condition value="(promptindex EQ 4)">
						<Prompt type="statement" name="tuiForUserPress4">
							<Prompt type="name" name="userName"/>
						</Prompt>
					</Condition>
					<Condition value="(promptindex EQ 5)">
						<Prompt type="statement" name="tuiForUserPress5">
							<Prompt type="name" name="userName"/>
						</Prompt>
					</Condition>
					<Condition value="(promptindex EQ 6)">
						<Prompt type="statement" name="tuiForUserPress6">
							<Prompt type="name" name="userName"/>
						</Prompt>
					</Condition>
					<Condition value="(promptindex EQ 7)">
						<Prompt type="statement" name="tuiForUserPress7">
							<Prompt type="name" name="userName"/>
						</Prompt>
					</Condition>
					<Condition value="(promptindex EQ 8)">
						<Prompt type="statement" name="tuiForUserPress8">
							<Prompt type="name" name="userName"/>
						</Prompt>
					</Condition>
					<Condition value="(promptindex EQ 9)">
						<Prompt type="statement" name="tuiForUserPress9">
							<Prompt type="name" name="userName"/>
						</Prompt>
					</Condition>

					<Transition event="noKey" action="anyMoreResultsToPlay" heavyaction="true" refId="1303" />
					<Transition event="noMoreResultsToPlay" action="null" refId="1304" />
					<Transition event="moreResultsToPlay" action="null" refId="1303" />
				</Menu>

				<!-- this menu is for taking input from user for the option he wants to select -->
				<Menu id="1304" minDtmfSize="1" maxDtmfSize="1" dtmfInputValue="option" interDigitTimeout="2">
					<Prompt type="statement" name="tuiNoneCorrect"/>
					<Prompt type="statement" name="tuiToRepeatNames"/>
					
					<Transition event="anyKey" action="validateSearchSelection" heavyaction="true" refId="1303" />
					<Transition event="validSelection" action="null" refId="out-506" />
					<Transition event="invalidSelection" action="null" refId="1410" />
					<!-- The folloiwing events wont be fired in SA anymore. They will be fired only in AA
					<Transition event="phoneNumberNotFound" action="null" refId="out-506" />
				<Transition event="userNotEnabledForUm" action="null" refId="out-506" />
				-->
					<Transition condition="searchTarget EQ personalContacts" event="*" action="continueSearch" refId="1301" />
					<Transition condition="searchTarget EQ globalAddressList" event="*" action="continueSearch" refId="1302" />
					<Transition event="0" action="replayResults" heavyaction="true" refId="1303" />
					<!-- If we have a # in the buffer repeat the results (to avoid the 'number is not valid' message) -->
					<Transition event="#" action="replayResults" heavyaction="true" refId="1303" />
				</Menu>

				 <!-- enter user by extension -->
				<Menu id="1320" minDtmfSize="extension" maxDtmfSize="extension" dtmfInputValue="extension" interDigitTimeout="3">
					<Prompt type="statement" name="tuiMessageExtension"/>

					<!-- lookup user -->
					<Transition event="anyKey" action="searchDirectoryByExtension" heavyaction="true" refId="1320"/>
					<Transition event="resultsLessThanAllowed" action="null" refId="out-506"/>
					<Transition event="noResultsMatched" action="null" refId="1325"/>
					<Transition event="*" action="null" refId="1302"/>
					<Transition event="timeout" condition="NOT IsNull(lastInput)" action="null" refId="1325"/>
				</Menu>	
		 
				<!-- wrong extension entered, or no user matched -->
				<Menu id="1325" minDtmfSize="0" maxDtmfSize="0" dtmfInputValue="option" interDigitTimeout="2">
					<!--The keys entered do not match a recognized name.  -->
					<Prompt type="statement" name="tuiKeysNotName"/>
					<Transition event="noKey" action="null" refId="1320"/>
				</Menu>

				<!-- wrong dtmf map entered, or no user matched from personal contacts menu-->
				<Menu id="1326" minDtmfSize="0" maxDtmfSize="0" dtmfInputValue="option" interDigitTimeout="2">
					<!--The keys entered do not match a recognized name.  -->
					<Prompt type="statement" name="tuiDtmfMapNotName"/>
					<Transition event="noKey" action="startNewSearch" refId="1301"/>
				</Menu>

				<!-- wrong extedtmf mapnsion entered, or no user matched -->
				<Menu id="1327" minDtmfSize="0" maxDtmfSize="0" dtmfInputValue="option" interDigitTimeout="2">
					<!--The keys entered do not match a recognized name.  -->
					<Prompt condition="currentSearchMode NE emailAlias" type="statement" name="tuiDtmfMapNotName"/>
					<!--The keys entered do not match a recognized e-mail alias.  -->
					<Prompt condition="currentSearchMode EQ emailAlias" type="statement" name="tuiKeysNotAlias"/>
					<Transition event="noKey" action="startNewSearch" refId="1302"/>
				</Menu>

				<!-- invalid selection in contact search -->
				<Menu id="1410" minDtmfSize="0" maxDtmfSize="0" dtmfInputValue="option">
					<Prompt type="statement" name="tuiInvalidKeys">
						<Prompt type="text" name="invalidSearchSelection"/>
					</Prompt>
					<Transition event="noKey" action="replayResults" heavyaction="true" refId="1303" />
				</Menu>	

				<!-- invalid search input. User entered key =1,0,* in Contact Search  -->
				<Menu id="1411" minDtmfSize="0" maxDtmfSize="0" dtmfInputValue="option">
					<Transition event="noKey" action="null" refId="1301"/>
					<Prompt type="statement" name="tuiInvalidKeys">
						<Prompt type="digit" name="searchInput"/>
					</Prompt>
				</Menu>

				<!-- invalid search input. User entered key =1,0,* in directory Search  -->
				<Menu id="1412" minDtmfSize="0" maxDtmfSize="0" dtmfInputValue="option">
					<Transition event="noKey" action="null" refId="1302"/>
					<Prompt type="statement" name="tuiInvalidKeys">
						<Prompt type="digit" name="searchInput"/>
					</Prompt>
				</Menu>

				<Menu id="adTransientErrorPrompt" minDtmfSize="0" maxDtmfSize="0" dtmfInputValue="option">
					<Prompt condition="searchTarget EQ personalContacts" type="statement" name="tuiSorryContactsSearchError"/>
					<Prompt condition="searchTarget EQ globalAddressList" type="statement" name="tuiSorryADSearchError"/>
					<Transition condition="searchTarget EQ personalContacts" event="noKey" action="startNewSearch" refId="1301" />
					<Transition condition="searchTarget EQ globalAddressList" event="noKey" action="startNewSearch" refId="1302" />
				</Menu>
			</DirectorySearchManager>

			<!-- cancel out of directory search goes here -->
			<Menu id="502" minDtmfSize="0" maxDtmfSize="0" dtmfInputValue="option">
				<Transition condition="numRecipients LT 1" event="noKey" action="cancelMessage" refId="503"/>
				<Transition condition="numRecipients GT 0" event="noKey" action="null" refId="505"/>
			</Menu>

			<!-- "message cancelled" -->
			<Menu id="503" minDtmfSize="0" maxDtmfSize="0" dtmfInputValue="option">
				<Prompt type="statement" name="tuiMessageCancelled"/>
				<Transition event="noKey" action="null" refId="out-106"/>
			</Menu>

			<!-- "[name] added" -->
			<Menu id="504" minDtmfSize="0" maxDtmfSize="0" dtmfInputValue="option">
				<Prompt type="statement" name="tuiUserAddedToMessage">
					<Prompt type="name" name="userName"/>
				</Prompt>
				<Transition event="noKey" action="null" refId="505"/>
			</Menu>

			<!-- Submit Message Menu -->
			<Menu id = "505" minDtmfSize = "1" maxDtmfSize = "1" dtmfInputValue = "option">
				<Prompt type = "statement" name = "tuiSubmitMessageMenu" />
				<Transition event = "1" action = "null" refId = "510"/>
				<Transition event = "2" action = "null" refId = "1400"/>
				<Transition event = "3" action = "removeRecipient" refId = "505"/>
				<Transition event = "*" action = "cancelMessage" refId = "503"/>
				<Transition event = "0" action = "null" refId = "505"/>
				<Transition event="noRecipients" action="null" refId="1400"/>			
			</Menu>

			<!-- Directory search menu goes here after successfully finding a recipient -->
			<Menu id="506" minDtmfSize="0" maxDtmfSize="0" dtmfInputValue="option">
				<Transition event="noKey" action="addRecipientBySearch" refId="504"/>
				<Transition event="unknownRecipient" action="null" refId="507"/>
			</Menu>

			<!-- Played if the user selected through directory search doesn't have a valid address -->
			<Menu id="507" minDtmfSize="0" maxDtmfSize="0" dtmfInputValue="option">
				<Prompt type="statement" name="tuiUserNotAddedToMessageEmail"/>
				<Transition event="noKey" action="null" refId="1400"/>
			</Menu>
		
			<!-- Recording states for submit message -->

			<!-- At the tone, record your message, then press pound -->
			<Menu id = "510" minDtmfSize = "0" maxDtmfSize = "1" dtmfInputValue = "option">
				<Prompt type = "statement" name = "tuiRecordMessageCue"/>
				<Transition event = "noKey" action = "null" refId = "511"/>
				<Transition event = "#" action = "null" refId = "511"/>
			</Menu>

			<!-- *Beep* -->
			<Record id = "511" dtmfStopTones="#*"  type="message">
				<Transition event = "*" action = "cancelMessage" refId = "503" />
				<Transition event = "anyKey" action = "null" refId = "515" />
				<Transition event = "silence" condition="IsNull(recording)" action = "null" refId = "512" />			
				<Transition event = "silence" condition="NOT IsNull(recording)" action = "null" refId = "515" />			
				<Transition event = "timeout" action = "null" refId = "513" />			
				<Transition event = "userHangup" action = "sendMessage" heavyaction="false" refId = "DisconnectState" />
			</Record>

			<!-- Are you still there? -->
			<Menu id = "512" minDtmfSize = "0" maxDtmfSize = "0" dtmfInputValue = "option">
				<Prompt type = "statement" name = "tuiAreYouThere" />
				<Transition event = "noKey" action = "appendRecording" refId = "510"/>
			</Menu>

			<!-- Recoding too long -->
			<Menu id = "513" minDtmfSize = "0" maxDtmfSize = "0" dtmfInputValue = "option">
				<Prompt type="statement" name="tuiRecordingTooLong"/>
				<Transition event = "noKey" action = "null" refId = "515"/>			
			</Menu>

			<!-- After recording menu -->
			<Menu id = "515" minDtmfSize = "1" maxDtmfSize = "1" dtmfInputValue = "option">
				<Prompt type = "statement" name = "tuiAfterRecordingMenuWithDRMOptions" />
				<Transition event="1" action="null" refId="RecordingAcceptedSubMenu"/>
				<Transition event = "2" action = "null" refId = "516" />
				<Transition event = "3" action = "clearRecording" refId = "510" />
				<Transition event = "4" condition="NOT recordingTimedOut" action = "appendRecording" refId = "518" />
				<Transition event = "4" condition="recordingTimedOut" action = "null" refId = "513" />
				<Transition event = "*" action = "cancelMessage" refId = "503" />			
				<Transition event = "0" action = "null" refId = "515" />			
				<Transition event = "userHangup" action = "sendMessage" heavyaction="false" refId = "DisconnectState" />
			</Menu>

			<!-- Menu choices after user has accepted recording -->
			<Menu id="RecordingAcceptedSubMenu" minDtmfSize="1" maxDtmfSize="1" dtmfInputValue="option">
				<Prompt type = "statement" name = "tuiAfterRecordingAcceptMenuOptionsPreamble" />

				<Condition value="DrmIsEnabled">
					<Prompt condition="(NOT IsSentImportant) AND (NOT MessageMarkedPrivate)" type="statement" name = "tuiAfterRecordingAcceptMenuOptionsWithDRMNIandNP" />
					<Prompt condition="(NOT IsSentImportant) AND MessageMarkedPrivate" type="statement" name = "tuiAfterRecordingAcceptMenuOptionsWithDRMNIandP" />
					<Prompt condition="IsSentImportant AND MessageMarkedPrivate" type="statement" name = "tuiAfterRecordingAcceptMenuOptionsWithDRMHIandP" />
					<Prompt condition="IsSentImportant AND (NOT MessageMarkedPrivate)" type="statement" name = "tuiAfterRecordingAcceptMenuOptionsWithDRMHIandNP" />
				</Condition>
				
				<Condition value="NOT DrmIsEnabled">
					<Prompt condition="NOT IsSentImportant" type="statement" name = "tuiAfterRecordingAcceptMenuOptionsNoDRMNI" />
					<Prompt condition="IsSentImportant" type="statement" name = "tuiAfterRecordingAcceptMenuOptionsNoDRMHI" />
				</Condition>

				<Prompt type = "statement" name = "tuiAfterRecordingAcceptMenuOptionsEnd" />

				<Transition event="#" action="sendMessage" heavyaction="true" refId="517"/>
				<Transition event="1" action="ToggleImportance" refId="PlaySelection"/>
				<Transition event="2" condition = "DrmIsEnabled" action="TogglePrivacy" refId="PlaySelection"/>
				<Transition event="0" action="null" refId="RecordingAcceptedSubMenu"/>
				<Transition event="*" action="ClearSelection" refId="515"/>
			</Menu>

			<!-- Play Selection to user -->
			<Menu id="PlaySelection" minDtmfSize="0" maxDtmfSize="1" dtmfInputValue="option">
				<Prompt condition="MessageMarkedPrivate AND IsSentImportant" type="statement" name="tuiPrivateAndHighImp" />
				<Prompt condition="MessageMarkedPrivate AND (NOT IsSentImportant)" type="statement" name="tuiPrivateAndNormalImp" />
				<Prompt condition="(NOT MessageMarkedPrivate) AND IsSentImportant" type="statement" name="tuiNotPrivateAndHighImp" />
				<Prompt condition="(NOT MessageMarkedPrivate) AND (NOT IsSentImportant)" type="statement" name="tuiNotPrivateAndNormalImp" />
				<Transition event="#" action="sendMessage" heavyaction="true" refId="517"/>
				<Transition event="noKey" action="null" refId="RecordingAcceptedSubMenu"/>
			</Menu>

			<!-- Replay recording -->
			<Menu id = "516" minDtmfSize = "0" maxDtmfSize = "0" dtmfInputValue = "option">
				<Prompt type = "tempwave" name = "recording" />
				<Transition event = "noKey" action = "null" refId = "515"/>
			</Menu>

			<!-- "Message Sent". Go back to the main menu  -->
			<Menu id = "517" minDtmfSize = "0" maxDtmfSize = "0" dtmfInputValue = "option">
				<Prompt type = "statement" name = "tuiMessageSent" />
				<Transition event = "noKey" action = "null" refId = "out-106" />
			</Menu>

			<!-- Continue recording -->
			<Menu id = "518" minDtmfSize = "0" maxDtmfSize = "0" dtmfInputValue = "option">
				<Prompt type = "statement" name = "tuiContinueRecording"/>
				<Transition event = "noKey" action = "null" refId = "511" />
			</Menu>

			<!-- Dummy State for disconnect -->
			<Menu id = "DisconnectState">
				<Transition event = "noKey" action="disconnect" refId="DisconnectState"/>
			</Menu>
		</SubmitMessageManager>
	</FsmModule>
</FiniteStateMachine>




