//////////////////////////////////////////////////////////////////////////////// // // THIS CODE IS NOT APPROVED FOR USE IN/ON ANY OTHER UI ELEMENT OR PRODUCT COMPONENT. // Copyright (c) 2009 Microsoft Corporation. All rights reserved. // //////////////////////////////////////////////////////////////////////////////// var gGadgetMode = (window.System !== undefined); var gBIDIMode = (document.dir=='rtl'); //////////////////////////////////////////////////////////////////////////////// // // PICKLIST UTILITIES for use on SELECT Lists // //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // // DoAdd(object oPickList, string anOptionValue, OPTIONAL string anOptionText) // Adds an Option to passed-in oPickList (SELECT Object) // //////////////////////////////////////////////////////////////////////////////// function DoAdd(oPickList, anOptionValue, anOptionText) { if (oPickList && anOptionValue.length) { var anOption = new Option; anOption.value = anOptionValue; // If we've been given a display value different than the option value, use it if (anOptionText) { anOption.text = anOptionText; } else { anOption.text = anOptionValue; } if (oPickList.selectedIndex > -1) { // If something is selected, then insertion point is below that item // Insert new option above currently selected row oPickList.add(anOption, oPickList.selectedIndex); // Set selectedIndex of Picklist to newly inserted item oPickList.selectedIndex -= 1; } else { oPickList.add(anOption); oPickList.selectedIndex = DoFindIndex(oPickList, anOption.value); } } } //////////////////////////////////////////////////////////////////////////////// // // DoRemoveOption(object oPickList, OPTIONAL int anOptionIndex) // Removes option from passed-in Select List. Default is to remove Selected- // Index but fn also accepts literal index in OPTIONAL param anOptionIndex // //////////////////////////////////////////////////////////////////////////////// function DoRemoveOption(oPickList, anOptionIndex) { var selectedItem = anOptionIndex; if (anOptionIndex===undefined) { selectedItem = oPickList.selectedIndex; } if (selectedItem > -1) { oPickList.options[selectedItem] = null; } // Set selectedIndex of Picklist to item above the one just removed // (or to the top of the list if we were already there) if (selectedItem>0) { oPickList.selectedIndex = selectedItem-1; } else { oPickList.selectedIndex = 0; } } //////////////////////////////////////////////////////////////////////////////// // // DoMoveUp(object oPickList) - Moves the currently selected option from // passed-in Select List Up one line // //////////////////////////////////////////////////////////////////////////////// function DoMoveUp(oPickList) { var selectedItem = oPickList.selectedIndex; if (selectedItem > 0) { // If we're not already at the top of the list ... var theOption = oPickList[selectedItem]; var theOptionB4 = oPickList[selectedItem-1]; for (prop in theOption) { if ((prop=="text") || (prop=="value")) { // Swap the salient properties of the two options var theOptionProp = theOption[prop]; theOption[prop] = theOptionB4[prop]; theOptionB4[prop] = theOptionProp; } } oPickList.selectedIndex = selectedItem - 1; } } //////////////////////////////////////////////////////////////////////////////// // // DoMoveDown(object oPickList) - Moves the currently selected option from // passed-in Select List Up one line // //////////////////////////////////////////////////////////////////////////////// function DoMoveDown(oPickList) { var selectedItem = oPickList.selectedIndex; if ( (selectedItem > -1) && (selectedItem < oPickList.length-1) ) { var theOption = oPickList[selectedItem]; var theOptionB4 = oPickList[selectedItem+1]; for (prop in theOption) { if ((prop=="text") || (prop=="value")) { // Swap the salient properties of the two options var theOptionProp = theOption[prop]; theOption[prop] = theOptionB4[prop]; theOptionB4[prop] = theOptionProp; } } oPickList.selectedIndex = selectedItem + 1; } } //////////////////////////////////////////////////////////////////////////////// // // DoFindIndex(object oPickList, string anOptionValue, string anOptionText) // returns index value from a passed-in oPickList for either an // optionValue or optionText (both OPTIONAL) // //////////////////////////////////////////////////////////////////////////////// function DoFindIndex(oPickList, anOptionValue, anOptionText) { var theIndex = -1; if (oPickList.length) { for (var i=0; i -1) { // If we have a number with decimal places, save off the value to the // right of the decimal place for later use theDecimalValue = aNumber.substring(aNumber.lastIndexOf("."), aNumber.length); // Strip off the decimal portion of the number retVal = retVal.substring(0, retVal.lastIndexOf(".")); } // Reverse the number var aNewNumber = ""; for (var i=0;i= -90) && (report.Latitude <= 90) && (report.Longitude <= 180) && (report.Longitude >= -180) ) ) { throw "Latitude/Longitude outside acceptable range"; } return report; } //////////////////////////////////////////////////////////////////////////////// // // getAPIStatus( ) - returns current status from location API // in case of exception, returns -1 //////////////////////////////////////////////////////////////////////////////// function getAPIStatus( MicrosoftGadgetObject ) { var status = -1; try { status = MicrosoftGadgetObject.factory.Status; } catch ( err ) { System.Debug.outputString ( "API returned error, polling for status. Gadget state indeterminate" ); } return status; } //////////////////////////////////////////////////////////////////////////////// // // DistanceMovedSinceLastPositionUpdate( ) - returns distance since last position update //////////////////////////////////////////////////////////////////////////////// function DistanceMovedSinceLastPositionUpdate(positionPrevious, positionCurrent) { // KNOWN CONSTANTS var degreesToRadians = Math.PI / 180; var earthRadius = 6371; // approximation in kilometers assuming earth to be spherical // CONVERT LATITUDE AND LONGITUDE VALUES TO RADIANS var previousRadianLat = positionPrevious.Latitude * degreesToRadians; var previousRadianLong = positionPrevious.Longitude * degreesToRadians; var currentRadianLat = positionCurrent.Latitude * degreesToRadians; var currentRadianLong = positionCurrent.Longitude * degreesToRadians; // CALCULATE RADIAN DELTA BETWEEN THE TWO POSITIONS var latitudeRadianDelta = currentRadianLat - previousRadianLat; var longitudeRadianDelta = currentRadianLong - previousRadianLong; var expr1 = ( Math.sin(latitudeRadianDelta / 2) * Math.sin(latitudeRadianDelta / 2) ) + ( Math.cos(previousRadianLat) * Math.cos(currentRadianLat) * Math.sin(longitudeRadianDelta/2) * Math.sin(longitudeRadianDelta/2) ); var expr2 = 2 * Math.atan2( Math.sqrt( expr1 ), Math.sqrt( 1 - expr1 ) ); var distanceValue = earthRadius * expr2; return distanceValue; } //////////////////////////////////////////////////////////////////////////////// // // CONSTANTS // //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // // GADGET STATES FOR LOCATION AWARENESS // //////////////////////////////////////////////////////////////////////////////// var LOCATION_SENSING_STATE_DISABLED = 0; var LOCATION_SENSING_STATE_ERROR_AUTO = 1; var LOCATION_SENSING_STATE_ERROR_MANUAL = 2; var LOCATION_SENSING_STATE_OK_AUTO = 3; var LOCATION_SENSING_STATE_OK_MANUAL = 4; var LOCATION_SENSING_STATE_DISCONNECTED_AUTO = 5; var LOCATION_SENSING_STATE_DISCONNECTED_MANUAL = 6; var LOCATION_SENSING_STATE_INVALID = 7; var LOCATION_SENSING_VALID_STATES_ARRAY = new Array( LOCATION_SENSING_STATE_DISABLED , LOCATION_SENSING_STATE_ERROR_AUTO , LOCATION_SENSING_STATE_ERROR_MANUAL , LOCATION_SENSING_STATE_OK_AUTO , LOCATION_SENSING_STATE_OK_MANUAL , LOCATION_SENSING_STATE_DISCONNECTED_AUTO , LOCATION_SENSING_STATE_DISCONNECTED_MANUAL ); var LOCATION_SENSING_MANUAL_STATES_ARRAY = new Array( LOCATION_SENSING_STATE_ERROR_MANUAL , LOCATION_SENSING_STATE_OK_MANUAL , LOCATION_SENSING_STATE_DISCONNECTED_MANUAL ); var LOCATION_SENSING_AUTO_STATES_ARRAY = new Array( LOCATION_SENSING_STATE_ERROR_AUTO , LOCATION_SENSING_STATE_OK_AUTO , LOCATION_SENSING_STATE_DISCONNECTED_AUTO ); //////////////////////////////////////////////////////////////////////////////// // // ARRAY UTILITIES // //////////////////////////////////////////////////////////////////////////////// if ( !Array.prototype.exists ) { Array.prototype.exists = function( elementToSearch ) { var numElements = this.length; var counter; for ( counter = 0 ; counter < numElements ; counter++ ) { if ( counter in this && this[counter] === elementToSearch ) return (true); } return (false); }; }