
var cFos_object;
try {
   cFos_object = new ActiveXObject(ole_object);
}
catch(x) {
   var m = new ml_object;
   alert(ole_object + "\n\n" + x.message + "\n\n" + m.ole_error);
   window.close();
}

function Calibration() 
{
   cFos_object.spd_command("tsclear;pingboot;burst");
}

function ChangeMode() 
{
   var Mode = cFos_object.spd_command("gset latency"); 
   var Result = Mode.search("1");
   if( Result == -1 )
   {
      //alert("BandWidth, should update to Ping Time(low latency)");
      cFos_object.spd_command("gset latency 1 -save"); 
   }
   else
   {
      //alert("Ping Time, should update to BandWidth(speed)"); 
      cFos_object.spd_command("gset latency 2 -save"); 
   }
}

function OpenSpeedTestWebSite()
{
   cFos_object.param("speed_test_url")  = "http://www.cfosspeed.de/speed-test/speed-test_en.htm";
   cFos_object.param("speed_test_name") = "cFos Speed Test";

   var ScreenWidth = screen.width;   
   var ScreenHeight = screen.height;   
   var config = "left=0,top=0,width=ScreenWidth,height=ScreenHeight,toolbar=yes,menubar=yes,scrollbar=yes,resizable=yes,location=yes,directories=yes,status=yes";
   window.open('http://www.cfosspeed.de/speed-test/speed-test_en.htm', 'ASUSTeK', config);  
}

function Exec_Graph_Web() 
{
   //   var url = "bgraph_tpl.cfhta";
   //   window.location.href = url;
   //   return;

   var param = GameFirstII_APP.commandLine.match(/[\w!#$%&'*+-/=?^_`{}~\\:]+|\"[^\"]*\"/g);
   for (var i=0; i < param.length; ++i) 
   {
       if (param[i].charAt(0) == '"') param[i] = param[i].substr(1, param[i].length-2);
   }
   homedir = param[0].substr(0, param[0].lastIndexOf('\\')+1);
   var sh = new ActiveXObject("Shell.Application");
   sh.ShellExecute("MSHTA.exe", "\"" + homedir + "bgraph.cfhta" + "\"");
}

function Exec_Console_Web() 
{
   var param = GameFirstII_APP.commandLine.match(/[\w!#$%&'*+-/=?^_`{}~\\:]+|\"[^\"]*\"/g);
   for (var i=0; i < param.length; ++i) 
   {
       if (param[i].charAt(0) == '"') param[i] = param[i].substr(1, param[i].length-2);
   }
   homedir = param[0].substr(0, param[0].lastIndexOf('\\')+1);
   var sh = new ActiveXObject("Shell.Application");
   sh.ShellExecute("MSHTA.exe", "\"" +homedir + "console.cfhta" + "\"");
}

function Exec_AdvancedMode_Web() 
{
   var param = GameFirstII_APP.commandLine.match(/[\w!#$%&'*+-/=?^_`{}~\\:]+|\"[^\"]*\"/g);
   for (var i=0; i < param.length; ++i) 
   {
       if (param[i].charAt(0) == '"') param[i] = param[i].substr(1, param[i].length-2);
   }
   homedir = param[0].substr(0, param[0].lastIndexOf('\\')+1);
   var sh = new ActiveXObject("Shell.Application");
   sh.ShellExecute("MSHTA.exe", "\"" +homedir + "cFospreferences.cfhta"+ "\"");
}

function Exec_THIS() 
{
   var param = GameFirstII_APP.commandLine.match(/[\w!#$%&'*+-/=?^_`{}~\\:]+|\"[^\"]*\"/g);
   for (var i=0; i < param.length; ++i) 
   {
       if (param[i].charAt(0) == '"') param[i] = param[i].substr(1, param[i].length-2);
   }
   homedir = param[0].substr(0, param[0].lastIndexOf('\\')+1);
   var sh = new ActiveXObject("Shell.Application");
   sh.ShellExecute("MSHTA.exe", "\"" +homedir + "preferences.cfhta"+ "\"");
}

function Exec_AppPriority() 
{
   var param = GameFirstII_APP.commandLine.match(/[\w!#$%&'*+-/=?^_`{}~\\:]+|\"[^\"]*\"/g);
   for (var i=0; i < param.length; ++i) 
   {
       if (param[i].charAt(0) == '"') param[i] = param[i].substr(1, param[i].length-2);
   }
   homedir = param[0].substr(0, param[0].lastIndexOf('\\')+1);
   var sh = new ActiveXObject("Shell.Application");
   sh.ShellExecute("MSHTA.exe", "\"" +homedir + "priority.cfhta"+ "\"");
}


function GetCPUUsage() 
{

        var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}");
        e = new Enumerator(wmi.InstancesOf("Win32_PerfFormattedData_PerfOS_Processor"));
	for(; !e.atEnd(); e.moveNext()) 
        {
	   var s = e.item();
	   WScript.Echo(s.Name + ": " + s.PercentUserTime);
//alert(s.Name);
//alert(s.PercentUserTime);
alert(s.Name + ": " + s.PercentUserTime)
	}
	return;

	var wmi = GetObject("winmgmts:\\root\\cimv2"); 
	var p1data = []; 
	var wql = "Select IDProcess,Name,PercentProcessorTime,"+ "Timestamp_Sys100NS from Win32_PerfRawData_PerfProc_Process"; 
	for ( var e=new Enumerator(wmi.ExecQuery(wql)); !e.atEnd(); e.moveNext() ) 
	{ 
		var p = e.item(); 
		p1data[p.IDProcess+p.Name] = p; 
	} 

	WScript.Sleep(2000); 
	var list = []; 
	for ( var e=new Enumerator(wmi.ExecQuery(wql)); !e.atEnd(); e.moveNext() ) 
	{ 
		var p2 = e.item(); 
		var p1 = p1data[p2.IDProcess+p2.Name] || {}; 
		var n = p2.PercentProcessorTime - p1.PercentProcessorTime; 
		var d = p2.Timestamp_Sys100NS - p1.Timestamp_Sys100NS; 
		list.push((100*n/d).toFixed(2) + "% " + p2.Name); 
  	} 
	WScript.Echo(list.join("\n")); 
	alert(list);


}