<header>
	<var vSelectColorProfileMode= 0>
	<var saved_vUturn_penalty1>
	<var saved_vGPSPositionToRoad permanent>
	<var vAdvSettingTodayState= 0>
	<var saved_bUnpaved=0>
	<var saved_bHighway=0>
	<var saved_bFerry=0>
	<var saved_bUTurn=0>
	<var saved_bToll=0>
	<var saved_bTax=0>
	<var saved_bSpecialRoad=0>
	<var saved_vCrossBorderRoutes=0>
	<var saved_bCarPool=0>
	<var saved_nVehicle>
	<var saved_vRouteType>
	<var saved_ZoomMode_3D>
	<var saved_ZoomMode_2D>
	<var bFirstStart=0>
	<var saved_OsVolume permanent>
	<var tmpMinMin>
	<var tmpMinMax>
	<var tmpMaxMin>
	<var tmpMaxMax>
	<var vAutoScrollHelp=0 permanent>
	<var vPedestrianWarning_Ignored=0 permanent>
	<var vZoom2DUnit=-1 permanent>
	<var vZoom3DUnit=-1 permanent>
	<var vZoomOverviewUnit=-1 permanent>
	<var vLastZoomLevels>
	<var vLastZoomMin>
	<var vLastZoomMax>
    <var tmpSpeedcamVis registermodel>
    <var tmpSpeedcamAud registermodel> 
    <var tmpSpeedcamBool registermodel>     
</header>

;****************************************************************************************************************
; Init
;****************************************************************************************************************
<script sc_SettingsInit>
	runif vZoom2DUnit -1 'vZoom2DUnit.SET bUnitType'
	runif vZoom3DUnit -1 'vZoom3DUnit.SET bUnitType'
	runif vZoomOverviewUnit -1 'vZoomOverviewUnit.SET bUnitType'
</script>

;****************************************************************************************************************
; Visuals *******************************************************************************************************
;****************************************************************************************************************

<state st_SettingVisual>
    <uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
    <uselayer ui_Footer2/>
	<uselayer ui_SettingVisual/>

	<script init>
        Title.SET "Visual Settings"
	</script>
</state>

<script sc_btnSV_Overview_OnRelease>
    runif vMapNorthUpOnAutoZoom 1 'btnSV_OverviewEx.ENABLE'
    else_run 'btnSV_OverviewEx.DISABLE'
</script>

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

<state st_SettingVisual3D>
    <uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
    <uselayer ui_Footer2/>
	<uselayer ui_SettingVisual3D/>

	<script init>
        Title.SET "3D Visual Settings"
	    runif %map.3d_buildings 0 'nBuildingDistance.SET 0'
        runif %map.3d_dem 0 'nTerrainDetail.SET 0'
	</script>
	
	<script done>
	    runif nBuildingDistance 0 '.map.3d_buildings 0'
	    runifnot nBuildingDistance 0 '.map.3d_buildings 1'
	
	    runif nTerrainDetail 0 '.map.3d_dem 0'
	    runifnot nTerrainDetail 0 '.map.3d_dem 1'
	</script>
	
</state>

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

<state st_ColorProfiles>
    <uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ColorProfiles/>

    <script init>
        Title.SET "Color Profiles"

        btnSVM_MapColor.TEXT vColorSchemeDayName
		    btnSVM_MapNightColor.TEXT vColorSchemeNightName
        
        ; Set slider state from night mode variables
        runif bAutoNightMode 1 'vMapColors.SET "AUTO"'
        else_runif bNightMode 1 'vMapColors.SET "NIGHT"'
        else_run 'vMapColors.SET "DAY"'
    </script>
</state>

<script sc_btnSVM_MapColor_OnRelease>
    vSelectColorProfileMode.SET 0
    NEXTSTATE st_SettingVisualMapColor
</script>

<script sc_btnSVM_MapNightColor_OnRelease>
    vSelectColorProfileMode.SET 1
    NEXTSTATE st_SettingVisualMapColor
</script>

<script sc_SetNightMode>
	runif vMapColors "AUTO" '.map.nightmode_dependent_backlight 1, bAutoNightMode.SET 1'
	else_runif vMapColors "NIGHT" '.map.nightmode_dependent_backlight 0, bAutoNightMode.SET 0, bNightMode.SET 1'
	else_run '.map.nightmode_dependent_backlight 0, bAutoNightMode.SET 0, bNightMode.SET 0'
</script>

<script sc_SetToNightMode>
	;bAutoNightMode.SET 0
	bNightMode.SET 1
	statusDay.show
	statusAutoDN.hide
	statusNight.hide
</script>

<script sc_SetToDayMode>
	;bAutoNightMode.SET 0
	bNightMode.SET 0
	statusAutoDN.hide
	statusNight.show
	statusDay.hide
</script>
;****************************************************************************************************************

<state st_SettingVisualMenu>
    <uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_SettingVisualMenu/>
	
	<script init>
		Title.SET "Menu Settings"
	</script>
</state>

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

<state st_SettingVisualSkin>
    <uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_SettingVisualSkin/>

	<script init>
		Title.SET "Skin Settings"
	</script>
</state>

<script sc_SelectTheme>
	vTmp.TEXTMODEL_WSTR "screen.theme.list.current.filename"
	vTmp.DROPMODEL
	screen.theme.change_will_restart vTmp nTmp
	runif nTmp 0 sc_SetTheme
	else_run 'INITMESSAGEBOX 1 "Program must be restarted!" sc_SetTheme sc_RestoreThemeIndex'
</script>

<script sc_SetTheme>
	vTmp.TEXTMODEL_WSTR "screen.theme.list.current.filename"
	vTmp.DROPMODEL
	screen.theme.change_theme vTmp
</script>

<script sc_RestoreThemeIndex>
	screen.theme.update_current_index
</script>

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

<state st_SettingVisualBackground>
    <uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_SettingVisualBackground/>
	
	<script init>
		Title.SET "Change Background"
	</script>
</state>

<script sc_et_SettingVisualBackground_OnRelease>
  vTmp.TEXTMODEL_WSTR "screen.background.list.current.filename"
  vBackgroundFile.SET vTmp
  sprH_Background.BMP vBackgroundFile
  spr_msg_bg.BMP vBackgroundFile
  spr_emsg_bg.BMP vBackgroundFile
  spr_sdtmsg_bg.BMP vBackgroundFile
  spr_MP_bg.BMP vBackgroundFile
  vTmp.DROPMODEL

  STATE st_SettingVisualBackground
</script>

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

<state st_SettingVisualMapColor>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
    <uselayer ui_Footer2/>
	<uselayer ui_SettingVisualMapColor/>
	
	<script init>
	    RUNIF     vSelectColorProfileMode 0 'title.text "Day Colour Profile"'
	    ELSE_RUNIF vSelectColorProfileMode 1 'title.text "Night Colour Profile"'
	
	    ATTACHCOLORPROFILEMODEL lstSVM_Profiles vSelectColorProfileMode
		
	    runif vSelectColorProfileMode 0 'lstSVM_Profiles.SETSELECTION vColorSchemeDayName'
	    runif vSelectColorProfileMode 1 'lstSVM_Profiles.SETSELECTION vColorSchemeNightName'
	</script>
</state>

