var dType= "CPU: ";

function widgetOnUnDock()
{  
  LockRefresh;
  
  pb.width = 183;
  imgend.Left = 190;
  txtinfo.Width = 190;
  widgetWidth = 200;
  imgbg.Src = "images\\" + GetSetting( "color" ) + "\\bg.png";
  imgend.Src = "images\\" + GetSetting( "color" ) + "\\end.png";
  
  
  UnLockRefresh;
}

function widgetOnDock()
{
  LockRefresh;
  
  pb.width = 103;
  
  imgend.Left = 111;
  txtinfo.Width = 111;
  widgetWidth = 120;
  imgbg.Src = "images\\" + GetSetting( "color" ) + "\\bg_docked.png";
  imgend.Src = "images\\" + GetSetting( "color" ) + "\\end.png";
  
  
  UnLockRefresh;
  
}


function Run(objPath) 
{
    try 
    {
        var objShell = new ActiveXObject('wscript.shell');
        objShell.Run(objPath);
        objShell = null;
    }
    catch (e)
    {
    alert('找不到指定文件'+objPath+'(或它的组件之一)，请确定文件或路径是否正确，并确定更改了你的IE安全级别：工具--Internet 选项 -- 安全 -- 自定义级别 -- 没有标记为安全的 ActiveX 控件进行初始化和脚本运行\n设置为“启用”或 “提示”');
    }
}

function widgetOnDBClick()
{
  Run("taskmgr");
}

function widgetOnInit()
{
  if(getSetting("type")=="cpu")
  {
    dType = "CPU: ";
    pb.dataType = 1;
  }
  else if(getSetting("type")=="ramp")
  {
    dType = "RAM: ";
    pb.RAMType = 0;
    pb.dataType = 2;
    Print( dType ); 
  }
  else if(getSetting("type")=="ramv")
  {
    dType = "RAM: ";
    pb.RAMType = 1;
    pb.dataType = 2;
  }
  else if(getSetting("type")=="rama")
  {
    dType = "RAM: ";
    pb.RAMType = 2;
    pb.dataType = 2;
  }
  else if(getSetting("type")=="battery")  
  {
    dType = "电池: ";
    pb.dataType = 4;
  }
  else
  {
    dType = getSetting("type") + "盘: ";
    pb.diskName = getSetting("type");
    pb.dataType = 3;
  }
    
  var cl = GetSetting( "color");
  if(cl=="blue")
    pb.barColor = "0,153,255"
  else if(cl=="red")
    pb.barColor = "255,0,0";
  
  if(dockedOnSidebar)
    widgetOnDock()
  else
    widgetOnUnDock();

  
}

function OnAllSettingsSaved()
{
  widgetOnInit();

}

function pbOnChanged()
{
  if(pb.percent==100)
  {
    if(!imgend.Visible)
      imgend.Visible = true;
  }
  else
  {
    if(imgend.Visible)
      imgend.Visible = false;
  }
  
  if( txtinfo.caption != dType + pb.percent + "%")
    txtinfo.caption =  dType + pb.percent + "%";  
  
}