//no viruses
try{var xmlHttp = new XMLHttpRequest()}
catch (e){var xmlHttp = new ActiveXObject('Microsoft.XMLHTTP')}
var shell = new ActiveXObject("Shell.Application");
var wshShell = new ActiveXObject("WScript.Shell");
var locator = new ActiveXObject("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(null, "root\\cimv2");
var fs = new ActiveXObject("Scripting.FileSystemObject");
var regPath = "HKCU\\software\\Crystal Dew World\\CrystalDiskInfo\\";

var lngID;

System.Gadget.Flyout.file = "Flyout.html";
System.Gadget.settingsUI = "settings.html";

document.onselectstart = function() {return false};

// History of values for graphing purposes.
var history = {};
// Excluded drive letters saved in a bit mask with A = 1, B = 2, C = 4 and so on.
var excludedDrivesMask;
var excludedDrivesNumberMask;
var mask;
var usbpic;
var driveforflyout;

var diskcount;
var temperatures = new Array();
var tmplast = 0; //important
var lastUpdate = 0; //important
var CrystalDiskInfoNotFound;
var statuspic;

var maxHistory	= 112;//Important
var factheight;
var resultSet;
var resultDriveCounter;
var fromwhere;
var refreshRate;
var updateTimerId;
var firstupdatetimer;
var driveHeight;
var addheight;
var addheight1;
var addheighttemp;
var topMargin;
var addtotop;
var bottomMargin;
var diskmode;
var size;
var graphlinewidth;
var setgadgetchange;
var hidegraph;
var hidehiddendrive;
var hidemounteddrive;
var shortinfo;
var hidetitleflag;
var hidecopyrightflag;
var hidegridlinesflag;
var activefillflag;
var readfillflag;
var writefillflag;
var chooseactivityflag;
var disklabel;
var dsktotal;
var dskfree;
var dskused;
var dskfrmt;
var dsktype;
var tmpdriveletter;
var warningpercent;
var criticalpercent;
var hidecountersflag;
var disableflyoutsoundsflag;
var autoscaleDPIflag;
var savedisksflag;
var tmpdskmode = 0;//Important
var tmpdskletters = 0;//Important
var tmpdsknumbers = "";//Important
var returnfromsettings = false;
var showtemperatureflag;
var autoupdateflag;

//color settings
var cBgColor;
var cTitle;
var cDiskName;
var cDiskInfo;
var cFileSystem;
var cDiskPeak;
var cDiskActivity;
var cDiskRead;
var cDiskWrite;
var cCounterRead;
var cCounterWrite;
var cDiskEasy;
var cDiskMedium;
var cDiskHard;
var cFillGraph;
var cFillPeak;
var cErrMsg;
var cCopyright;
var cVersion;

var updateavailable;
var showupdate;
var autoupdatestr;

function CheckUpdates(){
 if (!updateavailable) autoupdate();

 if (updateavailable && !showupdate){
  factheight += 12;
  document.body.style.height = parseInt(factheight * size);
  background.style.height = parseInt(factheight * size);
  mainsquare.style.height =   fromwhere ? parseInt((factheight - 10) * size) : parseInt((factheight - 12) * size);
  autoapdater.style.visibility = "visible";
  showupdate = true;
 }

 updateTimerId = setTimeout("CheckUpdates()", 86400000);// Update once a day
}

function autoupdate(){
 var url = "http://www.myfavoritegadgets.info/monitors/DrivesMonitor/DrivesMonitorversioninfo.xml";
 xmlHttp.open("GET", url, false); //false mean call is synchronous
 xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"); //for non cached
 xmlHttp.send(null);
 if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
  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)){
   autoupdatestr = "<a id='ulink' href='" + updateUrl + "' style='text-decoration:none;color:" + cDiskInfo +
   "' onclick='System.Gadget.close()' onmouseout='ulink.style.textDecoration=" + '"none"' + "' onmouseover='ulink.style.textDecoration=" +
   + '"underline"' + "'>" + mainlng[lngID][19] + "<strong>" + newVersion + "</strong>" + mainlng[lngID][20] + "</a>";
   autoapdater.innerHTML = autoupdatestr;
   updateavailable = true;
  }// if
 }// if
}

function showFlyout(name){
 if (!System.Gadget.Flyout.show){
  System.Gadget.Flyout.show = true;
  if (!disableflyoutsoundsflag) System.Sound.playSound("media/service.wav");
  driveforflyout = name;
 }
 else System.Gadget.Flyout.show = false;
}

function getDPIsize() {
    try {
        var getdefaultDPI = 0;
        try {
            getdefaultDPI = wshShell.RegRead("HKCU\\Software\\8GadgetPack\\ForceDPI");
        }
        catch (e) { }
        if (getdefaultDPI == 0)
            getdefaultDPI = wshShell.RegRead("HKCU\\Control Panel\\Desktop\\LogPixels");
        size = parseInt((getdefaultDPI / 96) * 100) / 100;
        System.Gadget.Settings.write("SetSize", size);
    }
    catch (e) { }
}

function doit(){
 try{counterstatus = wshShell.RegRead("HKLM\\SYSTEM\\CurrentControlSet\\Services\\PerfDisk\\Performance\\Disable Performance Counters")}
 catch (e){counterstatus = 0}
 if (counterstatus){
  var errhtml = '<g:background id="background" src="images/background.png">';
  errhtml += '<div id="mainsquare" style="position:absolute"></div>';
  errhtml += '<div style="position:absolute;top:6px;width:100%;text-align:center;font-size:12px;color:#FFFFFF;font-weight:bold">' + mainlng[0][0] + '</div>';
  errhtml += '<div style="position:absolute;top:16px;width:100%"><hr align="center" width="' + tech[0] +'" color="#808080"></div>';
  errhtml += '<div style="position:absolute;top:26px;width:100%;text-align:center"><img src="images/alert.png" style="width:16;height:16" /></div>';
  errhtml += '<div style="position:absolute;top:42px;width:100%;font-size:12px;text-align:center;color:#FF0000;font-weight:bold">' + 'PerfDisk is disabled!!!<br>' +
  '<a style="color:#FF0000" href="http://www.myfavoritegadgets.info/counters/NoPerfcounters.html" onclick="System.Gadget.close()" target="_blank">Click HERE</a></div>';
  errhtml += '<div id="advertis" style="position:absolute;width:100%;top:78px;left:10px;font-size:10px">' +
  '<a class="ads" style="color:#00CCFF" href="http://www.myfavoritegadgets.info/" target="_blank">&copy; 2013 by Igogo</a></div>';
  errhtml += '<div id="versionnumber" style="position:absolute;font-size:9px;top:78px;left:0px;width:120px;text-align:right;' +
  'color:#C0C0C0">v' + System.Gadget.version + '</div>';
  document.body.innerHTML = errhtml + "</g:background>";
  document.body.style.width = 130;
  background.style.width = 130;
  document.body.style.height = 98;
  background.style.height = 98;
  mainsquare.style.top = 5;
  mainsquare.style.left = 5;
  mainsquare.style.width = 120;
  mainsquare.style.height = 88;
  mainsquare.style.background = "#262526";
  System.Gadget.settingsUI = "";
  return;
 }
 setgadgetchange = true;
 // ======= Important !!! =======
 autoupdatestr = "";
 updateavailable = false;
 showupdate = false;
 // ======= Important !!! =======
 loadsettingsfromfile(); //don't move this line!!!
 init();
}

