var cl80,cl50,cl20;


function tmOnTimer()
{   
  LockRefresh;
  
  sRemaining = 8316;
  
  var sta = BatteryStatus;
  var per = BatteryUsage ;
  var remaining = BatteryLifeTime; 
  var hRemaining = Math.floor(remaining /60/60);
  var mRemaining = Math.floor( (remaining - hRemaining*60*60)/60 ) ;  
  var sRemaining = remaining - hRemaining*60*60 - mRemaining*60;
  
  ba.percent = per;

  if(sta==-1)
  {
    //没检测到电池或者未知状态
    if(!cross.Visible) 
      cross.Visible = true; 
    
    if(txt.Visible)
      txt.Visible = false;
    if(txtTime.Visible)
      txtTime.Visible = false;
  
  
  }
  else if(sta==0)
  {
    if(cross.Visible) 
      cross.Visible = false; 

    if(!txt.Visible)
      txt.Visible = true;
    txt.caption = per +'% 电池电源';
      
    txtTime.fontName = 'Tahoma';
    if(remaining>-1)
      remaining =  hRemaining + "h:" + mRemaining + "m:" + sRemaining + "s"
    else
    {
      txtTime.fontName = '黑体';
      remaining = '正在使用电池';
    }
    txtTime.caption = remaining ;
  
    if(!txtTime.Visible)
      txtTime.Visible = true;
  }
  else if(sta==1)
  {
    if(cross.Visible) 
      cross.Visible = false; 
    if(!txt.Visible)
      txt.Visible = true;
    txt.caption = per +'% 交流电源';

    txtTime.fontName = 'Tahoma';
    if(remaining>-1)
      remaining =  hRemaining + "h:" + mRemaining + "m:" + sRemaining + "s"
    else
    {
       txtTime.fontName = '黑体';
       if(per<100) 
         remaining = '正在充电...'
       else if(per==100)
         remaining = '充电完毕'
       else 
         remaining = '正在使用交流电源'; 
    }
    txtTime.caption = remaining ;
  
    if(!txtTime.Visible)
      txtTime.Visible = true;
  }

  if(per>=80)
    ba.barColor=cl80
  else if(per>=50)
    ba.barColor=cl50
  else if(per>=20)
    ba.barColor=cl20
  else 
    ba.barColor='clRed';


  UnLockRefresh;
}

function baOnChanged()
{

}

function widgetOnInit()
{
  cl80 = GetSetting('cl80');
  cl50 = GetSetting('cl50');
  cl20 = GetSetting('cl20');

  tmOnTimer();
}