<script sc_lstSVM_Profiles_OnItemSelected>
		runif vSelectColorProfileMode 0 'SETCOLORPROFILE lstSVM_Profiles 0 "vColorSchemeDayName"'
		runif vSelectColorProfileMode 1 'SETCOLORPROFILE lstSVM_Profiles 0 "vColorSchemeNightName"'
		PREVSTATE
</script>

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

<state st_SettingVisualZoom3D>
	<uselayer ui_Header2/>
	<uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_SettingVisualZoom3D/>

	<script init>
		Title.SET "3D Smart Zoom Settings"

		vLastZoomMin.SET %smartzoom.minzoom
		vLastZoomMax.SET %smartzoom.maxzoom

		GET_POSSIBLE_VALUES_ZOOM vLastZoomLevels 0 vZoom3DUnit
		GET_POSSIBLE_VALUES_ZOOM vTmp 0
		hscSVZ_Min3D.POSSIBLEVALUES vTmp
		GET_CORRESPONDING_ZOOM vLastZoomMin vLastZoomLevels vTmp
		.smartzoom.minzoom vLastZoomMin

		GET_POSSIBLE_VALUES_ZOOM vLastZoomLevels 1 vZoom3DUnit
		GET_POSSIBLE_VALUES_ZOOM vTmp 1
		hscSVZ_Max3D.POSSIBLEVALUES vTmp
		GET_CORRESPONDING_ZOOM vLastZoomMax vLastZoomLevels vTmp
		.smartzoom.maxzoom vLastZoomMax

		vZoom3DUnit.SET bUnitType
		DISTUNIT_TO_FORMATTEDSTR %smartzoom.minzoom txtSVZ_Min3D
		DISTUNIT_TO_FORMATTEDSTR %smartzoom.maxzoom txtSVZ_Max3D
	</script>
</state>

<script sc_hscSVZ_Min_3D_OnChange>
	DISTUNIT_TO_FORMATTEDSTR %smartzoom.minzoom txtSVZ_Min3D
    vTmp2.SET %smartzoom.maxzoom
	CHECK_MIN_MAX_RULE %smartzoom.minzoom vTmp2 0 vTmp
    runif vTmp 1 '.smartzoom.maxzoom vTmp2'
</script>

<script sc_hscSVZ_Max_3D_OnChange>
    DISTUNIT_TO_FORMATTEDSTR %smartzoom.maxzoom txtSVZ_Max3D
    vTmp2.SET %smartzoom.minzoom
    CHECK_MIN_MAX_RULE vTmp2 %smartzoom.maxzoom 1 vTmp
    runif vTmp 1 '.smartzoom.minzoom vTmp2'
</script>

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

<state st_SettingVisualZoom2D>
	<uselayer ui_Header2/>
	<uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_SettingVisualZoom2D/>

	<script enter>
		; setup possible values of scrollbar before viewer registration,
		; otherwise its model will be truncated to the default scrollbar maximum (1000)

		vLastZoomMin.SET %smartzoom.minzoom2d
		vLastZoomMax.SET %smartzoom.maxzoom2d

		GET_POSSIBLE_VALUES_ZOOM vLastZoomLevels 4 vZoom2DUnit
		GET_POSSIBLE_VALUES_ZOOM vTmp 4
		hscSVZ_Min2D.POSSIBLEVALUES vTmp
		GET_CORRESPONDING_ZOOM vLastZoomMin vLastZoomLevels vTmp
		.smartzoom.minzoom2d vLastZoomMin

		GET_POSSIBLE_VALUES_ZOOM vLastZoomLevels 5 vZoom2DUnit
		GET_POSSIBLE_VALUES_ZOOM vTmp 5
		hscSVZ_Max2D.POSSIBLEVALUES vTmp
		GET_CORRESPONDING_ZOOM vLastZoomMax vLastZoomLevels vTmp
		.smartzoom.maxzoom2d vLastZoomMax

		vZoom2DUnit.SET bUnitType
	</script>

	<script init>
		Title.SET "2D Smart Zoom Settings"

		DISTUNIT_TO_FORMATTEDSTR %smartzoom.minzoom2d txtSVZ_Min2D
		DISTUNIT_TO_FORMATTEDSTR %smartzoom.maxzoom2d txtSVZ_Max2D
	</script>
</state>

<script sc_hscSVZ_Min_2D_OnChange>
	DISTUNIT_TO_FORMATTEDSTR %smartzoom.minzoom2d txtSVZ_Min2D
    vTmp2.SET %smartzoom.maxzoom2d
	CHECK_MIN_MAX_RULE %smartzoom.minzoom2d vTmp2 0 vTmp
    runif vTmp 1 '.smartzoom.maxzoom2d vTmp2'
</script>

<script sc_hscSVZ_Max_2D_OnChange>
    DISTUNIT_TO_FORMATTEDSTR %smartzoom.maxzoom2d txtSVZ_Max2D
    vTmp2.SET %smartzoom.minzoom2d
    CHECK_MIN_MAX_RULE vTmp2 %smartzoom.maxzoom2d 1 vTmp
    runif vTmp 1 '.smartzoom.minzoom2d vTmp2'
</script>

<script sc_hscSVZ_Time_OnChange>
	hscSVZ_Time.get "vcf_nAutoFollowTime"
	TIME_TO_FOMATTEDSTR vcf_nAutoFollowTime vTmp
	runif vcf_nAutoFollowTime 9999 'txtSVZ_Time.text "OFF", vcf_bAutoFollowModeOn.set 0'
	else_run 'txtSVZ_Time.text vTmp, vcf_bAutoFollowModeOn.set 1'
</script>

;**********240x240********************************************************
<script sc_hscSVZ_Time_OnRelease>
	runif vcf_nAutoFollowTime 9999 'vcf_bAutoFollowModeOn.set 0'
	else_run 'vcf_bAutoFollowModeOn.set 1'
</script>

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

<state st_SettingVisualOverview>
	<uselayer ui_Header2/>
	<uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_SettingVisualOverview/>

	<script init>
		Title.SET "Overview Mode"

		GET_POSSIBLE_VALUES_ZOOM vLastZoomLevels 3 vZoomOverviewUnit
		GET_POSSIBLE_VALUES_ZOOM vTmp 3
		hscSVO_Dist.POSSIBLEVALUES vTmp
		GET_CORRESPONDING_ZOOM vNorthUpAutoZoomDistance vLastZoomLevels vTmp
		hscSVO_Dist.VALUE vNorthUpAutoZoomDistance

		GET_POSSIBLE_VALUES_ZOOM vLastZoomLevels 2 vZoomOverviewUnit
		GET_POSSIBLE_VALUES_ZOOM vTmp 2
		hscSVO_Level.POSSIBLEVALUES vTmp
		GET_CORRESPONDING_ZOOM vNorthUpAutoZoomValue vLastZoomLevels vTmp
		hscSVO_Level.VALUE vNorthUpAutoZoomValue

		vZoomOverviewUnit.SET bUnitType
	</script>
</state>

<script sc_hscSVO_Dist_OnChange>
    hscSVO_Dist.get "vNorthUpAutoZoomDistance"
    DISTUNIT_TO_FORMATTEDSTR vNorthUpAutoZoomDistance txtSVO_Dist
</script>

<script sc_hscSVO_Level_OnChange>
    hscSVO_Level.get "vNorthUpAutoZoomValue"
    DISTUNIT_TO_FORMATTEDSTR vNorthUpAutoZoomValue txtSVO_Level
</script>

;****************************************************************************************************************
; Sound *********************************************************************************************************
;****************************************************************************************************************

