<header>
	<var vScrollingLayer>
	<var vAutoScroll>
	<var vTmpOfGeneric>
</header>

<script sc_CancelMessageBox>
</script>

<script sc_StartConfirmMessageBox>
	btnMB_Ok.hide
	btnMB_Yes.show
	btnMB_No.show
    runif vUIres "800_480" 'sprMB_Icon.bmp "dialog_qm.spr"'
    else_runif vUIres "480_800" 'sprMB_Icon.bmp "dialog_qm.spr"'
    else_run 'sprMB_Icon.bmp "ui_igo8/common/dialog_qm.spr"'
</script>

<script sc_StartCustomMessageBox>
	btnMB_Ok.hide
	btnMB_Yes.show
	btnMB_No.show
    runif vUIres "800_480" 'sprMB_Icon.bmp "dialog_qm.spr"'
    else_runif vUIres "480_800" 'sprMB_Icon.bmp "dialog_qm.spr"'
    else_run 'sprMB_Icon.bmp "ui_igo8/common/dialog_qm.spr"'
</script>

<script sc_StartInfoMessageBox>
	btnMB_Ok.show
	btnMB_Yes.hide
	btnMB_No.hide
    runif vUIres "800_480" 'sprMB_Icon.bmp "dialog_em.spr"'
    else_runif vUIres "480_800" 'sprMB_Icon.bmp "dialog_em.spr"'
    else_run 'sprMB_Icon.bmp "ui_igo8/common/dialog_em.spr"'
	0 playsound "!button"
</script>

;-----------------------------------------------------------------
<script sc_Media_Video_RemotePause>
</script>
;-----------------------------------------------------------------

<script sc_ShowMessageBox>
	MODEL_EXISTS "oasis.media" "vTmpOfGeneric"
	runif vTmpOfGeneric 1 'run sc_Media_Video_RemotePause'
	bDialogBoxVisible.set 1
	ui_DisableLayer.show
	ui_MessageBox.show
	txtMB_Msg.set vMSGBOXTXT

	run sc_DisableGestures 0

	runif vMSGBOXTYPE 0 sc_StartInfoMessageBox
	runif vMSGBOXTYPE 1 sc_StartConfirmMessageBox
	runif vMSGBOXTYPE 2 sc_StartCustomMessageBox
</script>

<script sc_HideMessageBox>
	bDialogBoxVisible.set 0
	ui_DisableLayer.hide
	ui_MessageBox.hide
	vCustomMessageBox2ndLine.set ""
	runif vUseGestures 1 sc_UseGestures

	DEINITMESSAGEBOX
</script>

<script sc_findpath_error>
  INITMESSAGEBOX 0 $1
  termif $2 1
  runif %route.itiner.list.isempty 1 sc_DeleteIsolatedWaypoint
</script>

<script sc_DeleteIsolatedWaypoint>
    1 navigation.waypoints.ignore_startfromgps_waypoint 0
    goto 2
    2 run sc_DeleteIsolatedWaypoint_listforeach
    vtmp.boolexpr "navigation.waypoints.has_isolated_waypoint&navigation.waypoints.list.size > 1&!ui.vDeleteError"
    vtmp.dropmodel
    runif vtmp 1 'goto 2 sc_DeleteIsolatedWaypoint'
</script>

<script sc_DeleteIsolatedWaypoint_listforeach>
    vDeleteError.set 0
    ntmp.set 0
    vWaypointslistindex.set -1
	  LIST_FOREACH "navigation.waypoints.list" 'runif %*.as_start_isolated 0 \'\', else_runif %*.as_end_isolated 1 \'incval "ntmp"\', runif ntmp 1 \'vWaypointslistindex.set $i, ntmp.set 2\''
    navigation.waypoints.list.setcurrent vWaypointslistindex
    runif vWaypointslistindex > 0 'navigation.waypoints.delete_current'
    else_run 'vDeleteError.set 1'
    runif vWaypointslistindex -1 'deleteroute'
</script>

<script sc_KeyCandidateSelected>
	ui_key_candidates.hide
