/////////////////////////////////////////////////////////////////
//
//  Computer Status - Sideshow Enabled  
//
//  Lawrence James
//  law@gadgetdev.co.uk
//  www.GadgetDev.co.uk
//
/////////////////////////////////////////////////////////////////

// -- Initialise Variables -- //
var _HDD_RefreshInterval = 10
var _HDD_bIntervalsSet          = false;
var _HDD_RefreshIntervalID;
var _Tick_RefreshInterval = 2 // 2 second
var _Tick_bIntervalsSet          = false;
var _Tick_RefreshIntervalID;
var date,month,dayofweek,day,year;
var months = new Array('JANUARY','FEBRUARY','MARCH','APRIL','MAY','JUNE','JULY','AUGUST','SEPTEMBER','OCTOBER','NOVEMBER','DECEMBER');
var daysofweek = new Array('SUNDAY','MONDAY','TUESDAY','WED','THURS','FRIDAY','SAT');
var autosync;
var totalCPUs;
var letterList = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var drivesArray = new Array(26);
var drivesAliveArray = new Array(26);
var drivesPercentArray = new Array(26);
var HDCount = 0;
var CPUUsage = 0;
var dispHDSideShowString;
var dispRamUsage = 0;
var dispCPUString;
var dispBatteryString;
var dispWifiString;
var dispBinString

// -- Set Timers -- //
function SetHDDRefreshIntervals() { // Activate the timer
if (_HDD_bIntervalsSet == false)
{_HDD_RefreshIntervalID = setInterval(getHDDs, 1000 * _HDD_RefreshInterval)
_HDD_bIntervalsSet = true;}}

function ClearHDDRefreshIntervals() { // Deactivate the timers
if (_HDD_bIntervalsSet == true)
{clearInterval(_HDD_RefreshIntervalID);
_HDD_bIntervalsSet = false;}}

function TickInterval() { // Activate the timer
if (_Tick_bIntervalsSet == false)
{_Tick_RefreshIntervalID = setInterval(Tick, 1000 * _Tick_RefreshInterval)
_Tick_bIntervalsSet = true;}}

function ClearTickInterval() { // Deactivate the timers
if (_Tick_bIntervalsSet == true)
{clearInterval(_Tick_RefreshIntervalID);
_Tick_bIntervalsSet = false;}}

// -- Main Functions -- //
function runGadget()
{
    if (mediaPlayer.url==""){mediaPlayer.url ="http://www.977music.com/tunein/web/hitz.asx"}
    
    UpdateBin();
    getHDDs();
    Tick();
    TickInterval();
}

function procSettingsClosedEvent(event){ //process settings closed event
   if (event.closeAction == event.Action.commit) {
        RefreshGadget()
   }
}

function RefreshGadget()
{
    ClearHDDRefreshIntervals()
    ClearTickInterval()
    mediaPlayer.controls.stop();
    if (System.Gadget.Settings.read("radioURL")!=""){mediaPlayer.url  = System.Gadget.Settings.read("radioURL")}
    runGadget();
    doHeight();
}

function intialiseGadget()
{
    System.Shell.RecycleBin.onRecycleBinChanged = UpdateBin;
    System.Network.Wireless.connectionChanged = DetectWireless;
    System.Gadget.Flyout.file = "flyout.htm"; 
    document.body.ondrop = MoveToBin;
    binImg.ondragenter = cancelEvent;
    binImg.ondragover = cancelEvent;
    autosync = setInterval("SyncBin()", 120000);
    totalCPUs = System.Machine.CPUs.count;

    System.Gadget.settingsUI = "settings.htm";                              // set settings page
    System.Gadget.onSettingsClosed = procSettingsClosedEvent;               // set settings onclosed method
    System.Gadget.SideShow.setFriendlyName("Computer Status");
    
    DetectWireless()   
    DetectBattery();
    DetectDrives();
        
    doHeight();
    
    SetSideShowMenu();
}