<state st_SettingSound>
    <uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
    <uselayer ui_Footer2/>
	<uselayer ui_SettingSound/>

	<script init>
    Title.SET "Sound settings"
		runif nDynamicVolumeType 0 'btnSS_DynAdv.DISABLE'
		else_run 'btnSS_DynAdv.ENABLE'
		nDynamicVolumeType.onchange "sc_DynamicVolumeTypeChanged"
	</script>
</state>

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

;<state st_SettingsSoundDynamicVolumeMain>
;    <uselayer ui_Header2/>
;    <uselayer ui_Background/>
;  <uselayer ui_Title/>
;  <uselayer ui_Footer2/>
;	<uselayer ui_SettingsSoundDynamicVolumeMain/>
	
;	<script init>
;		Title.SET "Dynamic volume settings"
;		
;		btnSSDVM_MasterVol.HIDE
;		btnSSDVM_VoiceVol1.HIDE
;		btnSSDVM_VoiceVol2.HIDE
;		
;		runif nDynamicVolumeType 2 'btnSSDVM_VoiceVol1.SHOW'
;		else_runif nDynamicVolumeType 3 'btnSSDVM_MasterVol.SHOW'
;		else_runif nDynamicVolumeType 4 'btnSSDVM_MasterVol.SHOW, btnSSDVM_VoiceVol2.SHOW'
;	</script>
;</state>

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

<state st_SettingsSoundDynamicVolumeSpeed>
    <uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_SettingsSoundDynamicVolumeSpeed/>
	
	<script init>
		Title.SET "Dynamic volume settings"

		GET_POSSIBLE_VALUES_SPEED vTmp
		hscSSD_MinVolSpd.POSSIBLEVALUES vTmp
		hscSSD_MaxVolSpd.POSSIBLEVALUES vTmp
		;hscSSD_VoiceMaxVolSpd.POSSIBLEVALUES vTmp
		
		vTmp2.SET %sound.dynamic_volume_minspeed
		SPEEDUNIT_TO_USER_SETTINGS vTmp2 vTmp
		hscSSD_MinVolSpd.VALUE vTmp

		vTmp2.SET %sound.dynamic_volume_maxspeed
		SPEEDUNIT_TO_USER_SETTINGS vTmp2 vTmp
		hscSSD_MaxVolSpd.VALUE vTmp
		
		vTmp2.SET %sound.dynamic_volume_voicemaxspeed
		SPEEDUNIT_TO_USER_SETTINGS vTmp2 vTmp
		;hscSSD_VoiceMaxVolSpd.VALUE vTmp
	
		SETFORMATTED_UNIT_TEXT txtSSD_MinVolSpdUnit "km/h"
		SETFORMATTED_UNIT_TEXT txtSSD_MaxVolSpdUnit "km/h"
		;SETFORMATTED_UNIT_TEXT txtSSD_VoiceMaxVolSpdUnit "km/h"

		;runif nDynamicVolumeType 4 'sprSSD_VoiceMaxVolSpdBkg.SHOW, hscSSD_VoiceMaxVolSpd.SHOW, txtSSD_VoiceMaxVolSpdText.SHOW, txtSSD_VoiceMaxVolSpdValue.SHOW, txtSSD_VoiceMaxVolSpdUnit.SHOW'
		;else_run 'sprSSD_VoiceMaxVolSpdBkg.HIDE, hscSSD_VoiceMaxVolSpd.HIDE, txtSSD_VoiceMaxVolSpdText.HIDE, txtSSD_VoiceMaxVolSpdValue.HIDE, txtSSD_VoiceMaxVolSpdUnit.HIDE'
	</script>
	
	<script done>
		SYSCONFIG_SAVE
	</script>
</state>

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

;<state st_SettingsSoundDynamicVolumeMasterVol>
;    <uselayer ui_Header2/>
;    <uselayer ui_Background/>
;	<uselayer ui_Title/>
	;<uselayer ui_Footer2/>
	;<uselayer ui_SettingsSoundDynamicVolumeMasterVol/>

	;<script init>
	;	Title.SET "Dynamic volume - Master volume settings"
	;</script>
	
	;<script done>
	;	SYSCONFIG_SAVE
	;</script>
;</state>

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

;<state st_SettingsSoundDynamicVolumeVoiceVol>
;    <uselayer ui_Header2/>
;    <uselayer ui_Background/>
	;<uselayer ui_Title/>
	;<uselayer ui_Footer2/>
	;<uselayer ui_SettingsSoundDynamicVolumeVoiceVol/>

	;<script init>
	;	Title.SET "Dynamic volume - Voice guidance volume settings"
	;</script>
	
	;<script done>
	;	SYSCONFIG_SAVE
	;</script>
;</state>

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


<script sc_DynamicVolumeTypeChanged>
	playsound "!button"
	
	runif nDynamicVolumeType 0 'btnSS_DynAdv.DISABLE'
	else_run 'btnSS_DynAdv.ENABLE'
	
	runif nDynamicVolumeType 1 'EXEC "sound.dynamic_volume_autocalc_maxvoicespeed", vTmp.VALUEMODEL "sound.dynamic_volume_os_volume_max", vTmp.SET 255, vTmp.DROPMODEL, vTmp.VALUEMODEL "sound.dynamic_volume_voice_volume_max", vTmp.SET 63, vTmp.DROPMODEL'
</script>

<script sc_btnSS_DynAdv_OnRelease>
	NEXTSTATE st_SettingsSoundDynamicVolumeSpeed
  ;runif nDynamicVolumeType 1 'NEXTSTATE st_SettingsSoundDynamicVolumeSpeed'
	;else_run 'NEXTSTATE st_SettingsSoundDynamicVolumeMain'
</script>

<script sc_hscSSD_MinVolSpd_OnChange>
	tmpMinMin.VALUEMODEL "sound.dynamic_volume_minspeed"
	
	hscSSD_MinVolSpd.GET "tmpMinMin"
	txtSSD_MinVolSpdValue.SET tmpMinMin
	SPEEDUNIT_FROM_USER_SETTINGS tmpMinMin

	tmpMinMax.VALUEMODEL "sound.dynamic_volume_maxspeed"
	CHECK_MIN_MAX_RULE tmpMinMin tmpMinMax 0 nTmp
	RUNIF nTmp 1 'SPEEDUNIT_TO_USER_SETTINGS tmpMinMax nTmp, hscSSD_MaxVolSpd.VALUE nTmp'
	tmpMinMax.DROPMODEL

	;tmpMinMax.VALUEMODEL "sound.dynamic_volume_voicemaxspeed"
	;CHECK_MIN_MAX_RULE tmpMinMin tmpMinMax 0 nTmp
	;RUNIF nTmp 1 'SPEEDUNIT_TO_USER_SETTINGS tmpMinMax nTmp, hscSSD_VoiceMaxVolSpd.VALUE nTmp'
	;tmpMinMax.DROPMODEL
	
	tmpMinMin.DROPMODEL
	
	runif nDynamicVolumeType 1 'EXEC "sound.dynamic_volume_autocalc_maxvoicespeed"'
</script>

