/* Main table for all priorities */
function DisplayTable() {

    var tableContent = '';

    tableContent += '<table width="100%"><tr><td width="25%" valign="top" align="center">';
    tableContent += DisplayTableByPriority("Priorit&eacute; haute", 1);
    tableContent += '</td><td width="25%" valign="top" align="center">';

    tableContent += DisplayTableByPriority("Priorit&eacute; moyenne", 2);
    tableContent += '</td><td width="25%" valign="top" align="center">';

    tableContent += DisplayTableByPriority("Priorit&eacute; basse", 3);
    tableContent += '</td><td width="25%" valign="top" align="center">';

    tableContent += DisplayTableByPriority("Diff&eacute;r&eacute;", 0);

    tableContent += '</td><td width="25%" valign="top" align="center">';

    tableContent += DisplayTableRunningReport("Planifi&eacute;");
    tableContent += '</td></tr></table>';

    document.write(tableContent);
}

/* Sub table for each scheduling report */
function DisplayTableRunningReport(name) {
    var tableContent = getSubTableHeaderScheduling(name);

    /* Browse each report */
    var reportCount = schedulingReportArray.length;
    for (var i = 0; i < reportCount; i++) {
        var currentReport = schedulingReportArray[i];
        /* Display columns of the current report */
        tableContent += '<tr>';
        tableContent += '<td class="reportTable"><strong>' + currentReport['reportCode'] + '</strong></td>';
        tableContent += '<td class="reportTable">' + currentReport['name'] + '</td>';
        tableContent += '</tr>';
    }
    tableContent += '</table>';
    return tableContent;
}

function getSubTableHeaderScheduling(aPriorityName) {
    var content = '<DIV align="center" width="100%" style="border:1px solid #DDDDFF;border-bottom:3px double #DDDDFF;font-size:14px;font-weight:bold;color:#5555AA;margin-bottom:6px;background:#FAFAFF;">'
            + aPriorityName + '</DIV>';
    content += '<table cellspacing="0" cellpadding="1" border="0" width="95%" style="border:1px solid #9EC8DE;"><tr><th class="reportTable">Rapport</th><th class="reportTable">Nom planification</th></tr>';
    return content;
}

/* Sub table for each priority */
function DisplayTableByPriority(aPriorityName, aPriority) {
    var tableContent = getSubTableHeader(aPriorityName);

    // Browse each report
    var reportCount = reportArray.length;
    for (var i = 0; i < reportCount; i++) {
        var currentReport = reportArray[i];
        if (aPriority == '0') {
            // Special case of deferred
            if (currentReport['state'] != 'WAIT') {
                continue;
            }
        } else if (currentReport['priority'] != aPriority) {
            // Check priority value compliance
            continue;
        }
        // Display columns of the current report
        tableContent += '<tr>';
        tableContent += '<td class="reportTable"><strong>' + currentReport['reportCode'] + '</strong></td>';
        tableContent += '<td class="reportTable">' + currentReport['login'] + '</td>';
        tableContent += '</tr>';
    }
    tableContent += '</table>';
    return tableContent;
}

function getSubTableHeader(aPriorityName) {
    var content = '<DIV align="center" width="100%" style="border:1px solid #DDDDFF;border-bottom:3px double #DDDDFF;font-size:14px;font-weight:bold;color:#5555AA;margin-bottom:6px;background:#FAFAFF;">'
            + aPriorityName + '</DIV>';
    content += '<table cellspacing="0" cellpadding="1" border="0" width="95%" style="border:1px solid #9EC8DE;"><tr><th class="reportTable">Rapport</th><th class="reportTable">Utilisateur</th></tr>';
    return content;
}