function DetectWireless()
{
    if (System.Network.Wireless.ssid == ""){
        System.Gadget.Settings.write("enableWifi",false)
        wirelessDiv.style.display="none"
    }else{
        System.Gadget.Settings.write("enableWifi",true)
        wirelessDiv.style.display="block"
    }
}

function DetectBattery()
{
    if (System.Machine.PowerStatus.batteryPercentRemaining == 255){
        System.Gadget.Settings.write("enableBattery",false)
        batteryDiv.style.display="none"
    }else{
        System.Gadget.Settings.write("enableBattery",true)
        batteryDiv.style.display="block"
    }
}

function DetectDrives()
{
    HDCount = 0;
    for(var i = 0; i < 26; i++)  {
	    drivesArray[i] = System.Shell.drive(letterList.charAt(i));
	    try{if (drivesArray[i] && drivesArray[i].isReady){driveWorking=true}else{driveWorking=false}}catch(e){driveWorking=false}
		if (driveWorking){
		    drivesAliveArray[i] = true;
		    HDCount = HDCount + 1;
		}else{ 
		    drivesAliveArray[i] = false; 
		}
	}
}

function doHeight()
{
    var heightTotal = 11 //cpudiv is 11px from top   

    if (totalCPUs < 3){
        cpuDiv.style.height = 39
    }else{
        cpuDiv.style.height = 25 + (7*totalCPUs)
    }

               
    if (cpuDiv.style.display!="none"){heightTotal=heightTotal+parseInt(cpuDiv.style.height)}
    if (ramDiv.style.display!="none"){heightTotal=heightTotal+parseInt(ramDiv.style.height)}
    heightTotal=heightTotal+(HDCount*28);
    hddDivs.style.height = HDCount*28;
    if (wirelessDiv.style.display!="none"){heightTotal=heightTotal+parseInt(wirelessDiv.style.height)}
    if (batteryDiv.style.display!="none"){heightTotal=heightTotal+parseInt(batteryDiv.style.height)}
    if (recyclebindiv.style.display!="none"){heightTotal=heightTotal+parseInt(recyclebindiv.style.height)}
    if (bbcDateDiv.style.display!="none"){heightTotal=heightTotal+parseInt(bbcDateDiv.style.height)}
                  
    document.body.style.height = heightTotal
    bgImage.style.height = heightTotal
}



function Tick()
{
    if (System.Gadget.Settings.read("enableBattery")){UpdateBattery()}
    if (System.Gadget.Settings.read("enableWifi")){UpdateWifi()}
    ram()
	cpu();
	datetime();
	uptime();
	UpdateSideShow()
}


function getHDDs()
{
    hddDivs.innerHTML = ""
    dispHDSideShowString = ""
    
    count = 1;
    for (i=0; i<=26; i++){
        if (drivesAliveArray[i] == true){
            HDD(count,letterList.charAt(i))
            count = count + 1;
        }
    }
    
    SetHDDRefreshIntervals()
}


function convertBytes( bytes )
{
    var i = 0;var units = Array( " MB", " GB", " TB" );

    while ( bytes >= 1024 && ( bytes / 1024 ) >= 1 ){
	    bytes /= 1024;
	    i++;
    }
    
    return ( Math.round(bytes * 100) / 100 ) + units[i];
}