<script sc_hscSSD_MaxVolSpd_OnChange>
	tmpMaxMax.VALUEMODEL "sound.dynamic_volume_maxspeed"
	
	hscSSD_MaxVolSpd.GET "tmpMaxMax"
	txtSSD_MaxVolSpdValue.SET tmpMaxMax
	SPEEDUNIT_FROM_USER_SETTINGS tmpMaxMax

	tmpMaxMin.VALUEMODEL "sound.dynamic_volume_minspeed"
	CHECK_MIN_MAX_RULE tmpMaxMin tmpMaxMax 1 nTmp
	RUNIF nTmp 1 'SPEEDUNIT_TO_USER_SETTINGS tmpMaxMin nTmp, hscSSD_MinVolSpd.VALUE nTmp'
	tmpMaxMin.DROPMODEL

	;tmpMaxMin.VALUEMODEL "sound.dynamic_volume_voicemaxspeed"
	;CHECK_MIN_MAX_RULE tmpMaxMin tmpMaxMax 1 nTmp
	;RUNIF nTmp 1 'SPEEDUNIT_TO_USER_SETTINGS tmpMaxMin nTmp, hscSSD_VoiceMaxVolSpd.VALUE nTmp'
	;tmpMaxMin.DROPMODEL
	
	tmpMaxMax.DROPMODEL

	runif nDynamicVolumeType 1 'EXEC "sound.dynamic_volume_autocalc_maxvoicespeed"'
</script>

;<script sc_hscSSD_VoiceMaxVolSpd_OnChange>
;	vTmp.VALUEMODEL "sound.dynamic_volume_voicemaxspeed"
	
;	hscSSD_VoiceMaxVolSpd.GET "vTmp"
;	txtSSD_VoiceMaxVolSpdValue.SET vTmp
;	SPEEDUNIT_FROM_USER_SETTINGS vTmp

;	vTmp2.VALUEMODEL "sound.dynamic_volume_minspeed"
;	CHECK_MIN_MAX_RULE vTmp2 vTmp 1 nTmp
;	RUNIF nTmp 1 'SPEEDUNIT_TO_USER_SETTINGS vTmp2 nTmp, hscSSD_MinVolSpd.VALUE nTmp'
;	vTmp2.DROPMODEL

;	vTmp2.VALUEMODEL "sound.dynamic_volume_maxspeed"
;	CHECK_MIN_MAX_RULE vTmp vTmp2 0 nTmp
;	RUNIF nTmp 1 'SPEEDUNIT_TO_USER_SETTINGS vTmp2 nTmp, hscSSD_MaxVolSpd.VALUE nTmp'
;	vTmp2.DROPMODEL
	
;	vTmp.DROPMODEL
;</script>

;<script sc_hscSSD_OSVolMax_OnChange>
;	hscSSD_OSVolumeMax.GET "vTmp"
;	vTmp2.VALUEMODEL "sound.os_volume"
;	CHECK_MIN_MAX_RULE vTmp2 vTmp 1 nTmp
;	vTmp2.DROPMODEL
;</script>

;<script sc_hscSSD_OSVolMax_OnRelease>
;	vTmp.VALUEMODEL "sound.os_amplification"
;	vTmp.SET 255
;	PLAYSOUND "!nav_ding"
;	1 vTmp.SET 0
;	1 vTmp.DROPMODEL	
;</script>

;<script sc_hscSSD_OSVolumeNormal_OnChange>
;	hscSSD_OSVolumeNormal.GET "vTmp"
;	vTmp2.VALUEMODEL "sound.dynamic_volume_os_volume_max"
;	CHECK_MIN_MAX_RULE vTmp vTmp2 0 nTmp
;	vTmp2.DROPMODEL
;</script>

<script sc_hscSSD_VoiceVolMax_OnRelease>
	vTmp.VALUEMODEL "sound.amplification"
	vTmp.SET 63
	VOICEMODEL_PLAYTESTVOICE
	1 vTmp.SET 0
	1 vTmp.DROPMODEL	
</script>

<script sc_SetVolumeSlider>
	runif %sound.os_muted 0 'runif %sound.os_volume 0 sc_SetVolumePrev'
</script>

<script sc_SetVolumePrev>
	.sound.os_volume saved_OsVolume
</script>

<script sc_SetVolumeCheckBox>
	saved_OsVolume.set %sound.os_volume

;	run sc_hscSSD_OSVolumeNormal_OnChange
</script>

;<script sc_hscSSD_VoiceVolMax_OnChange>
;	hscSSD_VoiceVolumeMax.GET "vTmp"
;	vTmp2.VALUEMODEL "sound.voice_volume"
;	CHECK_MIN_MAX_RULE vTmp2 vTmp 1 nTmp
;	vTmp2.DROPMODEL
;</script>

;<script sc_hscSSD_VoiceVolumeNormal_OnChange>
;	hscSSD_VoiceVolumeNormal.GET "vTmp"
;	vTmp2.VALUEMODEL "sound.dynamic_volume_voice_volume_max"
;	CHECK_MIN_MAX_RULE vTmp vTmp2 0 nTmp
;	vTmp2.DROPMODEL
;</script>

<script sc_PlayTestSound>
	vTmp.SET %sound.sound_muted
	.sound.sound_muted 0
	playsound "!nav_ding"
	.sound.sound_muted vTmp
</script>

;****************************************************************************************************************
; Route *********************************************************************************************************
;****************************************************************************************************************

<state st_SettingRoute>
    <uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
    <uselayer ui_Footer2/>
	<uselayer ui_SettingRoute/>

	<script init>
    Title.SET "Route Settings"

    runif nVehicle 0 'nVehicleTmp.set "Car"'
    else_runif nVehicle 1 'nVehicleTmp.set "Taxi"'
    else_runif nVehicle 2 'nVehicleTmp.set "Bus"'
    else_runif nVehicle 3 'nVehicleTmp.set "Truck"'
    else_runif nVehicle 4 'nVehicleTmp.set "Emergency"'
    else_runif nVehicle 5 'nVehicleTmp.set "Pedestrian"'
    else_runif nVehicle 6 'nVehicleTmp.set "Bicycle"'
    btn_vehicle_value.set nVehicleTmp

    GET_POSSIBLE_VALUES_DISTANCE vTmp
    hscSR_UTurn.POSSIBLEVALUES vTmp
    hscSR_UTurn.VALUE vUturn_penalty1
    DISTUNIT_TO_FORMATTEDSTR vUturn_penalty1 txtSR_UTurn

  </script>

  <script enter>
    saved_vUturn_penalty1.SET vUturn_penalty1
    saved_nVehicle.set nVehicle
    saved_vRouteType.set vRouteType
  </script>
  
    <script done>
      runifnot nVehicle 5 '.smartzoom.enabled saved_ZoomMode_3D, .smartzoom.enabled2d saved_ZoomMode_2D'
	  else_run 'saved_ZoomMode_3D.set %smartzoom.enabled, saved_ZoomMode_2D.set %smartzoom.enabled2d, .smartzoom.enabled 0, .smartzoom.enabled2d 0'
    </script>
  
  <script exit>
    vTmp.SET 0
    runifnot saved_vUturn_penalty1 vUturn_penalty1 'vTmp.SET 1'
    runifnot saved_nVehicle nVehicle 'vTmp.set 1'
    runifnot saved_vRouteType vRouteType 'vTmp.set 1'

    runif vTmp 1 'ADVNAV_RECALC'
  </script>  
</state>

<script sc_hscSR_UTurn_OnChange>
    hscSR_UTurn.GET "vUturn_penalty1"
	DISTUNIT_TO_FORMATTEDSTR vUturn_penalty1 txtSR_UTurn
</script>

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