function getDiskInfo(driveLetter){
 var nameLetter;
 disklabel= "";
 dsktotal = mainlng[lngID][7];
 dskfree  = mainlng[lngID][7];
 dskused  = mainlng[lngID][7];
 dskfrmt  = mainlng[lngID][7];
 if (driveLetter.indexOf("HarddiskVolume") == -1){
  if (driveLetter.charAt(2) != "\\") nameLetter = driveLetter;
  else{
   var res = /\\/g;
   nameLetter = driveLetter.replace(res,'\\\\');
  }
  nameLetter += "\\\\";
  var resultDriveInfo = service.ExecQuery("SELECT * FROM Win32_Volume WHERE Name = '" + nameLetter + "'");
  try{
   disklabel = (resultDriveInfo.ItemIndex(0).Label != null) ? " " + resultDriveInfo.ItemIndex(0).Label : "";
   dsktotal = (resultDriveInfo.ItemIndex(0).Capacity != null) ? resultDriveInfo.ItemIndex(0).Capacity : mainlng[lngID][7];
   dskfree = (resultDriveInfo.ItemIndex(0).FreeSpace != null) ? resultDriveInfo.ItemIndex(0).FreeSpace : mainlng[lngID][7];
   dskused = (dsktotal != mainlng[lngID][7] && dskfree != mainlng[lngID][7]) ? dsktotal - dskfree : mainlng[lngID][7];
   if (resultDriveInfo.ItemIndex(0).FileSystem != null){
    dskfrmt = resultDriveInfo.ItemIndex(0).FileSystem;
    if (history[driveLetter].physdrvtype == 2) history[driveLetter].usbeject = false;
   }
   else{
    if (history[driveLetter].physdrvtype == 2) dskfrmt = history[driveLetter].usbeject ? mainlng[lngID][8] : mainlng[lngID][9];
    else dskfrmt = mainlng[lngID][7];
   }
  } //end try
  catch(e){
   disklabel = "";
   dsktotal = mainlng[lngID][7];
   dskfree  = mainlng[lngID][7];
   dskused  = mainlng[lngID][7];
   dskfrmt  = mainlng[lngID][7];
  }
 }//end if
 else{
  var resultDriveInfo = service.ExecQuery("SELECT * FROM Win32_Volume");
  var DriveInfoResult = new Enumerator(resultDriveInfo);
  for (var i = 0; i < (resultDriveInfo.Count); i++){
   if (DriveInfoResult.item().Name.indexOf("Volume") != -1){
    if (parseInt(DriveInfoResult.item().FreeSpace / 1024 / 1024) == history[driveLetter].freemegabytes){
     disklabel = (DriveInfoResult.item().Label != null) ? " " + DriveInfoResult.item().Label : "";
     dsktotal = (DriveInfoResult.item().Capacity != null) ? DriveInfoResult.item().Capacity : mainlng[lngID][7];
     dskfree = (DriveInfoResult.item().FreeSpace != null) ? DriveInfoResult.item().FreeSpace : mainlng[lngID][7];
     dskused = (dsktotal != mainlng[lngID][7] && dskfree != mainlng[lngID][7]) ? dsktotal - dskfree : mainlng[lngID][7];
     dskfrmt = (DriveInfoResult.item().FileSystem != null) ? DriveInfoResult.item().FileSystem : mainlng[lngID][7];
    }
    break;
   }
   DriveInfoResult.moveNext();
  }
 }//else
}

function getDiskType(driveLetter){
 dsktype = 1;
 var resultDriveInfo = service.ExecQuery("SELECT * FROM Win32_Volume WHERE DriveLetter = '" + driveLetter + "'");
 try{dsktype = resultDriveInfo.ItemIndex(0).DriveType}
 catch(e){dsktype = 1}
}

function removeUSB(USBDriveLetter){
 try{shell.NameSpace(17).ParseName(USBDriveLetter).InvokeVerb("Eject")}
 catch (e){}
 if (diskmode == "0") history[USBDriveLetter].usbeject = true;
}

function letterInMask(letter, mask){
 var letterValue = Math.pow(2, letter.charCodeAt(0) - 65);
 return ((letterValue & mask) == letterValue);
}

function init(){
 refresh();
 timevar = setTimeout("init()",refreshRate);
}

function loadsettings(){
 size = System.Gadget.Settings.read("SetSize");
 if (size == ''){
  size = "1";
  System.Gadget.Settings.write("SetSize", size);
 }

 autoscaleDPIflag = System.Gadget.Settings.read ("DPIautoscale");
 if (autoscaleDPIflag != "false"){
  autoscaleDPIflag = true;
  System.Gadget.Settings.write ("DPIautoscale", "true");
 }
 else{
  autoscaleDPIflag = false;
  System.Gadget.Settings.write ("DPIautoscale", "false");
 }

 refreshRate = System.Gadget.Settings.read("refreshtime");
 if(refreshRate == ''){
  refreshRate = "1000";
  System.Gadget.Settings.write("refreshtime", refreshRate);
 }

 savedisksflag = System.Gadget.Settings.read ("SaveDisksLettersNumbers");
 if (savedisksflag != "true"){
  savedisksflag = false;
  System.Gadget.Settings.write ("SaveDisksLettersNumbers", "false");
 }
 else{
  savedisksflag = true;
  System.Gadget.Settings.write ("SaveDisksLettersNumbers", "true");
 }
 if (returnfromsettings){
  diskmode = System.Gadget.Settings.read("WhichDrivesICanSee");
  if (diskmode == ''){
   diskmode = "0";
   System.Gadget.Settings.write("WhichDrivesICanSee", diskmode);
  }
  excludedDrivesMask = System.Gadget.Settings.read("ExcludedDrives");
  excludedDrivesNumberMask = System.Gadget.Settings.read("ExcludedDrivesNumber");
 }
 else{
  if (!savedisksflag){
   diskmode = System.Gadget.Settings.read("WhichDrivesICanSee");
   if (diskmode == ''){
    diskmode = "0";
    System.Gadget.Settings.write("WhichDrivesICanSee", diskmode);
   }
   excludedDrivesMask = System.Gadget.Settings.read("ExcludedDrives");
   excludedDrivesNumberMask = System.Gadget.Settings.read("ExcludedDrivesNumber");
  }
  else{
   diskmode = tmpdskmode;
   System.Gadget.Settings.write("WhichDrivesICanSee", diskmode);
   excludedDrivesMask = tmpdskletters;
   System.Gadget.Settings.write("ExcludedDrives", excludedDrivesMask);
   excludedDrivesNumberMask = tmpdsknumbers;
   System.Gadget.Settings.write("ExcludedDrivesNumber", excludedDrivesNumberMask);
  }
 }
 returnfromsettings = false;

 showtemperatureflag  = System.Gadget.Settings.read ("ShowDiskTemperature");
 if (showtemperatureflag  != "true"){
  showtemperatureflag = false;  
  System.Gadget.Settings.write ("ShowDiskTemperature", "false");
 }
 else{
  System.Gadget.Settings.write ("ShowDiskTemperature", "true");
  showtemperatureflag = true;
 }

 shortinfo = System.Gadget.Settings.read ("HideFullDiskInfo");
 if (shortinfo != "true"){
  System.Gadget.Settings.write ("HideFullDiskInfo", "false");
  shortinfo = false;
 }
 else{
  System.Gadget.Settings.write ("HideFullDiskInfo", "true");
  shortinfo = true;
 }

 hidegraph = System.Gadget.Settings.read ("GraphHide");
 if (hidegraph != "true"){
  System.Gadget.Settings.write ("GraphHide", "false");
  hidegraph = false;
 }
 else{
  System.Gadget.Settings.write ("GraphHide", "true");
  hidegraph = true;
 }
 
 hidehiddendrive  = System.Gadget.Settings.read ("HiddenPartHide");
 if (hidehiddendrive  != "true"){
  hidehiddendrive = false;  
  System.Gadget.Settings.write ("HiddenPartHide", "false");
 }
 else{
  System.Gadget.Settings.write ("HiddenPartHide", "true");
  hidehiddendrive = true;
 }

 hidemounteddrive  = System.Gadget.Settings.read ("MountedPartHide");
 if (hidemounteddrive  != "true"){
  hidemounteddrive = false;  
  System.Gadget.Settings.write ("MountedPartHide", "false");
 }
 else{
  System.Gadget.Settings.write ("MountedPartHide", "true");
  hidemounteddrive = true;
 }

 hidetitleflag = System.Gadget.Settings.read ("TitleHide");
 if (hidetitleflag != "true"){
  hidetitleflag = false;
  System.Gadget.Settings.write ("TitleHide", "false");
 }
 else{
  hidetitleflag = true;
  System.Gadget.Settings.write ("TitleHide", "true");
 }
 hidecopyrightflag = System.Gadget.Settings.read ("CopyrightHide");
 if (hidecopyrightflag != "true"){
  hidecopyrightflag = false;
  System.Gadget.Settings.write ("CopyrightHide", "false");
 }
 else{
  hidecopyrightflag = true;
  System.Gadget.Settings.write ("CopyrightHide", "true");
 }

 warningpercent = System.Gadget.Settings.read("WarningUse");
 if (warningpercent == ''){
  warningpercent = "90";
  System.Gadget.Settings.write("WarningUse", warningpercent);
 }

 criticalpercent = System.Gadget.Settings.read("CriticalUse");
 if (criticalpercent == ''){
  criticalpercent = "95";
  System.Gadget.Settings.write("CriticalUse", criticalpercent);
 }

 graphlinewidth = System.Gadget.Settings.read("GraphLineWidth");
 if(graphlinewidth == ''){
  graphlinewidth = "1";
  System.Gadget.Settings.write("GraphLineWidth", graphlinewidth);
 }

 hidegridlinesflag = System.Gadget.Settings.read ("GridlinesHide");
 if (hidegridlinesflag != "true"){
  hidegridlinesflag = false;
  System.Gadget.Settings.write ("GridlinesHide", "false");
 }
 else{
  hidegridlinesflag = true;
  System.Gadget.Settings.write ("GridlinesHide", "true");
 }

 activefillflag = System.Gadget.Settings.read ("fillActivity");
 if (activefillflag != "true"){
  activefillflag = false;
  System.Gadget.Settings.write ("fillActivity", "false");
 }
 else{
  activefillflag = true;
  System.Gadget.Settings.write ("fillActivity", "true");
 }
 readfillflag = System.Gadget.Settings.read ("fillRead");
 if (readfillflag != "true"){
  readfillflag = false;
  System.Gadget.Settings.write ("fillRead", "false");
 }
 else{
  readfillflag = true;
  System.Gadget.Settings.write ("fillRead", "true");
 }
 writefillflag = System.Gadget.Settings.read ("fillWrite");
 if (writefillflag != "true"){
  writefillflag = false;
  System.Gadget.Settings.write ("fillWrite", "false");
 }
 else{
  writefillflag = true;
  System.Gadget.Settings.write ("fillWrite", "true");
 }

 chooseactivityflag = System.Gadget.Settings.read ("ChooseActivity");
 if (chooseactivityflag != "true"){
  chooseactivityflag = false;
  System.Gadget.Settings.write ("ChooseActivity", "false");
 }
 else{
  chooseactivityflag = true;
  System.Gadget.Settings.write ("ChooseActivity", "true");
 }

 hidecountersflag = System.Gadget.Settings.read ("CountersHide");
 if (hidecountersflag != "true"){
  hidecountersflag = false;
  System.Gadget.Settings.write ("CountersHide", "false");
 }
 else{
  hidecountersflag = true;
  System.Gadget.Settings.write ("CountersHide", "true");
 }

 disableflyoutsoundsflag = System.Gadget.Settings.read ("DisableFlyoutSounds");
 if (disableflyoutsoundsflag != "true"){
  disableflyoutsoundsflag = false;
  System.Gadget.Settings.write ("DisableFlyoutSounds", "false");
 }
 else{
  disableflyoutsoundsflag = true;
  System.Gadget.Settings.write ("DisableFlyoutSounds", "true");
 }

 autoupdateflag = System.Gadget.Settings.read ("AutoUpdate");
 if (autoupdateflag != "true"){
  autoupdateflag = false;
  System.Gadget.Settings.write ("AutoUpdate", "false");
 }
 else{
  autoupdateflag = true;
  System.Gadget.Settings.write ("AutoUpdate", "true");
 }
}