function HDD(driveNum,curDriveLetter) 
{
    
    try{
        var curDrive = System.Shell.drive( curDriveLetter )
        var percentUsed = (110 - Math.round(curDrive.freeSpace / curDrive.totalSize * 110));
        var statusPercent = (100 - Math.round(curDrive.freeSpace / curDrive.totalSize * 100));
    	var curType = curDrive.driveType;
    }catch(e){
        DetectDrives();
        setTimeout(doHeight,200);
        setTimeout(getHDDs,400);
    }

    if ( null == curDrive ) {
        hddLevelTxt = "\n" + "\n" + "Drive Unavailable";
    }else{
        hddLevelTxt = convertBytes(curDrive.freeSpace) + " " + statusPercent+"%";
    }
    
	if (percentUsed == 100){graphImgSrc = "images/cpu2100.png";
	}else if (percentUsed >= 90){graphImgSrc = "images/cpu290.png";
	}else if (percentUsed >= 80){graphImgSrc = "images/cpu280.png";
	}else if (percentUsed >= 70){graphImgSrc = "images/cpu270.png";
	}else if (percentUsed >= 60){graphImgSrc = "images/cpu260.png";
	}else if (percentUsed >= 50){graphImgSrc = "images/cpu250.png";
	}else if (percentUsed >= 40){graphImgSrc = "images/cpu240.png";
	}else if (percentUsed >= 30){graphImgSrc = "images/cpu230.png";
	}else if (percentUsed >= 20){graphImgSrc = "images/cpu220.png";
	}else if (percentUsed >= 10){graphImgSrc = "images/cpu210.png";
	}else{graphImgSrc = "images/cpu200.png";
	}
	
	if (curDriveLetter == "A"){hddImgSrc = "images/drives/hdd1.png";
	}else if (curDriveLetter == "B"){hddImgSrc = "images/drives/hdd1.png";
	}else if (curType == 1) {hddImgSrc = "images/drives/hdd1.png";
	}else if (curType == 2) {hddImgSrc = "images/drives/hdd2.png";
	}else if (curType == 3) {hddImgSrc = "images/drives/hdd3.png";
	}else if (curType == 4) {hddImgSrc = "images/drives/hdd4.png";
	}else if (curType == 5) {hddImgSrc = "images/drives/hdd5.png";
	}else if (curType == 6) {hddImgSrc = "images/drives/hdd6.png";
	}else {hddImgSrc = "images/drives/hdd7.png";
	}   
	
    HDDDivText = '<div style="position:relative;height:28px;">'
    HDDDivText += '<img src="images/horizontalDivider.png" style="left:4px;" alt="" />'
    HDDDivText += '<img class="imgButton" alt="Click to show drive" src="'+hddImgSrc+'" style="left: 10px;top:4px;" onclick="launchDrive(\''+curDriveLetter+'\')" />'
    HDDDivText += '<div style="top: 2px;left: 38px;">'+curDriveLetter+':</div>'
    HDDDivText += '<div style="top: 2px;right: 11px">'+hddLevelTxt+'</div>'
    HDDDivText += '<img src="'+graphImgSrc+'" style="top: 18px;left: 40px;" />'
    HDDDivText += '</div>'
    
    dispHDSideShowString += '<txt align ="c">'+curDriveLetter+': '+ hddLevelTxt +'</txt>';
    dispHDSideShowString += '<br/>';
	
	hddDivs.innerHTML = hddDivs.innerHTML + HDDDivText;
}