<state st_SettingRouteParam>
	<uselayer ui_Header2/>
	<uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_SettingRouteParam/>

	<script init>
        runif %route.cross_border_routes 0 'vcross_border_routes.set 0'
        else_run 'vcross_border_routes.set 1'
     	runif bHasMapWithCarPool 0 'btnSR_Carpool.hide'
        else_run 'btnSR_Carpool.show'
        Title.SET "Road types to include"

	    saved_bUnpaved.set bUnpaved 
	    saved_bHighway.set bHighway
	    saved_bFerry.set bFerry
	    saved_bUTurn.set bUTurn
	    saved_bToll.set bToll
	    saved_bTax.set bTax
	    saved_bSpecialRoad.set bSpecialRoad
	    saved_bCarPool.set bCarPool
	    saved_vCrossBorderRoutes.set vCrossBorderRoutes
	    saved_nVehicle.set nVehicle
	
	    run sc_UpdateCheckButtons	
    </script>

	<script done>
        runif vcross_border_routes 1 '.route.cross_border_routes 1'
        else_run '.route.cross_border_routes 0'

     	runifnot nVehicle 5 'vGPSPositionToRoad.set 1, .smartzoom.enabled saved_ZoomMode_3D, .smartzoom.enabled2d saved_ZoomMode_2D'
	    else_run 'vGPSPositionToRoad.set 0, saved_ZoomMode_3D.set %smartzoom.enabled, saved_ZoomMode_2D.set %smartzoom.enabled2d, .smartzoom.enabled 0, .smartzoom.enabled2d 0'

        vTmp.set 0
	    runifnot saved_bUnpaved bUnpaved 'vTmp.set 1'
	    runifnot saved_bHighway bHighway 'vTmp.set 1'
	    runifnot saved_bFerry bFerry 'vTmp.set 1'
	    runifnot saved_bUTurn bUTurn 'vTmp.set 1'
	    runifnot saved_bToll bToll 'vTmp.set 1'
	    runifnot saved_bTax bTax 'vTmp.set 1'
	    runifnot saved_bSpecialRoad bSpecialRoad 'vTmp.set 1'
	    runifnot saved_bCarPool bCarPool 'vTmp.set 1'
	    runifnot saved_vCrossBorderRoutes vCrossBorderRoutes 'vTmp.set 1'
	    runifnot saved_nVehicle nVehicle 'vTmp.set 1'
    	
	    runif vTmp 1 sc_route_recalc
        else_run 'vMultiRouteCalculate.set 0'
	</script>
  
  <script sc_route_recalc>
    runif vMultiRouteCalculate 1 'FINDPATH_MULTIPLAN_RECALC,vMultiRouteCalculate.set 0'
    else_run 'ADVNAV_RECALC'
  </script>
 
</state>

<script sc_UpdateCheckButtons>
	runif nVehicle 0 'btnSR_Unpaved.ENABLE,  btnSR_Highway.ENABLE,  btnSR_Ferry.ENABLE,   btnSR_Special.ENABLE,  btnSR_Toll.ENABLE,  btnSR_Tax.ENABLE,  btnSR_Carpool.ENABLE'
	runif nVehicle 1 'btnSR_Unpaved.ENABLE,  btnSR_Highway.ENABLE,  btnSR_Ferry.ENABLE,   btnSR_Special.ENABLE,  btnSR_Toll.ENABLE,  btnSR_Tax.ENABLE,  btnSR_Carpool.ENABLE'
	runif nVehicle 2 'btnSR_Unpaved.ENABLE,  btnSR_Highway.ENABLE,  btnSR_Ferry.ENABLE,   btnSR_Special.ENABLE,  btnSR_Toll.ENABLE,  btnSR_Tax.ENABLE,  btnSR_Carpool.ENABLE'
	runif nVehicle 3 'btnSR_Unpaved.ENABLE,  btnSR_Highway.ENABLE,  btnSR_Ferry.ENABLE,   btnSR_Special.ENABLE,  btnSR_Toll.ENABLE,  btnSR_Tax.ENABLE,  btnSR_Carpool.ENABLE'
	runif nVehicle 4 'btnSR_Unpaved.ENABLE,  btnSR_Highway.ENABLE,  btnSR_Ferry.ENABLE,   btnSR_Special.ENABLE,  btnSR_Toll.ENABLE,  btnSR_Tax.ENABLE,  btnSR_Carpool.ENABLE'
	runif nVehicle 5 'btnSR_Unpaved.DISABLE, btnSR_Highway.DISABLE, btnSR_Ferry.DISABLE,  btnSR_Special.DISABLE, btnSR_Toll.DISABLE, btnSR_Tax.DISABLE, btnSR_Carpool.DISABLE'
	runif nVehicle 6 'btnSR_Unpaved.ENABLE,  btnSR_Highway.DISABLE, btnSR_Ferry.ENABLE,   btnSR_Special.ENABLE,  btnSR_Toll.ENABLE,  btnSR_Tax.ENABLE,  btnSR_Carpool.DISABLE'
</script>

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

<state st_SettingVehicle>
	<uselayer ui_Header2/>
	<uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_SettingVehicle/>

	<script init>
        Title.SET "Select Vehicle"
        saved_nVehicle.set nVehicle
        runif nVehicle 0 'nVehicleTmp.set "Car"'
        else_runif nVehicle 1 'nVehicleTmp.set "Taxi"'
        else_runif nVehicle 2 'nVehicleTmp.set "Bus"'
        else_runif nVehicle 3 'nVehicleTmp.set "Truck"'
        else_runif nVehicle 4 'nVehicleTmp.set "Emergency"'
        else_runif nVehicle 5 'nVehicleTmp.set "Pedestrian"'
        else_runif nVehicle 6 'nVehicleTmp.set "Bicycle"'

	</script>

	<script done>
    nVehicle.onchange ""
    
    runif nVehicleTmp "Car"        'nVehicle.set 0'
		runif nVehicleTmp "Taxi"       'nVehicle.set 1'
		runif nVehicleTmp "Bus"        'nVehicle.set 2'
		runif nVehicleTmp "Truck"      'nVehicle.set 3'
								 				
		runif nVehicleTmp "Emergency"  'nVehicle.set 4'
		runif nVehicleTmp "Pedestrian" 'nVehicle.set 5'
		runif nVehicleTmp "Bicycle"    'nVehicle.set 6'
		
		runifnot saved_nVehicle nVehicle 'run sc_route_recalc, run sc_nVehicle_change'
    nVehicle.onchange "sc_nVehicle_change"      
	</script>

</state>

;****************************************************************************************************************
; Regionals *****************************************************************************************************
;****************************************************************************************************************

<state st_SettingRegional>
	<uselayer ui_Header2/>
	<uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_SettingRegional/>

	<script init>
        Title.SET "Regional settings"
		btnSR_Language.text ""
		btnSR_Voice.text ""
        LANGUAGE_SET_BUTTON_TEXT btnSR_Language btnSR_Voice
	</script>
</state>


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

<state st_SettingRegionalDateTime>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
    <uselayer ui_Footer2/>
	<uselayer ui_SettingRegionalDateTime/>
	
	<script init>
		Title.SET "Date & Time Format"
        GETDATEFORMAT vDateFormat vDateDelimiter
        run sc_SetDelimiterInFormat
	</script>
  
  <script done>
        SETDATEFORMAT vDateFormat vDateDelimiter
  </script>
</state>

