try{var xmlHttp = new XMLHttpRequest()}
catch (e){var xmlHttp = new ActiveXObject('Microsoft.XMLHTTP')}

var locator = new ActiveXObject("WbemScripting.SWbemLocator");
var wmiService = locator.ConnectServer(null, "root\\cimv2");
var fs = new ActiveXObject("Scripting.FileSystemObject");

var lngID = System.Gadget.document.parentWindow.lngID;

var maxcores = System.Gadget.document.parentWindow.maxCPUcoressupport;
var cores;
var tmpvalue;
var valuefortemp;

System.Gadget.onSettingsClosing = SettingsClosing;

function checkforupdate(){
 var vString = "";
 var url = "http://www.myfavoritegadgets.info/monitors/SystemMonitorII/SystemMonitorIIversioninfo.xml";

 xmlHttp.open("GET", url, true); //true mean call is asynchronous
 xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"); //for non cached
 
 xmlHttp.onreadystatechange = function(){
  // Verify that the document is ready to parse.
  if (xmlHttp.readyState == 4){
   // Makes sure it found the file.
   if (xmlHttp.status == 200){
    // Extract information
    var newVersion = xmlHttp.responseXML.getElementsByTagName("version")[0].firstChild.nodeValue;
    var updateUrl = xmlHttp.responseXML.getElementsByTagName("url")[0].firstChild.nodeValue;
    // Compare and show message if a newer version is available.
    if (parseFloat(newVersion) > parseFloat(System.Gadget.version)){
     vString = "<font color='#FF0000'>" + setlng[lngID][170] + System.Gadget.version + "<br>";
     vString += "<strong><a href='" + updateUrl + "' onclick='System.Gadget.close()' ";
	 vString += "title='" + setlng[lngID][171] + " (" + newVersion + ")'>" + setlng[lngID][171] + " (" + newVersion + ")</a></strong></font>"; 
     updatestring.innerHTML = vString;
     updatebutton.style.display = "none";
    }
    else{
     updatestring.innerHTML = "<font color='#008000'>" + setlng[lngID][168] + "</font>";
     updatebutton.style.display = "none";
    }
   }//end status
   else{
    updatestring.innerHTML = "<font color='#FF0000' size='2'>" + setlng[lngID][169] + xmlHttp.status + "</b></font>";
    updatebutton.style.display = "none";
   }
  }//end readyState
 }//end function
 xmlHttp.send(null);
}

function copyText(field){
 window.clipboardData.setData('Text',field.innerText);
}

function validateNumber(e){
 var numcheck = /\d/;
 return numcheck.test(String.fromCharCode(e.keyCode));
}

function sizechange(){
 var tmp = parseInt(size.value,10);
 if (isNaN(tmp)) size.value = Math.ceil(System.Gadget.Settings.read("SetSize") * 100);
}

function timechange(){
 var tmp = parseInt(timetorefresh.value,10);
 if (isNaN(tmp)) timetorefresh.value = Math.ceil(System.Gadget.Settings.read("refreshtime") / 1000);
}

function switchtimechange(){
 var tmp = parseInt(timetoswitch.value,10);
 if (isNaN(tmp)) timetoswitch.value = Math.ceil(System.Gadget.Settings.read("SwithchRate") / 1000);
}

function fixscalefromchange(){
 var tmp = parseInt(fixscalefrom.value,10);
 if (isNaN(tmp) || (parseInt(fixscale.value) <= parseInt(fixscalefrom.value))) fixscalefrom.value = System.Gadget.Settings.read("LowScaleTemperatureGr");
}

function fixscalechange(){
 var tmp = parseInt(fixscale.value,10);
 if (isNaN(tmp) || (parseInt(fixscale.value) <= parseInt(fixscalefrom.value))) fixscale.value = System.Gadget.Settings.read("ScaleTemperatureGr");
}

function deltachange(){
 var tmp = parseInt(delta.value,10);
 if (isNaN(tmp) || (tmp <1) || (tmp >50)) delta.value = System.Gadget.Settings.read("DeltaOverheat");
}

function tjuncchange(){
 var tmp = parseInt(tjmax.value,10);
 if (isNaN(tmp) || (tmp < 40) || (tmp >221)) tjmax.value = System.Gadget.Settings.read("TjMaxtemp"); //40C = 104F 105C = 221F
}

function glwchange(){
 var tmp = parseInt(graphlinewidth.value,10);
 if (isNaN(tmp) || (tmp <1) || (tmp >20)) graphlinewidth.value = System.Gadget.Settings.read("GraphLineWidth");
}

function logclick(){
 if (enablelogging.checked) loghide.disabled = false;
 else loghide.disabled = true;
}

function swithflagchange(){
 if (enableswitch.checked) switchtime.disabled = false;
 else switchtime.disabled = true;
}

function CPUGraphTypesetup(){
 if (CPUGraphType.value != 0){
  hide2.disabled = true;
  graphtemperature.checked = false;
  cyclegraph.checked = false;
 }
 else if (!allinone.checked) hide2.disabled = false;
}

function allinonesetup(){
 if (allinone.checked){
  MemGraphType.value = 1;
  hide1.disabled = true;
  hide2.disabled = true;
  graphtemperature.checked = false;
  cyclegraph.checked = false;
  hidememgraphics.checked = true;
  hide3.disabled = true;
 }
 else{
  hide1.disabled = false;
  hide2.disabled = false;
  MemGraphType.value = System.Gadget.Settings.read("graphtype");
  hidememgraphics.checked = false;
  hide3.disabled = false;
 }
 // Warning! Don't change 2 lines below
 coreclick();
 grtempclick();
 CPUGraphTypesetup();
 hideramgraphsrttings();
}

function coreclick(){
 if (coretemp.checked){
  globalhide.disabled = false;
  TrackingSettingChanged();
 }
 else{
  globalhide.disabled = true;
  coretempinfo.checked = false;
  graphtemperature.checked = false;
  cyclegraph.checked = false;
  delta.disabled = true;
  tjmax.disabled = true;
 }
}

function grtempclick(){
 if (graphtemperature.checked){
  fixedscale.disabled = false;
  fixscalefrom.disabled = false;
  fixscale.disabled = false;
 }
 else{
  fixedscale.disabled = true;
  fixscalefrom.disabled = true;
  fixscale.disabled = true;
  cyclegraph.checked = false;
 }
}

function getCheckedValue(){
 var radioLength = group1.length;
 for (var i=0; i<radioLength; i++){
  if (group1[i].checked) return group1[i].value;
 }
}

function setCheckedValue(newValue){
 var radioLength = group1.length;
 for (var i=0; i<radioLength; i++){
  group1[i].checked = false;
  if (group1[i].value == newValue.toString()) group1[i].checked = true;
 }
}

function TrackingSettingChanged(){
 var index = getCheckedValue();
 switch (index){
  case "1":
   deltahide.disabled = false;
   delta.disabled = false;
   tjmaxhide.disabled = true;
   tjmax.disabled = true;
   playshide.disabled = false;
   break;

  case "2":
   deltahide.disabled = true;
   delta.disabled = true;
   tjmaxhide.disabled = false;
   tjmax.disabled = false;
   playshide.disabled = false;
   break;
     
  default:
   deltahide.disabled = true;
   delta.disabled = true;
   tjmaxhide.disabled = true;
   tjmax.disabled = true;
   playshide.disabled = true;
   break;
 }
}

function getCheckedValue1(){
 var radioLength = group2.length;
 for (var i=0; i < radioLength; i++){
  if (group2[i].checked) return group2[i].value;
 }
}

function setCheckedValue1(newValue){
 var radioLength = group2.length;
 for (var i=0; i<radioLength; i++){
  group2[i].checked = false;
  if (group2[i].value == newValue.toString()) group2[i].checked = true;
 }
}

function ColorSettingsChanged(){
 var index = getCheckedValue1();
 switch (index){
  case "1":
   SingleColorsArea.disabled = false;
   MultyColorsArea.disabled = true;
   break;

  case "2":
   SingleColorsArea.disabled = true;
   MultyColorsArea.disabled = false;
   break;
     
  default:
   SingleColorsArea.disabled = true;
   MultyColorsArea.disabled = true;
   break;
 }
}