function UpdateBattery()
{
    powerStatus = System.Machine.PowerStatus.isPowerLineConnected;
    batteryLife = System.Machine.PowerStatus.batteryPercentRemaining; 
    batteryTotalTime = System.Machine.PowerStatus.batteryCapacityTotal;
    batteryRemTime = (batteryTotalTime/60).toFixed(0);
			
	if(batteryLife==100){empty.src="images/psu100.png";
	}else if(batteryLife>=90 && batteryLife<100){empty.src="images/psu90.png";
	}else if(batteryLife>=80 && batteryLife<90){empty.src="images/psu80.png";
	}else if(batteryLife>=70 && batteryLife<80){empty.src="images/psu70.png";
	}else if(batteryLife>=60 && batteryLife<70){empty.src='images/psu60.png';
	}else if(batteryLife>=50 && batteryLife<60){empty.src="images/psu50.png";
	}else if(batteryLife>=40 && batteryLife<50){empty.src="images/psu40.png";
	}else if(batteryLife>=30 && batteryLife<40){empty.src="images/psu30.png";
	}else if(batteryLife>=20 && batteryLife<30){empty.src="images/psu20.png";
	}else if(batteryLife>=10 && batteryLife<20){empty.src="images/psu10.png";
	}else{empty.src="images/psu00.png";
	}
			
		if(powerStatus==1)
		{
			txt.innerText = batteryLife + "%";

			if(batteryLife==100){
				estado.src="images/carregar.png";
				txt2.innerText = "Battery: charged";
			}else{	
				estado.src="images/carregar.png";
				txt2.innerText = "Battery: charging";
			}

		}else{
			if (batteryRemTime >= 60)
			{
				hh = parseInt(String((batteryRemTime/60)));
				mm = String((batteryRemTime-(hh*60)).toFixed(0));
				separator = ":";
				time = "h";

				if (mm<10){mmm = "0" + mm;
				}else{mmm = mm;
				}
				
			}else if (batteryRemTime < 60){
				hh = "00";
				mm = batteryRemTime;
				separator = ":";
				time = "h";
				
				if (mm<10){mmm = "0" + mm;
				}else{mmm = mm;
				}
			}
			
			if (batteryTotalTime/60 < 1)
			{	
				hh = "N/D";
				mmm = "";
				separator = "";
				time = "";
			}

			
			txt.innerText =  hh + separator + mmm + time;
			txt2.innerText = "Battery: not charging";
		
			estado.src="images/descarregar.png";
		}
		
    batText.innerText = batteryLife + "%";
    
    dispBatteryString = '<body><content id="9" title="Battery">';
    dispBatteryString += '<txt align ="c">'+txt2.innerText+'</txt>';
    dispBatteryString += '<br/>';
    dispBatteryString += '<txt align ="c">'+batText.innerText+'</txt>';
    dispBatteryString += '<br/>';
    dispBatteryString += '<txt align ="c">'+txt.innerText+'</txt>';
    dispBatteryString += '<br/>';
    dispBatteryString += '</content>';
    dispBatteryString += '</body>';
}
				
function cpu()
{
	var usageTotal = 0;
	cpuGraphsDiv.innerHTML = ""
    dispCPUString = '<body><content id="6" title="Processor">';
    dispCPUString += '<txt align ="c">Total CPUs: <em>'+totalCPUs+'</em></txt>';
    dispCPUString += '<br/>';

	for (var i=0; i<totalCPUs; i++)
	{
	    cpuCalc = Math.min(Math.max(0,System.Machine.CPUs.item(i).usagePercentage), 100);
	    usageTotal = usageTotal + cpuCalc;
	    
	    if (cpuCalc == 100){graphSrc = "images/cpu2100.png";
	    }else if (cpuCalc >= 90){graphSrc = "images/cpu290.png";
	    }else if (cpuCalc >= 80){graphSrc = "images/cpu280.png";
	    }else if (cpuCalc >= 70){graphSrc = "images/cpu270.png";
	    }else if (cpuCalc >= 60){graphSrc = "images/cpu260.png";
	    }else if (cpuCalc >= 50){graphSrc = "images/cpu250.png";
	    }else if (cpuCalc >= 40){graphSrc = "images/cpu240.png";
	    }else if (cpuCalc >= 30){graphSrc = "images/cpu230.png";
	    }else if (cpuCalc >= 20){graphSrc = "images/cpu220.png";
	    }else if (cpuCalc >= 10){graphSrc = "images/cpu210.png";
	    }else{graphSrc = "images/cpu200.png";
	    }
	    
        dispCPUString += '<txt align ="c">CPU '+i+': <em>'+parseInt(cpuCalc)+'%</em></txt><br/>';

	    cpuGraphsDiv.innerHTML += '<img src="'+graphSrc+'" id="meter'+i+'" style="top: '+(i*6)+'px; left: 40px;" />'
	}
	
    var cpuusagepercentage = Math.min(Math.max(0, usageTotal / totalCPUs), 100);	
	percent.innerText = (parseInt(cpuusagepercentage) + "%");
	CPUUsage = cpuusagepercentage;
    
    dispCPUString += '<txt align ="c">Total CPU Usage: <em>'+parseInt(CPUUsage)+'%</em></txt>';
    dispCPUString += '<br/>';
    dispCPUString += '</content>';
    dispCPUString += '</body>';
}


