function Update()
{
//delcare variables for displaying battery icons.
var percent = FixedPercent(System.Machine.PowerStatus.batteryPercentRemaining);
var percentString;
var timeString;
var battIcon;
var onPower = false;
var charging = false;
//declare percentage zones for displaying battery icons.
//This can be easily edited to fit a new icon set if the set contains more or less icons than what is already here.
//Simply take 100 and divide it by the total number of battery icons you want to use, then edit the percentages accordingly.
if (percent > 95)
{
battIcon = 17;
}
else if (percent > 89)
{
battIcon = 16;
}
else if (percent > 83)
{
battIcon = 15;
}
else if (percent > 77)
{
battIcon = 14;
}
else if (percent > 71)
{
battIcon = 13;
}
else if (percent > 65)
{
battIcon = 12;
}
else if (percent > 59)
{
battIcon = 11;
}
else if (percent > 53)
{
battIcon = 10;
}
else if (percent > 47)
{
battIcon = 9;
}
else if (percent > 41)
{
battIcon = 8;
}
else if (percent > 35)
{
battIcon = 7;
}
else if (percent > 29)
{
battIcon = 6;
}
else if (percent > 23)
{
battIcon = 5;
}
else if (percent > 17)
{
battIcon = 4;
}
else if (percent > 11)
{
battIcon = 3;
}
else if (percent > 5)
{
battIcon = 2;
}
else
{
battIcon = 1;
}
if (percent < 20)
{
self.focus();
}
percentString = percent + "%";
if (System.Machine.PowerStatus.isBatteryCharging)
{
timeString = " ";
charging = true;
}
else if (System.Machine.PowerStatus.isPowerLineConnected)
{
timeString = " ";
onPower = true;
}
else
{
timeString = _timeRemaining.TimeRemainingString;
if (timeString == "")
{
timeString = " ";
}
}
if (_currentBattIcon != battIcon)
{
_imgBatt.src = "icons/battery_" + battIcon + ".png";
_currentBattIcon = battIcon;
}
if (_currentTimeString != timeString)
{
if (_currentTimeString == " ")
{
//If transitioning to having a time string present, clear the large percent text and force the percent text to update below.
_txtPercentageLarge.value = " ";
_currentPercentString = " ";
}
if (timeString == " ")
{
//If transitioning from having a time string present, clear the small percent text and force the percent text to update below.
_txtPercentage.value = " ";
_currentPercentString = " ";
}
_txtTime.value = timeString;
_currentTimeString = timeString;
}
if (_currentPercentString != percentString)
{
if (_currentTimeString == " ")
{
_txtPercentageLarge.value = percentString;
}
else
{
_txtPercentage.value = percentString;
}
_currentPercentString = percentString;
}
if ((_currentOnPower != onPower) || (_currentCharging != charging))
{
_currentOnPower = onPower;
_currentCharging = charging;
if (charging)
{
_imgPower.src = "icons/power_red.png";
}
else if (onPower)
{
_imgPower.src = "icons/power_black.png";
}
else
{
_imgPower.src = "icons/power_blank.png";
}
}
setTimeout(Update, 2000);
}