function hideramgraphsrttings(){
 if (MemGraphType.value != 1){
  Ramhide.checked = false;
  Pagehide.checked = false;
  Allhide.checked = false;
  hidegraphdisable.disabled = true;
 }
 else hidegraphdisable.disabled = false;
}

function hidesize(){
 sizehide.disabled = autoscaleDPI.checked;
}

function loadpartcheck(){
 if (bargrapsmode.value == 1){
  loadpart.disabled = false;
  ResLoadeColorsArea.disabled = false;
  resloadhide.style.display = "inline";
 }
 else{
  loadpart.disabled = true;
  ResLoadeColorsArea.disabled = true;
  resloadhide.style.display = "none";
 }
}

function createmediumselect(){
 mediumload.options.length = 0;
 //mediumload.innerHTML = null;
 for (var i=parseInt(easyload.value)+1; i<100; i++){
  newOption = new Option(i, i);
  mediumload.options[mediumload.length] = newOption;
 }
 if (parseInt(easyload.value)<valuefortemp) mediumload.options[valuefortemp - parseInt(easyload.value) - 1].selected = true;
 else mediumload.options[0].selected = true;

 setmediumdata();
}

function setmediumdata(){
 valuefortemp = mediumload.value;
}

function resettodefault(){
 easyload.options[64].selected = true;
 createmediumselect();
 mediumload.options[90-65-1].selected = true;
 valuefortemp = mediumload.value;
}

function setupCPUsoutput(){
 cores = (showcorestype.value == 0) ? System.Gadget.document.parentWindow.coreCount : System.Gadget.document.parentWindow.maxrealCPUcorescount; //System.Machine.CPUs.count;

 for (var i=1; i<=maxcores; i++){
  document.getElementById("Core" + i + "ColorSelect").disabled = false;
  document.getElementById("Coretitle" + i).disabled = false;
  document.getElementById("Core" + i).disabled = false;
  document.getElementById("core" + i + "text").disabled = false;
  document.getElementById("Corehidebar" + i).disabled = false;
  document.getElementById("core" + i + "b").disabled = false;
  document.getElementById("Corehide" + i).disabled = false;
  document.getElementById("core" + i + "h").disabled = false;
  document.getElementById("logCoreusage" + i).disabled = false;
  document.getElementById("core" + i + "ul").disabled = false;
  document.getElementById("logCoretemp" + i).disabled = false;
  document.getElementById("core" + i + "tl").disabled = false;
 }

 for (var i=cores+1; i<=maxcores; i++){
  document.getElementById("Core" + i + "ColorSelect").disabled = true;
  document.getElementById("Coretitle" + i).disabled = true;
  document.getElementById("Core" + i).disabled = true;
  document.getElementById("core" + i + "text").disabled = true;
  document.getElementById("Corehidebar" + i).disabled = true;
  document.getElementById("core" + i + "b").disabled = true;
  document.getElementById("Corehide" + i).disabled = true;
  document.getElementById("core" + i + "h").disabled = true;
  document.getElementById("logCoreusage" + i).disabled = true;
  document.getElementById("core" + i + "ul").disabled = true;
  document.getElementById("logCoretemp" + i).disabled = true;
  document.getElementById("core" + i + "tl").disabled = true;
 }

 if (showcorestype.value == 1){
  CPUnumber.disabled = true;
  switching.disabled = true;
  enableswitch.checked = false;
  CPUnumber.value = 0;
  for (var i=System.Gadget.document.parentWindow.coreCount+1; i<=cores; i++){
   document.getElementById("Corehidebar" + i).checked = false;
   document.getElementById("Corehide" + i).checked = false;
  }
 }
 else{
  if (CPUnumber.length >= 2){
   CPUnumber.disabled = false;
   switching.disabled = false;
  }
  for (var i=System.Gadget.document.parentWindow.coreperCPU+1; i<=maxcores; i++){
   document.getElementById("Corehidebar" + i).checked = true;
   document.getElementById("Corehide" + i).checked = true;
  }
 }
}

function buildlngselect(){
 for (var i=0; i<lnglist.length; i++){
  newOption = new Option(lnglist[i], i);
  languagelist.options[languagelist.length] = newOption;
 }
 languagelist.value = System.Gadget.Settings.read("LanguageId");
 setcorestring();
}

function setcorestring(){
 for (var i=1; i<=maxcores; i++){
  document.getElementById("core" + i + "text").innerText = setlng[lngID][86] + i;
  document.getElementById("core" + i + "b").innerText = setlng[lngID][86] + i;
  document.getElementById("core" + i + "h").innerText = setlng[lngID][86] + i;
  document.getElementById("core" + i + "ul").innerText = setlng[lngID][86] + i;
  document.getElementById("core" + i + "tl").innerText = setlng[lngID][86] + i;
  document.getElementById("Coretitle" + i).innerText = setlng[lngID][86] + " #" + i + ":";
 }
}

function setlogfilename(){
 logfilenamehere.innerText = setlng[lngID][149] + (System.Gadget.document.parentWindow.maxrealCPUcount == 1 ? "" : setlng[lngID][150] + (parseInt(CPUnumber.value) + 1)) + setlng[lngID][151];
}