function ram()
{
	var AvailableRam = System.Machine.availableMemory;
	var memoryPercentage = 100 - (parseInt(AvailableRam/System.Machine.totalMemory * 100 ));
	dispRamUsage = memoryPercentage + "%";	
	
	if (memoryPercentage >= 90){dispRamGraph = "images/mem90.png";
	}else if (memoryPercentage >= 80){dispRamGraph = "images/mem80.png";
	}else if (memoryPercentage >= 70){dispRamGraph = "images/mem70.png";
	}else if (memoryPercentage >= 60){dispRamGraph = "images/mem60.png";
	}else if (memoryPercentage >= 50){dispRamGraph = "images/mem50.png";
	}else if (memoryPercentage >= 40){dispRamGraph = "images/mem40.png";
	}else if (memoryPercentage >= 30){dispRamGraph = "images/mem30.png";
	}else if (memoryPercentage >= 20){dispRamGraph = "images/mem20.png";
	}else if (memoryPercentage >= 10){dispRamGraph = "images/mem10.png";
	}else{dispRamGraph = "images/mem00.png";
	}	
	
    ramLevel.innerText = dispRamUsage;
    ramGraph.src = dispRamGraph;
    ramAvail.innerText = "RAM: " + AvailableRam;
}

function UpdateWifi()
{
	var wifiObj = System.Network.Wireless;
	
	if(wifiObj.signalStrength < 10){dispWifiImg =  "images/wifi00.png";
	}else if(wifiObj.signalStrength >= 10 && wifiObj.signalStrength < 20){dispWifiImg =  "images/wifi10.png";
	}else if(wifiObj.signalStrength >= 20 && wifiObj.signalStrength < 30){dispWifiImg =  "images/wifi20.png";
	}else if(wifiObj.signalStrength >= 30 && wifiObj.signalStrength < 40){dispWifiImg =  "images/wifi30.png";
	}else if(wifiObj.signalStrength >= 40 && wifiObj.signalStrength < 50){dispWifiImg =  "images/wifi40.png";
	}else if(wifiObj.signalStrength >= 50 && wifiObj.signalStrength < 60){dispWifiImg =  "images/wifi50.png";
	}else if(wifiObj.signalStrength >= 60 && wifiObj.signalStrength < 70){dispWifiImg =  "images/wifi60.png";
	}else if(wifiObj.signalStrength >= 70 && wifiObj.signalStrength < 80){dispWifiImg =  "images/wifi70.png";
	}else if(wifiObj.signalStrength >= 80 && wifiObj.signalStrength < 90){dispWifiImg =  "images/wifi80.png";
	}else if(wifiObj.signalStrength >= 90 && wifiObj.signalStrength < 100){dispWifiImg =  "images/wifi90.png";
	}else{dispWifiImg =  "images/wifi100.png";
	}
	
	if (wifiObj.secureConnection){
		dispWifiSecureImg = "images/secure.png";
	}else{
		dispWifiSecureImg = "images/unsecure.png";
	}
	
	dispWifiStrength = wifiObj.signalStrength + "%";
	dispWifiTxt = (wifiObj.signalStrength > 0 && wifiObj.address != "") ? "Link: " + wifiObj.ssid : "Not connected ";



    wirelessImage.src = dispWifiImg;
    wifi.src = dispWifiSecureImg;
    wirelessQuality.innerText = dispWifiStrength;
    wirelessConnected.innerText = dispWifiTxt;
    
    dispWifiString = '<body><content id="10" title="Wifi">';
    dispWifiString += '<txt align ="c">' + wirelessConnected.innerText +'</txt>';
    dispWifiString += '<br/>';
    dispWifiString += '<txt align ="c">'+dispWifiStrength+'</txt>';
    dispWifiString += '<br/>';
	if (wifiObj.secureConnection){
        dispWifiString += '<txt align ="c"><em>Secured</em></txt>';
	}else{
        dispWifiString += '<txt align ="c"><em>Unsecured</em></txt>';
	}
    dispWifiString += '</content>';
    dispWifiString += '</body>';

}