<script sc_SetDelimiterInFormat>
	runif vDateDelimiter 45 'sldSRD_Format.value "YYYY-MM-DD|0|YYYY-DD-MM|1|DD-MM-YYYY|2|MM-DD-YYYY|3"'
	runif vDateDelimiter 46 'sldSRD_Format.value "YYYY.MM.DD|0|YYYY.DD.MM|1|DD.MM.YYYY|2|MM.DD.YYYY|3"'	
	runif vDateDelimiter 47 'sldSRD_Format.value "YYYY/MM/DD|0|YYYY/DD/MM|1|DD/MM/YYYY|2|MM/DD/YYYY|3"'	
</script>

;****************************************************************************************************************
; System ********************************************************************************************************
;****************************************************************************************************************

<state st_SettingSystem>
    <uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
    <uselayer ui_Footer2/>
	<uselayer ui_SettingSystem/>

	<script init>
    Title.SET "Device settings"
    GETSYSENTRY "screen_calibration" "debug" 0 vScreenCalibration

    AUTORUN_QUERY_STATE vTmp
    chkSS_ARun.PHASE vTmp
    TODAYPLUGIN_QUERY_STATE vAdvSettingTodaySliderState
    vAdvSettingTodayState.set vAdvSettingTodaySliderState
    
    runif vScreenCalibration 1 'run sc_ScreenCalibrate'

    runif %other.device.ispda 1 'sld_pwrMgmt.value "Keep backlight ON|0|Smart powersave|1|No power management|2"'
    else_run 'sld_pwrMgmt.value "Keep backlight ON|0|Smart powersave|1"'
  </script>

    <script done>
		runifnot vAdvSettingTodaySliderState vAdvSettingTodayState 'TODAYPLUGIN_SET_STATE vAdvSettingTodaySliderState'	
	</script>
</state>

;---  Override-olt script ------
<script sc_ScreenCalibrate>
</script>

<state st_SettingOrientation>
    <uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
    <uselayer ui_Footer2/>
	<uselayer ui_SettingOrientation/>

	<script init>
        Title.SET "Orientation settings"

        GETLANDSCAPE vCurrentOrientation
		runif vCurrentOrientation "PORTRAIT" 'vOrientationVar.SET 0'
		runif vCurrentOrientation "LANDSCAPE1" 'vOrientationVar.SET 1'
		runif vCurrentOrientation "LANDSCAPE2" 'vOrientationVar.SET 2'
    runif vCurrentOrientation "AUTO" 'vOrientationVar.SET 3'  
	</script>
</state>

<script sc_radSS_Ox_OnSelect>
    runif vOrientationVar $1 'TERM sc_radSS_Ox_OnSelect'
    vTmp.SET $1
    
    vTmp2.SET 0
    SETLANDSCAPE vTmp vTmp2
    ; 0 - no restart needed  1 - no restart, setting will be applied at next start  2 - restart needed

    runif      vTmp2 2 'run sc_radSS_Ox_OnSelectRestart vTmp'
    else_runif vTmp2 1 'INITMESSAGEBOX 0 "Your settings will be applied after next time you restart the software."'
    
    runifnot   vTmp2 2 'vOrientationVar.SET vTmp, SETLANDSCAPE vOrientationVar'
</script>

<script sc_radSS_Ox_OnSelectRestart>
    INITMESSAGEBOX 1 "The program will restart." 'vOrientationVar.SET vTmp, SETLANDSCAPE vOrientationVar' 'GETLANDSCAPE vCurrentOrientation'
</script>

;****************************************************************************************************************
; Warnings ******************************************************************************************************
;****************************************************************************************************************

<state st_SettingWarnings>
    <uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
    <uselayer ui_Footer2/>
	<uselayer ui_SettingWarnings/>

	<script init>
     
        Title.SET "Warnings settings"

        runif %interface.safemode_type 0 'vSafetyMode.set 0, chk_safetymode.unpress'
        else_run 'vSafetyMode.set 1, chk_safetymode.press'
        

        runif %warning.speedcam_warning 0 'chk_SpeedCamWarning.unpress'
        else_run 'chk_SpeedCamWarning.press'
        
	</script>
  
  <script done>
        runif vSafetyMode 0 '.interface.safemode_type 0'
        else_run '.interface.safemode_type 1'
  </script>
  
  <script sc_safemode_switch>
	runif vSafetyMode 0 sc_turnon_safemode
	runif vSafetyMode 1 sc_turnoff_safemode
</script>	

<script sc_turnoff_safemode>
	INITMESSAGEBOX 1 "Not recomended." 'vSafetyMode.set 0, chk_safetymode.unpress' 'vSafetyMode.set 1, chk_safetymode.press'
</script>

<script sc_turnon_safemode>
	INITMESSAGEBOX 1 "In safe mode you cannot operate\nthe screen while the car is in motion" 'vSafetyMode.set 1, chk_safetymode.press' 'vSafetyMode.set 0, chk_safetymode.unpress'
</script>

</state>

<script sc_SettingWarningsCheckSpeedCamEula>
	runif vSpeedcamEulaAck 0 'run sc_AskSpeedCamEula'
</script>

<script sc_AskSpeedCamEula>
    tmpSpeedcamVis.set %warning.speedcam_visualtype
    tmpSpeedcamAud.set %warning.speedcam_soundtype
    vCustomMessageBox2ndLine.set "Turn it on anyway?"
	INITMESSAGEBOX 2 "Using this function may be prohibited by law in certain countries." sc_SpeedcamWarningEnabled sc_SpeedcamWarningDisabled
</script>


<script sc_SpeedcamWarningEnabled>
	vSpeedcamEulaAck.SET 1
	.warning.speedcam_warning 1
	chk_SpeedCamWarning.phase 1
    tmpSpeedcamBool.boolexpr "ui.tmpSpeedcamVis|ui.tmpSpeedcamAud"
    runifnot  tmpSpeedcamBool 0 '.warning.speedcam_visualtype tmpSpeedcamVis
                                 .warning.speedcam_soundtype tmpSpeedcamAud'
</script>

<script sc_SpeedcamWarningDisabled>
	.warning.speedcam_warning 0
	vSpeedcamEulaAck.SET 0
	chk_SpeedCamWarning.phase 0
</script>

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

<state st_SettingWarningsOverSpeed>
    <uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
    <uselayer ui_Footer2/>
	<uselayer ui_SettingWarningsOverSpeed/>

    <script init>
        Title.SET "Overspeed settings"

		hscSWO_OTolerance.GET "vTmp"
		txtSWO_OToleranceV.SET vTmp
        hscSWO_OToleranceAlt.GET "vTmp"
        txtSWO_OToleranceAltV.SET vTmp
		    
    </script>

    <script done>
		SYSCONFIG_SAVE
	</script>
</state>

<script sc_hscSWO_OTolerance_OnChange>
	hscSWO_OTolerance.GET "vTmp"
	txtSWO_OToleranceV.SET vTmp
</script>

<script sc_hscSWO_OToleranceAlt_OnChange>
	hscSWO_OToleranceAlt.GET "vTmp"
	txtSWO_OToleranceAltV.SET vTmp
</script>

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

<state st_SettingWarningsSpeedCam>
    <uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
    <uselayer ui_Footer2/>
	<uselayer ui_SettingWarningsSpeedCam/>

    <script init>
        Title.SET "Speed camera settings"
    </script>
    
    <script done>
		runif %int:warning.speedcam_soundtype 0 'runif %int:warning.speedcam_visualtype 0 sc_Disable_SpeedcamWarning'
        SYSCONFIG_SAVE
    </script>
