<Gauge Name="Multi-Function Display, MFD" Version="1.0">
   <Comment>Artwork Copyright 2003, by Kevin Sparkuhl</Comment>
   <Element>
      <Visible>(A:Circuit general panel on, bool) (L:PFD Switch, bool) ! &amp;&amp;</Visible>
      <Element>
         <Visible>(L:Nav Display Switch, bool)</Visible>
            <Image Name="nd_bkgrnd.bmp" Bright="Yes" ImageSizes="396,386,0,0"/>
            <Element>
               <Position X="181" Y="2"/>
               <Text X="66" Y="28" Bright="Yes" Length="3" Font="Arial" Color="#ffffff" Adjust="Center" VerticalAdjust="Bottom" Multiline="No" Fixed="Yes">
                  <Axis X="15" Y="0"/>
                  <String>%(360 (A:Plane heading degrees gyro, degrees) dnor near d 0 == ?)%!03d!</String>
               </Text>
            </Element>
            <Element>
               <Position X="197" Y="211"/>
               <Clip/>
               <Image Name="nd_hsi_card.bmp" Bright="Yes" ImageSizes="329,329,0,0">
                  <Axis X="164.5" Y="164.5"/>
               </Image>
               <Rotate>
                  <Value>(A:Plane heading degrees gyro, radians) /-/</Value>
               </Rotate>
            </Element>
            <Element>
               <Position X="197" Y="211"/>
               <Image Name="nd_hsi_adf_needle.bmp" Bright="Yes" ImageSizes="27,329,21,228">
                  <Axis X="13.5" Y="164.5"/>
               </Image>
               <Rotate>
                  <Value>(A:ADF1 radial, radians)</Value>
               </Rotate>
            </Element>
            <Element>
               <Position X="197" Y="211"/>
               <Image Name="nd_hsi_vor2_needle.bmp" Bright="Yes" ImageSizes="27,329,27,228">
                  <Axis X="13.5" Y="164.5"/>
               </Image>
               <Rotate>
                  <Value>(A:NAV2 radial, radians) (A:Plane heading degrees gyro, radians) - pi  +</Value>
               </Rotate>
            </Element>
            <Element>
               <Position X="197" Y="211"/>
               <Image Name="nd_hsi_heading_bug.bmp" Bright="Yes" ImageSizes="33,13,0,0">
                  <Axis X="16.5" Y="174.5"/>
               </Image>
               <Rotate>
                  <Value>(A:Autopilot heading lock dir, radians) (A:Plane heading degrees gyro, radians) -</Value>
               </Rotate>
            </Element>
            <Element>
               <Position X="197" Y="211"/>
               <Image Name="nd_hsi_vor1_needle.bmp" Bright="Yes" ImageSizes="175,309,0,0">
                  <Axis X="87.5" Y="154.5"/>
               </Image>
               <Rotate>
                  <Value>(A:NAV1 OBS, radians) (A:Plane heading degrees gyro, radians) -</Value>
               </Rotate>
            </Element>
            <Element>
               <Position X="197" Y="211"/>
               <Select>
                  <Value>(A:HSI has localizer, bool) 0 !=</Value>
                  <Case Value="0">
                     <Image Name="nd_hsi_cdi_hollow.bmp" Bright="Yes" ImageSizes="17,105,0,0">
                        <Axis X="8.5" Y="52.5"/>
                     </Image>
                  </Case>
                  <Case Value="1">
                     <Image Name="nd_hsi_cdi_hollow.bmp" Bright="Yes" ImageSizes="17,105,0,0">
                        <Axis X="8.5" Y="52.5"/>
                     </Image>
                  </Case>
               </Select>
               <Shift>
                  <Value>(A:HSI CDI needle valid,bool) if{ (A:HSI CDI needle,number)  } els{ 0 }</Value>
                  <Scale X="0.61"><!--30/127 == 0.61--></Scale>
               </Shift>
               <Rotate>
                  <Value>(A:NAV1 OBS, radians) (A:Plane heading degrees gyro, radians) -</Value>
               </Rotate>
               <Clip/>
            </Element>
            <Element>
               <Position X="197" Y="211"/>
               <Visible>(A:HSI TF flags, enum) 0 !=</Visible>
               <Image Name="nd_hsi_tf_indicator.bmp" Bright="Yes" ImageSizes="25,15,0,0">
                  <Axis X="12.5" Y="51"/>
               </Image>
               <Rotate>
                  <Value>(A:NAV1 OBS, radians) (A:Plane heading degrees gyro, radians) - (A:HSI TF flags, enum) 2 == if{ pi  + }</Value>
               </Rotate>
            </Element>
            <Element>
               <Position X="197" Y="211"/>
               <Image Name="nd_hsi_track_line.bmp" Bright="Yes" ImageSizes="27,329,15,212">
                  <Axis X="13.5" Y="164.5"/>
               </Image>
               <Rotate>
                  <Value>(A:Velocity world X, m/s) (A:Velocity world Z, m/s) atg2 (A:Magvar, radians) - (A:Plane heading degrees gyro, radians) - </Value>
               </Rotate>
            </Element>
            <Element>
               <Position X="197" Y="211"/>
               <Image Name="nd_hsi_plane.bmp" Bright="Yes" ImageSizes="49,46,0,0">
                  <Axis X="24.5" Y="23"/>
               </Image>
            </Element>
         </Element>
         <Element>
            <Position X="367" Y="211"/>
            <Visible>(A:HSI GSI needle valid, bool) (L:VOR1 gs switch, bool) !</Visible>
            <Image Name="nd_glideslope_bkgrnd.bmp" Bright="Yes" ImageSizes="18,158,0,0">
               <Axis X="1" Y="58.5"/>
            </Image>
            <Element>
               <Image Name="nd_glideslope_needle.bmp" Bright="Yes" ImageSizes="18,28,0,0">
                  <Axis X="0" Y="10.5"/>
               </Image>
               <Shift>
               <Value Minimum="-1" Maximum="1">(A:HSI GSI needle, number) 120 /</Value>
               <Nonlinearity>
                  <Item Value="-1" X="0" Y="-49"/>
                  <Item Value="0" X="0" Y="0"/>
                  <Item Value="1" X="0" Y="49"/>
               </Nonlinearity>
               </Shift>
            </Element>
         </Element>
      </Element>

         <Visible>(L:Nav Display Switch, bool) !</Visible>




	<!-- local vars
		activateLeg				- 1=display activate leg popup, 0=hide activate leg popup
		blinkingField			- 1-based index of field that is blinking, 0 if no blinking
		blinkingFieldEnabled1	- bool to indicate whether field is available for cursor scrolling/blinking
		blinkingFieldEnabled2	- "
		blinkingFieldEnabled3	- "
		blinkingFieldSaved		- saved when going from one blinking screen to another to blink correct field on close
		currentGroup			- 0=nav, 1=wpt, 2=nrst, 3=fpl, 4=proc
		currentPageNAV		- current sub-page for page group 0
		currentPageWPT		- "                               1
		currentPageNRST		- "                               2
		currentPageFPL		- "                               3
		menuBlinker
		messagePopup			- 1=display message popup, 0=hide message popup
		modeCDI
		navPage0DetailLevel		- level of detail for nav page 0 (0=most, 3=least)
		navPage1DetailLevel		- level of detail for nav page 1 (0=most, 3=least)
		numberOfBlinkingFields	- number of blinkingFields; set to non-zero to prepare for PushCRSRButton handling
		popupMenu				- popup menu parameter
		popupMenuCurrent		- popup menu parameter
		popupMenuHeaderHeight	- popup menu parameter
		popupMenuHeight			- popup menu parameter
		popupMenuLineHeight		- popup menu parameter
		popupMenuMaxElements	- popup menu parameter
		popupMenuWidth			- popup menu parameter
		popupMenuX				- popup menu parameter
		popupMenuY				- popup menu parameter
		scaleCDI
		smallmap_ZoomStepDone
	-->
	<!-- Constants -->
	
	<Macro Name="FPLLineSpacing">26</Macro>

	<Macro Name="c">C:fs9gps</Macro>
	<Macro Name="g">C:fs9gps</Macro>
	<Macro Name="kFalse">0</Macro>
	<Macro Name="kTrue">1</Macro>
	<Macro Name="kOff">0</Macro>
	<Macro Name="kOn">1</Macro>
	<Macro Name="kDisabled">0</Macro>
	<Macro Name="kEnabled">1</Macro>
	
	<!-- main page group constants -->
	<Macro Name="kNAVPageGroup">0</Macro>
	<Macro Name="kWPTPageGroup">1</Macro>
	<Macro Name="kNRSTPageGroup">2</Macro>
	
	<!-- standalone page group constants -->
	<Macro Name="kFPLPageGroup">3</Macro>
	<Macro Name="kPROCPageGroup">4</Macro>

	<!-- NAV page constants -->
	<Macro Name="kNAVPageCnt">2</Macro>
	<Macro Name="kNAVPageDflt">0</Macro>
	<Macro Name="kNAVPageMap">1</Macro>

	<!-- WPT page constants -->
	<Macro Name="kWPTPageCnt">7</Macro>
	<Macro Name="kWPTPageAptLoc">0</Macro>
	<Macro Name="kWPTPageAptRun">1</Macro>
	<Macro Name="kWPTPageAptFreq">2</Macro>
	<Macro Name="kWPTPageAptApproach">3</Macro>
	<Macro Name="kWPTPageInt">4</Macro>
	<Macro Name="kWPTPageNdb">5</Macro>
	<Macro Name="kWPTPageVor">6</Macro>
	
	<!-- NRST page constants -->
	<Macro Name="kNRSTPageCnt">5</Macro>
	<Macro Name="kNRSTPageApt">0</Macro>
	<Macro Name="kNRSTPageInt">1</Macro>
	<Macro Name="kNRSTPageNDB">2</Macro>
	<Macro Name="kNRSTPageVOR">3</Macro>
	<Macro Name="kNRSTPageASP">4</Macro>

	<!-- popup constants -->
	<Macro Name="kPopupMenuSelectApproach">2</Macro>
	<Macro Name="kPopupMenuSelectTransition">3</Macro>

	<!-- B, C, D, MOA, RESTRICTED, PROHIBITED, WARNING, ALERT, DANGER, MODE_C, RADAR, TRAINING -->
	<Macro Name="kDisplayedAirspaces">0xEFC038</Macro>
	<!-- MOA, RESTRICTED, PROHIBITED, WARNING, ALERT, DANGER -->
	<Macro Name="kAlwaysDisplayedAirspaces">0x0FC000</Macro>

	<!-- General purpose macros -->
	<Macro Name="AirportIcon">%((@1))%{case}%{:1}%((@2,degrees) 45 / near 4 %)%{case}%{:0}1%{:1}2%{:2}3%{:3}4%{end}%{:2}5%{:3}6%{:4}7%{:5}8%{end}</Macro>
	<Macro Name="FormatLatitudeTabbed">%((@1,degrees) d 0 >=)%{if}N%{else}S%{end}\t%(abs 6000 * near 6000 / d flr - b)%!02d!\t&#xB0;%(60 *)%!05.2f!'</Macro>
	<Macro Name="FormatLongitudeTabbed">%((@1,degrees) d 0 >=)%{if}E%{else}W%{end}\t%(abs 6000 * near 6000 / d flr - b)%!03d!\t&#xB0;%(60 *)%!05.2f!'</Macro>
	<Macro Name="BlinkerCode">(@g:menuBlinker) d 0 > if{ -- (>@g:menuBlinker) 15 sp0 1 } els{ l0 -- s0 d 0 &lt;= if{ 30 sp0 } 15 > }</Macro>
	<Macro Name="RestoreBlinkingField">(@g:blinkingFieldSaved) (>@g:blinkingField) 0 (>@g:blinkingFieldSaved)</Macro>
	<Macro Name="InitBlinker">70 (>@g:menuBlinker)</Macro>
	<Macro Name="NumberOfPagesInCurrentGroup">1 1 @kNRSTPageCnt @kWPTPageCnt @kNAVPageCnt 5 (@g:currentGroup) case</Macro>
	<Macro Name="InvokePopupMenu">
		@1 (>@g:popupMenu) @2 (>@g:popupMenuX) @3 (>@g:popupMenuY) @4 (>@g:popupMenuWidth) @5 (>@g:popupMenuHeight) 
		@6 (>@g:popupMenuHeaderHeight) @7 (>@g:popupMenuLineHeight) @8 (>@g:popupMenuMaxElements) 
		0 (>@g:popupMenuCurrent) (@g:blinkingField) (>@g:blinkingFieldSaved) 0 (>@g:blinkingField) @InitBlinker
	</Macro>
	
	<Macro Name="InvokePopupSelectApproach">@InvokePopupMenu(@kPopupMenuSelectApproach, 144, 36, 90, 171, 19, 1, (@c:WaypointAirportApproachesNumber)) (@g:currentAirportApproach) (>@g:popupMenuCurrent)</Macro>
	<Macro Name="InvokePopupSelectTransition">@InvokePopupMenu(@kPopupMenuSelectTransition, 144, 36, 90, 171, 19, 1, (@g:currentAirportApproach) (>@c:WaypointAirportCurrentApproach) (@c:WaypointAirportApproachTransitionsNumber)) (@g:currentAirportTransition) (>@g:popupMenuCurrent)</Macro>
	
	<Macro Name="CancelPopupMenu">0 (>@g:popupMenu) (@g:blinkingFieldSaved) (>@g:blinkingField) 0 (>@g:blinkingFieldSaved) @InitBlinker</Macro>
	<Macro Name="CalculateZoomFactor">2000 1500 1000 500 350 200 150 100 50 35 20 15 10 5 3.5 2.0 1.5 1.0 0.576037 0.329164 0.246873 0.164582 0.082290 0 24 @1 case</Macro>
	<Macro Name="FitToZoom">@1 0.55 * sp1 1 sp0 :1 @CalculateZoomFactor(l0) 1852 * l1 &lt; if{ l0 ++ sp0 g1 } l0</Macro>
	<Macro Name="RecalcSmallZoom">0 (>@g:smallmap_ZoomStepDone)</Macro>
	<Macro Name="SetPageGroup">@1 (>@g:currentGroup)</Macro>
	<!-- Page macros -->
	<Macro Name="ProcedureScrollTop">
		(@g:currentGroup) @kPROCPageGroup == if{
			(@g:blinkingField) 1 == (@g:blinkingFieldEnabled1) 0 == and if{ 2 (>@g:blinkingField) }
			(@g:blinkingField) 2 == (@g:blinkingFieldEnabled2) 0 == and if{ 3 (>@g:blinkingField) }
		}
	</Macro>
	<Macro Name="ProcedureScrollUp">
		(@g:currentGroup) @kPROCPageGroup == if{
			(@g:blinkingField) 3 == (@g:blinkingFieldEnabled3) 0 == and if{ 2 (>@g:blinkingField) }
			(@g:blinkingField) 2 == (@g:blinkingFieldEnabled2) 0 == and if{ 1 (>@g:blinkingField) }
			(@g:blinkingField) 1 == (@g:blinkingFieldEnabled1) 0 == and if{ 2 (>@g:blinkingField) }
			(@g:blinkingField) 2 == (@g:blinkingFieldEnabled2) 0 == and if{ 3 (>@g:blinkingField) }
		}
	</Macro>
	<Macro Name="ProcedureScrollDown">
		(@g:currentGroup) @kPROCPageGroup == if{
			(@g:blinkingField) 1 == (@g:blinkingFieldEnabled1) 0 == and if{ 2 (>@g:blinkingField) }
			(@g:blinkingField) 2 == (@g:blinkingFieldEnabled2) 0 == and if{ 3 (>@g:blinkingField) }
			(@g:blinkingField) 3 == (@g:blinkingFieldEnabled3) 0 == and if{ 2 (>@g:blinkingField) }
			(@g:blinkingField) 2 == (@g:blinkingFieldEnabled2) 0 == and if{ 1 (>@g:blinkingField) }
		}
	</Macro>
	<Macro Name="ProcedurePageInit">
		3 (>@g:numberOfBlinkingFields)
		<!-- enable appropriate fields -->
		0 (>@g:blinkingFieldEnabled1)
		(@c:FlightPlanIsLoadedApproach) d (>@g:blinkingFieldEnabled1) (>@g:blinkingFieldEnabled2)
		1 (>@g:blinkingFieldEnabled3)
		(@c:FlightPlanIsLoadedApproach) if{ (@c:FlightPlanApproachTransitionIndex) 0 != if{ 2 } els{ 1 } } els{ 3 } (>@g:blinkingField)
		@InitBlinker
		@ProcedureScrollTop
	</Macro>
	<Macro Name="WaypointPagesInit">
		(@g:currentPageWPT) 0 == (@g:currentPageWPT) 1 == (@g:currentPageWPT) 2 == (@g:currentPageWPT) 3 == || || || if{
			(C:fs9gps:WaypointAirportIdent) slen 0 == if{ 0 (>@c:NearestAirportCurrentLine) (@c:NearestAirportCurrentICAO) (>@c:WaypointAirportICAO) }
		}
		(@g:currentPageWPT) 4 == if{
			(@c:WaypointIntersectionIdent) slen 0 == if{ 0 (>@c:NearestIntersectionCurrentLine) (@c:NearestIntersectionCurrentICAO) (>@c:WaypointIntersectionICAO) }
		}
		(@g:currentPageWPT) 5 == if{
			(@c:WaypointNdbIdent) slen 0 == if{ 0 (>@c:NearestNdbCurrentLine) (@c:NearestNdbCurrentICAO) (>@c:WaypointNdbICAO) }
		}
		(@g:currentPageWPT) 6 == if{
			(@c:WaypointVorIdent) slen 0 == if{ 0 (>@c:NearestVorCurrentLine) (@c:NearestVorCurrentICAO) (>@c:WaypointVorICAO) }
		}
		(@g:currentPageWPT) 3 == if{
			@kOff (>@g:selectApproach)
		}
	</Macro>	
	<Macro Name="PageInit">
		(C:fs9gps:currentGroup) 4 == (C:fs9gps:group4currentPage) 0 == &amp;&amp; if{ @ProcedurePageInit }
		(C:fs9gps:currentGroup) 1 == if{ @WaypointPagesInit }
		@RecalcSmallZoom
	</Macro>
	<!-- clear button macros -->
	<Macro Name="CancelInput">
		@InitBlinker 
		(@g:enteringInput) 0 != if{
			(@g:enteringInput) 100 &lt; if{ 
				(@g:enteringInput) 10 == if{ (@c:IcaoSearchInitialIcao) (>@c:WaypointAirportICAO) } 
				(@g:enteringInput) 11 == if{ (@c:IcaoSearchInitialIcao) (>@c:WaypointIntersectionICAO) } 
				(@g:enteringInput) 12 == if{ (@c:IcaoSearchInitialIcao) (>@c:WaypointNdbICAO) } 
				(@g:enteringInput) 13 == if{ (@c:IcaoSearchInitialIcao) (>@c:WaypointVorICAO) } 
				(@g:enteringInput) 31 == if{ (@c:IcaoSearchInitialIcao) (>@c:FacilityICAO) } 
				0 (>@c:IcaoSearchStopCursor) 
			}
			els{
				(@g:enteringInput) 110 == if{ (@c:NameSearchInitialIcao) (>@c:WaypointAirportICAO) } 
				(@g:enteringInput) 131 == if{ (@c:NameSearchInitialIcao) (>@c:FacilityICAO) } 
				0 (>@c:NameSearchStopCursor) 
			}
			0 (>@g:enteringInput)
		}
	</Macro>
	<Macro Name="EscapeMenu">
		@CancelInput
		0 (>@g:blinkingField)
		0 (>@g:popupMenu)
		0 (>@g:listItems)
		0 (>@g:directTo)
		0 (>@g:activateLeg)
		0 (>@g:noOptionMenu)
		@InitBlinker
	</Macro>
	<Macro Name="CLRButtonDelay">25</Macro>
	<Macro Name="CLRALLButton">
		@EscapeMenu
		0 (>@g:messagePopup)
		0 (>@g:setup_ColorTerrain)
		0 (>@g:navPage0DetailLevel)
		0 (>@g:navPage1DetailLevel)
		0 (>@g:map_ZoomStep0)
		0 (>@g:map_ZoomStep1)
		@RecalcSmallZoom
		@kNAVPageGroup (>@g:currentGroup) 0 (>@g:currentPageNAV) @PageInit
	</Macro>
	<Macro Name="MSGButtonDelay">25</Macro>
	<Macro Name="MSGToggle">(@g:messagesOff) ! (>@g:messagesOff)</Macro>
	<Macro Name="FPLEnrouteHeader">(@c:FlightPlanIsActiveFlightPlan) (@c:FlightPlanIsLoadedApproach) and</Macro>
	<Macro Name="FPLLinesCount">
		0
		@FPLEnrouteHeader +
		(@c:FlightPlanIsActiveFlightPlan) if{ (@c:FlightPlanWaypointsNumber) + }
		(@c:FlightPlanIsLoadedApproach) if{ ++ (@c:FlightPlanApproachWaypointsNumber) + }
	</Macro>
	<Macro Name="FPLLineIndex">
		(@c:FlightPlanIsActiveApproach) if{
			(@c:FlightPlanIsActiveFlightPlan) if{ (@c:FlightPlanWaypointsNumber) } els{ 0 }
			++
			(@c:FlightPlanActiveApproachWaypoint) +
		} els{
			(@c:FlightPlanActiveWaypoint) 
		} 
		@FPLEnrouteHeader +
	</Macro>
	<Macro Name="FPLLegalLeg">
		@1
		@FPLEnrouteHeader - 
		sp0
		1 (@c:FlightPlanWaypointsNumber) 1 - l0 rng (@c:FlightPlanIsActiveFlightPlan) and
		(@c:FlightPlanIsActiveFlightPlan) if{ (@c:FlightPlanWaypointsNumber) } els{ 0 } ++ d
			(@c:FlightPlanApproachWaypointsNumber) + 1 - l0 rng (@c:FlightPlanIsLoadedApproach) and
				or
	</Macro>
	<Macro Name="FPLActivateLeg">
		@1
		@FPLEnrouteHeader -
		sp0
		1 (@c:FlightPlanWaypointsNumber) -- l0 rng (@c:FlightPlanIsActiveFlightPlan) and if{
			l0 (>@c:FlightPlanActiveWaypoint)
		}
		els{
			l0 (@c:FlightPlanIsActiveFlightPlan) if{ (@c:FlightPlanWaypointsNumber) } els{ 0 } ++ - sp0
			0 (@c:FlightPlanApproachWaypointsNumber) -- l0 rng (@c:FlightPlanIsLoadedApproach) and if{
				l0 (>@c:FlightPlanActiveApproachWaypoint)
			}
		}		
	</Macro>
	<Macro Name="FPLLegName">
		@1
		@FPLEnrouteHeader -
		sp0
		1 (@c:FlightPlanWaypointsNumber) -- l0 rng (@c:FlightPlanIsActiveFlightPlan) and if{
			l0 (>@c:FlightPlanWaypointIndex) (@c:FlightPlanWaypointIdent)
		}
		els{
			l0 (@c:FlightPlanIsActiveFlightPlan) if{ (@c:FlightPlanWaypointsNumber) } els{ 0 } ++ - sp0
			0 (@c:FlightPlanApproachWaypointsNumber) -- l0 rng (@c:FlightPlanIsLoadedApproach) and if{
				l0 (>@c:FlightPlanWaypointApproachIndex) (@c:FlightPlanWaypointApproachName)
			}
		}		
	</Macro>
	<Macro Name="FPLPrevLegName">
		@1
		@FPLEnrouteHeader -
		sp0
		1 (@c:FlightPlanWaypointsNumber) -- l0 rng (@c:FlightPlanIsActiveFlightPlan) and if{
			l0 -- d 0 >= if{ (>@c:FlightPlanWaypointIndex) (@c:FlightPlanWaypointIdent) } els{ p '' }
		}
		els{
			l0 (@c:FlightPlanIsActiveFlightPlan) if{ (@c:FlightPlanWaypointsNumber) } els{ 0 } ++ - sp0
			0 (@c:FlightPlanApproachWaypointsNumber) -- l0 rng (@c:FlightPlanIsLoadedApproach) and if{
				l0 -- d 0 >= if{ (>@c:FlightPlanWaypointApproachIndex) (@c:FlightPlanWaypointApproachName) } els{ p '' }
			}
		}		
	</Macro>
	<Update Hidden="No">
		<!-- Calculate current mode: 0 no plan 1 en route 2 terminal mode 3 approach -->
		(A:GPS IS ACTIVE WAY POINT, bool) if{
			(A:GPS IS APPROACH ACTIVE, bool) if{
				3
			} els{
				(A:GPS FLIGHT PLAN WP COUNT, number) (A:GPS FLIGHT PLAN WP INDEX, number) ++ == (A:GPS WP DISTANCE, nmiles) s0 30 &lt; and if{ 
					l0 10 &lt; if{ 3 } els{ 2 } 
				} els{ 1 } 
			}
		} els{ 0 }
		(>@g:modeCDI)
		<!-- calculate CDI range -->
		0.3 1 5 0.001 4 (@g:modeCDI) case (@g:scaleCDI) s0 0.1 > if{ l0 - 0.002 min -0.002 max l0 + } (>@g:scaleCDI)
		<!-- calculate default zoom factor for the small map -->
		(@g:directTo) @kOff == (@g:currentGroup) @kWPTPageGroup == (@g:currentPageWPT) 1 == and and (@g:smallmap_ZoomStepDone) 0 == and if{
			(@g:currentAirportRunway) (>@c:WaypointAirportCurrentRunway)
			(@c:WaypointAirportRunwayLength, meters) 0 != if{
				@FitToZoom((@c:WaypointAirportRunwayLength, meters)) (>@g:smallmap_ZoomStep) 
				1 (>@g:smallmap_ZoomStepDone)
			}
		}
		(@g:directTo) @kOff == (@g:currentGroup) @kWPTPageGroup == (@g:currentPageWPT) 3 == and and if{
			(@g:currentAirportApproach) (@c:WaypointAirportApproachesNumber) -- min 0 max (>@g:currentAirportApproach)
			(@g:currentAirportTransition) (@c:WaypointAirportApproachTransitionsNumber) -- min 0 max (>@g:currentAirportTransition)
			(@g:smallmap_ZoomStepDone) 0 == if{
				(@g:currentAirportApproach) (>@c:WaypointAirportCurrentApproach) (@g:currentAirportTransition) (>@c:WaypointAirportApproachCurrentTransition)
				(@c:WaypointAirportApproachTransitionSize, meters) 0 != if{
					@FitToZoom((@c:WaypointAirportApproachTransitionSize, meters)) (>@g:smallmap_ZoomStep) 
					1 (>@g:smallmap_ZoomStepDone)
				}
			}
		}
		<!-- calculate zoom factor range -->
		(@g:map_ZoomStep0) 0 == if{ 13 (>@g:map_ZoomStep0) } 
		(@g:map_ZoomStep1) 0 == if{ 15 (>@g:map_ZoomStep1) } 
		(@g:currentPageNAV) @kNAVPageDflt == if{ (@g:map_ZoomStep0) } els{ (@g:map_ZoomStep1) } (>@g:map_ZoomStep)
		@CalculateZoomFactor((@g:map_ZoomStep)) (>@g:map_ZoomFactor)
		(@g:smallmap_ZoomStep) 0 == if{ 10 (>@g:smallmap_ZoomStep) } @CalculateZoomFactor((@g:smallmap_ZoomStep)) (>@g:smallmap_ZoomFactor)
		<!-- make sure current element exist -->
		0 sp1
		(@g:directTo) 0 == if{ 
			(@g:currentPageWPT) 2 == (@g:currentGroup) @kWPTPageGroup  == and if{ (@c:WaypointAirportFrequenciesNumber) sp1 17 sp2 180 sp3 }
			(@g:currentPageNRST) 0 == (@g:currentGroup) @kNRSTPageGroup  == and if{ (@c:NearestAirportItemsNumber) sp1 38 sp2 177 sp3 }
			(@g:currentPageNRST) 1 == (@g:currentGroup) @kNRSTPageGroup  == and if{ (@c:NearestIntersectionItemsNumber) sp1 17 sp2 177 sp3 }
			(@g:currentPageNRST) 2 == (@g:currentGroup) @kNRSTPageGroup  == and if{ (@c:NearestNdbItemsNumber) sp1 17 sp2 177 sp3 }
			(@g:currentPageNRST) 3 == (@g:currentGroup) @kNRSTPageGroup  == and if{ (@c:NearestVorItemsNumber) sp1 17 sp2 177 sp3 }
			(@g:currentPageNRST) 4 == (@g:currentGroup) @kNRSTPageGroup  == and if{ (@c:NearestAirspaceItemsNumber) sp1 38 sp2 177 sp3 }
			(@g:currentPageFPL) 0 == (@g:currentGroup) @kFPLPageGroup  == and if{ @FPLLinesCount sp1 17 sp2 159 sp3 }
		}
		l1 (>@g:listMaxElements)
		(@g:listCurrent) (@g:listMaxElements) -- min d 0 max (>@g:listCurrent) 0 &lt; if{ 0 (>@g:listItems) }
		<!-- scroll list if neccesary -->
		(@g:listItems) 0 != if{
			l1 l2 * l3 >= <!-- if text is bigger than the area -->
			if{
				:10 (@g:listCurrent) ++ l2 * (@g:listScroll) - 5 + l3 >= if{ (@g:listScroll) l2 + (>@g:listScroll) g10 } <!--scroll down up current is on screen -->
				:11 (@g:listScroll) 0 > (@g:listCurrent) l2 * (@g:listScroll) - 5 - 0 &lt;= and if{ (@g:listScroll) l2 - 0 max (>@g:listScroll) g11 } <!--scroll down until current is on screen -->
			} els{
				0 (>@g:listScroll)
			}
		}
		<!-- calculate list scrollbar -->
		0 (>@g:listScrollbarVisible)
		(@g:listMaxElements) 0 >
		if{
			l1 l2 * l3 >= if{ 
				1 (>@g:listScrollbarVisible)
				l3 8 - d d (>@g:listScrollbarSize)
				l3 l1 l2 * / * (>@g:listScrollbarLength)
				(@g:listScroll) l1 l2 * / * (>@g:listScrollbarOffset) 
			} els{ 
				0 (>@g:listScroll)
			}
		} 
		<!-- scroll menu if neccesary -->
		(@g:popupMenu) 0 != if{
			(@g:popupMenu) @kPopupMenuSelectApproach == if{
				(@c:WaypointAirportApproachesNumber) (>@g:popupMenuMaxElements)
				
				
			}
			(@g:popupMenu) @kPopupMenuSelectTransition == if{
				(@c:WaypointAirportApproachTransitionsNumber) (>@g:popupMenuMaxElements)
				
			}
			(@g:popupMenuCurrent) 0 &lt; if{ 0 (>@g:popupMenuCurrent) }
			(@g:popupMenuCurrent) (@g:popupMenuMaxElements) -- min (>@g:popupMenuCurrent)
			(@g:popupMenuHeaderHeight) (@g:popupMenuMaxElements) (@g:popupMenuLineHeight) 17 * * + (@g:popupMenuHeight) >= 
			if{
				:1 (@g:popupMenuHeaderHeight) (@g:popupMenuCurrent) ++ (@g:popupMenuLineHeight) 17 * * + (@g:popupMenuScroll) - (@g:popupMenuHeight) >= if{ 
					(@g:popupMenuScroll) 17 (@g:popupMenuLineHeight) * + (>@g:popupMenuScroll) g1 }
				:2 (@g:popupMenuScroll) 0 > if{ (@g:popupMenuCurrent) (@g:popupMenuLineHeight) 17 * * (@g:popupMenuScroll) - 0 &lt;= if{ 
					(@g:popupMenuScroll) 17 (@g:popupMenuLineHeight) * - (>@g:popupMenuScroll) g2 } }
			} els{
				0 (>@g:popupMenuScroll)
			}
		}
		<!-- calculate popup menu scrollbar -->
		0 (>@g:popupMenuScrollbarVisible)
		(@g:popupMenuMaxElements) 0 >
		if{
			(@g:popupMenuHeaderHeight) (@g:popupMenuMaxElements) (@g:popupMenuLineHeight) 17 * * + sp1
			(@g:popupMenuHeight) sp3
			l1 l3 >= if{ 
				1 (>@g:popupMenuScrollbarVisible)
				l3 8 - d d (>@g:popupMenuScrollbarSize)
				l3 l1 / * (>@g:popupMenuScrollbarLength)
				(@g:popupMenuScroll) l1 / * (>@g:popupMenuScrollbarOffset) 
			} els{ 
				0 (>@g:popupMenuScroll)
			}
		} 
		<!-- calculate number of blinking fields -->
		0 sp0
		(@g:currentGroup) @kWPTPageGroup == if{
			1 sp0
			(@g:currentPageWPT) @kWPTPageAptLoc == if{ 2 sp0 }
			(@g:currentPageWPT) @kWPTPageAptRun == if{ 2 sp0 }
			(@g:currentPageWPT) @kWPTPageAptApproach == if{ (@g:selectApproach) @kOn == (@g:currentAirportApproach) (@c:WaypointAirportApproachesNumber) &lt; and if{ 5 } els{ 3 } sp0 }
			(@g:currentPageWPT) @kWPTPageNdb == if{ 2 sp0 }
			(@g:currentPageWPT) @kWPTPageVor == if{ 2 sp0 }
		}
		(@g:currentGroup) @kPROCPageGroup == if{ 3 sp0 }
		(@g:directTo) @kOn == if{ 5 sp0 }
		l0 (>@g:numberOfBlinkingFields)
		l0 (@g:blinkingField) min (>@g:blinkingField)
		<!-- enable blinking fields -->	
		(@g:currentGroup) @kPROCPageGroup== if{
			(@c:FlightPlanIsLoadedApproach) d (>@g:blinkingFieldEnabled1) (>@g:blinkingFieldEnabled2)
		}
		<!-- update pages while typing -->
		(@g:enteringInput) 10 == if{ (@c:IcaoSearchCurrentIcao) (>@c:WaypointAirportICAO) }
		(@g:enteringInput) 11 == if{ (@c:IcaoSearchCurrentIcao) (>@c:WaypointIntersectionICAO) }
		(@g:enteringInput) 12 == if{ (@c:IcaoSearchCurrentIcao) (>@c:WaypointNdbICAO) }
		(@g:enteringInput) 13 == if{ (@c:IcaoSearchCurrentIcao) (>@c:WaypointVorICAO) }
		(@g:enteringInput) 31 == if{ (@c:IcaoSearchCurrentIcao) (>@c:FacilityICAO) }
		(@g:enteringInput) 110 == if{ (@c:NameSearchCurrentIcao) (>@c:WaypointAirportICAO) }
		(@g:enteringInput) 131 == if{ (@c:NameSearchCurrentIcao) (>@c:FacilityICAO) }
		<!-- update coords for the nearest pages -->
		(A:GPS POSITION LAT, Radians) (>@c:NearestAirportCurrentLatitude, Radians) (A:GPS POSITION LON, Radians) (>@c:NearestAirportCurrentLongitude, Radians) 9 (>@c:NearestAirportMaximumItems) 200 (>@c:NearestAirportMaximumDistance, NMiles) 
		(A:GPS POSITION LAT, Radians) (>@c:NearestIntersectionCurrentLatitude, Radians) (A:GPS POSITION LON, Radians) (>@c:NearestIntersectionCurrentLongitude, Radians) 9 (>@c:NearestIntersectionMaximumItems) 200 (>@c:NearestIntersectionMaximumDistance, NMiles)
		(A:GPS POSITION LAT, Radians) (>@c:NearestNdbCurrentLatitude, Radians) (A:GPS POSITION LON, Radians) (>@c:NearestNdbCurrentLongitude, Radians) 9 (>@c:NearestNdbMaximumItems) 200 (>@c:NearestNdbMaximumDistance, NMiles)
		(A:GPS POSITION LAT, Radians) (>@c:NearestVorCurrentLatitude, Radians) (A:GPS POSITION LON, Radians) (>@c:NearestVorCurrentLongitude, Radians) 9 (>@c:NearestVorMaximumItems) 200 (>@c:NearestVorMaximumDistance, NMiles)
		(A:GPS POSITION LAT, Radians) (>@c:NearestAirspaceCurrentLatitude, Radians) (A:GPS POSITION LON, Radians) (>@c:NearestAirspaceCurrentLongitude, Radians) (A:GPS POSITION ALT, Meters) (>@c:NearestAirspaceCurrentAltitude, Meters)
			(A:GPS GROUND TRUE TRACK, Radians) (>@c:NearestAirspaceTrueGroundTrack, Radians) (A:GPS GROUND SPEED, knots) (>@c:NearestAirspaceGroundSpeed, knots) 
			2 (>@c:NearestAirspaceNearDistance, nmiles) 200 (>@c:NearestAirspaceNearAltitude, feet) 10 (>@c:NearestAirspaceAheadTime, minutes)
			9 (>@c:NearestAirspaceMaximumItems) 100 (>@c:NearestAirspaceMaximumDistance, NMiles)
			@kDisplayedAirspaces (>@c:NearestAirspaceQuery)
		<!-- check CLR button -->
		(@g:clrButtonDown) 0 != if{
			(@g:clrButtonCount) ++ d (>@g:clrButtonCount) @CLRButtonDelay == if{ @CLRALLButton }
		}
		<!-- check MSG button -->
		(@g:msgButtonDown) 0 != if{
			(@g:msgButtonCount) ++ d (>@g:msgButtonCount) @MSGButtonDelay == if{ @MSGToggle }
		}
		
	</Update>

	
	

	
	
	
	


	<!-- Nav Group -->
	<!-- Map view -->
	<Element Name="MapView Pages">
        <Visible>(L:Range On Off, bool)</Visible>
			<Position X="0" Y="0"/>
			<CustomDraw Name="fs9gps:map" X="396" Y="386" LayerTerrain="Yes" LayerBorders="No" LayerFlightPlan="Yes" FlightPlanLineWidth="4" ActiveColorLayerFlightPlan="0x7010B0" PastColorLayerFlightPlan="0xF0F0F0" ColorLayerFlightPlan="0xF0F0F0" Bright="Yes" CenterX="198" CenterY="320">
				<Zoom>(@g:map_ZoomFactor) 1425.0 *</Zoom>
				<Latitude>(A:GPS POSITION LAT, Radians)</Latitude>
				<Longitude>(A:GPS POSITION LON, Radians)</Longitude>
				<Heading>(A:GPS GROUND TRUE TRACK, Radians)</Heading>
				<DetailLayerTerrain>(@g:setup_ColorTerrain) 0 == if{ 1 } els{ 2 }</DetailLayerTerrain>
				<LayerAirports>(@g:map_ZoomFactor) 500 &lt; 3 (@g:currentPageNAV) @kNAVPageDflt == if{ (@g:navPage0DetailLevel) } els{ (@g:navPage1DetailLevel) } > and</LayerAirports>
				<LayerVORs>(@g:map_ZoomFactor) 200 &lt; 2 (@g:currentPageNAV) @kNAVPageDflt == if{ (@g:navPage0DetailLevel) } els{ (@g:navPage1DetailLevel) } > and</LayerVORs>
				<LayerILSs>(@g:map_ZoomFactor) 50 &lt; 2 (@g:currentPageNAV) @kNAVPageDflt == if{ (@g:navPage0DetailLevel) } els{ (@g:navPage1DetailLevel) } > and</LayerILSs>
				<LayerNDBs>(@g:map_ZoomFactor) 100 &lt; 2 (@g:currentPageNAV) @kNAVPageDflt == if{ (@g:navPage0DetailLevel) } els{ (@g:navPage1DetailLevel) } > and</LayerNDBs>
				<LayerIntersections>(@g:map_ZoomFactor) 100 &lt; 2 (@g:currentPageNAV) @kNAVPageDflt == if{ (@g:navPage0DetailLevel) } els{ (@g:navPage1DetailLevel) } > and</LayerIntersections>
				<LayerAirspaces>0</LayerAirspaces>
				<ObjectDetailLayerAirspaces>(@g:currentPageNAV) @kNAVPageDflt == if{ (@g:navPage0DetailLevel) } els{ (@g:navPage1DetailLevel) } 1 >= if{ @kAlwaysDisplayedAirspaces } els{ @kDisplayedAirspaces }</ObjectDetailLayerAirspaces>
				<ColorLayerAirspaces>(@g:setup_ColorTerrain) 0 == if{ 0x808080 } els{ 0xFFFFFF }</ColorLayerAirspaces>
				<ObjectDetailLayerAirports>0 0 0 0 0 0 0x5 0x5 0x7 0x7 0x1F 0x1F 0x1F 0x1F 0x4F 0x4F 0x4F 0x4F 0x4F 0x4F 0x4F 0x4F 0x4F 0x4F 24 (@g:map_ZoomStep) case</ObjectDetailLayerAirports>
				<TextDetailLayerAirports>0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 24 (@g:map_ZoomStep) case</TextDetailLayerAirports>
				<TextDetailLayerVORs>0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 24 (@g:map_ZoomStep) case</TextDetailLayerVORs>
				<TextDetailLayerILSs>0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 24 (@g:map_ZoomStep) case</TextDetailLayerILSs>
				<TextDetailLayerNDBs>0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 24 (@g:map_ZoomStep) case</TextDetailLayerNDBs>
				<TextDetailLayerIntersections>0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 24 (@g:map_ZoomStep) case</TextDetailLayerIntersections>
				<ObjectDetailLayerFlightPlan>0xE 0xF (@c:FlightPlanIsActiveApproach) ?</ObjectDetailLayerFlightPlan>
				<TrackUp>(@g:currentPageNAV) @kNAVPageDflt ==</TrackUp>
			</CustomDraw>
	</Element>






	<Mouse Name="MouseRoutines">
		<!-- TERR Button -->
		<Macro Name="TerrainButton">@EscapeMenu (@g:setup_ColorTerrain) ! (>@g:setup_ColorTerrain)</Macro>
		<Area Name="TERR Button" Left="264" Top="313" Width="34" Height="21">
			<Click Kind="LeftSingle+Leave">
				(M:Event) 'LeftSingle' scmp 0 == (@g:terrButtonDown) 0 == and if{ 1 (>@g:terrButtonDown) @TerrainButton }
				(M:Event) 'Leave' scmp 0 == (@g:terrButtonDown) 1 == and if{ 0 (>@g:terrButtonDown) }
			</Click>
			<Cursor Type="Hand"/>
			<Tooltip ID="TOOLTIPTEXT_GPS_TERR_BUTTON"/>
		</Area>


		<!-- CLR/QUIT Button -->
		<Macro Name="CLRButton">
			@InitBlinker
			
			<!-- if message popup on screen, close and quit -->
			(@g:messagePopup) @kOn == if{
				@kOff (>@g:messagePopup)
				quit
			}

			(@g:noOptionMenu) 0 != if{
				0 (>@g:noOptionMenu)
				quit
			}
			(@g:popupMenu) 0 != if{
				@CancelPopupMenu
				quit
			}
			(@g:enteringInput) 0 != if{
				@CancelInput
				quit
			}
			(@g:activateLeg) 0 != if{
				0 (>@g:activateLeg)
				quit
			}
			(@g:directTo) 0 != if{
				0 (>@g:directTo)
				quit
			}
			(@g:blinkingField) 0 != (@g:listItems) 0 != || if{
				0 (>@g:blinkingField)
				0 (>@g:listItems)
				quit
			}
			
			<!-- if waypoint selected on FPL screen, delete waypoint -->
			(@g:currentGroup) @kFPLPageGroup == (@g:listCurrent) 0 > and if{
				quit
			}
				
			<!-- if navmap (either one) is displayed, declutter -->
			(@g:currentGroup) @kNAVPageGroup == if{
				(@g:currentPageNAV) 0 == if{
					0 2 (@g:navPage0DetailLevel) rng if{ (@g:navPage0DetailLevel) ++ (>@g:navPage0DetailLevel) } els{ 0 (>@g:navPage0DetailLevel) }
					quit
				}

				(@g:currentPageNAV) 1 == if{
					0 2 (@g:navPage1DetailLevel) rng if{ (@g:navPage1DetailLevel) ++ (>@g:navPage1DetailLevel) } els{ 0 (>@g:navPage1DetailLevel) }
					quit
				}
			}
			@EscapeMenu
			(@g:currentGroup) @kPROCPageGroup == if{ @kNavPageGroup (>@g:currentGroup) @PageInit }
		</Macro>
		<Area Name="CLR/QUIT Button" Left="405" Top="198" Width="34" Height="21">
			<Click Kind="LeftSingle+Leave">
				(M:Event) 'LeftSingle' scmp 0 == if{ (@g:clrButtonDown) 0 == if{ 1 (>@g:clrButtonDown) 0 (>@g:clrButtonCount) } }
				(M:Event) 'Leave' scmp 0 == if{ (@g:clrButtonDown) 1 == if{ 0 (>@g:clrButtonDown) (@g:clrButtonCount) @CLRButtonDelay &lt; if{ @CLRButton } } }
			</Click>
			<Cursor Type="Hand"/>
			<Tooltip ID="TOOLTIPTEXT_GPS_CLR_BUTTON"/>
		</Area>


		<!-- Range Button -->
		<Macro Name="ZOOMINButton">
					(@g:directTo) 0 == (@g:currentGroup) @kNAVPageGroup  == (@g:currentPageNAV) 0 == and and if{
						(@g:map_ZoomStep0) -- 1 max (>@g:map_ZoomStep0)
					}
					(@g:directTo) 0 == (@g:currentGroup) @kNAVPageGroup  == (@g:currentPageNAV) 1 == and and if{
						(@g:map_ZoomStep1) -- 1 max (>@g:map_ZoomStep1)
					}
					(@g:directTo) 0 == (@g:currentGroup) @kWPTPageGroup  == (@g:currentPageWPT) 1 == (@g:currentPageWPT) 3 == || and and if{
						(@g:smallmap_ZoomStep) -- 1 max (>@g:smallmap_ZoomStep)
					}
		</Macro>
		<Macro Name="ZOOMOUTButton">
					(@g:directTo) 0 == (@g:currentGroup) @kNAVPageGroup  == (@g:currentPageNAV) 0 == and and if{
						(@g:map_ZoomStep0) ++ 20 min (>@g:map_ZoomStep0)
					}
					(@g:directTo) 0 == (@g:currentGroup) @kNAVPageGroup  == (@g:currentPageNAV) 1 == and and if{
						(@g:map_ZoomStep1) ++ 20 min (>@g:map_ZoomStep1)
					}
					(@g:directTo) 0 == (@g:currentGroup) @kWPTPageGroup  == (@g:currentPageWPT) 1 == (@g:currentPageWPT) 3 == || and and if{
						(@g:smallmap_ZoomStep) ++ 18 min (>@g:smallmap_ZoomStep)
					}
		</Macro>
		<Area Name="RNG Button" Left="410" Top="46" Width="28" Height="70">
			<Area Name="RNG Out" Top="35" GpsSpecific="Y">
				<Click Kind="LeftSingle+Leave">
					(M:Event) 'LeftSingle' scmp 0 == (@g:zoominButtonDown) 0 == and if{ 1 (>@g:zoominButtonDown) @ZOOMINButton }
					(M:Event) 'Leave' scmp 0 == (@g:zoominButtonDown) 1 == and if{ 0 (>@g:zoominButtonDown) }
				</Click>
				<Cursor Type="UpArrow"/>
				<Tooltip ID="TOOLTIPTEXT_GPS_RANGE_UP"/>
			</Area>
			<Area Name="RNG In" Bottom="35" GpsSpecific="Y">
				<Click Kind="LeftSingle+Leave">
					(M:Event) 'LeftSingle' scmp 0 == (@g:zoomoutButtonDown) 0 == and if{ 1 (>@g:zoomoutButtonDown) @ZOOMOUTButton }
					(M:Event) 'Leave' scmp 0 == (@g:zoomoutButtonDown) 1 == and if{ 0 (>@g:zoomoutButtonDown) }
				</Click>
				<Cursor Type="DownArrow"/>
				<Tooltip ID="TOOLTIPTEXT_GPS_RANGE_DOWN"/>
			</Area>
		</Area>
	</Mouse>






	<Keys>
		<On Event="GPS_NEAREST_BUTTON">@NRSTButton</On>
		<On Event="GPS_OBS_BUTTON">@OBSButton</On>
		<On Event="GPS_MSG_BUTTON">@MSGButton</On>	
		<On Event="GPS_FLIGHTPLAN_BUTTON">@FPLButton</On>
		<On Event="GPS_TERRAIN_BUTTON">@TerrainButton</On>
		<On Event="GPS_PROCEDURE_BUTTON">@PROCButton</On>
		<On Event="GPS_ZOOMIN_BUTTON">@ZOOMINButton</On>
		<On Event="GPS_ZOOMOUT_BUTTON">@ZOOMOUTButton</On>
		<On Event="GPS_DIRECTTO_BUTTON">@DTOButton</On>
		<On Event="GPS_MENU_BUTTON">@MENUButton</On>
		<On Event="GPS_CLEAR_BUTTON">@CLRButton</On>
		<On Event="GPS_CLEAR_ALL_BUTTON">@CLRALLButton</On>
		<On Event="GPS_ENTER_BUTTON">@ENTButton</On>
		<On Event="GPS_CURSOR_BUTTON">@PushCRSRButton</On>
		<On Event="GPS_GROUP_KNOB_INC">@TopRightKnob</On>
		<On Event="GPS_GROUP_KNOB_DEC">@TopLeftKnob</On>
		<On Event="GPS_PAGE_KNOB_INC">@BottomRightKnob</On>
		<On Event="GPS_PAGE_KNOB_DEC">@BottomLeftKnob</On>
		<On Key="AlphaNumeric">
			<Visible>10 19 (C:fs9gps:enteringInput) rng 31 (C:fs9gps:enteringInput) == or</Visible>
			(M:Key) chr (>C:fs9gps:IcaoSearchEnterChar) @InitBlinker
		</On>
		<On Key="Ascii">
			<Visible>110 119 (C:fs9gps:enteringInput) rng 131 (C:fs9gps:enteringInput) == or</Visible>
			(M:Key) chr (>C:fs9gps:NameSearchEnterChar) @InitBlinker
		</On>
		<On Key="Backspace">
			<Visible>(C:fs9gps:enteringInput)</Visible>
			10 19 (C:fs9gps:enteringInput) rng 31 (C:fs9gps:enteringInput) == || if{ -1 (>C:fs9gps:IcaoSearchBackupChar) @InitBlinker quit }
			110 119 (C:fs9gps:enteringInput) rng 131 (C:fs9gps:enteringInput) == || if{ -1 (>C:fs9gps:NameSearchBackupChar) @InitBlinker quit }
		</On>
		<On Event="GPS_CLEAR_BUTTON_DOWN">(@g:clrButtonDown) 0 == if{ 1 (>@g:clrButtonDown) 0 (>@g:clrButtonCount) }</On>
		<On Event="GPS_CLEAR_BUTTON_UP">(@g:clrButtonDown) 1 == if{ 0 (>@g:clrButtonDown) (@g:clrButtonCount) @CLRButtonDelay &lt; if{ @CLRButton } }</On>
		<On Event="GPS_MSG_BUTTON_DOWN">(@g:msgButtonDown) 0 == if{ 1 (>@g:msgButtonDown) 0 (>@g:msgButtonCount) }</On>
		<On Event="GPS_MSG_BUTTON_UP">(@g:msgButtonDown) 1 == if{ 0 (>@g:msgButtonDown) (@g:msgButtonCount) @MSGButtonDelay &lt; if{ @MSGButton } }</On>
	</Keys>




      <Element>
         <Visible>(L:Nav Display Switch, bool) !</Visible>
         <Element>
            <Position X="0" Y="0"/>
            <Image Name="nd2_bkgrnd.bmp" Bright="Yes" ImageSizes="396,386,0,0"/>
            <Element>
               <Position X="184" Y="1"/>
               <Text X="62" Y="24" Bright="Yes" Length="3" Font="Arial" Color="White" Adjust="Center" VerticalAdjust="Bottom" Multiline="No" Fixed="Yes">
                  <Axis X="15" Y="0"/>
                  <String>%(360 (A:Plane heading degrees gyro, degrees) dnor near d 0 == ?)%!03d!</String>
               </Text>
            </Element>
            <Element>
               <Position X="197" Y="320"/>
               <Image Name="nd2_expanded_rose.bmp" Bright="Yes" ImageSizes="569,569,0,0">
                  <Axis X="284.5" Y="284.5"/>
               </Image>
               <Rotate>
                  <Value>(A:Plane heading degrees gyro, radians) /-/</Value>
               </Rotate>
               <Clip Left="0" Right="396" Top="40" Bottom="321"/>
            </Element>
            <Element>
               <Visible>(L:ND track, bool)</Visible>
               <Position X="197" Y="320"/>
               <Image Name="nd2_track.bmp" Bright="Yes" ImageSizes="11,246,0,0">
                  <Axis X="5.5" Y="246"/>
               </Image>
               <Rotate>
                  <Value>(A:Velocity world X, m/s) (A:Velocity world Z, m/s) atg2 (A:Magvar, radians) - (A:Plane heading degrees gyro, radians) - </Value>
               </Rotate>
               <Clip Left="0" Right="396" Top="70" Bottom="321"/>
            </Element>
            <Element>
               <Visible>1 (A:Nav2 has nav, bool) (L:VOR2 switch, bool) !</Visible>
               <Position X="197" Y="320"/>
               <Image Name="nd2_vor_arrow.bmp" Bright="Yes" PointsTo="West" ImageSizes="33,569,0,0">
                  <Axis X="16.5" Y="284.5"/>
               </Image>
               <Rotate>
                  <Value>(A:NAV2 radial, radians) (A:Plane heading degrees gyro, radians) - pi +</Value>
               </Rotate>
               <Clip Left="0" Right="396" Top="42" Bottom="210"/>
            </Element>
            <Element>
               <Visible>(A:ADF1 signal, number) 0 &gt; (L:ADF switch, bool) !</Visible>
               <Position X="197" Y="320"/>
               <Image Name="nd2_adf_arrow.bmp" Bright="Yes" PointsTo="West" ImageSizes="33,569,0,0">
                  <Axis X="16.5" Y="284.5"/>
               </Image>
               <Rotate>
                  <Value>(A:ADF1 radial, radians)</Value>
               </Rotate>
               <Clip Left="0" Right="396" Top="42" Bottom="210"/>
            </Element>
            <Element>
               <Position X="197" Y="320"/>
               <Image Name="nd2_heading_bug.bmp" Bright="Yes" ImageSizes="29,11,0,0">
                  <Axis X="14.5" Y="290"/>
               </Image>
               <Rotate>
                  <Value>(A:Autopilot heading lock dir, radians) (A:Plane heading degrees gyro, radians) -</Value>
               </Rotate>
               <Clip Left="0" Right="396" Top="20" Bottom="321"/>
            </Element>
            <Element>
               <Visible>(L:ND strack, bool) !</Visible>
               <Position X="197" Y="320"/>
               <Image Name="nd2_staple_track.bmp" Bright="Yes" ImageSizes="11,340,0,0">
                  <Axis X="5.5" Y="277"/>
               </Image>
               <Rotate>
                  <Value>(A:NAV1 OBS, radians) (A:Plane heading degrees gyro, radians) -</Value>
               </Rotate>
               <Clip Left="0" Right="396" Top="20" Bottom="386"/>
            </Element>
            <Element>
               <Visible>(A:HSI CDI needle valid, bool) (L:VOR1 loc switch, bool) !</Visible>
               <Clip/>
               <Position X="197" Y="320"/>
               <Image Name="nd2_localizer_bkgrnd.bmp" Bright="Yes" ImageSizes="175,19,0,0">
                  <Axis X="87.5" Y="9.5"/>
               </Image>
               <Rotate>
                  <Value>(A:NAV1 OBS, radians) (A:Plane heading degrees gyro, radians) -</Value>
               </Rotate>
            </Element>
            <Element>
               <Visible>(A:HSI CDI needle valid, bool) (L:VOR1 loc switch, bool) !</Visible>
               <Position X="197" Y="320"/>
               <Select>
                  <Value>(A:HSI has localizer, bool) 0 !=</Value>
                  <Case Value="0">
                     <Image Name="nd2_hsi_cdi_hollow.bmp" Bright="Yes" ImageSizes="13,85,0,0">
                        <Axis X="6.5" Y="42.5"/>
                     </Image>
                  </Case>
                  <Case Value="1">
                     <Image Name="nd2_hsi_cdi_hollow.bmp" Bright="Yes" ImageSizes="13,85,0,0">
                        <Axis X="6.5" Y="42.5"/>
                     </Image>
                  </Case>
               </Select>
               <Shift>
                  <Value>(A:HSI CDI needle valid,bool) if{ (A:HSI CDI needle,number)  } els{ 0 }</Value>
                  <Scale X="0.61"><!--31/127 == 0.61--></Scale>
               </Shift>
               <Rotate>
                  <Value>(A:NAV1 OBS, radians) (A:Plane heading degrees gyro, radians) -</Value>
               </Rotate>
               <Clip/>
            </Element>
            <Element>
               <Position X="197" Y="320"/>
               <Image Name="nd2_ownship.bmp" Bright="Yes" ImageSizes="29,37,0,0">
                  <Axis X="14.5" Y="0"/>
               </Image>
            </Element>
         </Element>
         <Element>
            <Position X="367" Y="211"/>
            <Visible>(A:HSI GSI needle valid, bool) (L:VOR1 gs switch, bool) !</Visible>
            <Image Name="nd_glideslope_bkgrnd.bmp" Bright="Yes" ImageSizes="13,117,0,0">
               <Axis X="1" Y="58.5"/>
            </Image>
            <Element>
               <Image Name="nd_glideslope_needle.bmp" Bright="Yes" ImageSizes="13,21,0,0">
                  <Axis X="0" Y="10.5"/>
               </Image>
               <Shift>
               <Value Minimum="-1" Maximum="1">(A:HSI GSI needle, number) 120 /</Value>
               <Nonlinearity>
                  <Item Value="-1" X="0" Y="-49"/>
                  <Item Value="0" X="0" Y="0"/>
                  <Item Value="1" X="0" Y="49"/>
               </Nonlinearity>
               </Shift>
            </Element>
         </Element>
      </Element>
      <Element>
         <Visible>(L:ND radio, bool) !</Visible>
         <Position X="4" Y="10"/>
         <Element>
            <Position X="0" Y="0"/>
            <Text X="75" Y="18" Bright="Yes" Length="10" Font="Arial" Color="#00ccff" Adjust="Left" VerticalAdjust="Bottom" Multiline="No">
               <Axis X="0" Y="0"/>
               <String>%((A:Adf1 active frequency, KHz))%!6.2f!</String>
            </Text>
         </Element>
         <Element>
            <Visible>(A:Ambient wind velocity, knots) 0 ></Visible> 
            <Element>
               <Position X="0" Y="19"/>
               <Text X="38" Y="18" Bright="Yes" Length="12" Font="Arial" Color="#9999FF" Adjust="Left" VerticalAdjust="Bottom" Multiline="No">
                  <String>%((A:Ambient wind direction, degrees) (A:Plane heading degrees gyro, degrees) - near d s0 0 &lt; if{ l0 360 + } els{ l0 } )%!03d!&#176;</String>
               </Text>
            </Element>
            <Element>
               <Position X="33" Y="19" /> 
               <Text X="65" Y="18" Bright="Yes" Length="12" Font="Arial" Color="#9900CC" Adjust="Left" VerticalAdjust="Bottom" Multiline="No">
                  <String>/%((A:Ambient wind velocity, knots))%!3d!KTS</String> 
               </Text>
            </Element>
         </Element>
         <Element>
            <Visible>(A:Ambient wind velocity, knots) 0 &gt;</Visible>
            <Element>
               <Position X="20" Y="52" />
               <Image Name="nd2_wind_arrow.bmp" Bright="Yes" ImageSizes="40,40,0,0">
                  <Axis X="20" Y="20" /> 
               </Image>
               <Rotate>
                  <Value>(A:Ambient wind direction, radians) (A:Plane heading degrees gyro, radians) - </Value> 
               </Rotate>
            </Element>
         </Element>
      </Element>
      <Element>
         <Visible>(L:ND radio, bool) !</Visible>
         <Position X="4" Y="324"/>
         <Element>
            <Position X="0" Y="0"/>
            <Visible>(A:Nav1 signal, bool)</Visible>
            <Text X="80" Y="18" Bright="Yes" Length="12" Font="Arial" Color="#60FF60" Adjust="Left" VerticalAdjust="Bottom" Multiline="No">
               <Axis X="0" Y="0"/>
               <String>VOR1</String>
            </Text>
         </Element>
         <Element>
            <Position X="0" Y="16"/>
            <Text X="80" Y="18" Bright="Yes" Length="12" Font="Arial" Color="#60FF60" Adjust="Left" VerticalAdjust="Bottom" Multiline="No">
               <Axis X="0" Y="0"/>
               <String>%((A:GPS drives nav1, bool))%{if}GPS%{else}%((A:Nav1 ident, string))%!s!%{end}</String>
            </Text>
         </Element>
         <Element>
            <Position X="0" Y="32"/>
            <Visible>(A:Adf1 signal, bool)</Visible>
            <Text X="80" Y="18" Bright="Yes" Length="12" Font="Arial" Color="#00ccff" Adjust="Left" VerticalAdjust="Bottom" Multiline="No">
               <Axis X="0" Y="0"/>
               <String>ADF</String>
            </Text>
         </Element>
         <Element>
            <Position X="0" Y="48"/>
            <Text X="80" Y="18" Bright="Yes" Length="12" Font="Arial" Color="#00ccff" Adjust="Left" VerticalAdjust="Bottom" Multiline="No">
               <Axis X="0" Y="0"/>
               <String>%((A:Adf1 active frequency, KHz))%!6.2f!</String>
            </Text>
         </Element>
      </Element>
      <Element>
         <Visible>(L:ND radio, bool) !</Visible>
         <Position X="312" Y="10"/>
         <Element>
            <Position X="0" Y="0"/>
            <Visible>(A:NAV1 SIGNAL,bool)</Visible>
            <Text X="79" Y="18" Bright="Yes" Length="12" Font="Arial" Color="#ff99ff" Adjust="Right" VerticalAdjust="Bottom" Multiline="No">
               <Axis X="0" Y="0"/>
               <String>% %((A:Nav1 active frequency, MHz))%!6.2f!</String>
            </Text>
         </Element>
         <Element>
            <Position X="0" Y="18"/>
            <Text X="75" Y="18" Bright="Yes" Length="12" Font="Arial" Color="#ffffff" Adjust="Right" VerticalAdjust="Bottom" Multiline="No">
               <Axis X="0" Y="0"/>
               <String>%((A:GPS drives nav1, bool))%{if}GPS%{else}DME%{end} %((A:HSI distance, nmiles) s1 0 &gt;=)%{if}%(l1 100 &gt;=)%{if}%(l1)%!d!%{else}%(l1)%!0.1f!%{end}%{else}----%{end}</String>
            </Text>
         </Element>
      </Element>
      <Element>
         <Visible>(L:ND radio, bool) !</Visible>
         <Position X="312" Y="324"/>
         <Element>
            <Position X="0" Y="0"/>
            <Visible>(A:Nav2 signal,bool)</Visible>
            <Text X="80" Y="18" Bright="Yes" Length="12" Font="Arial" Color="#60FF60" Adjust="Right" VerticalAdjust="Bottom" Multiline="No">
               <Axis X="0" Y="0"/>
               <String>VOR2</String>
            </Text>
         </Element>
         <Element>
            <Position X="0" Y="15"/>
            <Text X="80" Y="18" Bright="Yes" Length="12" Font="Arial" Color="#60FF60" Adjust="Right" VerticalAdjust="Bottom" Multiline="No">
               <Axis X="0" Y="0"/>
               <String>%((A:GPS drives nav1, bool))%{if}GPS%{else}%((A:Nav2 ident, string))%!s!%{end}</String>
            </Text>
         </Element>
         <Element>
            <Position X="0" Y="33"/>
            <Text X="80" Y="18" Bright="Yes" Length="12" Font="Arial" Color="#60FF60" Adjust="Right" VerticalAdjust="Bottom" Multiline="No">
               <Axis X="0" Y="0"/>
               <String>%((A:Nav2 active frequency, MHz))%!6.2f!</String>
            </Text>
         </Element>
         <Element>
            <Position X="0" Y="48"/>
            <Text X="80" Y="18" Bright="Yes" Length="12" Font="Arial" Color="#60FF60" Adjust="Right" VerticalAdjust="Bottom" Multiline="No">
               <Axis X="0" Y="0"/>
               <String>%((A:GPS drives nav1, bool))%{if}GPS%{else}DME%{end} %((A:Nav2 dme, nmiles) s1 0 &gt;=)%{if}%(l1 100 &gt;=)%{if}%(l1)%!d!%{else}%(l1)%!0.1f!%{end}%{else}----%{end}</String>
            </Text>
         </Element>
      </Element>
</Gauge>