function UpdateBin()
{
	var thesize = System.Shell.RecycleBin.sizeUsed;
	var suffix = '';

	if ((System.Shell.RecycleBin.fileCount == 0) && (System.Shell.RecycleBin.folderCount == 0))
	{
		dispBasketSize = "Empty";
		emptyAll.src = "images/emptybin_disabled.png";
		emptyAll.style.cursor = "normal";
		emptyAll.alt = "Bin already empty";
		dispBasketFileCount = "0 Items";
	} 
	else
	{
		if (thesize < 1024)
		{
			suffix = "B";
		}
		else if ((thesize >= 1024) && (thesize < (1024*1024)))
		{
			thesize = thesize / 1024;
			suffix = "KB";
		}
		else if ((thesize >= 1024*1024) && (thesize < (1024*1024*1024)))
		{
			thesize = thesize / 1024 / 1024;
			suffix = "MB";
		}
		else if ((thesize >= 1024*1024*1024))
		{
			thesize = thesize / 1024 / 1024 / 1024;
			suffix = "GB";
		}
		
		emptyAll.src = "images/emptybin.png";
		emptyAll.style.cursor = "hand";
		emptyAll.alt = "Delete All";
		
		thesize = thesize + "0"; // to cast integer to string
		thesize = thesize.substring(0, (thesize.length - 1));
		var CommaSep = thesize.indexOf(".");
		if (CommaSep != -1)
		{
			thesize = thesize.substring(0, CommaSep + 3);
		}

		dispBasketSize = thesize + " " + suffix;
		dispBasketFileCount = ((System.Shell.RecycleBin.fileCount + System.Shell.RecycleBin.folderCount) == 1) ? "1 Item" : (System.Shell.RecycleBin.fileCount + System.Shell.RecycleBin.folderCount) + " Items"; 
	}

	var assignimg = '000';
	if ((thesize < 512) && (thesize > 0) && (suffix != "GB"))
	{
		assignimg = "030";
	}
	else if ((thesize > 512) && (suffix != "KB" && suffix != "GB"))
	{
		assignimg = "070";
	}
	else if ((thesize > 1) && (suffix == "GB"))
	{
		assignimg = "100";
	}
	dispBinImg = "images/" + assignimg + ".png";
	
	dispBinString = '<body><content id="11" title="Recycle Bin">';
    dispBinString += '<txt align ="c">'+dispBasketFileCount+'</txt>';
    dispBinString += '<br/>';
    dispBinString += '<txt align ="c">'+dispBasketSize+'</txt>';
    dispBinString += '</content>';
    dispBinString += '</body>';
    
    binImg.src = dispBinImg;
    basketSize.innerText = dispBasketSize;
    fileCountx.innerText = dispBasketFileCount;
}

function EmptyPaperBasket()
{
	if (((System.Shell.RecycleBin.fileCount + System.Shell.RecycleBin.folderCount) > 0))
	{
		System.Shell.RecycleBin.emptyAll();
	}
}

function SyncBin()
{
	sync.style.visibility = "hidden";
	deac = setInterval("sync.style.visibility = 'visible'; clearInterval(deac);", 2000);

	UpdateBin();
}

function cancelEvent()
{
	event.returnValue = false;
}

