var cputype = 0;

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


function widgetOnInit()
{
  LockRefresh;
   
  chart1.style = GetSetting('style');
  chart1.fillColor = GetSetting('fillcl');
  chart1.penColor = GetSetting('linecl');
  chart1.gradientColor = GetSetting('gradcl');

  chart2.style = GetSetting('style');
  chart2.fillColor = GetSetting('fillcl');
  chart2.penColor = GetSetting('linecl');
  chart2.gradientColor = GetSetting('gradcl');

  cputype = parseInt( GetSetting('cpu') ); 
  if( cputype==0 )
  {
    //单cpu
    chart1.Width = 117;
    chart2.Visible = false; 
  }
  else
  {
    //双核cpu
    chart1.Width = 55;
    chart2.Visible = true; 
 
  }
  
  UnLockRefresh;

  tm.interval = parseInt( GetSetting('tm')  );
  tm.enabled = true;
   
}

function tmOnTimer()
{
  LockRefresh;
  
  if( cputype==0 )
  {
    //单cpu
    var c = cpuUsage;
    chart1.addItem( c );
    txt.caption = 'CPU: ' + c + '%';
  }
  else
  {
    //双核cpu
    cpuLoadInfo;
    var c1 = cpuUsageEx(0);
    var c2 = cpuUsageEx(1);
    chart1.addItem( c1 );
    chart2.addItem( c2 );
    txt.caption = 'CPU: ' + ((c1+c2)/2).toFixed(0) + '%';
 
  }
  
  UnLockRefresh;
  
}

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