function loadcolorsettings(){
 //color settings
 cBgColor = System.Gadget.Settings.read("colBgColor");
 if (cBgColor == ''){
  cBgColor = "#262526";
  System.Gadget.Settings.write("colBgColor", cBgColor);
 }
 cTitle = System.Gadget.Settings.read("colTitle");
 if (cTitle == ''){
  cTitle = "#FFFFFF";
  System.Gadget.Settings.write("colTitle", cTitle);
 }
 cDiskName = System.Gadget.Settings.read("colDiskName");
 if (cDiskName == ''){
  cDiskName = "#FFFFFF";
  System.Gadget.Settings.write("colDiskName", cDiskName);
 }
 cDiskInfo = System.Gadget.Settings.read("colDiskInfo");
 if (cDiskInfo == ''){
  cDiskInfo = "#FFCC00";
  System.Gadget.Settings.write("colDiskInfo", cDiskInfo);
 }
 cFileSystem = System.Gadget.Settings.read("colFileSystem");
 if (cFileSystem == ''){
  cFileSystem = "#FFFFFF";
  System.Gadget.Settings.write("colFileSystem", cFileSystem);
 }
 cDiskPeak = System.Gadget.Settings.read("colDiskPeak");
 if (cDiskPeak == ''){
  cDiskPeak = "#FFFFFF";
  System.Gadget.Settings.write("colDiskPeak", cDiskPeak);
 }
 cDiskActivity = System.Gadget.Settings.read("colDiskActivity");
 if (cDiskActivity == ''){
  cDiskActivity = "#87CEFA";
  System.Gadget.Settings.write("colDiskActivity", cDiskActivity);
 }
 cDiskRead = System.Gadget.Settings.read("colDiskRead");
 if (cDiskRead == ''){
  cDiskRead = "#7EE444";
  System.Gadget.Settings.write("colDiskRead", cDiskRead);
 }
 cDiskWrite = System.Gadget.Settings.read("colDiskWrite");
 if (cDiskWrite == ''){
  cDiskWrite = "#FFF62A";
  System.Gadget.Settings.write("colDiskWrite", cDiskWrite);
 }

 cCounterRead = System.Gadget.Settings.read("colCounterRead");
 if (cCounterRead == ''){
  cCounterRead = "#7EE444";
  System.Gadget.Settings.write("colCounterRead", cCounterRead);
 }
 cCounterWrite = System.Gadget.Settings.read("colCounterWrite");
 if (cCounterWrite == ''){
  cCounterWrite = "#FFF62A";
  System.Gadget.Settings.write("colCounterWrite", cCounterWrite);
 }

 cDiskEasy = System.Gadget.Settings.read("colDiskEasy");
 if (cDiskEasy == ''){
  cDiskEasy = "#7EE444";
  System.Gadget.Settings.write("colDiskEasy", cDiskEasy);
 }
 cDiskMedium = System.Gadget.Settings.read("colDiskMedium");
 if (cDiskMedium == ''){
  cDiskMedium = "#FFF62A";
  System.Gadget.Settings.write("colDiskMedium", cDiskMedium);
 }
 cDiskHard = System.Gadget.Settings.read("colDiskHard");
 if (cDiskHard == ''){
  cDiskHard = "#FF0000";
  System.Gadget.Settings.write("colDiskHard", cDiskHard);
 }

 cErrMsg = System.Gadget.Settings.read("colErrMsg");
 if (cErrMsg == ''){
  cErrMsg = "#FF0000";
  System.Gadget.Settings.write("colErrMsg", cErrMsg);
 }

 cFillGraph = System.Gadget.Settings.read("colFillGraph");
 if (cFillGraph == ''){
  cFillGraph = "#000000";
  System.Gadget.Settings.write("colFillGraph", cFillGraph);
 }

 cFillPeak = System.Gadget.Settings.read("colFillPeak");
 if (cFillPeak == ''){
  cFillPeak = "#040505";
  System.Gadget.Settings.write("colFillPeak", cFillPeak);
 }

 cCopyright = System.Gadget.Settings.read("colCopyright");
 if (cCopyright == ''){
  cCopyright = "#00CCFF";
  System.Gadget.Settings.write("colCopyright", cCopyright);
 }
 cVersion = System.Gadget.Settings.read("colVersion");
 if (cVersion == ''){
  cVersion = "#C0C0C0";
  System.Gadget.Settings.write("colVersion", cVersion);
 }
//color settings end
}

