
function timer0OnTimer()
{
  LockRefresh;
  
  getNetSpeed;
  var nup = netUpSpeed/1024; 
  var ndown = netDownSpeed/1024;
  
  txtDown.caption = "Dn: " +  ndown.toFixed(1)  + " k/s";
  txtUp.caption =  "Up: " + nup.toFixed(1)  + " k/s";
  txtIP.caption =  "IP : " + GetLocalIPAddress();
  //===================
  var maxdown = parseInt(GetSetting( "maxdown" ));
  if(ndown>maxdown)
  {
    maxdown = Math.round(ndown);
    SetSetting( "maxdown" ,maxdown );
    SaveSetting( "maxdown" );
  }
    
  var maxup = parseInt(GetSetting( "maxup" ));
  if(nup>maxup)
  {
    maxup = Math.round(nup);
    SetSetting( "maxup" ,maxup );
    SaveSetting( "maxup" );
  }
  //===================

  pbDown.percent = ndown/maxdown*100  ;
  if(pbDown.percent>=80)
    pbDown.Src = "red.png"  
  else if(pbDown.percent>=50)
    pbDown.Src = "pink.png"
  else 
    pbDown.Src = "blue.png";

  pbUp.percent = nup/maxup*100  ;
  if(pbUp.percent>=80)
    pbUp.Src = "red.png"
  else if(pbUp.percent>=50)
    pbUp.Src = "pink.png"
  else 
    pbUp.Src = "blue.png";
  
  UnLockRefresh;
  
}

function widgetOnInit()
{
  netAdaptIndex = GetSetting( "net" );
  bg.Src = "images\\bg" + GetSetting( "bg" ) + ".png"; 
}

function OnAllSettingsSaved()
{
  
  widgetOnInit();
}

function nMenu1OnClick()
{
  ShowSetting;
}

function btChangeBgOnClick()
{
  var bgnum = parseInt(GetSetting( "bg" ));
  if(bgnum + 1>46 )
    bgnum = 1
  else
    bgnum ++;
    
  bg.Src = "images\\bg" + bgnum + ".png"; 

  SetSetting( "bg" ,bgnum );
  SaveSetting("bg");
}

function GetLocalIPAddress()
    {
     var obj = null;
     var rslt = null;
     try
     {
     obj = new ActiveXObject("rcbdyctl.Setting");
     rslt = obj.GetIPAddress;
     obj = null;
     }
     catch(e)
     {
     //异常发生
     }
     var sl = rslt.split(";")
     var iptype = GetSetting("iptype");  
     if(iptype=="lan")
       return sl[0]
     else if(iptype=="wan")
     {
       if(sl.length<=1)
         return "未连接到互联网"
       else
         return sl[1];
     }
     else
     {
       return sl[ iptype ];
     }
     
     //Print( sl.length + "  "+ rslt);   
    }