</script>
;****************************************************************************************************************

<state st_About>
	<uselayer ui_Header2/>
	<uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_About/>

	<script init>
		Title.SET "About"
	</script>
</state>

;****************************************************************************************************************

<script sc_ScrollingLayerInit>
	vScrollingLayer.SET $1
	vAutoScroll.SET $2
	SCROLL_Y vScrollingLayer 0 1 0
	REGISTER_SCROLL vScrollingLayer
	runif vAutoScroll 1 '100 SCROLL_Y_AUTO vScrollingLayer vXTML_Y_target vXTML_Y_time _0.3'
</script>

<script sc_ScrollingLayerDone>
	DEREGISTER_SCROLL vScrollingLayer
	runif vAutoScroll 1 'TERM sc_ScrollingLayerInit, SCROLL_Y vScrollingLayer 0 1 0'
</script>

;****************************************************************************************************************

<state st_AboutMaps>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_AboutMaps/>

	<script init>
		Title.SET "Maps"
		LICENCE_ATTACHMODEL lbAM_Maps 1
	</script>
	
	<script exit>
		lbAM_Maps.SETSELECTION 0
	</script>
</state>

<state st_AboutMapDetails>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_AboutMapDetails/>

	<script init>
	    Title.SET "Map Details"
    	HASFILEINFO lbAM_Maps vTmp
	    runif vTmp 0 'PREVSTATE'
	    else_run 'SHOWFILEINFO lbAM_Maps sprAMD_MapLogo txtAMD_MapName txtAMD_MapSource txtAMD_MapFile txtAMD_MapSize txtAMD_MapDetail1 txtAMD_MapDetail2 txtAMD_MapDetail3 txtAMD_MapDetail4'
	</script>
</state>

<state st_AboutLicenses>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_AboutLicenses/>

	<script init>
		Title.SET "Licenses"
		other.license.list.index 0
	</script>
</state>

;****************************************************************************************************************

<state st_AboutCredits>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ScrollButtons/>
	<uselayer ui_CreditsScreenXHTML/>

	<script init>
		Title.SET "Credits"
		run sc_ScrollingLayerInit ui_CreditsScreenXHTML 1
	</script>

	<script done>
	    run sc_ScrollingLayerDone
	</script>
</state>

;****************************************************************************************************************

<state st_AboutLegal>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ScrollButtons/>
	<uselayer ui_LegalScreenXHTML/>

	<script init>
		Title.SET "EULA"
		run sc_ScrollingLayerInit ui_LegalScreenXHTML 1
	</script>
	
	<script done>
	    run sc_ScrollingLayerDone
	</script>
</state>

;****************************************************************************************************************

<state st_AboutUpdate>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ScrollButtons/>
	<uselayer ui_UpdateScreenXHTML/>

	<script init>
		Title.SET "Get updates"
		run sc_ScrollingLayerInit ui_UpdateScreenXHTML 1
	</script>
	
	<script done>
	    run sc_ScrollingLayerDone
	</script>
</state>

;****************************************************************************************************************

<state st_AboutSafety>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ScrollButtons/>
	<uselayer ui_SafetyScreenXHTML/>

	<script init>
		Title.SET "Safety Instructions"
		run sc_ScrollingLayerInit ui_SafetyScreenXHTML 1
	</script>
	
	<script done>
		run sc_ScrollingLayerDone
	</script>
</state>


<script sc_safemode_on>
	safemode_layer.show
	runifnot vActiveState "st_NavigateMap" 'run sc_ReturnToMap, run sc_FollowOn'
</script>

<script sc_safemode_off>
	safemode_layer.hide
</script>

 <script sc_notsafewarning>
	term sc_notsafewarning_hide
	INITMESSAGEBOX 0 "Drive safely!" 'term sc_notsafewarning_hide'
	1 run sc_notsafewarning_hide
</script>

<script sc_notsafewarning_hide>
	70 run sc_HideMessageBox
</script>