</state>

<script sc_Disable_SpeedcamWarning>
	.warning.speedcam_warning 0
</script>

;****************************************************************************************************************
; GUIDANCE ***********************************************************************************************************
;****************************************************************************************************************

<state st_SettingGuidance>
	<uselayer ui_Header2/>
	<uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_SettingGuidance/>

	<script init>
		vcf_bAutoFollowModeOn.set vcf_bAutoFollowModeOn_save

		Title.SET "Navigation Settings"

		vAutoRecalc.SET vAutoReplan

		btnSR_AlignToRoad.ENABLE
		runif nVehicle 5 'btnSR_AlignToRoad.DISABLE'

		runif vMapNorthUpOnAutoZoom 1 'btnSV_OverviewEx.ENABLE'
		else_run 'btnSV_OverviewEx.DISABLE'

		vAutoRestore.set vcf_bAutoFollowModeOn

		hscSVZ_Time.VALUE vcf_nAutoFollowTime
		run sc_hscSVZ_Time_OnChange

		TIME_TO_FOMATTEDSTR vcf_nAutoFollowTime vTmp
		runif vcf_nAutoFollowTime 9999 'txtSVZ_Time.text "OFF"'
		else_run 'txtSVZ_Time.text vTmp'
	</script>

	<script done>
		vcf_bAutoFollowModeOn_save.set vcf_bAutoFollowModeOn
		vcf_bAutoFollowModeOn.set 0
		run sc_offroute_change
	</script>
</state>

<script sc_offroute_change>
	;save on state done or btnSR_AlignToRoad.onRelease
	runif vAutoRecalc 1 'vRecalcOffByStartPoint.set 0'
	vAutoReplan.SET vAutoRecalc

	runifnot nVehicle 5 'saved_vGPSPositionToRoad.set vGPSPositionToRoad'
</script>

;****************************************************************************************************************
; GPS ***********************************************************************************************************
;****************************************************************************************************************

<state st_SettingGPS>
	<uselayer ui_Header2/>
	<uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_SettingGPS/>

	<script init>
		Title.SET "GPS Status"
		register_satellite_display "l_sat" "sat" "l_prn" "spr_prn"
	</script>
	
	<script done>
		unregister_satellite_display "l_sat" "sat" "l_prn" "spr_prn"
	</script>
</state>

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


<state st_SettingGPSAutoDetect>
	<uselayer ui_Header2/>
	<uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_SettingGPSAutoDetect/>
	<uselayer ui_SettingGPSConfigBack/>

	<script init>
    Title.SET "Detecting GPS device"

    GPS_STOP
    ;GPS_START
    REGISTER_AUTODETECT_DISPLAY txtSGA_Port txtSGA_Baud sc_GPSAutoDetectSuccess sc_GPSAutoDetectFailed
    100 GPS_AUTODETECT
  </script>
  
	<script done>
    ;UNREGISTER_AUTODETECT_DISPLAY txtSGA_Port txtSGA_Baud sc_GPSAutoDetectSuccess sc_GPSAutoDetectFailed
  </script>
</state>

<script sc_GPSAutoDetectFailed>
  UNREGISTER_AUTODETECT_DISPLAY txtSGA_Port txtSGA_Baud sc_GPSAutoDetectSuccess sc_GPSAutoDetectFailed
  
  GPS_STOP
  run sc_SetGpsStatus_NoCallback %gps.started

  PREVSTATE
  1 INITMESSAGEBOX 0 "GPS could not be found."
</script>

<script sc_GPSAutoDetectSuccess>
  UNREGISTER_AUTODETECT_DISPLAY txtSGA_Port txtSGA_Baud sc_GPSAutoDetectSuccess sc_GPSAutoDetectFailed
  
  PREVSTATE
  PREVSTATE
  1 INITMESSAGEBOX 0 "GPS receiver was detected\n successfully."
</script>

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

<state st_SettingGPSConfig>
	<uselayer ui_Header2/>
	<uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_SettingGPSConfig/>
	<uselayer ui_SettingGPSConfigBack/>

	<script init>
    Title.SET "Manual GPS config"

    run sc_SetGpsStatus_NoCallback %gps.started
  </script>

</state>

<script sc_OnGPSSettingsChanged>
  runif vGpsOnOff 1 '100 GPS_START'
</script>

<script sc_SetGpsStatus_NoCallback>
  chk_gps_status.ONSELECT ''
  chk_gps_status.ONDESELECT ''

  vGpsOnOff.SET $1

  chk_gps_status.ONSELECT 'GPS_START'
  chk_gps_status.ONDESELECT 'GPS_STOP'
</script>

;****************************************************************************************************************
<script sc_FastPedestrianWarning>
    runif %warning.pedestrian_warning 1 'run sc_FastPedestrianWarning_IfNotSimul'
</script>

<script sc_FastPedestrianWarning_IfNotSimul>
    runif vFlyoverOrSimulate 0 'run sc_FastPedestrianWarning_IfNotIgnored'
</script>

<script sc_FastPedestrianWarning_IfNotIgnored>
    runif vPedestrianWarning_Ignored 0 'run sc_FastPedestrianWarning2'
</script>

<script sc_FastPedestrianWarning2>
	  ;vCustomMessageBox2ndLine.set "Change vehicle type to car?"
    INITMESSAGEBOX 2 "Pedestrian too fast! Change to car or ignore?" 'run sc_FastPedestrianWarning_SetCar' 'run sc_FastPedestrianWarning_Ignore'
</script>

<script sc_FastPedestrianWarning_SetCar>

    nVehicle.SET 0

    .smartzoom.enabled saved_ZoomMode_3D
    .smartzoom.enabled2d saved_ZoomMode_2D

    btn_vehicle_value.SET "Car"

    ;.warning.pedestrian_warning 1
   vPedestrianWarning_Ignored.SET 0

    ADVNAV_RECALC
</script>

<script sc_FastPedestrianWarning_Ignore>
   ;.warning.pedestrian_warning 0
   vPedestrianWarning_Ignored.SET 1 
</script>

<script sc_SetPedestrianWarning>
   .warning.pedestrian_warning 1
   vPedestrianWarning_Ignored.SET 0
</script>


;****************************************************************************************************************
; Time & Time Zone Settings
;****************************************************************************************************************

<state st_SettingTime>
  <uselayer ui_Header2/>
  <uselayer ui_Background/>
  <uselayer ui_Title/>
  <uselayer ui_Footer2/>
  <uselayer ui_SettingTime/>

  <script init>
    Title.SET "Time Settings"
  </script>
</state>

<state st_SettingTimeZone>
  <uselayer ui_Header2/>
  <uselayer ui_Background/>
  <uselayer ui_Title/>
  <uselayer ui_Footer2/>
  <uselayer ui_SettingTimeZone/>

  <script init>
    Title.SET "Select Time Zone"
  </script>

  <script done>
  </script>

</state>

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

<script sc_OnAutoTimeZoneErrorChanged>
    runifnot vLastAutoTimeZoneError 0 'run sc_OnAutoTimeZoneError'
</script>

<script sc_OnAutoTimeZoneError>
    INITMESSAGEBOX 2 "Cannot set automatic time zone based on your position. Automatic time zone was disabled. Do you want to set the time zone manually?" sc_OnAutoTimeZoneErrorSet sc_OnAutoTimeZoneErrorSkip