function MoveToBin()
{
	var item = null;
	var index = 0;

	item = System.Shell.itemFromFileDrop(event.dataTransfer, index);
	while (item != null)
	{ 
		if (item){System.Shell.RecycleBin.deleteItem(item.path)}
		index++;
		item = System.Shell.itemFromFileDrop(event.dataTransfer, index);
	}

	SyncBin();
}

function datetime() 
{
    date = new Date();
    dayofweek = date.getDay();
    month = date.getMonth();
    day = date.getDate();
    year = date.getYear();
    
    dispMonth=daysofweek[dayofweek]
    dispDate=day
    
    monthTxt.innerText = dispMonth;
    dateTxt.innerText = dispDate;

}

function SetSideShowMenu()
{
    var xmlDisp = ""
    
    xmlDisp += '<body>';
    xmlDisp += '<menu id="1" title="Main Menu">';
    xmlDisp += '<item target="6">Processor</item>';
    xmlDisp += '<item target="7">Memory</item>';
    xmlDisp += '<item target="8">Hard Drives</item>';
    
    xmlDisp += '<div/>';

    if (System.Gadget.Settings.read("enableBattery")){
        xmlDisp += '<item target="9">Battery</item>';
    }
    if (System.Gadget.Settings.read("enableWifi")){
        xmlDisp += '<item target="10">WiFi</item>';
    }

    xmlDisp += '<item target="11">Recycle Bin</item>';
    xmlDisp += '<item target="12" >Uptime</item>';
    xmlDisp += '</menu>';
    xmlDisp += '</body>';
    
    System.Gadget.SideShow.remove(1);
    System.Gadget.SideShow.addText(1, xmlDisp);
    
    //path = System.Gadget.path + "\\images\\focus.jpg"
    //System.Gadget.SideShow.remove(20);
    //System.Gadget.SideShow.addImage(20,path);
}

function UpdateSideShow()
{
    System.Gadget.SideShow.remove(6);
    System.Gadget.SideShow.addText(6,dispCPUString);

    if (System.Gadget.Settings.read("enableBattery")){
        System.Gadget.SideShow.remove(9);
        System.Gadget.SideShow.addText(9,dispBatteryString);
    }
    if (System.Gadget.Settings.read("enableWifi")){
        System.Gadget.SideShow.remove(10);
        System.Gadget.SideShow.addText(10,dispWifiString);
    }
    
    System.Gadget.SideShow.remove(11);
    System.Gadget.SideShow.addText(11,dispBinString);

    var xmlDisp = '<body><content id="7" title="Memory">';
    xmlDisp += '<txt align ="c">RAM: <em>'+dispRamUsage+'</em></txt>';
    xmlDisp += '<br/>';
    xmlDisp += '</content>';
    xmlDisp += '</body>';
    
    System.Gadget.SideShow.remove(7);
    System.Gadget.SideShow.addText(7,xmlDisp);
    
    var xmlDisp = '<body><content id="8" title="Hard Drives">';
    xmlDisp += dispHDSideShowString;
    xmlDisp += '<br/>';
    xmlDisp += '</content>';
    xmlDisp += '</body>';
    
    System.Gadget.SideShow.remove(8);
    System.Gadget.SideShow.addText(8,xmlDisp);
    
    var xmlDisp = '<body><content id="12" title="Uptime">';
    xmlDisp += '<txt align ="c">Uptime</txt>';
    xmlDisp += '<br/>';
    xmlDisp += '<txt align ="c"><em>'+System.Gadget.Settings.read("uptimeSetting")+'</em></txt>';
    xmlDisp += '</content>';
    xmlDisp += '</body>';
    
    System.Gadget.SideShow.remove(12);
    System.Gadget.SideShow.addText(12,xmlDisp);
    
    System.Gadget.SideShow.addText(0,"CPU: " + parseInt(CPUUsage) + "%  -  RAM: " + dispRamUsage);
}

//onerror=handleErr
//function handleErr(msg,url,l){window.prompt("Line:" + l + " - " + url,msg)}
onerror=handleErr
function handleErr(msg,url,l){}