<script sc_contactnavi_start>
    run sc_EmptyStateQueue st_NavigateMap 
    NEXTSTATE st_ArrowPlace
</script>

<script sc_contactnavi_error>
    INITMESSAGEBOX 0 "Cannot find contact or address."
</script>

;***************************************** BT ******************************************

<script sc_drive_carefully_init>
    run sc_drive_carefully_show
    runif vUiRes "240_240" 'vScrollingLayer.SET ui_drive_carefully_xhtml'
    btn_dc_agree.hide
    KEY "RETURN"
    KEY "REC"
    KEY "UP"
    KEY "DOWN"
</script>

<script sc_drive_carefully_show>
	ui_drive_carefully_xhtml.z 100005
	btn_dc_agree.z 100205
	disable_layer_dcare.z 100200
	ui_drive_carefully_btn.z 1000000
	ui_drive_carefully_bg.z 100004   

    disable_layer_dcare.show
	ui_drive_carefully_bg.show
	ui_drive_carefully_xhtml.show
	ui_drive_carefully_btn.show
	
    100 btn_dc_agree.show
</script>

<script sc_drive_carefully_close>
  disable_layer_dcare.hide
  ui_drive_carefully_xhtml.hide
  ui_drive_carefully_btn.hide
  ui_drive_carefully_bg.hide
  exec "other.disclamer_closed"
</script>

<script sc_accept_drive_carefully>
    vDriveCarefully_show.set 0
	run sc_drive_carefully_close
</script>

<script sc_UseGestures>
	GESTURE "IG6" 'run sc_ReturnToMap' 1
	GESTURE "AG0" 'run sc_GoTo_MainMenu'
	vUseGestures.SET 1
</script>

; $1 - Clear global flag 'vUseGestures' as well?
<script sc_DisableGestures>
	GESTURE "IG6" ''
	GESTURE "AG0" ''
	runif $1 1 'vUseGestures.SET 0'
</script>

; =================== Simple Location API / SMS Buddy ===================

<script sc_OnIncomingPosition>
  vTmp.combined_textmodel "$other.fleet_mgmt.sender$: $other.fleet_mgmt.message:Sent Position$"
  vTmp.dropmodel
  vTmp2.combined_textmodel "$other.fleet_mgmt.sender$: $other.fleet_mgmt.message:Sent Position$ \n$other.fleet_mgmt.address:Unknown address.$"
  vTmp2.dropmodel
  mydata.history.create_item %other.fleet_mgmt.position_lat %other.fleet_mgmt.position_lon vTmp vTmp2

  runif %other.fleet_mgmt.source "SMS" 'run sc_OnIncomingSmsPosition'
  else_run 'run sc_OnIncomingExtPosition'
</script>
  
<script sc_OnIncomingSmsPosition>
  vTmp.combined_textmodel "Position received from $other.fleet_mgmt.sender$.\n$other.fleet_mgmt.message$: $other.fleet_mgmt.address:Unknown address$.\nDo you want to check it now?"
  vTmp.dropmodel
  INITMESSAGEBOX 2 vTmp 'run sc_OnIncomingPosAccept' 'run sc_OnIncomingPosCancel'
</script>
  
<script sc_OnIncomingExtPosition>
  vTmp.combined_textmodel "Position received from $other.fleet_mgmt.sender$.\n$other.fleet_mgmt.address:Unknown address$.\nDo you want to check it now?"
  vTmp.dropmodel
  INITMESSAGEBOX 2 vTmp 'run sc_OnIncomingPosAccept' 'run sc_OnIncomingPosCancel'
</script>

<script sc_OnIncomingPosAccept>
  SELECT_HISTORY 0
  map.MOVECURSORTOSELECTEDITEM
	nPlaceStateMode.SET 0
	NEXTSTATE st_Place
</script>

<script sc_OnIncomingPosCancel>
  INITMESSAGEBOX 0 "The received position has been saved to your History."
</script>

<observer obs_onincomingposition event="fleet_mgmt_incoming_position" onchange='run sc_OnIncomingPosition' start="NO_TRIGGER">

