var flag; 

function updateinfo()
{
  LockRefresh;
  txtp.caption = pb.percent + "%";
   
  var flag = BatteryStatus; 
  if(flag==-1)
  {
    //没电池  或  状态未知 
    imgno.Visible = true;
//    txtbg.bgColor =  "153,153,153"; //灰色
    txtbg.bgColor =  GetSetting( "clno" ); // "153,153,153"; //灰色
    
    imgprgbg.Visible = false; 
    txtp.Visible = false;
    imgon.Visible = false;
     
  }
  else
  {
    Usage = BatteryUsage;
    imgno.Visible = false;
    imgon.Visible = true;

    if(flag==1)  //插了插头 
      imgon.alpha = 100
    else
      imgon.alpha = 40;
   
   if(Usage>80)
      txtbg.bgColor =  GetSetting( "cl80" ) 
    else if(Usage>50)
      txtbg.bgColor =  GetSetting( "cl50" )
    else if(Usage>20)
      txtbg.bgColor =  GetSetting( "cl20" )
    else
      txtbg.bgColor =  GetSetting( "cl0" )
       
      
/*    if(Usage>50)
      txtbg.bgColor =  "86,202,0"  //绿色
    else if(Usage>20)
      txtbg.bgColor =  "255,204,0" //黄色 
    else
      txtbg.bgColor =  "255,60,0";  //红
 */ 
  }
  
  
  
  
  
  UnLockRefresh;


}

function widgetOnInit()
{
   pb.percent = 0;
   pb.update;
   updateinfo();
}

function pbOnChanged()
{                                       
  Print( "update changed" );
  updateinfo();
}

function timer0OnTimer()
{
  var vflag = BatteryStatus; 
  if(flag==vflag)
    return;
    
  flag = vflag ;  
  if(flag==-1)
  {
    //没电池  或  状态未知 
    imgno.Visible = true;
    imgon.Visible = false;
  }
  else
  {
    imgno.Visible = false;
    imgon.Visible = true;
     
    if(flag==1)  //插了插头 
      imgon.alpha = 100
    else
      imgon.alpha = 40;
  }
  Print( "flagchanged")
  
}

function widgetOnUnDock()
{
  scale = 100;
}

function widgetOnDock()
{
  scale = 88;
}