var g_diskCapacityTable = new MyTable("diskCapacityTable", [0, 1]);

function initializeDiskCapacityTable()
{
    g_diskCapacityTable.initialize(
        new Array("Duration", "Video Quality", "Capacity"));
}

function redrawDiskCapacityTable()
{
    var durationList;
    var hoursList;
    if (g_choice.useCustomDays && g_choice.customDays > 0) {
        durationList = new Array();
        hoursList = new Array();
        if (g_choice.customDayHour == 0) {  // Days
            durationList.push(g_choice.customDays + " Days");
            hoursList.push(g_choice.customDays * 24);
        }
        else {  // Hours
            durationList.push(g_choice.customDays + " Hours");
            hoursList.push(g_choice.customDays);
        }
    }
    else {
        durationList = new Array("1 Hour", "1 Day", "1 Week", "1 Month");
        hoursList = new Array(1, 24, 24*7, 24*30);
    }

    var HDD_UNIT = 1000;

    g_diskCapacityTable.empty();

    var qList = g_choice.dev.qualityList;

    var i;
    for (i = 0; i < qList.length; i++) {
        if (!g_choice.allQuality && i != g_choice.quality) {
            continue;
        }
	var bps = g_choice.calculateBitsPerSecond(i);
	var kbytesPerSecond = bps / (HDD_UNIT * 8);
        var mbytesPerHour = kbytesPerSecond * 3600 / HDD_UNIT;
	var j;
        for (j = 0; j < durationList.length; j++) {
            var hours = hoursList[j];
            var mbytes = Math.round(mbytesPerHour * hours * 10) / 10;
            var value;
            if (mbytes >= (HDD_UNIT*HDD_UNIT)) {
                value = Math.round((mbytes/(HDD_UNIT*HDD_UNIT))*10)/10;
                unit = " TB";
            }
            else if (mbytes >= HDD_UNIT) {
                value = Math.round((mbytes/HDD_UNIT)*10)/10;
                unit = " GB";
            }
            else {
                value = mbytes;
                unit = " MB";
            }

            var row = new MyTableRow(g_diskCapacityTable);
            row.cells.push(new MyTableCell(durationList[j], hoursList[j]));
            row.cells.push(new MyTableCell(qList[i], i));
            row.cells.push(new MyTableCell(value + unit, mbytes));
            g_diskCapacityTable.addRow(row);
	}
    }

    g_diskCapacityTable.redraw();
}