</script>

<script sc_OnAutoTimeZoneErrorSet>
    vLastAutoTimeZoneError.set 0
    ; Go to manual time zone selection list
    NEXTSTATE st_SettingTimeZone
</script>

<script sc_OnAutoTimeZoneErrorSkip>
    vLastAutoTimeZoneError.set 0
</script>

;*************************** HELP **********************************
<state st_HelpSettingVisual>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ScrollButtons/>
	<uselayer ui_HelpSettingVisual/>

	<script init>
		Title.SET "Visual Settings"
		run sc_ScrollingLayerInit ui_HelpSettingVisual vAutoScrollHelp
	</script>
	
	<script done>
	    run sc_ScrollingLayerDone
	</script>
</state>

<state st_HelpSettingVisual3D>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ScrollButtons/>
	<uselayer ui_HelpSettingVisual3D/>

	<script init>
		Title.SET "3D Visual Settings"
		run sc_ScrollingLayerInit ui_HelpSettingVisual3d vAutoScrollHelp
	</script>
	
	<script done>
	    run sc_ScrollingLayerDone
	</script>
</state>

<state st_HelpSettingVisualZoom>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ScrollButtons/>
	<uselayer ui_HelpSettingVisualZoom/>

	<script init>
		Title.SET "Smart Zoom"
		run sc_ScrollingLayerInit ui_HelpSettingVisualZoom vAutoScrollHelp
	</script>
	
	<script done>
	    run sc_ScrollingLayerDone
	</script>
</state>

<state st_HelpSettingVisualOverview>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ScrollButtons/>
	<uselayer ui_HelpSettingVisualOverview/>

	<script init>
		Title.SET "Overview Mode"
		run sc_ScrollingLayerInit ui_HelpSettingVisualOverview vAutoScrollHelp
	</script>
	
	<script done>
	    run sc_ScrollingLayerDone
	</script>
</state>

<state st_HelpSettingVisualMenu>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ScrollButtons/>
	<uselayer ui_HelpSettingVisualMenu/>

	<script init>
		Title.SET "Menu Mode"
		run sc_ScrollingLayerInit ui_HelpSettingVisualMenu vAutoScrollHelp
	</script>
	
	<script done>
	    run sc_ScrollingLayerDone
	</script>
</state>

<state st_HelpSettingRoute>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ScrollButtons/>
	<uselayer ui_HelpSettingRoute/>

	<script init>
		Title.SET "Route Settings"
		run sc_ScrollingLayerInit ui_HelpSettingRoute vAutoScrollHelp
	</script>
	
	<script done>
	    run sc_ScrollingLayerDone
	</script>
</state>

<state st_HelpSettingSystem>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ScrollButtons/>
	<uselayer ui_HelpSettingSystem/>

	<script init>
		Title.SET "Device settings"
		run sc_ScrollingLayerInit ui_HelpSettingSystem vAutoScrollHelp
	</script>
	
	<script done>
	    run sc_ScrollingLayerDone
	</script>
</state>

<state st_HelpSettingSound>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ScrollButtons/>
	<uselayer ui_HelpSettingSound/>

	<script init>
		Title.SET "Sound settings"
		run sc_ScrollingLayerInit ui_HelpSettingSound vAutoScrollHelp
	</script>
	
	<script done>
	    run sc_ScrollingLayerDone
	</script>
</state>

;<state st_HelpSettingsSoundDynamicVolume>
;	<uselayer ui_Header2/>
 ;   <uselayer ui_Background/>
	;<uselayer ui_Title/>
	;<uselayer ui_Footer2/>
	;<uselayer ui_ScrollButtons/>
	;<uselayer ui_HelpSettingSoundDinamicVolume/>

	;<script init>
	;	Title.SET "Dynamic Volume"
	;	run sc_ScrollingLayerInit ui_SettingsSoundDynamicVolumeMain vAutoScrollHelp
	;</script>
	
	;<script done>
	;    run sc_ScrollingLayerDone
	;</script>
;</state>

<state st_HelpSettingRegional>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ScrollButtons/>
	<uselayer ui_HelpSettingRegional/>

	<script init>
		Title.SET "Regional settings"
		run sc_ScrollingLayerInit ui_HelpSettingRegional vAutoScrollHelp
	</script>
	
	<script done>
	    run sc_ScrollingLayerDone
	</script>
</state>

<state st_HelpSettingTime>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ScrollButtons/>
	<uselayer ui_HelpSettingTime/>

	<script init>
		Title.SET "Time Settings"
		run sc_ScrollingLayerInit ui_HelpSettingTime vAutoScrollHelp
	</script>
	
	<script done>
	    run sc_ScrollingLayerDone
	</script>
</state>

<state st_HelpSettingWarnings>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ScrollButtons/>
	<uselayer ui_HelpSettingWarnings/>

	<script init>
		Title.SET "Warnings settings"
		run sc_ScrollingLayerInit ui_HelpSettingWarnings vAutoScrollHelp
	</script>
	
	<script done>
	    run sc_ScrollingLayerDone
	</script>
</state>

<state st_HelpSettingTrackLog>
  <uselayer ui_Header2/>
  <uselayer ui_Background/>
  <uselayer ui_Title/>
  <uselayer ui_Footer2/>
  <uselayer ui_ScrollButtons/>
  <uselayer ui_HelpSettingTrackLog/>

  <script init>
    Title.SET "Track Log Options"
    run sc_ScrollingLayerInit ui_HelpSettingTrackLog vAutoScrollHelp
  </script>

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

<state st_HelpSettingGuidance>
  <uselayer ui_Header2/>
  <uselayer ui_Background/>
  <uselayer ui_Title/>
  <uselayer ui_Footer2/>
  <uselayer ui_ScrollButtons/>
  <uselayer ui_HelpSettingGuidance/>

  <script init>
    Title.SET "Navigation Settings"
    run sc_ScrollingLayerInit ui_HelpSettingGuidance vAutoScrollHelp
  </script>

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

<state st_HelpSettingGPS>
  <uselayer ui_Header2/>
  <uselayer ui_Background/>
  <uselayer ui_Title/>
  <uselayer ui_Footer2/>
  <uselayer ui_ScrollButtons/>
  <uselayer ui_HelpSettingGPS/>

  <script init>
    Title.SET "GPS Settings"
    run sc_ScrollingLayerInit ui_HelpSettingGPS vAutoScrollHelp
  </script>

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

<state st_HelpSettingColorProfiles>
  <uselayer ui_Header2/>
  <uselayer ui_Background/>
  <uselayer ui_Title/>
  <uselayer ui_Footer2/>
  <uselayer ui_ScrollButtons/>
  <uselayer ui_HelpSettingColorProfiles/>

  <script init>
    Title.SET "Color Profiles"
    run sc_ScrollingLayerInit ui_HelpSettingColorProfiles vAutoScrollHelp
  </script>

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

<state st_mydata_help>
	<uselayer ui_Header2/>
    <uselayer ui_Background/>
	<uselayer ui_Title/>
	<uselayer ui_Footer2/>
	<uselayer ui_ScrollButtons/>
	<uselayer ui_mydata_help/>

	<script init>
		;Title.SET "Road types to include"
		run sc_ScrollingLayerInit ui_mydata_help vAutoScrollHelp
	</script>
	
	<script done>
	    run sc_ScrollingLayerDone
	</script>
</state>