function loadSettings(){
 CPUnumber.options.length = 0;
 var colItems = wmiService.ExecQuery("SELECT Name FROM Win32_Processor");
 var enumItems = new Enumerator(colItems);
 for (var i=0; !enumItems.atEnd(); enumItems.moveNext()){
  var objItem = enumItems.item();
  var name = objItem.Name;
  if(name.length > 40) name = name.substr(0,40);
  newOption = new Option(i + ": " + name, i);
  CPUnumber.options[CPUnumber.length] = newOption;
  i++;
 }
 CPUnumber.disabled = (CPUnumber.length < 2);
 switching.disabled = (CPUnumber.length < 2);
 CPUnumber.value = System.Gadget.Settings.read("CurrentCPUnum");

 buildlngselect();
 setlogfilename();

 var tmp;
 bargrapsmode.value = System.Gadget.Settings.read("GraphScheme");
 loadpartcheck();

 tmp = System.Gadget.Settings.read("EasyLoadUse");
 for (var i=1; i<99; i++){
  newOption = new Option(i, i);
  easyload.options[easyload.length] = newOption;
 }
 easyload.options[parseInt(tmp)-1].selected = true;

 tmp = System.Gadget.Settings.read("MediumLoadUse");
 for (var i=parseInt(easyload.value)+1; i<100; i++){
  newOption = new Option(i, i);
  mediumload.options[mediumload.length] = newOption;
 }

 mediumload.options[parseInt(parseInt(tmp)- parseInt(easyload.value) - 1)].selected = true;
 valuefortemp = mediumload.value; //Important!!!!

 size.value = Math.ceil(System.Gadget.Settings.read("SetSize") * 100);
 timetorefresh.value = Math.ceil(System.Gadget.Settings.read("refreshtime") / 1000);

 tmp = System.Gadget.Settings.read("DPIautoscale");
 if (tmp == "false") autoscaleDPI.checked = false;
 else autoscaleDPI.checked = true;
 hidesize();

 //!!! procedures order check graphtemperature and setCheckedValue first, coreclick and grtempclick after
 tmp = System.Gadget.Settings.read("ShowTempGraph");
 if (tmp == "false") graphtemperature.checked = false;
 else graphtemperature.checked = true;

 tmp = System.Gadget.Settings.read("CycleGraphEnable");
 if (tmp == "false") cyclegraph.checked = false;
 else cyclegraph.checked = true;

 tmp = System.Gadget.Settings.read("OverheatCheck");
 setCheckedValue(tmp);

 tmp = System.Gadget.Settings.read("CoreTempUse");
 if (tmp == "false") coretemp.checked = false;
 else coretemp.checked = true;

 //place after check CoreTempUse
 tmp = System.Gadget.Settings.read("InfoFromCoreTemp");
 if (tmp == "false") coretempinfo.checked = false;
 else coretempinfo.checked = true;

 tmp = System.Gadget.Settings.read("CombinedAllGraph");
 if (tmp == "false") allinone.checked = false;
 else allinone.checked = true;

 //place CPUGraphType before allinonesetup()
 CPUGraphType.value = System.Gadget.Settings.read("CPUGraphsType");

 allinonesetup();
 //place after allinonesetup
 MemGraphType.value = System.Gadget.Settings.read("graphtype");
 hideramgraphsrttings();

 fixscalefrom.value = System.Gadget.Settings.read("LowScaleTemperatureGr");
 fixscale.value = System.Gadget.Settings.read("ScaleTemperatureGr");

 CPUBarsType.value = System.Gadget.Settings.read("barstype");

 tmp = System.Gadget.Settings.read("TitleHide");
 if (tmp == "false") hidetitle.checked = false;
 else hidetitle.checked = true;
 tmp = System.Gadget.Settings.read("CopyrightHide");
 if (tmp == "false") hidecopyright.checked = false;
 else hidecopyright.checked = true;

 tmp = System.Gadget.Settings.read("GridlinesHide");
 if (tmp == "false") hidegridlines.checked = false;
 else hidegridlines.checked = true;

 tmp = System.Gadget.Settings.read("MemUsageHide");
 if (tmp == "false") hidememused.checked = false;
 else hidememused.checked = true;
 
 tmp = System.Gadget.Settings.read("MemNumbersHide");
 if (tmp == "false") hidememnumbers.checked = false;
 else hidememnumbers.checked = true;
 tmp = System.Gadget.Settings.read("RamNumbersHide");
 if (tmp == "false") hideRAMnumbers.checked = false;
 else hideRAMnumbers.checked = true;
 tmp = System.Gadget.Settings.read("PageNumbersHide");
 if (tmp == "false") hidePAGEnumbers.checked = false;
 else hidePAGEnumbers.checked = true;
 tmp = System.Gadget.Settings.read("AllNumbersHide");
 if (tmp == "false") hideALLnumbers.checked = false;
 else hideALLnumbers.checked = true;

 tmp = System.Gadget.Settings.read("MemBarsHide");
 if (tmp == "false") hidemembars.checked = false;
 else hidemembars.checked = true;
 tmp = System.Gadget.Settings.read("RamBarsHide");
 if (tmp == "false") hideRAMbars.checked = false;
 else hideRAMbars.checked = true;
 tmp = System.Gadget.Settings.read("PageBarsHide");
 if (tmp == "false") hidePAGEbars.checked = false;
 else hidePAGEbars.checked = true;
 tmp = System.Gadget.Settings.read("AllBarsHide");
 if (tmp == "false") hideALLbars.checked = false;
 else hideALLbars.checked = true;

 tmp = System.Gadget.Settings.read("CPUIdentHide");
 if (tmp == "false") hideCPUident.checked = false;
 else hideCPUident.checked = true;

 tmp = System.Gadget.Settings.read("CPUClockHide");
 if (tmp == "false") hideCPUclock.checked = false;
 else hideCPUclock.checked = true;

 tmp = System.Gadget.Settings.read("CPUUsageHide");
 if (tmp == "false") hideCPUusage.checked = false;
 else hideCPUusage.checked = true;

 tmp = System.Gadget.Settings.read("HideCPUallbars");
 if (tmp == "false") hidecpubars.checked = false;
 else hidecpubars.checked = true;

 tmp = System.Gadget.Settings.read("MemGraphHide");
 if (tmp == "false") hidememgraphics.checked = false;
 else hidememgraphics.checked = true;
 
 tmp = System.Gadget.Settings.read("CPUGraphHide");
 if (tmp == "false") hidecpugraphics.checked = false;
 else hidecpugraphics.checked = true;

 graphlinewidth.value = System.Gadget.Settings.read("GraphLineWidth");

 tmp = System.Gadget.Settings.read("fillRam");
 if (tmp == "false") Ramfill.checked = false;
 else Ramfill.checked = true;
 tmp = System.Gadget.Settings.read("fillPage");
 if (tmp == "false") Pagefill.checked = false;
 else Pagefill.checked = true;
 tmp = System.Gadget.Settings.read("fillAll");
 if (tmp == "false") Allfill.checked = false;
 else Allfill.checked = true;

 tmp = System.Gadget.Settings.read("hideRam");
 if (tmp == "false") Ramhide.checked = false;
 else Ramhide.checked = true;
 tmp = System.Gadget.Settings.read("hidePage");
 if (tmp == "false") Pagehide.checked = false;
 else Pagehide.checked = true;
 tmp = System.Gadget.Settings.read("hideAll");
 if (tmp == "false") Allhide.checked = false;
 else Allhide.checked = true;

 tmp = System.Gadget.Settings.read("LogEnabled");
 if (tmp == "false") enablelogging.checked = false;
 else enablelogging.checked = true;
 tmp = System.Gadget.Settings.read("modeIO");
 if (tmp == "false") iomode.checked = false;
 else iomode.checked = true;
 timetologging.value = System.Gadget.Settings.read("refreshlogtime");
 tmp = System.Gadget.Settings.read("CPUusagelog");
 if (tmp == "false") logCPUusage.checked = false;
 else logCPUusage.checked = true;
 tmp = System.Gadget.Settings.read("CPUfreqlog");
 if (tmp == "false") logCPUfreq.checked = false;
 else logCPUfreq.checked = true;
 tmp = System.Gadget.Settings.read("RAMusagelog");
 if (tmp == "false") logRAMusage.checked = false;
 else logRAMusage.checked = true;
 tmp = System.Gadget.Settings.read("Pageusagelog");
 if (tmp == "false") logPageusage.checked = false;
 else logPageusage.checked = true;
 tmp = System.Gadget.Settings.read("Allusagelog");
 if (tmp == "false") logAllusage.checked = false;
 else logAllusage.checked = true;

 for (var i=1; i<=maxcores; i++){
  tmp = System.Gadget.Settings.read ("Core" + i + "fill");
  if (tmp == "false") document.getElementById("Core" + i).checked = false;
  else document.getElementById("Core" + i).checked = true;

  tmp = System.Gadget.Settings.read ("Corehide" + i + "bar");
  if (tmp == "false") document.getElementById("Corehidebar" + i).checked = false;
  else document.getElementById("Corehidebar" + i).checked = true;

  tmp = System.Gadget.Settings.read ("Core" + i + "hide");
  if (tmp == "false") document.getElementById("Corehide" + i).checked = false;
  else document.getElementById("Corehide" + i).checked = true;

  tmp = System.Gadget.Settings.read ("Core" + i + "log");
  if (tmp == "false") document.getElementById("logCoreusage" + i).checked = false;
  else document.getElementById("logCoreusage" + i).checked = true;

  tmp = System.Gadget.Settings.read ("Coretemp" + i + "log");
  if (tmp == "false") document.getElementById("logCoretemp" + i).checked = false;
  else document.getElementById("logCoretemp" + i).checked = true;
 }

 tmp = System.Gadget.Settings.read("logParkingCore");
 if (tmp == "false") logCoresparking.checked = false;
 else logCoresparking.checked = true;

 tmp = System.Gadget.Settings.read("ParkingCore");
 if (tmp == "false") parking.checked = false;
 else parking.checked = true;
 
 Action.value = System.Gadget.Settings.read("dblclick");

 delta.value = System.Gadget.Settings.read("DeltaOverheat");

 tjmax.value = System.Gadget.Settings.read("TjMaxtemp");

 tmp = System.Gadget.Settings.read("PlaySound");
 if (tmp == "false") playsound.checked = false;
 else playsound.checked = true;

 logclick(); //after check enablelogging

 tmp = System.Gadget.Settings.read("DisableFlyoutSounds");
 if (tmp == "false") disableflyoutsounds.checked = false;
 else disableflyoutsounds.checked = true;

 tmp = System.Gadget.Settings.read("DisableShowWheel");
 if (tmp == "false") disableshowwheel.checked = false;
 else disableshowwheel.checked = true;

 tmp = System.Gadget.Settings.read("GetWEIfromWMIenable");
 if (tmp == "false") enablegetweifromwmi.checked = false;
 else enablegetweifromwmi.checked = true;

 tmp = System.Gadget.Settings.read("Switch");
 if (tmp == "false") enableswitch.checked = false;
 else enableswitch.checked = true;
 if (CPUnumber.length < 2) enableswitch.checked = false; //Important
 swithflagchange();
 timetoswitch.value = Math.ceil(System.Gadget.Settings.read("SwithchRate") / 1000);

 CPUClockformula.value = System.Gadget.Settings.read("CPUClockFormula");

 tmp = System.Gadget.Settings.read("AutoUpdate");
 if (tmp == "false") enablecheckforupdate.checked = false;
 else enablecheckforupdate.checked = true;

 //color settings 
 tmp = System.Gadget.Settings.read("ColorModeCheck");
 setCheckedValue1(tmp);
 ColorSettingsChanged(); 
 
 tmp = System.Gadget.Settings.read("sBgColorSelect");
 if (tmp !=""){
  document.getElementById("BgColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("BgColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor1").style.background = System.Gadget.Settings.read("colBgColor");
 document.getElementById("multiColorPicker1").value = System.Gadget.Settings.read("colBgColor").substr(1);
 needenable("BgColorSelect","multiColorPicker1");

 tmp = System.Gadget.Settings.read("sTitColorSelect");
 if (tmp !=""){
  document.getElementById("TitColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("TitColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor2").style.background = System.Gadget.Settings.read("colTitle");
 document.getElementById("multiColorPicker2").value = System.Gadget.Settings.read("colTitle").substr(1);
 needenable("TitColorSelect","multiColorPicker2");

 tmp = System.Gadget.Settings.read("sMemColorSelect");
 if (tmp !=""){
  document.getElementById("MemColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("MemColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor3").style.background = System.Gadget.Settings.read("colMemUsage");
 document.getElementById("multiColorPicker3").value = System.Gadget.Settings.read("colMemUsage").substr(1);
 needenable("MemColorSelect","multiColorPicker3");

 tmp = System.Gadget.Settings.read("sMMemColorSelect");
 if (tmp !=""){
  document.getElementById("MMemColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("MMemColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor4").style.background = System.Gadget.Settings.read("colMemMenu");
 document.getElementById("multiColorPicker4").value = System.Gadget.Settings.read("colMemMenu").substr(1);
 needenable("MMemColorSelect","multiColorPicker4");

 tmp = System.Gadget.Settings.read("sRamMemColorSelect");
 if (tmp !=""){
  document.getElementById("RamMemColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("RamMemColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor5").style.background = System.Gadget.Settings.read("colMemRam");
 document.getElementById("multiColorPicker5").value = System.Gadget.Settings.read("colMemRam").substr(1);
 needenable("RamMemColorSelect","multiColorPicker5");

 tmp = System.Gadget.Settings.read("sPageMemColorSelect");
 if (tmp !=""){
  document.getElementById("PageMemColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("PageMemColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor6").style.background = System.Gadget.Settings.read("colMemPage");
 document.getElementById("multiColorPicker6").value = System.Gadget.Settings.read("colMemPage").substr(1);
 needenable("PageMemColorSelect","multiColorPicker6");

 tmp = System.Gadget.Settings.read("sAllMemColorSelect");
 if (tmp !=""){
  document.getElementById("AllMemColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("AllMemColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor7").style.background = System.Gadget.Settings.read("colMemAll");
 document.getElementById("multiColorPicker7").value = System.Gadget.Settings.read("colMemAll").substr(1);
 needenable("AllMemColorSelect","multiColorPicker7");

 tmp = System.Gadget.Settings.read("sCPUnameColorSelect");
 if (tmp !=""){
  document.getElementById("CPUnameColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("CPUnameColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor8").style.background = System.Gadget.Settings.read("colCPUmodel");
 document.getElementById("multiColorPicker8").value = System.Gadget.Settings.read("colCPUmodel").substr(1);
 needenable("CPUnameColorSelect","multiColorPicker8");

 tmp = System.Gadget.Settings.read("sCoreColorSelect");
 if (tmp !=""){
  document.getElementById("CoreColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("CoreColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor9").style.background = System.Gadget.Settings.read("colCoreCpuspeed");
 document.getElementById("multiColorPicker9").value = System.Gadget.Settings.read("colCoreCpuspeed").substr(1);
 needenable("CoreColorSelect","multiColorPicker9");

 tmp = System.Gadget.Settings.read("sCPUusedColorSelect");
 if (tmp !=""){
  document.getElementById("CPUusedColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("CPUusedColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor10").style.background = System.Gadget.Settings.read("colCpuused");
 document.getElementById("multiColorPicker10").value = System.Gadget.Settings.read("colCpuused").substr(1);
 needenable("CPUusedColorSelect","multiColorPicker10");

 tmp = System.Gadget.Settings.read("sParkingColorSelect");
 if (tmp !=""){
  document.getElementById("ParkingColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("ParkingColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor11").style.background = System.Gadget.Settings.read("colCpuParked");
 document.getElementById("multiColorPicker11").value = System.Gadget.Settings.read("colCpuParked").substr(1);
 needenable("ParkingColorSelect","multiColorPicker11");

 tmp = System.Gadget.Settings.read("sGrBgColorSelect");
 if (tmp !=""){
  document.getElementById("GrBgColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("GrBgColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor12").style.background = System.Gadget.Settings.read("colFillGraph");
 document.getElementById("multiColorPicker12").value = System.Gadget.Settings.read("colFillGraph").substr(1);
 needenable("GrBgColorSelect","multiColorPicker12");

 tmp = System.Gadget.Settings.read("sVersnColorSelect");
 if (tmp !=""){
  document.getElementById("VersnColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("VersnColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor13").style.background = System.Gadget.Settings.read("colVersion");
 document.getElementById("multiColorPicker13").value = System.Gadget.Settings.read("colVersion").substr(1);
 needenable("VersnColorSelect","multiColorPicker13");

 tmp = System.Gadget.Settings.read("sCopyColorSelect");
 if (tmp !=""){
  document.getElementById("CopyColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("CopyColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor14").style.background = System.Gadget.Settings.read("colCopyright");
 document.getElementById("multiColorPicker14").value = System.Gadget.Settings.read("colCopyright").substr(1);
 needenable("CopyColorSelect","multiColorPicker14");

 tmp = System.Gadget.Settings.read("sSingleColorSelect");
 if (tmp !=""){
  document.getElementById("SingleColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("SingleColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor15").style.background = System.Gadget.Settings.read("colCpuAllinone");
 document.getElementById("multiColorPicker15").value = System.Gadget.Settings.read("colCpuAllinone").substr(1);
 needenable("SingleColorSelect","multiColorPicker15");

 for (var i=1; i<=maxcores; i++){
  tmp = System.Gadget.Settings.read("sCore" + i + "ColorSelect");
  if (tmp !=""){
   document.getElementById("Core" + i + "ColorSelect").selectedIndex = tmp;
  }
  else{
   document.getElementById("Core" + i + "ColorSelect").selectedIndex = 0;
  }
  document.getElementById("simplecolor" + (i+15)).style.background = System.Gadget.Settings.read("Core" + i + "col");
  document.getElementById("multiColorPicker" + (i+15)).value = System.Gadget.Settings.read("Core" + i + "col").substr(1);
  needenable("Core" + i + "ColorSelect","multiColorPicker" + (i+15));
 }

 tmp = System.Gadget.Settings.read("sEasyLoadColorSelect");
 if (tmp !=""){
  document.getElementById("EasyLoadColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("EasyLoadColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor40").style.background = System.Gadget.Settings.read("colCpuEasy");
 document.getElementById("multiColorPicker40").value = System.Gadget.Settings.read("colCpuEasy").substr(1);
 needenable("EasyLoadColorSelect","multiColorPicker40");

 tmp = System.Gadget.Settings.read("sModerateLoadColorSelect");
 if (tmp !=""){
  document.getElementById("ModerateLoadColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("ModerateLoadColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor41").style.background = System.Gadget.Settings.read("colCpuMedium");
 document.getElementById("multiColorPicker41").value = System.Gadget.Settings.read("colCpuMedium").substr(1);
 needenable("ModerateLoadColorSelect","multiColorPicker41");

 tmp = System.Gadget.Settings.read("sHardLoadColorSelect");
 if (tmp !=""){
  document.getElementById("HardLoadColorSelect").selectedIndex = tmp;
 }
 else{
  document.getElementById("HardLoadColorSelect").selectedIndex = 0;
 }
 document.getElementById("simplecolor42").style.background = System.Gadget.Settings.read("colCpuHard");
 document.getElementById("multiColorPicker42").value = System.Gadget.Settings.read("colCpuHard").substr(1);
 needenable("HardLoadColorSelect","multiColorPicker42");

 // plase in the end of settings
 showcorestype.value = System.Gadget.Settings.read("ShowCoresType");
 setupCPUsoutput();
 if (CPUnumber.length < 2){
  hideformultyCPU.disabled = true;
  showcorestype.value = 0;
 }
}

function SettingsClosing(event){
 if (event.closeAction == event.Action.commit){
  System.Gadget.Settings.write("LanguageId", languagelist.value);

  System.Gadget.Settings.write("CurrentCPUnum",CPUnumber.value);
  System.Gadget.Settings.write("GraphScheme", bargrapsmode.value);
  System.Gadget.Settings.write("EasyLoadUse", easyload.value);
  System.Gadget.Settings.write("MediumLoadUse", mediumload.value);
  timechange();
  System.Gadget.Settings.write("refreshtime", timetorefresh.value * 1000);
  sizechange();
  System.Gadget.Settings.write("SetSize", size.value / 100);
  System.Gadget.Settings.write("graphtype", MemGraphType.value);
  System.Gadget.Settings.write("barstype", CPUBarsType.value);

  if (autoscaleDPI.checked) System.Gadget.Settings.write ("DPIautoscale", "true");
  else System.Gadget.Settings.write ("DPIautoscale", "false");

  if (allinone.checked) System.Gadget.Settings.write ("CombinedAllGraph", "true");
  else System.Gadget.Settings.write ("CombinedAllGraph", "false");

  System.Gadget.Settings.write ("CPUGraphsType",  CPUGraphType.value);

  if (coretemp.checked) System.Gadget.Settings.write ("CoreTempUse", "true");
  else System.Gadget.Settings.write ("CoreTempUse", "false");

  if (coretempinfo.checked) System.Gadget.Settings.write ("InfoFromCoreTemp", "true");
  else System.Gadget.Settings.write ("InfoFromCoreTemp", "false");

  if (hidetitle.checked) System.Gadget.Settings.write ("TitleHide", "true");
  else System.Gadget.Settings.write ("TitleHide", "false");
  if (hidecopyright.checked) System.Gadget.Settings.write ("CopyrightHide", "true");
  else System.Gadget.Settings.write ("CopyrightHide", "false");

  if (hidegridlines.checked) System.Gadget.Settings.write ("GridlinesHide", "true");
  else System.Gadget.Settings.write ("GridlinesHide", "false");

  if (hidememused.checked) System.Gadget.Settings.write ("MemUsageHide", "true");
  else System.Gadget.Settings.write ("MemUsageHide", "false");

  if (hidememnumbers.checked) System.Gadget.Settings.write ("MemNumbersHide", "true");
  else System.Gadget.Settings.write ("MemNumbersHide", "false");
  if (hideRAMnumbers.checked) System.Gadget.Settings.write ("RamNumbersHide", "true");
  else System.Gadget.Settings.write ("RamNumbersHide", "false");
  if (hidePAGEnumbers.checked) System.Gadget.Settings.write ("PageNumbersHide", "true");
  else System.Gadget.Settings.write ("PageNumbersHide", "false");
  if (hideALLnumbers.checked) System.Gadget.Settings.write ("AllNumbersHide", "true");
  else System.Gadget.Settings.write ("AllNumbersHide", "false");
  if (hidememgraphics.checked) System.Gadget.Settings.write ("MemGraphHide", "true");
  else System.Gadget.Settings.write ("MemGraphHide", "false");

  if (hidemembars.checked) System.Gadget.Settings.write ("MemBarsHide", "true");
  else System.Gadget.Settings.write ("MemBarsHide", "false");
  if (hideRAMbars.checked) System.Gadget.Settings.write ("RamBarsHide", "true");
  else System.Gadget.Settings.write ("RamBarsHide", "false");
  if (hidePAGEbars.checked) System.Gadget.Settings.write ("PageBarsHide", "true");
  else System.Gadget.Settings.write ("PageBarsHide", "false");
  if (hideALLbars.checked) System.Gadget.Settings.write ("AllBarsHide", "true");
  else System.Gadget.Settings.write ("AllBarsHide", "false");

  if (hidememgraphics.checked) System.Gadget.Settings.write ("MemGraphHide", "true");
  else System.Gadget.Settings.write ("MemGraphHide", "false");

  if (hideCPUident.checked) System.Gadget.Settings.write ("CPUIdentHide", "true");
  else System.Gadget.Settings.write ("CPUIdentHide", "false");

  if (hideCPUclock.checked) System.Gadget.Settings.write ("CPUClockHide", "true");
  else System.Gadget.Settings.write ("CPUClockHide", "false");

  if (hideCPUusage.checked) System.Gadget.Settings.write ("CPUUsageHide", "true");
  else System.Gadget.Settings.write ("CPUUsageHide", "false");

  if (hidecpubars.checked) System.Gadget.Settings.write ("HideCPUallbars", "true");
  else System.Gadget.Settings.write ("HideCPUallbars", "false");

  if (hidecpugraphics.checked) System.Gadget.Settings.write ("CPUGraphHide", "true");
  else System.Gadget.Settings.write ("CPUGraphHide", "false");

  glwchange();
  System.Gadget.Settings.write("GraphLineWidth", graphlinewidth.value);

  if (Ramfill.checked) System.Gadget.Settings.write ("fillRam", "true");
  else System.Gadget.Settings.write ("fillRam", "false");
  if (Pagefill.checked) System.Gadget.Settings.write ("fillPage", "true");
  else System.Gadget.Settings.write ("fillPage", "false");
  if (Allfill.checked) System.Gadget.Settings.write ("fillAll", "true");
  else System.Gadget.Settings.write ("fillAll", "false");

  if (Ramhide.checked) System.Gadget.Settings.write ("hideRam", "true");
  else System.Gadget.Settings.write ("hideRam", "false");
  if (Pagehide.checked) System.Gadget.Settings.write ("hidePage", "true");
  else System.Gadget.Settings.write ("hidePage", "false");
  if (Allhide.checked) System.Gadget.Settings.write ("hideAll", "true");
  else System.Gadget.Settings.write ("hideAll", "false");

  if (enablelogging.checked) System.Gadget.Settings.write ("LogEnabled", "true");
  else System.Gadget.Settings.write ("LogEnabled", "false");
  if (iomode.checked) System.Gadget.Settings.write ("modeIO", "true");
  else System.Gadget.Settings.write ("modeIO", "false");
  System.Gadget.Settings.write("refreshlogtime", timetologging.value);
  if (logCPUusage.checked) System.Gadget.Settings.write ("CPUusagelog", "true");
  else System.Gadget.Settings.write ("CPUusagelog", "false");
  if (logCPUfreq.checked) System.Gadget.Settings.write ("CPUfreqlog", "true");
  else System.Gadget.Settings.write ("CPUfreqlog", "false");
  if (logRAMusage.checked) System.Gadget.Settings.write ("RAMusagelog", "true");
  else System.Gadget.Settings.write ("RAMusagelog", "false");
  if (logPageusage.checked) System.Gadget.Settings.write ("Pageusagelog", "true");
  else System.Gadget.Settings.write ("Pageusagelog", "false");
  if (logAllusage.checked) System.Gadget.Settings.write ("Allusagelog", "true");
  else System.Gadget.Settings.write ("Allusagelog", "false");

  for (var i=1; i<=maxcores; i++){
   if (document.getElementById("Core" + i).checked) System.Gadget.Settings.write ("Core" + i + "fill", "true");
   else System.Gadget.Settings.write ("Core" + i + "fill", "false");

   if (document.getElementById("Corehidebar" + i).checked) System.Gadget.Settings.write ("Corehide" + i + "bar", "true");
   else System.Gadget.Settings.write ("Corehide" + i + "bar", "false");

   if (document.getElementById("Corehide" + i).checked) System.Gadget.Settings.write ("Core" + i + "hide", "true");
   else System.Gadget.Settings.write ("Core" + i + "hide", "false");

   if (document.getElementById("logCoreusage" + i).checked) System.Gadget.Settings.write ("Core" + i + "log", "true");
   else System.Gadget.Settings.write ("Core" + i + "log", "false");

   if (document.getElementById("logCoretemp" + i).checked) System.Gadget.Settings.write ("Coretemp" + i + "log", "true");
   else System.Gadget.Settings.write ("Coretemp" + i + "log", "false");
  }

  if (logCoresparking.checked) System.Gadget.Settings.write ("logParkingCore", "true");
  else System.Gadget.Settings.write ("logParkingCore", "false");

  if (parking.checked) System.Gadget.Settings.write ("ParkingCore", "true");
  else System.Gadget.Settings.write ("ParkingCore", "false");

  System.Gadget.Settings.write("dblclick", Action.value);

  tmpvalue = getCheckedValue();
  System.Gadget.Settings.write("OverheatCheck", tmpvalue);

  deltachange();
  System.Gadget.Settings.write("DeltaOverheat", delta.value);

  tjuncchange();
  System.Gadget.Settings.write("TjMaxtemp", tjmax.value);

  fixscalechange();
  System.Gadget.Settings.write("ScaleTemperatureGr", fixscale.value);
  fixscalefromchange();
  System.Gadget.Settings.write("LowScaleTemperatureGr", fixscalefrom.value);

  if (playsound.checked) System.Gadget.Settings.write ("PlaySound", "true");
  else System.Gadget.Settings.write ("PlaySound", "false");

  if (graphtemperature.checked) System.Gadget.Settings.write ("ShowTempGraph", "true");
  else System.Gadget.Settings.write ("ShowTempGraph", "false");

  if (cyclegraph.checked) System.Gadget.Settings.write ("CycleGraphEnable", "true");
  else System.Gadget.Settings.write ("CycleGraphEnable", "false");

  if (disableflyoutsounds.checked) System.Gadget.Settings.write ("DisableFlyoutSounds", "true");
  else System.Gadget.Settings.write ("DisableFlyoutSounds", "false");

  if (disableshowwheel.checked) System.Gadget.Settings.write ("DisableShowWheel", "true");
  else System.Gadget.Settings.write ("DisableShowWheel", "false");

  if (enablegetweifromwmi.checked) System.Gadget.Settings.write ("GetWEIfromWMIenable", "true");
  else System.Gadget.Settings.write ("GetWEIfromWMIenable", "false");

  if (enableswitch.checked) System.Gadget.Settings.write ("Switch", "true");
  else System.Gadget.Settings.write ("Switch", "false");
  switchtimechange();
  System.Gadget.Settings.write("SwithchRate", timetoswitch.value * 1000);

  System.Gadget.Settings.write("CPUClockFormula", CPUClockformula.value);

  System.Gadget.Settings.write("ShowCoresType", showcorestype.value);

  if (enablecheckforupdate.checked) System.Gadget.Settings.write ("AutoUpdate", "true");
  else System.Gadget.Settings.write ("AutoUpdate", "false");

  //color settings
  tmpvalue = getCheckedValue1();
  System.Gadget.Settings.write("ColorModeCheck", tmpvalue);
  System.Gadget.Settings.write("colBgColor", "#"+document.getElementById('multiColorPicker1').value);
  System.Gadget.Settings.write("colTitle", "#"+document.getElementById('multiColorPicker2').value);
  System.Gadget.Settings.write("colMemUsage", "#"+document.getElementById('multiColorPicker3').value);
  System.Gadget.Settings.write("colMemMenu", "#"+document.getElementById('multiColorPicker4').value);
  System.Gadget.Settings.write("colMemRam", "#"+document.getElementById('multiColorPicker5').value);
  System.Gadget.Settings.write("colMemPage", "#"+document.getElementById('multiColorPicker6').value);
  System.Gadget.Settings.write("colMemAll", "#"+document.getElementById('multiColorPicker7').value);
  System.Gadget.Settings.write("colCPUmodel", "#"+document.getElementById('multiColorPicker8').value);
  System.Gadget.Settings.write("colCoreCpuspeed", "#"+document.getElementById('multiColorPicker9').value);
  System.Gadget.Settings.write("colCpuused", "#"+document.getElementById('multiColorPicker10').value);
  System.Gadget.Settings.write("colCpuParked", "#"+document.getElementById('multiColorPicker11').value);
  System.Gadget.Settings.write("colFillGraph", "#"+document.getElementById('multiColorPicker12').value);
  System.Gadget.Settings.write("colVersion", "#"+document.getElementById('multiColorPicker13').value);
  System.Gadget.Settings.write("colCopyright", "#"+document.getElementById('multiColorPicker14').value);
  System.Gadget.Settings.write("colCpuAllinone", "#"+document.getElementById('multiColorPicker15').value);
  for (var i=1; i<=maxcores; i++){
   System.Gadget.Settings.write("Core" + i + "col", "#"+document.getElementById('multiColorPicker' + (i+15)).value);
  }
  System.Gadget.Settings.write("colCpuEasy", "#"+document.getElementById('multiColorPicker40').value);
  System.Gadget.Settings.write("colCpuMedium", "#"+document.getElementById('multiColorPicker41').value);
  System.Gadget.Settings.write("colCpuHard", "#"+document.getElementById('multiColorPicker42').value);

  savesettingstofile();
 }
 event.cancel = false;
}

var names = new Array ("tabname_1","tabname_2","tabname_3","tabname_4","tabname_5","tabname_6","tabname_7","tabname_8","tabname_9","tabname_10","tabname_11","tabname_12","tabname_13");
var conts= new Array ("tabcontent_1","tabcontent_2","tabcontent_3","tabcontent_4","tabcontent_5","tabcontent_6","tabcontent_7","tabcontent_8","tabcontent_9","tabcontent_10","tabcontent_11","tabcontent_12","tabcontent_13");

function showtab(id){
 for(i=0;i<names.length;i++) { document.getElementById(names[i]).className = 'nonactive' }
 for(i=0;i<conts.length;i++) { document.getElementById(conts[i]).className = 'hide' }
 document.getElementById('tabname_' + id).className = 'active';
 document.getElementById('tabcontent_' + id).className = 'show';
}

//Warning!!! This function need for switch to #8 tab from settings
function showtab8(){
 for(i=0;i<names.length;i++) { document.getElementById(names[i]).className = 'nonactive' }
 for(i=0;i<conts.length;i++) { document.getElementById(conts[i]).className = 'hide' }
 document.getElementById('tabname_8').className = 'active';
 document.getElementById('tabcontent_8').className = 'show';
}

function savesettingstofile(){
 var inifilename = System.Environment.getEnvironmentVariable("APPDATA") + "\\" + System.Gadget.name + "_CPU" + CPUnumber.value + "_Settings.ini";
 try {
  var inifile = fs.OpenTextFile(inifilename, 2, true); //2 write file true - create file

  try {
   inifile.WriteLine(";System Monitor II (c) 2010-2013 by Igor 'Igogo' Bushin");
   inifile.WriteLine(";CPU" + CPUnumber.value + " configuration file");
   inifile.WriteLine(";purr purr meow meow");

   inifile.WriteLine(languagelist.value);
   //color settings
   tmpvalue = getCheckedValue1();
   inifile.WriteLine(tmpvalue);
   inifile.WriteLine(document.getElementById("BgColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker1').value);
   inifile.WriteLine(document.getElementById("TitColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker2').value);
   inifile.WriteLine(document.getElementById("MemColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker3').value);
   inifile.WriteLine(document.getElementById("MMemColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker4').value);
   inifile.WriteLine(document.getElementById("RamMemColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker5').value);
   inifile.WriteLine(document.getElementById("PageMemColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker6').value);
   inifile.WriteLine(document.getElementById("AllMemColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker7').value);
   inifile.WriteLine(document.getElementById("CPUnameColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker8').value);
   inifile.WriteLine(document.getElementById("CoreColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker9').value);
   inifile.WriteLine(document.getElementById("CPUusedColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker10').value);
   inifile.WriteLine(document.getElementById("ParkingColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker11').value);
   inifile.WriteLine(document.getElementById("GrBgColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker12').value);
   inifile.WriteLine(document.getElementById("VersnColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker13').value);
   inifile.WriteLine(document.getElementById("CopyColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker14').value);
   inifile.WriteLine(document.getElementById("SingleColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker15').value);
   for (var i=1; i<=maxcores; i++){
    inifile.WriteLine(document.getElementById("Core" + i + "ColorSelect").selectedIndex);
    inifile.WriteLine('#'+document.getElementById('multiColorPicker' + (i+15)).value);
   }
   inifile.WriteLine(document.getElementById("EasyLoadColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker40').value);
   inifile.WriteLine(document.getElementById("ModerateLoadColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker41').value);
   inifile.WriteLine(document.getElementById("HardLoadColorSelect").selectedIndex);
   inifile.WriteLine('#'+document.getElementById('multiColorPicker42').value);
   //color settings end

   inifile.WriteLine(bargrapsmode.value);
   inifile.WriteLine(easyload.value);
   inifile.WriteLine(mediumload.value);
   inifile.WriteLine(timetorefresh.value * 1000);
   inifile.WriteLine(size.value / 100);
   inifile.WriteLine(MemGraphType.value);
   inifile.WriteLine(Action.value);
   inifile.WriteLine(CPUBarsType.value);

   if (hidememused.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   if (hidememnumbers.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (hideRAMnumbers.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (hidePAGEnumbers.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (hideALLnumbers.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   if (hidemembars.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (hideRAMbars.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (hidePAGEbars.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (hideALLbars.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   if (hideCPUident.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (hideCPUclock.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (hideCPUusage.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   if (hidecpubars.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   if (hidecpugraphics.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   if (hidememgraphics.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   if (Ramfill.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (Pagefill.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (Allfill.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   
   if (Ramhide.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (Pagehide.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (Allhide.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   for (var i=1; i<=maxcores; i++){
    if (document.getElementById("Core" + i).checked) inifile.WriteLine("true");
    else inifile.WriteLine("false");

    if (document.getElementById("Corehidebar" + i).checked) inifile.WriteLine("true");
    else inifile.WriteLine("false");

    if (document.getElementById("Corehide" + i).checked) inifile.WriteLine("true");
    else inifile.WriteLine("false");
   }

   if (parking.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   if (coretemp.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   tmpvalue = getCheckedValue();
   inifile.WriteLine(tmpvalue);
   
   inifile.WriteLine(delta.value);

   inifile.WriteLine(tjmax.value);

   if (playsound.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   if (graphtemperature.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   inifile.WriteLine(fixscalefrom.value);
   inifile.WriteLine(fixscale.value);

   if (cyclegraph.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   if (enablelogging.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (iomode.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   inifile.WriteLine(timetologging.value);
   if (logCPUusage.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (logCPUfreq.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (logRAMusage.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (logPageusage.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (logAllusage.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   for (var i=1; i<=maxcores; i++){
    if (document.getElementById("logCoreusage" + i).checked) inifile.WriteLine("true");
    else inifile.WriteLine("false");
    if (document.getElementById("logCoretemp" + i).checked) inifile.WriteLine("true");
    else inifile.WriteLine("false");
   }
   if (logCoresparking.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   if (hidetitle.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   if (hidecopyright.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   inifile.WriteLine(graphlinewidth.value);

   if (hidegridlines.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   if (allinone.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   if (coretempinfo.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   inifile.WriteLine(CPUGraphType.value);

   if (enablecheckforupdate.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   if (disableflyoutsounds.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   if (enablegetweifromwmi.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   if (enableswitch.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
   inifile.WriteLine(timetoswitch.value * 1000);

   inifile.WriteLine(CPUClockformula.value);

   inifile.WriteLine(showcorestype.value);

   if (disableshowwheel.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");

   if (autoscaleDPI.checked) inifile.WriteLine("true");
   else inifile.WriteLine("false");
  }//end try 2

  finally {inifile.Close()}
 }//end try 1

 catch (e) {}
}

function restorefactorycolors1(){
 System.Gadget.Settings.write("sBgColorSelect",0);
 document.getElementById("BgColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor1").style.background = document.getElementById("BgColorSelect").value;
 document.getElementById("multiColorPicker1").value = document.getElementById("BgColorSelect").value.substr(1);
 System.Gadget.Settings.write("sTitColorSelect",0);
 document.getElementById("TitColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor2").style.background = document.getElementById("TitColorSelect").value;
 document.getElementById("multiColorPicker2").value = document.getElementById("TitColorSelect").value.substr(1);
 System.Gadget.Settings.write("sMemColorSelect",0);
 document.getElementById("MemColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor3").style.background = document.getElementById("MemColorSelect").value;
 document.getElementById("multiColorPicker3").value = document.getElementById("MemColorSelect").value.substr(1);
 System.Gadget.Settings.write("sMMemColorSelect",0);
 document.getElementById("MMemColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor4").style.background = document.getElementById("MMemColorSelect").value;
 document.getElementById("multiColorPicker4").value = document.getElementById("MMemColorSelect").value.substr(1);
 System.Gadget.Settings.write("sRamMemColorSelect",0);
 document.getElementById("RamMemColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor5").style.background = document.getElementById("RamMemColorSelect").value;
 document.getElementById("multiColorPicker5").value = document.getElementById("RamMemColorSelect").value.substr(1);
 System.Gadget.Settings.write("sPageMemColorSelect",0);
 document.getElementById("PageMemColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor6").style.background = document.getElementById("PageMemColorSelect").value;
 document.getElementById("multiColorPicker6").value = document.getElementById("PageMemColorSelect").value.substr(1);
 System.Gadget.Settings.write("sAllMemColorSelect",0);
 document.getElementById("AllMemColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor7").style.background = document.getElementById("AllMemColorSelect").value;
 document.getElementById("multiColorPicker7").value = document.getElementById("AllMemColorSelect").value.substr(1);
 System.Gadget.Settings.write("sCPUnameColorSelect",0);
 document.getElementById("CPUnameColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor8").style.background = document.getElementById("CPUnameColorSelect").value;
 document.getElementById("multiColorPicker8").value = document.getElementById("CPUnameColorSelect").value.substr(1);
 System.Gadget.Settings.write("sCoreColorSelect",0);
 document.getElementById("CoreColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor9").style.background = document.getElementById("CoreColorSelect").value;
 document.getElementById("multiColorPicker9").value = document.getElementById("CoreColorSelect").value.substr(1);
 System.Gadget.Settings.write("sCPUusedColorSelect",0);
 document.getElementById("CPUusedColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor10").style.background = document.getElementById("CPUusedColorSelect").value;
 document.getElementById("multiColorPicker10").value = document.getElementById("CPUusedColorSelect").value.substr(1);
 System.Gadget.Settings.write("sParkingColorSelect",0);
 document.getElementById("ParkingColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor11").style.background = document.getElementById("ParkingColorSelect").value;
 document.getElementById("multiColorPicker11").value = document.getElementById("ParkingColorSelect").value.substr(1);
 System.Gadget.Settings.write("sGrBgColorSelect",0);
 document.getElementById("GrBgColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor12").style.background = document.getElementById("GrBgColorSelect").value;
 document.getElementById("multiColorPicker12").value = document.getElementById("GrBgColorSelect").value.substr(1);
 System.Gadget.Settings.write("sVersnColorSelect",0);
 document.getElementById("VersnColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor13").style.background = document.getElementById("VersnColorSelect").value;
 document.getElementById("multiColorPicker13").value = document.getElementById("VersnColorSelect").value.substr(1);
 System.Gadget.Settings.write("sCopyColorSelect",0);
 document.getElementById("CopyColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor14").style.background = document.getElementById("CopyColorSelect").value;
 document.getElementById("multiColorPicker14").value = document.getElementById("CopyColorSelect").value.substr(1);
}

function restorefactorycolors2(){
 System.Gadget.Settings.write("sSingleColorSelect",0);
 document.getElementById("SingleColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor15").style.background = document.getElementById("SingleColorSelect").value;
 document.getElementById("multiColorPicker15").value = document.getElementById("SingleColorSelect").value.substr(1);
 for (var i=1; i<=maxcores; i++){
  System.Gadget.Settings.write("sCore" + i + "ColorSelect",0); 
  document.getElementById("Core" + i + "ColorSelect").selectedIndex = 0;
  document.getElementById("simplecolor" + (i+15)).style.background = document.getElementById("Core" + i + "ColorSelect").value;
  document.getElementById("multiColorPicker" + (i+15)).value = document.getElementById("Core" + i + "ColorSelect").value.substr(1);
 }
 System.Gadget.Settings.write("sEasyLoadColorSelect",0);
 document.getElementById("EasyLoadColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor40").style.background = document.getElementById("EasyLoadColorSelect").value;
 document.getElementById("multiColorPicker40").value = document.getElementById("EasyLoadColorSelect").value.substr(1);
 System.Gadget.Settings.write("sModerateLoadColorSelect",0);
 document.getElementById("ModerateLoadColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor41").style.background = document.getElementById("ModerateLoadColorSelect").value;
 document.getElementById("multiColorPicker41").value = document.getElementById("ModerateLoadColorSelect").value.substr(1);
 System.Gadget.Settings.write("sHardLoadColorSelect",0);
 document.getElementById("HardLoadColorSelect").selectedIndex = 0;
 document.getElementById("simplecolor42").style.background = document.getElementById("HardLoadColorSelect").value;
 document.getElementById("multiColorPicker42").value = document.getElementById("HardLoadColorSelect").value.substr(1);
}

function colorSelected(obj1,obj2,obj3){
 document.getElementById(obj1).blur();
 if (document.getElementById(obj1).selectedIndex == document.getElementById(obj1).length - 1){
  document.getElementById(obj2).disabled = false;
 }
 else{
  document.getElementById(obj2).disabled = true;
  document.getElementById(obj3).style.background = document.getElementById(obj1).value;
  document.getElementById(obj2).value = document.getElementById(obj1).value.substr(1);
 }
 System.Gadget.Settings.write("s"+obj1,document.getElementById(obj1).selectedIndex);
}

function needenable(obj1,obj2){
 if (document.getElementById(obj1).selectedIndex == document.getElementById(obj1).length - 1) document.getElementById(obj2).disabled = false;
 else document.getElementById(obj2).disabled = true;
}

function showlogfile(){
 var logfilename = System.Environment.getEnvironmentVariable("APPDATA") + "\\" + System.Gadget.name + "_CPU" + CPUnumber.value + "_log.txt";
 System.Shell.execute("notepad", logfilename);
}

function restoresettingstodefault(){
 CPUnumber.options.length = 0;
 var colItems = wmiService.ExecQuery("SELECT Name FROM Win32_Processor");
 var enumItems = new Enumerator(colItems);
 for (var i=0; !enumItems.atEnd(); enumItems.moveNext()){
  var objItem = enumItems.item();
  var name = objItem.Name;
  if(name.length > 40) name = name.substr(0,40);
  newOption = new Option(i + ": " + name, i);
  CPUnumber.options[CPUnumber.length] = newOption;
  i++;
 }
 CPUnumber.disabled = (CPUnumber.length < 2);
 switching.disabled = (CPUnumber.length < 2);
 CPUnumber.value = 0;
 setlogfilename();
 bargrapsmode.value = 0;
 languagelist.value = 0;
 loadpartcheck();
 easyload.options.length = 0;
 for (var i=1; i<99; i++){
  newOption = new Option(i, i);
  easyload.options[easyload.length] = newOption;
 }
 resettodefault();
 size.value = 100;
 timetorefresh.value = 1;
 autoscaleDPI.checked = true;
 hidesize();
 //!!! procedures order check graphtemperature and setCheckedValue first, coreclick and grtempclick after
 graphtemperature.checked = false;
 cyclegraph.checked = false;
 setCheckedValue(0);
 coretemp.checked = false;
 //place after check CoreTempUse
 coretempinfo.checked = false;
 allinone.checked = false;
 //place CPUGraphType before allinonesetup()
 CPUGraphType.value = 0;
 allinonesetup();
 //place after allinonesetup
 MemGraphType.value = 0;
 hideramgraphsrttings();
 fixscalefrom.value = 0;
 fixscale.value = 100;
 CPUBarsType.value = 0;
 hidetitle.checked = false;
 hidecopyright.checked = false;
 hidegridlines.checked = false;
 hidememused.checked = false;
 hidememnumbers.checked = false;
 hideRAMnumbers.checked = false;
 hidePAGEnumbers.checked = false;
 hideALLnumbers.checked = false;
 hidemembars.checked = false;
 hideRAMbars.checked = false;
 hidePAGEbars.checked = false;
 hideALLbars.checked = false;
 hideCPUident.checked = false;
 hideCPUclock.checked = false;
 hideCPUusage.checked = false;
 hidecpubars.checked = false;
 hidememgraphics.checked = false;
 hidecpugraphics.checked = false;
 graphlinewidth.value = 1;
 Ramfill.checked = false;
 Pagefill.checked = false;
 Allfill.checked = false;
 Ramhide.checked = false;
 Pagehide.checked = false;
 Allhide.checked = false;
 enablelogging.checked = false;
 iomode.checked = false;
 timetologging.value = 300000;
 logCPUusage.checked = false;
 logCPUfreq.checked = false;
 logRAMusage.checked = false;
 logPageusage.checked = false;
 logAllusage.checked = false;
 for (var i=1; i<=maxcores; i++){
  document.getElementById("Core" + i).checked = false;
  document.getElementById("Corehidebar" + i).checked = false;
  document.getElementById("Corehide" + i).checked = false;
  document.getElementById("logCoreusage" + i).checked = false;
  document.getElementById("logCoretemp" + i).checked = false;
 }
 logCoresparking.checked = false;
 parking.checked = false;
 Action.value = 0;
 delta.value = 10;
 tjmax.value = 90;
 playsound.checked = false;
 logclick(); //after check enablelogging
 disableflyoutsounds.checked = false;
 disableshowwheel.checked = false;
 enablegetweifromwmi.checked = false;
 enableswitch.checked = false;
 swithflagchange();
 timetoswitch.value = 10;
 CPUClockformula.value = 0;
 enablecheckforupdate.checked = false;
 setCheckedValue1(0);
 ColorSettingsChanged(); 
 restorefactorycolors1();
 restorefactorycolors2();
 // plase in the end of restore
 showcorestype.value = 0;
 setupCPUsoutput();
 if (CPUnumber.length < 2){
  hideformultyCPU.disabled = true;
  showcorestype.value = 0;
 }
}