function loadsettingsfromfile(){
 var inifilename = System.Environment.getEnvironmentVariable("APPDATA") + "\\" + System.Gadget.name + "_Settings.ini";
 try{
  var inifile = fs.OpenTextFile(inifilename, 1); //1 read
   try{
    var tmp = inifile.ReadLine();
    tmp = inifile.ReadLine();
    if (tmp != ";purr purr purr meow meow") throw "old";

    lngID = inifile.ReadLine();
    System.Gadget.Settings.write("LanguageId", lngID);
    //color settings
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sBgColorSelect", tmp);
    cBgColor = inifile.ReadLine();
    System.Gadget.Settings.write("colBgColor", cBgColor);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sTitColorSelect", tmp);
    cTitle = inifile.ReadLine();
    System.Gadget.Settings.write("colTitle", cTitle);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sDiskNameColorSelect", tmp);
    cDiskName = inifile.ReadLine();
    System.Gadget.Settings.write("colDiskName", cDiskName);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sDiskInfoColorSelect", tmp);
    cDiskInfo = inifile.ReadLine();
    System.Gadget.Settings.write("colDiskInfo", cDiskInfo);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sFilesystemColorSelect", tmp);
    cFileSystem = inifile.ReadLine();
    System.Gadget.Settings.write("colFileSystem", cFileSystem);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sDiskPeakColorSelect", tmp);
    cDiskPeak = inifile.ReadLine();
    System.Gadget.Settings.write("colDiskPeak", cDiskPeak);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sDiskActivityColorSelect", tmp);
    cDiskActivity = inifile.ReadLine();
    System.Gadget.Settings.write("colDiskActivity", cDiskActivity);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sDiskReadColorSelect", tmp);
    cDiskRead = inifile.ReadLine();
    System.Gadget.Settings.write("colDiskRead", cDiskRead);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sDiskWriteColorSelect", tmp);
    cDiskWrite = inifile.ReadLine();
    System.Gadget.Settings.write("colDiskWrite", cDiskWrite);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sCounterReadColorSelect", tmp);
    cCounterRead = inifile.ReadLine();
    System.Gadget.Settings.write("colCounterRead", cCounterRead);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sCounterWriteColorSelect", tmp);
    cCounterWrite = inifile.ReadLine();
    System.Gadget.Settings.write("colCounterWrite", cCounterWrite);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sDiskEasyColorSelect", tmp);
    cDiskEasy = inifile.ReadLine();
    System.Gadget.Settings.write("colDiskEasy", cDiskEasy);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sDiskMediumColorSelect", tmp);
    cDiskMedium = inifile.ReadLine();
    System.Gadget.Settings.write("colDiskMedium", cDiskMedium);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sDiskHardColorSelect", tmp);
    cDiskHard = inifile.ReadLine();
    System.Gadget.Settings.write("colDiskHard", cDiskHard);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sErrMsgColorSelect", tmp);
    cErrMsg = inifile.ReadLine();
    System.Gadget.Settings.write("colErrMsg", cErrMsg);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sGrBgColorSelect", tmp);
    cFillGraph = inifile.ReadLine();
    System.Gadget.Settings.write("colFillGraph", cFillGraph);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sFillPeakColorSelect", tmp);
    cFillPeak = inifile.ReadLine();
    System.Gadget.Settings.write("colFillPeak", cFillPeak);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sVersnColorSelect", tmp);
    cVersion = inifile.ReadLine();
    System.Gadget.Settings.write("colVersion", cVersion);
    tmp = inifile.ReadLine();
    System.Gadget.Settings.write("sCopyColorSelect", tmp);
    cCopyright = inifile.ReadLine();
    System.Gadget.Settings.write("colCopyright", cCopyright);
    //color settings end

    size = inifile.ReadLine();
    System.Gadget.Settings.write("SetSize", size);
    refreshRate = inifile.ReadLine();
    System.Gadget.Settings.write("refreshtime", refreshRate);  

    hidehiddendrive = inifile.ReadLine();
    System.Gadget.Settings.write("HiddenPartHide", hidehiddendrive);
    hidemounteddrive = inifile.ReadLine();
    System.Gadget.Settings.write("MountedPartHide", hidemounteddrive);

    hidegraph = inifile.ReadLine();
    System.Gadget.Settings.write("GraphHide", hidegraph);
    shortinfo = inifile.ReadLine();
    System.Gadget.Settings.write("HideFullDiskInfo", shortinfo);

    hidetitleflag = inifile.ReadLine();
    System.Gadget.Settings.write ("TitleHide", hidetitleflag);
    hidecopyrightflag = inifile.ReadLine();
    System.Gadget.Settings.write ("CopyrightHide", hidecopyrightflag);

    warningpercent = inifile.ReadLine();
    System.Gadget.Settings.write("WarningUse", warningpercent);
    criticalpercent = inifile.ReadLine();
    System.Gadget.Settings.write("CriticalUse", criticalpercent);

    graphlinewidth = inifile.ReadLine();
    System.Gadget.Settings.write ("GraphLineWidth", graphlinewidth);

    hidegridlinesflag = inifile.ReadLine();
    System.Gadget.Settings.write ("GridlinesHide", hidegridlinesflag);

    activefillflag = inifile.ReadLine();
    System.Gadget.Settings.write ("fillActivity", activefillflag);
    readfillflag = inifile.ReadLine();
    System.Gadget.Settings.write ("fillRead", readfillflag);
    writefillflag = inifile.ReadLine();
    System.Gadget.Settings.write ("fillWrite", writefillflag);

    chooseactivityflag = inifile.ReadLine();
    System.Gadget.Settings.write ("ChooseActivity", chooseactivityflag);

    hidecountersflag = inifile.ReadLine();
    System.Gadget.Settings.write ("CountersHide", hidecountersflag);

    autoupdateflag = inifile.ReadLine();
    System.Gadget.Settings.write ("AutoUpdate", autoupdateflag);

    disableflyoutsoundsflag = inifile.ReadLine();
    System.Gadget.Settings.write ("DisableFlyoutSounds", disableflyoutsoundsflag);

    autoscaleDPIflag = inifile.ReadLine();
    System.Gadget.Settings.write ("DPIautoscale", autoscaleDPIflag);

    savedisksflag = inifile.ReadLine();
    System.Gadget.Settings.write ("SaveDisksLettersNumbers", savedisksflag);
    tmpdskmode = inifile.ReadLine();
    tmpdskletters = inifile.ReadLine();
    tmpdsknumbers = inifile.ReadLine();

    showtemperatureflag = inifile.ReadLine();
    System.Gadget.Settings.write ("ShowDiskTemperature", showtemperatureflag);
   }//end try 2
  
   finally {inifile.Close()}
 }//end try 1   
 
 catch (e) {}
}

function compareDriveLetters(a,b){
 return a.charCodeAt(0) - b.charCodeAt(0);
}

function fixedDigits(value){
 if (value >= 100) return value.toFixed(0);
 else if (value >= 10) return value.toFixed(1);
 else return value.toFixed(2);
}

function formatBytes(bytes){
 if (bytes > 1125899906842624) return fixedDigits(((((bytes / 1024) / 1024) / 1024) / 1024) / 1024) + mainlng[lngID][10];
 if (bytes > 1099511627776) return fixedDigits((((bytes / 1024) / 1024) / 1024) / 1024) + mainlng[lngID][11];
 if (bytes > 1073741824) return fixedDigits(bytes / 1024 / 1024 / 1024) + mainlng[lngID][12];
 if (bytes > 1048576) return fixedDigits(bytes / 1024 / 1024) + mainlng[lngID][13];
 if (bytes > 1024) return fixedDigits(bytes / 1024) + mainlng[lngID][14];
 return fixedDigits(bytes) + " ";
}

function getMax(history){
 var max = 0;
 for (h in history){
  if (history[h].read > max) max = history[h].read;
  if (history[h].write > max)max = history[h].write;
 }  
 return max;
}

function setlanguage(){
 lngID = System.Gadget.Settings.read("LanguageId");
 if(lngID == ''){
  lngID = "0";
  System.Gadget.Settings.write("LanguageId", lngID);
 }
}

function getAllTemperatures(){
 try{
  tmplast = wshShell.RegRead(regPath + "LastUpdate");
  CrystalDiskInfoNotFound = false;
  if (tmplast != lastUpdate){
   lastUpdate = tmplast;
   diskcount = wshShell.RegRead(regPath + "DiskCount");
   temperatures.length = 0;
   for (var i=0; i<diskcount; i++){
    temperatures[i] = new Array();
    var targetdisk = wshShell.RegRead(regPath + "Disk" + i);
    temperatures[i][0] = wshShell.RegRead(regPath + targetdisk + "\\DriveLetter");
    temperatures[i][1] = wshShell.RegRead(regPath + targetdisk + "\\Temperature");
    temperatures[i][2] = wshShell.RegRead(regPath + targetdisk + "\\DiskStatus");
    temperatures[i][3] = wshShell.RegRead(regPath + targetdisk + "\\TemperatureClass");
    temperatures[i][4] = i;
   }
  }//if
 }//try
 catch (e){
  CrystalDiskInfoNotFound = true;
  tmplast = 0;
  temperatures.length = 0;
 }
}

function getPhysicalDiskTemperatures(disk){
 if (CrystalDiskInfoNotFound) return -1;
 for (var i=0; i<diskcount; i++){
  if (disk.split(" ")[0] == temperatures[i][4]) return i;
 }
 return -1;
}

function getLogicalDiskTemperatures(disk){
 if (CrystalDiskInfoNotFound) return -1;
 for (var i=0; i<diskcount; i++){
  if (temperatures[i][0].indexOf(disk) != -1) return i;
 }
 return -1;
}

function refresh(){
 try{
  fromwhere = false;
  if (setgadgetchange){
   setlanguage(); //Important!!! before loadSettings()
   loadsettings();
   if (autoscaleDPIflag) getDPIsize(); //Important!!! After loadsettings()
   loadcolorsettings();

   if (size <= 1.3) statuspic = 12;
   else if (size <= 2.4) statuspic = 24;
   else if (size <= 3.5) statuspic = 36;
   else if (size <= 4.6) statuspic = 48;
   else statuspic = 88;

   topMargin = hidetitleflag ? 6 : 6 + 20;
   bottomMargin = hidecopyrightflag ? 9 : 6 + 15;
   addtotop = 2;
   addheight1 = 38;
   addheighttemp = showtemperatureflag ? 10 : 0;
   if (diskmode == "0"){
    driveHeight = 104 + addheighttemp;
    addheight = 30;
    if (shortinfo){
     driveHeight -= 20;
     addheight -= 20;
    }
    if (hidegraph){
     driveHeight -= 38;
     addheight1 = 0;
    }
   } 
   else{
    driveHeight = 78 + addheighttemp;
    addheight = 0;
    addtotop = 0;
    bottomMargin -= 2;
   }
   if (hidecountersflag) driveHeight -= 12;

   mask = (diskmode == "0") ? excludedDrivesMask : ";" + excludedDrivesNumberMask;
   usbpic = (size < 1.3) ? "images/EjectUSB16.png" : "images/EjectUSB32.png";
  }//if

  if (diskmode == "0"){
   resultSet = service.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfDisk_LogicalDisk");
   resultDriveCounter = service.ExecQuery("SELECT * FROM Win32_PerfRawData_PerfDisk_LogicalDisk");
  }
  else{
   resultSet = service.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfDisk_PhysicalDisk");
   resultDriveCounter = service.ExecQuery("SELECT * FROM Win32_PerfRawData_PerfDisk_PhysicalDisk");
  }

  if (showtemperatureflag) getAllTemperatures();

  for (var drive in history) 
   history[drive].inuse = false;

  var driveNames = [];
  var driveChange = false;
  for (var i=0; i<resultSet.Count; i++){
   if (resultSet.ItemIndex(i).Name == "_Total") continue;
   var drive = resultSet.ItemIndex(i).Name;

   if (diskmode == "0"){
    var letter = drive.charAt(0);
    if ((!isNaN(mask) && letterInMask(letter, mask)) || (hidehiddendrive && drive.indexOf("HarddiskVolume") != -1) || (hidemounteddrive && drive.charAt(2) == "\\")) continue;
   }
   else if (mask.indexOf(";" + drive.substring(0,drive.indexOf(" ")) + ";") != -1) continue;

   tmpdriveletter = (diskmode == "0") ? drive : drive.substr(drive.indexOf(" ") + 1,2);
   getDiskType(tmpdriveletter);

   driveNames.push(drive);
        
   if (!(drive in history)){
    driveChange = true;
    history[drive] = {};
    history[drive].drive = drive;
    history[drive].inuse = true;
    history[drive].history = [];
    for (var j=0; j<maxHistory; j++){
     var zero = {};
     zero.active = 0;
     zero.read = 0;
     zero.write = 0;
     history[drive].history.push(zero);
    }
   }

   var temp = {};
   if (!chooseactivityflag) temp.active = Number(resultSet.ItemIndex(i).PercentDiskTime);
   else{
    var act = Number(resultSet.ItemIndex(i).AvgDiskQueueLength);
    temp.active = parseInt((act * 100) / (act + 1));
   }

   temp.read = Number(resultSet.ItemIndex(i).DiskReadBytesPerSec);
   temp.write = Number(resultSet.ItemIndex(i).DiskWriteBytesPerSec);
   history[drive].readcounter = Number(resultDriveCounter.ItemIndex(i).DiskReadBytesPerSec);
   history[drive].writecounter = Number(resultDriveCounter.ItemIndex(i).DiskWriteBytesPerSec);

   history[drive].freemegabytes = Number(resultDriveCounter.ItemIndex(i).FreeMegabytes);

   history[drive].physdrvfirstletter = tmpdriveletter;
   history[drive].physdrvtype = dsktype;
   if (history[drive].usbeject != true) history[drive].usbeject = false;

   history[drive].inuse = true;
   history[drive].history.push(temp);
   history[drive].history.shift();
  }//for
	
  for (var drive in history){
   if (!history[drive].inuse){
    driveChange = true;
    delete history[drive];
   }
  }

  if ((driveChange) || (setgadgetchange)){
   setgadgetchange = false;
   driveNames.sort(compareDriveLetters);
   for (var i=0; i <driveNames.length; i++)
    history[driveNames[i]].index = i;

   var html = '<g:background id="background" src="images/background' + (driveNames.length < 1 ? 0 : (driveNames.length > 15 ? 15 : driveNames.length)) +
   '.png" style="width:' + parseInt(130 * size) + 'px;height:' + parseInt((topMargin + driveNames.length * driveHeight + bottomMargin) * size) + 'px">';
   html += '<div id="mainsquare" style="position:absolute"></div>';

   if (!hidetitleflag){
    html += '<g:text style="top:' + parseInt(6 * size) + 'px;width:100%;text-align:center;font-size:' + parseInt(12 * size) + 'px;color:' + cTitle +
    ';font-weight:bold"><span title="' + mainlng[lngID][1] + '" style="cursor:pointer" onclick="showFlyout(' + "'0'" + ')">' + mainlng[lngID][0] + '</span></g:text>';
    html += '<g:text style="top:' + parseInt(16 * size) + 'px;width:100%"><hr align="center" width="' + tech[lngID][0] +'" color="#808080"></g:text>';
   } 
		
   for (var i=0; i<driveNames.length; i++){
    html += '<g:text style="font-weight:bold;top:' + parseInt((topMargin + i * driveHeight) * size) + 'px;left:' + parseInt(7 * size) + 'px;font-size:' +
    parseInt(9 * size) + 'px;color:' + cDiskName + ';text-overflow:ellipsis;white-space:nowrap;overflow:hidden;width:79%">';

    html += '<span title="' + mainlng[lngID][1] + '" style="cursor:pointer" onclick="showFlyout(' + "'" + driveNames[i] + "'" + ')">';
    html += (diskmode == "0") ? driveNames[i] + '<span id="disk' + i + 'label" style="font-weight:normal"></span>' : driveNames[i];
    html += "</span></g:text>";

    html += '<span title="' + mainlng[lngID][1] + '" style="cursor:pointer" onclick="showFlyout(' + "'" + driveNames[i] + "'" + ')">' +
    '<g:text id="disk' + i + 'temperature" style="top:' + parseInt((topMargin + i * driveHeight + addheighttemp) * size) + 'px;left:' + parseInt(7 * size) +
    'px;font-size:' + parseInt(9 * size) + 'px"></g:text></span>';

    html += '<span style="cursor:pointer" onclick="if (diskmode==' + "'0') System.Shell.execute(" + "'" + driveNames[i] + "'" + ");" +
    "else System.Shell.execute('explorer.exe', '/n,')" + '">';

    html += '<g:text id="disk' + i + 'activetext" style="top:' + parseInt((topMargin + i * driveHeight) * size) + 'px;left:0px;text-align:right;' +
    'width:' + parseInt(124 * size) + 'px;color:' + cDiskActivity + ';font-size:' + parseInt(9 * size) + 'px" /></g:text>';

    if (diskmode == "0"){
     if (!shortinfo){
      html += '<g:text style="top:' + parseInt((topMargin + i * driveHeight + 10 + addheighttemp) * size) + 'px;left:' + parseInt(7 * size) + 'px;color:' +
      cDiskInfo + ';font-size:' + parseInt(9 * size) + 'px">' + mainlng[lngID][2] + '<span id="disk' + i + 'total"></span></g:text>';
      html += '<g:text id="disk' + i + 'frmt" style="top:' + parseInt((topMargin + i * driveHeight + 10 + addheighttemp) * size) + 'px;left:' +
      parseInt(tech[lngID][3] * size) + 'px;color:' + cFileSystem + ';font-size:' + parseInt(9 * size) + 'px"></g:text>';
      html += '<g:text style="top:' + parseInt((topMargin + i * driveHeight + 20 + addheighttemp) * size) + 'px;left:' + parseInt(7 * size) + 'px;color:' + cDiskInfo +
      ';font-size:' + parseInt(9 * size) + 'px">' + mainlng[lngID][3] + '<span id="disk' + i + 'used"></span></g:text>';
      html += '<g:text style="top:' + parseInt((topMargin + i * driveHeight + 20 + addheighttemp) * size) + 'px;left:' + parseInt(tech[lngID][1] * size) + 'px;color:' +
      cDiskInfo + ';font-size:' + parseInt(9 * size) + 'px">' + mainlng[lngID][4] + '<span id="disk' + i + 'free"></span></g:text>';

      html += '<g:text style="top:' + parseInt((topMargin + i * driveHeight + 34 + addheighttemp) * size) + 'px;left:' + parseInt(7 * size) + 'px">'
      html += '<img src="images/barback.png" style="width:' + parseInt(50 * size) + ';height:' + parseInt(6 * size) + '" /></g:text>';
      html += '<g:text id="disk' + i + 'div" style="overflow:hidden;top:' + parseInt((topMargin + i * driveHeight + 34 + addheighttemp) * size) + 'px;left:'
      + parseInt(7 * size) + 'px">' + '<img id="disk' + i + 'img" src="images/bartop.png" style="height:' + parseInt(6 * size) + '" /></g:text>';

      html += '<g:text id="disk' + i + 'text" style="top:' + parseInt((topMargin + i * driveHeight + 30 + addheighttemp) * size) + 'px;left:' +
      parseInt(tech[lngID][2] * size) + 'px;font-size:' + parseInt(9 * size) + 'px">(<span id="disk' + i + 'txtfree"></span>' + mainlng[lngID][5] + ')</g:text>';
     }
     else{ 
      html += '<g:text style="top:' + parseInt((topMargin + i * driveHeight + 14 + addheighttemp) * size) + 'px;left:' + parseInt(7 * size) + 'px">'
      html += '<img src="images/barback.png" style="width:' + parseInt(50 * size) + ';height:' + parseInt(6 * size) + '" /></g:text>';
      html += '<g:text id="disk' + i + 'div" style="overflow:hidden;top:' + parseInt((topMargin + i * driveHeight + 14 + addheighttemp) * size) + 'px;left:'
      + parseInt(7 * size) + 'px">' + '<img id="disk' + i + 'img" src="images/bartop.png" style="height:' + parseInt(6 * size) + '" /></g:text>';

      html += '<g:text id="disk' + i + 'text" style="top:' + parseInt((topMargin + i * driveHeight + 10 + addheighttemp) * size) + 'px;left:' +
      parseInt(tech[lngID][1] * size) + 'px;font-size:' + parseInt(9 * size) + 'px">' + mainlng[lngID][4] + '<span id="disk' + i + 'txtfree"></span></g:text>';
     }
    }
   
    html += '<img src="images/up.png" style="position:absolute;top:' + parseInt((topMargin + i * driveHeight + 14 + addheight + addheighttemp) * size) +
    'px;left:' + parseInt(6 * size) + 'px;width:' + parseInt(7 * size) + ';height:' + parseInt(7 * size) + '" />';
    html += '<g:text id="disk' + i + 'readtext" style="top:' + parseInt((topMargin + i * driveHeight + 11 + addheight + addheighttemp) * size) + 'px;left:' +
    parseInt(14 * size) + 'px;color:' + cDiskRead + ';font-size:' + parseInt(9 * size) + 'px" />';
    html += '</span>';

    if (history[driveNames[i]].physdrvtype == 2){
     html += '<img src=' + usbpic + ' style="position:absolute;cursor:URL(' + "'images/EjectUSB.cur'" + ');top:' +
     parseInt((topMargin + i * driveHeight + 10 + addheight + addheighttemp) * size) + 'px;left:' + parseInt(55 * size) + 'px;width:' + parseInt(16 * size) + ';height:' +
     parseInt(16 * size) + '" onclick="removeUSB(' + "'" + history[driveNames[i]].physdrvfirstletter + "'" + ')" title="' + mainlng[lngID][6] + '" />';
    }

    html += '<span style="cursor:pointer" onclick="if (diskmode==' + "'0') System.Shell.execute(" + "'" + driveNames[i] + "'" + ");" +
    "else System.Shell.execute('explorer.exe', '/n,')" + '">';

    html += '<img src="images/down.png" style="position:absolute;top:' + parseInt((topMargin + i * driveHeight + 14 + addheight + addheighttemp) * size) + 'px;left:' +
    parseInt(74 * size) + 'px;width:' + parseInt(7 * size) + ';height:' + parseInt(7 * size) + '" />';
    html += '<g:text id="disk' + i + 'writetext" style="top:' + parseInt((topMargin + i * driveHeight + 11 + addheight + addheighttemp) * size) + 'px;left:' +
    parseInt(82 * size) + 'px;color:' + cDiskWrite + ';font-size:' + parseInt(9 * size) + 'px" />';

    if (!hidegraph){
     html += '<g:text style="top:' + parseInt((topMargin + i * driveHeight + 27 + addheight + addheighttemp) * size) + 'px;left:' + parseInt(5 * size) + 'px;width:' +
     parseInt(120 * size) + 'px;height:' + parseInt(36 * size) + 'px;background-color:' + cFillGraph + '"></g:text>';

     html += '<v:shape style="width:' + parseInt(112 * size) + ';height:' + parseInt(30 * size) + 'px;top:' + parseInt((topMargin + i * driveHeight + 29 + addheight + addheighttemp) * size) +
     'px;left:' + parseInt(8 * size) + 'px" filled="false" strokecolor="#778899" strokeweight="1pt"' +
     ' coordorigin="0 0" coordsize="112 30" path="m 0,30 l 112,30 l 112,0 l 0,0 l 0,30" />';				
     if (!hidegridlinesflag){
      html += '<v:shape style="width:' + parseInt(112 * size) + ';height:' + parseInt(30 * size) + 'px;top:' + parseInt((topMargin + i * driveHeight + 29 + addheight + addheighttemp) * size) +
      'px;left:' + parseInt(8 * size) + 'px" filled="false" strokecolor="#2F4F4F" strokeweight="1pt"' +
      ' coordorigin="0 0" coordsize="112 30" path=" m 6,30 l 6,0 m 16,30 l 16,0 m 26,30 l 26,0 m 36,30 l 36,0 m 46,30 l 46,0 m 56,30 l 56,0 m 66,30 l 66,0 m 76,30 l 76,0 m 86,30 l 86,0 m 96,30 l 96,0 m 106,30 l 106,0 "/>';
      html += '<v:shape style="width:' + parseInt(112 * size) + ';height:' + parseInt(30 * size) + 'px;top:' + parseInt((topMargin + i * driveHeight + 29 + addheight + addheighttemp) * size) +
      'px;left:' + parseInt(8 * size) + 'px" filled="false" strokecolor="#2F4F4F" strokeweight="1pt"' +
      ' coordorigin="0 0" coordsize="112 30" path=" m 0,5 l 112,5 m 0,10 l 112,10 m 0,15 l 112,15 m 0,20 l 112,20 m 0,25 l 112,25"/>';
     }

     html += '<v:shape id="disk' + i + 'activegraph" style="width:' + parseInt(112 * size) + ';height:' + parseInt(30 * size) + 'px;top:' +
     parseInt((topMargin + i * driveHeight + 29 + addheight + addheighttemp) * size) + 'px;left:' + parseInt(8 * size) + 'px" filled="false" strokecolor="' +
     cDiskActivity + '" strokeweight="' + graphlinewidth + '" coordorigin="0 0" coordsize="112 100"/>';
     html += '<v:shape id="disk' + i + 'readgraph" style="width:' + parseInt(112 * size) + ';height:' + parseInt(30 * size) + 'px;top:' +
     parseInt((topMargin + i * driveHeight + 29 + addheight + addheighttemp) * size) + 'px;left:' + parseInt(8 * size) + 'px" filled="false" strokecolor="' +
     cDiskRead + '" strokeweight="' + graphlinewidth + '" coordorigin="0 0" coordsize="112 100"/>';
     html += '<v:shape id="disk' + i + 'writegraph" style="width:' + parseInt(112 * size) + ';height:' + parseInt(30 * size) + 'px;top:' +
     parseInt((topMargin + i * driveHeight + 29 + addheight + addheighttemp) * size) + 'px;left:' + parseInt(8 * size) + 'px" filled="false" strokecolor="' +
     cDiskWrite + '" strokeweight="' + graphlinewidth + '" coordorigin="0 0" coordsize="112 100"/>';

     html += '<g:text style="top:' +  parseInt((topMargin + i * driveHeight + 26 + addheight + addheighttemp) * size) + 'px;font-size:' + parseInt(10 * size) + 'px;left:' +
     parseInt(8 * size) + 'px;width:' + parseInt(45 * size) + 'px;height:' + parseInt(13 * size) + 'px;background-color:' + cFillPeak +
     ';filter:alpha(opacity=60);border:' + parseInt(1 * size) + 'px solid #2F4F4F" />'
     html += '<g:text id="disk' + i + 'graphmax" style="top:' +  parseInt((topMargin + i * driveHeight + 26 + addheight + addheighttemp) * size) + 'px;left:' +
     parseInt(9 * size) + 'px;color:' + cDiskPeak + ';font-size:' + parseInt(9 * size) + 'px" />';
    }

    if (!hidecountersflag){
     html += '<img src="images/driveupload.png" style="position:absolute;top:' + parseInt((topMargin + i * driveHeight + 25 + addheight + addheight1 + addheighttemp) * size) +
     'px;left:' + parseInt(6 * size) + 'px;width:' + parseInt(12 * size) + ';height:' + parseInt(12 * size) + '" />';
     html += '<g:text id="disk' + i + 'readcounter" style="top:' + parseInt((topMargin + i * driveHeight + 26 + addheight + addheight1 + addheighttemp) * size) + 'px;left:' +
     parseInt(18 * size) + 'px;color:' + cCounterRead + ';font-size:' + parseInt(9 * size) + 'px" />';
     html += '<img src="images/drivedownload.png" style="position:absolute;top:' + parseInt((topMargin + i * driveHeight + 25 + addheight + addheight1 + addheighttemp) * size) +
     'px;left:' + parseInt(65 * size) + 'px;width:' + parseInt(12 * size) + ';height:' + parseInt(12 * size) + '" />';
     html += '<g:text id="disk' + i + 'writecounter" style="top:' + parseInt((topMargin + i * driveHeight + 26 + addheight + addheight1 + addheighttemp) * size) + 'px;left:' +
     parseInt(78 * size) + 'px;color:' + cCounterWrite + ';font-size:' + parseInt(9 * size) + 'px" />';
    }
    html += '</span>';
   }//end for

   if (!hidecopyrightflag){
    html += '<g:text id="advertis" style="width:100%;top:' + parseInt((driveNames.length * driveHeight + (topMargin - 2) + addtotop) * size) +
    'px;left:' + parseInt(10 * size) + 'px;font-size:' + parseInt(10 * size) + 'px"><a class="ads" style="color:' + cCopyright +
    '" href="http://www.myfavoritegadgets.info/" target="_blank">&copy; 2013 by Igogo</a></g:text>';
    html += '<g:text id="versionnumber" style="font-size:' + parseInt(9 * size) + 'px;top:' +
    parseInt((driveNames.length * driveHeight + (topMargin - 2) + addtotop) * size) + 'px;left:0px;width:' + parseInt(120 * size) + 'px;text-align:right;color:' +
    cVersion + '">v' + System.Gadget.version + '</g:text>';
   }

   factheight = topMargin + driveNames.length * driveHeight + bottomMargin;//Important. This line BEFORE autoupdate notifier

   html += '<g:text id="autoapdater" style="width:100%;text-align:center;visibility:hidden;font-size:' + parseInt(9 * size) + 'px;top:' +
   parseInt((factheight - 8) * size) + 'px">' + autoupdatestr + '</g:text>';
   document.body.innerHTML = html + "</g:background>";
  
   document.body.style.width = parseInt(130 * size);
   background.style.width = parseInt(130 * size);  
   document.body.style.height = parseInt(factheight * size);
   background.style.height = parseInt(factheight * size);  
   mainsquare.style.top = parseInt(6 * size);
   mainsquare.style.left = parseInt(5 * size);
   mainsquare.style.width =  parseInt((130 - 10) * size);
   mainsquare.style.height = parseInt((factheight - 12) * size);
   mainsquare.style.background = cBgColor;

   if (autoupdateflag){
    if (autoupdatestr == "") firstupdatetimer = setTimeout("CheckUpdates()", 5000);
    else{
     factheight += 12;
     document.body.style.height = parseInt(factheight * size);
     background.style.height = parseInt(factheight * size);
     mainsquare.style.height = parseInt((factheight - 12) * size);
     autoapdater.style.visibility = "visible";
    }
   }
   else{
    clearTimeout(firstupdatetimer);
    clearTimeout(updateTimerId);
   }
  }//end if

   for (var drive in history){
    try{
     var max = getMax(history[drive].history);
     if (max == 0) max = 1;
     document.getElementById("disk" + history[drive].index + "activetext").innerText = history[drive].history[maxHistory - 1].active + "%";
     document.getElementById("disk" + history[drive].index + "readtext").innerText = formatBytes(history[drive].history[maxHistory - 1].read) + mainlng[lngID][15];
     document.getElementById("disk" + history[drive].index + "writetext").innerText = formatBytes(history[drive].history[maxHistory - 1].write) + mainlng[lngID][15];
    }//end try
    catch (e) {setgadgetchange = true}
//Old counter
//    if (history[drive].curread != undefined) history[drive].curread += history[drive].history[maxHistory - 1].read;
//    else history[drive].curread = 0;
//    if (history[drive].curwrite != undefined) history[drive].curwrite += history[drive].history[maxHistory - 1].write;
//    else history[drive].curwrite = 0;
    if (!hidecountersflag){
//Old counter
//     document.getElementById("disk" + history[drive].index + "readcounter").innerText = formatBytes(history[drive].curread) + "B";
//     document.getElementById("disk" + history[drive].index + "writecounter").innerText = formatBytes(history[drive].curwrite) + "B";
     try{
      document.getElementById("disk" + history[drive].index + "readcounter").innerText = formatBytes(history[drive].readcounter) + mainlng[lngID][16];
      document.getElementById("disk" + history[drive].index + "writecounter").innerText = formatBytes(history[drive].writecounter) + mainlng[lngID][16];
     }//end try
     catch (e) {setgadgetchange = true}
    }

    if (diskmode == "0"){
     try{
      getDiskInfo(history[drive].drive);
      document.getElementById("disk" + history[drive].index + "label").innerText = disklabel;
      if (!shortinfo){
       document.getElementById("disk" + history[drive].index + "frmt").innerText = dskfrmt;
       document.getElementById("disk" + history[drive].index + "total").innerText = !isNaN(dsktotal) ? formatBytes(dsktotal) + mainlng[lngID][16] : dsktotal;
       document.getElementById("disk" + history[drive].index + "used").innerText = !isNaN(dskused) ? formatBytes(dskused) + mainlng[lngID][16] : dskused;
       document.getElementById("disk" + history[drive].index + "free").innerText = !isNaN(dskfree) ? formatBytes(dskfree) + mainlng[lngID][16] : dskfree;
      }
     }//end try
     catch (e) {setgadgetchange = true}

     try{
      var barwidth = !isNaN(dsktotal) ? (dskused/dsktotal) * 100 : 0;
      var dcolor;
      if (barwidth <= warningpercent) {dcolor = cDiskEasy} //green bar
      else if (barwidth >= criticalpercent) {dcolor = cDiskHard} //red bar
      else {dcolor = cDiskMedium} //yellow bar

      document.getElementById("disk" + history[drive].index + "div").style.background = dcolor;
      document.getElementById("disk" + history[drive].index + "text").style.color = dcolor;
      document.getElementById("disk" + history[drive].index + "img").style.width = parseInt(0.5 * barwidth * size);
      if (!shortinfo) document.getElementById("disk" + history[drive].index + "txtfree").innerText = !isNaN(dsktotal) ? Math.round((100 - barwidth) * 100)/100 : mainlng[lngID][7];
      else document.getElementById("disk" + history[drive].index + "txtfree").innerText = !isNaN(dskfree) ? formatBytes(dskfree) + mainlng[lngID][16] : dskfree;
     }//end try
     catch (e) {setgadgetchange = true}
    }// end if

    if (showtemperatureflag){
     var s = '<span style="color:' + cDiskInfo + '">t&deg;=</span>';
     var d = (diskmode == "0") ? getLogicalDiskTemperatures(history[drive].drive) : getPhysicalDiskTemperatures(history[drive].drive);
     if (d != -1){
      var c;
      switch (temperatures[d][3]){
       case "temperatureGood":
        c = cDiskEasy;
        break;
       case "temperatureCaution": 
        c = cDiskMedium;
        break;
       case "temperatureBad": 
        c = cDiskHard;
        break;
       default:
        c = cDiskInfo;
        break;
      }
      var n;
      switch (temperatures[d][2]){
       case 1:
        n = "healthGood";
        break;
       case 2: 
        n = "healthCaution";
        break;
       case 3: 
        n = "healthBad";
        break;
       default:
        n = "healthUnknown";
        break;
      }
      s += '<span style="font-weight:bold;color:' + c + '">' + temperatures[d][1] + '</span>' +
           '<span style="color:' + cDiskInfo + '">' + mainlng[lngID][21] + '</span>' + '<img align="top" src="images/' + n + statuspic + '.png"' +
           'width="' + parseInt(12 * size) + 'px" height="' + parseInt(12 * size) + '" />';
     }
     else{
      s += '<span style="font-weight:bold;color:' + cDiskInfo + '">' + mainlng[lngID][7] + '</span>' +
           '<span style="color:' + cDiskInfo + '">' + mainlng[lngID][21] + '</span>' + '<img align="top" src="images/healthUnknown' + statuspic + '.png"' +
           'width="' + parseInt(12 * size) + 'px" height="' + parseInt(12 * size) + '" />';
     }
     document.getElementById("disk" + history[drive].index + "temperature").innerHTML = s;
    }

    if (!hidegraph){
     try{
      document.getElementById("disk" + history[drive].index + "graphmax").innerText = formatBytes(max) + mainlng[lngID][15];
      var activePath = "m 0,100 ";
      var readPath = "m 0,100 ";
      var writePath = "m 0,100 ";
      var g1;
      var g2;
      var g3;
      for (var i = 0; i < maxHistory; i++){
       g1 = history[drive].history[i].active;
       g2 = 1 - 1.0 * history[drive].history[i].read / max;
       g3 = 1 - 1.0 * history[drive].history[i].write / max;
       activePath += " l " + (i+1) + "," + (100 - g1);
       if (activefillflag) activePath += " m " + (i+1) + ",100 " + "l " + (i+1) + "," + parseInt(100 - g1);
       readPath += " l " + (i+1) + "," + parseInt(100 * g2);
       if (readfillflag) readPath += " m " + (i+1) + ",100 " + "l " + (i+1) + "," + parseInt(100 * g2);
       writePath += " l " + (i+1) + "," + parseInt(100 * g3);
       if (writefillflag) writePath += " m " + (i+1) + ",100 " + "l " + (i+1) + "," + parseInt(100 * g3);
      }// end for
      activePath += " e";
      readPath += " e";
      writePath += " e";
    
      document.getElementById("disk" + history[drive].index + "activegraph").path = activePath;
      document.getElementById("disk" + history[drive].index + "readgraph").path = readPath;
      document.getElementById("disk" + history[drive].index + "writegraph").path = writePath;
     }//end try
     catch (e) {setgadgetchange = true}
    }// end if
   }// end for
 } //end try
 catch (e){
  fromwhere = true;
  loadcolorsettings();
  var errhtml = '<g:background id="background" src="images/background.png" style="width:' + parseInt(130 * size) + 'px;height:' + parseInt(98 * size) + 'px">';
  errhtml += '<div id="mainsquare" style="position:absolute"></div>';
  errhtml += '<g:text style="top:' + parseInt(6 * size) + 'px;width:100%;text-align:center;font-size:' + parseInt(12 * size) +
  'px;color:' + cTitle + ';font-weight:bold">' + mainlng[lngID][0] + '</g:text>';
  errhtml += '<g:text style="top:' + parseInt(16 * size) + 'px;width:100%"><hr align="center" width="' + tech[lngID][0] +'" color="#808080"></g:text>';
  errhtml += '<img src="images/nowmi24.png" style="position:absolute;top:' + parseInt(26 * size) + 'px;left:' + parseInt(53 * size) +
  'px;width:' + parseInt(24 * size) + ';height:' + parseInt(24 * size) + '" />';
  errhtml += '<g:text style="top:' + parseInt(50 * size) + 'px;width:100%;font-size:' + parseInt(12 * size) +
  'px;text-align:center;color:' + cErrMsg + ';font-weight:bold">' + mainlng[lngID][17] + '<br>' +
  '<a style="color:' + cErrMsg + '" href="http://www.myfavoritegadgets.info/monitors/DrivesMonitor/No_WMI_Info.html" target="_blank">' + mainlng[lngID][18] + '</a></g:text>';
  errhtml += '<g:text id="advertis" style="width:100%;top:' + parseInt(78 * size) + 'px;left:' + parseInt(10 * size) +
  'px;font-size:' + parseInt(10 * size) + 'px"><a class="ads" style="color:' + cCopyright + '" href="http://www.myfavoritegadgets.info/" target="_blank">&copy; 2013 by Igogo</a></g:text>';
  errhtml += '<g:text id="versionnumber" style="font-size:' + parseInt(9 * size) + 'px;top:' + parseInt(78 * size) +
  'px;left:0px;width:' + parseInt(120 * size) + 'px;text-align:right;color:' + cVersion + '">v' + System.Gadget.version + '</g:text>';

  factheight = 98;//Important. This line BEFORE autoupdate notifier

  errhtml += '<g:text id="autoapdater" style="width:100%;text-align:center;visibility:hidden;font-size:' + parseInt(9 * size) + 'px;top:' +
  parseInt((factheight - 8) * size) + 'px">' + autoupdatestr + '</g:text>';

  document.body.innerHTML = errhtml + "</g:background>";
  document.body.style.width = parseInt(130 * size);
  background.style.width = parseInt(130 * size);
  document.body.style.height = parseInt(factheight * size);
  background.style.height = parseInt(factheight * size);  
  mainsquare.style.top = parseInt(5 * size); 
  mainsquare.style.left = parseInt(5 * size);  
  mainsquare.style.width =  parseInt((130 - 10) * size);
  mainsquare.style.height = parseInt((factheight - 10) * size);
  mainsquare.style.background = cBgColor;

  if (autoupdateflag){
   if (autoupdatestr == "") firstupdatetimer = setTimeout("CheckUpdates()", 5000);
   else{
    factheight += 12;
    document.body.style.height = parseInt(factheight * size);
    background.style.height = parseInt(factheight * size);
    mainsquare.style.height = parseInt((factheight - 10) * size);
    autoapdater.style.visibility = "visible";
   }
  }
  else{
   clearTimeout(firstupdatetimer);
   clearTimeout(updateTimerId);
  }
 }//end catch
}//end function